Improvements to policy monitoring framework

This fixes the isseu where policy monitoring is configured per device type, they were not used. With this fix, main policy monitoring config is with cdm-config.xml and per device type can be enabled separately in the device type related xml file.
revert-70aa11f8
geethkokila 7 years ago
parent d8caf3baea
commit 1a957666e3

@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -52,4 +53,6 @@ public interface DeviceManagementService {
DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig(); DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig();
GeneralConfig getGeneralConfig();
} }

@ -522,6 +522,8 @@ public interface DeviceManagementProviderService {
List<String> getAvailableDeviceTypes() throws DeviceManagementException; List<String> getAvailableDeviceTypes() throws DeviceManagementException;
List<String> getPolicyMonitoringEnableDeviceTypes() throws DeviceManagementException;
boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException; boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException;
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException; boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;

@ -1177,6 +1177,29 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return deviceTypesResponse; return deviceTypesResponse;
} }
@Override
public List<String> getPolicyMonitoringEnableDeviceTypes() throws DeviceManagementException {
List<String> deviceTypes = this.getAvailableDeviceTypes();
List<String> deviceTyepsToMonitor = new ArrayList<>();
int tenantId = this.getTenantId();
Map<DeviceTypeServiceIdentifier, DeviceManagementService> registeredTypes =
pluginRepository.getAllDeviceManagementServices(tenantId);
List<DeviceManagementService> services = new ArrayList<>(registeredTypes.values());
for (DeviceManagementService deviceType : services) {
if (deviceType != null && deviceType.getGeneralConfig() != null &&
deviceType.getGeneralConfig().isPolicyMonitoringEnabled()) {
for (String type : deviceTypes) {
if (type.equalsIgnoreCase(deviceType.getType())) {
deviceTyepsToMonitor.add(type);
}
}
}
}
return deviceTyepsToMonitor;
}
@Override @Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException { public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
if (deviceId == null || device == null) { if (deviceId == null || device == null) {
@ -1489,13 +1512,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public List<Activity> getFilteredActivities(String operationCode, int limit, int offset) throws OperationManagementException{ public List<Activity> getFilteredActivities(String operationCode, int limit, int offset) throws OperationManagementException {
limit = DeviceManagerUtil.validateActivityListPageSize(limit); limit = DeviceManagerUtil.validateActivityListPageSize(limit);
return DeviceManagementDataHolder.getInstance().getOperationManager().getFilteredActivities(operationCode, limit, offset); return DeviceManagementDataHolder.getInstance().getOperationManager().getFilteredActivities(operationCode, limit, offset);
} }
@Override @Override
public int getTotalCountOfFilteredActivities(String operationCode) throws OperationManagementException{ public int getTotalCountOfFilteredActivities(String operationCode) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getTotalCountOfFilteredActivities(operationCode); return DeviceManagementDataHolder.getInstance().getOperationManager().getTotalCountOfFilteredActivities(operationCode);
} }
@ -2565,7 +2588,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.openConnection();
return deviceDAO.findGeoClusters(southWest,northEast,geohashLength,this.getTenantId()); return deviceDAO.findGeoClusters(southWest, northEast, geohashLength, this.getTenantId());
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving the geo clusters."; String msg = "Error occurred while retrieving the geo clusters.";
log.error(msg, e); log.error(msg, e);

@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.*;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -108,4 +109,9 @@ public class TestDeviceManagementService implements DeviceManagementService {
public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() { public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() {
return null; return null;
} }
@Override
public GeneralConfig getGeneralConfig() {
return null;
}
} }

@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -69,6 +70,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
private InitialOperationConfig initialOperationConfig; private InitialOperationConfig initialOperationConfig;
private PullNotificationSubscriber pullNotificationSubscriber; private PullNotificationSubscriber pullNotificationSubscriber;
private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig;
private GeneralConfig generalConfig;
public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, public DeviceTypeManagerService(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier,
DeviceTypeConfiguration deviceTypeConfiguration) { DeviceTypeConfiguration deviceTypeConfiguration) {
@ -84,6 +86,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
this.setDeviceStatusTaskPluginConfig(deviceTypeConfiguration.getDeviceStatusTaskConfiguration()); this.setDeviceStatusTaskPluginConfig(deviceTypeConfiguration.getDeviceStatusTaskConfiguration());
this.setPolicyMonitoringManager(deviceTypeConfiguration.getPolicyMonitoring()); this.setPolicyMonitoringManager(deviceTypeConfiguration.getPolicyMonitoring());
this.setPullNotificationSubscriber(deviceTypeConfiguration.getPullNotificationSubscriberConfig()); this.setPullNotificationSubscriber(deviceTypeConfiguration.getPullNotificationSubscriberConfig());
this.setGeneralConfig(deviceTypeConfiguration);
} }
@Override @Override
@ -92,7 +95,7 @@ public class DeviceTypeManagerService implements DeviceManagementService {
} }
@Override @Override
public OperationMonitoringTaskConfig getOperationMonitoringConfig(){ public OperationMonitoringTaskConfig getOperationMonitoringConfig() {
return operationMonitoringConfigs; return operationMonitoringConfigs;
} }
@ -193,6 +196,11 @@ public class DeviceTypeManagerService implements DeviceManagementService {
return deviceStatusTaskPluginConfig; return deviceStatusTaskPluginConfig;
} }
@Override
public GeneralConfig getGeneralConfig() {
return generalConfig;
}
private void setProvisioningConfig(String tenantDomain, DeviceTypeConfiguration deviceTypeConfiguration) { private void setProvisioningConfig(String tenantDomain, DeviceTypeConfiguration deviceTypeConfiguration) {
if (deviceTypeConfiguration.getProvisioningConfig() != null) { if (deviceTypeConfiguration.getProvisioningConfig() != null) {
boolean sharedWithAllTenants = deviceTypeConfiguration.getProvisioningConfig().isSharedWithAllTenants(); boolean sharedWithAllTenants = deviceTypeConfiguration.getProvisioningConfig().isSharedWithAllTenants();
@ -264,4 +272,12 @@ public class DeviceTypeManagerService implements DeviceManagementService {
} }
} }
} }
public void setGeneralConfig(DeviceTypeConfiguration deviceTypeConfiguration) {
this.generalConfig = new GeneralConfig();
if (deviceTypeConfiguration.getPolicyMonitoring() != null) {
this.generalConfig.setPolicyMonitoringEnabled(deviceTypeConfiguration.getPolicyMonitoring().isEnabled());
}
}
} }

@ -33,7 +33,7 @@ public class InitialOperationConfig {
return operations; return operations;
} }
public void setOperationsll(List<String> operations) { public void setOperations(List<String> operations) {
this.operations = operations; this.operations = operations;
} }
} }

@ -52,6 +52,9 @@ public class PolicyMonitoring {
protected String value; protected String value;
@XmlAttribute(name = "enabled") @XmlAttribute(name = "enabled")
protected boolean enabled; protected boolean enabled;
// protected String policyEvaluationPoint;
// protected String cacheEnable;
/** /**
* Gets the value of the value property. * Gets the value of the value property.

@ -33,6 +33,7 @@ import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -76,6 +77,7 @@ public class DeviceTypeManagerServiceTest {
private Method populatePushNotificationConfig; private Method populatePushNotificationConfig;
private Method setPolicyMonitoringManager; private Method setPolicyMonitoringManager;
private Method setPullNotificationSubscriber; private Method setPullNotificationSubscriber;
private Method setGeneralConfig;
@BeforeClass @BeforeClass
public void setup() throws NoSuchMethodException, SAXException, JAXBException, ParserConfigurationException, public void setup() throws NoSuchMethodException, SAXException, JAXBException, ParserConfigurationException,
@ -102,10 +104,19 @@ public class DeviceTypeManagerServiceTest {
.getDeclaredMethod("setPullNotificationSubscriber", PullNotificationSubscriberConfig.class); .getDeclaredMethod("setPullNotificationSubscriber", PullNotificationSubscriberConfig.class);
setPullNotificationSubscriber.setAccessible(true); setPullNotificationSubscriber.setAccessible(true);
setGeneralConfig = DeviceTypeManagerService.class
.getDeclaredMethod("setGeneralConfig", DeviceTypeConfiguration.class);
setGeneralConfig.setAccessible(true);
Field deviceStatusTaskPluginConfig = DeviceTypeManagerService.class Field deviceStatusTaskPluginConfig = DeviceTypeManagerService.class
.getDeclaredField("deviceStatusTaskPluginConfig"); .getDeclaredField("deviceStatusTaskPluginConfig");
deviceStatusTaskPluginConfig.setAccessible(true); deviceStatusTaskPluginConfig.setAccessible(true);
Field generalConfig = DeviceTypeManagerService.class
.getDeclaredField("generalConfig");
generalConfig.setAccessible(true);
Field operationMonitoringConfigs = DeviceTypeManagerService.class Field operationMonitoringConfigs = DeviceTypeManagerService.class
.getDeclaredField("operationMonitoringConfigs"); .getDeclaredField("operationMonitoringConfigs");
operationMonitoringConfigs.setAccessible(true); operationMonitoringConfigs.setAccessible(true);

@ -30,6 +30,7 @@
</Feature> </Feature>
</Features> </Features>
<PolicyMonitoring enabled="false"/>
<ProvisioningConfig> <ProvisioningConfig>
<SharedWithAllTenants>true</SharedWithAllTenants> <SharedWithAllTenants>true</SharedWithAllTenants>
</ProvisioningConfig> </ProvisioningConfig>

@ -209,7 +209,12 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
List<ComplianceFeature> complianceFeatures = List<ComplianceFeature> complianceFeatures =
monitoringManager.checkPolicyCompliance(deviceIdentifier, response); monitoringManager.checkPolicyCompliance(deviceIdentifier, response);
return !(complianceFeatures == null || complianceFeatures.isEmpty()); if(complianceFeatures == null || complianceFeatures.isEmpty()) {
return true;
} else {
return false;
}
} }
@Override @Override

@ -242,6 +242,9 @@ public class MonitoringDAOImpl implements MonitoringDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;
NonComplianceData complianceData = new NonComplianceData(); NonComplianceData complianceData = new NonComplianceData();
// Setting the initial compliance status as true;
// complianceData.setStatus(true);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {

@ -20,6 +20,7 @@ package org.wso2.carbon.policy.mgt.core.mgt.impl;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
@ -92,19 +93,21 @@ public class MonitoringManagerImpl implements MonitoringManager {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
NonComplianceData cmd = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId()); NonComplianceData cmd = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo().getId());
complianceData = monitoringService.checkPolicyCompliance(deviceIdentifier, complianceData = monitoringService.checkPolicyCompliance(deviceIdentifier,
policy, deviceResponse); policy, deviceResponse);
if (cmd != null) {
complianceData.setId(cmd.getId());
complianceData.setPolicy(policy);
complianceFeatures = complianceData.getComplianceFeatures();
complianceData.setDeviceId(device.getId());
complianceData.setPolicyId(policy.getId());
}
complianceData.setId(cmd.getId());
complianceData.setPolicy(policy);
complianceFeatures = complianceData.getComplianceFeatures();
complianceData.setDeviceId(device.getId());
complianceData.setPolicyId(policy.getId());
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyComplianceException("Error occurred while opening a data source connection", e); throw new PolicyComplianceException("Error occurred while opening a data source connection", e);
} catch (MonitoringDAOException e) { } catch (MonitoringDAOException e) {
throw new PolicyComplianceException( throw new PolicyComplianceException(
"Unable to add the none compliance features to database for device " + "Unable to add the none compliance features to database for device " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e); deviceIdentifier.getId() + " - " + deviceIdentifier.getType(), e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }
@ -115,7 +118,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
try { try {
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
monitoringDAO.setDeviceAsNoneCompliance(device.getId(), device.getEnrolmentInfo().getId(), monitoringDAO.setDeviceAsNoneCompliance(device.getId(), device.getEnrolmentInfo().getId(),
policy.getId()); policy.getId());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Compliance status primary key " + complianceData.getId()); log.debug("Compliance status primary key " + complianceData.getId());
} }
@ -181,19 +184,19 @@ public class MonitoringManagerImpl implements MonitoringManager {
device = service.getDevice(deviceIdentifier, false); device = service.getDevice(deviceIdentifier, false);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PolicyComplianceException("Unable to retrieve device data for " + deviceIdentifier.getId() + throw new PolicyComplianceException("Unable to retrieve device data for " + deviceIdentifier.getId() +
" - " + deviceIdentifier.getType(), e); " - " + deviceIdentifier.getType(), e);
} }
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
NonComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo() NonComplianceData complianceData = monitoringDAO.getCompliance(device.getId(), device.getEnrolmentInfo()
.getId()); .getId());
if (complianceData == null || !complianceData.isStatus()) { if (complianceData != null && !complianceData.isStatus()) {
return false; return false;
} }
} catch (MonitoringDAOException e) { } catch (MonitoringDAOException e) {
throw new PolicyComplianceException("Unable to retrieve compliance status for " + deviceIdentifier.getId() + throw new PolicyComplianceException("Unable to retrieve compliance status for " + deviceIdentifier.getId() +
" - " + deviceIdentifier.getType(), e); " - " + deviceIdentifier.getType(), e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyComplianceException("Error occurred while opening a connection to the data source", e); throw new PolicyComplianceException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -204,7 +207,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
@Override @Override
public NonComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws public NonComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws
PolicyComplianceException { PolicyComplianceException {
NonComplianceData complianceData; NonComplianceData complianceData;
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
@ -218,11 +221,11 @@ public class MonitoringManagerImpl implements MonitoringManager {
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PolicyComplianceException("Unable to retrieve device data for " + deviceIdentifier.getId() + throw new PolicyComplianceException("Unable to retrieve device data for " + deviceIdentifier.getId() +
" - " + deviceIdentifier.getType(), e); " - " + deviceIdentifier.getType(), e);
} catch (MonitoringDAOException e) { } catch (MonitoringDAOException e) {
throw new PolicyComplianceException("Unable to retrieve compliance data for " + deviceIdentifier.getId() + throw new PolicyComplianceException("Unable to retrieve compliance data for " + deviceIdentifier.getId() +
" - " + deviceIdentifier.getType(), e); " - " + deviceIdentifier.getType(), e);
} catch (SQLException e) { } catch (SQLException e) {
throw new PolicyComplianceException("Error occurred while opening a connection to the data source", e); throw new PolicyComplianceException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -288,10 +291,10 @@ public class MonitoringManagerImpl implements MonitoringManager {
if (complianceData.getAttempts() == 0) { if (complianceData.getAttempts() == 0) {
deviceIdsToAddOperation.put(complianceData.getDeviceId(), deviceIdsToAddOperation.put(complianceData.getDeviceId(),
deviceIds.get(complianceData.getDeviceId())); deviceIds.get(complianceData.getDeviceId()));
} else { } else {
deviceIdsWithExistingOperation.put(complianceData.getDeviceId(), deviceIdsWithExistingOperation.put(complianceData.getDeviceId(),
deviceIds.get(complianceData.getDeviceId())); deviceIds.get(complianceData.getDeviceId()));
} }
} }
} }
@ -315,7 +318,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
log.debug("These devices are in the system for the first time"); log.debug("These devices are in the system for the first time");
for (PolicyDeviceWrapper wrapper : firstTimeDevices) { for (PolicyDeviceWrapper wrapper : firstTimeDevices) {
log.debug("First time device primary key : " + wrapper.getDeviceId() + " & policy id " + log.debug("First time device primary key : " + wrapper.getDeviceId() + " & policy id " +
wrapper.getPolicyId()); wrapper.getPolicyId());
} }
} }
@ -358,11 +361,11 @@ public class MonitoringManagerImpl implements MonitoringManager {
List<String> deviceTypes = new ArrayList<>(); List<String> deviceTypes = new ArrayList<>();
try { try {
//when shutdown, it sets DeviceManagementService to null, therefore need to have a null check //when shutdown, it sets DeviceManagementService to null, therefore need to have a null check
if (PolicyManagementDataHolder.getInstance().getDeviceManagementService() != null) { if (PolicyManagementDataHolder.getInstance().getDeviceManagementService() != null) {
deviceTypes = deviceTypes =
PolicyManagementDataHolder.getInstance().getDeviceManagementService().getAvailableDeviceTypes(); PolicyManagementDataHolder.getInstance().getDeviceManagementService().getPolicyMonitoringEnableDeviceTypes();
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
throw new PolicyComplianceException("Error occurred while getting the device types.", e); throw new PolicyComplianceException("Error occurred while getting the device types.", e);
} }

@ -46,6 +46,8 @@ import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask; import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; 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.mock.TypeXDeviceManagementService; import org.wso2.carbon.policy.mgt.core.mock.TypeXDeviceManagementService;
import org.wso2.carbon.policy.mgt.core.task.MonitoringTask; import org.wso2.carbon.policy.mgt.core.task.MonitoringTask;
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
@ -232,7 +234,7 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
} }
@Test(dependsOnMethods = "applyPolicy") @Test(dependsOnMethods = "applyPolicy")
public void checkCompliance() throws PolicyComplianceException { public void checkCompliance() throws PolicyComplianceException, DeviceManagementException {
new MonitoringTask().execute(); new MonitoringTask().execute();
List<ComplianceFeature> complianceFeatures = new ArrayList<>(); List<ComplianceFeature> complianceFeatures = new ArrayList<>();
@ -246,6 +248,15 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
complianceFeature.setMessage("Test message"); complianceFeature.setMessage("Test message");
complianceFeature.setCompliance(true); complianceFeature.setCompliance(true);
complianceFeatures.add(complianceFeature); complianceFeatures.add(complianceFeature);
Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDevice(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), false);
List<Device> deviceList = new ArrayList<>();
deviceList.add(device);
MonitoringManager mm = new MonitoringManagerImpl();
mm.addMonitoringOperation(deviceList);
policyManagerService.checkCompliance(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), complianceFeatures); policyManagerService.checkCompliance(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), complianceFeatures);
boolean deviceCompliance = policyManagerService.isCompliant(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A)); boolean deviceCompliance = policyManagerService.isCompliant(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
@ -253,7 +264,7 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
} }
@Test(dependsOnMethods = "checkCompliance") @Test(dependsOnMethods = "checkCompliance")
public void checkNonCompliance() throws PolicyComplianceException { public void checkNonCompliance() throws PolicyComplianceException, DeviceManagementException {
new MonitoringTask().execute(); new MonitoringTask().execute();
List<ComplianceFeature> complianceFeatures = new ArrayList<>(); List<ComplianceFeature> complianceFeatures = new ArrayList<>();
@ -267,6 +278,17 @@ public class PolicyManagerServiceImplTest extends BasePolicyManagementDAOTest {
complianceFeature.setMessage("Test message"); complianceFeature.setMessage("Test message");
complianceFeature.setCompliance(false); complianceFeature.setCompliance(false);
complianceFeatures.add(complianceFeature); complianceFeatures.add(complianceFeature);
Device device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider().
getDevice(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), false);
List<Device> deviceList = new ArrayList<>();
deviceList.add(device);
MonitoringManager mm = new MonitoringManagerImpl();
mm.addMonitoringOperation(deviceList);
policyManagerService.checkCompliance(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), complianceFeatures); policyManagerService.checkCompliance(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A), complianceFeatures);
boolean deviceCompliance = policyManagerService.isCompliant(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A)); boolean deviceCompliance = policyManagerService.isCompliant(new DeviceIdentifier(DEVICE1, DEVICE_TYPE_A));
Assert.assertFalse(deviceCompliance, "Policy was compliant even though the response was not compliant"); Assert.assertFalse(deviceCompliance, "Policy was compliant even though the response was not compliant");

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.MonitoringOperation;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig; import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.general.GeneralConfig;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber; import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig; import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
@ -96,4 +97,9 @@ public class TypeXDeviceManagementService implements DeviceManagementService {
public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() { public DeviceStatusTaskPluginConfig getDeviceStatusTaskPluginConfig() {
return null; return null;
} }
@Override
public GeneralConfig getGeneralConfig() {
return null;
}
} }

Loading…
Cancel
Save