|
|
@ -21,17 +21,16 @@ package org.wso2.carbon.policy.mgt.core.task;
|
|
|
|
|
|
|
|
|
|
|
|
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.EnrolmentInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
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.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.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
|
|
|
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.MonitoringManager;
|
|
|
|
import org.wso2.carbon.user.api.Tenant;
|
|
|
|
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -60,88 +59,69 @@ public class MonitoringTask implements Task {
|
|
|
|
log.debug("Monitoring task started to run.");
|
|
|
|
log.debug("Monitoring task started to run.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager();
|
|
|
|
|
|
|
|
List<String> deviceTypes = new ArrayList<>();
|
|
|
|
|
|
|
|
List<String> configDeviceTypes = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Tenant tenants[] = PolicyManagementDataHolder.getInstance().
|
|
|
|
deviceTypes = monitoringManager.getDeviceTypes();
|
|
|
|
getRealmService().getTenantManager().getAllTenants();
|
|
|
|
for (String deviceType : deviceTypes) {
|
|
|
|
|
|
|
|
if (isPlatformExist(deviceType)) {
|
|
|
|
for (Tenant tenant : tenants) {
|
|
|
|
configDeviceTypes.add(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
} catch (PolicyComplianceException e) {
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain());
|
|
|
|
log.error("Error occurred while getting the device types.");
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!deviceTypes.isEmpty()) {
|
|
|
|
MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager();
|
|
|
|
try {
|
|
|
|
List<String> deviceTypes = new ArrayList<>();
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService =
|
|
|
|
List<String> configDeviceTypes = new ArrayList<>();
|
|
|
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
|
|
|
try {
|
|
|
|
for (String deviceType : configDeviceTypes) {
|
|
|
|
deviceTypes = monitoringManager.getDeviceTypes();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
for (String deviceType : deviceTypes) {
|
|
|
|
log.debug("Running task for device type : " + deviceType);
|
|
|
|
if (isPlatformExist(deviceType)) {
|
|
|
|
|
|
|
|
configDeviceTypes.add(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (PolicyComplianceException e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while getting the device types.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!deviceTypes.isEmpty()) {
|
|
|
|
PolicyMonitoringManager monitoringService =
|
|
|
|
try {
|
|
|
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService()
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService =
|
|
|
|
.getPolicyMonitoringManager(deviceType);
|
|
|
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
|
|
|
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
|
|
|
|
for (String deviceType : configDeviceTypes) {
|
|
|
|
if (monitoringService != null && !devices.isEmpty()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
List<Device> notifiableDevices = new ArrayList<>();
|
|
|
|
log.debug("Running task for device type : " + deviceType);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Removing inactive and blocked devices from the list for the device type : " +
|
|
|
|
PolicyMonitoringManager monitoringService =
|
|
|
|
deviceType);
|
|
|
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService()
|
|
|
|
}
|
|
|
|
.getPolicyMonitoringManager(deviceType);
|
|
|
|
for (Device device : devices) {
|
|
|
|
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
|
|
|
|
|
|
|
|
if (monitoringService != null && !devices.isEmpty()) {
|
|
|
|
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
|
|
|
|
List<Device> notifiableDevices = new ArrayList<>();
|
|
|
|
if (status.equals(EnrolmentInfo.Status.BLOCKED) ||
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
status.equals(EnrolmentInfo.Status.REMOVED) ||
|
|
|
|
log.debug("Removing inactive and blocked devices from the list for the device type : " +
|
|
|
|
status.equals(EnrolmentInfo.Status.UNCLAIMED) ||
|
|
|
|
deviceType);
|
|
|
|
status.equals(EnrolmentInfo.Status.DISENROLLMENT_REQUESTED) ||
|
|
|
|
}
|
|
|
|
status.equals(EnrolmentInfo.Status.SUSPENDED)) {
|
|
|
|
for (Device device : devices) {
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
|
|
|
|
notifiableDevices.add(device);
|
|
|
|
if (status.equals(EnrolmentInfo.Status.BLOCKED) ||
|
|
|
|
|
|
|
|
status.equals(EnrolmentInfo.Status.REMOVED) ||
|
|
|
|
|
|
|
|
status.equals(EnrolmentInfo.Status.UNCLAIMED) ||
|
|
|
|
|
|
|
|
status.equals(EnrolmentInfo.Status.DISENROLLMENT_REQUESTED) ||
|
|
|
|
|
|
|
|
status.equals(EnrolmentInfo.Status.SUSPENDED)) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
notifiableDevices.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Following devices selected to send the notification for " + deviceType);
|
|
|
|
|
|
|
|
for (Device device : notifiableDevices) {
|
|
|
|
|
|
|
|
log.debug(device.getDeviceIdentifier());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!notifiableDevices.isEmpty()) {
|
|
|
|
|
|
|
|
monitoringManager.addMonitoringOperation(notifiableDevices);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
}
|
|
|
|
log.debug("Monitoring task running completed.");
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Following devices selected to send the notification for " + deviceType);
|
|
|
|
|
|
|
|
for (Device device : notifiableDevices) {
|
|
|
|
|
|
|
|
log.debug(device.getDeviceIdentifier());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while trying to run a task.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!notifiableDevices.isEmpty()) {
|
|
|
|
log.info("No device types registered currently. So did not run the monitoring task.");
|
|
|
|
monitoringManager.addMonitoringOperation(notifiableDevices);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Monitoring task running completed.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while trying to run a task.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
log.info("No device types registered currently. So did not run the monitoring task.");
|
|
|
|
log.error("Error occurred while trying to get the available tenants", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|