diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-07-23 09:41:43 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-09-16 12:44:14 +0200 |
| commit | e99ed30f6cae36c5f3fa03007d991e67894a01bb (patch) | |
| tree | 5fdfe6aab9e31ebd8c282eb16d42c5e2f75b1217 /src/main/java/com/c2kernel/entity/agent | |
| parent | 0bb38e90ac6e88cb406facbc075983384a2e164f (diff) | |
More
Diffstat (limited to 'src/main/java/com/c2kernel/entity/agent')
| -rw-r--r-- | src/main/java/com/c2kernel/entity/agent/ActiveEntity.java | 2 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/entity/agent/Job.java | 495 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/entity/agent/JobList.java | 4 |
3 files changed, 274 insertions, 227 deletions
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<Job> {
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<Job> j = currentMembers.next();
if( j.getItemSysKey() == sysKey )
- remove( String.valueOf(j.getID()) );
+ remove( String.valueOf(j.getId()) );
}
Logger.msg(5, "JobList::removeJobsWithSysKey() - " + sysKey + " DONE." );
|
