incoorporating review comments

revert-70ac1926
Ace 4 years ago
parent bac6e3ba67
commit 4df57ede61

@ -298,11 +298,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
} }
activityList.setList(activities); activityList.setList(activities);
activityList.setCount(count); activityList.setCount(count);
// if (activities == null || activities.size() == 0) {
// if (isIfModifiedSinceSet) {
// return Response.notModified().build();
// }
// }
return Response.ok().entity(activityList).build(); return Response.ok().entity(activityList).build();
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg String msg

@ -797,13 +797,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
@Override @Override
public List<Device> getAllocatedDevices(String type, int tenantId, int activeServerCount, int serverIndex) throws DeviceManagementDAOException { public List<Device> getAllocatedDevices(String type, int tenantId, int activeServerCount,
Connection conn; int serverIndex) throws DeviceManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
List<Device> devices = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); Connection conn = this.getConnection();
String sql = "SELECT d1.ID AS DEVICE_ID," + String sql = "SELECT d1.ID AS DEVICE_ID," +
" d1.DESCRIPTION," + " d1.DESCRIPTION," +
" d1.NAME AS DEVICE_NAME," + " d1.NAME AS DEVICE_NAME," +
@ -832,24 +830,31 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
" AND MOD(d1.ID, ?) = ? " + " AND MOD(d1.ID, ?) = ? " +
"ORDER BY e.DATE_OF_LAST_UPDATE DESC"; "ORDER BY e.DATE_OF_LAST_UPDATE DESC";
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, type); stmt.setString(1, type);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setInt(4, activeServerCount); stmt.setInt(4, activeServerCount);
stmt.setInt(5, serverIndex); stmt.setInt(5, serverIndex);
rs = stmt.executeQuery();
devices = new ArrayList<>(); devices = new ArrayList<>();
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) { while (rs.next()) {
Device device = DeviceManagementDAOUtil.loadActiveDevice(rs, false); Device device = DeviceManagementDAOUtil.loadActiveDevice(rs, false);
if (device != null) { if (device != null) {
devices.add(device); devices.add(device);
} }
} }
} catch (Exception e) {
log.error("Error encountered while populating allocated active devices for server with index : " + serverIndex +
" active-server-count " + activeServerCount + " device-type " + type + " tenant-id " + tenantId);
throw new DeviceManagementDAOException("Error occurred while populating active devices '" + type + "'", e);
}
}
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error encountered while retrieving allocated devices for server with index : " + serverIndex +
" active-server-count " + activeServerCount + " device-type " + type + " tenant-id " + tenantId);
throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e); throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return devices; return devices;
} }

@ -165,6 +165,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
} }
} }
@Override
public List<Device> getAllocatedDevices(PaginationRequest request, int tenantId, public List<Device> getAllocatedDevices(PaginationRequest request, int tenantId,
int activeServerCount, int serverIndex) int activeServerCount, int serverIndex)
throws DeviceManagementDAOException { throws DeviceManagementDAOException {

@ -18,6 +18,8 @@
*/ */
package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl; package org.wso2.carbon.device.mgt.core.operation.mgt.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
@ -39,6 +41,8 @@ import java.util.Map;
public class OperationMappingDAOImpl implements OperationMappingDAO { public class OperationMappingDAOImpl implements OperationMappingDAO {
private static final Log log = LogFactory.getLog(OperationMappingDAOImpl.class);
@Override @Override
public void addOperationMapping(Operation operation, Integer deviceId, boolean isScheduled, Device device, Integer tenantId) throws public void addOperationMapping(Operation operation, Integer deviceId, boolean isScheduled, Device device, Integer tenantId) throws
OperationManagementDAOException { OperationManagementDAOException {
@ -228,11 +232,10 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
} }
@Override @Override
public List<OperationEnrolmentMapping> getFirstPendingOperationMappingsForActiveEnrolments(long minDuration, public List<OperationEnrolmentMapping> getFirstPendingOperationMappingsForActiveEnrolments(
long minDuration,
long maxDuration, int deviceTypeId, long maxDuration, int deviceTypeId,
int activeServerCount, int serverHashIndex) throws OperationManagementDAOException { int activeServerCount, int serverHashIndex) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
List<OperationEnrolmentMapping> enrolmentOperationMappingList; List<OperationEnrolmentMapping> enrolmentOperationMappingList;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
@ -242,27 +245,27 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
"AS CREATED_TIMESTAMP, E.STATUS AS ENROLMENT_STATUS, E.TENANT_ID FROM " + "AS CREATED_TIMESTAMP, E.STATUS AS ENROLMENT_STATUS, E.TENANT_ID FROM " +
"DM_ENROLMENT_OP_MAPPING OP INNER JOIN DM_ENROLMENT E ON OP.ENROLMENT_ID = E.ID INNER JOIN " + "DM_ENROLMENT_OP_MAPPING OP INNER JOIN DM_ENROLMENT E ON OP.ENROLMENT_ID = E.ID INNER JOIN " +
"DM_DEVICE D ON E.DEVICE_ID = D.ID WHERE " + "DM_DEVICE D ON E.DEVICE_ID = D.ID WHERE " +
"OP.STATUS IN ('"+ Operation.Status.PENDING.name() + "','" + Operation.Status.REPEATED.name() + "') " + "OP.STATUS IN ('" + Operation.Status.PENDING.name() + "','" + Operation.Status.REPEATED.name() + "') " +
"AND OP.CREATED_TIMESTAMP BETWEEN ? AND ? AND E.STATUS IN ('" + EnrolmentInfo.Status.ACTIVE.name() + "AND OP.CREATED_TIMESTAMP BETWEEN ? AND ? AND E.STATUS IN ('" + EnrolmentInfo.Status.ACTIVE.name() +
"','" + EnrolmentInfo.Status.UNREACHABLE.name() + "') AND D.DEVICE_TYPE_ID = ? AND MOD(D.ID, ?) = ? GROUP BY ENROLMENT_ID," + "','" + EnrolmentInfo.Status.UNREACHABLE.name() + "') AND D.DEVICE_TYPE_ID = ? AND MOD(D.ID, ?) = ? GROUP BY ENROLMENT_ID," +
" D.DEVICE_IDENTIFICATION, E.STATUS, E.TENANT_ID"; " D.DEVICE_IDENTIFICATION, E.STATUS, E.TENANT_ID";
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setLong(1, maxDuration); stmt.setLong(1, maxDuration);
stmt.setLong(2, minDuration); stmt.setLong(2, minDuration);
stmt.setInt(3, deviceTypeId); stmt.setInt(3, deviceTypeId);
stmt.setInt(4, activeServerCount); stmt.setInt(4, activeServerCount);
stmt.setInt(5, serverHashIndex); stmt.setInt(5, serverHashIndex);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
enrolmentOperationMappingList = new ArrayList<>(); enrolmentOperationMappingList = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
OperationEnrolmentMapping enrolmentOperationMapping = this.getEnrolmentOpMapping(rs); OperationEnrolmentMapping enrolmentOperationMapping = this.getEnrolmentOpMapping(rs);
enrolmentOperationMappingList.add(enrolmentOperationMapping); enrolmentOperationMappingList.add(enrolmentOperationMapping);
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while fetching pending operation mappings for " + throw new OperationManagementDAOException("Error occurred while fetching pending operation mappings for " +
"active devices of type '" + deviceTypeId + "'", e); "active devices of type '" + deviceTypeId + "'", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
} }
return enrolmentOperationMappingList; return enrolmentOperationMappingList;
} }
@ -300,9 +303,11 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
} }
@Override @Override
public Map<Integer, Long> getLastConnectedTimeForActiveEnrolments(long timeStamp, int deviceTypeId, int activeServerCount, int serverHashIndex) throws OperationManagementDAOException { public Map<Integer, Long> getLastConnectedTimeForActiveEnrolments(long timeStamp,
PreparedStatement stmt = null; int deviceTypeId,
ResultSet rs = null; int activeServerCount,
int serverHashIndex)
throws OperationManagementDAOException {
Map<Integer, Long> lastConnectedTimeMap = null; Map<Integer, Long> lastConnectedTimeMap = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
@ -314,21 +319,23 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
"OP.STATUS = '" + Operation.Status.COMPLETED.name() + "'" + "OP.STATUS = '" + Operation.Status.COMPLETED.name() + "'" +
"AND OP.UPDATED_TIMESTAMP >= ? AND E.STATUS IN ('" + EnrolmentInfo.Status.ACTIVE.name() + "AND OP.UPDATED_TIMESTAMP >= ? AND E.STATUS IN ('" + EnrolmentInfo.Status.ACTIVE.name() +
"','" + EnrolmentInfo.Status.UNREACHABLE.name() + "') AND D.DEVICE_TYPE_ID = ? AND MOD(D.ID, ?) = ? GROUP BY ENROLMENT_ID"; "','" + EnrolmentInfo.Status.UNREACHABLE.name() + "') AND D.DEVICE_TYPE_ID = ? AND MOD(D.ID, ?) = ? GROUP BY ENROLMENT_ID";
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setLong(1, timeStamp); stmt.setLong(1, timeStamp);
stmt.setInt(2, deviceTypeId); stmt.setInt(2, deviceTypeId);
stmt.setInt(3, activeServerCount); stmt.setInt(3, activeServerCount);
stmt.setInt(4, serverHashIndex); stmt.setInt(4, serverHashIndex);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
lastConnectedTimeMap = new HashMap<>(); lastConnectedTimeMap = new HashMap<>();
while (rs.next()) { while (rs.next()) {
lastConnectedTimeMap.put(rs.getInt("EID"), rs.getLong("LAST_CONNECTED_TIME")); lastConnectedTimeMap.put(rs.getInt("EID"), rs.getLong("LAST_CONNECTED_TIME"));
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while fetching last connected time for " + String msg = "Error occurred while fetching last connected time for " +
"active devices of type '" + deviceTypeId + "'", e); "active devices of type '" + deviceTypeId + "'";
} finally { log.error(msg, e);
OperationManagementDAOUtil.cleanupResources(stmt, rs); throw new OperationManagementDAOException(msg, e);
} }
return lastConnectedTimeMap; return lastConnectedTimeMap;
} }

@ -231,7 +231,7 @@ public class OperationDAOUtil {
if (rs.getBoolean("IS_LARGE_RESPONSE")) { if (rs.getBoolean("IS_LARGE_RESPONSE")) {
largeResponseIDs.add(rs.getInt("OP_RES_ID")); largeResponseIDs.add(rs.getInt("OP_RES_ID"));
} else { } else {
if(activityStatus.getResponses() == null){ if (activityStatus.getResponses() == null) {
List<OperationResponse> operationResponses = new ArrayList<>(); List<OperationResponse> operationResponses = new ArrayList<>();
activityStatus.setResponses(operationResponses); activityStatus.setResponses(operationResponses);
} }

@ -795,7 +795,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving all devices of type '" + String msg = "Error occurred while retrieving all devices of type '" +
deviceType + "' that are being managed within the scope of current tenant"; deviceType + "' that are being managed within the scope of current tenant";
log.error(msg); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source"; String msg = "Error occurred while opening a connection to the data source";

@ -1,3 +1,21 @@
/*
* Copyright (c) 2020, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
*
* Entgra Pvt Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core; package org.wso2.carbon.device.mgt.core;
import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent; import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent;

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
~ ~
~ WSO2 Inc. licenses this file to you under the Apache License, ~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except ~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License. ~ in compliance with the License.
~ You may obtain a copy of the License at ~ You may obtain a copy of the License at
~ ~
~ http://www.apache.org/licenses/LICENSE-2.0 ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~
~ Unless required by applicable law or agreed to in writing, ~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an ~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the ~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@ -31,7 +31,7 @@
<packaging>bundle</packaging> <packaging>bundle</packaging>
<name>Entgra - Heartbeat Beacon</name> <name>Entgra - Heartbeat Beacon</name>
<description>Entgra - Server Startup and Heartbeat Monitoring Component</description> <description>Entgra - Server Startup and Heartbeat Monitoring Component</description>
<url>http://wso2.org</url> <url>http://www.entgra.io</url>
<build> <build>
<plugins> <plugins>

@ -55,8 +55,10 @@ public class HeartBeatBeaconUtils {
DocumentBuilder docBuilder = factory.newDocumentBuilder(); DocumentBuilder docBuilder = factory.newDocumentBuilder();
return docBuilder.parse(file); return docBuilder.parse(file);
} catch (Exception e) { } catch (Exception e) {
throw new HeartBeatBeaconConfigurationException("Error occurred while parsing file, while converting " + String msg = "Error occurred while parsing file, while converting " +
"to a org.w3c.dom.Document", e); "to a org.w3c.dom.Document";
log.error(msg, e);
throw new HeartBeatBeaconConfigurationException(msg, e);
} }
} }
@ -76,7 +78,9 @@ public class HeartBeatBeaconUtils {
final InitialContext context = new InitialContext(jndiProperties); final InitialContext context = new InitialContext(jndiProperties);
return (DataSource) context.doLookup(dataSourceName); return (DataSource) context.doLookup(dataSourceName);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); String msg = "Error in looking up data source: " + e.getMessage();
log.error(msg);
throw new RuntimeException(msg, e);
} }
} }
@ -110,7 +114,11 @@ public class HeartBeatBeaconUtils {
uuid = props.getProperty("server.uuid"); uuid = props.getProperty("server.uuid");
input.close(); input.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
log.info("File : server-credentials.properties does not exist, new UUID will be generated for server."); String msg = "File : server-credentials.properties does not exist, new UUID will be generated for server.";
if(log.isDebugEnabled()){
log.debug(msg, e);
}
log.info(msg);
} catch (IOException e) { } catch (IOException e) {
log.error("Error accessing server-credentials.properties to locate server.uuid.", e); log.error("Error accessing server-credentials.properties to locate server.uuid.", e);
} }

@ -49,7 +49,6 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
@Override @Override
public String recordServerCtx(ServerContext ctx) throws HeartBeatDAOException { public String recordServerCtx(ServerContext ctx) throws HeartBeatDAOException {
PreparedStatement stmt = null;
String uuid = null; String uuid = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
@ -57,167 +56,167 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
String sql; String sql;
sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, UUID, SERVER_PORT) VALUES (?, ?, ?)"; sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, UUID, SERVER_PORT) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, ctx.getHostName()); stmt.setString(1, ctx.getHostName());
stmt.setString(2, serverUUID); stmt.setString(2, serverUUID);
stmt.setInt(3, ctx.getCarbonServerPort()); stmt.setInt(3, ctx.getCarbonServerPort());
if(stmt.executeUpdate() > 0){ if (stmt.executeUpdate() > 0) {
uuid = serverUUID; uuid = serverUUID;
} }
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while persisting server context for : '" + String msg = "Error occurred while persisting server context for : '" +
"port '" + ctx.getCarbonServerPort() + "' " + "port '" + ctx.getCarbonServerPort() + "' " +
"hostname : '" + ctx.getHostName() + "' ", e); "hostname : '" + ctx.getHostName() + "'";
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); throw new HeartBeatDAOException(msg, e);
} }
return uuid; return uuid;
} }
@Override @Override
public boolean recordElectedCandidate(String serverUUID) throws HeartBeatDAOException { public boolean recordElectedCandidate(String serverUUID) throws HeartBeatDAOException {
PreparedStatement stmt = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql; String sql;
sql = "INSERT INTO ELECTED_LEADER_META_INFO(UUID) VALUES (?)"; sql = "INSERT INTO ELECTED_LEADER_META_INFO(UUID) VALUES (?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, serverUUID); stmt.setString(1, serverUUID);
return stmt.executeUpdate() > 0; return stmt.executeUpdate() > 0;
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while persisting UUID of chosen " + String msg = "Error occurred while persisting UUID of chosen " +
"elected dynamic task execution candidate : " + serverUUID , e); "elected dynamic task execution candidate : " + serverUUID;
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); throw new HeartBeatDAOException(msg, e);
} }
} }
@Override @Override
public void purgeCandidates() throws HeartBeatDAOException { public void purgeCandidates() throws HeartBeatDAOException {
Statement stmt = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
String sql = "TRUNCATE TABLE ELECTED_LEADER_META_INFO"; String sql = "TRUNCATE TABLE ELECTED_LEADER_META_INFO";
stmt = conn.createStatement(); try (Statement stmt = conn.createStatement()) {
stmt.execute(sql); stmt.execute(sql);
conn.commit(); conn.commit();
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while truncating ELECTED_LEADER_META_INFO table.", e); String msg = "Error occurred while truncating ELECTED_LEADER_META_INFO table.";
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); throw new HeartBeatDAOException(msg, e);
} }
} }
@Override @Override
public ElectedCandidate retrieveCandidate() throws HeartBeatDAOException { public ElectedCandidate retrieveCandidate() throws HeartBeatDAOException {
Statement stmt = null;
ResultSet resultSet = null;
ElectedCandidate candidate = null; ElectedCandidate candidate = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql = "SELECT * from ELECTED_LEADER_META_INFO"; String sql = "SELECT * from ELECTED_LEADER_META_INFO";
stmt = conn.createStatement();
resultSet = stmt.executeQuery(sql); try (Statement stmt = conn.createStatement()) {
while (resultSet.next()){ try (ResultSet resultSet = stmt.executeQuery(sql)) {
while (resultSet.next()) {
candidate = HeartBeatBeaconDAOUtil.populateCandidate(resultSet); candidate = HeartBeatBeaconDAOUtil.populateCandidate(resultSet);
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while retrieving meta information of elected candidate", e); String msg = "Error occurred while retrieving meta information of elected candidate";
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); throw new HeartBeatDAOException(msg, e);
} }
return candidate; return candidate;
} }
@Override @Override
public boolean acknowledgeTask(String uuid, List<String> taskList) throws HeartBeatDAOException { public boolean acknowledgeTask(String uuid, List<String> taskList)
PreparedStatement stmt = null; throws HeartBeatDAOException {
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql; String sql;
sql = "UPDATE ELECTED_LEADER_META_INFO SET ACKNOWLEDGED_TASK_LIST = ? WHERE UUID = ?"; sql = "UPDATE ELECTED_LEADER_META_INFO SET ACKNOWLEDGED_TASK_LIST = ? WHERE UUID = ?";
stmt = conn.prepareStatement(sql, new String[]{"UUID"});
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"UUID"})) {
stmt.setString(1, String.join(",", taskList)); stmt.setString(1, String.join(",", taskList));
stmt.setString(2, uuid); stmt.setString(2, uuid);
return stmt.executeUpdate() > 0; return stmt.executeUpdate() > 0;
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while updating task list of elected server : '" + String msg = "Error occurred while updating task list of elected server : '" +
uuid + "' and task list " + taskList, e); uuid + "' and task list " + taskList;
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); throw new HeartBeatDAOException(msg, e);
} }
} }
@Override @Override
public boolean recordHeatBeat(HeartBeatEvent event) throws HeartBeatDAOException { public boolean recordHeatBeat(HeartBeatEvent event) throws HeartBeatDAOException {
PreparedStatement stmt = null;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql; String sql;
sql = "UPDATE SERVER_HEART_BEAT_EVENTS SET LAST_UPDATED_TIMESTAMP = ? WHERE UUID = ?"; sql = "UPDATE SERVER_HEART_BEAT_EVENTS SET LAST_UPDATED_TIMESTAMP = ? WHERE UUID = ?";
stmt = conn.prepareStatement(sql, new String[]{"ID"}); try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"ID"})) {
stmt.setTimestamp(1, event.getTime()); stmt.setTimestamp(1, event.getTime());
stmt.setString(2, event.getServerUUID()); stmt.setString(2, event.getServerUUID());
return stmt.executeUpdate() > 0; return stmt.executeUpdate() > 0;
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while updating heartbeat event against server with UUID : '" + String msg = "Error occurred while updating heartbeat event against server with UUID : '" +
event.getServerUUID() + "' and timestamp " + event.getTime(), e); event.getServerUUID() + "' and timestamp " + event.getTime();
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); throw new HeartBeatDAOException(msg, e);
} }
} }
@Override @Override
public boolean checkUUIDValidity(String uuid) throws HeartBeatDAOException { public boolean checkUUIDValidity(String uuid) throws HeartBeatDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
boolean result = false; boolean result = false;
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
String sql = "SELECT ID FROM SERVER_HEART_BEAT_EVENTS WHERE UUID = ?"; String sql = "SELECT ID FROM SERVER_HEART_BEAT_EVENTS WHERE UUID = ?";
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, uuid); stmt.setString(1, uuid);
try (ResultSet resultSet = stmt.executeQuery()) {
resultSet = stmt.executeQuery(); if (resultSet.next()) {
if(resultSet.next()){
result = true; result = true;
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred checking existense of UUID" + uuid + String msg = "Error occurred checking existense of UUID" + uuid +
" amongst heartbeat meta info ", e); " amongst heartbeat meta info.";
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); throw new HeartBeatDAOException(msg, e);
} }
return result; return result;
} }
@Override @Override
public String retrieveExistingServerCtx(ServerContext ctx) throws HeartBeatDAOException { public String retrieveExistingServerCtx(ServerContext ctx) throws HeartBeatDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
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 SERVER_PORT = ?"; String sql = "SELECT UUID FROM SERVER_HEART_BEAT_EVENTS WHERE HOST_NAME = ? AND SERVER_PORT = ?";
stmt = conn.prepareStatement(sql, new String[]{"UUID"});
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"UUID"})) {
stmt.setString(1, ctx.getHostName()); stmt.setString(1, ctx.getHostName());
stmt.setInt(2, ctx.getCarbonServerPort()); stmt.setInt(2, ctx.getCarbonServerPort());
try (ResultSet resultSet = stmt.executeQuery()) {
resultSet = stmt.executeQuery(); if (resultSet.next()) {
if (resultSet.next()){
uuid = resultSet.getString("UUID"); uuid = resultSet.getString("UUID");
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while retrieving meta information for heart beat event from " + String msg = "Error occurred while retrieving meta information for heart beat event from " +
"port '" + ctx.getCarbonServerPort() + "' " + "port '" + ctx.getCarbonServerPort() + "' " +
"hostname : '" + ctx.getHostName() + "' ", e); "hostname : '" + ctx.getHostName() + "'";
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); throw new HeartBeatDAOException(msg, e);
} }
return uuid; return uuid;
} }
@ -225,8 +224,6 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
@Override @Override
public Map<String, ServerContext> getActiveServerDetails(int elapsedTimeInSeconds) public Map<String, ServerContext> getActiveServerDetails(int elapsedTimeInSeconds)
throws HeartBeatDAOException { throws HeartBeatDAOException {
PreparedStatement stmt = null;
ResultSet resultSet = null;
Map<String, ServerContext> ctxList = new HashMap<>(); Map<String, ServerContext> ctxList = new HashMap<>();
try { try {
Connection conn = HeartBeatBeaconDAOFactory.getConnection(); Connection conn = HeartBeatBeaconDAOFactory.getConnection();
@ -234,17 +231,19 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
"SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " + "SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " +
"WHERE LAST_UPDATED_TIMESTAMP > ? " + "WHERE LAST_UPDATED_TIMESTAMP > ? " +
"ORDER BY UUID"; "ORDER BY UUID";
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds))); stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)));
resultSet = stmt.executeQuery(); try (ResultSet resultSet = stmt.executeQuery()) {
while (resultSet.next()) { while (resultSet.next()) {
ctxList.put(resultSet.getString("UUID"), HeartBeatBeaconDAOUtil.populateContext(resultSet)); ctxList.put(resultSet.getString("UUID"), HeartBeatBeaconDAOUtil.populateContext(resultSet));
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new HeartBeatDAOException("Error occurred while retrieving acting server count with " + String msg = "Error occurred while retrieving acting server count with " +
"heartbeat updates within " + elapsedTimeInSeconds + " seconds.", e); "heartbeat updates within " + elapsedTimeInSeconds + " seconds.";
} finally { log.error(msg, e);
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); throw new HeartBeatDAOException(msg, e);
} }
return ctxList; return ctxList;
} }

@ -47,13 +47,15 @@ public class HeartBeatExecutor {
ScheduledExecutorService executor = ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor(); Executors.newSingleThreadScheduledExecutor();
if(CONFIG == null){ if (CONFIG == null) {
throw new HeartBeatBeaconConfigurationException("Error while initiating schedule taks for recording heartbeats."); String msg = "Error while initiating schedule taks for recording heartbeats.";
log.error(msg);
throw new HeartBeatBeaconConfigurationException(msg);
} }
try { try {
String uuid = HeartBeatBeaconUtils.readUUID(); String uuid = HeartBeatBeaconUtils.readUUID();
if(uuid == null){ if (uuid == null) {
uuid = HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().updateServerContext(ctx); uuid = HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().updateServerContext(ctx);
HeartBeatBeaconUtils.saveUUID(uuid); HeartBeatBeaconUtils.saveUUID(uuid);
} }
@ -77,9 +79,13 @@ public class HeartBeatExecutor {
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.", e); String msg = "Error occured while updating initial server context.";
log.error(msg);
throw new HeartBeatBeaconConfigurationException(msg, e);
} catch (IOException e) { } catch (IOException e) {
throw new HeartBeatBeaconConfigurationException("Error while persisting UUID of server.", e); String msg = "Error while persisting UUID of server.";
log.error(msg);
throw new HeartBeatBeaconConfigurationException(msg, e);
} }
} }
@ -87,7 +93,8 @@ public class HeartBeatExecutor {
HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().recordHeartBeat(new HeartBeatEvent(uuid)); HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().recordHeartBeat(new HeartBeatEvent(uuid));
} }
static void electDynamicTaskExecutionCandidate(int cumilativeTimeOut) throws HeartBeatManagementException { static void electDynamicTaskExecutionCandidate(int cumilativeTimeOut)
throws HeartBeatManagementException {
HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().electCandidate(cumilativeTimeOut); HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().electCandidate(cumilativeTimeOut);
} }

@ -18,7 +18,6 @@
package io.entgra.server.bootup.heartbeat.beacon.service; package io.entgra.server.bootup.heartbeat.beacon.service;
import io.entgra.server.bootup.heartbeat.beacon.dto.ElectedCandidate;
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;

@ -47,7 +47,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
private final HeartBeatDAO heartBeatDAO; private final HeartBeatDAO heartBeatDAO;
public HeartBeatManagementServiceImpl(){ public HeartBeatManagementServiceImpl() {
this.heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO(); this.heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO();
} }
@ -57,7 +57,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()) { if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
try { try {
HeartBeatBeaconDAOFactory.openConnection(); HeartBeatBeaconDAOFactory.openConnection();
int timeOutIntervalInSeconds = HeartBeatBeaconConfig.getInstance().getServerTimeOutIntervalInSeconds(); int timeOutIntervalInSeconds = HeartBeatBeaconConfig.getInstance().getServerTimeOutIntervalInSeconds();
@ -74,9 +74,11 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
} }
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while opening a connection to the underlying data source"; String msg = "Error occurred while opening a connection to the underlying data source";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {
String msg = "Error occurred while retrieving active server count."; String msg = "Error occurred while retrieving active server count.";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} finally { } finally {
HeartBeatBeaconDAOFactory.closeConnection(); HeartBeatBeaconDAOFactory.closeConnection();
@ -91,10 +93,11 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
@Override @Override
public boolean isTaskPartitioningEnabled() throws HeartBeatManagementException { public boolean isTaskPartitioningEnabled() throws HeartBeatManagementException {
boolean enabled = false; boolean enabled = false;
if(HeartBeatBeaconConfig.getInstance() != null){ if (HeartBeatBeaconConfig.getInstance() != null) {
enabled = HeartBeatBeaconConfig.getInstance().isEnabled(); enabled = HeartBeatBeaconConfig.getInstance().isEnabled();
} else { } else {
String msg = "Issue instantiating heart beat config."; String msg = "Issue instantiating heart beat config.";
log.error(msg);
throw new HeartBeatManagementException(msg); throw new HeartBeatManagementException(msg);
} }
return enabled; return enabled;
@ -104,7 +107,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
@Override @Override
public String updateServerContext(ServerContext ctx) throws HeartBeatManagementException { public String updateServerContext(ServerContext ctx) throws HeartBeatManagementException {
String uuid = null; String uuid = null;
if(HeartBeatBeaconConfig.getInstance().isEnabled()) { if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
try { try {
HeartBeatBeaconDAOFactory.beginTransaction(); HeartBeatBeaconDAOFactory.beginTransaction();
uuid = heartBeatDAO.retrieveExistingServerCtx(ctx); uuid = heartBeatDAO.retrieveExistingServerCtx(ctx);
@ -114,10 +117,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
} }
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {
String msg = "Error Occured while retrieving server context."; String msg = "Error Occured while retrieving server context.";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
HeartBeatBeaconDAOFactory.rollbackTransaction(); HeartBeatBeaconDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating server context. Issue in opening a connection to the underlying data source"; String msg = "Error occurred while updating server context. Issue in opening a connection to the underlying data source";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} finally { } finally {
HeartBeatBeaconDAOFactory.closeConnection(); HeartBeatBeaconDAOFactory.closeConnection();
@ -132,22 +137,24 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
@Override @Override
public boolean isQualifiedToExecuteTask() throws HeartBeatManagementException { public boolean isQualifiedToExecuteTask() throws HeartBeatManagementException {
boolean isQualified = false; boolean isQualified = false;
if(HeartBeatBeaconConfig.getInstance().isEnabled()) { if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
try { try {
String localServerUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID(); String localServerUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID();
HeartBeatBeaconDAOFactory.openConnection(); HeartBeatBeaconDAOFactory.openConnection();
ElectedCandidate candidate = heartBeatDAO.retrieveCandidate(); ElectedCandidate candidate = heartBeatDAO.retrieveCandidate();
if(candidate != null && candidate.getServerUUID().equalsIgnoreCase(localServerUUID)){ if (candidate != null && candidate.getServerUUID().equalsIgnoreCase(localServerUUID)) {
isQualified = true; isQualified = true;
if(log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("Node : " + localServerUUID + " Qualified to execute randomly assigned task."); log.debug("Node : " + localServerUUID + " Qualified to execute randomly assigned task.");
} }
} }
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {
String msg = "Error occurred while checking if server is qualified to execute randomly designated task."; String msg = "Error occurred while checking if server is qualified to execute randomly designated task.";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while opening a connection to the underlying data source"; String msg = "Error occurred while opening a connection to the underlying data source";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} finally { } finally {
HeartBeatBeaconDAOFactory.closeConnection(); HeartBeatBeaconDAOFactory.closeConnection();
@ -160,23 +167,24 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
} }
@Override @Override
public boolean updateTaskExecutionAcknowledgement(String newTask) throws HeartBeatManagementException { public boolean updateTaskExecutionAcknowledgement(String newTask)
throws HeartBeatManagementException {
boolean result = false; boolean result = false;
if(HeartBeatBeaconConfig.getInstance().isEnabled()) { if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
try { try {
String serverUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID(); String serverUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID();
HeartBeatBeaconDAOFactory.beginTransaction(); HeartBeatBeaconDAOFactory.beginTransaction();
ElectedCandidate candidate = heartBeatDAO.retrieveCandidate(); ElectedCandidate candidate = heartBeatDAO.retrieveCandidate();
if(candidate != null && candidate.getServerUUID().equals(serverUUID)){ if (candidate != null && candidate.getServerUUID().equals(serverUUID)) {
List<String> taskList = candidate.getAcknowledgedTaskList(); List<String> taskList = candidate.getAcknowledgedTaskList();
boolean taskExecuted = false; boolean taskExecuted = false;
for(String task : taskList){ for (String task : taskList) {
if(task.equalsIgnoreCase(newTask)){ if (task.equalsIgnoreCase(newTask)) {
taskExecuted = true; taskExecuted = true;
break; break;
} }
} }
if(!taskExecuted) { if (!taskExecuted) {
taskList.add(newTask); taskList.add(newTask);
result = heartBeatDAO.acknowledgeTask(serverUUID, taskList); result = heartBeatDAO.acknowledgeTask(serverUUID, taskList);
HeartBeatBeaconDAOFactory.commitTransaction(); HeartBeatBeaconDAOFactory.commitTransaction();
@ -184,10 +192,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
} }
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {
String msg = "Error occurred while updating acknowledged task."; String msg = "Error occurred while updating acknowledged task.";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
HeartBeatBeaconDAOFactory.rollbackTransaction(); HeartBeatBeaconDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating acknowledged task.. Issue in opening a connection to the underlying data source"; String msg = "Error occurred while updating acknowledged task.. Issue in opening a connection to the underlying data source";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} finally { } finally {
HeartBeatBeaconDAOFactory.closeConnection(); HeartBeatBeaconDAOFactory.closeConnection();
@ -223,10 +233,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
} }
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {
String msg = "Error occurred while electing candidate for dynamic task execution."; String msg = "Error occurred while electing candidate for dynamic task execution.";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
HeartBeatBeaconDAOFactory.rollbackTransaction(); HeartBeatBeaconDAOFactory.rollbackTransaction();
String msg = "Error occurred while electing candidate for dynamic task execution. Issue in opening a connection to the underlying data source"; String msg = "Error occurred while electing candidate for dynamic task execution. Issue in opening a connection to the underlying data source";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} finally { } finally {
HeartBeatBeaconDAOFactory.closeConnection(); HeartBeatBeaconDAOFactory.closeConnection();
@ -243,8 +255,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
} }
private String getRandomElement(Set<String> valueSet) private String getRandomElement(Set<String> valueSet) {
{
Random rand = new Random(); Random rand = new Random();
List<String> items = new ArrayList<>(valueSet); List<String> items = new ArrayList<>(valueSet);
return items.get(rand.nextInt(items.size())); return items.get(rand.nextInt(items.size()));
@ -257,11 +268,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
if (HeartBeatBeaconConfig.getInstance().isEnabled()) { if (HeartBeatBeaconConfig.getInstance().isEnabled()) {
try { try {
HeartBeatBeaconDAOFactory.beginTransaction(); HeartBeatBeaconDAOFactory.beginTransaction();
if(heartBeatDAO.checkUUIDValidity(event.getServerUUID())){ if (heartBeatDAO.checkUUIDValidity(event.getServerUUID())) {
operationSuccess = heartBeatDAO.recordHeatBeat(event); operationSuccess = heartBeatDAO.recordHeatBeat(event);
HeartBeatBeaconDAOFactory.commitTransaction(); HeartBeatBeaconDAOFactory.commitTransaction();
} else { } else {
String msg = "Server UUID Does not exist, heartbeat not recorded."; String msg = "Server UUID Does not exist, heartbeat not recorded.";
log.error(msg);
throw new HeartBeatManagementException(msg); throw new HeartBeatManagementException(msg);
} }
} catch (HeartBeatDAOException e) { } catch (HeartBeatDAOException e) {
@ -271,12 +283,14 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic
HeartBeatBeaconDAOFactory.rollbackTransaction(); HeartBeatBeaconDAOFactory.rollbackTransaction();
String msg = "Error occurred performing heart beat record transaction. " + String msg = "Error occurred performing heart beat record transaction. " +
"Transaction rolled back."; "Transaction rolled back.";
log.error(msg, e);
throw new HeartBeatManagementException(msg, e); throw new HeartBeatManagementException(msg, e);
} finally { } finally {
HeartBeatBeaconDAOFactory.closeConnection(); HeartBeatBeaconDAOFactory.closeConnection();
} }
} else { } else {
String msg = "Heart Beat Configuration Disabled. Recording Heart Beat Failed."; String msg = "Heart Beat Configuration Disabled. Recording Heart Beat Failed.";
log.error(msg);
throw new HeartBeatManagementException(msg); throw new HeartBeatManagementException(msg);
} }
return operationSuccess; return operationSuccess;

@ -1,5 +1,5 @@
# #
# Copyright 2009 WSO2, Inc. (http://wso2.com) # Copyright 2020 Entgra Pvt. Ltd.. (http://entgra.io)
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -15,7 +15,7 @@
# #
# #
# This is the log4j configuration file used by WSO2 Carbon # This is the log4j configuration file used by Entgra Pvt. Ltd.
# #
# IMPORTANT : Please do not remove or change the names of any # IMPORTANT : Please do not remove or change the names of any
# of the Appenders defined here. The layout pattern & log file # of the Appenders defined here. The layout pattern & log file

@ -1,11 +1,11 @@
<!-- <!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
~ ~
~ WSO2 Inc. licenses this file to you under the Apache License, ~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except ~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License. ~ in compliance with the License.
~ you may obtain a copy of the License at ~ You may obtain a copy of the License at
~ ~
~ http://www.apache.org/licenses/LICENSE-2.0 ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
~ ~
~ WSO2 Inc. licenses this file to you under the Apache License, ~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except ~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License. ~ in compliance with the License.
~ You may obtain a copy of the License at ~ You may obtain a copy of the License at
~ ~
~ http://www.apache.org/licenses/LICENSE-2.0 ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~
~ Unless required by applicable law or agreed to in writing, ~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an ~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the ~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

@ -70,7 +70,7 @@ public class DelegationTask extends DynamicPartitionedScheduleTask {
try { try {
devices = new ArrayList<>(); devices = new ArrayList<>();
toBeNotified = new ArrayList<>(); toBeNotified = new ArrayList<>();
if(super.isDynamicTaskEligible()) { if (super.isDynamicTaskEligible()) {
devices.addAll(service.getAllocatedDevices(deviceType, devices.addAll(service.getAllocatedDevices(deviceType,
super.getTaskContext().getActiveServerCount(), super.getTaskContext().getActiveServerCount(),
super.getTaskContext().getServerHashIndex())); super.getTaskContext().getServerHashIndex()));
@ -82,8 +82,7 @@ public class DelegationTask extends DynamicPartitionedScheduleTask {
&& device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) { && device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) {
toBeNotified.add(device); toBeNotified.add(device);
} }
// } if (log.isDebugEnabled()) {
if(log.isDebugEnabled()){
log.debug("Adding policy operation to device : " + device.getDeviceIdentifier()); log.debug("Adding policy operation to device : " + device.getDeviceIdentifier());
} }
} }

@ -139,7 +139,7 @@ public class MonitoringTask extends DynamicPartitionedScheduleTask {
status.equals(EnrolmentInfo.Status.UNREACHABLE)) { status.equals(EnrolmentInfo.Status.UNREACHABLE)) {
notifiableDevices.add(device); notifiableDevices.add(device);
} }
if(log.isDebugEnabled()){ if (log.isDebugEnabled()) {
log.debug("Adding monitoring operation to device : " + device.getDeviceIdentifier()); log.debug("Adding monitoring operation to device : " + device.getDeviceIdentifier());
} }
} }

@ -1,3 +1,21 @@
/*
* Copyright (c) 2020, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
*
* Entgra Pvt Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.policy.mgt.core.mock; package org.wso2.carbon.policy.mgt.core.mock;
import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent; import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent;

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
~ Copyright (C) 2018 - 2020 Entgra (Pvt) Ltd, Inc - All Rights Reserved. ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
~ ~
~ Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. ~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ ~ Version 2.0 (the "License"); you may not use this file except
~ Licensed under the Entgra Commercial License, Version 1.0 (the "License"); ~ in compliance with the License.
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at ~ You may obtain a copy of the License at
~ ~
~ https://entgra.io/licenses/entgra-commercial/1.0 ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~
~ Unless required by applicable law or agreed to in writing, ~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an ~ software distributed under the License is distributed on an

@ -1,21 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
~ Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
~ ~
~ WSO2 Inc. licenses this file to you under the Apache License, ~ Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
~ Version 2.0 (the "License"); you may not use this file except ~ Version 2.0 (the "License"); you may not use this file except
~ in compliance with the License. ~ in compliance with the License.
~ You may obtain a copy of the License at ~ You may obtain a copy of the License at
~ ~
~ http://www.apache.org/licenses/LICENSE-2.0 ~ http://www.apache.org/licenses/LICENSE-2.0
~ ~
~ Unless required by applicable law or agreed to in writing, ~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an ~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the ~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations ~ specific language governing permissions and limitations
~ under the License. ~ under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@ -32,7 +32,7 @@
<version>4.1.11-SNAPSHOT</version> <version>4.1.11-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Entgra - Heart Beat Feature</name> <name>Entgra - Heart Beat Feature</name>
<url>http://wso2.org</url> <url>http://entgra.io</url>
<modules> <modules>
<module>io.entgra.server.heart.beat.feature</module> <module>io.entgra.server.heart.beat.feature</module>

Loading…
Cancel
Save