Merge pull request #496 from madhawap/release-2.0.x

Task operation config related changes
4.x.x
Rasika Perera 8 years ago committed by GitHub
commit 6f7d87a590

@ -52,6 +52,6 @@ public class OperationMonitoringTaskConfig {
public void setMonitoringOperation(List<MonitoringOperation> monitoringOperation) {
this.monitoringOperation = monitoringOperation;
}
}
}

@ -195,7 +195,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
} else {
deviceTaskManagerService.startTask(deviceManagementService.getType(),
operationMonitoringTaskConfig);
// TODO: In here a race condition can arise. Need to handle it.
}
}
} catch (DeviceMgtTaskException e) {

@ -58,11 +58,11 @@ public class DeviceTaskManagerServiceComponent {
log.debug("Initializing device details retrieving task manager bundle.");
}
// This will start the device details retrieving task.
// DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
// DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(
// deviceTaskManagerService);
// componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
// deviceTaskManagerService, null);
// DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
// DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(
// deviceTaskManagerService);
// componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
// deviceTaskManagerService, null);
getDeviceOperationMonitoringConfig(componentContext);
@ -76,12 +76,12 @@ public class DeviceTaskManagerServiceComponent {
}
}
private void getDeviceOperationMonitoringConfig(ComponentContext componentContext) throws DeviceMgtTaskException {
private void getDeviceOperationMonitoringConfig(ComponentContext componentContext)
throws DeviceMgtTaskException {
DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(
deviceTaskManagerService);
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManagerService);
componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
deviceTaskManagerService, null);
@ -89,11 +89,10 @@ public class DeviceTaskManagerServiceComponent {
Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder
.getInstance().getOperationMonitoringConfigFromMap();
for (String platformType : new ArrayList<String>(deviceConfigMap.keySet())) {
for (String platformType : new ArrayList<>(deviceConfigMap.keySet())) {
deviceTaskManagerService.startTask(platformType, deviceConfigMap.get(platformType));
deviceConfigMap.remove(platformType);
}
}
@SuppressWarnings("unused")

@ -1222,17 +1222,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public List<MonitoringOperation> getMonitoringOperationList(String deviceType) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
// Map<DeviceTypeIdentifier, DeviceManagementService> deviceManagementServiceMap =
// pluginRepository.getAllDeviceManagementServices(tenantId);
DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId);
// ;
// OperationMonitoringTaskConfig operationMonitoringTaskConfig;
//Map<String, List<MonitoringOperation>> deviceTypeSpecificMonitoringOperations = new HashMap<>();
// for(DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()){
// dms = deviceManagementServiceMap.get(dti);
//
// }
OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getOperationMonitoringConfig();
return operationMonitoringTaskConfig.getMonitoringOperation();
}

@ -19,8 +19,10 @@
package org.wso2.carbon.device.mgt.core.task.impl;
import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
import org.wso2.carbon.ntask.core.Task;
@ -32,10 +34,18 @@ public class DeviceDetailsRetrieverTask implements Task {
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
private String deviceType;
private String oppConfig;
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
@Override
public void setProperties(Map<String, String> map) {
deviceType = map.get("DEVICE_TYPE");
oppConfig = map.get("OPPCONFIG");
Gson gson = new Gson();
operationMonitoringTaskConfig = gson.fromJson(oppConfig,
OperationMonitoringTaskConfig.class);
}
@Override
@ -49,14 +59,18 @@ public class DeviceDetailsRetrieverTask implements Task {
log.debug("Device details retrieving task started to run.");
}
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType);
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);
log.error(
"Error occurred while trying to add the operations to device to retrieve device details.",
e);
}
}
}

@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
@ -46,30 +47,26 @@ 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<>();
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
public DeviceTaskManagerImpl(String deviceType,
OperationMonitoringTaskConfig operationMonitoringTaskConfig) {
this.operationMonitoringTaskConfig = operationMonitoringTaskConfig;
this.deviceType = deviceType;
}
public DeviceTaskManagerImpl(String deviceType) {
this.deviceType = deviceType;
}
//get device type specific operations
public List<MonitoringOperation> getOperationList() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.getMonitoringOperationList(
deviceType);//Get task list from each device type
private List<MonitoringOperation> getOperationList() throws DeviceMgtTaskException {
return operationMonitoringTaskConfig.getMonitoringOperation();
}
@Override
public int getTaskFrequency() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.getDeviceMonitoringFrequency(deviceType);
return operationMonitoringTaskConfig.getFrequency();
}
// @Override
@ -80,11 +77,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
@Override
public boolean isTaskEnabled() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType);
return operationMonitoringTaskConfig.isEnabled();
}
@ -149,13 +142,22 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
return opNames;
}
private List<MonitoringOperation> getOperationListforTask() throws DeviceMgtTaskException {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
.getInstance().
getDeviceManagementProvider();
return deviceManagementProviderService.getMonitoringOperationList(
deviceType);//Get task list from each device type
}
@Override
public boolean isTaskOperation(String opName) {
try {
List<MonitoringOperation> monitoringOperations = this.getOperationList();
List<MonitoringOperation> monitoringOperations = this.getOperationListforTask();
for (MonitoringOperation taop : monitoringOperations) {
if (taop.getTaskName().equalsIgnoreCase(opName)) {
return true;

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.core.task.impl;
import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -46,9 +47,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
private static Log log = LogFactory.getLog(DeviceTaskManagerServiceImpl.class);
@Override
public void startTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException {
// String TASK_NAME = deviceType;
public void startTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException {
log.info("Task adding for " + deviceType);
@ -60,45 +60,52 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
if (log.isDebugEnabled()) {
log.debug("Device details retrieving task is started for the tenant id " + tenantId);
// log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager
// .getTaskFrequency());
log.debug("Device details retrieving task is at frequency of : " + operationMonitoringTaskConfig
.getFrequency());
// log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager
// .getTaskFrequency());
log.debug(
"Device details retrieving task is at frequency of : " + operationMonitoringTaskConfig
.getFrequency());
}
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
// triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency());
// triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency());
triggerInfo.setIntervalMillis(operationMonitoringTaskConfig.getFrequency());
triggerInfo.setRepeatCount(-1);
Gson gson = new Gson();
String operationConfigs = gson.toJson(operationMonitoringTaskConfig);
Map<String, String> properties = new HashMap<>();
properties.put(TENANT_ID, String.valueOf(tenantId));
properties.put("DEVICE_TYPE", deviceType);
properties.put("OPPCONFIG", operationConfigs);
String taskName = deviceType + String.valueOf(tenantId);
if (!taskManager.isTaskScheduled(deviceType)) {
TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, triggerInfo);
TaskInfo taskInfo = new TaskInfo(taskName, TASK_CLASS, properties, triggerInfo);
taskManager.registerTask(taskInfo);
taskManager.rescheduleTask(taskInfo.getName());
} else {
throw new DeviceMgtTaskException("Device details retrieving task is already started for this tenant " +
tenantId);
throw new DeviceMgtTaskException(
"Device details retrieving task is already started for this tenant " + tenantId);
}
} catch (TaskException e) {
throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId, e);
throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId,
e);
}
}
@Override
public void stopTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException {
// String TASK_NAME = deviceType;
public void stopTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException {
try {
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
@ -108,18 +115,18 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
}
} catch (TaskException e) {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId, e);
throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId,
e);
}
}
@Override
public void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException {
// String TASK_NAME = deviceType;
public void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
// deviceTaskManager = new DeviceTaskManagerImpl();
// deviceTaskManager = new DeviceTaskManagerImpl();
try {
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
@ -134,21 +141,20 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
Map<String, String> properties = new HashMap<>();
properties.put(TENANT_ID, String.valueOf(tenantId));
TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties,
triggerInfo);
TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, triggerInfo);
taskManager.registerTask(taskInfo);
taskManager.rescheduleTask(taskInfo.getName());
} else {
throw new DeviceMgtTaskException("Device details retrieving task has not been started for this tenant " +
tenantId + ". Please start the task first.");
throw new DeviceMgtTaskException(
"Device details retrieving task has not been started for this tenant " +
tenantId + ". Please start the task first.");
}
} catch (TaskException e) {
throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId, e);
throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId,
e);
}
}
}

Loading…
Cancel
Save