From 273be79ca212bc4cee1e15ca5a3b0be656098c4f Mon Sep 17 00:00:00 2001 From: Harshan Liyanage Date: Thu, 20 Apr 2017 15:57:12 +0530 Subject: [PATCH] Resolving #695:Fix for Policy Delegation task is not starting for tenants in distributed setup --- .../impl/PolicyAdministratorPointImpl.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 73e21e03036..50d58c3bf48 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -144,33 +144,35 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { //Check whether the TaskType is already registered. If not we'll register it here. if (!registeredTaskTypes.contains(PolicyManagementConstants.DELEGATION_TASK_TYPE)) { taskService.registerTaskType(PolicyManagementConstants.DELEGATION_TASK_TYPE); - TaskInfo registeredTaskInfo = null; - // getTask method will throw a TaskException if the task is not registered. Hence we'll handle the - // exception and register the task. - try { - registeredTaskInfo = taskManager.getTask(taskName); - } catch (TaskException e) { + } + + TaskInfo registeredTaskInfo = null; + // getTask method will throw a TaskException if the task is not registered. Hence we'll handle the + // exception and register the task. + try { + registeredTaskInfo = taskManager.getTask(taskName); + } catch (TaskException e) { // No need of any specific logic to handle this exception as it is thrown if the task is not registered. - } finally { - // If registeredTaskInfo is null that means there's no registered delegation-task. - if (registeredTaskInfo == null) { - TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, - properties, triggerInfo); - taskManager.registerTask(taskInfo); - taskManager.scheduleTask(taskInfo.getName()); - } - } - } else { - if (!taskManager.isTaskScheduled(taskName)) { + } finally { + // If registeredTaskInfo is null that means there's no registered delegation-task. + if (registeredTaskInfo == null) { TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, - properties, triggerInfo); + properties, triggerInfo); + taskManager.registerTask(taskInfo); taskManager.scheduleTask(taskInfo.getName()); } else { - throw new PolicyManagementException("There is a task already running for policy changes. Please try " + - "to apply " + - "changes after few minutes."); + if (!taskManager.isTaskScheduled(taskName)) { + TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, + properties, triggerInfo); + taskManager.scheduleTask(taskInfo.getName()); + } else { + throw new PolicyManagementException("There is a task already running for policy changes. Please try " + + "to apply " + + "changes after few minutes."); + } } } + } catch (TaskException e) { String msg = "Error occurred while creating the policy delegation task for tenant " + PrivilegedCarbonContext.