From a5a9d02deec97dfd69d04c3b5c747fd3215a1323 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 14 Jul 2015 19:39:03 +0530 Subject: [PATCH 01/10] Implemented getDeviceByStatus function --- .../device/mgt/common/EnrolmentInfo.java | 2 +- .../carbon/device/mgt/core/dao/DeviceDAO.java | 2 ++ .../mgt/core/dao/impl/DeviceDAOImpl.java | 28 +++++++++++++++ .../DeviceManagementProviderService.java | 9 +++++ .../DeviceManagementProviderServiceImpl.java | 36 +++++++++++++++++++ 5 files changed, 76 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java index 82e3fb57d40..b3a594a95c3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/EnrolmentInfo.java @@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.common; public class EnrolmentInfo { public enum Status { - CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED + CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED } public enum OwnerShip { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index ad87c15096b..75cddd8141c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -60,5 +60,7 @@ public interface DeviceDAO { EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, int tenantId) throws DeviceManagementDAOException; + + List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 55d19152ff3..06a17f06855 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -442,4 +442,32 @@ public class DeviceDAOImpl implements DeviceDAO { return enrolmentInfo; } + public List getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + List devices = new ArrayList(); + try { + conn = this.getConnection(); + stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_TYPE_ID, " + + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + + "AND STATUS = ?) e, DM_DEVICE d WHERE DEVICE_ID = e.DEVICE_ID AND d.TENANT_ID = ?"); + stmt.setInt(1, tenantId); + stmt.setString(2, status.toString()); + stmt.setInt(3, tenantId); + ResultSet rs = stmt.executeQuery(); + + while (rs.next()) { + Device device = this.loadDevice(rs); + devices.add(device); + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " + + "'" + status + "'", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, null); + } + return devices; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 9c72e0323c8..345838a1e50 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -79,4 +79,13 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM List getDevicesByName(String deviceName) throws DeviceManagementException; void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; + + /** + * This method is used to retrieve list of devices based on the device status + * + * @param status Device status + * @return List of devices + * @throws DeviceManagementException + */ + List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException; } 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 9aa80d7e256..6e9ccdd0509 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 @@ -699,4 +699,40 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } + public List getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException { + List devices = new ArrayList(); + List allDevices; + try { + DeviceManagementDAOFactory.getConnection(); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + allDevices = deviceDAO.getDevicesByStatus(status, tenantId); + + } catch (DeviceManagementDAOException e) { + String errorMsg = "Error occurred while fetching the list of devices that matches to status: '" + + status + "'"; + log.error(errorMsg, e); + throw new DeviceManagementException(errorMsg, e); + } finally { + + try { + DeviceManagementDAOFactory.closeConnection(); + } catch (DeviceManagementDAOException e) { + log.warn("Error occurred while closing the connection", e); + } + } + + for (Device device : allDevices) { + Device dmsDevice = + this.getPluginRepository().getDeviceManagementService( + device.getType()).getDeviceManager().getDevice( + new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } + devices.add(device); + } + return devices; + } + } From a82351f53fdb5c5ea5bf181865fd409a37a94a44 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 14 Jul 2015 20:31:37 +0530 Subject: [PATCH 02/10] Refactered getDevicesByType query --- .../wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 06a17f06855..fdb18454f70 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -448,11 +448,12 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = new ArrayList(); try { conn = this.getConnection(); - stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_TYPE_ID, " + + stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + - "AND STATUS = ?) e, DM_DEVICE d WHERE DEVICE_ID = e.DEVICE_ID AND d.TENANT_ID = ?"); + "AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " + + "AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"); stmt.setInt(1, tenantId); stmt.setString(2, status.toString()); stmt.setInt(3, tenantId); From 5a4231485569683e6fb4d6b8b1198b3b32467745 Mon Sep 17 00:00:00 2001 From: milanperera Date: Thu, 16 Jul 2015 19:58:13 +0530 Subject: [PATCH 03/10] Added dynamic-client-authentication-feature --- carbon-devicemgt.ids | 197 ++++++++++++++++++ .../pom.xml | 154 ++++++++++++++ .../src/main/resources/p2.inf | 2 + features/oauth-extensions/pom.xml | 42 ++++ pom.xml | 1 + 5 files changed, 396 insertions(+) create mode 100644 carbon-devicemgt.ids create mode 100644 features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml create mode 100644 features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf create mode 100644 features/oauth-extensions/pom.xml diff --git a/carbon-devicemgt.ids b/carbon-devicemgt.ids new file mode 100644 index 00000000000..d0219166cff --- /dev/null +++ b/carbon-devicemgt.ids @@ -0,0 +1,197 @@ + + + + + " + + + + + + + + +
+ + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + +
+ + + + + + + +
+ + + + + + + +
+
+
\ No newline at end of file diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml new file mode 100644 index 00000000000..a20ebb17c68 --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/pom.xml @@ -0,0 +1,154 @@ + + + + + + + + org.wso2.carbon.devicemgt + oauth-extentions-feature + 0.9.2-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.oauth.extensions.server.feature + pom + 0.9.2-SNAPSHOT + WSO2 Carbon - Oauth Extensions Server Feature + http://wso2.org + This feature contains oauth functionality + + + + + + + + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.4 + + + copy + package + + copy + + + + + org.wso2.mdm + dynamic-client-manager + ${project.version} + war + true + ${basedir}/src/main/resources/ + dynamic-client-manager.war + + + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + org.wso2.carbon.oauth.extensions.server + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:false + + + + + + + + + + + + + + + + + + org.wso2.carbon.core.server:${carbon.kernel.version} + + + + + + + + + + + + + diff --git a/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf new file mode 100644 index 00000000000..3143c5e9dfb --- /dev/null +++ b/features/oauth-extensions/org.wso2.carbon.oauth.extensions.server.feature/src/main/resources/p2.inf @@ -0,0 +1,2 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.oauth.extensions.server_${feature.version}/dynamic-client-manager.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-manager.war,overwrite:true);\ \ No newline at end of file diff --git a/features/oauth-extensions/pom.xml b/features/oauth-extensions/pom.xml new file mode 100644 index 00000000000..87ed9a7ef07 --- /dev/null +++ b/features/oauth-extensions/pom.xml @@ -0,0 +1,42 @@ + + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 0.9.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.devicemgt + oauth-extentions-feature + 0.9.2-SNAPSHOT + pom + WSO2 Carbon - Policy Management Feature + http://wso2.org + + + org.wso2.carbon.oauth.extensions.server.feature + + + diff --git a/pom.xml b/pom.xml index f31068a4572..ffd4eda2ebe 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ features/device-mgt features/policy-mgt features/webapp-authenticator-framework + features/oauth-extensions From f20037432075d5dfca0893b9bd48cec9c46655a1 Mon Sep 17 00:00:00 2001 From: milanperera Date: Thu, 16 Jul 2015 20:05:09 +0530 Subject: [PATCH 04/10] removing ids --- carbon-devicemgt.ids | 197 ------------------------------------------- 1 file changed, 197 deletions(-) delete mode 100644 carbon-devicemgt.ids diff --git a/carbon-devicemgt.ids b/carbon-devicemgt.ids deleted file mode 100644 index d0219166cff..00000000000 --- a/carbon-devicemgt.ids +++ /dev/null @@ -1,197 +0,0 @@ - - - - - " - - - - - - - - -
- - - - -
- - - - - - -
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - -
- - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - -
- - - - - - -
- - - - - - - -
- - - - - - - -
-
-
\ No newline at end of file From 4049d1a2b43b42f714bc7f86196d92f50d199ca3 Mon Sep 17 00:00:00 2001 From: manoj Date: Mon, 20 Jul 2015 09:39:38 +0530 Subject: [PATCH 05/10] Remove properties from config operations --- .../device/mgt/core/operation/mgt/ConfigOperation.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java index dca49142254..83cfd0e6127 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -26,9 +26,7 @@ import java.util.List; public class ConfigOperation extends Operation { - private List properties; - - public ConfigOperation() { +/* public ConfigOperation() { properties = new ArrayList(); } @@ -38,7 +36,7 @@ public class ConfigOperation extends Operation { public void addConfigProperty(String name, Object value, Class type) { properties.add(new Property(name, value, type)); - } + }*/ public static class Property implements Serializable { private String name; From e0301e4ce3b5f83e2ca6ccc5079f9eb32ce8cefd Mon Sep 17 00:00:00 2001 From: geethkokila Date: Mon, 20 Jul 2015 10:49:37 +0530 Subject: [PATCH 06/10] Adding the 90% completed monitoring task --- .../mgt/common/Monitor/ComplianceData.java | 37 +++++ .../Monitor/ComplianceDecisionPoint.java | 7 +- ...ava => PolicyMonitoringTaskException.java} | 28 ++-- .../common/spi/PolicyMonitoringService.java | 2 +- .../policy/mgt/core/PolicyManagerService.java | 12 +- .../mgt/core/PolicyManagerServiceImpl.java | 7 + .../policy/mgt/core/dao/MonitoringDAO.java | 7 +- .../mgt/core/dao/impl/MonitoringDAOImpl.java | 139 ++++++++++++++++-- .../impl/ComplianceDecisionPointImpl.java | 113 +++++++------- .../internal/PolicyManagementDataHolder.java | 10 ++ .../PolicyManagementServiceComponent.java | 27 +++- .../mgt/core/mgt/MonitoringManager.java | 3 + .../core/mgt/impl/MonitoringManagerImpl.java | 85 ++++++++++- .../core/service/PolicyManagementService.java | 15 +- .../policy/mgt/core/task/MonitoringTask.java | 31 +++- .../mgt/core/task/TaskScheduleService.java | 31 ++++ .../core/task/TaskScheduleServiceImpl.java | 129 ++++++++++++++++ .../core/util/PolicyManagementConstants.java | 7 + 18 files changed, 584 insertions(+), 106 deletions(-) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{PolicyVerificationException.java => PolicyMonitoringTaskException.java} (51%) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleService.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleServiceImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceData.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceData.java index 5511604078e..0304e690f01 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceData.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceData.java @@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common.monitor; import org.wso2.carbon.policy.mgt.common.Policy; +import java.sql.Timestamp; import java.util.List; public class ComplianceData { @@ -30,6 +31,10 @@ public class ComplianceData { private int policyId; List complianceFeatures; private boolean status; + private Timestamp lastRequestedTime; + private Timestamp lastSucceededTime; + private Timestamp lastFailedTime; + private int attempts; private String message; /** @@ -47,6 +52,38 @@ public class ComplianceData { this.id = id; } + public Timestamp getLastRequestedTime() { + return lastRequestedTime; + } + + public void setLastRequestedTime(Timestamp lastRequestedTime) { + this.lastRequestedTime = lastRequestedTime; + } + + public Timestamp getLastSucceededTime() { + return lastSucceededTime; + } + + public void setLastSucceededTime(Timestamp lastSucceededTime) { + this.lastSucceededTime = lastSucceededTime; + } + + public Timestamp getLastFailedTime() { + return lastFailedTime; + } + + public void setLastFailedTime(Timestamp lastFailedTime) { + this.lastFailedTime = lastFailedTime; + } + + public int getAttempts() { + return attempts; + } + + public void setAttempts(int attempts) { + this.attempts = attempts; + } + public int getDeviceId() { return deviceId; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceDecisionPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceDecisionPoint.java index ada9b19a892..8799653fe30 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceDecisionPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceDecisionPoint.java @@ -20,14 +20,19 @@ package org.wso2.carbon.policy.mgt.common.monitor; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.Policy; +import java.util.List; + public interface ComplianceDecisionPoint { String getNoneComplianceRule(Policy policy) throws PolicyComplianceException; - void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; + void setDevicesAsUnreachable(List deviceIdentifiers) throws PolicyComplianceException; + + void setDevicesAsUnreachableWith(List devices) throws PolicyComplianceException; void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyMonitoringTaskException.java similarity index 51% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyMonitoringTaskException.java index f0a25966c12..7fc01603ea8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyMonitoringTaskException.java @@ -19,38 +19,38 @@ package org.wso2.carbon.policy.mgt.common; -public class PolicyVerificationException extends Exception { +public class PolicyMonitoringTaskException extends Exception { - private String policyVerificationErrorMessage; + private String policyMonitoingErrorMessage; - public String getPolicyVerificationErrorMessage() { - return policyVerificationErrorMessage; + public String getPolicyMonitoingErrorMessage() { + return policyMonitoingErrorMessage; } - public void setPolicyVerificationErrorMessage(String policyVerificationErrorMessage) { - this.policyVerificationErrorMessage = policyVerificationErrorMessage; + public void setPolicyMonitoingErrorMessage(String policyMonitoingErrorMessage) { + this.policyMonitoingErrorMessage = policyMonitoingErrorMessage; } - public PolicyVerificationException(String message) { + public PolicyMonitoringTaskException(String message) { super(message); - setPolicyVerificationErrorMessage(message); + setPolicyMonitoingErrorMessage(message); } - public PolicyVerificationException(String message, Exception ex) { + public PolicyMonitoringTaskException(String message, Exception ex) { super(message, ex); - setPolicyVerificationErrorMessage(message); + setPolicyMonitoingErrorMessage(message); } - public PolicyVerificationException(String message, Throwable cause) { + public PolicyMonitoringTaskException(String message, Throwable cause) { super(message, cause); - setPolicyVerificationErrorMessage(message); + setPolicyMonitoingErrorMessage(message); } - public PolicyVerificationException() { + public PolicyMonitoringTaskException() { super(); } - public PolicyVerificationException(Throwable cause) { + public PolicyMonitoringTaskException(Throwable cause) { super(cause); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java index 81478b6ba47..c1ca58a291e 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java @@ -28,7 +28,7 @@ import org.wso2.carbon.policy.mgt.common.Policy; import java.util.List; -public interface PolicyMonitoringService { +public interface PolicyMonitoringService { void notifyDevices(List devices) throws PolicyComplianceException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index 59e0c7a30d2..405fe73f7ab 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -21,17 +21,11 @@ package org.wso2.carbon.policy.mgt.core; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; -import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.Profile; -import org.wso2.carbon.policy.mgt.common.ProfileFeature; +import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import java.util.List; @@ -69,6 +63,8 @@ public interface PolicyManagerService { PolicyEvaluationPoint getPEP() throws PolicyManagementException; + TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException; + int getPolicyCount() throws PolicyManagementException; List CheckPolicyCompliance(DeviceIdentifier deviceIdentifier, Object diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index 70e76eb1f2c..f3045bb2127 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -35,6 +35,8 @@ import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl; +import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; +import org.wso2.carbon.policy.mgt.core.task.TaskScheduleServiceImpl; import java.util.ArrayList; import java.util.List; @@ -203,6 +205,11 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); } + @Override + public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException { + return new TaskScheduleServiceImpl(); + } + @Override public int getPolicyCount() throws PolicyManagementException { return policyAdministratorPoint.getPolicyCount(); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/MonitoringDAO.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/MonitoringDAO.java index 426935e4e0a..3286ed39455 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/MonitoringDAO.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/MonitoringDAO.java @@ -30,16 +30,21 @@ public interface MonitoringDAO { void setDeviceAsCompliance(int deviceId, int policyId) throws MonitoringDAOException; - void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List complianceFeatures) + void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List + complianceFeatures) throws MonitoringDAOException; ComplianceData getCompliance(int deviceId) throws MonitoringDAOException; + List getCompliance(List deviceIds) throws MonitoringDAOException; + List getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException; void deleteNoneComplianceData(int policyComplianceStatusId) throws MonitoringDAOException; void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException; + void updateAttempts(List deviceId, boolean reset) throws MonitoringDAOException; + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/MonitoringDAOImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/MonitoringDAOImpl.java index e6bb638537f..c39bf57ab9d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/MonitoringDAOImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/dao/impl/MonitoringDAOImpl.java @@ -29,11 +29,9 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory; import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException; import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; public class MonitoringDAOImpl implements MonitoringDAO { @@ -46,14 +44,17 @@ public class MonitoringDAOImpl implements MonitoringDAO { Connection conn; PreparedStatement stmt = null; ResultSet generatedKeys = null; + Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); try { conn = this.getConnection(); - String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS) VALUES" + - " (?, ?, ?) "; + String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS, LAST_FAILED_TIME, " + + "ATTEMPTS) VALUES (?, ?, ?, ?, ?) "; stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); stmt.setInt(1, deviceId); stmt.setInt(2, policyId); stmt.setInt(3, 0); + stmt.setTimestamp(4, currentTimestamp); + stmt.setInt(5, 0); stmt.executeUpdate(); generatedKeys = stmt.getGeneratedKeys(); @@ -78,12 +79,15 @@ public class MonitoringDAOImpl implements MonitoringDAO { Connection conn; PreparedStatement stmt = null; + Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); try { conn = this.getConnection(); - String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ? WHERE DEVICE_ID = ?"; + String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ?, ATTEMPTS=0, LAST_SUCCESS_TIME = ?" + + " WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(query); stmt.setInt(1, 1); - stmt.setInt(2, deviceId); + stmt.setTimestamp(2, currentTimestamp); + stmt.setInt(3, deviceId); stmt.executeUpdate(); @@ -105,8 +109,8 @@ public class MonitoringDAOImpl implements MonitoringDAO { try { conn = this.getConnection(); String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS) " + - "VALUES" + - " (?, ?, ?) "; + "VALUES (?, ?, ?) "; + stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS); for (ComplianceFeature feature : complianceFeatures) { stmt.setInt(1, policyComplianceStatusId); @@ -145,6 +149,10 @@ public class MonitoringDAOImpl implements MonitoringDAO { complianceData.setDeviceId(resultSet.getInt("DEVICE_ID")); complianceData.setPolicyId(resultSet.getInt("POLICY_ID")); complianceData.setStatus(resultSet.getBoolean("STATUS")); + complianceData.setAttempts(resultSet.getInt("ATTEMPTS")); + complianceData.setLastRequestedTime(resultSet.getTimestamp("LAST_REQUESTED_TIME")); + complianceData.setLastSucceededTime(resultSet.getTimestamp("LAST_SUCCESS_TIME")); + complianceData.setLastFailedTime(resultSet.getTimestamp("LAST_FAILED_TIME")); } return complianceData; @@ -158,6 +166,48 @@ public class MonitoringDAOImpl implements MonitoringDAO { } } + @Override + public List getCompliance(List deviceIds) throws MonitoringDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + List complianceDataList = null; + + try { + conn = this.getConnection(); + String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID IN (?)"; + stmt = conn.prepareStatement(query); + stmt.setString(1, makeString(deviceIds)); + + resultSet = stmt.executeQuery(); + + while (resultSet.next()) { + + ComplianceData complianceData = new ComplianceData(); + + complianceData.setId(resultSet.getInt("ID")); + complianceData.setDeviceId(resultSet.getInt("DEVICE_ID")); + complianceData.setPolicyId(resultSet.getInt("POLICY_ID")); + complianceData.setStatus(resultSet.getBoolean("STATUS")); + complianceData.setAttempts(resultSet.getInt("ATTEMPTS")); + complianceData.setLastRequestedTime(resultSet.getTimestamp("LAST_REQUESTED_TIME")); + complianceData.setLastSucceededTime(resultSet.getTimestamp("LAST_SUCCESS_TIME")); + complianceData.setLastFailedTime(resultSet.getTimestamp("LAST_FAILED_TIME")); + + complianceDataList.add(complianceData); + } + return complianceDataList; + + } catch (SQLException e) { + String msg = "Unable to retrieve compliance data from database."; + log.error(msg, e); + throw new MonitoringDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, resultSet); + this.closeConnection(); + } + } + @Override public List getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException { @@ -217,9 +267,68 @@ public class MonitoringDAOImpl implements MonitoringDAO { @Override public void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException { + Connection conn; + PreparedStatement stmt = null; + Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); + try { + + conn = this.getConnection(); + String query = ""; + if (reset) { + query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " + + "WHERE DEVICE_ID = ?"; + } else { + query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = ATTEMPTS + 1, LAST_REQUESTED_TIME = ? " + + "WHERE DEVICE_ID = ?"; + } + stmt = conn.prepareStatement(query); + stmt.setTimestamp(1, currentTimestamp); + stmt.setInt(2, deviceId); + stmt.executeUpdate(); + + } catch (SQLException e) { + String msg = "Unable to update the attempts data in database."; + log.error(msg, e); + throw new MonitoringDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } } + @Override + public void updateAttempts(List deviceIds, boolean reset) throws MonitoringDAOException { + Connection conn; + PreparedStatement stmt = null; + Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); + try { + + conn = this.getConnection(); + String query = ""; + if (reset) { + query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " + + "WHERE DEVICE_ID = ?"; + } else { + query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = ATTEMPTS + 1, LAST_REQUESTED_TIME = ? " + + "WHERE DEVICE_ID = ?"; + } + stmt = conn.prepareStatement(query); + for (int deviceId : deviceIds) { + stmt.setTimestamp(1, currentTimestamp); + stmt.setInt(2, deviceId); + stmt.addBatch(); + } + stmt.executeBatch(); + + } catch (SQLException e) { + String msg = "Unable to update the attempts data in database."; + log.error(msg, e); + throw new MonitoringDAOException(msg, e); + } finally { + PolicyManagementDAOUtil.cleanupResources(stmt, null); + } + } + private Connection getConnection() throws MonitoringDAOException { try { @@ -238,4 +347,14 @@ public class MonitoringDAOImpl implements MonitoringDAO { log.warn("Unable to close the database connection."); } } + + private String makeString(List values) { + + StringBuilder buff = new StringBuilder(); + for (int value : values) { + buff.append(value).append(","); + } + buff.deleteCharAt(buff.length() - 1); + return buff.toString(); + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java index 5506bcb363c..3036be50507 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/ComplianceDecisionPointImpl.java @@ -23,15 +23,13 @@ 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.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; -import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.core.dao.EnrolmentDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; @@ -39,10 +37,7 @@ import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; -import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager; -import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl; import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants; -import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; import java.util.ArrayList; import java.util.List; @@ -51,50 +46,58 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { private static final Log log = LogFactory.getLog(ComplianceDecisionPointImpl.class); - private EnrolmentDAO enrolmentDAO; - private DeviceDAO deviceDAO; - - private PolicyManager policyManager; - - public ComplianceDecisionPointImpl() { - enrolmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO(); - deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); - policyManager = new PolicyManagerImpl(); - } - @Override public String getNoneComplianceRule(Policy policy) throws PolicyComplianceException { return policy.getCompliance(); } @Override - public void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { + public void setDevicesAsUnreachable(List deviceIdentifiers) throws PolicyComplianceException { try { - int tenantId = PolicyManagerUtil.getTenantId(); - Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(), - EnrolmentInfo.Status.UNREACHABLE, tenantId); - - } catch (DeviceManagementDAOException e) { - String msg = "Error occurred while setting the device as unreachable for " + - deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { + Device device = service.getDevice(deviceIdentifier); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.UNREACHABLE); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while setting the device as unreachable"; log.error(msg, e); throw new PolicyComplianceException(msg, e); } } + @Override + public void setDevicesAsUnreachableWith(List devices) throws PolicyComplianceException { + try { + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + for (Device device : devices) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.UNREACHABLE); + } + } catch (DeviceManagementException e) { + String msg = "Error occurred while setting the device as unreachable"; + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } + } + @Override public void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { - int tenantId = PolicyManagerUtil.getTenantId(); - Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(), - EnrolmentInfo.Status.ACTIVE, tenantId); - } catch (DeviceManagementDAOException e) { + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + Device device = service.getDevice(deviceIdentifier); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.ACTIVE); + + } catch (DeviceManagementException e) { String msg = "Error occurred while setting the device as reachable for " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); @@ -167,12 +170,12 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { public void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { - int tenantId = PolicyManagerUtil.getTenantId(); - Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(), - EnrolmentInfo.Status.BLOCKED, tenantId); + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + Device device = service.getDevice(deviceIdentifier); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.BLOCKED); - } catch (DeviceManagementDAOException e) { + } catch (DeviceManagementException e) { String msg = "Error occurred while marking device as none compliance " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); @@ -184,16 +187,15 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { public void markDeviceAsCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { - int tenantId = PolicyManagerUtil.getTenantId(); - Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(), - EnrolmentInfo.Status.ACTIVE, tenantId); + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + Device device = service.getDevice(deviceIdentifier); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.ACTIVE); - } catch (DeviceManagementDAOException e) { + } catch (DeviceManagementException e) { String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); - throw new PolicyComplianceException(msg, e); } } @@ -202,12 +204,13 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { - int tenantId = PolicyManagerUtil.getTenantId(); - Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(), - EnrolmentInfo.Status.INACTIVE, tenantId); - } catch (DeviceManagementDAOException e) { + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + Device device = service.getDevice(deviceIdentifier); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.INACTIVE); + + } catch (DeviceManagementException e) { String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); @@ -219,12 +222,12 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { public void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { try { - int tenantId = PolicyManagerUtil.getTenantId(); - Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(), - EnrolmentInfo.Status.ACTIVE, tenantId); + DeviceManagementProviderService service = this.getDeviceManagementProviderService(); + Device device = service.getDevice(deviceIdentifier); + service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(), + EnrolmentInfo.Status.ACTIVE); - } catch (DeviceManagementDAOException e) { + } catch (DeviceManagementException e) { String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); log.error(msg, e); @@ -257,4 +260,8 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { this.markDeviceAsNoneCompliance(deviceIdentifier); } } + + private DeviceManagementProviderService getDeviceManagementProviderService() { + return PolicyManagementDataHolder.getInstance().getDeviceManagementService(); + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java index 4f2d664494c..af03b36d566 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java @@ -19,6 +19,7 @@ package org.wso2.carbon.policy.mgt.core.internal; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; @@ -35,6 +36,7 @@ public class PolicyManagementDataHolder { private PolicyInformationPoint policyInformationPoint; private DeviceManagementProviderService deviceManagementService; private Map policyMonitoringServiceMap; + private TaskService taskService; private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder(); @@ -99,4 +101,12 @@ public class PolicyManagementDataHolder { public void unsetPolicyMonitoringService(String deviceType) { this.policyMonitoringServiceMap.remove(deviceType); } + + public TaskService getTaskService() { + return taskService; + } + + public void setTaskService(TaskService taskService) { + this.taskService = taskService; + } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index d6f72dba744..4ea26e0a1b7 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; @@ -58,6 +59,12 @@ import org.wso2.carbon.user.core.service.RealmService; * policy="dynamic" * bind="setPolicyMonitoringService" * unbind="unsetPolicyMonitoringService" + * @scr.reference name="ntask.component" + * interface="org.wso2.carbon.ntask.core.service.TaskService" + * cardinality="1..1" + * policy="dynamic" + * bind="setTaskService" + * unbind="unsetTaskService" */ @SuppressWarnings("unused") public class PolicyManagementServiceComponent { @@ -131,7 +138,7 @@ public class PolicyManagementServiceComponent { protected void unsetPEPService(PolicyEvaluationPoint pepService) { if (log.isDebugEnabled()) { - log.debug("Unsetting Policy Information Service"); + log.debug("Removing Policy Information Service"); } PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null); } @@ -145,7 +152,7 @@ public class PolicyManagementServiceComponent { protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementService) { if (log.isDebugEnabled()) { - log.debug("Unsetting Device Management Service"); + log.debug("Removing Device Management Service"); } PolicyManagementDataHolder.getInstance().setDeviceManagementService(null); } @@ -161,10 +168,24 @@ public class PolicyManagementServiceComponent { protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) { if (log.isDebugEnabled()) { - log.debug("Setting Policy Monitoring Service"); + log.debug("Removing the Policy Monitoring Service"); } // TODO: FIX THE device type by taking from properties PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(""); } + protected void setTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Setting the task service."); + } + PolicyManagementDataHolder.getInstance().setTaskService(taskService); + } + + protected void unsetTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Removing the task service."); + } + PolicyManagementDataHolder.getInstance().setTaskService(null); + } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java index 8ad323f2eb8..9da602f2613 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/MonitoringManager.java @@ -19,6 +19,7 @@ package org.wso2.carbon.policy.mgt.core.mgt; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; @@ -36,4 +37,6 @@ public interface MonitoringManager { ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; + void addMonitoringOperation(List devices) throws PolicyComplianceException; + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java index 37b3b6491d0..ec6714cb902 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/MonitoringManagerImpl.java @@ -43,7 +43,7 @@ import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; -import java.util.List; +import java.util.*; public class MonitoringManagerImpl implements MonitoringManager { @@ -186,4 +186,87 @@ public class MonitoringManagerImpl implements MonitoringManager { } return complianceData; } + + @Override + public void addMonitoringOperation(List devices) throws PolicyComplianceException { + + try { + + ComplianceDecisionPoint decisionPoint = new ComplianceDecisionPointImpl(); + + int tenantId = PolicyManagerUtil.getTenantId(); + Map deviceIds = new HashMap<>(); + + for (Device device : devices) { + deviceIds.put(device.getId(), device); + } + + List complianceDatas = monitoringDAO.getCompliance(new ArrayList<>(deviceIds.keySet())); + + Map deviceIdsToAddOperation = new HashMap<>(); + Map deviceIdsWithExistingOperation = new HashMap<>(); + Map inactiveDeviceIds = new HashMap<>(); + + Map tempMap = new HashMap<>(); + + + for (ComplianceData complianceData : complianceDatas) { + + tempMap.put(complianceData.getDeviceId(), complianceData); + + if (complianceData.getAttempts() == 0) { + deviceIdsToAddOperation.put(complianceData.getDeviceId(), + deviceIds.get(complianceData.getDeviceId())); + } else { + deviceIdsWithExistingOperation.put(complianceData.getDeviceId(), + deviceIds.get(complianceData.getDeviceId())); + } + if (complianceData.getAttempts() >= 20) { + inactiveDeviceIds.put(complianceData.getDeviceId(), + deviceIds.get(complianceData.getDeviceId())); + } + } + + for (Device device : devices) { + if (!tempMap.containsKey(device.getId())) { + deviceIdsToAddOperation.put(device.getId(), device); + } + } + + if (!deviceIdsToAddOperation.isEmpty()) { + this.addMonitoringOperationsToDatabase(new ArrayList<>(deviceIdsToAddOperation.values())); + } + + if (!deviceIdsWithExistingOperation.isEmpty()) { + monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false); + decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices( + new ArrayList<>(deviceIdsWithExistingOperation.values()))); + } + + } catch (MonitoringDAOException e) { + String msg = "Error occurred from monitoring dao."; + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } + + } + + + private void addMonitoringOperationsToDatabase(List devices) throws PolicyComplianceException { + + } + + private List getDeviceIdentifiersFromDevices(List devices) { + + List deviceIdentifiers = new ArrayList<>(); + for (Device device : devices) { + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setId(device.getDeviceIdentifier()); + identifier.setType(device.getType()); + + deviceIdentifiers.add(identifier); + } + return deviceIdentifiers; + } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java index 5c73fcedea4..f2b738b1efc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/service/PolicyManagementService.java @@ -20,19 +20,13 @@ package org.wso2.carbon.policy.mgt.core.service; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.policy.mgt.common.FeatureManagementException; +import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; -import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint; -import org.wso2.carbon.policy.mgt.common.PolicyManagementException; -import org.wso2.carbon.policy.mgt.common.Profile; -import org.wso2.carbon.policy.mgt.common.ProfileFeature; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; +import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import java.util.List; @@ -112,6 +106,11 @@ public class PolicyManagementService implements PolicyManagerService { return policyManagerService.getPEP(); } + @Override + public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException { + return policyManagerService.getTaskScheduleService(); + } + @Override public int getPolicyCount() throws PolicyManagementException { return policyManagerService.getPolicyCount(); 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 cf62d08b07c..5780966645c 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 @@ -19,6 +19,8 @@ package org.wso2.carbon.policy.mgt.core.task; +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.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; @@ -27,6 +29,8 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; +import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; +import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl; import java.util.List; import java.util.Map; @@ -34,10 +38,14 @@ import java.util.Map; public class MonitoringTask implements Task { private DeviceTypeDAO deviceTypeDAO; + private static Log log = LogFactory.getLog(MonitoringTask.class); + + Map properties; + @Override public void setProperties(Map map) { - + this.properties = map; } @Override @@ -47,23 +55,34 @@ public class MonitoringTask implements Task { @Override public void execute() { - try { - List deviceTypes = deviceTypeDAO.getDeviceTypes(); + if(log.isDebugEnabled()) { + log.debug("Monitoring task started to run."); + } + try { + List deviceTypes = deviceTypeDAO.getDeviceTypes(); DeviceManagementProviderService deviceManagementProviderService = PolicyManagementDataHolder.getInstance().getDeviceManagementService(); + MonitoringManager monitoringManager = new MonitoringManagerImpl(); for (DeviceType deviceType : deviceTypes) { PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType.getName()); - List devices = deviceManagementProviderService.getAllDevices(deviceType.getName()); - monitoringService.notifyDevices(devices); + if (monitoringService != null && !devices.isEmpty()) { + monitoringManager.addMonitoringOperation(devices); + monitoringService.notifyDevices(devices); + } } - } catch (Exception e) { + if(log.isDebugEnabled()) { + log.debug("Monitoring task running completed."); + } + } catch (Exception e) { + String msg = "Error occurred while trying to run a task."; + log.error(msg, e); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleService.java new file mode 100644 index 00000000000..29d45149eb2 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleService.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.task; + +import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; + +public interface TaskScheduleService { + + void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException; + + void stopTask() throws PolicyMonitoringTaskException; + + void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException; +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleServiceImpl.java new file mode 100644 index 00000000000..ac0eaf1f67f --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/TaskScheduleServiceImpl.java @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.task; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.ntask.common.TaskException; +import org.wso2.carbon.ntask.core.TaskInfo; +import org.wso2.carbon.ntask.core.TaskManager; +import org.wso2.carbon.ntask.core.service.TaskService; +import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; +import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; +import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants; +import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil; +import org.wso2.carbon.ntask.core.TaskInfo.TriggerInfo; + +import java.util.HashMap; +import java.util.Map; + +public class TaskScheduleServiceImpl implements TaskScheduleService { + + private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class); + + @Override + public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException { + + if (monitoringFrequency <= 0) { + throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0."); + } + try { + int tenantId = PolicyManagerUtil.getTenantId(); + TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); + taskService.registerTaskType(PolicyManagementConstants.TASK_TYPE); + + if (log.isDebugEnabled()) { + log.debug("Monitoring task is started for the tenant id " + tenantId); + } + + TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE); + + TriggerInfo triggerInfo = new TriggerInfo(); + + triggerInfo.setIntervalMillis(monitoringFrequency); + triggerInfo.setRepeatCount(-1); + + Map properties = new HashMap<>(); + properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId)); + + String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId); + + TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.TASK_CLAZZ, properties, triggerInfo); + + taskManager.registerTask(taskInfo); + taskManager.rescheduleTask(taskInfo.getName()); + + + } catch (TaskException e) { + String msg = "Error occurred while creating the task for tenant " + PolicyManagerUtil.getTenantId(); + log.error(msg, e); + throw new PolicyMonitoringTaskException(msg ,e); + } + + + } + + @Override + public void stopTask() throws PolicyMonitoringTaskException { + try { + int tenantId = PolicyManagerUtil.getTenantId(); + String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId); + TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); + TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE); + taskManager.deleteTask(taskName); + } catch (TaskException e) { + String msg = "Error occurred while deleting the task for tenant " + PolicyManagerUtil.getTenantId(); + log.error(msg, e); + throw new PolicyMonitoringTaskException(msg ,e); + } + } + + @Override + public void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException { + try{ + int tenantId = PolicyManagerUtil.getTenantId(); + String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId); + TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); + + TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE); + + taskManager.deleteTask(taskName); + + TriggerInfo triggerInfo = new TriggerInfo(); + + triggerInfo.setIntervalMillis(monitoringFrequency); + triggerInfo.setRepeatCount(-1); + + Map properties = new HashMap<>(); + properties.put("tenantId", String.valueOf(tenantId)); + + TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.TASK_CLAZZ, properties, triggerInfo); + + taskManager.registerTask(taskInfo); + taskManager.rescheduleTask(taskInfo.getName()); + + } catch (TaskException e) { + String msg = "Error occurred while updating the task for tenant " + PolicyManagerUtil.getTenantId(); + log.error(msg, e); + throw new PolicyMonitoringTaskException(msg ,e); + } + + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java index 477e9bcb322..e6fe25c9a45 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagementConstants.java @@ -24,10 +24,17 @@ public final class PolicyManagementConstants { public static final String ANY = "ANY"; public static final String POLICY_BUNDLE = "POLICY_BUNDLE"; + public static final String TENANT_ID = "TENANT_ID"; + public static final String MONITOR = "MONITOR"; public static final String ENFORCE = "ENFORCE"; public static final String WARN = "WARN"; public static final String BLOCK = "BLOCK"; + public static final String TASK_TYPE = "MONITORING_TASK"; + public static final String TASK_NAME = "MONITORING"; + public static final String TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.task.MonitoringTask"; + + } From 57299063b3374287a04f3e22d7881879a3297cea Mon Sep 17 00:00:00 2001 From: harshanl Date: Mon, 20 Jul 2015 11:16:15 +0530 Subject: [PATCH 07/10] Added policy configuration to the cdm-config --- .../DeviceManagementConfigRepository.java | 11 ++++ .../config/policy/PolicyConfiguration.java | 57 +++++++++++++++++++ .../src/main/resources/conf/cdm-config.xml | 5 ++ 3 files changed, 73 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java index 2867b080149..d3bfb77b9ab 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfigRepository.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.email.EmailConfigurations; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; +import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @@ -33,6 +34,7 @@ public class DeviceManagementConfigRepository { private DataSourceConfig dataSourceConfig; private EmailConfigurations emailConfigurations; private IdentityConfigurations identityConfigurations; + private PolicyConfiguration policyConfiguration; @XmlElement(name = "DataSourceConfiguration", required = true) public DataSourceConfig getDataSourceConfig() { @@ -60,4 +62,13 @@ public class DeviceManagementConfigRepository { public void setIdentityConfigurations(IdentityConfigurations identityConfigurations) { this.identityConfigurations = identityConfigurations; } + + @XmlElement(name = "PolicyConfiguration", required = true) + public PolicyConfiguration getPolicyConfiguration() { + return policyConfiguration; + } + + public void setPolicyConfiguration(PolicyConfiguration policyConfiguration) { + this.policyConfiguration = policyConfiguration; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java new file mode 100644 index 00000000000..fe38dbbd955 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.config.policy; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "PolicyConfiguration") +public class PolicyConfiguration { + + private String monitoringClass; + private int maxRetries; + private int minRetriesToMarkUnreachable; + + @XmlElement(name = "monitoringClass", required = true) + public String getMonitoringClass() { + return monitoringClass; + } + + public void setMonitoringClass(String monitoringClass) { + this.monitoringClass = monitoringClass; + } + + @XmlElement(name = "maxRetries", required = true) + public int getMaxRetries() { + return maxRetries; + } + + public void setMaxRetries(int maxRetries) { + this.maxRetries = maxRetries; + } + + @XmlElement(name = "minRetriesToMarkUnreachable", required = true) + public int getMinRetriesToMarkUnreachable() { + return minRetriesToMarkUnreachable; + } + + public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) { + this.minRetriesToMarkUnreachable = minRetriesToMarkUnreachable; + } +} diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index a6646f863a1..0efa651a73e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -35,6 +35,11 @@ admin admin + + org.wso2.carbon.policy.mgt + 5 + 8 + From 9ca5815ec363c5fb2c9045e556fb0044019f3c4b Mon Sep 17 00:00:00 2001 From: geethkokila Date: Mon, 20 Jul 2015 16:47:25 +0530 Subject: [PATCH 08/10] Fixing the saving issues --- .../impl/PolicyAdministratorPointImpl.java | 3 +- .../policy/mgt/core/mgt/PolicyManager.java | 6 ++- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 44 ++++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 052199f4e0a..e6091c16900 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -21,7 +21,6 @@ package org.wso2.carbon.policy.mgt.core.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.policy.mgt.common.FeatureManagementException; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; @@ -130,7 +129,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException { - policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy.getId(), policy.getProfile().getProfileFeaturesList()); + policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy); } @Override diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java index 0aa8c11ac77..f398658df9a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/PolicyManager.java @@ -60,8 +60,10 @@ public interface PolicyManager { List getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException; - void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List profileFeatures) throws - PolicyManagementException; + void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List + profileFeatures) throws PolicyManagementException; + + void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException; boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 821b6ee187d..f80f6964fba 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -653,14 +653,15 @@ public class PolicyManagerImpl implements PolicyManager { } @Override - public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List profileFeatures) throws + public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, + List profileFeatures) throws PolicyManagementException { int deviceId = -1; try { int tenantId = PolicyManagerUtil.getTenantId(); Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); - deviceId = device.getId(); + deviceId = device.getId(); boolean exist = policyDAO.checkPolicyAvailable(deviceId); PolicyManagementDAOFactory.beginTransaction(); if (exist) { @@ -687,6 +688,45 @@ public class PolicyManagerImpl implements PolicyManager { } + @Override + public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws + PolicyManagementException { + + int deviceId = -1; + try { + int tenantId = PolicyManagerUtil.getTenantId(); + Device device = deviceDAO.getDevice(deviceIdentifier, tenantId); + deviceId = device.getId(); + boolean exist = policyDAO.checkPolicyAvailable(deviceId); + PolicyManagementDAOFactory.beginTransaction(); + if (exist) { + Policy policySaved = policyDAO.getAppliedPolicy(deviceId); + if (!policy.equals(policySaved)) { + policyDAO.updateEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile(). + getProfileFeaturesList()); + } + } else { + policyDAO.addEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile(). + getProfileFeaturesList()); + } + PolicyManagementDAOFactory.commitTransaction(); + } catch (PolicyManagerDAOException e) { + try { + PolicyManagementDAOFactory.rollbackTransaction(); + } catch (PolicyManagerDAOException e1) { + log.warn("Error occurred while roll backing the transaction."); + } + String msg = "Error occurred while adding the evaluated policy to device (" + + deviceId + " - " + policy.getId() + ")"; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")"; + log.error(msg, e); + throw new PolicyManagementException(msg, e); + } + } + @Override public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { From c4739efd0e10cf7806507a036032356193ad8ce7 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Mon, 20 Jul 2015 19:05:13 +0530 Subject: [PATCH 09/10] Fixing the policy monitoring service adding --- .../policy/mgt/common/spi/PolicyMonitoringService.java | 2 ++ .../mgt/core/internal/PolicyManagementServiceComponent.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java index c1ca58a291e..5494c0a942c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/spi/PolicyMonitoringService.java @@ -34,4 +34,6 @@ public interface PolicyMonitoringService { ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response) throws PolicyComplianceException; + + String getType(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 4ea26e0a1b7..f0b98fa6f6a 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -163,7 +163,8 @@ public class PolicyManagementServiceComponent { log.debug("Setting Policy Monitoring Service"); } // TODO: FIX THE device type by taking from properties - PolicyManagementDataHolder.getInstance().setPolicyMonitoringService("", policyMonitoringService); + PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(), + policyMonitoringService); } protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) { @@ -171,7 +172,7 @@ public class PolicyManagementServiceComponent { log.debug("Removing the Policy Monitoring Service"); } // TODO: FIX THE device type by taking from properties - PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(""); + PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType()); } protected void setTaskService(TaskService taskService) { From 00b93032830af47e99b9b563d2ef29cf0a40ae37 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 21 Jul 2015 10:26:24 +0530 Subject: [PATCH 10/10] Fixed the issue with java package name --- .../policy/mgt/common/{Monitor => monitor}/ComplianceData.java | 0 .../mgt/common/{Monitor => monitor}/ComplianceDecisionPoint.java | 0 .../policy/mgt/common/{Monitor => monitor}/ComplianceFeature.java | 0 .../common/{Monitor => monitor}/PolicyComplianceException.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{Monitor => monitor}/ComplianceData.java (100%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{Monitor => monitor}/ComplianceDecisionPoint.java (100%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{Monitor => monitor}/ComplianceFeature.java (100%) rename components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/{Monitor => monitor}/PolicyComplianceException.java (100%) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceData.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/ComplianceData.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceData.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/ComplianceData.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceDecisionPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/ComplianceDecisionPoint.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceDecisionPoint.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/ComplianceDecisionPoint.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceFeature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/ComplianceFeature.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/ComplianceFeature.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/ComplianceFeature.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/PolicyComplianceException.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/PolicyComplianceException.java similarity index 100% rename from components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/Monitor/PolicyComplianceException.java rename to components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/monitor/PolicyComplianceException.java