fixing EMM-1750

revert-70aa11f8
hasuniea 8 years ago
parent 790ca36443
commit 2128f08658

@ -19,7 +19,9 @@
package org.wso2.carbon.device.mgt.core.config.policy; package org.wso2.carbon.device.mgt.core.config.policy;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "PolicyConfiguration") @XmlRootElement(name = "PolicyConfiguration")
public class PolicyConfiguration { public class PolicyConfiguration {
@ -30,6 +32,7 @@ public class PolicyConfiguration {
private int maxRetries; private int maxRetries;
private int minRetriesToMarkUnreachable; private int minRetriesToMarkUnreachable;
private int minRetriesToMarkInactive; private int minRetriesToMarkInactive;
private List<String> platforms;
@XmlElement(name = "MonitoringClass", required = true) @XmlElement(name = "MonitoringClass", required = true)
public String getMonitoringClass() { public String getMonitoringClass() {
@ -85,4 +88,14 @@ public class PolicyConfiguration {
this.monitoringFrequency = monitoringFrequency; this.monitoringFrequency = monitoringFrequency;
} }
@XmlElementWrapper(name = "Platforms", required = true)
@XmlElement(name = "Platform", required = true)
public List<String> getPlatforms() {
return platforms;
}
public void setPlatforms(List<String> platforms) {
this.platforms = platforms;
}
} }

@ -23,6 +23,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
@ -59,8 +61,14 @@ public class MonitoringTask implements Task {
MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager();
List<String> deviceTypes = new ArrayList<>(); List<String> deviceTypes = new ArrayList<>();
List<String> configDeviceTypes = new ArrayList<>();
try { try {
deviceTypes = monitoringManager.getDeviceTypes(); deviceTypes = monitoringManager.getDeviceTypes();
for (String deviceType : deviceTypes) {
if (isPlatformExist(deviceType)) {
configDeviceTypes.add(deviceType);
}
}
} catch (PolicyComplianceException e) { } catch (PolicyComplianceException e) {
log.error("Error occurred while getting the device types."); log.error("Error occurred while getting the device types.");
} }
@ -68,7 +76,7 @@ public class MonitoringTask implements Task {
try { try {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementProviderService deviceManagementProviderService =
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); PolicyManagementDataHolder.getInstance().getDeviceManagementService();
for (String deviceType : deviceTypes) { for (String deviceType : configDeviceTypes) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Running task for device type : " + deviceType); log.debug("Running task for device type : " + deviceType);
} }
@ -82,6 +90,7 @@ public class MonitoringTask implements Task {
deviceType); deviceType);
} }
for (Device device : devices) { for (Device device : devices) {
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus(); EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
if (status.equals(EnrolmentInfo.Status.BLOCKED) || if (status.equals(EnrolmentInfo.Status.BLOCKED) ||
status.equals(EnrolmentInfo.Status.REMOVED) || status.equals(EnrolmentInfo.Status.REMOVED) ||
@ -116,4 +125,18 @@ public class MonitoringTask implements Task {
} }
} }
/**
* Check whether Device platform (ex: android) is exist in the cdm-config.xml file before adding a
* Monitoring operation to a specific device type.
*
* @param deviceType available device types.
* @return return platform is exist(true) or not (false).
*/
private boolean isPlatformExist(String deviceType) {
PolicyConfiguration policyConfiguration =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getPolicyConfiguration();
return (policyConfiguration.getPlatforms().contains(deviceType));
}
} }

@ -42,6 +42,11 @@
<MaxRetries>5</MaxRetries> <MaxRetries>5</MaxRetries>
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable> <MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive> <MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
<Platforms>
<Platform>android</Platform>
<Platform>ios</Platform>
<Platform>windows</Platform>
</Platforms>
</PolicyConfiguration> </PolicyConfiguration>
<TaskConfiguration> <TaskConfiguration>
<Enable>true</Enable> <Enable>true</Enable>

Loading…
Cancel
Save