mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Revert 2988357eb9
This commit is contained in:
parent
4fdeec89cc
commit
a2d0c59e17
@ -22,23 +22,17 @@ package org.wso2.carbon.device.mgt.core.task.impl;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
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.OperationMonitoringTaskConfig;
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
||||||
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
||||||
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
||||||
import org.wso2.carbon.ntask.core.Task;
|
import org.wso2.carbon.ntask.core.Task;
|
||||||
import org.wso2.carbon.user.api.Tenant;
|
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DeviceDetailsRetrieverTask implements Task {
|
public class DeviceDetailsRetrieverTask implements Task {
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
|
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
|
||||||
// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
|
// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
|
||||||
private String deviceType;
|
private String deviceType;
|
||||||
private String oppConfig;
|
private String oppConfig;
|
||||||
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
|
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
|
||||||
@ -63,35 +57,18 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device details retrieving task started to run.");
|
log.debug("Device details retrieving task started to run.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
||||||
|
operationMonitoringTaskConfig);
|
||||||
|
//pass the configurations also from here, monitoring tasks
|
||||||
try {
|
try {
|
||||||
Tenant tenants[] = DeviceManagementDataHolder.getInstance().
|
deviceTaskManager.addOperations();
|
||||||
getRealmService().getTenantManager().getAllTenants();
|
} catch (DeviceMgtTaskException e) {
|
||||||
|
log.error(
|
||||||
for (Tenant tenant : tenants) {
|
"Error occurred while trying to add the operations to device to retrieve device details.",
|
||||||
|
e);
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain());
|
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId());
|
|
||||||
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
|
||||||
operationMonitoringTaskConfig);
|
|
||||||
//pass the configurations also from here, monitoring tasks
|
|
||||||
try {
|
|
||||||
deviceTaskManager.addOperations();
|
|
||||||
} catch (DeviceMgtTaskException e) {
|
|
||||||
log.error("Error occurred while trying to add the operations to " +
|
|
||||||
"device to retrieve device details.", e);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
log.error("Error occurred while trying to get the available tenants", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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();
|
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain());
|
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId());
|
|
||||||
|
|
||||||
MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager();
|
|
||||||
List<String> deviceTypes = new ArrayList<>();
|
|
||||||
List<String> configDeviceTypes = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
deviceTypes = monitoringManager.getDeviceTypes();
|
|
||||||
for (String deviceType : deviceTypes) {
|
|
||||||
if (isPlatformExist(deviceType)) {
|
|
||||||
configDeviceTypes.add(deviceType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (PolicyComplianceException e) {
|
|
||||||
log.error("Error occurred while getting the device types.");
|
|
||||||
}
|
|
||||||
if (!deviceTypes.isEmpty()) {
|
|
||||||
try {
|
|
||||||
DeviceManagementProviderService deviceManagementProviderService =
|
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
|
||||||
for (String deviceType : configDeviceTypes) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Running task for device type : " + deviceType);
|
|
||||||
}
|
|
||||||
PolicyMonitoringManager monitoringService =
|
|
||||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService()
|
|
||||||
.getPolicyMonitoringManager(deviceType);
|
|
||||||
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
|
|
||||||
if (monitoringService != null && !devices.isEmpty()) {
|
|
||||||
List<Device> notifiableDevices = new ArrayList<>();
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Removing inactive and blocked devices from the list for the device type : " +
|
|
||||||
deviceType);
|
|
||||||
}
|
|
||||||
for (Device device : devices) {
|
|
||||||
|
|
||||||
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
|
|
||||||
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.");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Error occurred while trying to run a task.", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.info("No device types registered currently. So did not run the monitoring task.");
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (PolicyComplianceException e) {
|
||||||
|
log.error("Error occurred while getting the device types.");
|
||||||
|
}
|
||||||
|
if (!deviceTypes.isEmpty()) {
|
||||||
|
try {
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService =
|
||||||
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
||||||
|
for (String deviceType : configDeviceTypes) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Running task for device type : " + deviceType);
|
||||||
|
}
|
||||||
|
PolicyMonitoringManager monitoringService =
|
||||||
|
PolicyManagementDataHolder.getInstance().getDeviceManagementService()
|
||||||
|
.getPolicyMonitoringManager(deviceType);
|
||||||
|
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
|
||||||
|
if (monitoringService != null && !devices.isEmpty()) {
|
||||||
|
List<Device> notifiableDevices = new ArrayList<>();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Removing inactive and blocked devices from the list for the device type : " +
|
||||||
|
deviceType);
|
||||||
|
}
|
||||||
|
for (Device device : devices) {
|
||||||
|
|
||||||
} catch (UserStoreException e) {
|
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
|
||||||
log.error("Error occurred while trying to get the available tenants", e);
|
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.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Error occurred while trying to run a task.", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("No device types registered currently. So did not run the monitoring task.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user