From b09117bff95e8dfd2877e0177ba1de4b815a12bf Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 27 Oct 2012 14:11:11 +0000 Subject: [PATCH] Reactivate launcher git-svn-id: https://svn.argeo.org/slc/trunk@5672 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- dep/org.argeo.slc.dep.minimal/pom.xml | 51 +----- .../org.argeo.slc.launcher/log4j.properties | 26 +++ runtime/org.argeo.slc.launcher/pom.xml | 42 +++-- .../main/java/org/argeo/slc/cli/SlcMain.java | 149 ++++++++++-------- .../org/argeo/slc/execution/RealizedFlow.java | 28 ++++ runtime/org.argeo.slc.support.osgi/pom.xml | 13 +- .../org/argeo/slc/osgi/BundlesManager.java | 10 +- 7 files changed, 181 insertions(+), 138 deletions(-) create mode 100644 runtime/org.argeo.slc.launcher/log4j.properties diff --git a/dep/org.argeo.slc.dep.minimal/pom.xml b/dep/org.argeo.slc.dep.minimal/pom.xml index d80e061d9..8b16b2060 100644 --- a/dep/org.argeo.slc.dep.minimal/pom.xml +++ b/dep/org.argeo.slc.dep.minimal/pom.xml @@ -28,27 +28,15 @@ - org.argeo.slc - org.argeo.slc.core - 1.1.4-SNAPSHOT - - - org.argeo.slc - org.argeo.slc.support.jcr - 1.1.4-SNAPSHOT - - - org.argeo.slc - org.argeo.slc.support.osgi + org.argeo.slc.launcher 1.1.4-SNAPSHOT - org.argeo.slc - org.argeo.slc.agent + org.argeo.slc.support.jcr 1.1.4-SNAPSHOT @@ -76,32 +64,11 @@ ${version.argeo-commons} - - - org.argeo.commons.base - org.argeo.osgi.boot - ${version.argeo-commons} - - - - - org.argeo.commons.base - org.argeo.dep.log4j - ${version.argeo-commons} - pom - - org.argeo.commons.security org.argeo.security.core ${version.argeo-commons} - - - org.argeo.tp - bcprov - - @@ -120,12 +87,6 @@ javax.annotation - - - org.argeo.tp - org.springframework.osgi.extender - - org.argeo.commons.server @@ -153,10 +114,10 @@ - - - - + + org.argeo.tp + org.h2 + diff --git a/runtime/org.argeo.slc.launcher/log4j.properties b/runtime/org.argeo.slc.launcher/log4j.properties new file mode 100644 index 000000000..d034a2afb --- /dev/null +++ b/runtime/org.argeo.slc.launcher/log4j.properties @@ -0,0 +1,26 @@ +#log4j.rootLogger=WARN, console +log4j.rootLogger=WARN, 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.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 + +## Appenders +# 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 + +# development appender (slow!) +log4j.appender.development=org.apache.log4j.ConsoleAppender +log4j.appender.development.layout=org.apache.log4j.PatternLayout +log4j.appender.development.layout.ConversionPattern=%d{HH:mm:ss} [%16.16t] %5p %m (%F:%L) %c%n diff --git a/runtime/org.argeo.slc.launcher/pom.xml b/runtime/org.argeo.slc.launcher/pom.xml index 28c346bd1..8945e8f3b 100644 --- a/runtime/org.argeo.slc.launcher/pom.xml +++ b/runtime/org.argeo.slc.launcher/pom.xml @@ -1,4 +1,6 @@ - + + 4.0.0 org.argeo.slc @@ -35,15 +37,6 @@ - - org.argeo.slc.* - - - org.w3c.dom;version="0.0.0", - javax.xml.*;version="0.0.0", - org.argeo.slc.build, - * - org.argeo.slc.cli.SlcMain @@ -71,32 +64,49 @@ + org.argeo.slc org.argeo.slc.core 1.1.4-SNAPSHOT + + org.argeo.slc + org.argeo.slc.support.osgi + 1.1.4-SNAPSHOT + + + + + org.argeo.slc + org.argeo.slc.agent + 1.1.4-SNAPSHOT + + + org.argeo.commons.base org.argeo.osgi.boot ${version.argeo-commons} + - org.argeo.tp - org.apache.commons.cli + org.argeo.commons.base + org.argeo.dep.log4j + ${version.argeo-commons} + pom + org.argeo.tp - org.eclipse.osgi + org.springframework.osgi.extender org.argeo.tp - org.springframework.oxm - true + org.apache.commons.cli - \ No newline at end of file diff --git a/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java b/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java index 8c63c9bb8..7a995e434 100644 --- a/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java +++ b/runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/cli/SlcMain.java @@ -24,71 +24,79 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.GnuParser; import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.io.IOUtils; import org.argeo.osgi.boot.OsgiBoot; import org.argeo.slc.SlcException; -import org.argeo.slc.execution.ExecutionModulesManager; import org.eclipse.core.runtime.adaptor.EclipseStarter; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -@SuppressWarnings("static-access") +@SuppressWarnings("restriction") public class SlcMain { - public enum Type { - standalone, agent, server - } + /** Unique launch module */ + public static String UNIQUE_LAUNCH_MODULE_PROPERTY = "slc.launch.module"; + + /** Unique launch flow */ + public static String UNIQUE_LAUNCH_FLOW_PROPERTY = "slc.launch.flow"; + + // public enum Type { + // standalone, agent, server + // } - private static Boolean debug = true; + // private static Boolean debug = true; // private final static String BOOTSTRAP_LOG4J_CONFIG = // "org/argeo/slc/cli/bootstrapLog4j.properties"; // private final static String DEFAULT_AGENT_CONTEXT = // "classpath:org/argeo/slc/cli/spring-agent-default.xml"; - private final static Option typeOpt = OptionBuilder.withLongOpt("mode") - .withArgName("mode").hasArg() - .withDescription("Execution type, one of: " + listTypeValues()) - .create('t'); - - private final static Option propertyOpt = OptionBuilder - .withLongOpt("property").withArgName("prop1=val1,prop2=val2") - .hasArgs().withValueSeparator(',') - .withDescription("use value for given property").create('p'); - - private final static Option propertiesOpt = OptionBuilder - .withLongOpt("properties").withArgName("properties file").hasArgs() - .withValueSeparator(',') - .withDescription("load properties from file (-p has priority)") - .create('P'); - - private final static Option moduleOpt = OptionBuilder.withLongOpt("module") - .withArgName("module").hasArg().withDescription("Execution module") - .create('m'); - - private final static Option flowsOpt = OptionBuilder.withLongOpt("flows") - .withArgName("flows").hasArg().withDescription("Flows to execute") - .create('f'); - - private final static Option runtimeOpt = OptionBuilder - .withLongOpt("runtime").withArgName("runtime").hasArg() - .withDescription("Runtime URL").create('r'); + // private final static Option typeOpt = OptionBuilder.withLongOpt("mode") + // .withArgName("mode").hasArg() + // .withDescription("Execution type, one of: " + listTypeValues()) + // .create('t'); + // + // private final static Option propertyOpt = OptionBuilder + // .withLongOpt("property").withArgName("prop1=val1,prop2=val2") + // .hasArgs().withValueSeparator(',') + // .withDescription("use value for given property").create('p'); + // + // private final static Option propertiesOpt = OptionBuilder + // .withLongOpt("properties").withArgName("properties file").hasArgs() + // .withValueSeparator(',') + // .withDescription("load properties from file (-p has priority)") + // .create('P'); + // + // private final static Option moduleOpt = + // OptionBuilder.withLongOpt("module") + // .withArgName("module").hasArg().withDescription("Execution module") + // .create('m'); + // + // private final static Option flowsOpt = OptionBuilder.withLongOpt("flows") + // .withArgName("flows").hasArg().withDescription("Flows to execute") + // .create('f'); + // + // private final static Option runtimeOpt = OptionBuilder + // .withLongOpt("runtime").withArgName("runtime").hasArg() + // .withDescription("Runtime URL").create('r'); private final static Options options; private final static String commandName = "slc"; - private static String bundlesToInstall = "/usr/share/osgi;in=*.jar"; + // private static String bundlesToInstall = "/usr/share/osgi;in=*.jar"; + private static String bundlesToInstall = System.getProperty("user.home") + + "/dev/src/slc/runtime/org.argeo.slc.launcher/target/dependency;in=*.jar"; + // private static String bundlesToStart = + // "org.springframework.osgi.extender," + // + "org.argeo.node.repofactory.jackrabbit," + // + "org.argeo.node.repo.jackrabbit," + "org.argeo.security.dao.os," + // + "org.argeo.slc.node.jackrabbit," + "org.argeo.slc.agent," + // + "org.argeo.slc.agent.jcr"; private static String bundlesToStart = "org.springframework.osgi.extender," - + "org.argeo.node.repofactory.jackrabbit," - + "org.argeo.node.repo.jackrabbit," + "org.argeo.security.dao.os," - + "org.argeo.slc.node.jackrabbit," + "org.argeo.slc.agent," - + "org.argeo.slc.agent.jcr"; + + "org.argeo.slc.agent"; static { options = new Options(); @@ -100,6 +108,7 @@ public class SlcMain { // options.addOption(runtimeOpt); } + @SuppressWarnings({ "unchecked" }) public static void main(String[] args) { // Type type = null; // Properties properties = new Properties(); @@ -137,14 +146,8 @@ public class SlcMain { } } - // System.setProperty( - // ExecutionModulesManager.UNIQUE_LAUNCH_MODULE_PROPERTY, - // module); - // System.setProperty( - // ExecutionModulesManager.UNIQUE_LAUNCH_FLOW_PROPERTY, flow); - String executionDir = System.getProperty("user.dir"); - File slcDir = new File(executionDir, ".slc"); + File slcDir = new File(executionDir, "target/.slc"); File dataDir = new File(slcDir, "data"); if (!dataDir.exists()) dataDir.mkdirs(); @@ -165,7 +168,6 @@ public class SlcMain { // OSGi bootstrap OsgiBoot osgiBoot = new OsgiBoot(bundleContext); osgiBoot.installUrls(osgiBoot.getBundlesUrls(bundlesToInstall)); - osgiBoot.startBundles(bundlesToStart); if (moduleUrl != null) { Bundle bundle = osgiBoot.installUrl(moduleUrl); @@ -173,15 +175,28 @@ public class SlcMain { // TODO deal with version } - // retrieve modulesManager - ServiceReference sr = bundleContext - .getServiceReference(ExecutionModulesManager.class - .getName()); - ExecutionModulesManager modulesManager = (ExecutionModulesManager) bundleContext - .getService(sr); - - - modulesManager.execute(null); + System.setProperty(UNIQUE_LAUNCH_MODULE_PROPERTY, module); + System.setProperty(UNIQUE_LAUNCH_FLOW_PROPERTY, flow); + System.setProperty("log4j.configuration", "file:./log4j.properties"); + + // start runtime + osgiBoot.startBundles(bundlesToStart); + + // Bundle bundle = (Bundle) osgiBoot.getBundlesBySymbolicName().get( + // "org.argeo.slc.specs"); + // bundle.loadClass(Execu) + // + // // retrieve modulesManager + // BundlesManager bundlesManager = new + // BundlesManager(bundleContext); + // ExecutionModulesManager modulesManager = bundlesManager + // .getSingleService(ExecutionModulesManager.class, null, true); + // + // RealizedFlow realizedFlow = RealizedFlow.create(module, null, + // flow, + // null); + // modulesManager.start(new BasicNameVersion(module, "0.0.0")); + // modulesManager.execute(realizedFlow); // osgiBoot.bootstrap(); // osgiBoot.bootstrap(); @@ -266,15 +281,15 @@ public class SlcMain { new HelpFormatter().printHelp(commandName, options, true); } - private static String listTypeValues() { - StringBuffer buf = new StringBuffer(""); - for (Type mode : Type.values()) { - buf.append(mode).append(", "); - } - String str = buf.toString(); - // unsafe, but there will be at least one value in the enum - return str.substring(0, str.length() - 2); - } + // private static String listTypeValues() { + // StringBuffer buf = new StringBuffer(""); + // for (Type mode : Type.values()) { + // buf.append(mode).append(", "); + // } + // String str = buf.toString(); + // // unsafe, but there will be at least one value in the enum + // return str.substring(0, str.length() - 2); + // } protected static void addProperty(Properties properties, String property) { int eqIndex = property.indexOf('='); diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/RealizedFlow.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/RealizedFlow.java index a2e33fa88..5928e1732 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/RealizedFlow.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/RealizedFlow.java @@ -16,6 +16,8 @@ package org.argeo.slc.execution; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import org.argeo.slc.BasicNameVersion; import org.argeo.slc.NameVersion; @@ -55,4 +57,30 @@ public class RealizedFlow implements Serializable { public void setFlowDescriptor(ExecutionFlowDescriptor flowDescriptor) { this.flowDescriptor = flowDescriptor; } + + /** Create a simple realized flow */ + public static RealizedFlow create(String module, String version, + String flowName, Map args) { + final RealizedFlow realizedFlow = new RealizedFlow(); + realizedFlow.setModuleName(module); + // TODO deal with version + if (version == null) + version = "0.0.0"; + realizedFlow.setModuleVersion(version); + ExecutionFlowDescriptor efd = new ExecutionFlowDescriptor(); + efd.setName(flowName); + + // arguments + if (args != null && args.size() > 0) { + Map values = new HashMap(); + for (String key : args.keySet()) { + String value = args.get(key); + values.put(key, value); + } + efd.setValues(values); + } + + realizedFlow.setFlowDescriptor(efd); + return realizedFlow; + } } diff --git a/runtime/org.argeo.slc.support.osgi/pom.xml b/runtime/org.argeo.slc.support.osgi/pom.xml index abdf10772..c0c40e1dc 100644 --- a/runtime/org.argeo.slc.support.osgi/pom.xml +++ b/runtime/org.argeo.slc.support.osgi/pom.xml @@ -57,11 +57,6 @@ org.springframework.osgi.extender - - org.argeo.tp - org.springframework.osgi.web - - org.argeo.tp net.sf.cglib @@ -73,10 +68,10 @@ - - org.argeo.tp - org.apache.xalan - + + + + \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java index 6be2294a4..0ddfe71a5 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java @@ -55,6 +55,13 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, private final Object refreshedPackageSem = new Object(); private Boolean packagesRefreshed = false; + public BundlesManager() { + } + + public BundlesManager(BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + /** * Stop the module, update it, refresh it and restart it. All synchronously. */ @@ -282,7 +289,8 @@ public class BundlesManager implements BundleContextAware, FrameworkListener, @SuppressWarnings(value = { "unchecked" }) public T getSingleService(Class clss, String filter, Boolean synchronous) { - Assert.isTrue(OsgiFilterUtils.isValidFilter(filter), "valid filter"); + if (filter != null) + Assert.isTrue(OsgiFilterUtils.isValidFilter(filter), "valid filter"); ServiceReference[] sfs; try { if (synchronous) -- 2.39.2