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