From 9c5d6e82b5ce733cf23e4317e3bafaa42c2221ba Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 1 Oct 2014 21:09:06 +0200 Subject: Collection version support, stored as a new final component of the Collection path. Null version implies "last". --- .../lifecycle/instance/predefined/AddNewSlot.java | 10 +++-- .../agent/CreateAgentFromDescription.java | 26 ++++++----- .../predefined/item/CreateItemFromDescription.java | 52 ++++++++++------------ 3 files changed, 44 insertions(+), 44 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java index a482a43..facf7e1 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/AddNewSlot.java @@ -49,8 +49,9 @@ public class AddNewSlot extends PredefinedStep * Creates a new slot in the given aggregation, that holds instances of the given item description * * Params: - * 0 - collection name - * 1 - Item Description key (optional) + *
  1. Collection name
  2. + *
  3. Item Description key (optional)
  4. + *
*/ @Override protected String runActivityLogic(AgentPath agent, ItemPath item, @@ -64,9 +65,10 @@ public class AddNewSlot extends PredefinedStep String[] params = getDataList(requestData); if (Logger.doLog(3)) Logger.msg(3, "AddNewSlot: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + // resolve desc item path and version try { collName = params[0]; - if (params.length > 1 && params[1].length() > 0) descKey = new ItemPath(params[1]); + if (params.length > 1 && params[1].length() > 0) descKey = new ItemPath(params[1]); } catch (Exception e) { throw new InvalidDataException("AddNewSlot: Invalid parameters "+Arrays.toString(params), ""); } @@ -90,7 +92,7 @@ public class AddNewSlot extends PredefinedStep if (descKey != null) { PropertyDescriptionList propList; try { - propList = PropertyUtility.getPropertyDescriptionOutcome(descKey); + propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, "last"); } catch (ObjectNotFoundException e) { throw new InvalidDataException("AddNewSlot: Item "+descKey+" does not contain a PropertyDescription outcome to define a slot", ""); } 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 780c82e..26856e1 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 @@ -39,8 +39,11 @@ public class CreateAgentFromDescription extends CreateItemFromDescription /** * Params: - *
  1. 1: new Agent name
  2. - *
  3. 2...: Roles to assign to the agent. Must already exist. + *
    1. New Agent name
    2. + *
    3. Description version to use
    4. + *
    5. Comma-delimited Role names to assign to the agent. Must already exist.
    6. + *
    7. Initial properties to set in the new Agent
    8. + *
    * @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String) */ @Override @@ -49,19 +52,20 @@ public class CreateAgentFromDescription extends CreateItemFromDescription String[] input = getDataList(requestData); String newName = input[0]; + String descVer = input[1]; + String roles = input[2]; PropertyArrayList initProps = - input.length > 1?getInitProperties(input[1]):new PropertyArrayList(); + input.length > 3 ? getInitProperties(input[3]):new PropertyArrayList(); 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 2 ? input[2]:"last"; PropertyArrayList initProps = - input.length > 2?getInitProperties(input[2]):new PropertyArrayList(); + input.length > 3?getInitProperties(input[3]):new PropertyArrayList(); Logger.msg(1, "CreateItemFromDescription - Starting."); @@ -96,9 +95,9 @@ public class CreateItemFromDescription extends PredefinedStep newItem.initialise( agent.getSystemKey(), - Gateway.getMarshaller().marshall(getNewProperties(itemPath, initProps, newName, agent)), - Gateway.getMarshaller().marshall(getNewWorkflow(itemPath)), - Gateway.getMarshaller().marshall(getNewCollections(itemPath)) + Gateway.getMarshaller().marshall(getNewProperties(itemPath, descVer, initProps, newName, agent)), + Gateway.getMarshaller().marshall(getNewWorkflow(itemPath, descVer)), + Gateway.getMarshaller().marshall(getNewCollections(itemPath, descVer)) ); // add its domain path @@ -122,9 +121,9 @@ public class CreateItemFromDescription extends PredefinedStep } } - protected PropertyArrayList getNewProperties(ItemPath itemPath, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { + protected PropertyArrayList getNewProperties(ItemPath itemPath, String descVer, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException { // copy properties -- intend to create from propdesc - PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath); + PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath, descVer); PropertyArrayList props = pdList.instantiate(initProps); // set Name prop or create if not present boolean foundName = false; @@ -139,25 +138,20 @@ public class CreateItemFromDescription extends PredefinedStep return props; } - protected CompositeActivity getNewWorkflow(ItemPath itemPath) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException { - // loop through collections, collecting instantiated descriptions and finding the default workflow def - String[] collNames = Gateway.getStorage().getClusterContents(itemPath, ClusterStorage.COLLECTION); + protected CompositeActivity getNewWorkflow(ItemPath itemPath, String descVer) throws ClusterStorageException, ObjectNotFoundException, InvalidDataException { + // find the workflow def for the given description version + String wfDefName = null; Integer wfDefVer = null; - for (String collName : collNames) { - if (collName.equalsIgnoreCase("workflow")) { - Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName, null); - ArrayList members = thisCol.getMembers().list; - // get the first member from the wf collection - CollectionMember wfMember = members.get(0); - wfDefName = wfMember.resolveItem().getName(); - Object wfVerObj = wfMember.getProperties().get("Version"); - try { - wfDefVer = Integer.parseInt(wfVerObj.toString()); - } catch (NumberFormatException ex) { - throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), ""); - } - } - } + + Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/workflow/"+descVer, null); + CollectionMember wfMember = thisCol.getMembers().list.get(0); + wfDefName = wfMember.resolveItem().getName(); + Object wfVerObj = wfMember.getProperties().get("Version"); + try { + wfDefVer = Integer.parseInt(wfVerObj.toString()); + } catch (NumberFormatException ex) { + throw new InvalidDataException("Invalid workflow version number: "+wfVerObj.toString(), ""); + } // load workflow def if (wfDefName == null) @@ -175,14 +169,14 @@ public class CreateItemFromDescription extends PredefinedStep } } - protected CollectionArrayList getNewCollections(ItemPath itemPath) throws ClusterStorageException, ObjectNotFoundException { + protected CollectionArrayList getNewCollections(ItemPath itemPath, String descVer) throws ClusterStorageException, ObjectNotFoundException { // loop through collections, collecting instantiated descriptions and finding the default workflow def CollectionArrayList colls = new CollectionArrayList(); String[] collNames = Gateway.getStorage().getClusterContents(itemPath, ClusterStorage.COLLECTION); for (String collName : collNames) { - Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName, null); + Collection thisCol = (Collection)Gateway.getStorage().get(itemPath, ClusterStorage.COLLECTION+"/"+collName+"/"+descVer, null); if (thisCol instanceof CollectionDescription) { - CollectionDescription thisDesc = (CollectionDescription)thisCol; + CollectionDescription thisDesc = (CollectionDescription)thisCol; colls.put(thisDesc.newInstance()); } } -- cgit v1.2.3