From d43164830403245353080f5d6f838ed9f56d9a35 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 18 Nov 2013 09:48:03 +0100 Subject: 3.0-SNAPSHOT (Will be first open source version) New StateMachine desc IssueID #28 --- src/main/java/com/c2kernel/process/Bootstrap.java | 14 +++++---- .../java/com/c2kernel/process/UserCodeProcess.java | 35 +++++++++++++--------- .../java/com/c2kernel/process/module/Module.java | 2 +- 3 files changed, 31 insertions(+), 20 deletions(-) (limited to 'src/main/java/com/c2kernel/process') 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, 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 ignoredPaths = new ArrayList(); HashMap errors = new HashMap(); @@ -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 jobs, int transition) { + private static Job getJob(HashMap 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); -- cgit v1.2.3