package org.argeo.slc.core.execution;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.argeo.slc.SlcException;
-import org.argeo.slc.execution.ExecutionContext;
-import org.argeo.slc.execution.ExecutionFlow;
-import org.argeo.slc.execution.ExecutionFlowDescriptor;
-import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
import org.argeo.slc.execution.ExecutionModule;
-import org.argeo.slc.execution.ExecutionModuleDescriptor;
-import org.argeo.slc.execution.ExecutionSpec;
-import org.argeo.slc.execution.ExecutionSpecAttribute;
-import org.springframework.aop.scope.ScopedObject;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.util.Assert;
@Deprecated
public abstract class AbstractSpringExecutionModule implements ExecutionModule
+++ /dev/null
-package org.argeo.slc.core.execution;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.MutablePropertyValues;
-import org.springframework.beans.PropertyValue;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-
-public class ConsoleContextDescriber implements ContextDescriber {
- private final static Log log = LogFactory
- .getLog(ConsoleContextDescriber.class);
-
- public void describeContext(BeanDefinitionRegistry registry) {
- String[] beanNames = registry.getBeanDefinitionNames();
- for (String beanName : beanNames) {
- log("\n## BEAN: " + beanName);
- describeBean(registry.getBeanDefinition(beanName));
- }
- }
-
- public void describeBean(BeanDefinition beanDefinition) {
- log("BeanDefinition class: "+beanDefinition.getClass());
- log("# ATTRIBUTES");
- for(String attr:beanDefinition.attributeNames()){
- log(attr+"="+beanDefinition.getAttribute(attr));
- }
- log("# PROPERTIES");
- MutablePropertyValues pValues = beanDefinition.getPropertyValues();
- for (PropertyValue pv : pValues.getPropertyValues()) {
- log(pv.getName() + "= (" + pv.getValue().getClass() + ") "
- + pv.getValue());
- }
- }
-
- protected void log(Object obj){
- System.out.println(obj);
- }
-}
+++ /dev/null
-package org.argeo.slc.core.execution;
-
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-
-public interface ContextDescriber {
- public void describeContext(BeanDefinitionRegistry registry);
- public void describeBean(BeanDefinition bd);
-}
import java.util.HashMap;
import java.util.Map;
-import java.util.Stack;
import java.util.UUID;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.execution.ExecutionFlow;
import org.argeo.slc.execution.ExecutionSpec;
import org.argeo.slc.execution.ExecutionSpecAttribute;
import org.springframework.beans.factory.BeanNameAware;
public class DefaultExecutionSpec implements ExecutionSpec, BeanNameAware {
- private final static Log log = LogFactory
- .getLog(DefaultExecutionSpec.class);
-
-// private final static ThreadLocal<Stack<ExecutionFlow> > flowStack = new ThreadLocal<Stack<ExecutionFlow> >();
-
private Map<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
private String name = getClass().getName() + "#" + UUID.randomUUID();
placeholder).toString();\r
\r
else {// execution\r
- log.debug("Bean class: " + bean.getClass());\r
// next call fail if no execution context available\r
Object obj = executionContext.getVariable(placeholder);\r
if (obj != null) {\r
}\r
return entriesModified ? newContent : value;\r
} else {\r
- //log.debug(beanName + ": " + value.getClass() + " : " + value);\r
+ // log.debug(beanName + ": " + value.getClass() + " : " + value);\r
return value;\r
}\r
\r
obj = newObj;
threadLocal.set(obj);
threadLocalBeanName.set(name);
- if (log.isDebugEnabled()) {
+ if (log.isTraceEnabled()) {
log.debug(obj.getClass() + " instantiated. (beanName=" + name
+ ")");
}
+++ /dev/null
-package org.argeo.slc.core.execution;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.execution.ExecutionFlow;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
-
-public class InstantiationPostProcessor extends
- InstantiationAwareBeanPostProcessorAdapter {
- private final static Log log = LogFactory
- .getLog(InstantiationPostProcessor.class);
-
- private InstantiationManager instantiationManager;
-
- public InstantiationManager getInstantiationManager() {
- return instantiationManager;
- }
-
- public void setInstantiationManager(InstantiationManager instantiationManager) {
- this.instantiationManager = instantiationManager;
- }
-
- @Override
- public boolean postProcessAfterInstantiation(Object bean, String beanName)
- throws BeansException {
- if (bean instanceof ExecutionFlow)
- instantiationManager
- .flowInitializationStarted((ExecutionFlow) bean, beanName);
- return true;
- }
-
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanName)
- throws BeansException {
- if (bean instanceof ExecutionFlow)
- instantiationManager
- .flowInitializationFinished((ExecutionFlow) bean, beanName);
- return bean;
- }
-
-}
package org.argeo.slc.core.execution;
public class RefSpecAttribute extends AbstractSpecAttribute {
- private Class targetClass;
+ private Class<?> targetClass;
/** Read only. */
private String targetClassName;
private Object value = null;
this.value = value;
}
- public Class getTargetClass() {
+ public Class<?> getTargetClass() {
return targetClass;
}
- public void setTargetClass(Class targetClass) {
+ public void setTargetClass(Class<?> targetClass) {
this.targetClass = targetClass;
this.targetClassName = targetClass.getName();
}
+++ /dev/null
-package org.argeo.slc.core.execution;\r
-\r
-public class SimpleSpringExecutionModule extends AbstractSpringExecutionModule {\r
-\r
- private String name;\r
- private String version;\r
- \r
- public void setName(String name) {\r
- this.name = name;\r
- }\r
-\r
- public void setVersion(String version) {\r
- this.version = version;\r
- }\r
-\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- public String getVersion() {\r
- return version;\r
- }\r
-\r
-}\r
--- /dev/null
+package org.argeo.slc.core.execution.doc;
+
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.PropertyValue;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+
+public class ConsoleContextDescriber implements ContextDescriber {
+ public void describeContext(BeanDefinitionRegistry registry) {
+ String[] beanNames = registry.getBeanDefinitionNames();
+ for (String beanName : beanNames) {
+ log("\n## BEAN: " + beanName);
+ describeBean(registry.getBeanDefinition(beanName));
+ }
+ }
+
+ public void describeBean(BeanDefinition beanDefinition) {
+ log("BeanDefinition class: "+beanDefinition.getClass());
+ log("# ATTRIBUTES");
+ for(String attr:beanDefinition.attributeNames()){
+ log(attr+"="+beanDefinition.getAttribute(attr));
+ }
+ log("# PROPERTIES");
+ MutablePropertyValues pValues = beanDefinition.getPropertyValues();
+ for (PropertyValue pv : pValues.getPropertyValues()) {
+ log(pv.getName() + "= (" + pv.getValue().getClass() + ") "
+ + pv.getValue());
+ }
+ }
+
+ protected void log(Object obj){
+ System.out.println(obj);
+ }
+}
--- /dev/null
+package org.argeo.slc.core.execution.doc;
+
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+
+public interface ContextDescriber {
+ public void describeContext(BeanDefinitionRegistry registry);
+ public void describeBean(BeanDefinition bd);
+}
import org.argeo.slc.process.SlcExecutionStep;\r
import org.argeo.slc.structure.StructureRegistry;\r
\r
+/** Use {@link MethodCall} instead. */\r
+@Deprecated\r
public class SlcManager implements Runnable, SlcExecutionRelated {\r
private String uuid;\r
private String slcExecutionUuid;\r
private String slcExecutionStepUuid;\r
- \r
+\r
private String action;\r
private DeployedSystemManager<DeployedSystem> manager;\r
\r
uuid = UUID.randomUUID().toString();\r
executeActions(StructureRegistry.ALL);\r
}\r
- \r
+\r
protected void executeActions(String mode) {\r
try {\r
- Method method = manager.getClass().getMethod(action, null);\r
- method.invoke(manager, null);\r
+ Class<?>[] argClasses = null;\r
+ Method method = manager.getClass().getMethod(action, argClasses);\r
+ Object[] argObjects = null;\r
+ method.invoke(manager, argObjects);\r
} catch (Exception e) {\r
throw new SlcException("Cannot execute action " + action\r
+ " for manager " + manager, e);\r
}\r
}\r
- \r
+\r
public void setAction(String action) {\r
this.action = action;\r
}\r
public void setSlcExecutionStepUuid(String slcExecutionStepUuid) {\r
this.slcExecutionStepUuid = slcExecutionStepUuid;\r
}\r
- \r
+\r
public void notifySlcExecution(SlcExecution slcExecution) {\r
if (slcExecution != null) {\r
slcExecutionUuid = slcExecution.getUuid();\r
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
-
+
<description>Minimal configuration</description>
-
+
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="execution">
- <ref local="executionScope" />
+ <bean class="org.argeo.slc.core.execution.ExecutionScope" />
</entry>
</map>
</property>
</bean>
- <bean id="executionScope" class="org.argeo.slc.core.execution.ExecutionScope" />
<bean id="executionStack" class="org.argeo.slc.core.execution.DefaultExecutionStack"
scope="execution">
<bean id="instantiationManager" class="org.argeo.slc.core.execution.InstantiationManager" />
- <bean id="parameterRef" factory-bean="instantiationManager"
- factory-method="createRef" abstract="true" />
-
<bean class="org.argeo.slc.core.execution.ExecutionParameterPostProcessor">
<property name="executionContext" ref="executionContext" />
<property name="instantiationManager" ref="instantiationManager" />
import org.springframework.context.support.ClassPathXmlApplicationContext;\r
\r
public abstract class AbstractExecutionFlowTestCase extends TestCase {\r
- \r
+\r
protected final Log log = LogFactory.getLog(getClass());\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
+\r
protected void validateTestResult(SimpleTestResult testResult) {\r
validateTestResult(testResult, TestStatus.PASSED);\r
}\r
- \r
- protected void validateTestResult(SimpleTestResult testResult, int expectedStatus) {\r
- for(TestResultPart part : testResult.getParts()) {\r
- if(part.getStatus() != expectedStatus) {\r
+\r
+ protected void validateTestResult(SimpleTestResult testResult,\r
+ int expectedStatus) {\r
+ for (TestResultPart part : testResult.getParts()) {\r
+ if (part.getStatus() != expectedStatus) {\r
fail("Error found in TestResult: " + part.getMessage());\r
}\r
- } \r
- } \r
- \r
- protected ConfigurableApplicationContext createApplicationContext(String applicationContextSuffix) {\r
- ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));\r
- applicationContext.start();\r
+ }\r
+ }\r
+\r
+ protected ConfigurableApplicationContext createApplicationContext(\r
+ String applicationContextSuffix) {\r
+ ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(\r
+ inPackage(applicationContextSuffix));\r
+ // applicationContext.start();\r
return applicationContext;\r
}\r
- \r
- protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {\r
+\r
+ protected void configureAndExecuteSlcFlow(String applicationContextSuffix,\r
+ String beanName) {\r
ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);\r
- ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);\r
- executionFlow.run(); \r
+ ExecutionFlow executionFlow = (ExecutionFlow) applicationContext\r
+ .getBean(beanName);\r
+ executionFlow.run();\r
applicationContext.close();\r
- } \r
- \r
+ }\r
+\r
protected String inPackage(String suffix) {\r
String prefix = getClass().getPackage().getName().replace('.', '/');\r
return prefix + '/' + suffix;\r
- } \r
+ }\r
}\r
--- /dev/null
+package org.argeo.slc.core.test.context;\r
+\r
+import java.util.Map;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.SlcException;\r
+import org.springframework.beans.factory.BeanFactoryUtils;\r
+import org.springframework.beans.factory.ListableBeanFactory;\r
+import org.springframework.context.ConfigurableApplicationContext;\r
+import org.springframework.context.support.ClassPathXmlApplicationContext;\r
+\r
+/** Helper for tests using a Spring application co,text. */\r
+abstract class AbstractInternalSpringTestCase extends TestCase {\r
+ protected final Log log = LogFactory.getLog(getClass());\r
+ private ConfigurableApplicationContext context;\r
+\r
+ /**\r
+ * Gets (and create if necessary) the application context to use. Default\r
+ * implementation uses a class path xml application context and calls\r
+ * {@link #getApplicationContextLocation()}.\r
+ */\r
+ protected ConfigurableApplicationContext getContext() {\r
+ if (context == null) {\r
+ context = new ClassPathXmlApplicationContext(\r
+ getApplicationContextLocation());\r
+ }\r
+ return context;\r
+ }\r
+\r
+ /** Returns a bean from the underlying context */\r
+ @SuppressWarnings(value = { "unchecked" })\r
+ protected <T> T getBean(String beanId) {\r
+ return (T) getContext().getBean(beanId);\r
+ }\r
+\r
+ protected <T> T getBean(Class<? extends T> clss) {\r
+ T bean = loadSingleFromContext(getContext(), clss);\r
+ if (bean == null) {\r
+ throw new SlcException("Cannot retrieve a unique bean of type "\r
+ + clss);\r
+ } else {\r
+ return bean;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Th location of the application to load. The default implementation\r
+ * returns <i>applicationContext.xml</i> found in the same package as the\r
+ * test.\r
+ */\r
+ protected String getApplicationContextLocation() {\r
+ return inPackage("applicationContext.xml");\r
+ }\r
+\r
+ /**\r
+ * Prefixes the package of the class after converting the '.' to '/' in\r
+ * order to have a resource path.\r
+ */\r
+ protected String inPackage(String suffix) {\r
+ String prefix = getClass().getPackage().getName().replace('.', '/');\r
+ return prefix + '/' + suffix;\r
+ }\r
+\r
+ @SuppressWarnings(value = { "unchecked" })\r
+ protected <T> T loadSingleFromContext(ListableBeanFactory context,\r
+ Class<T> clss) {\r
+ Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(\r
+ context, clss, false, false);\r
+ if (beans.size() == 1) {\r
+ return beans.values().iterator().next();\r
+ } else if (beans.size() > 1) {\r
+ if (log.isDebugEnabled()) {\r
+ log\r
+ .debug(("Found more that on bean for type " + clss\r
+ + ": " + beans.keySet()));\r
+ }\r
+ return null;\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+\r
+}\r
import org.argeo.slc.test.TestResultPart;\r
import org.argeo.slc.test.TestStatus;\r
import org.argeo.slc.test.context.ContextAware;\r
-import org.argeo.slc.unit.internal.AbstractSpringTestCase;\r
\r
-public class ContextTest extends AbstractSpringTestCase {\r
+public class ContextTest extends AbstractInternalSpringTestCase {\r
\r
public void testComplexContext() {\r
SimpleTestResult testResult = new SimpleTestResult();\r
+++ /dev/null
-package org.argeo.slc.unit.internal;\r
-\r
-import java.util.Map;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.springframework.beans.factory.BeanFactoryUtils;\r
-import org.springframework.beans.factory.ListableBeanFactory;\r
-import org.springframework.context.ConfigurableApplicationContext;\r
-import org.springframework.context.support.ClassPathXmlApplicationContext;\r
-\r
-/** Helper for tests using a Spring application co,text. */\r
-public abstract class AbstractSpringTestCase extends TestCase {\r
- protected final Log log = LogFactory.getLog(getClass());\r
- private ConfigurableApplicationContext context;\r
-\r
- /**\r
- * Gets (and create if necessary) the application context to use. Default\r
- * implementation uses a class path xml application context and calls\r
- * {@link #getApplicationContextLocation()}.\r
- */\r
- protected ConfigurableApplicationContext getContext() {\r
- if (context == null) {\r
- context = new ClassPathXmlApplicationContext(\r
- getApplicationContextLocation());\r
- if (getIsStartContext())\r
- context.start();\r
- }\r
- return context;\r
- }\r
-\r
- /** Whether the context should be started after being created. */\r
- protected Boolean getIsStartContext() {\r
- return false;\r
- }\r
-\r
- /** Returns a bean from the underlying context */\r
- @SuppressWarnings(value = { "unchecked" })\r
- protected <T> T getBean(String beanId) {\r
- return (T) getContext().getBean(beanId);\r
- }\r
-\r
- protected <T> T getBean(Class<? extends T> clss) {\r
- T bean = loadSingleFromContext(getContext(), clss);\r
- if (bean == null) {\r
- throw new SlcException("Cannot retrieve a unique bean of type "\r
- + clss);\r
- } else {\r
- return bean;\r
- }\r
- }\r
-\r
- /**\r
- * Th location of the application to load. The default implementation\r
- * returns <i>applicationContext.xml</i> found in the same package as the\r
- * test.\r
- */\r
- protected String getApplicationContextLocation() {\r
- return inPackage("applicationContext.xml");\r
- }\r
-\r
- /**\r
- * Prefixes the package of the class after converting the '.' to '/' in\r
- * order to have a resource path.\r
- */\r
- protected String inPackage(String suffix) {\r
- String prefix = getClass().getPackage().getName().replace('.', '/');\r
- return prefix + '/' + suffix;\r
- }\r
-\r
- @SuppressWarnings(value = { "unchecked" })\r
- protected <T> T loadSingleFromContext(ListableBeanFactory context,\r
- Class<T> clss) {\r
- Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(\r
- context, clss, false, false);\r
- if (beans.size() == 1) {\r
- return beans.values().iterator().next();\r
- } else if (beans.size() > 1) {\r
- if (log.isDebugEnabled()) {\r
- log\r
- .debug(("Found more that on bean for type " + clss\r
- + ": " + beans.keySet()));\r
- }\r
- return null;\r
- } else {\r
- return null;\r
- }\r
- }\r
-\r
-}\r
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<import resource="classpath:org/argeo/slc/core/execution/spring.xml" />