From e99ed30f6cae36c5f3fa03007d991e67894a01bb Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 23 Jul 2013 09:41:43 +0200 Subject: More --- .../java/com/c2kernel/entity/TraceableEntity.java | 6 +- .../com/c2kernel/entity/agent/ActiveEntity.java | 2 +- src/main/java/com/c2kernel/entity/agent/Job.java | 495 +++++++++++---------- .../java/com/c2kernel/entity/agent/JobList.java | 4 +- .../java/com/c2kernel/entity/proxy/AgentProxy.java | 15 +- .../java/com/c2kernel/entity/proxy/ItemProxy.java | 9 +- 6 files changed, 286 insertions(+), 245 deletions(-) (limited to 'src/main/java/com/c2kernel/entity') diff --git a/src/main/java/com/c2kernel/entity/TraceableEntity.java b/src/main/java/com/c2kernel/entity/TraceableEntity.java index 83c30a2..4152ab5 100644 --- a/src/main/java/com/c2kernel/entity/TraceableEntity.java +++ b/src/main/java/com/c2kernel/entity/TraceableEntity.java @@ -21,7 +21,6 @@ import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.agent.JobArrayList; import com.c2kernel.lifecycle.instance.CompositeActivity; import com.c2kernel.lifecycle.instance.Workflow; -import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.InvalidEntityPathException; import com.c2kernel.persistency.ClusterStorage; @@ -183,13 +182,14 @@ public class TraceableEntity extends ItemPOA try { Logger.msg(1, "TraceableEntity::request("+mSystemKey+") - " + - Transitions.getTransitionName(transitionID) + " "+stepPath + " by " +agentId ); + transitionID + " "+stepPath + " by " +agentId ); AgentPath agent = new AgentPath(agentId); Workflow lifeCycle = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); lifeCycle.requestAction( agent, stepPath, + mSystemKey, transitionID, requestData ); @@ -251,7 +251,7 @@ public class TraceableEntity extends ItemPOA Workflow wf = (Workflow)mStorage.get(mSystemKey, ClusterStorage.LIFECYCLE+"/workflow", null); JobArrayList jobBag = new JobArrayList(); CompositeActivity domainWf = (CompositeActivity)wf.search("workflow/domain"); - jobBag.list = filter?domainWf.calculateJobs(agent, true):domainWf.calculateAllJobs(agent, true); + jobBag.list = filter?domainWf.calculateJobs(agent, mSystemKey, true):domainWf.calculateAllJobs(agent, mSystemKey, true); Logger.msg(1, "TraceableEntity::queryLifeCycle("+mSystemKey+") - Returning "+jobBag.list.size()+" jobs."); return Gateway.getMarshaller().marshall( jobBag ); } diff --git a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java index d20fc1e..4c14cff 100644 --- a/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java +++ b/src/main/java/com/c2kernel/entity/agent/ActiveEntity.java @@ -247,7 +247,7 @@ public class ActiveEntity extends AgentPOA // merge new jobs in for (Object name : newJobList.list) { Job newJob = (Job)name; - Logger.msg(6, "Adding job for "+newJob.getItemSysKey()+"/"+newJob.getStepPath()+":"+newJob.getPossibleTransition()); + Logger.msg(6, "Adding job for "+newJob.getItemSysKey()+"/"+newJob.getStepPath()+":"+newJob.getTransitionId()); currentJobs.addJob(newJob); } diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java index f1aa215..f2a401a 100644 --- a/src/main/java/com/c2kernel/entity/agent/Job.java +++ b/src/main/java/com/c2kernel/entity/agent/Job.java @@ -1,14 +1,18 @@ package com.c2kernel.entity.agent; +import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.proxy.AgentProxy; import com.c2kernel.entity.proxy.ItemProxy; -import com.c2kernel.lifecycle.instance.stateMachine.Transitions; +import com.c2kernel.lifecycle.instance.Activity; +import com.c2kernel.lifecycle.instance.stateMachine.Transition; +import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.EntityPath; import com.c2kernel.lookup.InvalidEntityPathException; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.outcome.Outcome; +import com.c2kernel.persistency.outcome.Schema; import com.c2kernel.persistency.outcome.Viewpoint; import com.c2kernel.process.Gateway; import com.c2kernel.scripting.ErrorInfo; @@ -22,35 +26,49 @@ import com.c2kernel.utils.Logger; ******************************************************************************/ public class Job implements C2KLocalObject { - private int mID; + // persistent + + private int id; - private String mName; + private int itemSysKey; - private int mItemSysKey; - - private String mStepPath; - - private int mPossibleTransition; - - private int mCurrentState; - - private int mTargetState; - - private String mStepName; + private String stepName; + + private String stepPath; + + private String stepType; + + private int transitionId; - private int mAgentId = -1; + private int currentStateId; - private String mAgentName; + private int targetStateId; - private String mAgentRole; + private int agentId = -1; - private CastorHashMap mActProps = new CastorHashMap(); + private String agentRole; - private String mOutcome; + private String schemaName; - private ErrorInfo mError; - - private String mStepType; + private int schemaVersion; + + private boolean outcomeRequired; + + private String scriptName; + + private int scriptVersion; + + private CastorHashMap actProps = new CastorHashMap(); + + // non-persistent + + private String name; + + private String agentName; + + private String outcomeData; + + private ErrorInfo error; private ItemProxy item = null; @@ -65,36 +83,205 @@ public class Job implements C2KLocalObject { } - /*************************************************************************** - * - **************************************************************************/ - public Job(int sysKey, String path, int transition, int currState, int targState, String stepName, CastorHashMap actProps, String stepType, String agentName) + public Job(Activity act, int itemSysKey, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException { + + setItemSysKey(itemSysKey); + setStepPath(act.getPath()); + setTransitionId(transition.getId()); + setCurrentStateId(transition.getOriginStateCode()); + setTargetStateId(transition.getTerminalStateCode()); + setStepName(act.getName()); + setActProps(act.getProperties()); + setStepType(act.getType()); + setAgentName(agent.getAgentName()); + setAgentRole(role); + + if (transition.hasOutcome()) { + Schema schema = transition.getSchema(act.getProperties()); + setSchemaName(schema.docType); + setSchemaVersion(schema.docVersion); + outcomeRequired = transition.getOutcome().isRequired(); + } + + if (transition.hasScript()) { + setScriptName(transition.getScript().getScriptName()); + setScriptVersion(Integer.parseInt(transition.getScript().getScriptVersion())); + } + } + + + // Castor persistent fields + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + name = String.valueOf(id); + } + + public int getItemSysKey() { + return itemSysKey; + } + + public void setItemSysKey(int sysKey) { + itemSysKey = sysKey; + item = null; + } + + public String getStepName() { + return stepName; + } + + public void setStepName(String string) { + stepName = string; + } + + public String getStepPath() { + return stepPath; + } + + public void setStepPath(String string) { + stepPath = string; + } + + public String getStepType() { + return stepType; + } + + public void setStepType(String actType) { + stepType = actType; + } + + public int getTransitionId() { + return transitionId; + } + + public void setTransitionId(int tid) { + transitionId = tid; + } + + public int getCurrentStateId() { + return currentStateId; + } + + public void setCurrentStateId(int stateId) { + currentStateId = stateId; + } + + public int getTargetStateId() { + return targetStateId; + } + + public void setTargetStateId(int targetStateId) { + this.targetStateId = targetStateId; + } + + public int getAgentId() throws ObjectNotFoundException { + if (agentId == -1) + agentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey(); + return agentId; + } + + public void setAgentId(int id) { + agentId = id; + agent = null; + } + + public String getAgentName() { - setItemSysKey(sysKey); - setStepPath(path); - setPossibleTransition(transition); - setCurrentState(currState); - setTargetState(targState); - setStepName(stepName); - setActProps(actProps); - setStepType(stepType); - setAgentName(agentName); - } - - public int getItemSysKey() + if (agentName == null) + agentName = (String) actProps.get("Agent Name"); + return agentName; + } + + public void setAgentName(String agentName) { - return mItemSysKey; + this.agentName = agentName; + } + + public String getAgentRole() { + return agentRole; } - public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException + public void setAgentRole(String role) { + agentRole = role; + } + + public String getSchemaName() { + return schemaName; + } + + public void setSchemaName(String schemaName) { + this.schemaName = schemaName; + } + + public int getSchemaVersion() { + return schemaVersion; + } + + public void setSchemaVersion(int schemaVersion) { + this.schemaVersion = schemaVersion; + } + + public boolean isOutcomeRequired() { + return outcomeRequired; + } + + public void setOutcomeRequired(boolean outcomeRequired) { + this.outcomeRequired = outcomeRequired; + } + + public String getScriptName() { + return scriptName; + } + + public void setScriptName(String scriptName) { + this.scriptName = scriptName; + } + + public int getScriptVersion() { + return scriptVersion; + } + + public void setScriptVersion(int scriptVersion) { + this.scriptVersion = scriptVersion; + } + + public KeyValuePair[] getKeyValuePairs() { + return actProps.getKeyValuePairs(); + } + + public void setKeyValuePairs(KeyValuePair[] pairs) { + actProps.setKeyValuePairs(pairs); + } + + // Non-persistent fields + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + try { + id = Integer.parseInt(name); + } catch (NumberFormatException ex) { + id = -1; + } + } + + public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException { if (item == null) - item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(mItemSysKey)); + item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey)); return item; } - public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException - { + public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException { if (agent == null) agent = (AgentProxy) Gateway.getProxyManager().getProxy(new EntityPath(getAgentId())); return agent; @@ -102,42 +289,22 @@ public class Job implements C2KLocalObject public String getDescription() { - String desc = (String) mActProps.get("Description"); + String desc = (String) actProps.get("Description"); if (desc == null) desc = "No Description"; return desc; } - - public String getSchemaType() - { - if (isError()) return "Errors"; - if (requiresOutcome()) return (String)mActProps.get("SchemaType"); - else return null; - } - - public int getSchemaVersion() - { - if (isError()) return 0; - if (requiresOutcome()) - try { - return Integer.parseInt((String) mActProps.get("SchemaVersion")); - } catch (NumberFormatException ex) { - return -1; - } - return -1; - } - - public void setOutcome(String outcome) + public void setOutcome(String outcome) { - mOutcome = outcome; - outcomeSet = !(mOutcome == null); + outcomeData = outcome; + outcomeSet = !(outcomeData == null); } public void setError(ErrorInfo errors) { - mError = errors; + error = errors; try { - mOutcome = Gateway.getMarshaller().marshall(mError); + outcomeData = Gateway.getMarshaller().marshall(error); } catch (Exception e) { Logger.error("Error marshalling ErrorInfo in job"); Logger.error(e); @@ -146,121 +313,42 @@ public class Job implements C2KLocalObject public String getOutcomeString() { - if (mOutcome == null && requiresOutcome()) + if (outcomeData == null && isOutcomeRequired()) { String viewName = (String) getActProp("Viewpoint"); - mOutcome = null; + outcomeData = null; if (viewName.length() > 0) try { - Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaType() + "/" + viewName, null); - mOutcome = view.getOutcome().getData(); + Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaName() + "/" + viewName, null); + outcomeData = view.getOutcome().getData(); outcomeSet = true; } catch (Exception ex) { - mOutcome = null; + outcomeData = null; outcomeSet = false; } } - return mOutcome; + return outcomeData; } public Outcome getOutcome() { - return new Outcome(-1, getOutcomeString(), getSchemaType(), getSchemaVersion()); - } - - public int getAgentId() throws ObjectNotFoundException - { - if (mAgentId == -1) - mAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey(); - return mAgentId; - } - - public void setAgentId(int id) - { - mAgentId = id; - agent = null; - } - - public String getAgentName() - { - if (mAgentName == null) - mAgentName = (String) mActProps.get("AgentName"); - return mAgentName; - } - - public void setAgentName(String agentName) - { - mAgentName = agentName; - } - - public String getAgentRole() - { - if (mAgentRole == null) - mAgentRole = (String) mActProps.get("Agent Role"); - return mAgentRole; - } - - public void setAgentRole(String role) - { - mAgentRole = role; - } - - public boolean requiresOutcome() - { - String schemaType = (String) mActProps.get("SchemaType"); - return (mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals("")); + return new Outcome(-1, getOutcomeString(), getSchemaName(), getSchemaVersion()); } - public boolean isError() { - return (mPossibleTransition == Transitions.SUSPEND); + public boolean hasOutcome() { + return schemaName!=null; } - public boolean hasOutcome() { - return requiresOutcome() || isError(); + public boolean hasScript() { + return scriptName!=null; } public boolean isOutcomeSet() { return outcomeSet; - } - - public int getID() - { - return mID; - } - - @Override - public String getName() - { - return mName; - } - - public void setID(int id) - { - mID = id; - mName = String.valueOf(id); - } - - @Override - public void setName(String name) - { - mName = name; - try - { - mID = Integer.parseInt(name); - } catch (NumberFormatException ex) - { - mID = -1; - } - } - - public void setItemSysKey(int sysKey) - { - mItemSysKey = sysKey; - item = null; - } + } @Override public String getClusterType() @@ -270,100 +358,59 @@ public class Job implements C2KLocalObject public boolean equals(Job job) { - return (getItemSysKey() == job.getItemSysKey()) && this.mStepPath.equals(job.mStepPath) && this.mPossibleTransition == job.mPossibleTransition; + return (getItemSysKey() == job.getItemSysKey()) && this.stepPath.equals(job.stepPath) && this.transitionId == job.transitionId; + } + + private void setActProps(CastorHashMap actProps) { + this.actProps = actProps; } public Object getActProp(String name) { - return mActProps.get(name); + return actProps.get(name); } public String getActPropString(String name) { - try - { - return mActProps.get(name).toString(); - } catch (NullPointerException ex) - { - return null; - } - } - - public String getStepName() - { - return mStepName; - } - - public void setStepName(String string) - { - mStepName = string; + return String.valueOf(actProps.get(name)); } - public String getStepPath() - { - return mStepPath; - } - public void setStepPath(String string) + // Deprecated methods from old state machine + + @Deprecated + public String getSchemaType() { - mStepPath = string; + return getSchemaName(); } - + + @Deprecated public int getPossibleTransition() { - return mPossibleTransition; + return transitionId; } + @Deprecated public void setPossibleTransition(int lint) { - mPossibleTransition = lint; + transitionId = lint; } + @Deprecated public CastorHashMap getActProps() { - return mActProps; - } - - public void setActProps(CastorHashMap map) - { - mActProps = map; - } - - public KeyValuePair[] getKeyValuePairs() - { - return mActProps.getKeyValuePairs(); - } - - public void setKeyValuePairs(KeyValuePair[] pairs) - { - mActProps.setKeyValuePairs(pairs); + return actProps; } + @Deprecated public int getCurrentState() { - return mCurrentState; - } - - public void setCurrentState(int string) - { - mCurrentState = string; + return getCurrentStateId(); } + @Deprecated public int getTargetState() { - return mTargetState; - } - - public void setTargetState(int mTargetState) { - this.mTargetState = mTargetState; + return getTargetStateId(); } - public String getStepType() - { - return mStepType; - } - - public void setStepType(String actType) - { - mStepType = actType; - } } \ No newline at end of file diff --git a/src/main/java/com/c2kernel/entity/agent/JobList.java b/src/main/java/com/c2kernel/entity/agent/JobList.java index 3772c22..271decb 100644 --- a/src/main/java/com/c2kernel/entity/agent/JobList.java +++ b/src/main/java/com/c2kernel/entity/agent/JobList.java @@ -33,7 +33,7 @@ public class JobList extends RemoteMap { synchronized(this) { int jobId = getLastId()+1; - job.setID(jobId); + job.setId(jobId); put(String.valueOf(jobId), job); } } @@ -65,7 +65,7 @@ public class JobList extends RemoteMap j = currentMembers.next(); if( j.getItemSysKey() == sysKey ) - remove( String.valueOf(j.getID()) ); + remove( String.valueOf(j.getId()) ); } Logger.msg(5, "JobList::removeJobsWithSysKey() - " + sysKey + " DONE." ); diff --git a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java index 24172dc..d803079 100644 --- a/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/AgentProxy.java @@ -25,7 +25,6 @@ import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.ManageableEntity; import com.c2kernel.entity.agent.Job; import com.c2kernel.lifecycle.instance.predefined.PredefinedStep; -import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.DomainPath; import com.c2kernel.lookup.EntityPath; @@ -111,14 +110,13 @@ public class AgentProxy extends EntityProxy ScriptErrorException { OutcomeValidator validator = null; - String scriptName = job.getActPropString("ScriptName"); Date startTime = new Date(); Logger.msg(3, "AgentProxy - executing "+job.getStepPath()+" for "+path.getAgentName()); // get the outcome validator if present - if (job.requiresOutcome() || job.isError()) + if (job.hasOutcome()) { - String schemaName = job.isError()?"Errors":job.getSchemaType(); - int schemaVersion = job.isError()?0:job.getSchemaVersion(); + String schemaName = job.getSchemaName(); + int schemaVersion = job.getSchemaVersion(); Logger.msg(5, "AgentProxy - fetching schema "+schemaName+"_"+schemaVersion+" for validation"); // retrieve schema @@ -134,9 +132,8 @@ public class AgentProxy extends EntityProxy } } - if(scriptName != null && scriptName.length() > 0 && - (job.getPossibleTransition() == Transitions.DONE || job.getPossibleTransition() == Transitions.COMPLETE)) { - Logger.msg(3, "AgentProxy - executing script "+scriptName); + if(job.hasScript()) { + Logger.msg(3, "AgentProxy - executing script "+job.getScriptName()+" v"+job.getScriptVersion()); try { // pre-validate outcome from script if there is one @@ -151,7 +148,6 @@ public class AgentProxy extends EntityProxy // load script ErrorInfo scriptErrors = (ErrorInfo)callScript(item, job); - String errorString = scriptErrors.toString(); if (scriptErrors.getFatal()) { Logger.msg(3, "AgentProxy - fatal script error"); @@ -171,6 +167,7 @@ public class AgentProxy extends EntityProxy if (error.length() > 0) throw new InvalidDataException(error, ""); } + else if (job.isOutcomeRequired()) job.setAgentId(getSystemKey()); Logger.msg(3, "AgentProxy - submitting job to item proxy"); diff --git a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java index 67685e7..1740159 100644 --- a/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java +++ b/src/main/java/com/c2kernel/entity/proxy/ItemProxy.java @@ -26,7 +26,6 @@ import com.c2kernel.entity.ManageableEntity; import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.agent.JobArrayList; import com.c2kernel.lifecycle.instance.Workflow; -import com.c2kernel.lifecycle.instance.stateMachine.Transitions; import com.c2kernel.persistency.ClusterStorage; import com.c2kernel.persistency.outcome.Viewpoint; import com.c2kernel.process.Gateway; @@ -110,7 +109,7 @@ public class ItemProxy extends EntityProxy String outcome = thisJob.getOutcomeString(); // check fields that should have been filled in if (outcome==null) - if (thisJob.requiresOutcome()) + if (thisJob.isOutcomeRequired()) throw new InvalidDataException("Outcome is required.", ""); else outcome=""; @@ -120,7 +119,7 @@ public class ItemProxy extends EntityProxy Logger.msg(7, "ItemProxy - executing "+thisJob.getStepPath()+" for "+thisJob.getAgentName()); requestAction (thisJob.getAgentId(), thisJob.getStepPath(), - thisJob.getPossibleTransition(), outcome); + thisJob.getTransitionId(), outcome); } //requestData is xmlString @@ -200,9 +199,7 @@ public class ItemProxy extends EntityProxy ArrayList jobList = getJobList(agentId); for (Job job : jobList) { - int transition = job.getPossibleTransition(); - if (job.getStepName().equals(actName)) - if (transition == Transitions.COMPLETE || transition == Transitions.DONE) + if (job.getStepName().equals(actName) && job.hasOutcome()) return job; } return null; -- cgit v1.2.3