|
|
|
@ -27,6 +27,7 @@ import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementExc
|
|
|
|
|
import io.entgra.server.bootup.heartbeat.beacon.dto.ServerContext;
|
|
|
|
|
import io.entgra.server.bootup.heartbeat.beacon.internal.HeartBeatBeaconDataHolder;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.ServerCtxInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -39,6 +40,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
|
int hashIndex = -1;
|
|
|
|
|
ServerContext localServerCtx = null;
|
|
|
|
|
ServerCtxInfo serverCtxInfo = null;
|
|
|
|
|
if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
|
|
|
|
|
try {
|
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
@ -64,6 +66,10 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
|
} finally {
|
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String msg = "Heart Beat Configuration Disabled. Server Context Information Not available.";
|
|
|
|
|
throw new HeartBeatManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
return serverCtxInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -71,23 +77,30 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
|
public String updateServerContext(ServerContext ctx) throws HeartBeatManagementException {
|
|
|
|
|
HeartBeatDAO heartBeatDAO;
|
|
|
|
|
String uuid = null;
|
|
|
|
|
if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
|
|
|
|
|
try {
|
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
|
HeartBeatBeaconDAOFactory.beginTransaction();
|
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
|
|
|
|
|
|
uuid = heartBeatDAO.retrieveExistingServerCtx(ctx);
|
|
|
|
|
if (uuid == null) {
|
|
|
|
|
uuid = heartBeatDAO.recordServerCtx(ctx);
|
|
|
|
|
HeartBeatBeaconDAOFactory.commitTransaction();
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
} catch (HeartBeatDAOException e) {
|
|
|
|
|
String msg = "Error Occured while retrieving active server count.";
|
|
|
|
|
String msg = "Error Occured while retrieving server context.";
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
HeartBeatBeaconDAOFactory.rollbackTransaction();
|
|
|
|
|
String msg = "Error occurred while updating server context. Issue in opening a connection to the underlying data source";
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String msg = "Heart Beat Configuration Disabled. Updating Server Context Failed.";
|
|
|
|
|
throw new HeartBeatManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
return uuid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -96,19 +109,27 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
|
public boolean recordHeartBeat(HeartBeatEvent event) throws HeartBeatManagementException {
|
|
|
|
|
HeartBeatDAO heartBeatDAO;
|
|
|
|
|
boolean operationSuccess = false;
|
|
|
|
|
if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
|
|
|
|
|
try {
|
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
|
HeartBeatBeaconDAOFactory.beginTransaction();
|
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
|
operationSuccess = heartBeatDAO.recordHeatBeat(event);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
HeartBeatBeaconDAOFactory.commitTransaction();
|
|
|
|
|
} catch (HeartBeatDAOException e) {
|
|
|
|
|
String msg = "Error Occured while retrieving active server count.";
|
|
|
|
|
String msg = "Error occurred while recording heart beat.";
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
HeartBeatBeaconDAOFactory.rollbackTransaction();
|
|
|
|
|
String msg = "Error occurred performing heart beat record transaction. " +
|
|
|
|
|
"Transaction rolled back.";
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
} finally {
|
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String msg = "Heart Beat Configuration Disabled. Recording Heart Beat Failed.";
|
|
|
|
|
throw new HeartBeatManagementException(msg);
|
|
|
|
|
}
|
|
|
|
|
return operationSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|