summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/process
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2013-11-18 09:48:03 +0100
committerAndrew Branson <andrew.branson@cern.ch>2013-11-18 17:25:00 +0100
commitd43164830403245353080f5d6f838ed9f56d9a35 (patch)
treed880c9103fb61f5ef39f1723c4dbd634d5d83b67 /src/main/java/com/c2kernel/process
parent37a3c3867cb4c7705065ed1d079bdac4f3f52f50 (diff)
3.0-SNAPSHOT (Will be first open source version)
New StateMachine desc IssueID #28
Diffstat (limited to 'src/main/java/com/c2kernel/process')
-rw-r--r--src/main/java/com/c2kernel/process/Bootstrap.java14
-rw-r--r--src/main/java/com/c2kernel/process/UserCodeProcess.java35
-rw-r--r--src/main/java/com/c2kernel/process/module/Module.java2
3 files changed, 31 insertions, 20 deletions
diff --git a/src/main/java/com/c2kernel/process/Bootstrap.java b/src/main/java/com/c2kernel/process/Bootstrap.java
index 08cf2e7..b37cc8a 100644
--- a/src/main/java/com/c2kernel/process/Bootstrap.java
+++ b/src/main/java/com/c2kernel/process/Bootstrap.java
@@ -17,8 +17,7 @@ import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Workflow;
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.lifecycle.instance.stateMachine.Transition;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.EntityPath;
@@ -152,7 +151,8 @@ 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);
+ Transition predefDone = new Transition(0, "Done", 0, 0);
+ Event newEvent = hist.addEvent("system", "Admin", "Bootstrap", "Bootstrap", "Bootstrap", getDataType(itemType), 0, "PredefinedStep", 0, predefDone, String.valueOf(version));
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());
@@ -186,7 +186,7 @@ public class Bootstrap
else if (itemType.equals("OD")) wf = "ManageSchema";
else if (itemType.equals("SC")) wf = "ManageScript";
else throw new Exception("Unknown bootstrap item type: "+itemType);
- ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(wf, "last")).instantiate();
+ ca = (CompositeActivity) ((CompositeActivityDef)LocalObjectLoader.getActDef(wf, 0)).instantiate();
}
EntityPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
@@ -209,6 +209,8 @@ public class Bootstrap
return new DomainPath("/desc/Script/");
if (type.equals("OD"))
return new DomainPath("/desc/OutcomeDesc/");
+ if (type.equals("SM"))
+ return new DomainPath("/desc/StateMachine");
throw new Exception("Unknown bootstrap item type: "+type);
}
@@ -221,6 +223,8 @@ public class Bootstrap
return "Schema";
if (type.equals("SC"))
return "Script";
+ if (type.equals("SM"))
+ return "StateMachine";
throw new Exception("Unknown bootstrap item type: "+type);
}
@@ -307,7 +311,7 @@ public class Bootstrap
}
public static void initServerItemWf() throws Exception {
- CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", "last");
+ CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", 0);
Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate());
PredefinedStepContainer predef = (PredefinedStepContainer)wf.search("workflow/predefined");
wf.getChildGraphModel().removeVertex(predef);
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;
}
}
diff --git a/src/main/java/com/c2kernel/process/module/Module.java b/src/main/java/com/c2kernel/process/module/Module.java
index a932361..d0a017c 100644
--- a/src/main/java/com/c2kernel/process/module/Module.java
+++ b/src/main/java/com/c2kernel/process/module/Module.java
@@ -67,7 +67,7 @@ public class Module {
}
moduleItem.dependencyList.add(children);
// Add moduleXML
- Outcome moduleOutcome = new Outcome("Module", "0", "last", null);
+ Outcome moduleOutcome = new Outcome("Module", 0, "last", null);
moduleOutcome.data = moduleXML;
moduleItem.outcomes.add(moduleOutcome);
imports.list.add(moduleItem);