From: Mathieu Baudier Date: Fri, 27 Feb 2009 20:44:02 +0000 (+0000) Subject: Improve execution specs X-Git-Tag: argeo-slc-2.1.7~2102 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=743ecb28b3c0236bc91a5d0993f70477236d96fd;hp=51d1c842e4e92cc65708b8bb88152d7344d43d04;p=gpl%2Fargeo-slc.git Improve execution specs git-svn-id: https://svn.argeo.org/slc/trunk@2200 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/basic.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/basic.xml index 168a56c9a..a513e3f4f 100644 --- a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/basic.xml +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/basic.xml @@ -7,28 +7,31 @@ 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"> - + - + - + - + - + - - + @@ -52,34 +55,11 @@ - - + + - - - - - - - - - - - \ No newline at end of file diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/canonic.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/canonic.xml new file mode 100644 index 000000000..ddc7acae5 --- /dev/null +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/canonic.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/common.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/common.xml index 4ed1362f7..75f40055c 100644 --- a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/common.xml +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/common.xml @@ -1,19 +1,17 @@ - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/imports.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/imports.xml index 68316a1b9..6bff52fb1 100644 --- a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/imports.xml +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/imports.xml @@ -6,4 +6,7 @@ + + \ No newline at end of file diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/main.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/main.xml index 6b943dc7f..5d849311e 100644 --- a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/main.xml +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/main.xml @@ -7,20 +7,15 @@ 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"> - - - + - + - + @@ -32,18 +27,15 @@ + + - + - - - - \ No newline at end of file diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-001.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-001.xml index a5426649e..7571fc957 100644 --- a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-001.xml +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-001.xml @@ -7,7 +7,7 @@ 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"> - + diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-002.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-002.xml index c2946fdfb..5720d9693 100644 --- a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-002.xml +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/basic-002.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/canonic-001.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/canonic-001.xml new file mode 100644 index 000000000..77d4fee64 --- /dev/null +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/canonic-001.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/canonic-002.xml b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/canonic-002.xml new file mode 100644 index 000000000..5916c08e6 --- /dev/null +++ b/demo/org.argeo.slc.demo.basic/src/main/resources/conf/testCases/canonic-002.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + diff --git a/demo/org.argeo.slc.demo.basic/src/test/java/org/argeo/slc/demo/basic/BasicExecutionTest.java b/demo/org.argeo.slc.demo.basic/src/test/java/org/argeo/slc/demo/basic/BasicExecutionTest.java index fc914a16e..0d703cdad 100644 --- a/demo/org.argeo.slc.demo.basic/src/test/java/org/argeo/slc/demo/basic/BasicExecutionTest.java +++ b/demo/org.argeo.slc.demo.basic/src/test/java/org/argeo/slc/demo/basic/BasicExecutionTest.java @@ -1,22 +1,29 @@ package org.argeo.slc.demo.basic; +import java.util.Map; + import junit.framework.TestCase; import org.argeo.slc.core.execution.ExecutionContext; -import org.argeo.slc.core.execution.NewExecutionEvent; import org.argeo.slc.execution.ExecutionFlow; -import org.argeo.slc.process.SlcExecution; +import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor; import org.springframework.context.support.ClassPathXmlApplicationContext; public class BasicExecutionTest extends TestCase { public void testExecution() throws Exception { - String[] files = { "conf/main.xml", "conf/imports.xml", - "conf/common.xml", "conf/basic.xml", - "conf/testCases/basic-001.xml", "conf/testCases/basic-002.xml" }; + String[] files = { "conf/imports.xml", "conf/common.xml", + "conf/basic.xml", "conf/canonic.xml", + "conf/testCases/basic-001.xml", "conf/testCases/basic-002.xml", + "conf/testCases/canonic-001.xml", + "conf/testCases/canonic-002.xml", "conf/main.xml" }; ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( files); applicationContext.start(); + // GenericBeanFactoryAccessor accessor = new + // GenericBeanFactoryAccessor(applicationContext); + // Map + String bean = "main"; ExecutionContext.registerExecutionContext(new ExecutionContext()); ExecutionContext.getVariables().put("slc.flows", bean); @@ -24,12 +31,12 @@ public class BasicExecutionTest extends TestCase { .getBean(bean); executionFlow.execute(); -// SlcExecution slcExecution = new SlcExecution(); -// slcExecution.getAttributes().put("slc.flows", "main"); -// applicationContext.publishEvent(new NewExecutionEvent(this, -// slcExecution)); -// -// Thread.sleep(5000); + // SlcExecution slcExecution = new SlcExecution(); + // slcExecution.getAttributes().put("slc.flows", "main"); + // applicationContext.publishEvent(new NewExecutionEvent(this, + // slcExecution)); + // + // Thread.sleep(5000); applicationContext.close(); } diff --git a/demo/org.argeo.slc.demo.manager/src/main/resources/conf/manager-osgi.xml b/demo/org.argeo.slc.demo.manager/src/main/resources/conf/manager-osgi.xml index a37132e76..bc9fa6904 100644 --- a/demo/org.argeo.slc.demo.manager/src/main/resources/conf/manager-osgi.xml +++ b/demo/org.argeo.slc.demo.manager/src/main/resources/conf/manager-osgi.xml @@ -6,5 +6,6 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - + \ No newline at end of file diff --git a/demo/org.argeo.slc.demo.manager/src/test/java/org/argeo/slc/demo/manager/JmsTesting.java b/demo/org.argeo.slc.demo.manager/src/test/java/org/argeo/slc/demo/manager/JmsTesting.java index 21575fa0b..31122e213 100644 --- a/demo/org.argeo.slc.demo.manager/src/test/java/org/argeo/slc/demo/manager/JmsTesting.java +++ b/demo/org.argeo.slc.demo.manager/src/test/java/org/argeo/slc/demo/manager/JmsTesting.java @@ -1,16 +1,19 @@ package org.argeo.slc.demo.manager; +import java.net.URI; +import java.net.URISyntaxException; + import javax.jms.ConnectionFactory; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.Session; import javax.jms.TextMessage; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; -import org.springframework.beans.BeansException; -import org.springframework.jms.JmsException; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; @@ -21,10 +24,29 @@ public class JmsTesting { * @param args */ public static void main(String[] args) { +// BrokerService broker; +// try { +// broker = new BrokerService(); +// broker.setPersistent(false); +// TransportConnector transportConnector = new TransportConnector(); +// transportConnector.setUri(new URI("tcp://localhost:61616")); +// broker.addConnector(transportConnector); +// broker.start(); +// +// Thread.sleep(5000); +// } catch (URISyntaxException e1) { +// // TODO Auto-generated catch block +// e1.printStackTrace(); +// } catch (Exception e1) { +// // TODO Auto-generated catch block +// e1.printStackTrace(); +// } + ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "org/argeo/slc/activemq/spring.xml"); try { + ConnectionFactory connectionFactory = (ConnectionFactory) applicationContext .getBean("slcDefault.jms.connectionFactory"); JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory); diff --git a/org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java b/org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java index d7da1e673..17b5f139e 100644 --- a/org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java +++ b/org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java @@ -285,7 +285,7 @@ public class Main { } private static void info(Object obj) { - System.out.println("[INFO] " + obj); + //System.out.println("[INFO] " + obj); } private static void bundleInstallWarn(Object obj) { diff --git a/org.argeo.slc/pom.xml b/org.argeo.slc/pom.xml index f90ea744d..1416cfd53 100644 --- a/org.argeo.slc/pom.xml +++ b/org.argeo.slc/pom.xml @@ -776,6 +776,11 @@ limitations under the License. com.springsource.org.apache.activemq.web ${version.activemq} + + org.apache.activemq + com.springsource.org.apache.activemq.pool + ${version.activemq} + + @@ -73,20 +74,48 @@ + + + + + + - + - + + + + - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java index c8da41a90..c38d866d7 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.argeo.slc.core.execution.SimpleExecutionFlow; +import org.argeo.slc.core.execution.DefaultExecutionFlow; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.process.Executable; @@ -13,7 +13,7 @@ public class ExecutionFlowFactory { public ExecutionFlow createExecutionFlow(Map attributes){ - SimpleExecutionFlow executionFlow = new SimpleExecutionFlow(); + DefaultExecutionFlow executionFlow = new DefaultExecutionFlow(); executionFlow.setExecutables(executables); return executionFlow; } diff --git a/runtime/org.argeo.slc.support.simple/pom.xml b/runtime/org.argeo.slc.support.simple/pom.xml index 2e7c091f5..3753cb576 100644 --- a/runtime/org.argeo.slc.support.simple/pom.xml +++ b/runtime/org.argeo.slc.support.simple/pom.xml @@ -38,6 +38,7 @@ org.argeo.slc.*,org.argeo.slc.core.test.spring *,org.apache.commons.logging;version="1.1", + org.hibernate.proxy;resolution:="optional", org.dbunit;resolution:="optional", org.dbunit.database;resolution:="optional", org.dbunit.dataset;resolution:="optional", diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpecAttribute.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpecAttribute.java index b8a599bdb..52f1adae5 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpecAttribute.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpecAttribute.java @@ -3,8 +3,11 @@ package org.argeo.slc.core.execution; import org.argeo.slc.execution.ExecutionSpecAttribute; public abstract class AbstractSpecAttribute implements ExecutionSpecAttribute { - private Boolean isParameter = true; + private Boolean isParameter = false; + private Boolean isFrozen = false; + private Boolean isHidden = false; + /** Has to be set at instantiation */ public Boolean getIsParameter() { return isParameter; } @@ -13,4 +16,22 @@ public abstract class AbstractSpecAttribute implements ExecutionSpecAttribute { this.isParameter = isParameter; } + /** Cannot be overridden at runtime */ + public Boolean getIsFrozen() { + return isFrozen; + } + + public void setIsFrozen(Boolean isFinal) { + this.isFrozen = isFinal; + } + + /** Should not be shown to the end user */ + public Boolean getIsHidden() { + return isHidden; + } + + public void setIsHidden(Boolean isHidden) { + this.isHidden = isHidden; + } + } diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java index fa42917fd..4e0842e37 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java @@ -2,7 +2,9 @@ package org.argeo.slc.core.execution; import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; +import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.execution.ExecutionModule; @@ -10,6 +12,7 @@ import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; import org.argeo.slc.process.SlcExecution; +import org.springframework.aop.scope.ScopedObject; import org.springframework.beans.BeansException; import org.springframework.beans.factory.generic.GenericBeanFactoryAccessor; import org.springframework.context.ApplicationContext; @@ -40,21 +43,46 @@ public abstract class AbstractSpringExecutionModule implements ExecutionModule, Assert.notNull(executionSpec); Assert.notNull(executionSpec.getName()); - Map values = new HashMap(); + Map values = new TreeMap(); for (String key : executionSpec.getAttributes().keySet()) { ExecutionSpecAttribute attribute = executionSpec .getAttributes().get(key); - if (attribute instanceof SimpleExecutionSpec - && attribute.getIsParameter()) { - values.put(key, executionFlow.getParameter(key)); + + if (executionFlow.isSetAsParameter(key)) { + Object value = executionFlow.getParameter(key); + if (attribute instanceof PrimitiveSpecAttribute) { + PrimitiveValue primitiveValue = new PrimitiveValue(); + primitiveValue + .setType(((PrimitiveSpecAttribute) attribute) + .getType()); + primitiveValue.setValue(value); + values.put(key, primitiveValue); + } else if (attribute instanceof RefSpecAttribute) { + RefValue refValue = new RefValue(); + if (value instanceof ScopedObject) { + refValue.setLabel("RUNTIME " + + value.getClass().getName()); + } else { + refValue.setLabel("STATIC " + + value.getClass().getName()); + } + values.put(key, refValue); + } else { + throw new SlcException("Unkown spec attribute type " + + attribute.getClass()); + } } + } ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(name, values, executionSpec); + // Add execution spec if necessary if (!md.getExecutionSpecs().contains(executionSpec)) md.getExecutionSpecs().add(executionSpec); + + // Add execution flow md.getExecutionFlows().add(efd); } diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java new file mode 100644 index 000000000..e2c343de3 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java @@ -0,0 +1,143 @@ +package org.argeo.slc.core.execution; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang.math.RandomUtils; +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.argeo.slc.process.Executable; +import org.argeo.slc.test.ExecutableTestRun; +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.validation.MapBindingResult; + +public class DefaultExecutionFlow implements ExecutionFlow, InitializingBean, + BeanNameAware { + private ExecutionSpec executionSpec = new DefaultExecutionSpec(); + private String name = null; + private Map parameters = new HashMap(); + private List executables = new ArrayList(); + + public DefaultExecutionFlow() { + + } + + public DefaultExecutionFlow(Map parameters) { + this.parameters.putAll(parameters); + } + + public void execute() { + for (Executable executable : executables) { + executable.execute(); + } + } + + public void afterPropertiesSet() throws Exception { + // Validate execution specs + if (executionSpec == null) + return; + + MapBindingResult errors = new MapBindingResult(parameters, "execution#" + + getName()); + for (String key : executionSpec.getAttributes().keySet()) { + ExecutionSpecAttribute attr = executionSpec.getAttributes() + .get(key); + + if (attr.getIsParameter() && !isSetAsParameter(key)) { + errors.rejectValue(key, "Parameter not set"); + break; + } + + if (attr.getIsFrozen() && !isSetAsParameter(key)) { + errors.rejectValue(key, "Frozen but not set as parameter"); + break; + } + + if (attr.getIsHidden() && !isSetAsParameter(key)) { + errors.rejectValue(key, "Hidden but not set as parameter"); + break; + } + + /* + * if (!parameters.containsKey(key)) { Object defaultValue = + * attr.getValue(); if (defaultValue == null) + * errors.rejectValue(key, "Not set and no default value"); else + * parameters.put(key, defaultValue); } else {// contains key Object + * obj = parameters.get(key); if (attr instanceof RefSpecAttribute) + * { RefSpecAttribute rsa = (RefSpecAttribute) attr; // TODO: make + * sure this will not cause pb with OSGi Class targetClass = + * rsa.getTargetClass(); if + * (!targetClass.isAssignableFrom(obj.getClass())) { + * errors.reject(key + " not compatible with target class " + + * targetClass); } } } + */ + } + + if (errors.hasErrors()) + throw new SlcException("Could not prepare execution flow: " + + errors.toString()); + } + + public void setBeanName(String name) { + this.name = name; + } + + public void setExecutables(List executables) { + this.executables = executables; + } + + public void setExecutionSpec(ExecutionSpec executionSpec) { + this.executionSpec = executionSpec; + } + + public void setParameters(Map attributes) { + this.parameters = attributes; + } + + public String getName() { + return name; + } + + public ExecutionSpec getExecutionSpec() { + return executionSpec; + } + + public Object getParameter(String name) { + if (parameters.containsKey(name)) { + return parameters.get(name); + } else { + if (executionSpec.getAttributes().containsKey(name)) { + ExecutionSpecAttribute esa = executionSpec.getAttributes().get( + name); + if (esa.getValue() != null) + return esa.getValue(); + } else { + throw new SlcException("Key " + name + + " is not defined in the specifications of " + + toString()); + } + } + throw new SlcException("Key " + name + " is not set as parameter in " + + toString()); + } + + public Boolean isSetAsParameter(String key) { + return parameters.containsKey(key) + || (executionSpec.getAttributes().containsKey(key) && executionSpec + .getAttributes().get(key).getValue() != null); + } + + public String toString() { + return new StringBuffer("Flow ").append(name).toString(); + } + + public boolean equals(Object obj) { + return ((ExecutionFlow) obj).getName().equals(name); + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionSpec.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionSpec.java new file mode 100644 index 000000000..6711f658d --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionSpec.java @@ -0,0 +1,93 @@ +package org.argeo.slc.core.execution; + +import java.util.HashMap; +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.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 initializingFlow = new ThreadLocal(); + + private Map attributes = new HashMap(); + + private String name = null; + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + public Object createRef(String name) { + ExecutionFlow flow = initializingFlow.get(); + if (flow == null) + throw new SlcException("No flow is currently initializing." + + " Declare flow refs as inner beans or prototypes."); + /* + * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes + * .get(name); Class targetClass = refSpecAttribute.getTargetClass(); + * ExecutionTargetSource targetSource = new ExecutionTargetSource(flow, + * targetClass, name); ProxyFactory proxyFactory = new ProxyFactory(); + * proxyFactory.setTargetClass(targetClass); + * proxyFactory.setProxyTargetClass(true); + * proxyFactory.setTargetSource(targetSource); + * + * return proxyFactory.getProxy(); + */ + return flow.getParameter(name); + } + + public void setBeanName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + // FLOWS INITIALIZATION SUPPORT + + public static void flowInitializationStarted(ExecutionFlow flow) { + if (log.isTraceEnabled()) + log.trace("Start initialization of " + flow.hashCode() + " (" + + flow + " - " + flow.getClass() + ")"); + initializingFlow.set(flow); + } + + public static void flowInitializationFinished(ExecutionFlow flow) { + if (log.isTraceEnabled()) + log.trace("Finish initialization of " + flow.hashCode() + " (" + + flow + " - " + flow.getClass() + ")"); + ExecutionFlow registeredFlow = initializingFlow.get(); + if (registeredFlow != null) { + if (!flow.getName().equals(registeredFlow.getName())) + throw new SlcException("Current flow is " + flow); + initializingFlow.set(null); + } + } + + public static Object getInitializingFlowParameter(String key) { + if (initializingFlow.get() == null) + throw new SlcException("No initializing flow available."); + return initializingFlow.get().getParameter(key); + } + + public static Boolean isInFlowInitialization() { + return initializingFlow.get() != null; + } + + public boolean equals(Object obj) { + return ((ExecutionSpec) obj).getName().equals(name); + } + +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionContext.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionContext.java index 97f7268b6..732dd819e 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionContext.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionContext.java @@ -61,8 +61,8 @@ public class ExecutionContext { Map specAttrs = executionFlow .getExecutionSpec().getAttributes(); for (String key : specAttrs.keySet()) { - ExecutionSpecAttribute esa = specAttrs.get(key); - if (esa.getIsParameter()) { + //ExecutionSpecAttribute esa = specAttrs.get(key); + if (executionFlow.isSetAsParameter(key)) { runtime.getLocalVariables().put(key, executionFlow.getParameter(key)); if (log.isTraceEnabled()) diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java index d393d774f..a95670b10 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java @@ -28,48 +28,37 @@ public class ExecutionParameterPostProcessor extends public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { - if (!ExecutionContext.isExecuting()) + if (!ExecutionContext.isExecuting()){ + //&& !DefaultExecutionSpec.isInFlowInitialization()) { + //log.info("Skip parameter conversion for bean " + beanName); return pvs; - -// ExecutionFlow currentFlow = ExecutionContext.getCurrentFlow(); -// -// Properties props = new Properties(); -// Map attributes = currentFlow.getAttributes(); -// Map specAttributes = currentFlow -// .getExecutionSpec().getAttributes(); -// -// for (String key : specAttributes.keySet()) { -// ExecutionSpecAttribute obj = specAttributes.get(key); -// if (!(obj instanceof RefSpecAttribute)) { -// if (!attributes.containsKey(key)) -// throw new SlcException("Specified attribute " + key -// + " is not set in " + currentFlow); -// -// props.setProperty(key, attributes.get(key).toString()); -// // if (log.isTraceEnabled()) -// // log.trace("Use attribute " + key); -// } -// } + } else { + //log.info("Execute parameter conversion for bean " + beanName); + } Properties props = new Properties(); CustomPpc ppc = new CustomPpc(props); for (PropertyValue pv : pvs.getPropertyValues()) { +// log.info(" PropertyValue pv " + pv.getValue() + " - " +// + pv.getValue().getClass()); + String originalValue = null; + String convertedValue = null; if (pv.getValue() instanceof TypedStringValue) { TypedStringValue tsv = (TypedStringValue) pv.getValue(); - String originalValue = tsv.getValue(); - String convertedValue = ppc.process(originalValue); + originalValue = tsv.getValue(); + convertedValue = ppc.process(originalValue); tsv.setValue(convertedValue); - if (log.isTraceEnabled()) { - if (!originalValue.equals(convertedValue)) - log.trace("Converted field '" + pv.getName() + "': '" - + originalValue + "' to '" + convertedValue - + "' in bean " + beanName); - } - } else { - // if (log.isTraceEnabled()) - // log.trace(beanName + "[" + pv.getName() + "]: " - // + pv.getValue().getClass()); + } else if (pv.getValue() instanceof String) { + originalValue = pv.getValue().toString(); + convertedValue = ppc.process(originalValue); + pv.setConvertedValue(convertedValue); + } + if (convertedValue != null && log.isTraceEnabled()) { + if (!originalValue.equals(convertedValue)) + log.trace("Converted field '" + pv.getName() + "': '" + + originalValue + "' to '" + convertedValue + + "' in bean " + beanName); } } @@ -107,10 +96,11 @@ public class ExecutionParameterPostProcessor extends @Override protected String resolvePlaceholder(String placeholder, Properties props) { + //log.info("Try convert placeholder " + placeholder); if (ExecutionContext.isExecuting()) return ExecutionContext.getVariable(placeholder).toString(); - else if (SimpleExecutionSpec.isInFlowInitialization()) - return SimpleExecutionSpec.getInitializingFlowParameter( + else if (DefaultExecutionSpec.isInFlowInitialization()) + return DefaultExecutionSpec.getInitializingFlowParameter( placeholder).toString(); else return super.resolvePlaceholder(placeholder, props); diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/InstantiationPostProcessor.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/InstantiationPostProcessor.java index d9ff3d521..785043958 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/InstantiationPostProcessor.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/InstantiationPostProcessor.java @@ -15,16 +15,24 @@ public class InstantiationPostProcessor extends public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException { if (bean instanceof ExecutionFlow) - SimpleExecutionSpec.flowInitializationStarted((ExecutionFlow) bean); + DefaultExecutionSpec + .flowInitializationStarted((ExecutionFlow) bean); return true; } @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) + throws BeansException { if (bean instanceof ExecutionFlow) - SimpleExecutionSpec + DefaultExecutionSpec .flowInitializationFinished((ExecutionFlow) bean); return bean; } + } diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java new file mode 100644 index 000000000..daddc0aa8 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java @@ -0,0 +1,34 @@ +package org.argeo.slc.core.execution; + +public class PrimitiveSpecAttribute extends AbstractSpecAttribute { +// public enum Type { +// string, integer +// } + + public final static String TYPE_STRING = "string"; + public final static String TYPE_INTEGER = "integer"; + public final static String TYPE_LONG = "long"; + public final static String TYPE_FLOAT = "float"; + public final static String TYPE_DOUBLE = "double"; + public final static String TYPE_BOOLEAN = "boolean"; + + private String type = "string"; + private Object value = null; + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java new file mode 100644 index 000000000..e29d67e90 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java @@ -0,0 +1,24 @@ +package org.argeo.slc.core.execution; + +public class PrimitiveValue { + private String type; + + private Object value; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java new file mode 100644 index 000000000..bc5336caa --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java @@ -0,0 +1,14 @@ +package org.argeo.slc.core.execution; + +public class RefValue { + private String label; + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionFlow.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionFlow.java deleted file mode 100644 index 2f351fbd5..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionFlow.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.argeo.slc.core.execution; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang.math.RandomUtils; -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.argeo.slc.process.Executable; -import org.argeo.slc.test.ExecutableTestRun; -import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.validation.MapBindingResult; - -public class SimpleExecutionFlow implements ExecutionFlow, InitializingBean, - BeanNameAware { - private ExecutionSpec executionSpec = new SimpleExecutionSpec(); - private String name = null; - private Map parameters = new HashMap(); - private List executables = new ArrayList(); - - public SimpleExecutionFlow() { - - } - - public SimpleExecutionFlow(Map parameters) { - this.parameters.putAll(parameters); - } - - public void execute() { - for (Executable executable : executables) { - executable.execute(); - } - } - - public void afterPropertiesSet() throws Exception { - // Validate execution specs - if (executionSpec == null) - return; - - MapBindingResult errors = new MapBindingResult(parameters, "execution#" - + getName()); - for (String key : executionSpec.getAttributes().keySet()) { - ExecutionSpecAttribute executionSpecAttr = executionSpec - .getAttributes().get(key); - if (!parameters.containsKey(key)) { - Object defaultValue = executionSpecAttr.getValue(); - if (defaultValue == null) - errors.rejectValue(key, "Not set and no default value"); - else - parameters.put(key, defaultValue); - } else {// contains key - Object obj = parameters.get(key); - if (executionSpecAttr instanceof RefSpecAttribute) { - RefSpecAttribute rsa = (RefSpecAttribute) executionSpecAttr; - // TODO: make sure this will not cause pb with OSGi - Class targetClass = rsa.getTargetClass(); - if (!targetClass.isAssignableFrom(obj.getClass())) { - errors.reject(key - + " not compatible with target class " - + targetClass); - } - } - } - } - - if (errors.hasErrors()) - throw new SlcException("Could not prepare execution flow: " - + errors.toString()); - } - - public void setBeanName(String name) { - this.name = name; - } - - public void setExecutables(List executables) { - this.executables = executables; - } - - public void setExecutionSpec(ExecutionSpec executionSpec) { - this.executionSpec = executionSpec; - } - - public void setParameters(Map attributes) { - this.parameters = attributes; - } - - public String getName() { - return name; - } - - public ExecutionSpec getExecutionSpec() { - return executionSpec; - } - - public Object getParameter(String name) { - if (parameters.containsKey(name)) { - return parameters.get(name); - } else { - if (executionSpec.getAttributes().containsKey(name)) { - ExecutionSpecAttribute esa = executionSpec.getAttributes().get( - name); - if (esa.getValue() != null) - return esa.getValue(); - } else { - throw new SlcException("Key " + name - + " is not defined in the specifications of " - + toString()); - } - } - throw new SlcException("Key " + name + " is not set as parameter in " - + toString()); - } - - public String toString() { - return new StringBuffer("Flow ").append(name).toString(); - } - - public boolean equals(Object obj) { - return ((ExecutionFlow) obj).getName().equals(name); - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionSpec.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionSpec.java deleted file mode 100644 index ed1b76bc1..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleExecutionSpec.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.argeo.slc.core.execution; - -import java.util.HashMap; -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.ExecutionFlow; -import org.argeo.slc.execution.ExecutionSpec; -import org.argeo.slc.execution.ExecutionSpecAttribute; -import org.springframework.beans.factory.BeanNameAware; - -public class SimpleExecutionSpec implements ExecutionSpec, BeanNameAware { - private final static Log log = LogFactory.getLog(SimpleExecutionSpec.class); - - private final static ThreadLocal initializingFlow = new ThreadLocal(); - - private Map attributes = new HashMap(); - - private String name = null; - - public Map getAttributes() { - return attributes; - } - - public void setAttributes(Map attributes) { - this.attributes = attributes; - } - - public Object createRef(String name) { - ExecutionFlow flow = initializingFlow.get(); - if (flow == null) - throw new SlcException("No flow is currently initializing." - + " Declare flow refs as inner beans or prototypes."); - /* - * RefSpecAttribute refSpecAttribute = (RefSpecAttribute) attributes - * .get(name); Class targetClass = refSpecAttribute.getTargetClass(); - * ExecutionTargetSource targetSource = new ExecutionTargetSource(flow, - * targetClass, name); ProxyFactory proxyFactory = new ProxyFactory(); - * proxyFactory.setTargetClass(targetClass); - * proxyFactory.setProxyTargetClass(true); - * proxyFactory.setTargetSource(targetSource); - * - * return proxyFactory.getProxy(); - */ - return flow.getParameter(name); - } - - public void setBeanName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - // FLOWS INITIALIZATION SUPPORT - - public static void flowInitializationStarted(ExecutionFlow flow) { - if (log.isTraceEnabled()) - log.trace("Start initialization of " + flow.hashCode() + " (" - + flow + " - " + flow.getClass() + ")"); - initializingFlow.set(flow); - } - - public static void flowInitializationFinished(ExecutionFlow flow) { - if (log.isTraceEnabled()) - log.trace("Finish initialization of " + flow.hashCode() + " (" - + flow + " - " + flow.getClass() + ")"); - ExecutionFlow registeredFlow = initializingFlow.get(); - if (registeredFlow != null) { - if (!flow.getName().equals(registeredFlow.getName())) - throw new SlcException("Current flow is " + flow); - initializingFlow.set(null); - } - } - - public static Object getInitializingFlowParameter(String key) { - if (initializingFlow.get() == null) - throw new SlcException("No initializing flow available."); - return initializingFlow.get().getParameter(key); - } - - public static Boolean isInFlowInitialization() { - return initializingFlow.get() != null; - } - - public boolean equals(Object obj) { - return ((ExecutionSpec) obj).getName().equals(name); - } - -} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleSpecAttribute.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleSpecAttribute.java deleted file mode 100644 index 0985375ed..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/SimpleSpecAttribute.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.argeo.slc.core.execution; - -public class SimpleSpecAttribute extends AbstractSpecAttribute { - private Object value = null; - - public Object getValue() { - return value; - } - - public void setValue(Object value) { - this.value = value; - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/specs.xml b/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/specs.xml new file mode 100644 index 000000000..1e748e5f5 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/specs.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/spring.xml b/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/spring.xml index 5d684fb39..8a950fcf0 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/spring.xml +++ b/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/spring.xml @@ -7,6 +7,9 @@ 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"> + + + diff --git a/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/tasks/core.xml b/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/tasks/core.xml new file mode 100644 index 000000000..0051fe5b2 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/resources/org/argeo/slc/core/execution/tasks/core.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file