From 4acaa7b3eca85263027b1a8875cf0b1971a09c7b Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 5 Jul 2011 15:17:01 +0000 Subject: [PATCH] Improve logging Logging in UI git-svn-id: https://svn.argeo.org/slc/trunk@4667 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../slc/core/test/tree/TreeTestResult.java | 26 +++++++++++++++---- .../msg/process/SlcExecutionStepsRequest.java | 15 ++++++----- .../impl/SlcExecutionServiceAdapter.java | 3 ++- .../argeo/slc/execution/ExecutionStep.java | 7 +++-- .../argeo/slc/process/SlcExecutionStep.java | 5 +++- .../slc/jms/JmsSlcExecutionNotifier.java | 3 ++- .../xml/process/FileSlcExecutionNotifier.java | 13 +++++----- .../WebServiceSlcExecutionNotifier.java | 20 +++++--------- .../unit/process/SlcExecutionTestUtils.java | 21 +++++++++------ 9 files changed, 69 insertions(+), 44 deletions(-) diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java index c27da2f76..16eb26c53 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResult.java @@ -70,6 +70,8 @@ public class TreeTestResult implements TestResult, StructureAware, // TODO is it really necessary closeDate == null ? private Boolean isClosed = false; + private Boolean cache = true; + private transient List> listeners = new Vector>(); /** Sets the list of listeners. */ @@ -88,15 +90,18 @@ public class TreeTestResult implements TestResult, StructureAware, if (currentPath == null) throw new SlcException("No current path set."); - PartSubList subList = resultParts.get(currentPath); - if (subList == null) { - subList = new PartSubList(); - resultParts.put(currentPath, subList); + if (cache) { + PartSubList subList = resultParts.get(currentPath); + if (subList == null) { + subList = new PartSubList(); + resultParts.put(currentPath, subList); + } + subList.getParts().add(part); } + if (part instanceof TestRunAware && currentTestRun != null) { ((TestRunAware) part).notifyTestRun(currentTestRun); } - subList.getParts().add(part); // notify listeners synchronized (listeners) { @@ -115,6 +120,9 @@ public class TreeTestResult implements TestResult, StructureAware, public void notifyCurrentPath(StructureRegistry registry, TreeSPath path) { + if (!cache) + return; + if (registry != null) { for (TreeSPath p : path.getHierarchyAsList()) { if (!elements.containsKey(p)) { @@ -305,4 +313,12 @@ public class TreeTestResult implements TestResult, StructureAware, this.strictChecks = strictChecks; } + /** + * Whether information should be stored in thsi object or simply forwarded + * to teh listeners. + */ + public void setCache(Boolean cache) { + this.cache = cache; + } + } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java index 7492338ef..5ae4727fa 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/msg/process/SlcExecutionStepsRequest.java @@ -19,8 +19,8 @@ package org.argeo.slc.msg.process; import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import java.util.Vector; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.process.SlcExecutionStep; public class SlcExecutionStepsRequest implements Serializable { @@ -33,16 +33,17 @@ public class SlcExecutionStepsRequest implements Serializable { } public SlcExecutionStepsRequest(String slcExecutionUuid, - List steps) { + List steps) { this.slcExecutionUuid = slcExecutionUuid; - this.steps = steps; + for (ExecutionStep step : steps) { + this.steps.add((SlcExecutionStep) step); + } } - public SlcExecutionStepsRequest(String slcExecutionUuid, - SlcExecutionStep step) { + public SlcExecutionStepsRequest(String slcExecutionUuid, ExecutionStep step) { this.slcExecutionUuid = slcExecutionUuid; - List steps = new Vector(); - steps.add(step); + List steps = new ArrayList(); + steps.add((SlcExecutionStep) step); this.steps = steps; } diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/SlcExecutionServiceAdapter.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/SlcExecutionServiceAdapter.java index b1abbeef1..6c8b48cd6 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/SlcExecutionServiceAdapter.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/SlcExecutionServiceAdapter.java @@ -21,6 +21,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.execution.ExecutionProcess; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.msg.process.SlcExecutionStatusRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; import org.argeo.slc.process.SlcExecutionNotifier; @@ -47,7 +48,7 @@ public class SlcExecutionServiceAdapter implements SlcExecutionNotifier { } public void addSteps(ExecutionProcess slcExecution, - List additionalSteps) { + List additionalSteps) { SlcExecutionStepsRequest req = new SlcExecutionStepsRequest( slcExecution.getUuid(), additionalSteps); try { 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 index df2d805a8..4cabeec09 100644 --- 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 @@ -26,8 +26,6 @@ import java.util.Date; 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"; @@ -36,6 +34,11 @@ public class ExecutionStep implements Serializable { public final static String DEBUG = "DEBUG"; public final static String TRACE = "TRACE"; + /** @deprecated*/ + public final static String START = "START"; + /** @deprecated*/ + public final static String END = "END"; + // TODO make the fields final and private when we don't need POJO support // anymore (that // is when SlcExecutionStep is removed) 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 cc1dc7f2d..2d81d2f5a 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 @@ -59,6 +59,8 @@ public class SlcExecutionStep extends ExecutionStep { String thread) { super(timestamp, type, log, thread); } + + public String getUuid() { return uuid; @@ -88,7 +90,8 @@ public class SlcExecutionStep extends ExecutionStep { this.logLines = logLines; } - protected String addLog(String log) { + /** public for legacy reasons*/ + public String addLog(String log) { if (logLines == null) logLines = new ArrayList(); diff --git a/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsSlcExecutionNotifier.java b/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsSlcExecutionNotifier.java index 8a13f5d7d..7cb5906f4 100644 --- a/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsSlcExecutionNotifier.java +++ b/runtime/org.argeo.slc.support.activemq/src/main/java/org/argeo/slc/jms/JmsSlcExecutionNotifier.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.slc.UnsupportedException; import org.argeo.slc.execution.ExecutionProcess; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.msg.process.SlcExecutionStatusRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; import org.argeo.slc.process.SlcExecution; @@ -51,7 +52,7 @@ public class JmsSlcExecutionNotifier implements SlcExecutionNotifier { } public void addSteps(ExecutionProcess slcExecution, - List additionalSteps) { + List additionalSteps) { SlcExecutionStepsRequest req = new SlcExecutionStepsRequest( slcExecution.getUuid(), additionalSteps); convertAndSend(req); diff --git a/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/xml/process/FileSlcExecutionNotifier.java b/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/xml/process/FileSlcExecutionNotifier.java index 93cde8ddf..8b110ecd2 100644 --- a/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/xml/process/FileSlcExecutionNotifier.java +++ b/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/xml/process/FileSlcExecutionNotifier.java @@ -29,21 +29,22 @@ import org.argeo.slc.SlcException; import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.process.SlcExecutionNotifier; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.process.SlcExecutionStep; import org.springframework.oxm.Marshaller; /** @deprecated Probably not even working anymore */ public class FileSlcExecutionNotifier implements SlcExecutionNotifier { -// private final static SimpleDateFormat sdf = new SimpleDateFormat( -// "yyyyMMdd-HHmmss"); -// -// private String basePath; + // private final static SimpleDateFormat sdf = new SimpleDateFormat( + // "yyyyMMdd-HHmmss"); + // + // private String basePath; private Marshaller marshaller; private Map uuidToDir = new HashMap(); public void addSteps(ExecutionProcess slcExecution, - List additionalSteps) { + List additionalSteps) { writeSlcExecution(slcExecution); } @@ -80,7 +81,7 @@ public class FileSlcExecutionNotifier implements SlcExecutionNotifier { } public void setBasePath(String basePath) { - //this.basePath = basePath; + // this.basePath = basePath; } public void setMarshaller(Marshaller marshaller) { diff --git a/runtime/org.argeo.slc.support.ws.client/src/main/java/org/argeo/slc/ws/process/WebServiceSlcExecutionNotifier.java b/runtime/org.argeo.slc.support.ws.client/src/main/java/org/argeo/slc/ws/process/WebServiceSlcExecutionNotifier.java index f6b9dee14..133033bd1 100644 --- a/runtime/org.argeo.slc.support.ws.client/src/main/java/org/argeo/slc/ws/process/WebServiceSlcExecutionNotifier.java +++ b/runtime/org.argeo.slc.support.ws.client/src/main/java/org/argeo/slc/ws/process/WebServiceSlcExecutionNotifier.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.argeo.slc.msg.process.SlcExecutionRequest; import org.argeo.slc.msg.process.SlcExecutionStatusRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.process.SlcExecutionNotifier; @@ -40,7 +41,7 @@ public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier { private Boolean cannotConnect = false; public void newExecution(ExecutionProcess process) { - SlcExecution slcExecution= (SlcExecution)process; + SlcExecution slcExecution = (SlcExecution) process; if (cannotConnect) return; @@ -78,7 +79,7 @@ public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier { public void updateStatus(ExecutionProcess process, String oldStatus, String newStatus) { - SlcExecution slcExecution= (SlcExecution)process; + SlcExecution slcExecution = (SlcExecution) process; if (cannotConnect) return; @@ -97,20 +98,13 @@ public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier { } public void addSteps(ExecutionProcess process, - List additionalSteps) { - SlcExecution slcExecution= (SlcExecution)process; + List additionalSteps) { + SlcExecution slcExecution = (SlcExecution) process; if (cannotConnect) return; - SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(); - req.setSlcExecutionUuid(slcExecution.getUuid()); - req.setSteps(additionalSteps); - if (log.isTraceEnabled()) { - for (SlcExecutionStep step : additionalSteps) { - log.trace("Step " + step.getUuid() + ": " + step); - } - } - + SlcExecutionStepsRequest req = new SlcExecutionStepsRequest( + slcExecution.getUuid(), additionalSteps); try { WebServiceUtils.marshalSendAndReceive(template, req); if (log.isTraceEnabled()) diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java index 65f3ec1dd..d621d2921 100644 --- a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java +++ b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.UUID; import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionStep; import org.argeo.slc.process.RealizedFlow; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.process.SlcExecutionStep; @@ -89,17 +90,21 @@ public abstract class SlcExecutionTestUtils { } - public static void assertSlcExecutionStep(SlcExecutionStep expected, - SlcExecutionStep reached) { + public static void assertSlcExecutionStep(ExecutionStep expected, + ExecutionStep reached) { assertNotNull(reached); - assertEquals(expected.getUuid(), reached.getUuid()); assertEquals(expected.getType(), reached.getType()); assertDateSec(expected.getTimestamp(), reached.getTimestamp()); - assertEquals(expected.getLogLines().size(), reached.getLogLines() - .size()); - for (int i = 0; i < expected.getLogLines().size(); i++) { - assertEquals(expected.getLogLines().get(i), reached.getLogLines() - .get(i)); + if (expected instanceof SlcExecutionStep) { + SlcExecutionStep slcExpected = (SlcExecutionStep)expected; + SlcExecutionStep slcReached = (SlcExecutionStep)reached; + assertEquals(slcExpected.getUuid(), slcReached.getUuid()); + assertEquals(slcExpected.getLogLines().size(), slcReached.getLogLines() + .size()); + for (int i = 0; i < slcExpected.getLogLines().size(); i++) { + assertEquals(slcExpected.getLogLines().get(i), slcReached + .getLogLines().get(i)); + } } } -- 2.39.2