From d048913e068972cb21157391483f8545e6bfb100 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Mon, 13 Jul 2015 10:55:27 +0530 Subject: [PATCH] Adding the momitoring task partialy --- .../mgt/common/Monitor/ComplianceData.java | 25 +++ .../Monitor/ComplianceDecisionPoint.java | 5 +- .../policy/mgt/common/ProfileFeature.java | 3 +- .../common/spi/PolicyMonitoringService.java | 3 +- .../policy/mgt/core/dao/MonitoringDAO.java | 6 +- .../mgt/core/dao/impl/MonitoringDAOImpl.java | 16 +- .../impl/ComplianceDecisionPointImpl.java | 170 +++++++++++++++++- .../core/mgt/impl/MonitoringManagerImpl.java | 10 +- .../policy/mgt/core/task/MonitoringTask.java | 30 +++- .../core/util/PolicyManagementConstants.java | 6 + .../mgt/core/util/PolicyManagerUtil.java | 2 + 11 files changed, 261 insertions(+), 15 deletions(-) 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 ea64f964179..5511604078e 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 @@ -19,6 +19,8 @@ package org.wso2.carbon.policy.mgt.common.monitor; +import org.wso2.carbon.policy.mgt.common.Policy; + import java.util.List; public class ComplianceData { @@ -30,6 +32,13 @@ public class ComplianceData { private boolean status; private String message; + /** + * This parameter is to inform the policy core, weather related device type plugins does need the full policy or + * the part which is none compliance. + */ + private boolean completePolicy; + private Policy policy; + public int getId() { return id; } @@ -77,4 +86,20 @@ public class ComplianceData { public void setMessage(String message) { this.message = message; } + + public boolean isCompletePolicy() { + return completePolicy; + } + + public void setCompletePolicy(boolean completePolicy) { + this.completePolicy = completePolicy; + } + + public Policy getPolicy() { + return policy; + } + + public void setPolicy(Policy policy) { + this.policy = policy; + } } 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 fa751528ab0..ada9b19a892 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 @@ -31,7 +31,8 @@ public interface ComplianceDecisionPoint { void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; - void reEnforcePolicy(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; + void reEnforcePolicy(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws + PolicyComplianceException; void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; @@ -41,7 +42,7 @@ public interface ComplianceDecisionPoint { void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException; - void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy) throws + void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws PolicyComplianceException; diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java index 9c677b72e9a..00e3b65d968 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/ProfileFeature.java @@ -19,10 +19,11 @@ package org.wso2.carbon.policy.mgt.common; import java.io.Serializable; -import org.wso2.carbon.device.mgt.common.Feature; public class ProfileFeature implements Serializable { + private static final long serialVersionUID = 19981018L; + private int id; private String featureCode; private int profileId; 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 890a72aaee0..81478b6ba47 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 @@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common.spi; 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; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.Policy; @@ -31,6 +32,6 @@ public interface PolicyMonitoringService { void notifyDevices(List devices) throws PolicyComplianceException; - List checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response) + ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response) throws PolicyComplianceException; } 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 a29928f8c4c..426935e4e0a 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 @@ -37,5 +37,9 @@ public interface MonitoringDAO { List getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException; - void deleteNoneComplianceData(int deviceId) throws MonitoringDAOException; + void deleteNoneComplianceData(int policyComplianceStatusId) throws MonitoringDAOException; + + void updateAttempts(int 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 8676709c093..e6bb638537f 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 @@ -80,9 +80,10 @@ public class MonitoringDAOImpl implements MonitoringDAO { PreparedStatement stmt = null; try { conn = this.getConnection(); - String query = "DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?"; + String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ? WHERE DEVICE_ID = ?"; stmt = conn.prepareStatement(query); - stmt.setInt(1, deviceId); + stmt.setInt(1, 1); + stmt.setInt(2, deviceId); stmt.executeUpdate(); @@ -193,15 +194,15 @@ public class MonitoringDAOImpl implements MonitoringDAO { } @Override - public void deleteNoneComplianceData(int deviceId) throws MonitoringDAOException { + public void deleteNoneComplianceData(int policyComplianceStatusId) throws MonitoringDAOException { Connection conn; PreparedStatement stmt = null; try { conn = this.getConnection(); - String query = "DELETE FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID = ?"; + String query = "DELETE FROM DM_POLICY_COMPLIANCE_FEATURES WHERE COMPLIANCE_STATUS_ID = ?"; stmt = conn.prepareStatement(query); - stmt.setInt(1, deviceId); + stmt.setInt(1, policyComplianceStatusId); stmt.executeUpdate(); } catch (SQLException e) { @@ -214,6 +215,11 @@ public class MonitoringDAOImpl implements MonitoringDAO { } + @Override + public void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException { + + } + private Connection getConnection() throws MonitoringDAOException { try { 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 313b4272767..5506bcb363c 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 @@ -21,15 +21,31 @@ 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.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +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.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; +import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; 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; public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { @@ -54,41 +70,191 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint { @Override public void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) 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(); + 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) { + String msg = "Error occurred while setting the device as reachable for " + + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } + } @Override - public void reEnforcePolicy(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException { + public void reEnforcePolicy(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws + PolicyComplianceException { + + try { + Policy policy = complianceData.getPolicy(); + if (policy != null) { + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); + + + List profileOperationList = new ArrayList(); + + PolicyOperation policyOperation = new PolicyOperation(); + policyOperation.setEnabled(true); + policyOperation.setType(Operation.Type.POLICY); + policyOperation.setCode(PolicyOperation.POLICY_OPERATION_CODE); + + + if (complianceData.isCompletePolicy()) { + List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); + + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation profileOperation = new ProfileOperation(); + profileOperation.setCode(feature.getFeatureCode()); + profileOperation.setEnabled(true); + profileOperation.setStatus(Operation.Status.PENDING); + profileOperation.setType(Operation.Type.PROFILE); + profileOperation.setPayLoad(feature.getContent()); + profileOperationList.add(profileOperation); + } + } else { + List noneComplianceFeatures = complianceData.getComplianceFeatures(); + for (ComplianceFeature feature : noneComplianceFeatures) { + ProfileOperation profileOperation = new ProfileOperation(); + + profileOperation.setCode(feature.getFeatureCode()); + profileOperation.setEnabled(true); + profileOperation.setStatus(Operation.Status.PENDING); + profileOperation.setType(Operation.Type.PROFILE); + profileOperation.setPayLoad(feature.getFeature().getContent()); + profileOperationList.add(profileOperation); + } + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setPayLoad(policyOperation.getProfileOperations()); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(policyOperation, deviceIdentifiers); + + } + + } catch (OperationManagementException e) { + String msg = "Error occurred while re-enforcing the policy to device " + deviceIdentifier.getId() + " - " + + deviceIdentifier.getType(); + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } } @Override 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); + + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while marking device as none compliance " + deviceIdentifier.getId() + " - " + + deviceIdentifier.getType(); + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } } @Override 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); + + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " + + deviceIdentifier.getType(); + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } + } @Override 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) { + String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " + + deviceIdentifier.getType(); + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } } @Override 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); + + } catch (DeviceManagementDAOException e) { + String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " + + deviceIdentifier.getType(); + log.error(msg, e); + throw new PolicyComplianceException(msg, e); + } } @Override - public void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy) throws + public void validateDevicePolicyCompliance(DeviceIdentifier deviceIdentifier, ComplianceData complianceData) throws PolicyComplianceException { + Policy policy = complianceData.getPolicy(); + String compliance = this.getNoneComplianceRule(policy); + + if (compliance.equals("")) { + String msg = "Compliance rule is empty for the policy " + policy.getPolicyName() + ". Therefore " + + "Monitoring Engine cannot run."; + throw new PolicyComplianceException(msg); + } + + if (PolicyManagementConstants.ENFORCE.equalsIgnoreCase(compliance)) { + this.reEnforcePolicy(deviceIdentifier, complianceData); + } + + if (PolicyManagementConstants.WARN.equalsIgnoreCase(compliance)) { + this.markDeviceAsNoneCompliance(deviceIdentifier); + } + + if (PolicyManagementConstants.BLOCK.equalsIgnoreCase(compliance)) { + this.markDeviceAsNoneCompliance(deviceIdentifier); + } } } 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 d5143122a32..37b3b6491d0 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 @@ -27,6 +27,7 @@ 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.policy.mgt.common.monitor.ComplianceData; +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.common.Policy; @@ -37,6 +38,7 @@ import org.wso2.carbon.policy.mgt.core.dao.MonitoringDAOException; import org.wso2.carbon.policy.mgt.core.dao.PolicyDAO; 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.impl.ComplianceDecisionPointImpl; 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; @@ -48,6 +50,7 @@ public class MonitoringManagerImpl implements MonitoringManager { private PolicyDAO policyDAO; private DeviceDAO deviceDAO; private MonitoringDAO monitoringDAO; + private ComplianceDecisionPoint complianceDecisionPoint; private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class); @@ -55,6 +58,7 @@ public class MonitoringManagerImpl implements MonitoringManager { this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO(); + this.complianceDecisionPoint = new ComplianceDecisionPointImpl(); } @Override @@ -71,13 +75,15 @@ public class MonitoringManagerImpl implements MonitoringManager { PolicyMonitoringService monitoringService = PolicyManagementDataHolder.getInstance(). getPolicyMonitoringService(deviceIdentifier.getType()); - complianceFeatures = monitoringService.checkPolicyCompliance(deviceIdentifier, + ComplianceData complianceData = monitoringService.checkPolicyCompliance(deviceIdentifier, policy, deviceResponse); + complianceData.setPolicy(policy); + complianceFeatures = complianceData.getComplianceFeatures(); if (!complianceFeatures.isEmpty()) { int complianceId = monitoringDAO.setDeviceAsNoneCompliance(device.getId(), policy.getId()); monitoringDAO.addNoneComplianceFeatures(complianceId, device.getId(), complianceFeatures); - + complianceDecisionPoint.validateDevicePolicyCompliance(deviceIdentifier, complianceData); List profileFeatures = policy.getProfile().getProfileFeaturesList(); for (ComplianceFeature compFeature : complianceFeatures) { for (ProfileFeature profFeature : profileFeatures) { 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 e68c55e921f..cf62d08b07c 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,12 +19,22 @@ package org.wso2.carbon.policy.mgt.core.task; +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; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; +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 java.util.List; import java.util.Map; public class MonitoringTask implements Task { + private DeviceTypeDAO deviceTypeDAO; + @Override public void setProperties(Map map) { @@ -32,11 +42,29 @@ public class MonitoringTask implements Task { @Override public void init() { - + deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); } @Override public void execute() { + try { + List deviceTypes = deviceTypeDAO.getDeviceTypes(); + + + DeviceManagementProviderService deviceManagementProviderService = + PolicyManagementDataHolder.getInstance().getDeviceManagementService(); + + for (DeviceType deviceType : deviceTypes) { + PolicyMonitoringService monitoringService = + PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType.getName()); + + List devices = deviceManagementProviderService.getAllDevices(deviceType.getName()); + monitoringService.notifyDevices(devices); + } + + } catch (Exception 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 fa390ffdb2c..477e9bcb322 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,4 +24,10 @@ public final class PolicyManagementConstants { public static final String ANY = "ANY"; public static final String POLICY_BUNDLE = "POLICY_BUNDLE"; + public static final String MONITOR = "MONITOR"; + public static final String ENFORCE = "ENFORCE"; + public static final String WARN = "WARN"; + public static final String BLOCK = "BLOCK"; + + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java index 8e2ca941d08..7cbcabeac07 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/util/PolicyManagerUtil.java @@ -98,4 +98,6 @@ public class PolicyManagerUtil { } return tenantId; } + + }