Updated task schedule service to fix EMM-1145, EMM-1100

revert-70aa11f8
harshanl 9 years ago
parent cbee88c7d0
commit 402b843e5d

@ -28,4 +28,6 @@ public interface TaskScheduleService {
void stopTask() throws PolicyMonitoringTaskException; void stopTask() throws PolicyMonitoringTaskException;
void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException; void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException;
boolean isTaskScheduled() throws PolicyMonitoringTaskException;
} }

@ -49,15 +49,13 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
@Override @Override
public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException { public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
int tenantId = getTenantId();
if (policyConfiguration.getMonitoringEnable()) { if (policyConfiguration.getMonitoringEnable()) {
if (monitoringFrequency <= 0) { if (monitoringFrequency <= 0) {
throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0."); throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0.");
} }
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
taskService.registerTaskType(PolicyManagementConstants.MONITORING_TASK_TYPE); taskService.registerTaskType(PolicyManagementConstants.MONITORING_TASK_TYPE);
@ -91,8 +89,7 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
} catch (TaskException e) { } catch (TaskException e) {
throw new PolicyMonitoringTaskException("Error occurred while creating the task for tenant " + throw new PolicyMonitoringTaskException("Error occurred while creating the task for tenant " +
PrivilegedCarbonContext. tenantId, e);
getThreadLocalCarbonContext().getTenantId(), e);
} }
} else { } else {
throw new PolicyMonitoringTaskException("Policy monitoring is not enabled in the cdm-config.xml."); throw new PolicyMonitoringTaskException("Policy monitoring is not enabled in the cdm-config.xml.");
@ -102,23 +99,22 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
@Override @Override
public void stopTask() throws PolicyMonitoringTaskException { public void stopTask() throws PolicyMonitoringTaskException {
int tenantId = getTenantId();
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId); String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE); TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
taskManager.deleteTask(taskName); taskManager.deleteTask(taskName);
} catch (TaskException e) { } catch (TaskException e) {
throw new PolicyMonitoringTaskException("Error occurred while deleting the task for tenant " + throw new PolicyMonitoringTaskException("Error occurred while deleting the task for tenant " +
PrivilegedCarbonContext. tenantId, e);
getThreadLocalCarbonContext().getTenantId(), e);
} }
} }
@Override @Override
public void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException { public void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
int tenantId = getTenantId();
try { try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId); String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE); TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
@ -144,10 +140,27 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
} }
} catch (TaskException e) { } catch (TaskException e) {
throw new PolicyMonitoringTaskException("Error occurred while updating the task for tenant " + throw new PolicyMonitoringTaskException("Error occurred while updating the task for tenant " + tenantId, e);
PrivilegedCarbonContext. }
getThreadLocalCarbonContext().getTenantId(), e);
}
@Override
public boolean isTaskScheduled() throws PolicyMonitoringTaskException {
int tenantId = getTenantId();
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
TaskManager taskManager;
try {
taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
return taskManager.isTaskScheduled(taskName);
} catch (TaskException e) {
throw new PolicyMonitoringTaskException("Error occurred while checking task for tenant " +
tenantId, e);
} }
}
private int getTenantId() {
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
} }
} }

Loading…
Cancel
Save