From 3743d182d99dbed9d2be84dc357f6839ffe4d2ec Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 18 Sep 2014 10:39:05 +0200 Subject: Hierarchical Roles. Fixes #199 --- .../com/c2kernel/lifecycle/instance/Activity.java | 48 +++++++++++++++------- .../agent/CreateAgentFromDescription.java | 2 +- .../instance/predefined/agent/RemoveAgent.java | 2 +- .../instance/predefined/agent/SetAgentRoles.java | 4 +- .../instance/predefined/server/RemoveRole.java | 9 ++-- 5 files changed, 41 insertions(+), 24 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index 95e0ede..3dd94b0 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java @@ -1,5 +1,6 @@ package com.c2kernel.lifecycle.instance; import java.util.ArrayList; +import java.util.Iterator; import java.util.Map; import java.util.Vector; @@ -21,6 +22,7 @@ import com.c2kernel.lifecycle.instance.stateMachine.Transition; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidAgentPathException; import com.c2kernel.lookup.ItemPath; +import com.c2kernel.lookup.Path; import com.c2kernel.lookup.RolePath; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.persistency.outcome.Outcome; @@ -203,7 +205,16 @@ public class Activity extends WfVertex DateUtility.setToNow(mStateDate); //refresh all the job lists - pushJobsToAgents(itemPath); + String agentRole = getCurrentAgentRole(); + if (agentRole != null && agentRole.length()>0) { + try { + RolePath myRole = Gateway.getLookup().getRolePath(agentRole); + pushJobsToAgents(itemPath, myRole); + } catch (ObjectNotFoundException ex) { // non-existent role + Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); + } + } + return outcome; } @@ -451,22 +462,29 @@ public class Activity extends WfVertex } return jobs; } - - public void pushJobsToAgents(ItemPath itemPath) - { - String agentRole = getCurrentAgentRole(); - if (agentRole == null || agentRole.length()==0) return; - RolePath myRole; - try { - myRole = Gateway.getLookup().getRolePath(agentRole); - } catch (ObjectNotFoundException ex) { // non-existent role - Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); - return; - } - if (myRole.hasJobList()) - new JobPusher(this, itemPath, myRole).start(); + public void pushJobsToAgents(ItemPath itemPath) { + String agentRole = getCurrentAgentRole(); + if (agentRole != null && agentRole.length()>0) { + try { + RolePath myRole = Gateway.getLookup().getRolePath(agentRole); + pushJobsToAgents(itemPath, myRole); + } catch (ObjectNotFoundException ex) { // non-existent role + Logger.msg(7, "Activity.pushJobsToAgents() - Activity role '"+agentRole+" not found."); + } + } + } + + public void pushJobsToAgents(ItemPath itemPath, RolePath role) + { + if (role.hasJobList()) + new JobPusher(this, itemPath, role).start(); + Iterator childRoles = role.getChildren(); + while (childRoles.hasNext()) { + RolePath childRole = (RolePath)childRoles.next(); + pushJobsToAgents(itemPath, childRole); + } } /** diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java index 520f70f..7683143 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -57,7 +57,7 @@ public class CreateAgentFromDescription extends CreateItemFromDescription throw new InvalidDataException("Agent should have at least one Role defined on creation"); // check if given roles exist for(int i=1; i 0) throw new InvalidDataException("Cannot remove role. "+agents.length+" agents still hold it.", ""); try { - lookup.removeRole(agent, thisRole); + lookup.delete(thisRole); } catch (ObjectCannotBeUpdated e) { Logger.error(e); throw new InvalidDataException("Role "+params[0]+" could not be removed.", ""); - } catch (ObjectNotFoundException e) { - throw new InvalidDataException("Role "+params[0]+" not found.", ""); } return requestData; -- cgit v1.2.3