Introduce CLI module
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 3 Mar 2013 20:55:33 +0000 (20:55 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 3 Mar 2013 20:55:33 +0000 (20:55 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6095 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

dep/org.argeo.slc.dep.minimal/pom.xml
modules/org.argeo.slc.agent.cli/META-INF/spring/cli-osgi.xml [new file with mode: 0644]
modules/org.argeo.slc.agent.cli/META-INF/spring/cli.xml [new file with mode: 0644]
modules/org.argeo.slc.agent.cli/pom.xml [new file with mode: 0644]
modules/pom.xml
runtime/org.argeo.slc.launcher/jaas.config
runtime/org.argeo.slc.launcher/log4j.properties
runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java

index 22f85a351f63dd20ffaa5696ab879e3f1d5ca00a..475f5c45cf4cb68ce3273ea7064eb76ae3b212c3 100644 (file)
                        <type>pom</type>
                </dependency>
 
-               <!-- JCR Agent -->
+               <!-- CLI Agent -->
                <dependency>
                        <groupId>org.argeo.slc</groupId>
-                       <artifactId>org.argeo.slc.support.jcr</artifactId>
+                       <artifactId>org.argeo.slc.launcher</artifactId>
                        <version>1.1.12-SNAPSHOT</version>
                </dependency>
                <dependency>
                        <groupId>org.argeo.slc</groupId>
-                       <artifactId>org.argeo.slc.agent.jcr</artifactId>
+                       <artifactId>org.argeo.slc.agent.cli</artifactId>
                        <version>1.1.12-SNAPSHOT</version>
                </dependency>
+
+               <!-- JCR Agent -->
                <dependency>
                        <groupId>org.argeo.slc</groupId>
-                       <artifactId>org.argeo.slc.node.jackrabbit</artifactId>
+                       <artifactId>org.argeo.slc.support.jcr</artifactId>
                        <version>1.1.12-SNAPSHOT</version>
                </dependency>
-
-               <!-- Launcher -->
                <dependency>
                        <groupId>org.argeo.slc</groupId>
-                       <artifactId>org.argeo.slc.launcher</artifactId>
+                       <artifactId>org.argeo.slc.agent.jcr</artifactId>
+                       <version>1.1.12-SNAPSHOT</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.argeo.slc</groupId>
+                       <artifactId>org.argeo.slc.node.jackrabbit</artifactId>
                        <version>1.1.12-SNAPSHOT</version>
                </dependency>
 
diff --git a/modules/org.argeo.slc.agent.cli/META-INF/spring/cli-osgi.xml b/modules/org.argeo.slc.agent.cli/META-INF/spring/cli-osgi.xml
new file mode 100644 (file)
index 0000000..0e80b8e
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans:beans xmlns="http://www.springframework.org/schema/osgi"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"\r
+       xmlns:util="http://www.springframework.org/schema/util"\r
+       xsi:schemaLocation="http://www.springframework.org/schema/osgi  \r
+       http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd\r
+       http://www.springframework.org/schema/beans   \r
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/util\r
+       http://www.springframework.org/schema/util/spring-util-2.5.xsd">\r
+\r
+       <!-- REFERENCES -->\r
+       <reference id="authenticationManager"\r
+               interface="org.springframework.security.AuthenticationManager" />\r
+\r
+       <reference id="modulesManager"\r
+               interface="org.argeo.slc.execution.ExecutionModulesManager" />\r
+\r
+       <!-- SERVICES -->\r
+       <service ref="agent" interface="org.argeo.slc.execution.SlcAgent" />\r
+       <service ref="agentCli" interface="org.argeo.slc.execution.SlcAgentCli" />\r
+\r
+       <service ref="fileSystemManager" interface="org.apache.commons.vfs.FileSystemManager" />\r
+</beans:beans>
\ No newline at end of file
diff --git a/modules/org.argeo.slc.agent.cli/META-INF/spring/cli.xml b/modules/org.argeo.slc.agent.cli/META-INF/spring/cli.xml
new file mode 100644 (file)
index 0000000..5c57592
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
+\r
+       <bean id="agent" class="org.argeo.slc.core.execution.DefaultAgent"\r
+               init-method="init" destroy-method="destroy">\r
+               <property name="modulesManager" ref="modulesManager" />\r
+       </bean>\r
+\r
+       <bean id="agentCli" class="org.argeo.slc.core.execution.DefaultAgentCli">\r
+               <property name="agent" ref="agent" />\r
+               <property name="authenticationManager" ref="authenticationManager" />\r
+       </bean>\r
+\r
+       <bean\r
+               class="org.argeo.security.core.AuthenticatedApplicationContextInitialization">\r
+               <property name="authenticationManager" ref="authenticationManager" />\r
+       </bean>\r
+\r
+       <bean name="fileSystemManager" class="org.apache.commons.vfs.impl.StandardFileSystemManager"\r
+               init-method="init" destroy-method="close" />\r
+</beans>
\ No newline at end of file
diff --git a/modules/org.argeo.slc.agent.cli/pom.xml b/modules/org.argeo.slc.agent.cli/pom.xml
new file mode 100644 (file)
index 0000000..6d2ae41
--- /dev/null
@@ -0,0 +1,26 @@
+<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>modules</artifactId>
+               <version>1.1.12-SNAPSHOT</version>
+               <relativePath>..</relativePath>
+       </parent>
+       <artifactId>org.argeo.slc.agent.cli</artifactId>
+       <name>SLC Agent CLI</name>
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.felix</groupId>
+                               <artifactId>maven-bundle-plugin</artifactId>
+                               <configuration>
+                                       <instructions>
+                                               <Import-Package>
+                                                       *,
+                                               </Import-Package>
+                                       </instructions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </build>
+</project>
\ No newline at end of file
index d86bd6534de04f2e8519247852fb0425da1e0f7a..5c54f49f8f0dd68f28017de20adcbbf69442fe48 100644 (file)
@@ -1,4 +1,5 @@
-<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>
@@ -13,6 +14,7 @@
                <module>org.argeo.slc.ext.castor</module>
                <module>org.argeo.slc.agent</module>
                <module>org.argeo.slc.agent.jcr</module>
+               <module>org.argeo.slc.agent.cli</module>
                <module>org.argeo.slc.node.jackrabbit</module>
                <module>org.argeo.slc.server.repo</module>
                <module>org.argeo.slc.server.repo.webapp</module>
index a63021f2b4f00e7254c8613459edebed3a8a4406..2fc1198395e6c49deeeb85f75f279e7e8ec0479c 100644 (file)
@@ -1,3 +1,7 @@
 NIX {
-   com.sun.security.auth.module.UnixLoginModule required debug=true;
-};
\ No newline at end of file
+   com.sun.security.auth.module.UnixLoginModule required;
+};
+
+WINDOWS {
+   com.sun.security.auth.module.NTLoginModule required;
+};
index 0b091606c7f279e24c0c4b884235e89d442a4278..92553a61a48c1fdb3657e5bc39eb8c40f9981272 100644 (file)
@@ -1,18 +1,9 @@
-#log4j.rootLogger=WARN, console
-log4j.rootLogger=WARN, development
+log4j.rootLogger=WARN, console
+#log4j.rootLogger=DEBUG, development
 
 ## Levels
-log4j.logger.org.argeo=DEBUG
-log4j.logger.org.argeo.jackrabbit.remote.ExtendedDispatcherServlet=ERROR
-log4j.logger.org.springframework.web.servlet.PageNotFound=ERROR
-log4j.logger.org.argeo.server.webextender.TomcatDeployer=WARN
+log4j.logger.org.argeo=INFO
 
-#log4j.logger.org.apache=DEBUG
-#log4j.logger.org.springframework.security=DEBUG
-
-log4j.logger.org.apache.coyote=INFO
-log4j.logger.org.apache.catalina.core.ContainerBase=INFO
-log4j.logger.org.apache.directory.server=ERROR
 log4j.logger.org.apache.jackrabbit.core.query.lucene=ERROR
 log4j.logger.org.apache.jackrabbit.core.config.ConfigurationErrorHandler=ERROR
 log4j.logger.org.apache.jackrabbit.core.util.db.DbUtility=FATAL
@@ -21,7 +12,7 @@ log4j.logger.org.apache.jackrabbit.core.util.db.DbUtility=FATAL
 # default appender
 log4j.appender.console=org.apache.log4j.ConsoleAppender
 log4j.appender.console.layout=org.apache.log4j.PatternLayout
-log4j.appender.console.layout.ConversionPattern=%d{yyyyMMdd HH:mm:ss} %-5p %m [%t] %c%n
+log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} %m%n
 
 # development appender
 log4j.appender.development=org.apache.log4j.ConsoleAppender
index 90ca7411f9ad23cdfb205c7a0e03b4a951f42f7f..4c5c82dd136f65493791e61941ec908136ebd8c2 100644 (file)
@@ -32,12 +32,30 @@ import javax.security.auth.login.LoginContext;
 
 import org.argeo.osgi.boot.OsgiBoot;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.launch.Framework;
 import org.osgi.framework.launch.FrameworkFactory;
-import org.osgi.util.tracker.ServiceTracker;
 
 /** Configures an SLC runtime and runs a process. */
 public class SlcMain implements Runnable {
+       public final static String NIX = "NIX";
+       public final static String WINDOWS = "WINDOWS";
+       public final static String SOLARIS = "SOLARIS";
+
+       public final static String os;
+       static {
+               String osName = System.getProperty("os.name");
+               if (osName.startsWith("Win"))
+                       os = WINDOWS;
+               else if (osName.startsWith("Solaris"))
+                       os = SOLARIS;
+               else
+                       os = NIX;
+       }
+
+       // private final DateFormat dateFormat = new
+       // SimpleDateFormat("HH:mm:ss,SSS");
+       private Long timeout = 30 * 1000l;
        private final String[] args;
 
        // private static String bundlesToInstall = "/usr/share/osgi;in=*.jar";
@@ -56,22 +74,31 @@ public class SlcMain implements Runnable {
                bundlesToStart.add("org.argeo.slc.node.jackrabbit");
                bundlesToStart.add("org.argeo.slc.agent");
                bundlesToStart.add("org.argeo.slc.agent.jcr");
+               // bundlesToStart.add("org.argeo.slc.agent.cli");
        }
 
        public void run() {
+               long begin = System.currentTimeMillis();
+               // System.out.println(dateFormat.format(new Date()));
+
+               Boolean isTransient = false;
+               File dataDir = null;
                final LoginContext lc;
                try {
                        // Authenticate
-                       lc = new LoginContext("NIX");
+                       lc = new LoginContext(os);
                        lc.login();
 
                        // Prepare directories
                        String executionDir = System.getProperty("user.dir");
-                       File slcDir = new File(executionDir, "target/.slc");
+                       File slcDir = new File(executionDir, ".slc");
                        File tempDir = new File(System.getProperty("java.io.tmpdir"));
 
-                       File dataDir = new File(tempDir, "slc-data-"
-                                       + UUID.randomUUID().toString());
+                       if (isTransient)
+                               dataDir = new File(tempDir, "slc-data-"
+                                               + UUID.randomUUID().toString());
+                       else
+                               dataDir = new File(slcDir, "data");
                        if (!dataDir.exists())
                                dataDir.mkdirs();
 
@@ -80,8 +107,9 @@ public class SlcMain implements Runnable {
                                confDir.mkdirs();
 
                        System.setProperty("log4j.configuration", "file:./log4j.properties");
-                       System.setProperty("argeo.node.repo.configuration",
-                                       "osgibundle:repository-memory.xml");
+                       if (isTransient)
+                               System.setProperty("argeo.node.repo.configuration",
+                                               "osgibundle:repository-memory.xml");
 
                        // Start Equinox
                        ServiceLoader<FrameworkFactory> ff = ServiceLoader
@@ -91,7 +119,8 @@ public class SlcMain implements Runnable {
                        configuration.put("osgi.configuration.area",
                                        confDir.getCanonicalPath());
                        configuration.put("osgi.instance.area", dataDir.getCanonicalPath());
-                       configuration.put("osgi.clean", "true");
+                       // configuration.put("osgi.clean", "true");
+                       // configuration.put("osgi.console", "");
 
                        // Spring configs currently require System properties
                        System.getProperties().putAll(configuration);
@@ -113,11 +142,26 @@ public class SlcMain implements Runnable {
                        osgiBoot.startBundles(bundlesToStart);
 
                        // Find SLC Agent
-                       ServiceTracker agentTracker = new ServiceTracker(bundleContext,
-                                       "org.argeo.slc.execution.SlcAgentCli", null);
-                       agentTracker.open();
-                       final Object agentCli = agentTracker.waitForService(30 * 1000);
-
+                       ServiceReference sr = null;
+                       while (sr == null) {
+                               sr = bundleContext
+                                               .getServiceReference("org.argeo.slc.execution.SlcAgentCli");
+                               if (System.currentTimeMillis() - begin > timeout)
+                                       throw new RuntimeException("Cannot find SLC agent CLI");
+                               Thread.sleep(100);
+                       }
+                       final Object agentCli = bundleContext.getService(sr);
+
+                       // ServiceTracker agentTracker = new ServiceTracker(bundleContext,
+                       // "org.argeo.slc.execution.SlcAgentCli", null);
+                       // agentTracker.open();
+                       // final Object agentCli = agentTracker.waitForService(30 * 1000);
+                       // if (agentCli == null)
+                       // throw new RuntimeException("Cannot find SLC agent CLI");
+
+                       long duration = System.currentTimeMillis() - begin;
+                       System.out.println("Initialized in " + (duration / 1000) + "s "
+                                       + (duration % 1000) + "ms");
                        // Run as a privileged action
                        Subject.doAs(Subject.getSubject(AccessController.getContext()),
                                        new PrivilegedAction<String>() {
@@ -148,6 +192,11 @@ public class SlcMain implements Runnable {
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(1);
+               } finally {
+                       if (isTransient && dataDir != null && dataDir.exists()) {
+                               // TODO clean up transient data dir
+                       }
+
                }
        }