adding fixes to the flow

revert-70ac1926
Ace 4 years ago
parent 56f93161f0
commit 3744a7cfc7

@ -59,6 +59,7 @@
javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional, javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional,
org.wso2.carbon.context, org.wso2.carbon.context,
org.wso2.carbon.utils.*, org.wso2.carbon.utils.*,
org.wso2.carbon.ndatasource.core,
org.w3c.dom, org.w3c.dom,
org.apache.velocity;version="${velocity.version}", org.apache.velocity;version="${velocity.version}",
org.apache.velocity.app;version="${velocity.version}", org.apache.velocity.app;version="${velocity.version}",
@ -168,6 +169,16 @@
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.mgt.common</artifactId> <artifactId>org.wso2.carbon.device.mgt.common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
<exclusions>
<exclusion>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -30,7 +30,6 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File; import java.io.File;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Hashtable; import java.util.Hashtable;
@ -68,7 +67,7 @@ public class HeartBeatBeaconUtils {
return (DataSource) InitialContext.doLookup(dataSourceName); return (DataSource) InitialContext.doLookup(dataSourceName);
} }
final InitialContext context = new InitialContext(jndiProperties); final InitialContext context = new InitialContext(jndiProperties);
return (DataSource) context.lookup(dataSourceName); return (DataSource) context.doLookup(dataSourceName);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
} }
@ -77,20 +76,10 @@ public class HeartBeatBeaconUtils {
public static ServerContext getServerDetails() throws UnknownHostException, SocketException { public static ServerContext getServerDetails() throws UnknownHostException, SocketException {
InetAddress localHost = InetAddress.getLocalHost(); InetAddress localHost = InetAddress.getLocalHost();
NetworkInterface ni = NetworkInterface.getByInetAddress(localHost);
byte[] hardwareAddress = ni.getHardwareAddress();
String[] hexadecimal = new String[hardwareAddress.length];
for (int i = 0; i < hardwareAddress.length; i++) {
hexadecimal[i] = String.format("%02X", hardwareAddress[i]);
}
String macAddress = String.join("-", hexadecimal);
int iotsCorePort = Integer.parseInt(System.getProperty("iot.core.https.port")); int iotsCorePort = Integer.parseInt(System.getProperty("iot.core.https.port"));
ServerContext ctx = new ServerContext(); ServerContext ctx = new ServerContext();
ctx.setHostName(localHost.getHostName()); ctx.setHostName(localHost.getHostName());
ctx.setMacAddress(macAddress);
ctx.setCarbonServerPort(iotsCorePort); ctx.setCarbonServerPort(iotsCorePort);
return ctx; return ctx;
} }

@ -35,6 +35,7 @@ import java.io.File;
@XmlRootElement(name = "HeartBeatBeaconConfig") @XmlRootElement(name = "HeartBeatBeaconConfig")
public class HeartBeatBeaconConfig { public class HeartBeatBeaconConfig {
private boolean enabled;
private int notifierFrequency; private int notifierFrequency;
private int notifierDelay; private int notifierDelay;
private int serverTimeOutIntervalInSeconds; private int serverTimeOutIntervalInSeconds;
@ -44,7 +45,7 @@ public class HeartBeatBeaconConfig {
private static HeartBeatBeaconConfig config; private static HeartBeatBeaconConfig config;
private static final String HEART_BEAT_NOTIFIER_CONFIG_PATH = private static final String HEART_BEAT_NOTIFIER_CONFIG_PATH =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "heart-beat-config.xml"; CarbonUtils.getCarbonConfigDirPath() + File.separator + "heart-beat-config.xml";
private HeartBeatBeaconConfig() { private HeartBeatBeaconConfig() {
} }
@ -102,6 +103,15 @@ public class HeartBeatBeaconConfig {
this.dataSourceConfig = dataSourceConfig; this.dataSourceConfig = dataSourceConfig;
} }
@XmlElement(name = "Enable", required = true)
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public static void init() throws HeartBeatBeaconConfigurationException { public static void init() throws HeartBeatBeaconConfigurationException {
try { try {
File emailSenderConfig = new File(HEART_BEAT_NOTIFIER_CONFIG_PATH); File emailSenderConfig = new File(HEART_BEAT_NOTIFIER_CONFIG_PATH);

@ -167,7 +167,6 @@ public class HeartBeatBeaconDAOFactory {
currentConnection.remove(); currentConnection.remove();
} }
/** /**
* Resolve data source from the data source definition * Resolve data source from the data source definition
* *
@ -190,7 +189,7 @@ public class HeartBeatBeaconDAOFactory {
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
jndiConfig.getJndiProperties(); jndiConfig.getJndiProperties();
if (jndiPropertyList != null) { if (jndiPropertyList != null) {
Hashtable<Object, Object> jndiProperties = new Hashtable<>(); Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
jndiProperties.put(prop.getName(), prop.getValue()); jndiProperties.put(prop.getName(), prop.getValue());
} }

@ -29,6 +29,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -46,23 +47,21 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
String uuid = null; String uuid = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String serverUUID = UUID.randomUUID().toString();
String sql; String sql;
sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, MAC, UUID, SERVER_PORT) VALUES (?, ?, ?, ?)"; sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, UUID, SERVER_PORT) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(sql, new String[]{"UUID"}); stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, ctx.getHostName()); stmt.setString(1, ctx.getHostName());
stmt.setString(2, ctx.getMacAddress()); stmt.setString(2, serverUUID);
stmt.setString(3, UUID.randomUUID().toString()); stmt.setInt(3, ctx.getCarbonServerPort());
stmt.setInt(4, ctx.getCarbonServerPort());
stmt.executeUpdate(); if(stmt.executeUpdate() > 0){
ResultSet result = stmt.getGeneratedKeys(); uuid = serverUUID;
if (result.next()){
uuid = result.getString("UUID");
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while persisting server context for : '" + throw new HeartBeatDAOException("Error occurred while persisting server context for : '" +
"mac '" + ctx.getMacAddress() + "' " + "port '" + ctx.getCarbonServerPort() + "' " +
"hostname : '" + ctx.getHostName() + "' ", e); "hostname : '" + ctx.getHostName() + "' ", e);
} finally { } finally {
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); HeartBeatBeaconDAOUtil.cleanupResources(stmt, null);
@ -97,11 +96,10 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
String uuid = null; String uuid = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql = "SELECT UUID FROM SERVER_HEART_BEAT_EVENTS WHERE HOST_NAME = ? AND MAC = ? AND SERVER_PORT = ?"; String sql = "SELECT UUID FROM SERVER_HEART_BEAT_EVENTS WHERE HOST_NAME = ? AND SERVER_PORT = ?";
stmt = conn.prepareStatement(sql, new String[]{"UUID"}); stmt = conn.prepareStatement(sql, new String[]{"UUID"});
stmt.setString(1, ctx.getHostName()); stmt.setString(1, ctx.getHostName());
stmt.setString(2, ctx.getMacAddress()); stmt.setInt(2, ctx.getCarbonServerPort());
stmt.setInt(3, ctx.getCarbonServerPort());
resultSet = stmt.executeQuery(); resultSet = stmt.executeQuery();
if (resultSet.next()){ if (resultSet.next()){
@ -109,7 +107,7 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while retrieving meta information for heart beat event from " + throw new HeartBeatDAOException("Error occurred while retrieving meta information for heart beat event from " +
"mac '" + ctx.getMacAddress() + "' " + "port '" + ctx.getCarbonServerPort() + "' " +
"hostname : '" + ctx.getHostName() + "' ", e); "hostname : '" + ctx.getHostName() + "' ", e);
} finally { } finally {
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet);
@ -124,7 +122,7 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
Map<String, ServerContext> ctxList = new HashMap<>(); Map<String, ServerContext> ctxList = new HashMap<>();
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql = "SELECT (@row_number:=@row_number + 1) AS IDX, UUID, HOST_NAME, MAC, SERVER_PORT from " + String sql = "SELECT (@row_number:=@row_number + 1) AS IDX, UUID, HOST_NAME, SERVER_PORT from " +
"SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " + "SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " +
"WHERE LAST_UPDATED_TIMESTAMP > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL ? SECOND) " + "WHERE LAST_UPDATED_TIMESTAMP > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL ? SECOND) " +
"ORDER BY UUID"; "ORDER BY UUID";

@ -85,7 +85,6 @@ public final class HeartBeatBeaconDAOUtil {
ctx.setIndex(resultSet.getInt("IDX")); ctx.setIndex(resultSet.getInt("IDX"));
ctx.setUuid(resultSet.getString("UUID")); ctx.setUuid(resultSet.getString("UUID"));
ctx.setHostName(resultSet.getString("HOST_NAME")); ctx.setHostName(resultSet.getString("HOST_NAME"));
ctx.setMacAddress(resultSet.getString("MAC"));
ctx.setCarbonServerPort(resultSet.getInt("SERVER_PORT")); ctx.setCarbonServerPort(resultSet.getInt("SERVER_PORT"));
return ctx; return ctx;
} }

@ -21,7 +21,6 @@ package io.entgra.server.bootup.heartbeat.beacon.dto;
public class ServerContext { public class ServerContext {
private String hostName; private String hostName;
private String macAddress;
private int carbonServerPort; private int carbonServerPort;
private String uuid; private String uuid;
private int index; private int index;
@ -34,14 +33,6 @@ public class ServerContext {
this.hostName = hostName; this.hostName = hostName;
} }
public String getMacAddress() {
return macAddress;
}
public void setMacAddress(String macAddress) {
this.macAddress = macAddress;
}
public String getUuid() { public String getUuid() {
return uuid; return uuid;
} }

@ -27,10 +27,17 @@ import io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementServi
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.ndatasource.core.DataSourceService;
/** /**
* @scr.component name="io.entgra.server.bootup.heartbeat.beacon.heartbeatBeaconComponent" * @scr.component name="io.entgra.server.bootup.heartbeat.beacon.heartbeatBeaconComponent"
* immediate="true" * immediate="true"
* @scr.reference name="org.wso2.carbon.ndatasource"
* interface="org.wso2.carbon.ndatasource.core.DataSourceService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDataSourceService"
* unbind="unsetDataSourceService"
*/ */
public class HeartBeatBeaconComponent { public class HeartBeatBeaconComponent {
@ -42,21 +49,24 @@ public class HeartBeatBeaconComponent {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing email sender core bundle"); log.debug("Initializing email sender core bundle");
} }
this.registerHeartBeatServices(componentContext);
//heart beat notifier configuration */ //heart beat notifier configuration */
HeartBeatBeaconConfig.init(); HeartBeatBeaconConfig.init();
DataSourceConfig dsConfig = HeartBeatBeaconConfig.getInstance().getDataSourceConfig();
HeartBeatBeaconDAOFactory.init(dsConfig);
this.registerHeartBeatServices(componentContext); if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
DataSourceConfig dsConfig = HeartBeatBeaconConfig.getInstance().getDataSourceConfig();
HeartBeatBeaconDAOFactory.init(dsConfig);
//Setting up executors to notify heart beat status */ //Setting up executors to notify heart beat status */
HeartBeatInternalUtils.setUpNotifiers(HeartBeatBeaconUtils.getServerDetails()); HeartBeatInternalUtils.setUpNotifiers(HeartBeatBeaconUtils.getServerDetails());
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Email sender core bundle has been successfully initialized"); log.debug("Heart Beat Notifier bundle has been successfully initialized");
} }
} catch (Throwable e) { } catch (Throwable e) {
log.error("Error occurred while initializing email sender core bundle", e); log.error("Error occurred while initializing Heart Beat Notifier bundle", e);
} }
} }
@ -74,4 +84,16 @@ public class HeartBeatBeaconComponent {
componentContext.getBundleContext().registerService(HeartBeatManagementService.class, heartBeatServiceProvider, null); componentContext.getBundleContext().registerService(HeartBeatManagementService.class, heartBeatServiceProvider, null);
} }
protected void setDataSourceService(DataSourceService dataSourceService) {
/* This is to avoid mobile device management component getting initialized before the underlying datasources
are registered */
if (log.isDebugEnabled()) {
log.debug("Data source service set to mobile service component");
}
}
protected void unsetDataSourceService(DataSourceService dataSourceService) {
//do nothing
}
} }

@ -20,6 +20,7 @@ package io.entgra.server.bootup.heartbeat.beacon.internal;
import io.entgra.server.bootup.heartbeat.beacon.config.HeartBeatBeaconConfig; import io.entgra.server.bootup.heartbeat.beacon.config.HeartBeatBeaconConfig;
import io.entgra.server.bootup.heartbeat.beacon.HeartBeatBeaconConfigurationException; import io.entgra.server.bootup.heartbeat.beacon.HeartBeatBeaconConfigurationException;
import io.entgra.server.bootup.heartbeat.beacon.dao.HeartBeatBeaconDAOFactory;
import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent; import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent;
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.exception.HeartBeatManagementException; import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException;
@ -66,7 +67,7 @@ public class HeartBeatInternalUtils {
CONFIG.getNotifierFrequency() != 0 ? CONFIG.getNotifierFrequency() : DEFAULT__NOTIFIER_INTERVAL, CONFIG.getNotifierFrequency() != 0 ? CONFIG.getNotifierFrequency() : DEFAULT__NOTIFIER_INTERVAL,
TimeUnit.SECONDS); TimeUnit.SECONDS);
} catch (HeartBeatManagementException e) { } catch (HeartBeatManagementException e) {
throw new HeartBeatBeaconConfigurationException("Error occured while updating initial server context."); throw new HeartBeatBeaconConfigurationException("Error occured while updating initial server context.", e);
} }
} }

@ -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,30 +40,35 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
int hashIndex = -1; int hashIndex = -1;
ServerContext localServerCtx = null; ServerContext localServerCtx = null;
ServerCtxInfo serverCtxInfo = null; ServerCtxInfo serverCtxInfo = null;
try { if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
HeartBeatBeaconDAOFactory.openConnection(); try {
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO(); HeartBeatBeaconDAOFactory.openConnection();
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
int timeOutIntervalInSeconds = HeartBeatBeaconConfig.getInstance().getServerTimeOutIntervalInSeconds(); int timeOutIntervalInSeconds = HeartBeatBeaconConfig.getInstance().getServerTimeOutIntervalInSeconds();
int timeSkew = HeartBeatBeaconConfig.getInstance().getTimeSkew(); int timeSkew = HeartBeatBeaconConfig.getInstance().getTimeSkew();
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();
serverCtxInfo = new ServerCtxInfo(serverCtxMap.size(), hashIndex); serverCtxInfo = new ServerCtxInfo(serverCtxMap.size(), hashIndex);
}
} }
} 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 occurred while retrieving active server count.";
throw new HeartBeatManagementException(msg, e);
} finally {
HeartBeatBeaconDAOFactory.closeConnection();
} }
} catch (SQLException e) { } else {
String msg = "Error occurred while opening a connection to the underlying data source"; String msg = "Heart Beat Configuration Disabled. Server Context Information Not available.";
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg);
} catch (HeartBeatDAOException e) {
String msg = "Error occurred while retrieving active server count.";
throw new HeartBeatManagementException(msg, e);
} finally {
HeartBeatBeaconDAOFactory.closeConnection();
} }
return serverCtxInfo; return serverCtxInfo;
} }
@ -71,22 +77,29 @@ 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;
try { if(HeartBeatBeaconConfig.getInstance().isEnabled()) {
HeartBeatBeaconDAOFactory.openConnection(); try {
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO(); HeartBeatBeaconDAOFactory.beginTransaction();
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 (HeartBeatDAOException e) {
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();
} }
} catch (SQLException e) { } else {
String msg = "Error occurred while opening a connection to the underlying data source"; String msg = "Heart Beat Configuration Disabled. Updating Server Context Failed.";
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg);
} catch (HeartBeatDAOException e) {
String msg = "Error Occured while retrieving active server count.";
throw new HeartBeatManagementException(msg, e);
} finally {
HeartBeatBeaconDAOFactory.closeConnection();
} }
return uuid; return uuid;
} }
@ -96,18 +109,26 @@ 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;
try { if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
HeartBeatBeaconDAOFactory.openConnection(); try {
heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO(); HeartBeatBeaconDAOFactory.beginTransaction();
operationSuccess = heartBeatDAO.recordHeatBeat(event); heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
} catch (SQLException e) { operationSuccess = heartBeatDAO.recordHeatBeat(event);
String msg = "Error occurred while opening a connection to the underlying data source"; HeartBeatBeaconDAOFactory.commitTransaction();
throw new HeartBeatManagementException(msg, e); } catch (HeartBeatDAOException e) {
} catch (HeartBeatDAOException e) { String msg = "Error occurred while recording heart beat.";
String msg = "Error Occured while retrieving active server count."; throw new HeartBeatManagementException(msg, e);
throw new HeartBeatManagementException(msg, e); } catch (TransactionManagementException e) {
} finally { HeartBeatBeaconDAOFactory.rollbackTransaction();
HeartBeatBeaconDAOFactory.closeConnection(); 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; return operationSuccess;
} }

@ -87,7 +87,6 @@
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -115,42 +114,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<!-- Creating Heart Beat Management schema -->
<id>create-heart-beat-mgt-schema</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo message="########### Create Heart Beat Management H2 Schema ###########" />
<property name="db.dir" value="target/maven-shared-archive-resources/database" />
<property name="userid" value="wso2carbon" />
<property name="password" value="wso2carbon" />
<property name="dbURL" value="jdbc:h2:file:${basedir}/${db.dir}/HeartBeat_DB;DB_CLOSE_ON_EXIT=FALSE" />
<mkdir dir="${basedir}/${db.dir}" />
<sql driver="org.h2.Driver" url="${dbURL}" userid="${userid}" password="${password}" autocommit="true" onerror="continue">
<classpath refid="maven.dependency.classpath" />
<classpath refid="maven.compile.classpath" />
<classpath refid="maven.runtime.classpath" />
<fileset file="${basedir}/src/main/resources/dbscripts/heart-beat/h2.sql" />
</sql>
<echo message="##################### END ####################" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.wso2.maven</groupId> <groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId> <artifactId>carbon-p2-plugin</artifactId>

@ -19,9 +19,10 @@
--> -->
<HeartBeatBeaconConfig> <HeartBeatBeaconConfig>
<DataSourceConfiguration type="heart-beat"> <Enable>true</Enable>
<DataSourceConfiguration>
<JndiLookupDefinition> <JndiLookupDefinition>
<Name>jdbc/ServerHeartBeat_DS</Name> <Name>jdbc/HeartBeat_DS</Name>
</JndiLookupDefinition> </JndiLookupDefinition>
</DataSourceConfiguration> </DataSourceConfiguration>
<NotifierInitialDelayInSeconds>30</NotifierInitialDelayInSeconds> <NotifierInitialDelayInSeconds>30</NotifierInitialDelayInSeconds>

@ -16,25 +16,23 @@
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<datasources-configuration xmlns:svns="http://org.wso2.securevault/configuration">
<datasources-configuration>
<providers> <providers>
<provider>org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader</provider> <provider>org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader</provider>
</providers> </providers>
<datasources> <datasources>
<datasource> <datasource>
<name>jdbc/ServerHeartBeat_DS</name> <name>HeartBeat_DS</name>
<description>The datasource used for recording server Heart Beats</description> <description>The datasource Server Heart Beat</description>
<jndiConfig> <jndiConfig>
<name>jdbc/ServerHeartBeat_DS</name> <name>jdbc/HeartBeat_DS</name>
</jndiConfig> </jndiConfig>
<definition type="RDBMS"> <definition type="RDBMS">
<configuration> <configuration>
<url>jdbc:h2:repository/database/HeartBeat_DB;DB_CLOSE_ON_EXIT=FALSE</url> <url>jdbc:mysql://localhost:3306/heart_beat</url>
<username>wso2carbon</username> <username>root</username>
<password>wso2carbon</password> <password>root</password>
<driverClassName>org.h2.Driver</driverClassName> <driverClassName>com.mysql.jdbc.Driver</driverClassName>
<maxActive>50</maxActive> <maxActive>50</maxActive>
<maxWait>60000</maxWait> <maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow> <testOnBorrow>true</testOnBorrow>

@ -4,7 +4,6 @@
CREATE TABLE IF NOT EXISTS SERVER_HEART_BEAT_EVENTS ( CREATE TABLE IF NOT EXISTS SERVER_HEART_BEAT_EVENTS (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
HOST_NAME VARCHAR(100) NOT NULL, HOST_NAME VARCHAR(100) NOT NULL,
MAC VARCHAR(100) NOT NULL,
UUID VARCHAR(100) NOT NULL, UUID VARCHAR(100) NOT NULL,
SERVER_PORT INTEGER NOT NULL, SERVER_PORT INTEGER NOT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

@ -6,7 +6,6 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[S
CREATE TABLE SERVER_HEART_BEAT_EVENTS ( CREATE TABLE SERVER_HEART_BEAT_EVENTS (
ID INT NOT NULL AUTO_INCREMENT, ID INT NOT NULL AUTO_INCREMENT,
HOST_NAME VARCHAR(100) NOT NULL, HOST_NAME VARCHAR(100) NOT NULL,
MAC VARCHAR(100) NOT NULL,
UUID VARCHAR(100) NOT NULL, UUID VARCHAR(100) NOT NULL,
SERVER_PORT INT NOT NULL, SERVER_PORT INT NOT NULL,
LAST_UPDATED_TIMESTAMP DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, LAST_UPDATED_TIMESTAMP DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,

@ -4,7 +4,6 @@
CREATE TABLE IF NOT EXISTS SERVER_HEART_BEAT_EVENTS ( CREATE TABLE IF NOT EXISTS SERVER_HEART_BEAT_EVENTS (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
HOST_NAME VARCHAR(100) NOT NULL, HOST_NAME VARCHAR(100) NOT NULL,
MAC VARCHAR(100) NOT NULL,
UUID VARCHAR(100) NOT NULL, UUID VARCHAR(100) NOT NULL,
SERVER_PORT INTEGER NOT NULL, SERVER_PORT INTEGER NOT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

@ -5,7 +5,6 @@
CREATE TABLE SERVER_HEART_BEAT_EVENTS ( CREATE TABLE SERVER_HEART_BEAT_EVENTS (
ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL, ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL,
HOST_NAME VARCHAR(100) NOT NULL, HOST_NAME VARCHAR(100) NOT NULL,
MAC VARCHAR(100) NOT NULL,
UUID VARCHAR(100) NOT NULL, UUID VARCHAR(100) NOT NULL,
SERVER_PORT INTEGER NOT NULL, SERVER_PORT INTEGER NOT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,

@ -4,7 +4,6 @@
CREATE TABLE IF NOT EXISTS SERVER_HEART_BEAT_EVENTS ( CREATE TABLE IF NOT EXISTS SERVER_HEART_BEAT_EVENTS (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
HOST_NAME VARCHAR(100) NOT NULL, HOST_NAME VARCHAR(100) NOT NULL,
MAC VARCHAR(100) NOT NULL,
UUID VARCHAR(100) NOT NULL, UUID VARCHAR(100) NOT NULL,
SERVER_PORT INTEGER NOT NULL, SERVER_PORT INTEGER NOT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

@ -1,11 +1,8 @@
instructions.configure = \ instructions.configure = \
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/datasources/,target:${installFolder}/../../../conf/datasources/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/datasources/,target:${installFolder}/../../conf/datasources/,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/conf/heart-beat-config.xml,target:${installFolder}/../../../conf/heart-beat-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/conf/heart-beat-config.xml,target:${installFolder}/../../conf/heart-beat-config.xml,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/dbscripts/heart-beat/,target:${installFolder}/../../../dbscripts/heart-beat,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/dbscripts/heart-beat/,target:${installFolder}/../../../dbscripts/heart-beat,overwrite:true);\
org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../../repository/database/);\
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.server.heart.beat_${feature.version}/database/,target:${installFolder}/../../../repository/database/,overwrite:true);\
instructions.unconfigure = \ instructions.unconfigure = \
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../conf/datasources/heart-beat-datasources.xml);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../conf/datasources/heart-beat-datasources.xml);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../../dbscripts/heart-beat);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../../dbscripts/heart-beat);\
org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../database/HeartBeat_DB.h2.db);\

Loading…
Cancel
Save