diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-10-24 13:12:52 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-10-24 13:12:52 +0200 |
| commit | 04048a6c4026b47fc6c372e792ffb60726baee56 (patch) | |
| tree | f45ead5986b8df26d4f9171350638b418fca3e47 /src/main/java/com/c2kernel/process | |
| parent | 8b32fe15554c0103585321c3d397f6e46dd451b4 (diff) | |
Clear of exceptions
Diffstat (limited to 'src/main/java/com/c2kernel/process')
| -rw-r--r-- | src/main/java/com/c2kernel/process/Bootstrap.java | 5 | ||||
| -rw-r--r-- | src/main/java/com/c2kernel/process/UserCodeProcess.java | 49 |
2 files changed, 37 insertions, 17 deletions
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java index 08cf2e7..93698e8 100644 --- a/src/main/java/com/c2kernel/process/Bootstrap.java +++ b/src/main/java/com/c2kernel/process/Bootstrap.java @@ -15,10 +15,9 @@ import com.c2kernel.events.History; import com.c2kernel.lifecycle.CompositeActivityDef;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
+import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
import com.c2kernel.lifecycle.instance.predefined.ServerPredefinedStepContainer;
-import com.c2kernel.lifecycle.instance.stateMachine.States;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -152,7 +151,7 @@ public class Bootstrap // data was missing or doesn't match
Logger.msg("Bootstrap.verifyResource() - Writing new version "+version+" to "+getDataType(itemType)+" "+itemName);
History hist = new History(thisProxy.getSystemKey(), thisProxy);
- Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Bootstrap", "Bootstrap", "Bootstrap", getDataType(itemType), 0, String.valueOf(version), States.FINISHED);
+ Event newEvent = hist.addEvent("system", "Admin", PredefinedStep.DONE, "Bootstrap", "Bootstrap", "Bootstrap", getDataType(itemType), 0, String.valueOf(version), PredefinedStep.AVAILABLE);
newOutcome.setID(newEvent.getID());
Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID());
Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), String.valueOf(version), 0, newEvent.getID());
diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index 0abd906..f58da51 100644 --- a/src/main/java/com/c2kernel/process/UserCodeProcess.java +++ b/src/main/java/com/c2kernel/process/UserCodeProcess.java @@ -11,7 +11,6 @@ import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.entity.proxy.MemberSubscription;
-import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.scripting.ErrorInfo;
import com.c2kernel.scripting.ScriptErrorException;
@@ -26,7 +25,14 @@ import com.c2kernel.utils.Logger; * All rights reserved.
**************************************************************************/
public class UserCodeProcess extends StandardClient implements EntityProxyObserver<Job>, Runnable {
- protected AgentProxy agent;
+
+ // Default state machine transitions
+ private static final int START = 1;
+ private static final int COMPLETE = 2;
+ private static final int SUSPEND = 3;
+ private static final int RESUME = 4;
+
+ protected AgentProxy agent;
static boolean active = true;
ArrayList<String> ignoredPaths = new ArrayList<String>();
HashMap<String, ErrorInfo> errors = new HashMap<String, ErrorInfo>();
@@ -60,13 +66,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Job thisJob = null;
synchronized (jobs) {
if (jobs.size() > 0) {
- thisJob = getJob(jobs, Transitions.COMPLETE);
+ thisJob = getJob(jobs, COMPLETE);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.START);
+ thisJob = getJob(jobs, START);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.SUSPEND);
+ thisJob = getJob(jobs, SUSPEND);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.RESUME);
+ thisJob = getJob(jobs, RESUME);
if (thisJob == null) {
Logger.error("No supported jobs, but joblist is not empty! Discarding remaining jobs");
@@ -80,7 +86,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv if (thisJob != null) {
String jobKey = thisJob.getItemSysKey()+":"+thisJob.getStepPath();
try {
- if (thisJob.getPossibleTransition()==Transitions.START) {
+ if (thisJob.getTransitionId()==START) {
Logger.msg(5, "Testing start conditions");
boolean start = assessStartConditions(thisJob);
if (start) {
@@ -91,13 +97,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Logger.msg(5, "Start conditions failed "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
}
}
- else if (thisJob.getPossibleTransition()==Transitions.COMPLETE) {
+ else if (thisJob.getTransitionId()==COMPLETE) {
Logger.msg(5, "Executing logic");
runUCLogic(thisJob);
if (ignoredPaths.contains(jobKey))
ignoredPaths.remove(jobKey);
}
- else if (thisJob.getPossibleTransition()==Transitions.SUSPEND) {
+ else if (thisJob.getTransitionId()==SUSPEND) {
if (ignoredPaths.contains(jobKey)) {
if (errors.containsKey(jobKey)) {
thisJob.setOutcome(Gateway.getMarshaller().marshall(errors.get(jobKey)));
@@ -106,7 +112,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv agent.execute(thisJob);
}
}
- else if (thisJob.getPossibleTransition()==Transitions.RESUME) {
+ else if (thisJob.getTransitionId()==RESUME) {
if (!ignoredPaths.contains(jobKey))
agent.execute(thisJob);
}
@@ -116,7 +122,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv } catch (InvalidTransitionException ex) {
// must have already been done by someone else - ignore
} catch (Throwable ex) {
- Logger.error("Error executing "+Transitions.getTransitionName(thisJob.getPossibleTransition())+" job:");
+ Logger.error("Error executing "+getTransitionName(thisJob.getTransitionId())+" job:");
Logger.error(ex);
ErrorInfo ei = new ErrorInfo();
ei.setFatal();
@@ -148,12 +154,27 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
}
- private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
+ private static String getTransitionName(int transitionId) {
+ switch (transitionId) {
+ case 1:
+ return "Start";
+ case 2:
+ return "Complete";
+ case 3:
+ return "Suspend";
+ case 4:
+ return "Resume";
+ default:
+ return "Unknown";
+ }
+ }
+
+ private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
for (C2KLocalObject c2kLocalObject : jobs.values()) {
Job thisJob = (Job)c2kLocalObject;
- if (thisJob.getPossibleTransition() == transition) {
+ if (thisJob.getTransitionId() == transition) {
Logger.msg(1,"=================================================================");
- Logger.msg(1, "Got "+Transitions.getTransitionName(transition)+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
+ Logger.msg(1, "Got "+getTransitionName(transition)+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
return thisJob;
}
}
|
