|
|
@ -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.dto.ServerContext;
|
|
|
|
import io.entgra.server.bootup.heartbeat.beacon.internal.HeartBeatBeaconDataHolder;
|
|
|
|
import io.entgra.server.bootup.heartbeat.beacon.internal.HeartBeatBeaconDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.common.ServerCtxInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.ServerCtxInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
@ -39,6 +40,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
int hashIndex = -1;
|
|
|
|
int hashIndex = -1;
|
|
|
|
ServerContext localServerCtx = null;
|
|
|
|
ServerContext localServerCtx = null;
|
|
|
|
ServerCtxInfo serverCtxInfo = null;
|
|
|
|
ServerCtxInfo serverCtxInfo = null;
|
|
|
|
|
|
|
|
if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
@ -48,7 +50,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
int cumilativeTimeOut = timeOutIntervalInSeconds + timeSkew;
|
|
|
|
int cumilativeTimeOut = timeOutIntervalInSeconds + timeSkew;
|
|
|
|
String localServerUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID();
|
|
|
|
String localServerUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID();
|
|
|
|
Map<String, ServerContext> serverCtxMap = heartBeatDAO.getActiveServerDetails(cumilativeTimeOut);
|
|
|
|
Map<String, ServerContext> serverCtxMap = heartBeatDAO.getActiveServerDetails(cumilativeTimeOut);
|
|
|
|
if(!serverCtxMap.isEmpty()) {
|
|
|
|
if (!serverCtxMap.isEmpty()) {
|
|
|
|
localServerCtx = serverCtxMap.get(localServerUUID);
|
|
|
|
localServerCtx = serverCtxMap.get(localServerUUID);
|
|
|
|
if (localServerCtx != null) {
|
|
|
|
if (localServerCtx != null) {
|
|
|
|
hashIndex = localServerCtx.getIndex();
|
|
|
|
hashIndex = localServerCtx.getIndex();
|
|
|
@ -64,6 +66,10 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Heart Beat Configuration Disabled. Server Context Information Not available.";
|
|
|
|
|
|
|
|
throw new HeartBeatManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
return serverCtxInfo;
|
|
|
|
return serverCtxInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -71,23 +77,30 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
public String updateServerContext(ServerContext ctx) throws HeartBeatManagementException {
|
|
|
|
public String updateServerContext(ServerContext ctx) throws HeartBeatManagementException {
|
|
|
|
HeartBeatDAO heartBeatDAO;
|
|
|
|
HeartBeatDAO heartBeatDAO;
|
|
|
|
String uuid = null;
|
|
|
|
String uuid = null;
|
|
|
|
|
|
|
|
if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
HeartBeatBeaconDAOFactory.beginTransaction();
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
|
|
|
|
|
|
|
|
uuid = heartBeatDAO.retrieveExistingServerCtx(ctx);
|
|
|
|
uuid = heartBeatDAO.retrieveExistingServerCtx(ctx);
|
|
|
|
if(uuid == null){
|
|
|
|
if (uuid == null) {
|
|
|
|
uuid = heartBeatDAO.recordServerCtx(ctx);
|
|
|
|
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) {
|
|
|
|
} 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);
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Heart Beat Configuration Disabled. Updating Server Context Failed.";
|
|
|
|
|
|
|
|
throw new HeartBeatManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
return uuid;
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -96,19 +109,27 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
|
|
|
|
public boolean recordHeartBeat(HeartBeatEvent event) throws HeartBeatManagementException {
|
|
|
|
public boolean recordHeartBeat(HeartBeatEvent event) throws HeartBeatManagementException {
|
|
|
|
HeartBeatDAO heartBeatDAO;
|
|
|
|
HeartBeatDAO heartBeatDAO;
|
|
|
|
boolean operationSuccess = false;
|
|
|
|
boolean operationSuccess = false;
|
|
|
|
|
|
|
|
if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
HeartBeatBeaconDAOFactory.openConnection();
|
|
|
|
HeartBeatBeaconDAOFactory.beginTransaction();
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
|
|
|
|
operationSuccess = heartBeatDAO.recordHeatBeat(event);
|
|
|
|
operationSuccess = heartBeatDAO.recordHeatBeat(event);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
HeartBeatBeaconDAOFactory.commitTransaction();
|
|
|
|
String msg = "Error occurred while opening a connection to the underlying data source";
|
|
|
|
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
|
|
|
|
} catch (HeartBeatDAOException e) {
|
|
|
|
} 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);
|
|
|
|
throw new HeartBeatManagementException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
HeartBeatBeaconDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Heart Beat Configuration Disabled. Recording Heart Beat Failed.";
|
|
|
|
|
|
|
|
throw new HeartBeatManagementException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
return operationSuccess;
|
|
|
|
return operationSuccess;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|