|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|