public ExecutionModuleDescriptor getDescriptor();
+ //TODO: remove
public void execute(SlcExecution slcExecution);
+
+ public void execute(ExecutionFlowDescriptor descriptor);
}
applicationContext.publishEvent(new NewExecutionEvent(this,
slcExecution));
}
+
+ public void execute(ExecutionFlowDescriptor descriptor) {
+ ExecutionFlow flow = (ExecutionFlow) applicationContext.getBean(descriptor.getName(),
+ ExecutionFlow.class);
+ flow.execute();
+ }
+
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.execution.ExecutionFlow;
+import org.argeo.slc.execution.ExecutionFlowDescriptor;
import org.argeo.slc.execution.ExecutionModule;
import org.argeo.slc.execution.ExecutionModuleDescriptor;
import org.argeo.slc.execution.ExecutionModulesManager;
+import org.argeo.slc.process.RealizedFlow;
import org.argeo.slc.process.SlcExecution;
import org.springframework.util.Assert;
.getLog(DefaultModulesManager.class);
private List<ExecutionModule> executionModules = new ArrayList<ExecutionModule>();
-
- public ExecutionModuleDescriptor getExecutionModuleDescriptor(
- String moduleName, String version) {
- ExecutionModule module = null;
+
+ protected ExecutionModule getExecutionModule(String moduleName, String version) {
for (ExecutionModule moduleT : executionModules) {
if (moduleT.getName().equals(moduleName)) {
// TODO: check version
- module = moduleT;
- break;
+ return moduleT;
}
}
-
+ return null;
+ }
+
+ public ExecutionModuleDescriptor getExecutionModuleDescriptor(
+ String moduleName, String version) {
+ ExecutionModule module = getExecutionModule(moduleName, version);
+
Assert.notNull(module);
return module.getDescriptor();
public void process(SlcExecution slcExecution) {
log.info("SlcExecution " + slcExecution);
+ for(RealizedFlow flow : slcExecution.getRealizedFlows()) {
+ ExecutionModule module = getExecutionModule(flow.getModuleName(),
+ flow.getModuleVersion());
+ if(module != null) {
+ ExecutionContext executionContext = new ExecutionContext();
+ executionContext.addVariables(slcExecution.getAttributes());
+ ExecutionThread thread = new ExecutionThread(executionContext, flow.getFlowDescriptor(),
+ module);
+ thread.start();
+ }
+ else {
+ // throw exception ?
+ }
+ }
}
+ private class ExecutionThread extends Thread {
+ private final ExecutionFlowDescriptor executionFlowDescriptor;
+ private final ExecutionContext executionContext;
+ private final ExecutionModule executionModule;
+
+ public ExecutionThread(ExecutionContext executionContext,
+ ExecutionFlowDescriptor executionFlowDescriptor,
+ ExecutionModule executionModule) {
+ super("SLC Execution #" + executionContext.getUuid());
+ this.executionFlowDescriptor = executionFlowDescriptor;
+ this.executionContext = executionContext;
+ this.executionModule = executionModule;
+ }
+
+ public void run() {
+ ExecutionContext.registerExecutionContext(executionContext);
+ try {
+ executionModule.execute(executionFlowDescriptor);
+ } catch (Exception e) {
+ log.error("Execution " + executionContext.getUuid()
+ + " failed.", e);
+ }
+ }
+ }
+
}
return null;
return executionContext.get().variables;
}
+
+ public void addVariables(Map<? extends String, ? extends Object> variablesToAdd) {
+ variables.putAll(variablesToAdd);
+ }
public static ExecutionContext getCurrent() {
return executionContext.get();
--- /dev/null
+package org.argeo.slc.core.execution;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.argeo.slc.SlcException;\r
+import org.argeo.slc.execution.ExecutionFlowDescriptor;\r
+import org.argeo.slc.execution.ExecutionModule;\r
+import org.argeo.slc.process.RealizedFlow;\r
+import org.argeo.slc.process.SlcExecution;\r
+import org.argeo.slc.unit.AbstractSpringTestCase;\r
+import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.ConfigurableApplicationContext;\r
+import org.springframework.context.support.ClassPathXmlApplicationContext;\r
+\r
+import junit.framework.TestCase;\r
+\r
+public class DefaultModulesMangerTest extends AbstractSpringTestCase {\r
+\r
+ public void testSimpleExecution() throws Exception {\r
+ //do nothing\r
+ \r
+ // create an execution\r
+ SlcExecution execution = new SlcExecution();\r
+ execution.setUuid("TestUUID");\r
+ List<RealizedFlow> realizedFlows = new ArrayList<RealizedFlow>();\r
+ RealizedFlow flow = new RealizedFlow();\r
+ flow.setModuleName("dummyname");\r
+ flow.setModuleVersion("dummyversion");\r
+ ExecutionFlowDescriptor executionFlowDescriptor = new ExecutionFlowDescriptor();\r
+ executionFlowDescriptor.setName("main");\r
+ flow.setFlowDescriptor(executionFlowDescriptor);\r
+ realizedFlows.add(flow);\r
+ execution.setRealizedFlows(realizedFlows);\r
+ \r
+ // create a module\r
+ ApplicationContext applicationContext = prepareExecution("applicationContext.xml");\r
+ ExecutionModule module = createExecutionModule(applicationContext);\r
+ \r
+ // create an Execution Module Manager\r
+ DefaultModulesManager manager = new DefaultModulesManager();\r
+ List<ExecutionModule> modules = new ArrayList<ExecutionModule>();\r
+ modules.add(module);\r
+ manager.setExecutionModules(modules);\r
+ \r
+ manager.process(execution);\r
+ } \r
+ \r
+ protected ExecutionModule createExecutionModule(ApplicationContext applicationContext) {\r
+ AbstractSpringExecutionModule module = new AbstractSpringExecutionModule() {\r
+ public String getName() {return "dummyname";}\r
+ public String getVersion() {return "dummyversion";} \r
+ };\r
+ module.setApplicationContext(applicationContext);\r
+ return module;\r
+ }\r
+ \r
+ protected ConfigurableApplicationContext prepareExecution(String applicationContextSuffix) {\r
+ ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));\r
+ applicationContext.start();\r
+ return applicationContext;\r
+ } \r
+ \r
+}\r
package org.argeo.slc.core.execution;\r
\r
+import org.argeo.slc.core.test.SimpleTestResult;\r
import org.argeo.slc.execution.ExecutionFlow;\r
+import org.argeo.slc.test.TestStatus;\r
import org.argeo.slc.unit.AbstractSpringTestCase;\r
import org.springframework.beans.factory.BeanCreationException;\r
import org.springframework.context.ConfigurableApplicationContext;\r
public class ExecutionFlowTest extends AbstractSpringTestCase {\r
\r
public void testSimpleExecution() throws Exception {\r
-// configureAndExecuteSlcFlow("main");\r
configureAndExecuteSlcFlow("applicationContext.xml", "main");\r
}\r
\r
public void testCanonic() throws Exception {\r
- configureAndExecuteSlcFlow("minimal.xml", "minimal");\r
// Parameter without default value in specification\r
configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
-// configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
+ configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
\r
/* try {\r
configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");\r
fail("Parameter not set - should be rejected.");\r
} catch (BeanCreationException e) {\r
// exception expected\r
- //e.printStackTrace();\r
- }*/\r
- \r
+ logException(e);\r
+ }\r
+*/ \r
/* try {\r
configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");\r
- fail("Unkown parameter set - should be rejected.");\r
+ fail("Unknown parameter set - should be rejected.");\r
} catch (BeanCreationException e) {\r
// exception expected\r
- //e.printStackTrace();\r
- } */\r
+ logException(e);\r
+ } */\r
} \r
\r
- protected void configureSlcFlow(String beanName) {\r
+/* public void testRecursive() throws Exception {\r
+ ConfigurableApplicationContext applicationContext = prepareExecution("test.xml");\r
+ ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("first");\r
+ executionFlow.execute(); \r
+ SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("basicTestResult");\r
+ if(res.getParts().get(0).getStatus() != TestStatus.PASSED) {\r
+ fail("Unexpected string returned");\r
+ }\r
+ applicationContext.close(); \r
+ }*/\r
+ \r
+ protected void logException(Throwable ex) {\r
+ log.info("Got Exception of class " + ex.getClass().toString()\r
+ + " with message '" + ex.getMessage() + "'.");\r
+ }\r
+ \r
+ protected void initExecutionContext() {\r
// if an execution context was registered, unregister it\r
if(ExecutionContext.getCurrent() != null) {\r
ExecutionContext.unregisterExecutionContext();\r
}\r
// register a new ExecutionContext\r
- ExecutionContext.registerExecutionContext(new ExecutionContext());\r
- \r
-// ExecutionContext.getVariables().put("slc.flows", beanName);\r
- }\r
- \r
-/* \r
- @Override\r
- protected Boolean getIsStartContext() {\r
- return true;\r
- }\r
-\r
- @Override\r
- protected ConfigurableApplicationContext getContext() {\r
- return getStaticContext();\r
- }\r
-\r
- private static ConfigurableApplicationContext staticContext; \r
- \r
- protected ConfigurableApplicationContext getStaticContext() {\r
- if (staticContext == null) {\r
- staticContext = new ClassPathXmlApplicationContext(\r
- getApplicationContextLocation());\r
- if(getIsStartContext())\r
- staticContext.start();\r
- }\r
- return staticContext; \r
+ ExecutionContext.registerExecutionContext(new ExecutionContext()); \r
}\r
\r
- protected void configureAndExecuteSlcFlow(String beanName) {\r
- // Triggers a start of the ApplicationContext\r
- // Required before starting some tests\r
- // TODO: understand why !\r
- getContext(); \r
- configureSlcFlow(beanName);\r
- ExecutionFlow executionFlow = (ExecutionFlow) getContext().getBean(beanName);\r
- executionFlow.execute(); \r
+ protected ConfigurableApplicationContext prepareExecution(String applicationContextSuffix) {\r
+ ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));\r
+ applicationContext.start();\r
+ initExecutionContext();\r
+ return applicationContext;\r
}\r
- */\r
\r
protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {\r
- // create a new context\r
- ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(\r
- inPackage(applicationContextSuffix));\r
- applicationContext.start();\r
- \r
- configureSlcFlow(beanName);\r
+ ConfigurableApplicationContext applicationContext = prepareExecution(applicationContextSuffix);\r
ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);\r
executionFlow.execute(); \r
-// applicationContext.stop();\r
applicationContext.close();\r
} \r
}\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+ xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+ xmlns:aop="http://www.springframework.org/schema/aop"\r
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+ <import resource="imports.xml" /> \r
+\r
+ <bean id="second" parent="slcTemplate.simpleFlow">\r
+ <property name="executionSpec">\r
+ <bean parent="slcTemplate.simpleSpec">\r
+ <property name="attributes">\r
+ <map>\r
+ <entry key="testKey">\r
+ <bean parent="specAttr.primitive" p:value="second" />\r
+ </entry>\r
+ </map>\r
+ </property>\r
+ </bean>\r
+ </property>\r
+ <property name="executables">\r
+ <list>\r
+ <ref local="echo1" />\r
+ <bean class="org.argeo.slc.core.test.SimpleTestRun">\r
+ <property name="testDefinition" ref="basic.testDef" />\r
+ <property name="testData" ref="basic.testData" />\r
+ <property name="testResult" ref="basicTestResult"/>\r
+ </bean> \r
+ </list>\r
+ </property>\r
+ </bean>\r
+\r
+\r
+ <bean id="first" parent="slcTemplate.simpleFlow">\r
+ <property name="executionSpec">\r
+ <bean parent="slcTemplate.simpleSpec">\r
+ <property name="attributes">\r
+ <map>\r
+ <entry key="testKey">\r
+ <bean parent="specAttr.primitive" p:value="first" />\r
+ </entry>\r
+ </map>\r
+ </property>\r
+ </bean>\r
+ </property>\r
+ <property name="executables">\r
+ <list>\r
+ <ref local="second" />\r
+ </list>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="basic.testData" class="org.argeo.slc.core.test.BasicTestData" scope="execution">\r
+ <aop:scoped-proxy />\r
+ <property name="expected" value="first" />\r
+ <property name="reached" value="@{testKey}" />\r
+ </bean>\r
+ \r
+ <bean id="basic.testDef" class="org.argeo.slc.core.test.BasicTestDefinition">\r
+ <aop:scoped-proxy />\r
+ </bean> \r
+\r
+\r
+ <bean id="echo1" parent="task.echo" scope="execution">\r
+ <property name="message"\r
+ value="testKey=@{testKey}" />\r
+ <aop:scoped-proxy />\r
+ </bean>\r
+ \r
+ <bean id="basicTestResult" class="org.argeo.slc.core.test.SimpleTestResult" />\r
+\r
+</beans>
\ No newline at end of file