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