diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java index ed4d4edd05f..d0605d54670 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/ActivityProviderServiceImpl.java @@ -298,11 +298,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService } activityList.setList(activities); activityList.setCount(count); -// if (activities == null || activities.size() == 0) { -// if (isIfModifiedSinceSet) { -// return Response.notModified().build(); -// } -// } + return Response.ok().entity(activityList).build(); } catch (OperationManagementException e) { String msg diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index a8fee010df5..996dca889e5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -797,13 +797,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { @Override - public List getAllocatedDevices(String type, int tenantId, int activeServerCount, int serverIndex) throws DeviceManagementDAOException { - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; + public List getAllocatedDevices(String type, int tenantId, int activeServerCount, + int serverIndex) throws DeviceManagementDAOException { List devices = null; try { - conn = this.getConnection(); + Connection conn = this.getConnection(); String sql = "SELECT d1.ID AS DEVICE_ID," + " d1.DESCRIPTION," + " d1.NAME AS DEVICE_NAME," + @@ -832,24 +830,31 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { " AND MOD(d1.ID, ?) = ? " + "ORDER BY e.DATE_OF_LAST_UPDATE DESC"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, type); - stmt.setInt(2, tenantId); - stmt.setInt(3, tenantId); - stmt.setInt(4, activeServerCount); - stmt.setInt(5, serverIndex); - rs = stmt.executeQuery(); - devices = new ArrayList<>(); - while (rs.next()) { - Device device = DeviceManagementDAOUtil.loadActiveDevice(rs, false); - if (device != null) { - devices.add(device); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, type); + stmt.setInt(2, tenantId); + stmt.setInt(3, tenantId); + stmt.setInt(4, activeServerCount); + stmt.setInt(5, serverIndex); + devices = new ArrayList<>(); + + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + Device device = DeviceManagementDAOUtil.loadActiveDevice(rs, false); + if (device != null) { + 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) { + 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); - } finally { - DeviceManagementDAOUtil.cleanupResources(stmt, rs); } return devices; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java index 2cdacdcd210..49522ba74c6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/PostgreSQLDeviceDAOImpl.java @@ -165,6 +165,7 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl { } } + @Override public List getAllocatedDevices(PaginationRequest request, int tenantId, int activeServerCount, int serverIndex) throws DeviceManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java index 10742b5c284..df1ebd7b64c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationMappingDAOImpl.java @@ -18,6 +18,8 @@ */ 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.EnrolmentInfo; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; @@ -39,6 +41,8 @@ import java.util.Map; public class OperationMappingDAOImpl implements OperationMappingDAO { + private static final Log log = LogFactory.getLog(OperationMappingDAOImpl.class); + @Override public void addOperationMapping(Operation operation, Integer deviceId, boolean isScheduled, Device device, Integer tenantId) throws OperationManagementDAOException { @@ -228,11 +232,10 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { } @Override - public List getFirstPendingOperationMappingsForActiveEnrolments(long minDuration, - long maxDuration, int deviceTypeId, - int activeServerCount, int serverHashIndex) throws OperationManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; + public List getFirstPendingOperationMappingsForActiveEnrolments( + long minDuration, + long maxDuration, int deviceTypeId, + int activeServerCount, int serverHashIndex) throws OperationManagementDAOException { List enrolmentOperationMappingList; try { 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 " + "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 " + - "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() + "','" + 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"; - stmt = conn.prepareStatement(sql); - stmt.setLong(1, maxDuration); - stmt.setLong(2, minDuration); - stmt.setInt(3, deviceTypeId); - stmt.setInt(4, activeServerCount); - stmt.setInt(5, serverHashIndex); - rs = stmt.executeQuery(); - enrolmentOperationMappingList = new ArrayList<>(); - while (rs.next()) { - OperationEnrolmentMapping enrolmentOperationMapping = this.getEnrolmentOpMapping(rs); - enrolmentOperationMappingList.add(enrolmentOperationMapping); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setLong(1, maxDuration); + stmt.setLong(2, minDuration); + stmt.setInt(3, deviceTypeId); + stmt.setInt(4, activeServerCount); + stmt.setInt(5, serverHashIndex); + try (ResultSet rs = stmt.executeQuery()) { + enrolmentOperationMappingList = new ArrayList<>(); + while (rs.next()) { + OperationEnrolmentMapping enrolmentOperationMapping = this.getEnrolmentOpMapping(rs); + enrolmentOperationMappingList.add(enrolmentOperationMapping); + } + } } } catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while fetching pending operation mappings for " + "active devices of type '" + deviceTypeId + "'", e); - } finally { - OperationManagementDAOUtil.cleanupResources(stmt, rs); } return enrolmentOperationMappingList; } @@ -300,9 +303,11 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { } @Override - public Map getLastConnectedTimeForActiveEnrolments(long timeStamp, int deviceTypeId, int activeServerCount, int serverHashIndex) throws OperationManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; + public Map getLastConnectedTimeForActiveEnrolments(long timeStamp, + int deviceTypeId, + int activeServerCount, + int serverHashIndex) + throws OperationManagementDAOException { Map lastConnectedTimeMap = null; try { Connection conn = OperationManagementDAOFactory.getConnection(); @@ -314,21 +319,23 @@ public class OperationMappingDAOImpl implements OperationMappingDAO { "OP.STATUS = '" + Operation.Status.COMPLETED.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"; - stmt = conn.prepareStatement(sql); - stmt.setLong(1, timeStamp); - stmt.setInt(2, deviceTypeId); - stmt.setInt(3, activeServerCount); - stmt.setInt(4, serverHashIndex); - rs = stmt.executeQuery(); - lastConnectedTimeMap = new HashMap<>(); - while (rs.next()) { - lastConnectedTimeMap.put(rs.getInt("EID"), rs.getLong("LAST_CONNECTED_TIME")); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setLong(1, timeStamp); + stmt.setInt(2, deviceTypeId); + stmt.setInt(3, activeServerCount); + stmt.setInt(4, serverHashIndex); + try (ResultSet rs = stmt.executeQuery()) { + lastConnectedTimeMap = new HashMap<>(); + while (rs.next()) { + lastConnectedTimeMap.put(rs.getInt("EID"), rs.getLong("LAST_CONNECTED_TIME")); + } + } } } catch (SQLException e) { - throw new OperationManagementDAOException("Error occurred while fetching last connected time for " + - "active devices of type '" + deviceTypeId + "'", e); - } finally { - OperationManagementDAOUtil.cleanupResources(stmt, rs); + String msg = "Error occurred while fetching last connected time for " + + "active devices of type '" + deviceTypeId + "'"; + log.error(msg, e); + throw new OperationManagementDAOException(msg, e); } return lastConnectedTimeMap; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 0d83c755cd6..6e20e1da816 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -231,7 +231,7 @@ public class OperationDAOUtil { if (rs.getBoolean("IS_LARGE_RESPONSE")) { largeResponseIDs.add(rs.getInt("OP_RES_ID")); } else { - if(activityStatus.getResponses() == null){ + if (activityStatus.getResponses() == null) { List operationResponses = new ArrayList<>(); activityStatus.setResponses(operationResponses); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index c260f322234..dba4736e0a9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -795,7 +795,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } catch (DeviceManagementDAOException e) { String msg = "Error occurred while retrieving all devices of type '" + deviceType + "' that are being managed within the scope of current tenant"; - log.error(msg); + log.error(msg, e); throw new DeviceManagementException(msg, e); } catch (SQLException e) { String msg = "Error occurred while opening a connection to the data source"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestHeartBeatManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestHeartBeatManagementService.java index 54dcc96504d..7a974084156 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestHeartBeatManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/TestHeartBeatManagementService.java @@ -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; import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent; diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml index 5cb57f3dfbc..42d318379dd 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml @@ -1,21 +1,21 @@ + ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) 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. + --> @@ -31,7 +31,7 @@ bundle Entgra - Heartbeat Beacon Entgra - Server Startup and Heartbeat Monitoring Component - http://wso2.org + http://www.entgra.io diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconUtils.java b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconUtils.java index 570c6c56c90..ec0ec4c9150 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconUtils.java +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/HeartBeatBeaconUtils.java @@ -55,8 +55,10 @@ public class HeartBeatBeaconUtils { DocumentBuilder docBuilder = factory.newDocumentBuilder(); return docBuilder.parse(file); } catch (Exception e) { - throw new HeartBeatBeaconConfigurationException("Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document", e); + String msg = "Error occurred while parsing file, while converting " + + "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); return (DataSource) context.doLookup(dataSourceName); } 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"); input.close(); } 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) { log.error("Error accessing server-credentials.properties to locate server.uuid.", e); } diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dao/impl/GenericHeartBeatDAOImpl.java b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dao/impl/GenericHeartBeatDAOImpl.java index ae8bbd247fa..ab20bd0f2c1 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dao/impl/GenericHeartBeatDAOImpl.java +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dao/impl/GenericHeartBeatDAOImpl.java @@ -49,7 +49,6 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO { @Override public String recordServerCtx(ServerContext ctx) throws HeartBeatDAOException { - PreparedStatement stmt = null; String uuid = null; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); @@ -57,167 +56,167 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO { String sql; sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, UUID, SERVER_PORT) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); - stmt.setString(1, ctx.getHostName()); - stmt.setString(2, serverUUID); - stmt.setInt(3, ctx.getCarbonServerPort()); - - if(stmt.executeUpdate() > 0){ - uuid = serverUUID; + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, ctx.getHostName()); + stmt.setString(2, serverUUID); + stmt.setInt(3, ctx.getCarbonServerPort()); + + if (stmt.executeUpdate() > 0) { + uuid = serverUUID; + } } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while persisting server context for : '" + - "port '" + ctx.getCarbonServerPort() + "' " + - "hostname : '" + ctx.getHostName() + "' ", e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); + String msg = "Error occurred while persisting server context for : '" + + "port '" + ctx.getCarbonServerPort() + "' " + + "hostname : '" + ctx.getHostName() + "'"; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } return uuid; } @Override public boolean recordElectedCandidate(String serverUUID) throws HeartBeatDAOException { - PreparedStatement stmt = null; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); String sql; sql = "INSERT INTO ELECTED_LEADER_META_INFO(UUID) VALUES (?)"; - stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); - stmt.setString(1, serverUUID); - - return stmt.executeUpdate() > 0; + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, serverUUID); + return stmt.executeUpdate() > 0; + } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while persisting UUID of chosen " + - "elected dynamic task execution candidate : " + serverUUID , e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); + String msg = "Error occurred while persisting UUID of chosen " + + "elected dynamic task execution candidate : " + serverUUID; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } } @Override public void purgeCandidates() throws HeartBeatDAOException { - Statement stmt = null; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); conn.setAutoCommit(false); String sql = "TRUNCATE TABLE ELECTED_LEADER_META_INFO"; - stmt = conn.createStatement(); - stmt.execute(sql); - conn.commit(); + try (Statement stmt = conn.createStatement()) { + stmt.execute(sql); + conn.commit(); + } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while truncating ELECTED_LEADER_META_INFO table.", e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); + String msg = "Error occurred while truncating ELECTED_LEADER_META_INFO table."; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } } @Override public ElectedCandidate retrieveCandidate() throws HeartBeatDAOException { - Statement stmt = null; - ResultSet resultSet = null; ElectedCandidate candidate = null; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); String sql = "SELECT * from ELECTED_LEADER_META_INFO"; - stmt = conn.createStatement(); - resultSet = stmt.executeQuery(sql); - while (resultSet.next()){ - candidate = HeartBeatBeaconDAOUtil.populateCandidate(resultSet); + + try (Statement stmt = conn.createStatement()) { + try (ResultSet resultSet = stmt.executeQuery(sql)) { + while (resultSet.next()) { + candidate = HeartBeatBeaconDAOUtil.populateCandidate(resultSet); + } + } } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while retrieving meta information of elected candidate", e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); + String msg = "Error occurred while retrieving meta information of elected candidate"; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } return candidate; } @Override - public boolean acknowledgeTask(String uuid, List taskList) throws HeartBeatDAOException { - PreparedStatement stmt = null; + public boolean acknowledgeTask(String uuid, List taskList) + throws HeartBeatDAOException { try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); String sql; sql = "UPDATE ELECTED_LEADER_META_INFO SET ACKNOWLEDGED_TASK_LIST = ? WHERE UUID = ?"; - stmt = conn.prepareStatement(sql, new String[]{"UUID"}); - stmt.setString(1, String.join(",", taskList)); - stmt.setString(2, uuid); - return stmt.executeUpdate() > 0; + try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"UUID"})) { + stmt.setString(1, String.join(",", taskList)); + stmt.setString(2, uuid); + return stmt.executeUpdate() > 0; + } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while updating task list of elected server : '" + - uuid + "' and task list " + taskList, e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); + String msg = "Error occurred while updating task list of elected server : '" + + uuid + "' and task list " + taskList; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } } @Override public boolean recordHeatBeat(HeartBeatEvent event) throws HeartBeatDAOException { - PreparedStatement stmt = null; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); String sql; sql = "UPDATE SERVER_HEART_BEAT_EVENTS SET LAST_UPDATED_TIMESTAMP = ? WHERE UUID = ?"; - stmt = conn.prepareStatement(sql, new String[]{"ID"}); - stmt.setTimestamp(1, event.getTime()); - stmt.setString(2, event.getServerUUID()); - - return stmt.executeUpdate() > 0; + try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"ID"})) { + stmt.setTimestamp(1, event.getTime()); + stmt.setString(2, event.getServerUUID()); + return stmt.executeUpdate() > 0; + } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while updating heartbeat event against server with UUID : '" + - event.getServerUUID() + "' and timestamp " + event.getTime(), e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, null); + String msg = "Error occurred while updating heartbeat event against server with UUID : '" + + event.getServerUUID() + "' and timestamp " + event.getTime(); + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } } @Override public boolean checkUUIDValidity(String uuid) throws HeartBeatDAOException { - PreparedStatement stmt = null; - ResultSet resultSet = null; boolean result = false; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); String sql = "SELECT ID FROM SERVER_HEART_BEAT_EVENTS WHERE UUID = ?"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - - resultSet = stmt.executeQuery(); - if(resultSet.next()){ - result = true; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, uuid); + try (ResultSet resultSet = stmt.executeQuery()) { + if (resultSet.next()) { + result = true; + } + } } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred checking existense of UUID" + uuid + - " amongst heartbeat meta info ", e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); + String msg = "Error occurred checking existense of UUID" + uuid + + " amongst heartbeat meta info."; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } return result; } @Override public String retrieveExistingServerCtx(ServerContext ctx) throws HeartBeatDAOException { - PreparedStatement stmt = null; - ResultSet resultSet = null; String uuid = null; try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); String sql = "SELECT UUID FROM SERVER_HEART_BEAT_EVENTS WHERE HOST_NAME = ? AND SERVER_PORT = ?"; - stmt = conn.prepareStatement(sql, new String[]{"UUID"}); - stmt.setString(1, ctx.getHostName()); - stmt.setInt(2, ctx.getCarbonServerPort()); - resultSet = stmt.executeQuery(); - if (resultSet.next()){ - uuid = resultSet.getString("UUID"); + try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"UUID"})) { + stmt.setString(1, ctx.getHostName()); + stmt.setInt(2, ctx.getCarbonServerPort()); + try (ResultSet resultSet = stmt.executeQuery()) { + if (resultSet.next()) { + uuid = resultSet.getString("UUID"); + } + } } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while retrieving meta information for heart beat event from " + - "port '" + ctx.getCarbonServerPort() + "' " + - "hostname : '" + ctx.getHostName() + "' ", e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); + String msg = "Error occurred while retrieving meta information for heart beat event from " + + "port '" + ctx.getCarbonServerPort() + "' " + + "hostname : '" + ctx.getHostName() + "'"; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } return uuid; } @@ -225,8 +224,6 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO { @Override public Map getActiveServerDetails(int elapsedTimeInSeconds) throws HeartBeatDAOException { - PreparedStatement stmt = null; - ResultSet resultSet = null; Map ctxList = new HashMap<>(); try { Connection conn = HeartBeatBeaconDAOFactory.getConnection(); @@ -234,17 +231,19 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO { "SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " + "WHERE LAST_UPDATED_TIMESTAMP > ? " + "ORDER BY UUID"; - stmt = conn.prepareStatement(sql); - stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds))); - resultSet = stmt.executeQuery(); - while (resultSet.next()) { - ctxList.put(resultSet.getString("UUID"), HeartBeatBeaconDAOUtil.populateContext(resultSet)); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds))); + try (ResultSet resultSet = stmt.executeQuery()) { + while (resultSet.next()) { + ctxList.put(resultSet.getString("UUID"), HeartBeatBeaconDAOUtil.populateContext(resultSet)); + } + } } } catch (SQLException e) { - throw new HeartBeatDAOException("Error occurred while retrieving acting server count with " + - "heartbeat updates within " + elapsedTimeInSeconds + " seconds.", e); - } finally { - HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet); + String msg = "Error occurred while retrieving acting server count with " + + "heartbeat updates within " + elapsedTimeInSeconds + " seconds."; + log.error(msg, e); + throw new HeartBeatDAOException(msg, e); } return ctxList; } diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/internal/HeartBeatExecutor.java b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/internal/HeartBeatExecutor.java index 1187513daa7..1f0d50539b1 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/internal/HeartBeatExecutor.java +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/internal/HeartBeatExecutor.java @@ -47,13 +47,15 @@ public class HeartBeatExecutor { ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); - if(CONFIG == null){ - throw new HeartBeatBeaconConfigurationException("Error while initiating schedule taks for recording heartbeats."); + if (CONFIG == null) { + String msg = "Error while initiating schedule taks for recording heartbeats."; + log.error(msg); + throw new HeartBeatBeaconConfigurationException(msg); } try { String uuid = HeartBeatBeaconUtils.readUUID(); - if(uuid == null){ + if (uuid == null) { uuid = HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().updateServerContext(ctx); HeartBeatBeaconUtils.saveUUID(uuid); } @@ -77,9 +79,13 @@ public class HeartBeatExecutor { CONFIG.getNotifierFrequency() != 0 ? CONFIG.getNotifierFrequency() : DEFAULT__NOTIFIER_INTERVAL, TimeUnit.SECONDS); } 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) { - 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)); } - static void electDynamicTaskExecutionCandidate(int cumilativeTimeOut) throws HeartBeatManagementException { + static void electDynamicTaskExecutionCandidate(int cumilativeTimeOut) + throws HeartBeatManagementException { HeartBeatBeaconDataHolder.getInstance().getHeartBeatManagementService().electCandidate(cumilativeTimeOut); } diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementService.java b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementService.java index 7038f6ee4c7..2edd5babdbf 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementService.java +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementService.java @@ -18,7 +18,6 @@ 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.ServerContext; import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException; diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementServiceImpl.java b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementServiceImpl.java index 6fe0d3a8589..5c742a984ea 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementServiceImpl.java +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/service/HeartBeatManagementServiceImpl.java @@ -47,7 +47,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic private final HeartBeatDAO heartBeatDAO; - public HeartBeatManagementServiceImpl(){ + public HeartBeatManagementServiceImpl() { this.heartBeatDAO = HeartBeatBeaconDAOFactory.getHeartBeatDAO(); } @@ -57,7 +57,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic int hashIndex = -1; ServerContext localServerCtx = null; ServerCtxInfo serverCtxInfo = null; - if(HeartBeatBeaconConfig.getInstance().isEnabled()) { + if (HeartBeatBeaconConfig.getInstance().isEnabled()) { try { HeartBeatBeaconDAOFactory.openConnection(); int timeOutIntervalInSeconds = HeartBeatBeaconConfig.getInstance().getServerTimeOutIntervalInSeconds(); @@ -74,9 +74,11 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic } } catch (SQLException e) { String msg = "Error occurred while opening a connection to the underlying data source"; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } catch (HeartBeatDAOException e) { String msg = "Error occurred while retrieving active server count."; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } finally { HeartBeatBeaconDAOFactory.closeConnection(); @@ -91,10 +93,11 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic @Override public boolean isTaskPartitioningEnabled() throws HeartBeatManagementException { boolean enabled = false; - if(HeartBeatBeaconConfig.getInstance() != null){ + if (HeartBeatBeaconConfig.getInstance() != null) { enabled = HeartBeatBeaconConfig.getInstance().isEnabled(); } else { String msg = "Issue instantiating heart beat config."; + log.error(msg); throw new HeartBeatManagementException(msg); } return enabled; @@ -104,7 +107,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic @Override public String updateServerContext(ServerContext ctx) throws HeartBeatManagementException { String uuid = null; - if(HeartBeatBeaconConfig.getInstance().isEnabled()) { + if (HeartBeatBeaconConfig.getInstance().isEnabled()) { try { HeartBeatBeaconDAOFactory.beginTransaction(); uuid = heartBeatDAO.retrieveExistingServerCtx(ctx); @@ -114,10 +117,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic } } catch (HeartBeatDAOException e) { String msg = "Error Occured while retrieving server context."; + log.error(msg, e); 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"; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } finally { HeartBeatBeaconDAOFactory.closeConnection(); @@ -132,22 +137,24 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic @Override public boolean isQualifiedToExecuteTask() throws HeartBeatManagementException { boolean isQualified = false; - if(HeartBeatBeaconConfig.getInstance().isEnabled()) { + if (HeartBeatBeaconConfig.getInstance().isEnabled()) { try { String localServerUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID(); HeartBeatBeaconDAOFactory.openConnection(); ElectedCandidate candidate = heartBeatDAO.retrieveCandidate(); - if(candidate != null && candidate.getServerUUID().equalsIgnoreCase(localServerUUID)){ + if (candidate != null && candidate.getServerUUID().equalsIgnoreCase(localServerUUID)) { isQualified = true; - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Node : " + localServerUUID + " Qualified to execute randomly assigned task."); } } } catch (HeartBeatDAOException e) { String msg = "Error occurred while checking if server is qualified to execute randomly designated task."; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } catch (SQLException e) { String msg = "Error occurred while opening a connection to the underlying data source"; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } finally { HeartBeatBeaconDAOFactory.closeConnection(); @@ -160,23 +167,24 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic } @Override - public boolean updateTaskExecutionAcknowledgement(String newTask) throws HeartBeatManagementException { + public boolean updateTaskExecutionAcknowledgement(String newTask) + throws HeartBeatManagementException { boolean result = false; - if(HeartBeatBeaconConfig.getInstance().isEnabled()) { + if (HeartBeatBeaconConfig.getInstance().isEnabled()) { try { String serverUUID = HeartBeatBeaconDataHolder.getInstance().getLocalServerUUID(); HeartBeatBeaconDAOFactory.beginTransaction(); ElectedCandidate candidate = heartBeatDAO.retrieveCandidate(); - if(candidate != null && candidate.getServerUUID().equals(serverUUID)){ + if (candidate != null && candidate.getServerUUID().equals(serverUUID)) { List taskList = candidate.getAcknowledgedTaskList(); boolean taskExecuted = false; - for(String task : taskList){ - if(task.equalsIgnoreCase(newTask)){ + for (String task : taskList) { + if (task.equalsIgnoreCase(newTask)) { taskExecuted = true; break; } } - if(!taskExecuted) { + if (!taskExecuted) { taskList.add(newTask); result = heartBeatDAO.acknowledgeTask(serverUUID, taskList); HeartBeatBeaconDAOFactory.commitTransaction(); @@ -184,10 +192,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic } } catch (HeartBeatDAOException e) { String msg = "Error occurred while updating acknowledged task."; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } catch (TransactionManagementException e) { HeartBeatBeaconDAOFactory.rollbackTransaction(); 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); } finally { HeartBeatBeaconDAOFactory.closeConnection(); @@ -223,10 +233,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic } } catch (HeartBeatDAOException e) { String msg = "Error occurred while electing candidate for dynamic task execution."; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } catch (TransactionManagementException e) { HeartBeatBeaconDAOFactory.rollbackTransaction(); 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); } finally { HeartBeatBeaconDAOFactory.closeConnection(); @@ -243,8 +255,7 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic } - private String getRandomElement(Set valueSet) - { + private String getRandomElement(Set valueSet) { Random rand = new Random(); List items = new ArrayList<>(valueSet); return items.get(rand.nextInt(items.size())); @@ -257,11 +268,12 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic if (HeartBeatBeaconConfig.getInstance().isEnabled()) { try { HeartBeatBeaconDAOFactory.beginTransaction(); - if(heartBeatDAO.checkUUIDValidity(event.getServerUUID())){ + if (heartBeatDAO.checkUUIDValidity(event.getServerUUID())) { operationSuccess = heartBeatDAO.recordHeatBeat(event); HeartBeatBeaconDAOFactory.commitTransaction(); } else { String msg = "Server UUID Does not exist, heartbeat not recorded."; + log.error(msg); throw new HeartBeatManagementException(msg); } } catch (HeartBeatDAOException e) { @@ -271,12 +283,14 @@ public class HeartBeatManagementServiceImpl implements HeartBeatManagementServic HeartBeatBeaconDAOFactory.rollbackTransaction(); String msg = "Error occurred performing heart beat record transaction. " + "Transaction rolled back."; + log.error(msg, e); throw new HeartBeatManagementException(msg, e); } finally { HeartBeatBeaconDAOFactory.closeConnection(); } } else { String msg = "Heart Beat Configuration Disabled. Recording Heart Beat Failed."; + log.error(msg); throw new HeartBeatManagementException(msg); } return operationSuccess; diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/log4j.properties b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/log4j.properties index dc3d465fc0c..18dca3223c3 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/log4j.properties +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/log4j.properties @@ -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"); # 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 # of the Appenders defined here. The layout pattern & log file diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/testng.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/testng.xml index 2da3b26042b..43b87672a2d 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/testng.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/test/resources/testng.xml @@ -1,18 +1,18 @@ diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index dc60f12880d..d00863f18e6 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -1,21 +1,21 @@ + ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) 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. + --> diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java index a85deab42c7..b24e84f0292 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/DelegationTask.java @@ -70,7 +70,7 @@ public class DelegationTask extends DynamicPartitionedScheduleTask { try { devices = new ArrayList<>(); toBeNotified = new ArrayList<>(); - if(super.isDynamicTaskEligible()) { + if (super.isDynamicTaskEligible()) { devices.addAll(service.getAllocatedDevices(deviceType, super.getTaskContext().getActiveServerCount(), super.getTaskContext().getServerHashIndex())); @@ -79,11 +79,10 @@ public class DelegationTask extends DynamicPartitionedScheduleTask { } for (Device device : devices) { if (device != null && device.getEnrolmentInfo() != null - && device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) { + && device.getEnrolmentInfo().getStatus() != EnrolmentInfo.Status.REMOVED) { toBeNotified.add(device); } - // } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Adding policy operation to device : " + device.getDeviceIdentifier()); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index e539ad2c61d..d51f283a8e7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -139,7 +139,7 @@ public class MonitoringTask extends DynamicPartitionedScheduleTask { status.equals(EnrolmentInfo.Status.UNREACHABLE)) { notifiableDevices.add(device); } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Adding monitoring operation to device : " + device.getDeviceIdentifier()); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestHeartBeatManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestHeartBeatManagementService.java index aa8b5177175..38d7dd0437d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestHeartBeatManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/mock/TestHeartBeatManagementService.java @@ -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; import io.entgra.server.bootup.heartbeat.beacon.dto.HeartBeatEvent; diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml index 7f6d79f5261..fd079f6619c 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml @@ -1,19 +1,18 @@ diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index 049bf35a50f..a56f5f9cd12 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -1,21 +1,21 @@ + ~ Copyright (c) 2020, Entgra (Pvt) Ltd. (http://entgra.io) 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. + --> @@ -32,7 +32,7 @@ 4.1.11-SNAPSHOT pom Entgra - Heart Beat Feature - http://wso2.org + http://entgra.io io.entgra.server.heart.beat.feature