summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-18 10:39:05 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-18 10:39:05 +0200
commit3743d182d99dbed9d2be84dc357f6839ffe4d2ec (patch)
tree7fe88768469f34601c494f5b027bd9c3a6d622e7 /src/main/java/com/c2kernel/lifecycle
parent1537f39761e11669335f6499474f23b11cf2cf38 (diff)
Hierarchical Roles. Fixes #199
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/Activity.java48
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java2
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java2
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java4
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java9
5 files changed, 41 insertions, 24 deletions
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<Path> 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<input.length; i++) {
- RolePath thisRole = new RolePath(input[i]);
+ RolePath thisRole = Gateway.getLookup().getRolePath(input[i]);
if (!thisRole.exists()) throw new InvalidDataException("Role "+input[i]+" does not exist");
}
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java
index 735a17d..8385453 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/RemoveAgent.java
@@ -36,7 +36,7 @@ public class RemoveAgent extends PredefinedStep {
//remove from roles
for (RolePath role: targetAgent.getRoles()) {
try {
- role.removeAgent(targetAgent);
+ Gateway.getLookupManager().removeRole(targetAgent, role);
} catch (ObjectCannotBeUpdated e) {
Logger.error(e);
throw new InvalidDataException("Error removing "+agentName+" from Role "+role.getName(), "");
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java
index 8cdcc49..0c2ed83 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/SetAgentRoles.java
@@ -52,7 +52,7 @@ public class SetAgentRoles extends PredefinedStep {
// remove roles not in new list
for (RolePath roleToRemove : rolesToRemove)
try {
- roleToRemove.removeAgent(targetAgent);
+ Gateway.getLookupManager().removeRole(targetAgent, roleToRemove);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error removing role "+roleToRemove.getName(), "");
@@ -61,7 +61,7 @@ public class SetAgentRoles extends PredefinedStep {
// add requested roles we don't already have
for (RolePath roleToAdd : requestedRoles)
try {
- roleToAdd.addAgent(targetAgent);
+ Gateway.getLookupManager().addRole(targetAgent, roleToAdd);
} catch (Exception e) {
Logger.error(e);
throw new InvalidDataException("Error adding role "+roleToAdd.getName(), "");
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java
index 44000c6..ec3071b 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/server/RemoveRole.java
@@ -42,22 +42,21 @@ public class RemoveRole extends PredefinedStep
throw new InvalidDataException(e.getMessage(), "");
}
- RolePath thisRole;
+ RolePath thisRole; AgentPath[] agents;
try {
thisRole = lookup.getRolePath(params[0]);
+ agents = Gateway.getLookup().getAgents(thisRole);
} catch (ObjectNotFoundException e) {
throw new InvalidDataException("Role "+params[0]+" not found.", "");
}
- AgentPath[] agents = thisRole.getAgentsWithRole();
+
if (agents.length > 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;