|
|
@ -22,25 +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.DeviceManagementException;
|
|
|
|
|
|
|
|
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.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;
|
|
|
@ -65,41 +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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
// Tenant tenants[] = DeviceManagementDataHolder.getInstance().
|
|
|
|
|
|
|
|
// getRealmService().getTenantManager().getAllTenants();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> tenants = DeviceManagementDataHolder.getInstance().
|
|
|
|
|
|
|
|
getDeviceManagementProvider().getDeviceEnrolledTenants();
|
|
|
|
|
|
|
|
for (Integer tenant : tenants) {
|
|
|
|
|
|
|
|
String tenantDomain = DeviceManagementDataHolder.getInstance().
|
|
|
|
|
|
|
|
getRealmService().getTenantManager().getDomain(tenant);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
|
|
|
|
|
|
|
|
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
|
|
|
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
|
|
|
operationMonitoringTaskConfig);
|
|
|
|
operationMonitoringTaskConfig);
|
|
|
|
//pass the configurations also from here, monitoring tasks
|
|
|
|
//pass the configurations also from here, monitoring tasks
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
deviceTaskManager.addOperations();
|
|
|
|
deviceTaskManager.addOperations();
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
log.error("Error occurred while trying to add the operations to " +
|
|
|
|
log.error(
|
|
|
|
"device to retrieve device details.", e);
|
|
|
|
"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);
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while trying to get the available tenants " +
|
|
|
|
|
|
|
|
"from device manager provider service.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|