summaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-07-31 10:28:05 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-07-31 10:28:05 +0200
commit84c93e0d119f042b7eb903128441e23a4ed2ebd1 (patch)
tree987eb758a484ab646a3e9810a48181264559b3b8 /src/main/java/com
parente6d1b8be6e0ad57d47c1f60fa5fcd9315d6b28fe (diff)
CreateAgentFromDescription reverted to current Agent/Role mechanism
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java45
1 files changed, 28 insertions, 17 deletions
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 f311dc1..a7971f3 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
@@ -14,11 +14,12 @@ package com.c2kernel.lifecycle.instance.predefined.agent;
import com.c2kernel.common.AccessRightsException;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectAlreadyExistsException;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Logger;
@@ -34,27 +35,36 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
super();
}
- //requestdata is xmlstring
+ /**
+ * Params:
+ * <ol><li>1: new Agent name</li>
+ * <li>2...: Roles to assign to the agent. Must already exist.
+ * @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String)
+ */
@Override
protected String runActivityLogic(AgentPath agent, int itemSysKey,
int transitionID, String requestData) throws InvalidDataException {
String[] input = getDataList(requestData);
String newName = input[0];
- String domPath = input[1];
- String wfDefName = null;
- int wfDefVer = -1;
- if (input.length > 2) // override wf
- wfDefName = input[2];
Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
try {
+
+ if (input.length < 2)
+ 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]);
+ if (!thisRole.exists()) throw new InvalidDataException("Role "+input[i]+" does not exist");
+ }
+
// check if the path is already taken
- DomainPath context = new DomainPath(new DomainPath(domPath), newName);
- Logger.debug(8,"context "+context.getSysKey()+" "+context.getPath()+" "+context.getString());
- if (context.getSysKey()!=-1)
- throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
+ try {
+ Gateway.getLookup().getAgentPath(newName);
+ throw new ObjectAlreadyExistsException("The agent name " +newName+ " exists already.", "");
+ } catch (ObjectNotFoundException ex) { }
// generate new entity key
Logger.msg(6, "CreateItemFromDescription - Requesting new sysKey");
@@ -70,7 +80,6 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
ActiveEntity newAgent = (ActiveEntity)factory.createEntity(newAgentPath);
Gateway.getLookupManager().add(newAgentPath);
-
// initialise it with its properties and workflow
Logger.msg(3, "CreateItemFromDescription - Initializing Item");
@@ -78,14 +87,16 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
newAgent.initialise(
agent.getSysKey(),
Gateway.getMarshaller().marshall(getNewProperties(itemSysKey, newName, agent)),
- Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey, wfDefName, wfDefVer)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(itemSysKey)),
Gateway.getMarshaller().marshall(getNewCollections(itemSysKey))
);
+
+ // add roles if given
+
+ for(int i=1; i<input.length; i++) {
+ newAgent.addRole(input[i]);
+ }
- // add its domain path
- Logger.msg(3, "CreateItemFromDescription - Creating "+context);
- context.setEntity(newAgentPath);
- Gateway.getLookupManager().add(context);
return requestData;
} catch (Exception e) {
Logger.error(e);