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/process/UserCodeProcess.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/process/UserCodeProcess.java')
| -rw-r--r-- | src/main/java/com/c2kernel/process/UserCodeProcess.java | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/main/java/com/c2kernel/process/UserCodeProcess.java b/src/main/java/com/c2kernel/process/UserCodeProcess.java index 0abd906..f7bbe74 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");
@@ -79,8 +85,9 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv if (thisJob != null) {
String jobKey = thisJob.getItemSysKey()+":"+thisJob.getStepPath();
+ int transitionId = thisJob.getTransition().getId();
try {
- if (thisJob.getPossibleTransition()==Transitions.START) {
+ if (transitionId==START) {
Logger.msg(5, "Testing start conditions");
boolean start = assessStartConditions(thisJob);
if (start) {
@@ -91,13 +98,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 (transitionId==COMPLETE) {
Logger.msg(5, "Executing logic");
runUCLogic(thisJob);
if (ignoredPaths.contains(jobKey))
ignoredPaths.remove(jobKey);
}
- else if (thisJob.getPossibleTransition()==Transitions.SUSPEND) {
+ else if (transitionId==SUSPEND) {
if (ignoredPaths.contains(jobKey)) {
if (errors.containsKey(jobKey)) {
thisJob.setOutcome(Gateway.getMarshaller().marshall(errors.get(jobKey)));
@@ -106,7 +113,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv agent.execute(thisJob);
}
}
- else if (thisJob.getPossibleTransition()==Transitions.RESUME) {
+ else if (transitionId==RESUME) {
if (!ignoredPaths.contains(jobKey))
agent.execute(thisJob);
}
@@ -116,7 +123,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 "+thisJob.getTransition().getName()+" job:");
Logger.error(ex);
ErrorInfo ei = new ErrorInfo();
ei.setFatal();
@@ -148,12 +155,12 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
}
- private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
+ 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.getTransition().getId() == transition) {
Logger.msg(1,"=================================================================");
- Logger.msg(1, "Got "+Transitions.getTransitionName(transition)+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
+ Logger.msg(1, "Got "+thisJob.getTransition().getName()+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
return thisJob;
}
}
|
