From: Mathieu Baudier Date: Tue, 5 Jul 2011 13:33:06 +0000 (+0000) Subject: Improve logging X-Git-Tag: argeo-slc-2.1.7~912 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=0e2ff188c2e8ffac85739cccc3925e8bd82d7be9;hp=8696d1a70c254b338d0cac390ef7c80b5f773942;p=gpl%2Fargeo-slc.git Improve logging Logging in UI git-svn-id: https://svn.argeo.org/slc/trunk@4666 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureClientApplication.java b/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureClientApplication.java index e56eadbda..e2b054219 100644 --- a/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureClientApplication.java +++ b/eclipse/plugins/org.argeo.slc.client.rcp/src/main/java/org/argeo/slc/client/rcp/SlcSecureClientApplication.java @@ -1,6 +1,8 @@ package org.argeo.slc.client.rcp; import org.argeo.security.ui.rcp.SecureRcp; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.window.Window.IExceptionHandler; import org.eclipse.ui.application.WorkbenchAdvisor; /** @@ -10,6 +12,14 @@ public class SlcSecureClientApplication extends SecureRcp { @Override protected WorkbenchAdvisor createWorkbenchAdvisor(String username) { + Window.setExceptionHandler(new IExceptionHandler() { + + public void handleException(Throwable t) { + System.err.println("Unexpected SLC UI exception: " + t); + + } + }); + return new SlcSecureWorkbenchAdvisor(username); } diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/controllers.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/controllers.xml index 866c7f473..229d6d1ab 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/controllers.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/controllers.xml @@ -5,6 +5,5 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/editors.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/editors.xml index 2ddbd7f10..31267a15a 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/editors.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/editors.xml @@ -7,6 +7,7 @@ + diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/jcr.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/jcr.xml index c463e7b57..b2043e29b 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/jcr.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/jcr.xml @@ -4,23 +4,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - - - - - - - - - - diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/listeners.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/listeners.xml deleted file mode 100644 index 42ed1408a..000000000 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/listeners.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - diff --git a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml index 8fb16bda3..9c4b4a908 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml +++ b/eclipse/plugins/org.argeo.slc.client.ui/META-INF/spring/views.xml @@ -4,52 +4,20 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - - - - - + + + + - - - - + + + - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java index 7d0a76ad5..328282c54 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/controllers/ProcessController.java @@ -26,7 +26,7 @@ public class ProcessController { private final static Log log = LogFactory.getLog(ProcessController.class); private Map agentFactories = new HashMap(); - public void process(Node processNode) { + public ExecutionProcess process(Node processNode) { JcrExecutionProcess process = new JcrExecutionProcess(processNode); try { // we currently only deal with single agents @@ -57,6 +57,7 @@ public class ProcessController { SlcAgent slcAgent = agentFactory.getAgent(agentUuid); slcAgent.process(process); } + return process; } catch (Exception e) { if (!process.getStatus().equals(ExecutionProcess.ERROR)) process.setStatus(ExecutionProcess.ERROR); diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java index a5d8676de..fc0e4f1c8 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessBuilderPage.java @@ -71,6 +71,7 @@ import org.eclipse.ui.forms.editor.FormPage; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.ScrolledForm; +/** Definition of the process. */ public class ProcessBuilderPage extends FormPage implements SlcNames { public final static String ID = "processBuilderPage"; // private final static Log log = diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java index b6df3548e..b00b41298 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessEditor.java @@ -1,5 +1,8 @@ package org.argeo.slc.client.ui.editors; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.UUID; import javax.jcr.Node; @@ -11,7 +14,10 @@ import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; 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; @@ -21,7 +27,8 @@ import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.forms.editor.FormEditor; -public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { +public class ProcessEditor extends FormEditor implements + ExecutionProcessNotifier, SlcTypes, SlcNames { public final static String ID = ClientUiPlugin.ID + ".processEditor"; private Session session; @@ -31,6 +38,8 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { private ProcessBuilderPage builderPage; private ProcessLogPage logPage; + private ExecutionModulesManager modulesManager; + @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { @@ -96,7 +105,11 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { } doSave(null); try { - processController.process(processNode); + ExecutionProcess process = processController.process(processNode); + Map properties = new HashMap(); + properties.put(ExecutionModulesManager.SLC_PROCESS_ID, + process.getUuid()); + modulesManager.registerProcessNotifier(this, properties); } catch (Exception e) { Error.show("Execution of " + processNode + " failed", e); } @@ -142,6 +155,14 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { return false; } + public void updateStatus(ExecutionProcess process, String oldStatus, + String newStatus) { + } + + public void addSteps(ExecutionProcess process, List steps) { + logPage.addSteps(steps); + } + /** Expects one session per editor. */ public void setSession(Session session) { this.session = session; @@ -151,4 +172,8 @@ public class ProcessEditor extends FormEditor implements SlcTypes, SlcNames { this.processController = processController; } + public void setModulesManager(ExecutionModulesManager modulesManager) { + this.modulesManager = modulesManager; + } + } diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessLogPage.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessLogPage.java index f50b5b99f..00ad3e48e 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessLogPage.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessLogPage.java @@ -1,13 +1,110 @@ package org.argeo.slc.client.ui.editors; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.List; + +import org.argeo.slc.execution.ExecutionStep; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.editor.FormEditor; import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.FormToolkit; public class ProcessLogPage extends FormPage { - public final static String ID = "processLogrPage"; + public final static String ID = "processLogPage"; + + private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); + + /** Where the log is displayed. */ + private Text text; + /** + * Stores logs received before the text was shown. TODO : rather store in in + * JCR and reads it from there. + */ + private StringBuffer beforeTextInit = new StringBuffer(""); public ProcessLogPage(FormEditor editor) { super(editor, ID, "Log"); } + @Override + public synchronized void createPartControl(Composite parent) { + // bypass createFormContent + FormToolkit tk = getEditor().getToolkit(); + // parent.setLayout(new FillLayout()); + text = tk.createText(parent, "", SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL); + text.setEditable(false); + + // transfer the existing buffer the first time + if (beforeTextInit.length() > 0) { + text.append(beforeTextInit.toString()); + // clear buffer + beforeTextInit.setLength(0); + } + + } + +// @Override +// protected synchronized void createFormContent(IManagedForm mf) { +// ScrolledForm form = mf.getForm(); +// form.setExpandHorizontal(true); +// form.setExpandVertical(true); +// // form.setText("Log"); +// FillLayout mainLayout = new FillLayout(); +// form.getBody().setLayout(mainLayout); +// +// FormToolkit tk = getManagedForm().getToolkit(); +// text = tk.createText(form.getBody(), "", SWT.MULTI | SWT.H_SCROLL +// | SWT.V_SCROLL); +// text.setEditable(false); +// // transfer the existing buffer the first time +// if (beforeTextInit.length() > 0) { +// text.append(beforeTextInit.toString()); +// // clear buffer +// beforeTextInit.setLength(0); +// } +// } + + public synchronized void addSteps(List steps) { + final StringBuffer buf = new StringBuffer(""); + for (ExecutionStep step : steps) { + buf.append(dateFormat.format(step.getTimestamp())); + buf.append(' '); + if (step.getType().equals(ExecutionStep.PHASE_START)) { + buf.append("## START ").append(step.getLog()); + buf.append('\n'); + } else if (step.getType().equals(ExecutionStep.PHASE_END)) { + buf.append("## END ").append(step.getLog()); + buf.append("\n"); + } else { + buf.append(step.getLog()); + } + } + + if (text != null) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + text.append(buf.toString()); + } + }); + } else + beforeTextInit.append(buf); + } + + @Override + public Control getPartControl() { + return text; + } + + @Override + public void setFocus() { + if (text != null) + text.setFocus(); + } + } 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 06c05248b..3b5613921 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 @@ -17,6 +17,7 @@ package org.argeo.slc.core.execution; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -28,9 +29,10 @@ 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.process.RealizedFlow; import org.argeo.slc.process.SlcExecutionNotifier; -import org.argeo.slc.process.SlcExecutionStep; /** Provides the base feature of an execution module manager. */ @SuppressWarnings("deprecation") @@ -41,7 +43,10 @@ public abstract class AbstractExecutionModulesManager implements private List slcExecutionNotifiers = new ArrayList(); - private ThreadGroup processesThreadGroup = new ThreadGroup("Processes"); + private List filteredNotifiers = Collections + .synchronizedList(new ArrayList()); + + private ThreadGroup processesThreadGroup = new ThreadGroup("SLC Processes"); protected abstract ExecutionFlow findExecutionFlow(String moduleName, String moduleVersion, String flowName); @@ -79,30 +84,50 @@ public abstract class AbstractExecutionModulesManager implements // } - public void dispatchUpdateStatus(ExecutionProcess slcExecution, + public void dispatchUpdateStatus(ExecutionProcess process, String oldStatus, String newStatus) { + // generic notifiers (notified of everything) for (Iterator it = getSlcExecutionNotifiers() .iterator(); it.hasNext();) { - it.next().updateStatus(slcExecution, oldStatus, newStatus); + it.next().updateStatus(process, oldStatus, 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 dispatchAddStep(ExecutionProcess slcExecution, - SlcExecutionStep step) { - List steps = new ArrayList(); - steps.add(step); + public void dispatchAddSteps(ExecutionProcess process, + List steps) { for (Iterator it = getSlcExecutionNotifiers() .iterator(); it.hasNext();) { - it.next().addSteps(slcExecution, steps); + it.next().addSteps(process, 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 setSlcExecutionNotifiers( List slcExecutionNotifiers) { this.slcExecutionNotifiers = slcExecutionNotifiers; } - public List getSlcExecutionNotifiers() { + private List getSlcExecutionNotifiers() { return slcExecutionNotifiers; } @@ -110,4 +135,45 @@ public abstract class AbstractExecutionModulesManager implements return processesThreadGroup; } + protected class FilteredNotifier { + private final ExecutionProcessNotifier notifier; + private final String processId; + + public FilteredNotifier(ExecutionProcessNotifier notifier, + Map properties) { + super(); + this.notifier = notifier; + 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) { + return notifier.equals(obj); + } + + public ExecutionProcessNotifier getNotifier() { + return notifier; + } + + } } 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 52040fd50..b42726dd4 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 @@ -19,8 +19,8 @@ package org.argeo.slc.core.execution; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.process.RealizedFlow; -import org.argeo.slc.process.SlcExecutionStep; /** Thread of a single execution */ public class ExecutionThread extends Thread { @@ -51,8 +51,8 @@ public class ExecutionThread extends Thread { .getFlowDescriptor(); String flowName = executionFlowDescriptor.getName(); - dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.PHASE_START, - "Flow " + flowName)); + dispatchAddStep(new ExecutionStep(ExecutionStep.PHASE_START, "Flow " + + flowName)); try { String autoUpgrade = System @@ -68,17 +68,17 @@ public class ExecutionThread extends Thread { // TODO: re-throw exception ? String msg = "Execution of flow " + flowName + " failed."; log.error(msg, e); - dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.ERROR, msg - + " " + e.getMessage())); + dispatchAddStep(new ExecutionStep(ExecutionStep.ERROR, msg + " " + + e.getMessage())); processThread.notifyError(); } finally { processThread.flowCompleted(); - dispatchAddStep(new SlcExecutionStep(SlcExecutionStep.PHASE_END, - "Flow " + flowName)); + dispatchAddStep(new ExecutionStep(ExecutionStep.PHASE_END, "Flow " + + flowName)); } } - private void dispatchAddStep(SlcExecutionStep step) { + private void dispatchAddStep(ExecutionStep step) { processThread.getProcessThreadGroup().dispatchAddStep(step); } 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 61e8c2f2a..6f0143f0f 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 @@ -16,8 +16,12 @@ package org.argeo.slc.core.execution; +import java.util.ArrayList; +import java.util.List; + import org.argeo.slc.execution.ExecutionModulesManager; import org.argeo.slc.execution.ExecutionProcess; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.process.SlcExecutionStep; @@ -38,11 +42,20 @@ public class ProcessThreadGroup extends ThreadGroup { // return processThread.getSlcProcess(); // } - public void dispatchAddStep(SlcExecutionStep step) { + public void dispatchAddStep(ExecutionStep step) { + // legacy ExecutionProcess slcProcess = processThread.getProcess(); if (slcProcess instanceof SlcExecution) - ((SlcExecution) slcProcess).getSteps().add(step); - executionModulesManager.dispatchAddStep(slcProcess, step); + ((SlcExecution) slcProcess).getSteps().add((SlcExecutionStep) step); + + List steps = new ArrayList(); + steps.add(step); + dispatchAddSteps(steps); + } + + public void dispatchAddSteps(List steps) { + ExecutionProcess slcProcess = processThread.getProcess(); + executionModulesManager.dispatchAddSteps(slcProcess, steps); } } 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 4400a18f2..88a8b2bfe 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 @@ -17,6 +17,7 @@ package org.argeo.slc.execution; import java.util.List; +import java.util.Map; import org.argeo.slc.deploy.ModulesManager; import org.argeo.slc.process.RealizedFlow; @@ -24,6 +25,9 @@ import org.argeo.slc.process.SlcExecutionStep; /** Provides access to the execution modules */ public interface ExecutionModulesManager extends ModulesManager { + /** Used to filter event notified to an execution notifier. */ + public static String SLC_PROCESS_ID = "slc.process.id"; + /** @return a full fledged module descriptor. */ public ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version); @@ -45,5 +49,13 @@ public interface ExecutionModulesManager extends ModulesManager { String oldStatus, String newStatus); /** Notify that a step was added in an {@link ExecutionProcess} */ - public void dispatchAddStep(ExecutionProcess process, SlcExecutionStep step); + 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); } 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 index 9bfdaf98f..e2466ec81 100644 --- 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 @@ -2,13 +2,19 @@ package org.argeo.slc.execution; import java.util.List; -import org.argeo.slc.process.SlcExecutionStep; - +/** + * Implementations of this interface can be notified of events related to + * process execution. + */ public interface ExecutionProcessNotifier { - public void addSteps(ExecutionProcess process, - List additionalSteps); - + /** + * 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/ExecutionStep.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionStep.java new file mode 100644 index 000000000..df2d805a8 --- /dev/null +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionStep.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * 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.io.Serializable; +import java.util.Date; + +/** + * An atomic step to be notified in during an {@link ExecutionProcess}. Can be a + * log or the start/end of a phase, etc. + */ +public class ExecutionStep implements Serializable { + private static final long serialVersionUID = 798640526532912161L; + + // public final static String START = "START"; + // public final static String END = "END"; + public final static String PHASE_START = "PHASE_START"; + public final static String PHASE_END = "PHASE_END"; + public final static String ERROR = "ERROR"; + public final static String WARNING = "WARNING"; + public final static String INFO = "INFO"; + public final static String DEBUG = "DEBUG"; + public final static String TRACE = "TRACE"; + + // TODO make the fields final and private when we don't need POJO support + // anymore (that + // is when SlcExecutionStep is removed) + protected String type; + protected String thread; + protected Date timestamp; + protected String log; + + /** Empty constructor */ + public ExecutionStep() { + thread = Thread.currentThread().getName(); + } + + /** Creates a step at the current date of type INFO */ + public ExecutionStep(String log) { + this(new Date(), INFO, log); + } + + /** Creates a step at the current date */ + public ExecutionStep(String type, String log) { + this(new Date(), type, log); + } + + /** Creates a step of the given type. */ + public ExecutionStep(Date timestamp, String type, String log) { + this(timestamp, type, log, Thread.currentThread().getName()); + } + + public ExecutionStep(Date timestamp, String type, String log, String thread) { + this.type = type; + this.timestamp = timestamp; + this.thread = thread; + this.log = addLog(log); + } + + public String getType() { + return type; + } + + public Date getTimestamp() { + return timestamp; + } + + public String getThread() { + return thread; + } + + /** + * Return the string that should be stored in the log field. Can be null if + * another mechanism is used to store log lines. + */ + protected String addLog(String log) { + return log; + } + + public String getLog() { + return log; + } + + @Override + public String toString() { + return "Execution step, thread=" + thread + ", type=" + type; + } + +} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java index 58f9d01a0..cc1dc7f2d 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionStep.java @@ -16,39 +16,28 @@ package org.argeo.slc.process; -import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.StringTokenizer; import java.util.UUID; +import org.argeo.slc.execution.ExecutionStep; + /** * An atomic step to be notified in during an {@link SlcExecution}. Can be a log * or the start/end of a phase, etc. + * + * @deprecated use {@link ExecutionStep} instead */ -public class SlcExecutionStep implements Serializable { +public class SlcExecutionStep extends ExecutionStep { private static final long serialVersionUID = -7308643628104726471L; - public final static String START = "START"; - public final static String END = "END"; - public final static String PHASE_START = "PHASE_START"; - public final static String PHASE_END = "PHASE_END"; - public final static String ERROR = "ERROR"; - public final static String WARNING = "WARNING"; - public final static String INFO = "INFO"; - public final static String DEBUG = "DEBUG"; - public final static String TRACE = "TRACE"; - private String uuid = UUID.randomUUID().toString(); - private String type; - private String thread; - private Date timestamp = new Date(); private List logLines = new ArrayList(); /** Empty constructor */ public SlcExecutionStep() { - thread = Thread.currentThread().getName(); } /** Creates a step at the current date of type INFO */ @@ -68,10 +57,7 @@ public class SlcExecutionStep implements Serializable { public SlcExecutionStep(Date timestamp, String type, String log, String thread) { - this.type = type; - this.timestamp = timestamp; - this.thread = thread; - addLog(log); + super(timestamp, type, log, thread); } public String getUuid() { @@ -82,26 +68,14 @@ public class SlcExecutionStep implements Serializable { this.uuid = uuid; } - public String getType() { - return type; - } - public void setType(String type) { this.type = type; } - public Date getTimestamp() { - return timestamp; - } - public void setTimestamp(Date begin) { this.timestamp = begin; } - public String getThread() { - return thread; - } - public void setThread(String thread) { this.thread = thread; } @@ -114,13 +88,17 @@ public class SlcExecutionStep implements Serializable { this.logLines = logLines; } - public void addLog(String log) { + protected String addLog(String log) { + if (logLines == null) + logLines = new ArrayList(); + if (log == null) - return; + return null; StringTokenizer st = new StringTokenizer(log, "\n"); while (st.hasMoreTokens()) logLines.add(removeNonXmlChars(st.nextToken())); + return null; } /** diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/log4j/SlcExecutionAppender.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/log4j/SlcExecutionAppender.java index a40c98e5a..880aefef1 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/log4j/SlcExecutionAppender.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/log4j/SlcExecutionAppender.java @@ -26,7 +26,7 @@ import org.apache.log4j.PatternLayout; import org.apache.log4j.spi.LoggingEvent; import org.argeo.slc.core.execution.ExecutionThread; import org.argeo.slc.core.execution.ProcessThreadGroup; -import org.argeo.slc.process.SlcExecutionStep; +import org.argeo.slc.execution.ExecutionStep; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -96,20 +96,20 @@ public class SlcExecutionAppender extends AppenderSkeleton implements final String type; if (event.getLevel().equals(Level.ERROR) || event.getLevel().equals(Level.FATAL)) - type = SlcExecutionStep.ERROR; + type = ExecutionStep.ERROR; else if (event.getLevel().equals(Level.WARN)) - type = SlcExecutionStep.WARNING; + type = ExecutionStep.WARNING; else if (event.getLevel().equals(Level.INFO)) - type = SlcExecutionStep.INFO; + type = ExecutionStep.INFO; else if (event.getLevel().equals(Level.DEBUG)) - type = SlcExecutionStep.DEBUG; + type = ExecutionStep.DEBUG; else if (event.getLevel().equals(Level.TRACE)) - type = SlcExecutionStep.TRACE; + type = ExecutionStep.TRACE; else - type = SlcExecutionStep.INFO; + type = ExecutionStep.INFO; - SlcExecutionStep step = new SlcExecutionStep(new Date(event - .getTimeStamp()), type, layout.format(event)); + ExecutionStep step = new ExecutionStep(new Date( + event.getTimeStamp()), type, layout.format(event)); try { dispatching.set(true);