</instructions>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1-beta-1</version>
+ <configuration>
+ <mainClass>org.argeo.slc.cli.SlcMain</mainClass>
+ <systemProperties>
+ <systemProperty>
+ <key>slc.runtime</key>
+ <value>ws</value>
+ </systemProperty>
+ <systemProperty>
+ <key>slc.rootFile</key>
+ <value>file:${basedir}/src/slc/root/slcRoot.properties</value>
+ </systemProperty>
+ </systemProperties>
+ <arguments>
+ <argument>--mode</argument>
+ <argument>agent</argument>
+ </arguments>
+ </configuration>
+ </plugin>
</plugins>
</build>
<dependencies>
<version>1.1.1</version>
<scope>testing</scope>
</dependency>
+
+ <!-- TESTING -->
+ <dependency>
+ <groupId>org.argeo.slc.runtime</groupId>
+ <artifactId>org.argeo.slc.launcher</artifactId>
+ <scope>testing</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.slc.runtime</groupId>
+ <artifactId>org.argeo.slc.support.activemq</artifactId>
+ <scope>testing</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.slc.runtime</groupId>
+ <artifactId>org.argeo.slc.support.ant</artifactId>
+ <scope>testing</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.slc.runtime</groupId>
+ <artifactId>org.argeo.slc.support.castor</artifactId>
+ <scope>testing</scope>
+ </dependency>
+
</dependencies>
</project>
</instructions>
</configuration>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.1-beta-1</version>
- <configuration>
- <mainClass>org.argeo.slc.cli.SlcMain</mainClass>
- </configuration>
- </plugin>
</plugins>
</build>
<dependencies>
<artifactId>org.argeo.dep.osgi.commons.cli</artifactId>
</dependency>
- <!-- TESTING -->
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.support.activemq</artifactId>
- <scope>testing</scope>
- </dependency>
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.support.castor</artifactId>
- <scope>testing</scope>
- </dependency>
-
</dependencies>
</project>
\ No newline at end of file
private static Log log = null;
private final static String BOOTSTRAP_LOG4J_CONFIG = "org/argeo/slc/cli/bootstrapLog4j.properties";
- private final static String DEFAULT_AGENT_CONTEXT = "classpath:org/argeo/slc/activemq/spring-agent.xml";
+ private final static String DEFAULT_AGENT_CONTEXT = "classpath:org/argeo/slc/cli/spring-agent-default.xml";
private final static Option modeOpt = OptionBuilder.withLongOpt("mode")
.withArgName("mode").hasArg().withDescription(
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"
+ default-lazy-init="false">
+
+
+ <bean
+ class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
+ lazy-init="false">
+ <property name="properties">
+ <props>
+ <prop key="org.apache.activemq.brokerURL">
+ tcp://localhost:61616
+ </prop>
+ </props>
+ </property>
+ <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
+ <property name="ignoreUnresolvablePlaceholders" value="true" />
+ </bean>
+
+ <import resource="classpath:org/argeo/slc/activemq/spring-agent.xml" />
+
+ <bean id="slcDefault.cli.agent" parent="slcDefault.jms.agent">
+ <property name="slcApplication" ref="slcDefault.cli.slcApplication" />
+ </bean>
+
+ <bean id="slcDefault.cli.jms.agentListenerContainer.newExecution"
+ parent="slcTemplate.jms.agentListenerContainer">
+ <property name="action" value="newExecution" />
+ <property name="jmsAgent" ref="slcDefault.cli.agent" />
+ </bean>
+
+
+ <bean id="slcDefault.cli.slcApplication" class="org.argeo.slc.ant.AntSlcApplication"
+ init-method="initFromSlcRootFile">
+ <property name="slcRootFile" value="${slc.rootFile}" />
+ </bean>
+
+</beans>
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.runtime;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.argeo.slc.process.SlcExecution;
+
+public interface SlcApplication<T extends SlcExecutionContext> {
+ public void execute(SlcExecution slcExecution, Properties properties,
+ Map<String, Object> references,
+ SlcExecutionOutput<T> executionOutput);
+}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.slc.SlcException;
+import org.argeo.slc.core.runtime.AbstractAgent;
import org.argeo.slc.process.SlcExecution;
import org.argeo.slc.runtime.SlcAgent;
import org.argeo.slc.runtime.SlcAgentDescriptor;
import org.springframework.jms.core.JmsTemplate;
/** JMS based implementation of SLC Agent. */
-public class JmsAgent implements SlcAgent, InitializingBean, DisposableBean {
+public class JmsAgent extends AbstractAgent implements SlcAgent, InitializingBean, DisposableBean {
private final static Log log = LogFactory.getLog(JmsAgent.class);
private final SlcAgentDescriptor agentDescriptor;
}
public void newExecution(SlcExecution slcExecution) {
- log.info("Would execute SlcExecution :" + slcExecution);
+ log.info("Execute SlcExecution :" + slcExecution);
+ runSlcExecution(slcExecution);
}
public void setJmsTemplate(JmsTemplate jmsTemplate) {
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"
default-lazy-init="false">
- <bean
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
- lazy-init="false">
- <property name="properties">
- <props>
- <prop key="org.apache.activemq.brokerURL">
- tcp://localhost:61616
- </prop>
- </props>
- </property>
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="ignoreUnresolvablePlaceholders" value="true" />
- </bean>
-
<import resource="classpath:org/argeo/slc/activemq/spring.xml" />
- <bean id="slcDefault.jms.agent" class="org.argeo.slc.jms.JmsAgent">
+ <bean id="slcDefault.jms.agent" class="org.argeo.slc.jms.JmsAgent" abstract="true">
<property name="jmsTemplate" ref="slcDefault.jms.jmsTemplate" />
<property name="agentRegister" ref="slcJms.destination.agent.register" />
<property name="agentUnregister" ref="slcJms.destination.agent.unregister" />
</bean>
- <bean id="slcTemplate.jms.agentListenerContainer.newExecution"
- parent="slcTemplate.jms.agentListenerContainer">
- <property name="action" value="newExecution" />
- </bean>
-
<!-- Templates -->
<bean id="slcTemplate.jms.agentListenerContainer" class="org.argeo.slc.jms.AgentListenerContainer"
abstract="true">
- <property name="jmsAgent" ref="slcDefault.jms.agent" />
<property name="connectionFactory" ref="slcDefault.jms.connectionFactory" />
<property name="messageConverter" ref="slcDefault.jms.castorMessageConverter" />
<property name="pubSubDomain" value="true" />
import org.argeo.slc.core.structure.tree.TreeSRegistry;
import org.argeo.slc.logging.Log4jUtils;
import org.argeo.slc.process.SlcExecution;
+import org.argeo.slc.runtime.SlcApplication;
import org.argeo.slc.runtime.SlcExecutionOutput;
+import org.argeo.slc.spring.SpringUtils;
import org.argeo.slc.structure.StructureRegistry;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.SystemPropertyUtils;
-public class AntSlcApplication {
+public class AntSlcApplication implements SlcApplication<AntExecutionContext> {
private final static String DEFAULT_APP_LOG4J_PROPERTIES = "org/argeo/slc/ant/defaultAppLog4j.properties";
private final static Log log = LogFactory.getLog(AntSlcApplication.class);
private Resource confDir;
private File workDir;
+ private Resource slcRootFile;
+
public void execute(SlcExecution slcExecution, Properties properties,
Map<String, Object> references,
SlcExecutionOutput<AntExecutionContext> executionOutput) {
this.parentContext = runtimeContext;
}
+ public void setSlcRootFile(Resource slcRootFile) {
+ this.slcRootFile = slcRootFile;
+ }
+
+ /**
+ * Init all directories based on the SLC root file. TODO: don't override
+ * already specified dirs.
+ */
+ public void initFromSlcRootFile() {
+ // AntSlcApplication application = new AntSlcApplication();
+ InputStream inRootFile = null;
+ try {
+ // Remove basedir property in order to avoid conflict with Maven
+ // if (all.containsKey("basedir"))
+ // all.remove("basedir");
+
+ inRootFile = slcRootFile.getInputStream();
+ Properties rootProps = loadFile(inRootFile);
+
+ Resource confDir = null;
+ File workDir = null;
+ // Root dir
+ final Resource rootDir = SpringUtils.getParent(slcRootFile);
+
+ // Conf dir
+ String confDirStr = rootProps
+ .getProperty(AntConstants.CONF_DIR_PROPERTY);
+ if (confDirStr != null)
+ confDir = new DefaultResourceLoader(getClass().getClassLoader())
+ .getResource(confDirStr);
+
+ if (confDir == null || !confDir.exists()) {
+ // confDir = rootDir.createRelative("../conf");
+ confDir = SpringUtils.getParent(rootDir)
+ .createRelative("conf/");
+ }
+
+ // Work dir
+ String workDirStr = rootProps
+ .getProperty(AntConstants.WORK_DIR_PROPERTY);
+ if (workDirStr != null) {
+ workDir = new File(workDirStr);
+ }
+
+ if (workDir == null || !workDir.exists()) {
+ try {
+ File rootDirAsFile = rootDir.getFile();
+ workDir = new File(rootDirAsFile.getParent()
+ + File.separator + "work").getCanonicalFile();
+ } catch (IOException e) {
+ workDir = new File(System.getProperty("java.io.tmpdir")
+ + File.separator + "slcExecutions" + File.separator
+ + slcRootFile.getURL().getPath());
+ log.debug("Root dir is not a file: " + e.getMessage()
+ + ", creating work dir in temp: " + workDir);
+ }
+ workDir.mkdirs();
+ }
+
+ setConfDir(confDir);
+ setRootDir(rootDir);
+ setWorkDir(workDir);
+
+ if (log.isDebugEnabled())
+ log.debug("Ant SLC application initialized based on root file "
+ + slcRootFile);
+ } catch (IOException e) {
+ throw new SlcException(
+ "Could not prepare SLC application for root file "
+ + slcRootFile, e);
+ } finally {
+ IOUtils.closeQuietly(inRootFile);
+ }
+ }
+
+ /** Loads the content of a file as <code>Properties</code>. */
+ private Properties loadFile(InputStream in) {
+ Properties p = new Properties();
+ try {
+ p.load(in);
+ } catch (IOException e) {
+ throw new SlcException("Cannot read SLC root file", e);
+ }
+ return p;
+ }
+
}
"Could not find any SLC root file, "
+ "please configure one at the root of your scripts hierarchy.");
+ // Create SlcExecution from arguments
SlcExecution slcExecution = createSlcExecution(runtime, slcRootFile,
scriptRes, targets);
- AntSlcApplication application = getApplication(slcRootFile);
+ // Init application
+ AntSlcApplication application = new AntSlcApplication();
+ application.setSlcRootFile(slcRootFile);
+ application.initFromSlcRootFile();
+
+ // Execute test
application.execute(slcExecution, properties, references,
executionOutput);
}
return slcExecution;
}
- protected AntSlcApplication getApplication(Resource slcRootFile) {
- AntSlcApplication application = new AntSlcApplication();
- InputStream inRootFile = null;
- try {
- // Remove basedir property in order to avoid conflict with Maven
- // if (all.containsKey("basedir"))
- // all.remove("basedir");
-
- inRootFile = slcRootFile.getInputStream();
- Properties rootProps = loadFile(inRootFile);
-
- Resource confDir = null;
- File workDir = null;
- // Root dir
- final Resource rootDir = SpringUtils.getParent(slcRootFile);
-
- // Conf dir
- String confDirStr = rootProps
- .getProperty(AntConstants.CONF_DIR_PROPERTY);
- if (confDirStr != null)
- confDir = new DefaultResourceLoader(application.getClass()
- .getClassLoader()).getResource(confDirStr);
-
- if (confDir == null || !confDir.exists()) {
- // confDir = rootDir.createRelative("../conf");
- confDir = SpringUtils.getParent(rootDir)
- .createRelative("conf/");
- }
-
- // Work dir
- String workDirStr = rootProps
- .getProperty(AntConstants.WORK_DIR_PROPERTY);
- if (workDirStr != null) {
- workDir = new File(workDirStr);
- }
-
- if (workDir == null || !workDir.exists()) {
- try {
- File rootDirAsFile = rootDir.getFile();
- workDir = new File(rootDirAsFile.getParent()
- + File.separator + "work").getCanonicalFile();
- } catch (IOException e) {
- workDir = new File(System.getProperty("java.io.tmpdir")
- + File.separator + "slcExecutions" + File.separator
- + slcRootFile.getURL().getPath());
- log.debug("Root dir is not a file: " + e.getMessage()
- + ", creating work dir in temp: " + workDir);
- }
- workDir.mkdirs();
- }
-
- application.setConfDir(confDir);
- application.setRootDir(rootDir);
- application.setWorkDir(workDir);
-
- return application;
- } catch (IOException e) {
- throw new SlcException(
- "Could not prepare SLC application for root file "
- + slcRootFile, e);
- } finally {
- IOUtils.closeQuietly(inRootFile);
- }
- }
-
/**
* Recursively scans directories downwards until it find a file name as
* defined by {@link #SLC_ROOT_FILE_NAME}.
+ currDir, e);
}
}
-
- /** Loads the content of a file as <code>Properties</code>. */
- private Properties loadFile(InputStream in) {
- Properties p = new Properties();
- try {
- p.load(in);
- } catch (IOException e) {
- throw new SlcException("Cannot read SLC root file", e);
- }
- return p;
- }
}
@Override\r
protected void append(LoggingEvent event) {\r
Project project = (Project) MDC.get(AntConstants.MDC_ANT_PROJECT);\r
- if (project == null)\r
- throw new SlcException("No Ant project registered in Log4j MDC.");\r
-\r
- SlcExecution slcExecution = getSlcExecution(project);\r
- if (currentStepNotified) {\r
- slcExecution.getSteps().add(\r
- new SlcExecutionStep(event.getMessage().toString()));\r
- currentStepNotified = false;\r
+ if (project == null) {\r
+ System.err.println("No Ant project registered in Log4j MDC.");\r
} else {\r
- slcExecution.currentStep().addLog(event.getMessage().toString());\r
+ SlcExecution slcExecution = getSlcExecution(project);\r
+ if (currentStepNotified) {\r
+ slcExecution.getSteps().add(\r
+ new SlcExecutionStep(event.getMessage().toString()));\r
+ currentStepNotified = false;\r
+ } else {\r
+ slcExecution.currentStep()\r
+ .addLog(event.getMessage().toString());\r
+ }\r
}\r
}\r
\r
--- /dev/null
+package org.argeo.slc.core.runtime;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.process.SlcExecution;
+import org.argeo.slc.runtime.SlcApplication;
+import org.argeo.slc.runtime.SlcExecutionContext;
+
+public abstract class AbstractAgent {
+ private final static Log log = LogFactory.getLog(AbstractAgent.class);
+
+ private SlcApplication<SlcExecutionContext> slcApplication;
+
+ protected void runSlcExecution(final SlcExecution slcExecution) {
+ // TODO: in a separate process
+ Thread thread = new Thread("SlcExecution " + slcExecution.getUuid()) {
+ public void run() {
+ slcApplication.execute(slcExecution, new Properties(), null,
+ null);
+ log.debug("Thread for SLC execution #" + slcExecution.getUuid()
+ + " finished.");
+ }
+ };
+ thread.start();
+ }
+
+ public void setSlcApplication(
+ SlcApplication<SlcExecutionContext> application) {
+ this.slcApplication = application;
+ }
+
+}