Improve detached launcher
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 27 Apr 2009 15:47:19 +0000 (15:47 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 27 Apr 2009 15:47:19 +0000 (15:47 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2382 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

demo/pom.xml
org.argeo.slc/pom.xml
runtime/org.argeo.slc.detached.launcher/pom.xml
runtime/org.argeo.slc.detached.launcher/src/main/java/org/argeo/slc/detached/launcher/Main.java
runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsAgent.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractSpringExecutionModule.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ResourceSpecAttribute.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.mysql/META-INF/spring/mysql.xml
server/org.argeo.slc.siteserver/bundles/org.argeo.slc.server.mysql/mysql.properties
server/org.argeo.slc.siteserver/pom.xml

index e8ed6781e0bda144bc839216e19e53c7511a014f..e4f569132e78ba7214314cde18b60f0e5d369e3d 100644 (file)
@@ -67,7 +67,7 @@
                                                                        org.springframework.osgi.web.extender,
                                                                        org.springframework.osgi.samples.simplewebapp,
                                                                        org.argeo.slc.server.activemq,
-                                                                       org.argeo.slc.server.mysql,
+                                                                       org.argeo.slc.server.hsqldb,
                                                                        org.argeo.slc.server.hibernate,
                                                                        org.argeo.slc.server.services,
                                                                        org.argeo.slc.server.jms,
index efa7f3db87295b49341b6e5653e96f62f4e9630f..8b31203665338ef7f2ddafbc15d02f679d382b13 100644 (file)
@@ -577,7 +577,7 @@ limitations under the License.
                        </dependency>
                        <dependency>
                                <groupId>net.sourceforge.jtds</groupId>
-                               <artifactId>jtds</artifactId>
+                               <artifactId>com.springsource.net.sourceforge.jtds</artifactId>
                                <version>1.2.2</version>
                        </dependency>
                        <dependency>
index b101f93dcab9fe0ccf2062396e3aa8f27ba30efb..895fd155d6af7f11038a0f9db87b0f1aac782525 100644 (file)
@@ -1,10 +1,11 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
-               <groupId>org.argeo.slc</groupId>
-               <artifactId>argeo-slc</artifactId>
+               <groupId>org.argeo.slc.runtime</groupId>
+               <artifactId>argeo-slc-runtime</artifactId>
                <version>0.11.3-SNAPSHOT</version>
-               <relativePath>../org.argeo.slc</relativePath>
+               <relativePath>..</relativePath>
        </parent>
        <artifactId>org.argeo.slc.detached.launcher</artifactId>
        <name>Argeo SLC Detached Launcher</name>
                                        </instructions>
                                </configuration>
                        </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-assembly-plugin</artifactId>
-                               <configuration>
-                                       <descriptors>
-                                               <descriptor>src/assembly/dist.xml</descriptor>
-                                       </descriptors>
-                               </configuration>
-                               <executions>
-                                       <execution>
-                                               <id>attach-assembly</id>
-                                               <phase>package</phase>
-                                               <goals>
-                                                       <goal>single</goal>
-                                               </goals>
-                                       </execution>
-                               </executions>
-                       </plugin>
+                       <!--
+                               <plugin> <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-assembly-plugin</artifactId> <configuration>
+                               <descriptors> <descriptor>src/assembly/dist.xml</descriptor>
+                               </descriptors> </configuration> <executions> <execution>
+                               <id>attach-assembly</id> <phase>package</phase> <goals>
+                               <goal>single</goal> </goals> </execution> </executions> </plugin>
+                       -->
                </plugins>
        </build>
        <dependencies>
-               <!--
-                       <dependency> <groupId>org.apache.felix</groupId>
-                       <artifactId>org.apache.felix.main</artifactId> </dependency>
-               -->
                <dependency>
                        <groupId>org.eclipse.osgi</groupId>
                        <artifactId>org.eclipse.osgi</artifactId>
                </dependency>
-<!-- 
-               <dependency>
-                       <groupId>org.springframework.osgi</groupId>
-                       <artifactId>org.springframework.osgi.extender</artifactId>
-               </dependency>
- -->
-
-               <!--
-                       Old <dependency> <groupId>org.springframework</groupId>
-                       <artifactId>spring-context</artifactId> <version>2.0.8</version>
-                       </dependency> <dependency> <groupId>commons-logging</groupId>
-                       <artifactId>commons-logging</artifactId> </dependency> <dependency>
-                       <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency>
-                       <dependency> <groupId>commons-io</groupId>
-                       <artifactId>commons-io</artifactId> </dependency>
-               -->
 
                <!--
-                       <dependency> <groupId>org.argeo.slc</groupId>
-                       <artifactId>org.argeo.slc.detached.ext.log4j</artifactId>
-                       <version>0.11.2</version> </dependency>
-               -->
-               <!-- Spring
-               <dependency>
-                       <groupId>org.springframework</groupId>
-                       <artifactId>org.springframework.context</artifactId>
-               </dependency>
- -->
-               <!--
-                       <dependency> <groupId>org.apache.xerces</groupId>
-                       <artifactId>com.springsource.org.apache.xerces</artifactId>
-                       </dependency> <dependency> <groupId>org.apache.xalan</groupId>
-                       <artifactId>com.springsource.org.apache.xalan</artifactId>
-                       </dependency> <dependency>
-                       <groupId>edu.emory.mathcs.backport</groupId> <artifactId>
-                       com.springsource.edu.emory.mathcs.backport </artifactId>
-                       </dependency>
-               -->
-               <!-- 
-               <dependency>
-                       <groupId>org.apache.commons</groupId>
-                       <artifactId>
-                               com.springsource.org.apache.commons.io
-                       </artifactId>
-               </dependency>
-               <dependency>
-                       <groupId>org.junit</groupId>
-                       <artifactId>com.springsource.junit</artifactId>
-               </dependency>
-               <dependency>
-                       <groupId>org.apache.log4j</groupId>
-                       <artifactId>com.springsource.org.apache.log4j</artifactId>
-               </dependency> -->
-               <!--
-                       <dependency> <groupId>org.slf4j</groupId>
-                       <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
-                       </dependency> <dependency> <groupId>org.slf4j</groupId>
-                       <artifactId>com.springsource.slf4j.jcl</artifactId> </dependency>
+                       <dependency> <groupId>org.springframework.osgi</groupId>
+                       <artifactId>org.springframework.osgi.extender</artifactId>
+                       </dependency> <dependency> <groupId>org.argeo.slc.runtime</groupId>
+                       <artifactId>org.argeo.slc.detached</artifactId> </dependency>
                -->
        </dependencies>
 </project>
\ No newline at end of file
index 807963e14f400a851b65a2abd153edc2d9cca2ee..3fc42326fb766040f49a6932c11724a3b4f4bca2 100644 (file)
@@ -11,6 +11,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.StringTokenizer;
+import java.util.TreeMap;
 import java.util.Vector;
 
 import org.eclipse.core.runtime.adaptor.EclipseStarter;
@@ -20,6 +21,7 @@ import org.osgi.framework.BundleException;
 
 public class Main {
        public final static String PROP_SLC_HOME = "slc.home";
+       public final static String PROP_SLC_DETACHED_PROEPRTIES = "slc.detached.properties";
        public final static String PROP_SLC_OSGI_START = "slc.osgi.start";
        public final static String PROP_SLC_OSGI_SCAN_CLASSPATH = "slc.osgi.scanClasspath";
        public final static String PROP_SLC_OSGI_EQUINOX_ARGS = "slc.osgi.equinox.args";
@@ -30,7 +32,8 @@ public class Main {
                info("Argeo SLC Detached launcher starting...");
                try {
                        // Load properties
-                       String propertyPath = "slc-detached.properties";
+                       String propertyPath = System.getProperty("slc.detached.properties",
+                                       "slc-detached.properties");
                        Properties config = prepareConfig(propertyPath);
 
                        // Start app (in main class loader)
@@ -40,25 +43,17 @@ public class Main {
                        try {
                                startEquinox(config);
                        } catch (Exception e) {
-                               // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        info("Argeo SLC Detached launcher started.");
                } catch (Exception e) {
                        e.printStackTrace();
-                       System.exit(-1);
+                       System.exit(1);
                }
        }
 
        protected static Properties prepareConfig(String propertyFilePath)
                        throws Exception {
-               // Format slc.home
-               String slcHome = System.getProperty(PROP_SLC_HOME);
-               if (slcHome != null) {
-                       slcHome = new File(slcHome).getCanonicalPath();
-                       System.setProperty(PROP_SLC_HOME, slcHome);
-               }
-
                // Load config
                Properties config = new Properties();
                InputStream in = null;
@@ -73,8 +68,28 @@ public class Main {
                                in.close();
                }
 
+               // Format slc.home
+               String slcHome = System.getProperty(Main.PROP_SLC_HOME);
+               if (slcHome == null) {
+                       slcHome = config.getProperty(Main.PROP_SLC_HOME);
+               }
+               if (slcHome != null) {
+                       slcHome = new File(slcHome).getCanonicalPath();
+                       System.setProperty(Main.PROP_SLC_HOME, slcHome);
+               }
+
                // System properties have priority.
                config.putAll(System.getProperties());
+
+               // SET ALL PROPERTIES AS SYSTEM PROPERTIES
+               TreeMap ordered = new TreeMap(config);
+               for (Iterator it = ordered.keySet().iterator(); it.hasNext();) {
+                       String key = it.next().toString();
+                       String value = ordered.get(key).toString();
+                       System.out.println(key + "=" + value);
+                       System.setProperty(key, value);
+               }
+
                return config;
        }
 
@@ -196,7 +211,7 @@ public class Main {
 
        private static void startBundle(BundleContext bundleContext,
                        String symbolicName) throws BundleException {
-               //info("Starting bundle " + symbolicName + "...");
+               // info("Starting bundle " + symbolicName + "...");
                Bundle bundle = findBundleBySymbolicName(bundleContext, symbolicName);
                if (bundle != null)
                        bundle.start();
@@ -296,6 +311,6 @@ public class Main {
 
        private static void bundleInstallWarn(Object obj) {
                System.err.println("[WARN] " + obj);
-               //Thread.dumpStack();
+               // Thread.dumpStack();
        }
 }
index 7490f32d1db4c4a89dab9b407fa46fca3b83b3e9..baddb1c604f075f4af5a5cc7667531331f48631a 100644 (file)
@@ -81,19 +81,6 @@ public class JmsAgent extends AbstractAgent implements SlcAgent,
                this.agentUnregister = agentUnregister;
        }
 
-       /*
-        * public void onMessage(Message message) { // FIXME: we filter the messages
-        * on the client side, // because of a weird problem with selector since
-        * moving to OSGi try { if (message.getStringProperty("slc-agentId").equals(
-        * agentDescriptor.getUuid())) { runSlcExecution((SlcExecution)
-        * messageConverter .fromMessage(message)); } else { if
-        * (log.isDebugEnabled()) log.debug("Filtered out message " + message); } }
-        * catch (JMSException e) { throw new SlcException("Cannot convert message "
-        * + message, e); }
-        * 
-        * }
-        */
-
        public String getMessageSelector() {
                String messageSelector = "slc_agentId='" + agentDescriptor.getUuid()
                                + "'";
@@ -131,6 +118,7 @@ public class JmsAgent extends AbstractAgent implements SlcAgent,
                        SlcExecution slcExecution = (SlcExecution) jmsTemplate
                                        .getMessageConverter().fromMessage(message);
                        runSlcExecution(slcExecution);
+                       return;
                } else {
                        // try {
                        // // FIXME: generalize
index 51ca2f159f8c08db9d48b226620e86c21efbe380..1cac123a81daf00a9489529a07e967aa5533eddb 100644 (file)
@@ -72,6 +72,13 @@ public abstract class AbstractSpringExecutionModule implements ExecutionModule,
                                                                        + value.getClass().getName());
                                                }
                                                values.put(key, refValue);
+                                       } else if (attribute instanceof ResourceSpecAttribute) {
+                                               PrimitiveValue primitiveValue = new PrimitiveValue();
+                                               primitiveValue
+                                                               .setType(((ResourceSpecAttribute) attribute)
+                                                                               .getType());
+                                               primitiveValue.setValue(value);
+                                               values.put(key, primitiveValue);
                                        } else {
                                                throw new SlcException("Unkown spec attribute type "
                                                                + attribute.getClass());
index 131c45a2ad86cc0d18b6f91502d4f69d9b39a54d..572665dd52211b195200404518d9340988974346 100644 (file)
@@ -41,4 +41,8 @@ public class ResourceSpecAttribute extends AbstractSpecAttribute {
                this.type = type;
        }
 
+       public String getType() {
+               return type;
+       }
+
 }
index 38b0f78b4f5b759390a3d1141145c28e00a371a2..f5a9db5cae4e17cafe527bfcd18c8559dccdaf02 100644 (file)
@@ -99,7 +99,7 @@ public class SystemCall implements Executable {
                        };
                        stdOutThread.start();
                        StreamReaderThread stdErrThread = new StreamReaderThread(process
-                                       .getInputStream()) {
+                                       .getErrorStream()) {
                                protected void callback(String line) {
                                        stdErrCallback(line);
                                }
@@ -111,8 +111,10 @@ public class SystemCall implements Executable {
                        // Wait for the end of the process
                        if (synchronous) {
                                Integer exitCode = process.waitFor();
-                               if (exitCode != 0)
+                               if (exitCode != 0) {
+                                       Thread.sleep(5000);// leave the process a chance to log
                                        log.warn("Process return exit code " + exitCode);
+                               }
                        } else {
                                // asynchronous: return
                        }
@@ -132,7 +134,7 @@ public class SystemCall implements Executable {
                else
                        return dir.getPath();
        }
-       
+
        protected void stdOutCallback(String line) {
                log(stdOutLogLevel, line);
        }
index 7f5d9a2b7de4823688385d2c0defe7c2cd14dfc3..8286594a22f0d02df4433c7d8e7620f065106e8b 100644 (file)
@@ -50,7 +50,7 @@
  -->
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
                destroy-method="close">
-               <property name="driverClassName" value="${jdbc.driverClassName}" />
+               <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="${jdbc.url}" />
                <property name="username" value="${jdbc.username}" />
                <property name="password" value="${jdbc.password}" />
index dc979ad4dd8f1639602ff803fb2c7196c53714a8..11a0d554441dec7aeb06668bf133458158f028c2 100644 (file)
@@ -1,4 +1,3 @@
-jdbc.driverClassName=com.mysql.jdbc.Driver
-jdbc.url=jdbc:mysql://localhost/sparta_prod
+jdbc.url=jdbc:mysql://localhost/slc
 jdbc.username=root
 jdbc.password=
index c2594095ea90b6e6f4777e3e01cbe2e8dd3e3fd9..286b1daca6a918c36c5c7731c5241c5575e1dbb8 100644 (file)
 
                <dependency>
                        <groupId>net.sourceforge.jtds</groupId>
-                       <artifactId>jtds</artifactId>
+                       <artifactId>com.springsource.net.sourceforge.jtds</artifactId>
                </dependency>
                <dependency>
                        <groupId>com.mysql.jdbc</groupId>