From: Mathieu Baudier Date: Tue, 17 Feb 2015 19:29:55 +0000 (+0000) Subject: First working version of SLC Runtime v2 X-Git-Tag: argeo-slc-2.1.7~89 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=7d137263a92df9bb874f9c900524dfce640495e6;p=gpl%2Fargeo-slc.git First working version of SLC Runtime v2 git-svn-id: https://svn.argeo.org/slc/trunk@7922 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionContext.java b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionContext.java index 056614314..9a88f52cd 100644 --- a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionContext.java +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionContext.java @@ -28,4 +28,8 @@ public interface ExecutionContext { public Object getVariable(String key); public void setVariable(String key, Object value); + + public void beforeFlow(ExecutionFlow executionFlow); + + public void afterFlow(ExecutionFlow executionFlow); } diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionFlow.java b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionFlow.java index 520f249df..5ebcdf07d 100644 --- a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionFlow.java +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionFlow.java @@ -36,7 +36,7 @@ public interface ExecutionFlow extends Runnable { /** * If there is one and only one runnable wrapped return it, throw an - * exeception otherwise. + * exception otherwise. */ public Runnable getRunnable(); @@ -45,10 +45,4 @@ public interface ExecutionFlow extends Runnable { * interpreted by UIs as a hierarchy; */ public String getName(); - - /** - * @deprecated will be removed in SLC 2.0, the path should be the part of - * the name with '/' - */ - public String getPath(); } diff --git a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStack.java b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStack.java index c4e88b93d..64cc3a8c5 100644 --- a/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStack.java +++ b/org.argeo.slc.api/src/org/argeo/slc/execution/ExecutionStack.java @@ -15,7 +15,7 @@ */ package org.argeo.slc.execution; -/** Deal with nested level of executions using different vartiables. */ +/** Deal with nested level of executions using different variables. */ public interface ExecutionStack { /** * @param name diff --git a/org.argeo.slc.core/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java b/org.argeo.slc.core/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java index 7cc8705f5..004605cab 100644 --- a/org.argeo.slc.core/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java +++ b/org.argeo.slc.core/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java @@ -20,6 +20,7 @@ import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.core.test.SimpleTestResult; +import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.test.TestResultPart; import org.argeo.slc.test.TestStatus; @@ -59,9 +60,19 @@ public abstract class AbstractExecutionFlowTestCase extends TestCase { protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) { ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix); + ExecutionContext executionContext = (ExecutionContext) applicationContext + .getBean("executionContext"); ExecutionFlow executionFlow = (ExecutionFlow) applicationContext .getBean(beanName); - executionFlow.run(); + if (executionFlow instanceof DefaultExecutionFlow) + ((DefaultExecutionFlow) executionFlow) + .setExecutionContext(executionContext); + try { + executionContext.beforeFlow(executionFlow); + executionFlow.run(); + } finally { + executionContext.afterFlow(executionFlow); + } applicationContext.close(); } diff --git a/org.argeo.slc.core/pom.xml b/org.argeo.slc.core/pom.xml index 653884040..f23f45231 100644 --- a/org.argeo.slc.core/pom.xml +++ b/org.argeo.slc.core/pom.xml @@ -9,6 +9,17 @@ org.argeo.slc.core SLC Runtime + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + @@ -28,6 +39,5 @@ org.argeo.slc.api 2.1.1-SNAPSHOT - \ No newline at end of file diff --git a/org.argeo.slc.core/src/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java b/org.argeo.slc.core/src/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java index 1a07313f0..1d401c6b0 100644 --- a/org.argeo.slc.core/src/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java +++ b/org.argeo.slc.core/src/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java @@ -31,8 +31,8 @@ public abstract class AbstractExecutionModulesManager implements private final static Log log = LogFactory .getLog(AbstractExecutionModulesManager.class); -// private List filteredNotifiers = Collections -// .synchronizedList(new ArrayList()); + // private List filteredNotifiers = Collections + // .synchronizedList(new ArrayList()); protected abstract ExecutionFlow findExecutionFlow(String moduleName, String moduleVersion, String flowName); @@ -64,94 +64,99 @@ public abstract class AbstractExecutionModulesManager implements // // Actually runs the flow, IN THIS THREAD // - flow.run(); + executionContext.beforeFlow(flow); + try { + flow.run(); + } finally { + executionContext.afterFlow(flow); + } // // // } -// public void dispatchUpdateStatus(ExecutionProcess process, -// String oldStatus, String newStatus) { -// // filtered notifiers -// for (Iterator it = filteredNotifiers.iterator(); it -// .hasNext();) { -// FilteredNotifier filteredNotifier = it.next(); -// if (filteredNotifier.receiveFrom(process)) -// filteredNotifier.getNotifier().updateStatus(process, oldStatus, -// newStatus); -// } -// -// } - -// public void dispatchAddSteps(ExecutionProcess process, -// List steps) { -// process.addSteps(steps); -// for (Iterator it = filteredNotifiers.iterator(); it -// .hasNext();) { -// FilteredNotifier filteredNotifier = it.next(); -// if (filteredNotifier.receiveFrom(process)) -// filteredNotifier.getNotifier().addSteps(process, steps); -// } -// } - -// public void registerProcessNotifier(ExecutionProcessNotifier notifier, -// Map properties) { -// filteredNotifiers.add(new FilteredNotifier(notifier, properties)); -// } -// -// public void unregisterProcessNotifier(ExecutionProcessNotifier notifier, -// Map properties) { -// filteredNotifiers.remove(notifier); -// } - -// protected class FilteredNotifier { -// private final ExecutionProcessNotifier notifier; -// private final String processId; -// -// public FilteredNotifier(ExecutionProcessNotifier notifier, -// Map properties) { -// super(); -// this.notifier = notifier; -// if (properties == null) -// properties = new HashMap(); -// if (properties.containsKey(SLC_PROCESS_ID)) -// processId = properties.get(SLC_PROCESS_ID); -// else -// processId = null; -// } -// -// /** -// * Whether event from this process should be received by this listener. -// */ -// public Boolean receiveFrom(ExecutionProcess process) { -// if (processId != null) -// if (process.getUuid().equals(processId)) -// return true; -// else -// return false; -// return true; -// } -// -// @Override -// public int hashCode() { -// return notifier.hashCode(); -// } -// -// @Override -// public boolean equals(Object obj) { -// if (obj instanceof FilteredNotifier) { -// FilteredNotifier fn = (FilteredNotifier) obj; -// return notifier.equals(fn.notifier); -// } else if (obj instanceof ExecutionProcessNotifier) { -// ExecutionProcessNotifier epn = (ExecutionProcessNotifier) obj; -// return notifier.equals(epn); -// } else -// return false; -// } -// -// public ExecutionProcessNotifier getNotifier() { -// return notifier; -// } -// -// } + // public void dispatchUpdateStatus(ExecutionProcess process, + // String oldStatus, String newStatus) { + // // filtered notifiers + // for (Iterator it = filteredNotifiers.iterator(); it + // .hasNext();) { + // FilteredNotifier filteredNotifier = it.next(); + // if (filteredNotifier.receiveFrom(process)) + // filteredNotifier.getNotifier().updateStatus(process, oldStatus, + // newStatus); + // } + // + // } + + // public void dispatchAddSteps(ExecutionProcess process, + // List steps) { + // process.addSteps(steps); + // for (Iterator it = filteredNotifiers.iterator(); it + // .hasNext();) { + // FilteredNotifier filteredNotifier = it.next(); + // if (filteredNotifier.receiveFrom(process)) + // filteredNotifier.getNotifier().addSteps(process, steps); + // } + // } + + // public void registerProcessNotifier(ExecutionProcessNotifier notifier, + // Map properties) { + // filteredNotifiers.add(new FilteredNotifier(notifier, properties)); + // } + // + // public void unregisterProcessNotifier(ExecutionProcessNotifier notifier, + // Map properties) { + // filteredNotifiers.remove(notifier); + // } + + // protected class FilteredNotifier { + // private final ExecutionProcessNotifier notifier; + // private final String processId; + // + // public FilteredNotifier(ExecutionProcessNotifier notifier, + // Map properties) { + // super(); + // this.notifier = notifier; + // if (properties == null) + // properties = new HashMap(); + // if (properties.containsKey(SLC_PROCESS_ID)) + // processId = properties.get(SLC_PROCESS_ID); + // else + // processId = null; + // } + // + // /** + // * Whether event from this process should be received by this listener. + // */ + // public Boolean receiveFrom(ExecutionProcess process) { + // if (processId != null) + // if (process.getUuid().equals(processId)) + // return true; + // else + // return false; + // return true; + // } + // + // @Override + // public int hashCode() { + // return notifier.hashCode(); + // } + // + // @Override + // public boolean equals(Object obj) { + // if (obj instanceof FilteredNotifier) { + // FilteredNotifier fn = (FilteredNotifier) obj; + // return notifier.equals(fn.notifier); + // } else if (obj instanceof ExecutionProcessNotifier) { + // ExecutionProcessNotifier epn = (ExecutionProcessNotifier) obj; + // return notifier.equals(epn); + // } else + // return false; + // } + // + // public ExecutionProcessNotifier getNotifier() { + // return notifier; + // } + // + // } } diff --git a/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlow.java b/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlow.java index 535c42dad..bebde7512 100644 --- a/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlow.java +++ b/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlow.java @@ -24,6 +24,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; +import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; @@ -46,6 +47,9 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, private Boolean failOnError = true; + // Only needed if stacked execution flows are used + private ExecutionContext executionContext = null; + public DefaultExecutionFlow() { this.executionSpec = new DefaultExecutionSpec(); } @@ -154,7 +158,16 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, } public void doExecuteRunnable(Runnable runnable) { - runnable.run(); + try { + if (executionContext != null) + if (runnable instanceof ExecutionFlow) + executionContext.beforeFlow((ExecutionFlow) runnable); + runnable.run(); + } finally { + if (executionContext != null) + if (runnable instanceof ExecutionFlow) + executionContext.afterFlow((ExecutionFlow) runnable); + } } public void afterPropertiesSet() throws Exception { @@ -258,4 +271,8 @@ public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, this.failOnError = failOnError; } + public void setExecutionContext(ExecutionContext executionContext) { + this.executionContext = executionContext; + } + } diff --git a/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java b/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java index 90a9f026f..beac9175a 100644 --- a/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java +++ b/org.argeo.slc.core/src/org/argeo/slc/core/execution/DefaultExecutionFlowDescriptorConverter.java @@ -163,7 +163,6 @@ public class DefaultExecutionFlowDescriptorConverter implements md.getExecutionFlows().addAll(set); } - @SuppressWarnings("deprecation") public ExecutionFlowDescriptor getExecutionFlowDescriptor( ExecutionFlow executionFlow) { if (executionFlow.getName() == null) @@ -213,11 +212,6 @@ public class DefaultExecutionFlowDescriptorConverter implements ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name, null, values, executionSpec); - if (executionFlow.getPath() != null) - efd.setPath(executionFlow.getPath()); - else - efd.setPath(""); - // Takes description from spring BeanFactory bf = getBeanFactory(); if (bf != null) { diff --git a/org.argeo.slc.core/src/org/argeo/slc/core/execution/MapExecutionContext.java b/org.argeo.slc.core/src/org/argeo/slc/core/execution/MapExecutionContext.java index 0bbc3f0df..324f97305 100644 --- a/org.argeo.slc.core/src/org/argeo/slc/core/execution/MapExecutionContext.java +++ b/org.argeo.slc.core/src/org/argeo/slc/core/execution/MapExecutionContext.java @@ -23,6 +23,8 @@ import java.util.UUID; import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionContext; +import org.argeo.slc.execution.ExecutionFlow; +import org.argeo.slc.execution.ExecutionStack; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeansException; @@ -37,6 +39,7 @@ public class MapExecutionContext implements ExecutionContext, private final String uuid; private ApplicationContext applicationContext; + private ExecutionStack executionStack; public MapExecutionContext() { uuid = UUID.randomUUID().toString(); @@ -84,6 +87,12 @@ public class MapExecutionContext implements ExecutionContext, // try system property in last resort if (value == null) value = System.getProperty(key); + + // if the variable was not found, look in the stack starting at the + // upper flows + if (value == null) { + value = executionStack.findLocalVariable(key); + } return value; } @@ -91,6 +100,20 @@ public class MapExecutionContext implements ExecutionContext, return uuid; } + @Override + public void beforeFlow(ExecutionFlow executionFlow) { + // getUuid(); + executionStack.enterFlow(executionFlow); + setVariable(ExecutionContext.VAR_FLOW_ID, + executionStack.getCurrentStackLevelUuid()); + setVariable(ExecutionContext.VAR_FLOW_NAME, executionFlow.getName()); + } + + @Override + public void afterFlow(ExecutionFlow executionFlow) { + executionStack.leaveFlow(executionFlow); + } + @Override public boolean equals(Object obj) { if (obj instanceof ExecutionContext) @@ -108,4 +131,8 @@ public class MapExecutionContext implements ExecutionContext, this.applicationContext = applicationContext; } + public void setExecutionStack(ExecutionStack executionStack) { + this.executionStack = executionStack; + } + } diff --git a/org.argeo.slc.core/src/org/argeo/slc/core/execution/runtime.xml b/org.argeo.slc.core/src/org/argeo/slc/core/execution/runtime.xml index 990d85cb2..33542ee20 100644 --- a/org.argeo.slc.core/src/org/argeo/slc/core/execution/runtime.xml +++ b/org.argeo.slc.core/src/org/argeo/slc/core/execution/runtime.xml @@ -1,21 +1,11 @@ - + + + + diff --git a/org.argeo.slc.core/src/org/argeo/slc/core/execution/simple.xml b/org.argeo.slc.core/src/org/argeo/slc/core/execution/simple.xml index b25f3d130..ff243baf6 100644 --- a/org.argeo.slc.core/src/org/argeo/slc/core/execution/simple.xml +++ b/org.argeo.slc.core/src/org/argeo/slc/core/execution/simple.xml @@ -1,21 +1,11 @@ - +