Merge branch 'master' of https://gitlab.com/entgra/carbon-device-mgt into entgra-master

revert-70aa11f8
Charitha Goonetilleke 6 years ago
commit c3893d93bb

@ -26,14 +26,23 @@ import java.util.Map;
public class Utils { public class Utils {
public static Map<String, Long> getTenantedTaskOperationMap(Map<Integer, Map<String, Long>> map) { public static Map<String, Long> getTenantedTaskOperationMap(Map<Integer, Map<String, Map<String, Long>>> map,
String deviceType) {
Map<String, Long> taskMap = new HashMap<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
if (map.containsKey(tenantId)) { if (map.containsKey(tenantId)) {
return map.get(tenantId); if (map.get(tenantId).containsKey(deviceType)) {
return map.get(tenantId).get(deviceType);
} else {
Map<String, Map<String, Long>> existingTenantMap = map.get(tenantId);
existingTenantMap.put(deviceType, taskMap);
return taskMap;
}
} else { } else {
Map<String, Long> mp = new HashMap<>(); HashMap<String, Map<String, Long>> typeMap = new HashMap<>();
map.put(tenantId, mp); typeMap.put(deviceType, taskMap);
return mp; map.put(tenantId, typeMap);
return taskMap;
} }
} }

@ -39,6 +39,7 @@ public class DeviceDetailsRetrieverTask implements Task {
private String deviceType; private String deviceType;
private boolean executeForTenants = false; private boolean executeForTenants = false;
private final String IS_CLOUD = "is.cloud"; private final String IS_CLOUD = "is.cloud";
private DeviceManagementProviderService deviceManagementProviderService;
@Override @Override
public void setProperties(Map<String, String> map) { public void setProperties(Map<String, String> map) {
@ -51,7 +52,7 @@ public class DeviceDetailsRetrieverTask implements Task {
@Override @Override
public void execute() { public void execute() {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance() deviceManagementProviderService = DeviceManagementDataHolder.getInstance()
.getDeviceManagementProvider(); .getDeviceManagementProvider();
OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceManagementProviderService OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceManagementProviderService
.getDeviceMonitoringConfig(deviceType); .getDeviceMonitoringConfig(deviceType);
@ -96,7 +97,9 @@ public class DeviceDetailsRetrieverTask implements Task {
operationMonitoringTaskConfig); operationMonitoringTaskConfig);
//pass the configurations also from here, monitoring tasks //pass the configurations also from here, monitoring tasks
try { try {
deviceTaskManager.addOperations(); if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) {
deviceTaskManager.addOperations();
}
} catch (DeviceMgtTaskException e) { } catch (DeviceMgtTaskException e) {
log.error("Error occurred while trying to add the operations to " + log.error("Error occurred while trying to add the operations to " +
"device to retrieve device details.", e); "device to retrieve device details.", e);

@ -36,17 +36,13 @@ import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.device.mgt.core.task.Utils; import org.wso2.carbon.device.mgt.core.task.Utils;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class DeviceTaskManagerImpl implements DeviceTaskManager { public class DeviceTaskManagerImpl implements DeviceTaskManager {
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class); private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
private String deviceType; private String deviceType;
private static Map<Integer, Map<String, Long>> map = new HashMap<>(); static volatile Map<Integer, Map<String, Map<String, Long>>> map = new HashMap<>();
private OperationMonitoringTaskConfig operationMonitoringTaskConfig; private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
public DeviceTaskManagerImpl(String deviceType, public DeviceTaskManagerImpl(String deviceType,
@ -126,7 +122,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
List<String> opNames = new ArrayList<>(); List<String> opNames = new ArrayList<>();
Long milliseconds = System.currentTimeMillis(); Long milliseconds = System.currentTimeMillis();
int frequency = this.getTaskFrequency(); int frequency = this.getTaskFrequency();
Map<String, Long> mp = Utils.getTenantedTaskOperationMap(map); Map<String, Long> mp = Utils.getTenantedTaskOperationMap(map, deviceType);
for (MonitoringOperation top : monitoringOperations) { for (MonitoringOperation top : monitoringOperations) {
if (!mp.containsKey(top.getTaskName())) { if (!mp.containsKey(top.getTaskName())) {

Loading…
Cancel
Save