From a1f0ecbb6a2bea6aa214322c412af2f3c5ce124b Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 7 May 2014 17:33:13 +0200 Subject: Agent now extends Item, so they can have workflows. All traces of the old 'Entity' superclasses should be removed, including proxies and paths. Very large change, breaks API compatibility with CRISTAL 2.x. Fixes #135 --- src/main/idl/Entity.idl | 132 ++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 76 deletions(-) (limited to 'src/main/idl') diff --git a/src/main/idl/Entity.idl b/src/main/idl/Entity.idl index f94bdf4..2aa9188 100644 --- a/src/main/idl/Entity.idl +++ b/src/main/idl/Entity.idl @@ -21,7 +21,7 @@ module entity * in a tree structure. **/ - abstract interface ManageableEntity + interface Item { /** @@ -29,7 +29,24 @@ module entity **/ unsigned long getSystemKey(); - + /** Initialises a new Item. Initial properties and the lifecycle are supplied. They should come from the Item's description. + * + * @param agentId the Agent doing the initialisation + * @param itemProps The XML marshalled {@link com.c2kernel.Property.PropertyArrayList PropertyArrayList} containing the initial + * Property objects of the Item + * @param workflow The XML marshalled new lifecycle of the Item + * @param collection The XML marshalled CollectionArrayList of the initial state of the Item's collections + * @exception ObjectNotFoundException + **/ + void initialise( in unsigned long agentId, + in string itemProps, + in string workflow, + in string collections ) + raises( common::AccessRightsException, + common::InvalidDataException, + common::PersistencyException, + common::ObjectNotFoundException ); + /** * Returns a chunk of XML which may be a serialized C2KLocalObject, or in the case of Outcomes is merely a fragment of XML. * @@ -54,77 +71,6 @@ module entity raises( common::AccessRightsException, common::ObjectNotFoundException, common::PersistencyException ); - }; - - - /************************************************************************** - * Agent is a ManageableEntity that represents an Activity executor in the - * system. It holds a job list, which are persistent requests for execution - * from waiting activities assigned to a role that has such Job pushing enabled. - **************************************************************************/ - interface Agent : ManageableEntity - { - /** Initialises a new Agent. Should not be done by client processes - they - * should use an Agent factory such as a Server item. - * @param agentProps - XML marshalled {@link com.c2kernel.Property.PropertyArrayList PropertyArrayList} containing the initial - * Property objects of the Agent - * @throws AccessRightsException not yet implemented, reserved for future access control - * @throws InvalidDataException when the data supplied couldn't be unmarshalled - * @throws PersistencyException when there was a problem communicating with storage - **/ - void initialise( in string agentProps ) - raises( common::AccessRightsException, - common::InvalidDataException, - common::PersistencyException ); - - /** Supplies the new set of jobs for the given item and activity. The Agent should replace all existing jobs for that activity - * with the given set. This method should generally only be called by a workflow while performing an execution. - * - * @param sysKey the item which generated the jobs - * @param stepPath the activity within the lifecycle of the item which the jobs relate to - * @param newJobs an XML marshalled {@link com.c2kernel.entity.agent.JobArrayList JobArrayList} containing the new Jobs - **/ - void refreshJobList( in unsigned long sysKey, in string stepPath, in string newJobs ); - - /** Add this Agent to the given role - * @param roleName the new role to add - * @throws ObjectNotFoundException when the role doesn't exist - * @throws CannotManageException when an error occurs writing the data to LDAP - **/ - void addRole( in string roleName ) - raises( common::ObjectNotFoundException, - common::CannotManageException ); - - /** Remove this Agent from the given role - * @param the role name to remove - * @throws CannotManageException when an error occurs writing the data to LDAP - **/ - void removeRole( in string roleName ) - raises( common::ObjectNotFoundException, - common::CannotManageException ); - }; - - - /************************************************************************** - * Item is an ManageableEntity which has a lifecycle, and as a consequence - * generates Events, Outcomes and Viewpoints. - **************************************************************************/ - interface Item : ManageableEntity - { - /** Initialises a new Item. Initial properties and the lifecycle are supplied. They should come from the Item's description. - * - * @param agentId the Agent doing the initialisation - * @param itemProps The XML marshalled {@link com.c2kernel.Property.PropertyArrayList PropertyArrayList} containing the initial - * Property objects of the Agent - * @param workflow The XML marshalled new lifecycle of the Item - * @exception ObjectNotFoundException - **/ - void initialise( in unsigned long agentId, - in string itemProps, - in string workflow ) - raises( common::AccessRightsException, - common::InvalidDataException, - common::PersistencyException ); /** * Requests a transition of an Activity in this Item's workflow. If possible and permitted, an Event is @@ -158,7 +104,7 @@ module entity void requestAction( in unsigned long agentID, in string stepPath, in unsigned long transitionID, - in string requestData + in string requestData ) raises( common::AccessRightsException, common::InvalidTransitionException, @@ -184,10 +130,44 @@ module entity in boolean filter ) raises( common::AccessRightsException, common::ObjectNotFoundException, - common::PersistencyException ); + common::PersistencyException ); + }; + + /************************************************************************** + * Agent is a ManageableEntity that represents an Activity executor in the + * system. It holds a job list, which are persistent requests for execution + * from waiting activities assigned to a role that has such Job pushing enabled. + **************************************************************************/ + interface Agent : Item + { + + /** Supplies the new set of jobs for the given item and activity. The Agent should replace all existing jobs for that activity + * with the given set. This method should generally only be called by a workflow while performing an execution. + * + * @param sysKey the item which generated the jobs + * @param stepPath the activity within the lifecycle of the item which the jobs relate to + * @param newJobs an XML marshalled {@link com.c2kernel.entity.agent.JobArrayList JobArrayList} containing the new Jobs + **/ + void refreshJobList( in unsigned long sysKey, in string stepPath, in string newJobs ); + + /** Add this Agent to the given role + * @param roleName the new role to add + * @throws ObjectNotFoundException when the role doesn't exist + * @throws CannotManageException when an error occurs writing the data to LDAP + **/ + void addRole( in string roleName ) + raises( common::ObjectNotFoundException, + common::CannotManageException ); - }; //end of Item + /** Remove this Agent from the given role + * @param the role name to remove + * @throws CannotManageException when an error occurs writing the data to LDAP + **/ + void removeRole( in string roleName ) + raises( common::ObjectNotFoundException, + common::CannotManageException ); + }; }; //end of module entity -- cgit v1.2.3 From 62c7a46967e949304e6b242854526463aae7ee17 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 16 May 2014 10:38:32 +0200 Subject: item.request returns the final outcome, which may be modified during the execution (e.g. in the case of Predefined Steps). Fixes #136 --- src/main/idl/Entity.idl | 2 +- .../java/com/c2kernel/entity/ItemImplementation.java | 5 +++-- src/main/java/com/c2kernel/entity/TraceableEntity.java | 4 ++-- .../java/com/c2kernel/entity/agent/ActiveEntity.java | 4 ++-- .../java/com/c2kernel/entity/proxy/AgentProxy.java | 18 ++++++++++-------- src/main/java/com/c2kernel/entity/proxy/ItemProxy.java | 4 ++-- .../java/com/c2kernel/lifecycle/instance/Activity.java | 4 +++- .../c2kernel/lifecycle/instance/CompositeActivity.java | 4 ++-- .../java/com/c2kernel/lifecycle/instance/Workflow.java | 4 ++-- 9 files changed, 27 insertions(+), 22 deletions(-) (limited to 'src/main/idl') diff --git a/src/main/idl/Entity.idl b/src/main/idl/Entity.idl index 2aa9188..51884a3 100644 --- a/src/main/idl/Entity.idl +++ b/src/main/idl/Entity.idl @@ -101,7 +101,7 @@ module entity * @throws PersistencyException There was a problem committing the changes to storage. * @throws ObjectAlreadyExistsException Not normally thrown, but reserved for PredefinedSteps to throw if they need to. **/ - void requestAction( in unsigned long agentID, + string requestAction( in unsigned long agentID, in string stepPath, in unsigned long transitionID, in string requestData diff --git a/src/main/java/com/c2kernel/entity/ItemImplementation.java b/src/main/java/com/c2kernel/entity/ItemImplementation.java index e0d107a..b12e105 100644 --- a/src/main/java/com/c2kernel/entity/ItemImplementation.java +++ b/src/main/java/com/c2kernel/entity/ItemImplementation.java @@ -113,7 +113,7 @@ public class ItemImplementation implements ItemOperations { @Override - public void requestAction(int agentId, String stepPath, int transitionID, + public String requestAction(int agentId, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, @@ -128,7 +128,7 @@ public class ItemImplementation implements ItemOperations { Workflow lifeCycle = (Workflow) mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE + "/workflow", null); - lifeCycle.requestAction(agent, stepPath, mSystemKey, + String finalOutcome = lifeCycle.requestAction(agent, stepPath, mSystemKey, transitionID, requestData); // store the workflow if we've changed the state of the domain @@ -136,6 +136,7 @@ public class ItemImplementation implements ItemOperations { if (!(stepPath.startsWith("workflow/predefined"))) mStorage.put(mSystemKey, lifeCycle, null); + return finalOutcome; // Normal operation exceptions } catch (AccessRightsException ex) { Logger.msg("Propagating AccessRightsException back to the calling agent"); diff --git a/src/main/java/com/c2kernel/entity/TraceableEntity.java b/src/main/java/com/c2kernel/entity/TraceableEntity.java index ffd5859..a0980ee 100644 --- a/src/main/java/com/c2kernel/entity/TraceableEntity.java +++ b/src/main/java/com/c2kernel/entity/TraceableEntity.java @@ -111,7 +111,7 @@ public class TraceableEntity extends ItemPOA **************************************************************************/ //requestdata is xmlstring @Override - public void requestAction( int agentId, + public String requestAction( int agentId, String stepPath, int transitionID, String requestData @@ -124,7 +124,7 @@ public class TraceableEntity extends ItemPOA ObjectAlreadyExistsException { synchronized (this) { - mItemImpl.requestAction(agentId, stepPath, transitionID, requestData); + return mItemImpl.requestAction(agentId, stepPath, transitionID, requestData); } } diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java index c59b0fe..a799b62 100644 --- a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java +++ b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java @@ -120,14 +120,14 @@ public class ActiveEntity extends AgentPOA } @Override - public void requestAction(int agentID, String stepPath, int transitionID, + public String requestAction(int agentID, String stepPath, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, InvalidDataException, PersistencyException, ObjectAlreadyExistsException { synchronized (this) { - mAgentImpl.requestAction(agentID, stepPath, transitionID, requestData); + return mAgentImpl.requestAction(agentID, stepPath, transitionID, requestData); } } diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java index 29550d4..b6566a8 100644 --- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java @@ -82,7 +82,7 @@ public class AgentProxy extends ItemProxy * @param job - the job to execute * @throws ScriptErrorException */ - public void execute(ItemProxy item, Job job) + public String execute(ItemProxy item, Job job) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, @@ -152,12 +152,14 @@ public class AgentProxy extends ItemProxy job.setAgentId(getSystemKey()); Logger.msg(3, "AgentProxy - submitting job to item proxy"); - item.requestAction(job); + String result = item.requestAction(job); if (Logger.doLog(3)) { Date timeNow = new Date(); long secsNow = (timeNow.getTime()-startTime.getTime())/1000; Logger.msg(3, "Execution took "+secsNow+" seconds"); } + + return result; } private Object callScript(ItemProxy item, Job job) throws ScriptingEngineException { @@ -178,7 +180,7 @@ public class AgentProxy extends ItemProxy * @throws ObjectAlreadyExistsException * @throws ScriptErrorException */ - public void execute(Job job) + public String execute(Job job) throws AccessRightsException, InvalidDataException, InvalidTransitionException, @@ -189,13 +191,13 @@ public class AgentProxy extends ItemProxy { try { ItemProxy targetItem = Gateway.getProxyManager().getProxy(new ItemPath(job.getItemSysKey())); - execute(targetItem, job); + return execute(targetItem, job); } catch (InvalidItemPathException e) { throw new ObjectNotFoundException("Job contained invalid item sysKey: "+job.getItemSysKey(), ""); } } - public void execute(ItemProxy item, String predefStep, C2KLocalObject obj) + public String execute(ItemProxy item, String predefStep, C2KLocalObject obj) throws AccessRightsException, InvalidDataException, InvalidTransitionException, @@ -210,10 +212,10 @@ public class AgentProxy extends ItemProxy Logger.error(ex); throw new InvalidDataException("Error on marshall", ""); } - execute(item, predefStep, param); + return execute(item, predefStep, param); } - public void execute(ItemProxy item, String predefStep, String... params) + public String execute(ItemProxy item, String predefStep, String... params) throws AccessRightsException, InvalidDataException, InvalidTransitionException, @@ -221,7 +223,7 @@ public class AgentProxy extends ItemProxy PersistencyException, ObjectAlreadyExistsException { - item.getItem().requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params)); + return item.getItem().requestAction(getSystemKey(), "workflow/predefined/"+predefStep, PredefinedStep.DONE, PredefinedStep.bundleData(params)); } /** Wrappers for scripts */ diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java index f3a2f44..454da6d 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java @@ -158,7 +158,7 @@ public class ItemProxy /************************************************************************** * **************************************************************************/ - public void requestAction( Job thisJob ) + public String requestAction( Job thisJob ) throws AccessRightsException, InvalidTransitionException, ObjectNotFoundException, @@ -178,7 +178,7 @@ public class ItemProxy throw new InvalidDataException("No Agent specified.", ""); Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName()); - getItem().requestAction (thisJob.getAgentId(), thisJob.getStepPath(), + return getItem().requestAction (thisJob.getAgentId(), thisJob.getStepPath(), thisJob.getTransition().getId(), outcome); } diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java index 8e578c2..b86e200 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Activity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Activity.java @@ -129,7 +129,7 @@ public class Activity extends WfVertex /** cf Item request * @throws ObjectNotFoundException * @throws PersistencyException */ - public void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException + public String request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException { // Find requested transition @@ -203,6 +203,8 @@ public class Activity extends WfVertex //refresh all the job lists pushJobsToAgents(itemSysKey); + + return outcome; } protected String runActivityLogic(AgentPath agent, int itemSysKey, diff --git a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java index 016298f..e6d1bf9 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/CompositeActivity.java @@ -413,12 +413,12 @@ public class CompositeActivity extends Activity } @Override - public void request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException + public String request(AgentPath agent, int itemSysKey, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectNotFoundException, PersistencyException { if (getChildrenGraphModel().getStartVertex() != null && !getStateMachine().getState(state).isFinished() && transitionID == CompositeActivity.START) ((WfVertex) getChildrenGraphModel().getStartVertex()).run(agent, itemSysKey); - super.request(agent, itemSysKey, transitionID, requestData); + return super.request(agent, itemSysKey, transitionID, requestData); } public void refreshJobs(int itemSysKey) diff --git a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java index fa5e66b..8ff2fe2 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/Workflow.java @@ -99,12 +99,12 @@ public class Workflow extends CompositeActivity implements C2KLocalObject * @throws PersistencyException */ //requestData is xmlstring - public void requestAction(AgentPath agent, String stepPath, int itemSysKey, int transitionID, String requestData) + public String requestAction(AgentPath agent, String stepPath, int itemSysKey, int transitionID, String requestData) throws ObjectNotFoundException, AccessRightsException, InvalidTransitionException, InvalidDataException, ObjectAlreadyExistsException, PersistencyException { Logger.msg(3, "Action: " + transitionID + " " + stepPath + " by " + agent.getAgentName()); if (search(stepPath) != null) - ((Activity) search(stepPath)).request(agent, itemSysKey, transitionID, requestData); + return ((Activity) search(stepPath)).request(agent, itemSysKey, transitionID, requestData); else throw new ObjectNotFoundException(stepPath + " not found", ""); } -- cgit v1.2.3