diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-11-18 09:48:03 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-11-18 17:25:00 +0100 |
| commit | d43164830403245353080f5d6f838ed9f56d9a35 (patch) | |
| tree | d880c9103fb61f5ef39f1723c4dbd634d5d83b67 /src/main/java/com/c2kernel/entity/agent/Job.java | |
| parent | 37a3c3867cb4c7705065ed1d079bdac4f3f52f50 (diff) | |
3.0-SNAPSHOT (Will be first open source version)
New StateMachine desc
IssueID #28
Diffstat (limited to 'src/main/java/com/c2kernel/entity/agent/Job.java')
| -rw-r--r-- | src/main/java/com/c2kernel/entity/agent/Job.java | 475 |
1 files changed, 228 insertions, 247 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java index f1aa215..5f9e6dc 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;
@@ -20,37 +24,42 @@ import com.c2kernel.utils.Logger; * @author $Author: abranson $ $Date: 2005/05/20 13:07:49 $
* @version $Revision: 1.62 $
******************************************************************************/
+
public class Job implements C2KLocalObject
{
- private int mID;
-
- private String mName;
-
- private int mItemSysKey;
-
- private String mStepPath;
-
- private int mPossibleTransition;
-
- private int mCurrentState;
+ // persistent
+
+ private int id;
- private int mTargetState;
+ private int itemSysKey;
- private String mStepName;
-
- private int mAgentId = -1;
-
- private String mAgentName;
+ private String stepName;
+
+ private String stepPath;
+
+ private String stepType;
+
+ private Transition transition;
+
+ private String originStateName;
+
+ private String targetStateName;
- private String mAgentRole;
+ private int agentId = -1;
- private CastorHashMap mActProps = new CastorHashMap();
+ private String agentRole;
- private String mOutcome;
+ private CastorHashMap actProps = new CastorHashMap();
- private ErrorInfo mError;
-
- private String mStepType;
+ // non-persistent
+
+ private String name;
+
+ private String agentName;
+
+ private String outcomeData;
+
+ private ErrorInfo error;
private ItemProxy item = null;
@@ -65,305 +74,277 @@ 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)
- {
- setItemSysKey(sysKey);
- setStepPath(path);
- setPossibleTransition(transition);
- setCurrentState(currState);
- setTargetState(targState);
- setStepName(stepName);
- setActProps(actProps);
- setStepType(stepType);
- setAgentName(agentName);
- }
-
- public int getItemSysKey()
- {
- return mItemSysKey;
+ public Job(Activity act, int itemSysKey, Transition transition, AgentPath agent, String role) throws InvalidDataException, ObjectNotFoundException {
+
+ setItemSysKey(itemSysKey);
+ setStepPath(act.getPath());
+ setTransition(transition);
+ setOriginStateName(act.getStateMachine().getState(transition.getOriginStateId()).getName());
+ setTargetStateName(act.getStateMachine().getState(transition.getTargetStateId()).getName());
+ setStepName(act.getName());
+ setActProps(act.getProperties());
+ setStepType(act.getType());
+ setAgentName(agent.getAgentName());
+ setAgentRole(role);
}
- public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException
- {
- if (item == null)
- item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(mItemSysKey));
- return item;
- }
+
+ // Castor persistent fields
+
+ public String getOriginStateName() {
+ return originStateName;
+ }
- public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException
- {
- if (agent == null)
- agent = (AgentProxy) Gateway.getProxyManager().getProxy(new EntityPath(getAgentId()));
- return agent;
- }
+ public void setOriginStateName(String originStateName) {
+ this.originStateName = originStateName;
+ }
- public String getDescription()
- {
- String desc = (String) mActProps.get("Description");
- if (desc == null)
- desc = "No Description";
- return desc;
- }
+ public String getTargetStateName() {
+ return targetStateName;
+ }
- public String getSchemaType()
- {
- if (isError()) return "Errors";
- if (requiresOutcome()) return (String)mActProps.get("SchemaType");
- else return null;
- }
+ public void setTargetStateName(String targetStateName) {
+ this.targetStateName = targetStateName;
+ }
- 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)
- {
- mOutcome = outcome;
- outcomeSet = !(mOutcome == null);
+ public int getId() {
+ return id;
}
- public void setError(ErrorInfo errors)
- {
- mError = errors;
- try {
- mOutcome = Gateway.getMarshaller().marshall(mError);
- } catch (Exception e) {
- Logger.error("Error marshalling ErrorInfo in job");
- Logger.error(e);
- }
+ 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 getOutcomeString()
- {
- if (mOutcome == null && requiresOutcome())
- {
- String viewName = (String) getActProp("Viewpoint");
- mOutcome = null;
- if (viewName.length() > 0)
- try
- {
- Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaType() + "/" + viewName, null);
- mOutcome = view.getOutcome().getData();
- outcomeSet = true;
- } catch (Exception ex)
- {
- mOutcome = null;
- outcomeSet = false;
- }
-
- }
- return mOutcome;
+ public String getStepName() {
+ return stepName;
}
- public Outcome getOutcome()
- {
- return new Outcome(-1, getOutcomeString(), getSchemaType(), getSchemaVersion());
+ public void setStepName(String string) {
+ stepName = string;
}
- public int getAgentId() throws ObjectNotFoundException
- {
- if (mAgentId == -1)
- mAgentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
- return mAgentId;
+ public String getStepPath() {
+ return stepPath;
}
- public void setAgentId(int id)
- {
- mAgentId = id;
- agent = null;
+ public void setStepPath(String string) {
+ stepPath = string;
}
- public String getAgentName()
- {
- if (mAgentName == null)
- mAgentName = (String) mActProps.get("AgentName");
- return mAgentName;
+ public String getStepType() {
+ return stepType;
}
- public void setAgentName(String agentName)
- {
- mAgentName = agentName;
+ public void setStepType(String actType) {
+ stepType = actType;
+ }
+
+ public Transition getTransition() {
+ return transition;
+ }
+
+ public void setTransition(Transition transition) {
+ this.transition = transition;
}
- public String getAgentRole()
- {
- if (mAgentRole == null)
- mAgentRole = (String) mActProps.get("Agent Role");
- return mAgentRole;
+ public int getAgentId() throws ObjectNotFoundException {
+ if (agentId == -1)
+ agentId = Gateway.getLDAPLookup().getRoleManager().getAgentPath(getAgentName()).getSysKey();
+ return agentId;
}
- public void setAgentRole(String role)
+ public void setAgentId(int id) {
+ agentId = id;
+ agent = null;
+ }
+
+ public String getAgentName()
{
- mAgentRole = role;
+ if (agentName == null)
+ agentName = (String) actProps.get("Agent Name");
+ return agentName;
}
- public boolean requiresOutcome()
+ public void setAgentName(String agentName)
{
- String schemaType = (String) mActProps.get("SchemaType");
- return (mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals(""));
+ this.agentName = agentName;
}
- public boolean isError() {
- return (mPossibleTransition == Transitions.SUSPEND);
+ public String getAgentRole() {
+ return agentRole;
+ }
+
+ public void setAgentRole(String role) {
+ agentRole = role;
}
- public boolean hasOutcome() {
- return requiresOutcome() || isError();
+ public String getSchemaName() throws InvalidDataException, ObjectNotFoundException {
+ if (transition.hasOutcome()) {
+ Schema schema = transition.getSchema(actProps);
+ return schema.docType;
+ }
+ return null;
}
- public boolean isOutcomeSet() {
- return outcomeSet;
+ public int getSchemaVersion() throws InvalidDataException, ObjectNotFoundException {
+ if (transition.hasOutcome()) {
+ Schema schema = transition.getSchema(actProps);
+ return schema.docVersion;
+ }
+ return -1;
}
- public int getID()
+ public boolean isOutcomeRequired()
{
- return mID;
+ return transition.hasOutcome() && transition.getOutcome().isRequired();
}
+
+ public String getScriptName() {
+ if (transition.hasScript()) {
+ return transition.getScript().getScriptName();
+ }
+ return null;
+ }
- @Override
- public String getName()
- {
- return mName;
+ public int getScriptVersion() throws InvalidDataException {
+ if (transition.hasScript()) {
+ return transition.getScriptVersion(actProps);
+ }
+ return -1;
+ }
+
+ public KeyValuePair[] getKeyValuePairs() {
+ return actProps.getKeyValuePairs();
}
- public void setID(int id)
- {
- mID = id;
- mName = String.valueOf(id);
+ public void setKeyValuePairs(KeyValuePair[] pairs) {
+ actProps.setKeyValuePairs(pairs);
}
-
+
+ // Non-persistent fields
+
@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;
+ public String getName() {
+ return name;
}
-
+
@Override
- public String getClusterType()
- {
- return ClusterStorage.JOB;
- }
-
- public boolean equals(Job job)
- {
- return (getItemSysKey() == job.getItemSysKey()) && this.mStepPath.equals(job.mStepPath) && this.mPossibleTransition == job.mPossibleTransition;
- }
-
- public Object getActProp(String name)
- {
- return mActProps.get(name);
- }
-
- public String getActPropString(String name)
- {
- try
- {
- return mActProps.get(name).toString();
- } catch (NullPointerException ex)
- {
- return null;
+ public void setName(String name) {
+ this.name = name;
+ try {
+ id = Integer.parseInt(name);
+ } catch (NumberFormatException ex) {
+ id = -1;
}
}
-
- public String getStepName()
- {
- return mStepName;
+
+ public ItemProxy getItemProxy() throws ObjectNotFoundException, InvalidEntityPathException {
+ if (item == null)
+ item = (ItemProxy) Gateway.getProxyManager().getProxy(new EntityPath(itemSysKey));
+ return item;
}
- public void setStepName(String string)
- {
- mStepName = string;
+ public AgentProxy getAgentProxy() throws ObjectNotFoundException, InvalidEntityPathException {
+ if (agent == null)
+ agent = (AgentProxy) Gateway.getProxyManager().getProxy(new EntityPath(getAgentId()));
+ return agent;
}
- public String getStepPath()
+ public String getDescription()
{
- return mStepPath;
+ String desc = (String) actProps.get("Description");
+ if (desc == null)
+ desc = "No Description";
+ return desc;
}
-
- public void setStepPath(String string)
+ public void setOutcome(String outcome)
{
- mStepPath = string;
+ outcomeData = outcome;
+ outcomeSet = !(outcomeData == null);
}
-
- public int getPossibleTransition()
+
+ public void setError(ErrorInfo errors)
{
- return mPossibleTransition;
+ error = errors;
+ try {
+ outcomeData = Gateway.getMarshaller().marshall(error);
+ } catch (Exception e) {
+ Logger.error("Error marshalling ErrorInfo in job");
+ Logger.error(e);
+ }
}
- public void setPossibleTransition(int lint)
+ public String getOutcomeString()
{
- mPossibleTransition = lint;
- }
+ if (outcomeData == null && isOutcomeRequired())
+ {
+ String viewName = (String) getActProp("Viewpoint");
+ outcomeData = null;
+ if (viewName.length() > 0)
+ try
+ {
+ Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaName() + "/" + viewName, null);
+ outcomeData = view.getOutcome().getData();
+ outcomeSet = true;
+ } catch (Exception ex)
+ {
+ outcomeData = null;
+ outcomeSet = false;
+ }
- public CastorHashMap getActProps()
- {
- return mActProps;
+ }
+ return outcomeData;
}
- public void setActProps(CastorHashMap map)
+ public Outcome getOutcome() throws InvalidDataException, ObjectNotFoundException
{
- mActProps = map;
+ return new Outcome(-1, getOutcomeString(), getSchemaName(), getSchemaVersion());
}
-
- public KeyValuePair[] getKeyValuePairs()
- {
- return mActProps.getKeyValuePairs();
+
+ public boolean hasOutcome() {
+ return transition.hasOutcome();
}
-
- public void setKeyValuePairs(KeyValuePair[] pairs)
- {
- mActProps.setKeyValuePairs(pairs);
+
+ public boolean hasScript() {
+ return transition.hasScript();
}
+
+ public boolean isOutcomeSet() {
+ return outcomeSet;
+ }
- public int getCurrentState()
+ @Override
+ public String getClusterType()
{
- return mCurrentState;
+ return ClusterStorage.JOB;
}
- public void setCurrentState(int string)
+ public boolean equals(Job job)
{
- mCurrentState = string;
+ return (getItemSysKey() == job.getItemSysKey()) && this.stepPath.equals(job.stepPath) && transition.getId() == job.getTransition().getId();
+ }
+
+ private void setActProps(CastorHashMap actProps) {
+ this.actProps = actProps;
}
- public int getTargetState() {
- return mTargetState;
- }
-
- public void setTargetState(int mTargetState) {
- this.mTargetState = mTargetState;
- }
-
- public String getStepType()
+ public Object getActProp(String name)
{
- return mStepType;
+ return actProps.get(name);
}
- public void setStepType(String actType)
+ public String getActPropString(String name)
{
- mStepType = actType;
+ return String.valueOf(actProps.get(name));
}
}
\ No newline at end of file |
