summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-10-03 17:30:41 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-10-03 17:30:41 +0200
commit275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 (patch)
treeddcc6b14077d90d1b970b67829f07120547dbb62 /src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
parenta139f95bfeca603333b8c0310ae09c6805e58584 (diff)
Huge exception overhaul: Merged ClusterStorageException with
PersistencyException. Replaced MembershipException with InvalidCollectionModification CORBA Exception. Made all predef steps throw more accurate exceptions when they go wrong, and let more exceptions bubble through from underneath.
Diffstat (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java')
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java123
1 files changed, 68 insertions, 55 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 0ce7c67..564c5db 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
@@ -20,10 +20,14 @@
*/
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 java.util.Arrays;
+
+import com.c2kernel.common.CannotManage;
+import com.c2kernel.common.InvalidData;
+import com.c2kernel.common.ObjectAlreadyExists;
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFound;
+import com.c2kernel.common.PersistencyException;
import com.c2kernel.entity.CorbaServer;
import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription;
@@ -53,71 +57,80 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
* <li>Comma-delimited Role names to assign to the agent. Must already exist.</li>
* <li>Initial properties to set in the new Agent</li>
* </ol>
+ * @throws ObjectNotFound
+ * @throws InvalidData The input parameters were incorrect
+ * @throws ObjectAlreadyExists The Agent already exists
+ * @throws CannotManage The Agent could not be created
+ * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed
* @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String)
*/
@Override
- protected String runActivityLogic(AgentPath agent, ItemPath itemPath,
- int transitionID, String requestData) throws InvalidDataException {
+ protected String runActivityLogic(AgentPath agent, ItemPath item,
+ int transitionID, String requestData) throws ObjectNotFound, InvalidData, ObjectAlreadyExists, CannotManage, ObjectCannotBeUpdated {
+
+ String[] params = getDataList(requestData);
+ if (Logger.doLog(3)) Logger.msg(3, "CreateAgentFromDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params));
+ if (params.length < 3 || params.length > 4)
+ throw new InvalidData("CreateAgentFromDescription: Invalid parameters "+Arrays.toString(params));
- String[] input = getDataList(requestData);
- String newName = input[0];
- String descVer = input[1];
- String roles = input[2];
+ String newName = params[0];
+ String descVer = params[1];
+ String roles = params[2];
PropertyArrayList initProps =
- input.length > 3 ? getInitProperties(input[3]):new PropertyArrayList();
+ params.length > 3 ? getInitProperties(params[3]):new PropertyArrayList();
Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
- try {
-
- // check if given roles exist
- String[] roleArr = roles.split(",");
- for(int i=0; i<roleArr.length; i++) {
- RolePath thisRole = Gateway.getLookup().getRolePath(roleArr[i]);
- if (!thisRole.exists()) throw new InvalidDataException("Role "+roleArr[i]+" does not exist");
- }
-
- // check if the path is already taken
- 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 agent path");
- AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
+ // check if given roles exist
+ String[] roleArr = roles.split(",");
+ for(int i=0; i<roleArr.length; i++) {
+ RolePath thisRole = Gateway.getLookup().getRolePath(roleArr[i]);
+ }
+
+ // check if the path is already taken
+ try {
+ Gateway.getLookup().getAgentPath(newName);
+ throw new ObjectAlreadyExists("The agent name " +newName+ " exists already.");
+ } catch (ObjectNotFound ex) { }
- // resolve the item factory
- Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
+ // generate new entity key
+ Logger.msg(6, "CreateItemFromDescription - Requesting new agent path");
+ AgentPath newAgentPath = new AgentPath(new ItemPath(), newName);
- // create the Item object
- Logger.msg(3, "CreateItemFromDescription - Creating Item");
- CorbaServer factory = Gateway.getCorbaServer();
- if (factory == null) throw new AccessRightsException("This process cannot create new Items", "");
- ActiveEntity newAgent = factory.createAgent(newAgentPath);
- Gateway.getLookupManager().add(newAgentPath);
+ // resolve the item factory
+ Logger.msg(6, "CreateItemFromDescription - Resolving item factory");
- // initialise it with its properties and workflow
+ // create the Item object
+ Logger.msg(3, "CreateItemFromDescription - Creating Item");
+ CorbaServer factory = Gateway.getCorbaServer();
+ if (factory == null) throw new CannotManage("This process cannot create new Items");
+ ActiveEntity newAgent = factory.createAgent(newAgentPath);
+ Gateway.getLookupManager().add(newAgentPath);
- Logger.msg(3, "CreateItemFromDescription - Initializing Item");
+ // initialise it with its properties and workflow
- newAgent.initialise(
- agent.getSystemKey(),
- Gateway.getMarshaller().marshall(getNewProperties(itemPath, descVer, initProps, newName, agent)),
- Gateway.getMarshaller().marshall(getNewWorkflow(itemPath, descVer)),
- Gateway.getMarshaller().marshall(getNewCollections(itemPath, descVer))
- );
-
- // add roles if given
-
- for(int i=1; i<input.length; i++) {
- newAgent.addRole(input[i]);
- }
+ Logger.msg(3, "CreateItemFromDescription - Initializing Item");
- return requestData;
- } catch (Exception e) {
- Logger.error(e);
- throw new InvalidDataException(e.getMessage(), "");
+ try {
+ newAgent.initialise(
+ agent.getSystemKey(),
+ Gateway.getMarshaller().marshall(getNewProperties(item, descVer, initProps, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewWorkflow(item, descVer)),
+ Gateway.getMarshaller().marshall(getNewCollections(item, descVer))
+ );
+ } catch (PersistencyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e) {
+ throw new InvalidData("CreateAgentFromDescription: Problem initializing new Agent. See log: "+e.getMessage());
+ }
+
+ // add roles if given
+
+ for(int i=1; i<roleArr.length; i++) {
+ newAgent.addRole(roleArr[i]);
}
+
+ return requestData;
}
}