From af9457b0628ba4cc625192762d0c0fe7564b9846 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Wed, 27 Feb 2013 12:46:52 +0000 Subject: [PATCH] Remove SLC process notifiers git-svn-id: https://svn.argeo.org/slc/trunk@6091 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../slc/client/ui/editors/ProcessEditor.java | 21 +- runtime/org.argeo.slc.core/pom.xml | 4 + .../AbstractExecutionModulesManager.java | 180 +++++++++--------- .../slc/core/execution/DefaultAgent.java | 45 +++-- .../slc/core/execution/DefaultProcess.java | 10 +- .../slc/core/execution/ExecutionThread.java | 52 ++--- .../slc/core/execution/ProcessThread.java | 40 ++-- .../core/execution/ProcessThreadGroup.java | 40 ++-- .../execution/ExecutionModulesManager.java | 37 ++-- .../execution/ExecutionProcessNotifier.java | 35 ---- .../org/argeo/slc/execution/SlcAgent.java | 13 +- .../slc/equinox/ExecutionCommandProvider.java | 1 + 12 files changed, 236 insertions(+), 242 deletions(-) delete mode 100644 runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionProcessNotifier.java diff --git a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java index a8d7b1fb3..75df4d320 100644 --- a/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java +++ b/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java @@ -16,7 +16,6 @@ package org.argeo.slc.client.ui.editors; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.UUID; @@ -33,8 +32,6 @@ import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.controllers.ProcessController; import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; -import org.argeo.slc.execution.ExecutionProcessNotifier; -import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.jcr.SlcJcrUtils; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; @@ -47,8 +44,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.editor.FormEditor; /** Editor for an execution process. */ -public class ProcessEditor extends FormEditor implements - ExecutionProcessNotifier, SlcTypes, SlcNames { +public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { public final static String ID = ClientUiPlugin.ID + ".processEditor"; private Session session; @@ -153,7 +149,7 @@ public class ProcessEditor extends FormEditor implements Map properties = new HashMap(); properties.put(ExecutionModulesManager.SLC_PROCESS_ID, process.getUuid()); - modulesManager.registerProcessNotifier(this, properties); + // modulesManager.registerProcessNotifier(this, properties); } catch (Exception e) { ErrorFeedback.show("Execution of " + processNode + " failed", e); } @@ -249,12 +245,13 @@ public class ProcessEditor extends FormEditor implements return false; } - public void updateStatus(ExecutionProcess process, String oldStatus, - String newStatus) { - } - - public void addSteps(ExecutionProcess process, List steps) { - } + // public void updateStatus(ExecutionProcess process, String oldStatus, + // String newStatus) { + // } + // + // public void addSteps(ExecutionProcess process, List steps) + // { + // } /** Expects one session per editor. */ public void setSession(Session session) { diff --git a/runtime/org.argeo.slc.core/pom.xml b/runtime/org.argeo.slc.core/pom.xml index 1c26c4f32..63017d913 100644 --- a/runtime/org.argeo.slc.core/pom.xml +++ b/runtime/org.argeo.slc.core/pom.xml @@ -66,6 +66,10 @@ org.argeo.tp org.apache.commons.exec + + org.argeo.tp + org.apache.commons.cli + org.argeo.tp diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java index cf44981cd..1a07313f0 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/AbstractExecutionModulesManager.java @@ -15,11 +15,6 @@ */ package org.argeo.slc.core.execution; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; @@ -28,9 +23,6 @@ import org.argeo.slc.execution.ExecutionContext; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionFlowDescriptorConverter; import org.argeo.slc.execution.ExecutionModulesManager; -import org.argeo.slc.execution.ExecutionProcess; -import org.argeo.slc.execution.ExecutionProcessNotifier; -import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.execution.RealizedFlow; /** Provides the base feature of an execution module manager. */ @@ -39,8 +31,8 @@ public abstract class AbstractExecutionModulesManager implements private final static Log log = LogFactory .getLog(AbstractExecutionModulesManager.class); - private List filteredNotifiers = Collections - .synchronizedList(new ArrayList()); +// private List filteredNotifiers = Collections +// .synchronizedList(new ArrayList()); protected abstract ExecutionFlow findExecutionFlow(String moduleName, String moduleVersion, String flowName); @@ -78,88 +70,88 @@ public abstract class AbstractExecutionModulesManager implements // } - public void dispatchUpdateStatus(ExecutionProcess process, - String oldStatus, String newStatus) { - // filtered notifiers - for (Iterator it = filteredNotifiers.iterator(); it - .hasNext();) { - FilteredNotifier filteredNotifier = it.next(); - if (filteredNotifier.receiveFrom(process)) - filteredNotifier.getNotifier().updateStatus(process, oldStatus, - newStatus); - } - - } - - public void dispatchAddSteps(ExecutionProcess process, - List steps) { - process.addSteps(steps); - for (Iterator it = filteredNotifiers.iterator(); it - .hasNext();) { - FilteredNotifier filteredNotifier = it.next(); - if (filteredNotifier.receiveFrom(process)) - filteredNotifier.getNotifier().addSteps(process, steps); - } - } - - public void registerProcessNotifier(ExecutionProcessNotifier notifier, - Map properties) { - filteredNotifiers.add(new FilteredNotifier(notifier, properties)); - } - - public void unregisterProcessNotifier(ExecutionProcessNotifier notifier, - Map properties) { - filteredNotifiers.remove(notifier); - } - - protected class FilteredNotifier { - private final ExecutionProcessNotifier notifier; - private final String processId; - - public FilteredNotifier(ExecutionProcessNotifier notifier, - Map properties) { - super(); - this.notifier = notifier; - if (properties == null) - properties = new HashMap(); - if (properties.containsKey(SLC_PROCESS_ID)) - processId = properties.get(SLC_PROCESS_ID); - else - processId = null; - } - - /** - * Whether event from this process should be received by this listener. - */ - public Boolean receiveFrom(ExecutionProcess process) { - if (processId != null) - if (process.getUuid().equals(processId)) - return true; - else - return false; - return true; - } - - @Override - public int hashCode() { - return notifier.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof FilteredNotifier) { - FilteredNotifier fn = (FilteredNotifier) obj; - return notifier.equals(fn.notifier); - } else if (obj instanceof ExecutionProcessNotifier) { - ExecutionProcessNotifier epn = (ExecutionProcessNotifier) obj; - return notifier.equals(epn); - } else - return false; - } - - public ExecutionProcessNotifier getNotifier() { - return notifier; - } - - } +// public void dispatchUpdateStatus(ExecutionProcess process, +// String oldStatus, String newStatus) { +// // filtered notifiers +// for (Iterator it = filteredNotifiers.iterator(); it +// .hasNext();) { +// FilteredNotifier filteredNotifier = it.next(); +// if (filteredNotifier.receiveFrom(process)) +// filteredNotifier.getNotifier().updateStatus(process, oldStatus, +// newStatus); +// } +// +// } + +// public void dispatchAddSteps(ExecutionProcess process, +// List steps) { +// process.addSteps(steps); +// for (Iterator it = filteredNotifiers.iterator(); it +// .hasNext();) { +// FilteredNotifier filteredNotifier = it.next(); +// if (filteredNotifier.receiveFrom(process)) +// filteredNotifier.getNotifier().addSteps(process, steps); +// } +// } + +// public void registerProcessNotifier(ExecutionProcessNotifier notifier, +// Map properties) { +// filteredNotifiers.add(new FilteredNotifier(notifier, properties)); +// } +// +// public void unregisterProcessNotifier(ExecutionProcessNotifier notifier, +// Map properties) { +// filteredNotifiers.remove(notifier); +// } + +// protected class FilteredNotifier { +// private final ExecutionProcessNotifier notifier; +// private final String processId; +// +// public FilteredNotifier(ExecutionProcessNotifier notifier, +// Map properties) { +// super(); +// this.notifier = notifier; +// if (properties == null) +// properties = new HashMap(); +// if (properties.containsKey(SLC_PROCESS_ID)) +// processId = properties.get(SLC_PROCESS_ID); +// else +// processId = null; +// } +// +// /** +// * Whether event from this process should be received by this listener. +// */ +// public Boolean receiveFrom(ExecutionProcess process) { +// if (processId != null) +// if (process.getUuid().equals(processId)) +// return true; +// else +// return false; +// return true; +// } +// +// @Override +// public int hashCode() { +// return notifier.hashCode(); +// } +// +// @Override +// public boolean equals(Object obj) { +// if (obj instanceof FilteredNotifier) { +// FilteredNotifier fn = (FilteredNotifier) obj; +// return notifier.equals(fn.notifier); +// } else if (obj instanceof ExecutionProcessNotifier) { +// ExecutionProcessNotifier epn = (ExecutionProcessNotifier) obj; +// return notifier.equals(epn); +// } else +// return false; +// } +// +// public ExecutionProcessNotifier getNotifier() { +// return notifier; +// } +// +// } } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java index 909fa1760..7d6ff315e 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgent.java @@ -19,6 +19,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; @@ -28,13 +29,11 @@ import org.apache.commons.logging.LogFactory; import org.argeo.slc.execution.ExecutionModuleDescriptor; import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; -import org.argeo.slc.execution.ExecutionProcessNotifier; -import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.execution.SlcAgent; import org.argeo.slc.execution.SlcAgentDescriptor; /** Implements the base methods of an SLC agent. */ -public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier { +public class DefaultAgent implements SlcAgent { private final static Log log = LogFactory.getLog(DefaultAgent.class); private SlcAgentDescriptor agentDescriptor; @@ -59,8 +58,8 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier { } processesThreadGroup = new ThreadGroup("SLC Processes of Agent #" + agentDescriptor.getUuid()); - modulesManager.registerProcessNotifier(this, - new HashMap()); + // modulesManager.registerProcessNotifier(this, + // new HashMap()); // final String module = System // .getProperty(ExecutionModulesManager.UNIQUE_LAUNCH_MODULE_PROPERTY); @@ -79,8 +78,8 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier { /** Clean up (needs to be called by overriding method) */ public void destroy() { - modulesManager.unregisterProcessNotifier(this, - new HashMap()); +// modulesManager.unregisterProcessNotifier(this, +// new HashMap()); } /** @@ -106,7 +105,14 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier { modulesManager, process); processThread.start(); runningProcesses.put(process.getUuid(), processThread); - // FIXME find a way to remove them from this register + + // clean up old processes + Iterator it = runningProcesses.values().iterator(); + while (it.hasNext()) { + ProcessThread pThread = it.next(); + if (!pThread.isAlive()) + it.remove(); + } } public void kill(ExecutionProcess process) { @@ -141,17 +147,18 @@ public class DefaultAgent implements SlcAgent, ExecutionProcessNotifier { /* * PROCESS NOTIFIER */ - public void updateStatus(ExecutionProcess process, String oldStatus, - String newStatus) { - if (newStatus.equals(ExecutionProcess.COMPLETED) - || newStatus.equals(ExecutionProcess.ERROR) - || newStatus.equals(ExecutionProcess.KILLED)) { - runningProcesses.remove(process.getUuid()); - } - } - - public void addSteps(ExecutionProcess process, List steps) { - } + // public void updateStatus(ExecutionProcess process, String oldStatus, + // String newStatus) { + // if (newStatus.equals(ExecutionProcess.COMPLETED) + // || newStatus.equals(ExecutionProcess.ERROR) + // || newStatus.equals(ExecutionProcess.KILLED)) { + // runningProcesses.remove(process.getUuid()); + // } + // } + // + // public void addSteps(ExecutionProcess process, List steps) + // { + // } /* * BEAN diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultProcess.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultProcess.java index 06ff4d2f7..30211800f 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultProcess.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultProcess.java @@ -8,11 +8,13 @@ import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.execution.RealizedFlow; +/** Canonical implementation of an {@link ExecutionProcess} as a bean. */ public class DefaultProcess implements ExecutionProcess { private String uuid = UUID.randomUUID().toString(); - private String status; + private String status = ExecutionProcess.NEW; private List steps = new ArrayList(); + private List realizedFlows = new ArrayList(); public String getUuid() { return uuid; @@ -31,7 +33,7 @@ public class DefaultProcess implements ExecutionProcess { } public List getRealizedFlows() { - return null; + return realizedFlows; } public List getSteps() { @@ -46,4 +48,8 @@ public class DefaultProcess implements ExecutionProcess { this.uuid = uuid; } + public void setRealizedFlows(List realizedFlows) { + this.realizedFlows = realizedFlows; + } + } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java index ec69c68d7..71e2100e2 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java @@ -22,6 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.execution.RealizedFlow; import org.springframework.security.Authentication; @@ -33,17 +34,20 @@ public class ExecutionThread extends Thread { private final static Log log = LogFactory.getLog(ExecutionThread.class); + private ExecutionModulesManager executionModulesManager; private final RealizedFlow realizedFlow; - private final ProcessThread processThread; + // private final ProcessThread processThread; private List destructionCallbacks = new ArrayList(); - public ExecutionThread(ProcessThread processThread, + public ExecutionThread(ProcessThreadGroup processThreadGroup, + ExecutionModulesManager executionModulesManager, RealizedFlow realizedFlow) { - super(processThread.getProcessThreadGroup(), "Flow " + super(processThreadGroup, "Flow " + realizedFlow.getFlowDescriptor().getName()); this.realizedFlow = realizedFlow; - this.processThread = processThread; + this.executionModulesManager = executionModulesManager; + // this.processThread = processThread; } public void run() { @@ -59,37 +63,40 @@ public class ExecutionThread extends Thread { .getFlowDescriptor(); String flowName = executionFlowDescriptor.getName(); - dispatchAddStep(new ExecutionStep(realizedFlow.getModuleName(), - ExecutionStep.PHASE_START, "Flow " + flowName)); + getProcessThreadGroup().dispatchAddStep( + new ExecutionStep(realizedFlow.getModuleName(), + ExecutionStep.PHASE_START, "Flow " + flowName)); try { String autoUpgrade = System .getProperty(SYSPROP_EXECUTION_AUTO_UPGRADE); if (autoUpgrade != null && autoUpgrade.equals("true")) - processThread.getExecutionModulesManager().upgrade( - realizedFlow.getModuleNameVersion()); + executionModulesManager.upgrade(realizedFlow + .getModuleNameVersion()); // START FLOW - processThread.getExecutionModulesManager().execute(realizedFlow); + executionModulesManager.execute(realizedFlow); // END FLOW } catch (Exception e) { // TODO: re-throw exception ? String msg = "Execution of flow " + flowName + " failed."; log.error(msg, e); - dispatchAddStep(new ExecutionStep(realizedFlow.getModuleName(), - ExecutionStep.ERROR, msg + " " + e.getMessage())); - processThread.notifyError(); + getProcessThreadGroup().dispatchAddStep( + new ExecutionStep(realizedFlow.getModuleName(), + ExecutionStep.ERROR, msg + " " + e.getMessage())); + // processThread.notifyError(); } finally { - processThread.flowCompleted(); - dispatchAddStep(new ExecutionStep(realizedFlow.getModuleName(), - ExecutionStep.PHASE_END, "Flow " + flowName)); + // processThread.flowCompleted(); + getProcessThreadGroup().dispatchAddStep( + new ExecutionStep(realizedFlow.getModuleName(), + ExecutionStep.PHASE_END, "Flow " + flowName)); processDestructionCallbacks(); } } - private void dispatchAddStep(ExecutionStep step) { - processThread.getProcessThreadGroup().dispatchAddStep(step); - } + // private void dispatchAddStep(ExecutionStep step) { + // getProcessThreadGroup().dispatchAddStep(step); + // } private synchronized void processDestructionCallbacks() { for (int i = destructionCallbacks.size() - 1; i >= 0; i--) { @@ -111,11 +118,12 @@ public class ExecutionThread extends Thread { } protected ProcessThreadGroup getProcessThreadGroup() { - return processThread.getProcessThreadGroup(); + return (ProcessThreadGroup) getThreadGroup(); + // return processThread.getProcessThreadGroup(); } - public RealizedFlow getRealizedFlow() { - return realizedFlow; - } + // public RealizedFlow getRealizedFlow() { + // return realizedFlow; + // } } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java index 8e7584b2b..5552d664e 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThread.java @@ -31,6 +31,10 @@ import org.argeo.slc.execution.RealizedFlow; import org.springframework.security.Authentication; import org.springframework.security.context.SecurityContextHolder; +/** + * Main thread coordinating an {@link ExecutionProcess}, launching parallel or + * sequential {@link ExecutionThread}s. + */ public class ProcessThread extends Thread { private final static Log log = LogFactory.getLog(ProcessThread.class); @@ -41,7 +45,7 @@ public class ProcessThread extends Thread { private Set executionThreads = Collections .synchronizedSet(new HashSet()); - private Boolean hadAnError = false; + // private Boolean hadAnError = false; private Boolean killed = false; public ProcessThread(ThreadGroup processesThreadGroup, @@ -50,8 +54,7 @@ public class ProcessThread extends Thread { super(processesThreadGroup, "SLC Process #" + process.getUuid()); this.executionModulesManager = executionModulesManager; this.process = process; - processThreadGroup = new ProcessThreadGroup(executionModulesManager, - this); + processThreadGroup = new ProcessThreadGroup(process); } public final void run() { @@ -71,10 +74,10 @@ public class ProcessThread extends Thread { // Start logging new LoggingThread().start(); - String oldStatus = process.getStatus(); + // String oldStatus = process.getStatus(); process.setStatus(ExecutionProcess.RUNNING); - executionModulesManager.dispatchUpdateStatus(process, oldStatus, - ExecutionProcess.RUNNING); + // executionModulesManager.dispatchUpdateStatus(process, oldStatus, + // ExecutionProcess.RUNNING); try { process(); @@ -101,16 +104,16 @@ public class ProcessThread extends Thread { /** Make sure this is called BEFORE all the threads are interrupted. */ private void computeFinalStatus() { - String oldStatus = process.getStatus(); + // String oldStatus = process.getStatus(); // TODO: error management at flow level? if (killed) process.setStatus(ExecutionProcess.KILLED); - else if (hadAnError) + else if (processThreadGroup.hadAnError()) process.setStatus(ExecutionProcess.ERROR); else process.setStatus(ExecutionProcess.COMPLETED); - executionModulesManager.dispatchUpdateStatus(process, oldStatus, - process.getStatus()); + // executionModulesManager.dispatchUpdateStatus(process, oldStatus, + // process.getStatus()); log.info("\n## SLC Process #" + process.getUuid() + " " + process.getStatus() + "\n"); } @@ -148,7 +151,8 @@ public class ProcessThread extends Thread { if (killed) return; - ExecutionThread thread = new ExecutionThread(this, realizedFlow); + ExecutionThread thread = new ExecutionThread(processThreadGroup, + executionModulesManager, realizedFlow); executionThreads.add(thread); thread.start(); @@ -158,13 +162,13 @@ public class ProcessThread extends Thread { return; } - public void notifyError() { - hadAnError = true; - } - - public synchronized void flowCompleted() { - // notifyAll(); - } +// public void notifyError() { +// hadAnError = true; +// } +// +// public synchronized void flowCompleted() { +// // notifyAll(); +// } public ExecutionProcess getProcess() { return process; diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java index 969c9b93f..2f264bed4 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ProcessThreadGroup.java @@ -15,12 +15,9 @@ */ package org.argeo.slc.core.execution; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.execution.ExecutionStep; import org.springframework.security.Authentication; @@ -28,20 +25,20 @@ import org.springframework.security.context.SecurityContextHolder; /** The thread group attached to a given {@link SlcExecution}. */ public class ProcessThreadGroup extends ThreadGroup { - private final ExecutionModulesManager executionModulesManager; - private final ProcessThread processThread; + // private final ExecutionModulesManager executionModulesManager; + // private final ProcessThread processThread; private final Authentication authentication; private final static Integer STEPS_BUFFER_CAPACITY = 5000; private BlockingQueue steps = new ArrayBlockingQueue( STEPS_BUFFER_CAPACITY); - public ProcessThreadGroup(ExecutionModulesManager executionModulesManager, - ProcessThread processThread) { - super("SLC Process #" + processThread.getProcess().getUuid() - + " thread group"); - this.executionModulesManager = executionModulesManager; - this.processThread = processThread; + private Boolean hadAnError = false; + + public ProcessThreadGroup(ExecutionProcess executionProcess) { + super("SLC Process #" + executionProcess.getUuid() + " thread group"); + // this.executionModulesManager = executionModulesManager; + // this.processThread = processThread; this.authentication = SecurityContextHolder.getContext() .getAuthentication(); } @@ -51,22 +48,27 @@ public class ProcessThreadGroup extends ThreadGroup { } public void dispatchAddStep(ExecutionStep step) { - ExecutionProcess slcProcess = processThread.getProcess(); - List steps = new ArrayList(); - steps.add(step); + // ExecutionProcess slcProcess = processThread.getProcess(); + // List steps = new ArrayList(); + // steps.add(step); // TODO clarify why we don't dispatch steps, must be a reason // dispatchAddSteps(steps); - slcProcess.addSteps(steps); + // slcProcess.addSteps(steps); + if (step.getType().equals(ExecutionStep.ERROR)) + hadAnError = true; this.steps.add(step); } - public void dispatchAddSteps(List steps) { - ExecutionProcess slcProcess = processThread.getProcess(); - executionModulesManager.dispatchAddSteps(slcProcess, steps); - } + // public void dispatchAddSteps(List steps) { + // ExecutionProcess slcProcess = processThread.getProcess(); + // executionModulesManager.dispatchAddSteps(slcProcess, steps); + // } public BlockingQueue getSteps() { return steps; } + public Boolean hadAnError() { + return hadAnError; + } } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModulesManager.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModulesManager.java index b04eca300..06681747a 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModulesManager.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionModulesManager.java @@ -16,7 +16,6 @@ package org.argeo.slc.execution; import java.util.List; -import java.util.Map; import org.argeo.slc.deploy.ModulesManager; @@ -44,22 +43,22 @@ public interface ExecutionModulesManager extends ModulesManager { /** Synchronously finds and executes an {@link ExecutionFlow}. */ public void execute(RealizedFlow realizedFlow); - /** Notify of a status update status of the {@link ExecutionProcess} */ - public void dispatchUpdateStatus(ExecutionProcess process, - String oldStatus, String newStatus); - - /** Notify that a step was added in an {@link ExecutionProcess} */ - public void dispatchAddSteps(ExecutionProcess process, - List steps); - - /** - * Register a notifier which will be notified based on the provided - * properties. - */ - public void registerProcessNotifier(ExecutionProcessNotifier notifier, - Map properties); - - /** Unregisters a notifier */ - public void unregisterProcessNotifier(ExecutionProcessNotifier notifier, - Map properties); + // /** Notify of a status update status of the {@link ExecutionProcess} */ +// public void dispatchUpdateStatus(ExecutionProcess process, +// String oldStatus, String newStatus); + // + // /** Notify that a step was added in an {@link ExecutionProcess} */ + // public void dispatchAddSteps(ExecutionProcess process, + // List steps); + // + // /** + // * Register a notifier which will be notified based on the provided + // * properties. + // */ + // public void registerProcessNotifier(ExecutionProcessNotifier notifier, + // Map properties); + // + // /** Unregisters a notifier */ + // public void unregisterProcessNotifier(ExecutionProcessNotifier notifier, + // Map properties); } diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionProcessNotifier.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionProcessNotifier.java deleted file mode 100644 index 28b2fed9f..000000000 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionProcessNotifier.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.argeo.slc.execution; - -import java.util.List; - -/** - * Implementations of this interface can be notified of events related to - * process execution. - */ -public interface ExecutionProcessNotifier { - /** - * Notify a status change, see {@link ExecutionProcess} for the list of - * vaailable statuses. - */ - public void updateStatus(ExecutionProcess process, String oldStatus, - String newStatus); - - /** Notifiy of new execution steps. */ - public void addSteps(ExecutionProcess process, List steps); - -} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/SlcAgent.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/SlcAgent.java index 9b8acb728..38fcb24a2 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/SlcAgent.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/SlcAgent.java @@ -17,8 +17,12 @@ package org.argeo.slc.execution; import java.util.List; - -/** A local agent, able to run SLC Execution locally. */ +/** + * A local agent can run SLC processes. It is responsible for creating their + * threads and integrating them with various UIs. It typically wraps + * {@link ExecutionModulesManager} which is used to run flows synchronously at a + * lower level. + */ public interface SlcAgent { /** Agent unique identifier */ public String getAgentUuid(); @@ -29,9 +33,14 @@ public interface SlcAgent { /** Kills this process */ public void kill(ExecutionProcess process); + /** + * Describe all the flows provided by this execution module. Typically + * called in order to build a realized flow. + */ public ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version); + /** List all execution modules which can be processed by this agent. */ public List listExecutionModuleDescriptors(); /** @return true if still alive. */ diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java index ae99ab0c4..25de1868d 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/ExecutionCommandProvider.java @@ -58,6 +58,7 @@ public class ExecutionCommandProvider implements CommandProvider { } } String executionName = ci.nextArgument(); + launch(slcCommand, firstArg, executionName); return "COMMAND COMPLETED"; -- 2.39.2