Merge branch 'master' into 'master'

Fixing issue with task scheduler

See merge request entgra/carbon-device-mgt!33
revert-70aa11f8
Charitha Goonetilleke 6 years ago
commit 0e3f3bb2c7

@ -26,14 +26,23 @@ import java.util.Map;
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();
if (map.containsKey(tenantId)) {
return map.get(tenantId);
if (map.get(tenantId).containsKey(deviceType)) {
return map.get(tenantId).get(deviceType);
} else {
Map<String, Long> mp = new HashMap<>();
map.put(tenantId, mp);
return mp;
Map<String, Map<String, Long>> existingTenantMap = map.get(tenantId);
existingTenantMap.put(deviceType, taskMap);
return taskMap;
}
} else {
HashMap<String, Map<String, Long>> typeMap = new HashMap<>();
typeMap.put(deviceType, taskMap);
map.put(tenantId, typeMap);
return taskMap;
}
}

@ -39,6 +39,7 @@ public class DeviceDetailsRetrieverTask implements Task {
private String deviceType;
private boolean executeForTenants = false;
private final String IS_CLOUD = "is.cloud";
private DeviceManagementProviderService deviceManagementProviderService;
@Override
public void setProperties(Map<String, String> map) {
@ -51,7 +52,7 @@ public class DeviceDetailsRetrieverTask implements Task {
@Override
public void execute() {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance()
deviceManagementProviderService = DeviceManagementDataHolder.getInstance()
.getDeviceManagementProvider();
OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceManagementProviderService
.getDeviceMonitoringConfig(deviceType);
@ -96,7 +97,9 @@ public class DeviceDetailsRetrieverTask implements Task {
operationMonitoringTaskConfig);
//pass the configurations also from here, monitoring tasks
try {
if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) {
deviceTaskManager.addOperations();
}
} catch (DeviceMgtTaskException e) {
log.error("Error occurred while trying to add the operations to " +
"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.util.DeviceManagerUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class DeviceTaskManagerImpl implements DeviceTaskManager {
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
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;
public DeviceTaskManagerImpl(String deviceType,
@ -126,7 +122,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
List<String> opNames = new ArrayList<>();
Long milliseconds = System.currentTimeMillis();
int frequency = this.getTaskFrequency();
Map<String, Long> mp = Utils.getTenantedTaskOperationMap(map);
Map<String, Long> mp = Utils.getTenantedTaskOperationMap(map, deviceType);
for (MonitoringOperation top : monitoringOperations) {
if (!mp.containsKey(top.getTaskName())) {

Loading…
Cancel
Save