summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/entity/agent/Job.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-07-12 14:52:36 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-07-12 14:52:36 +0200
commit20c81748688547c1b13686f15c65fbb1d60d81a0 (patch)
tree59dc2b94c47ed30b8bc93c07cab42e96904d1146 /src/main/java/com/c2kernel/entity/agent/Job.java
parent61559eef9369dbdbb027bec7c571d7f770b2e7a3 (diff)
Suspend transition now can carry an optional 'Errors' outcome where
client processes can record the reason for the suspension. Errors XML is marshalled ErrorInfo. UserCodeProcess automatically sends fatal ErrorInfos through suspend jobs. Job API added to to support all this. fixes #23
Diffstat (limited to 'src/main/java/com/c2kernel/entity/agent/Job.java')
-rw-r--r--src/main/java/com/c2kernel/entity/agent/Job.java66
1 files changed, 50 insertions, 16 deletions
diff --git a/src/main/java/com/c2kernel/entity/agent/Job.java b/src/main/java/com/c2kernel/entity/agent/Job.java
index b5274ec..216a88d 100644
--- a/src/main/java/com/c2kernel/entity/agent/Job.java
+++ b/src/main/java/com/c2kernel/entity/agent/Job.java
@@ -11,6 +11,7 @@ import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.persistency.outcome.Viewpoint;
import com.c2kernel.process.Gateway;
+import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.utils.CastorHashMap;
import com.c2kernel.utils.KeyValuePair;
import com.c2kernel.utils.Logger;
@@ -46,12 +47,16 @@ public class Job implements C2KLocalObject
private CastorHashMap mActProps = new CastorHashMap();
private String mOutcome;
+
+ private ErrorInfo mError;
private String mStepType;
private ItemProxy item = null;
private AgentProxy agent = null;
+
+ private boolean outcomeSet;
/***************************************************************************
* Empty constructor for Castor
@@ -105,29 +110,43 @@ public class Job implements C2KLocalObject
public String getSchemaType()
{
- return (String) mActProps.get("SchemaType");
+ if (isError()) return "Errors";
+ if (requiresOutcome()) return (String)mActProps.get("SchemaType");
+ else return null;
}
public int getSchemaVersion()
{
- try
- {
- return Integer.parseInt((String) mActProps.get("SchemaVersion"));
- } catch (NumberFormatException ex)
- {
- return -1;
- }
+ 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;
+ mOutcome = outcome;
+ outcomeSet = !(mOutcome == null);
+ }
+
+ public void setError(ErrorInfo errors)
+ {
+ mError = errors;
+ try {
+ mOutcome = Gateway.getMarshaller().marshall(errors);
+ } catch (Exception e) {
+ Logger.error("Error marshalling ErrorInfo in job");
+ Logger.error(e);
+ }
}
public String getOutcomeString()
{
- Logger.debug(8, "getOutcomeString() " + (mOutcome == null && isOutcomeUsed()));
- if (mOutcome == null && isOutcomeUsed())
+ if (mOutcome == null && requiresOutcome())
{
String viewName = (String) getActProp("Viewpoint");
mOutcome = null;
@@ -136,16 +155,19 @@ public class Job implements C2KLocalObject
{
Viewpoint view = (Viewpoint) Gateway.getStorage().get(getItemSysKey(), ClusterStorage.VIEWPOINT + "/" + getSchemaType() + "/" + viewName, null);
mOutcome = view.getOutcome().getData();
+ outcomeSet = true;
} catch (Exception ex)
- { // not found, return null
+ {
+ mOutcome = null;
+ outcomeSet = false;
}
+
}
return mOutcome;
}
public Outcome getOutcome()
{
- Logger.msg(1, "Get outcome");
return new Outcome(-1, getOutcomeString(), getSchemaType(), getSchemaVersion());
}
@@ -186,10 +208,22 @@ public class Job implements C2KLocalObject
mAgentRole = role;
}
- public boolean isOutcomeUsed()
+ public boolean requiresOutcome()
{
- String schemaType = getSchemaType();
- return (Boolean.TRUE.equals(getActProp("AlwaysUseOutcome")) || mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals(""));
+ String schemaType = (String) mActProps.get("SchemaVersion");
+ return (mPossibleTransition == Transitions.DONE || mPossibleTransition == Transitions.COMPLETE) && !(schemaType == null || schemaType.equals(""));
+ }
+
+ public boolean isError() {
+ return (mPossibleTransition == Transitions.SUSPEND);
+ }
+
+ public boolean hasOutcome() {
+ return requiresOutcome() || isError();
+ }
+
+ public boolean isOutcomeSet() {
+ return outcomeSet;
}
public int getID()