]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Improve executions and system calls
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 17 Feb 2010 23:23:20 +0000 (23:23 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 17 Feb 2010 23:23:20 +0000 (23:23 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3366 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ParameterRef.java
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/ModulesManager.java
runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java
runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/BundlesManager.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiBundle.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java

index c437ba0cb9afc08f9c15e14ee236b1bdd56dbec0..76d523bf8105f91ae2a149c579139ebe6a85c0d1 100644 (file)
@@ -2,23 +2,69 @@ package org.argeo.slc.core.execution;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.execution.ExecutionContext;
+import org.argeo.slc.execution.ExecutionFlow;
+import org.argeo.slc.execution.ExecutionFlowDescriptorConverter;
 import org.argeo.slc.execution.ExecutionModulesListener;
 import org.argeo.slc.execution.ExecutionModulesManager;
+import org.argeo.slc.process.RealizedFlow;
 import org.argeo.slc.process.SlcExecution;
 import org.argeo.slc.process.SlcExecutionNotifier;
 
 public abstract class AbstractExecutionModulesManager implements
                ExecutionModulesManager {
+       private final static Log log = LogFactory
+                       .getLog(AbstractExecutionModulesManager.class);
+
        private List<SlcExecutionNotifier> slcExecutionNotifiers = new ArrayList<SlcExecutionNotifier>();
        private List<ExecutionModulesListener> executionModulesListeners = new ArrayList<ExecutionModulesListener>();
 
        private ThreadGroup processesThreadGroup = new ThreadGroup("Processes");
 
+       protected abstract ExecutionFlow findExecutionFlow(String moduleName,
+                       String moduleVersion, String flowName);
+
+       protected abstract ExecutionContext findExecutionContext(String moduleName,
+                       String moduleVersion);
+
+       protected abstract ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
+                       String moduleName, String moduleVersion);
+
        public void process(SlcExecution slcExecution) {
                new ProcessThread(this, slcExecution).start();
        }
 
+       public void execute(RealizedFlow realizedFlow) {
+               if (log.isTraceEnabled())
+                       log.trace("Executing " + realizedFlow);
+
+               String moduleName = realizedFlow.getModuleName();
+               String moduleVersion = realizedFlow.getModuleVersion();
+
+               Map<? extends String, ? extends Object> variablesToAdd = getExecutionFlowDescriptorConverter(
+                               moduleName, moduleVersion).convertValues(
+                               realizedFlow.getFlowDescriptor());
+               ExecutionContext executionContext = findExecutionContext(moduleName,
+                               moduleVersion);
+               for (String key : variablesToAdd.keySet())
+                       executionContext.setVariable(key, variablesToAdd.get(key));
+
+               ExecutionFlow flow = findExecutionFlow(moduleName, moduleVersion,
+                               realizedFlow.getFlowDescriptor().getName());
+
+               //
+               // Actually runs the flow, IN THIS THREAD
+               //
+               flow.run();
+               //
+               //
+               //
+       }
+
        public void setSlcExecutionNotifiers(
                        List<SlcExecutionNotifier> slcExecutionNotifiers) {
                this.slcExecutionNotifiers = slcExecutionNotifiers;
index 3c85055f816dfa8efcda98a93677085e170ef27e..f1ebde364142d7db5cfa91085b7750d9ac208cd8 100644 (file)
@@ -14,6 +14,8 @@ import org.argeo.slc.process.SlcExecutionStep;
 
 /** Thread of a single execution */
 public class ExecutionThread extends Thread {
+       public final static String SYSPROP_EXECUTION_AUTO_UPGRADE = "slc.execution.autoupgrade";
+
        private final static Log log = LogFactory.getLog(ExecutionThread.class);
 
        private final RealizedFlow realizedFlow;
@@ -43,6 +45,11 @@ public class ExecutionThread extends Thread {
                                SlcExecutionStep.TYPE_PHASE_START, "Flow " + flowName));
 
                try {
+                       String autoUpgrade = System
+                                       .getProperty(SYSPROP_EXECUTION_AUTO_UPGRADE);
+                       if (autoUpgrade != null && autoUpgrade.equals("true"))
+                               processThread.getExecutionModulesManager().upgrade(
+                                               realizedFlow.getModuleNameVersion());
                        processThread.getExecutionModulesManager().execute(realizedFlow);
                } catch (Exception e) {
                        // TODO: re-throw exception ?
index 6fd277a10425d9307c6337ec1688daa70c327974..f28e1e49f058bbe621b445097771d7cee921254b 100644 (file)
@@ -16,12 +16,8 @@ public class ParameterRef implements FactoryBean {
        public ParameterRef() {
        }
 
-       /** @deprecated for backward compatibility with pre v0.11.4 approach. */
        public ParameterRef(String name) {
                this.name = name;
-               log
-                               .warn("Using constructor in parameter ref is deprecated"
-                                               + " and will be removed in a later version. Set with property 'name'.");
        }
 
        public Object getObject() throws Exception {
index 95154ef0f6fcccdf312b1dc910b6052600ba97d5..e5df71ab1ff291de369a271c6e75650888f606b9 100644 (file)
@@ -281,13 +281,15 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
                                stdOutputStream != null ? stdOutputStream
                                                : new LogOutputStream() {
                                                        protected void processLine(String line, int level) {
-                                                               log(stdOutLogLevel, line);
+                                                               if (line != null && !line.trim().equals(""))
+                                                                       log(stdOutLogLevel, line);
                                                                if (stdOutWriter != null)
                                                                        appendLineToFile(stdOutWriter, line);
                                                        }
                                                }, new LogOutputStream() {
                                        protected void processLine(String line, int level) {
-                                               log(stdErrLogLevel, line);
+                                               if (line != null && !line.trim().equals(""))
+                                                       log(stdErrLogLevel, line);
                                                if (stdErrWriter != null)
                                                        appendLineToFile(stdErrWriter, line);
                                        }
@@ -301,20 +303,19 @@ public class SystemCall extends TreeSRelatedHelper implements Runnable {
                return new ExecuteResultHandler() {
 
                        public void onProcessComplete(int exitValue) {
+                               String msg = "System call '" + commandLine
+                                               + "' properly completed.";
                                if (log.isDebugEnabled())
-                                       log
-                                                       .debug("Process " + commandLine
-                                                                       + " properly completed.");
+                                       log.debug(msg);
                                if (testResult != null) {
                                        forwardPath(testResult, null);
                                        testResult.addResultPart(new SimpleResultPart(
-                                                       TestStatus.PASSED, "Process " + commandLine
-                                                                       + " properly completed."));
+                                                       TestStatus.PASSED, msg));
                                }
                        }
 
                        public void onProcessFailed(ExecuteException e) {
-                               String msg = "Process " + commandLine + " failed.";
+                               String msg = "System call '" + commandLine + "' failed.";
                                if (testResult != null) {
                                        forwardPath(testResult, null);
                                        testResult.addResultPart(new SimpleResultPart(
index 93d325f5f4133f14049df396a515479c99cf5c1c..b80887d0f5aa07f693c45032705c8c1b0fe02d34 100644 (file)
@@ -2,6 +2,8 @@ package org.argeo.slc.deploy;
 
 import java.util.List;
 
+import org.argeo.slc.build.NameVersion;
+
 /** Provides access to modules */
 public interface ModulesManager {
        /** @return a full fledged module descriptor. */
@@ -12,4 +14,7 @@ public interface ModulesManager {
         * @return a list of minimal module descriptors
         */
        public List<ModuleDescriptor> listModules();
+
+       /** Synchronously upgrades the module referenced by this name version */
+       public void upgrade(NameVersion nameVersion);
 }
index 308b906e70d84991c7156fce6544f63851e0902d..1abf694284e2b68e10afed8a1d4aa7ab8ec128fb 100644 (file)
@@ -2,6 +2,8 @@ package org.argeo.slc.process;
 
 import java.io.Serializable;
 
+import org.argeo.slc.build.BasicNameVersion;
+import org.argeo.slc.build.NameVersion;
 import org.argeo.slc.execution.ExecutionFlowDescriptor;
 import org.argeo.slc.execution.ExecutionSpec;
 
@@ -20,6 +22,10 @@ public class RealizedFlow implements Serializable {
        public void setModuleName(String moduleName) {
                this.moduleName = moduleName;
        }
+       
+       public NameVersion getModuleNameVersion(){
+               return new BasicNameVersion(getModuleName(), getModuleVersion());
+       }
 
        public String getModuleVersion() {
                return moduleVersion;
index 9711c3c96ed4720b2a1e37c4e2888d59990359e9..8b9378e17267856d7a1a83269775a4f1cc950d1c 100644 (file)
@@ -58,9 +58,10 @@ public class ExecutionCommandProvider implements CommandProvider {
                                        + executionName);
 
                // Execute
-               if (SLC_WITH_REFRESH.equals(slcCommand))
-                       modulesManager.updateAndExecute(lastLaunch);
-               else if (SLC_NO_REFRESH.equals(slcCommand))
+               if (SLC_WITH_REFRESH.equals(slcCommand)) {
+                       modulesManager.upgrade(lastLaunch.getModuleNameVersion());
+                       modulesManager.execute(lastLaunch);
+               } else if (SLC_NO_REFRESH.equals(slcCommand))
                        modulesManager.execute(lastLaunch);
                else
                        throw new SlcException("Unrecognized SLC command " + slcCommand);
index 2f846ccb7a102663e5b10ba9986eaac2d0e7d130..5f50bf84fb1c5ba42a81920d17be130a37f74167 100644 (file)
@@ -91,9 +91,9 @@ public class BundlesManager implements BundleContextAware, FrameworkListener,
                        }
 
                        if (log.isDebugEnabled())
-                               log.debug("Bundle " + bundle.getSymbolicName()
-                                               + " ready to be used at latest version."
-                                               + " (upgrade performed in " + (end - begin) + "ms).");
+                               log.debug("Bundle '" + bundle.getSymbolicName()
+                                               + "' upgraded and ready " + " (upgrade performed in "
+                                               + (end - begin) + "ms).");
 
                        if (log.isTraceEnabled()) {
                                ApplicationContext applicationContext = (ApplicationContext) bundleContext
index 50b76fa4764c06abeb2460a03a0b8b765d41818f..19b357285a6f886b44670f906f831495787ac8d0 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.slc.osgi;
 
 import org.argeo.slc.build.BasicNameVersion;
 import org.argeo.slc.build.Distribution;
+import org.argeo.slc.build.NameVersion;
 import org.argeo.slc.core.build.ResourceDistribution;
 import org.argeo.slc.deploy.DeploymentData;
 import org.argeo.slc.deploy.Module;
@@ -26,6 +27,10 @@ public class OsgiBundle extends BasicNameVersion implements Module {
                super(name, version);
        }
 
+       public OsgiBundle(NameVersion nameVersion) {
+               super(nameVersion);
+       }
+
        public OsgiBundle(Bundle bundle) {
                super(bundle.getSymbolicName(), getVersionSafe(bundle));
                internalBundleId = bundle.getBundleId();
index 9fd9c09f419bb7b2bfe43c40a66868b91ed98dd4..50967384e8d8f097647b6ee1d9f99c812f18f0c8 100644 (file)
@@ -14,6 +14,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.slc.SlcException;
 import org.argeo.slc.build.BasicNameVersion;
+import org.argeo.slc.build.NameVersion;
 import org.argeo.slc.core.execution.AbstractExecutionModulesManager;
 import org.argeo.slc.core.execution.DefaultExecutionFlowDescriptorConverter;
 import org.argeo.slc.deploy.ModuleDescriptor;
@@ -258,10 +259,9 @@ public class OsgiExecutionModulesManager extends
                }
        }
 
-       public void updateAndExecute(RealizedFlow realizedFlow) {
-               OsgiBundle osgiBundle = new OsgiBundle(realizedFlow);
+       public void upgrade(NameVersion nameVersion) {
+               OsgiBundle osgiBundle = new OsgiBundle(nameVersion);
                bundlesManager.upgradeSynchronous(osgiBundle);
-               execute(realizedFlow);
        }
 
        protected synchronized ExecutionFlowDescriptorConverter getExecutionFlowDescriptorConverter(
@@ -283,33 +283,6 @@ public class OsgiExecutionModulesManager extends
                }
        }
 
-       public void execute(RealizedFlow realizedFlow) {
-               if (log.isTraceEnabled())
-                       log.trace("Executing " + realizedFlow);
-
-               String moduleName = realizedFlow.getModuleName();
-               String moduleVersion = realizedFlow.getModuleVersion();
-
-               Map<? extends String, ? extends Object> variablesToAdd = getExecutionFlowDescriptorConverter(
-                               moduleName, moduleVersion).convertValues(
-                               realizedFlow.getFlowDescriptor());
-               ExecutionContext executionContext = findExecutionContext(moduleName,
-                               moduleVersion);
-               for (String key : variablesToAdd.keySet())
-                       executionContext.setVariable(key, variablesToAdd.get(key));
-
-               ExecutionFlow flow = findExecutionFlow(moduleName, moduleVersion,
-                               realizedFlow.getFlowDescriptor().getName());
-
-               //
-               // Actually runs the flow, IN THIS THREAD
-               //
-               flow.run();
-               //
-               //
-               //
-       }
-
        public ModuleDescriptor getModuleDescriptor(String moduleName,
                        String version) {
                return getExecutionModuleDescriptor(moduleName, version);