From 81391595dca425ae58e2294898f09f11d9a32dbc Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Tue, 22 Sep 2015 12:49:09 -0700 Subject: bringing src to commit tag 65d551b50e782b0c1ea76c1a9ed1c5a801a5a7e4 Change-Id: Ib2da78962eaef856f418636c31b0f5c84286244f --- framework/src/onos/utils/stc/bin/stc | 2 +- framework/src/onos/utils/stc/pom.xml | 2 +- .../src/main/java/org/onlab/stc/Coordinator.java | 9 ++++++++ .../stc/src/main/java/org/onlab/stc/Main.java | 24 ++++++++++++++++----- .../src/main/java/org/onlab/stc/ScenarioStore.java | 25 ++++++++++++++++++++++ 5 files changed, 55 insertions(+), 7 deletions(-) (limited to 'framework/src/onos/utils/stc') diff --git a/framework/src/onos/utils/stc/bin/stc b/framework/src/onos/utils/stc/bin/stc index 23affc4a..241822c5 100755 --- a/framework/src/onos/utils/stc/bin/stc +++ b/framework/src/onos/utils/stc/bin/stc @@ -5,7 +5,7 @@ STC_ROOT=${STC_ROOT:-$(dirname $0)/..} cd $STC_ROOT -VER=1.3.0-SNAPSHOT +VER=1.4.0-SNAPSHOT PATH=$PWD/bin:$PATH diff --git a/framework/src/onos/utils/stc/pom.xml b/framework/src/onos/utils/stc/pom.xml index a3f96430..a71dcfe3 100644 --- a/framework/src/onos/utils/stc/pom.xml +++ b/framework/src/onos/utils/stc/pom.xml @@ -22,7 +22,7 @@ org.onosproject onlab-utils - 1.3.0-SNAPSHOT + 1.4.0-SNAPSHOT ../pom.xml diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java index 8e3aad5b..ef1c31f3 100644 --- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java +++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java @@ -108,6 +108,15 @@ public class Coordinator { // FIXME: implement this } + /** + * Returns number of milliseconds it took to execute. + * + * @return number of millis elapsed during the run + */ + public long duration() { + return store.endTime() - store.startTime(); + } + /** * Returns a list of steps that match the specified list of patterns. * diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java index 09b89456..bc10ec7a 100644 --- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java +++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Main.java @@ -44,11 +44,12 @@ public final class Main { private static final String GREEN = "\u001B[32;1m"; private static final String BLUE = "\u001B[36m"; - private static final String SUCCESS_SUMMARY = "%sPassed! %d steps succeeded%s"; + private static final String SUCCESS_SUMMARY = + "%s %sPassed! %d steps succeeded%s"; private static final String MIXED_SUMMARY = "%s%d steps succeeded; %s%d steps failed; %s%d steps skipped%s"; - private static final String FAILURE_SUMMARY = "%sFailed! " + MIXED_SUMMARY; - private static final String ABORTED_SUMMARY = "%sAborted! " + MIXED_SUMMARY; + private static final String FAILURE_SUMMARY = "%s %sFailed! " + MIXED_SUMMARY; + private static final String ABORTED_SUMMARY = "%s %sAborted! " + MIXED_SUMMARY; private boolean isReported = false; @@ -180,6 +181,7 @@ public final class Main { private void processList() { coordinator.getRecords() .forEach(event -> logStatus(event.time(), event.name(), event.status(), event.command())); + printSummary(0, false); System.exit(0); } @@ -201,14 +203,15 @@ public final class Main { if (!isReported) { isReported = true; Set steps = coordinator.getSteps(); + String duration = formatDuration((int) (coordinator.duration() / 1_000)); int count = steps.size(); if (exitCode == 0) { - print(SUCCESS_SUMMARY, color(SUCCEEDED), count, color(null)); + print(SUCCESS_SUMMARY, duration, color(SUCCEEDED), count, color(null)); } else { long success = steps.stream().filter(s -> coordinator.getStatus(s) == SUCCEEDED).count(); long failed = steps.stream().filter(s -> coordinator.getStatus(s) == FAILED).count(); long skipped = steps.stream().filter(s -> coordinator.getStatus(s) == SKIPPED).count(); - print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY, + print(isAborted ? ABORTED_SUMMARY : FAILURE_SUMMARY, duration, color(FAILED), color(SUCCEEDED), success, color(FAILED), failed, color(SKIPPED), skipped, color(null)); } @@ -281,6 +284,17 @@ public final class Main { } } + // Formats time duration + private static String formatDuration(int totalSeconds) { + int seconds = totalSeconds % 60; + int totalMinutes = totalSeconds / 60; + int minutes = totalMinutes % 60; + int hours = totalMinutes / 60; + return hours > 0 ? + String.format("%d:%02d:%02d", hours, minutes, seconds) : + String.format("%d:%02d", minutes, seconds); + } + // Shutdown hook to report status even when aborted. private class ShutdownHook extends Thread { @Override diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java index d37222b1..7313462e 100644 --- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java +++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/ScenarioStore.java @@ -43,6 +43,9 @@ class ScenarioStore { private final List events = Lists.newArrayList(); private final Map statusMap = Maps.newConcurrentMap(); + private long startTime = Long.MAX_VALUE; + private long endTime = Long.MIN_VALUE; + /** * Creates a new scenario store for the specified process flow. * @@ -69,6 +72,8 @@ class ScenarioStore { PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile); cfg.clear(); cfg.save(); + startTime = Long.MAX_VALUE; + endTime = Long.MIN_VALUE; } catch (ConfigurationException e) { print("Unable to store file %s", storeFile); } @@ -156,6 +161,8 @@ class ScenarioStore { private synchronized void add(StepEvent event) { events.add(event); statusMap.put(event.name(), event.status()); + startTime = Math.min(startTime, event.time()); + endTime = Math.max(endTime, event.time()); } /** @@ -198,4 +205,22 @@ class ScenarioStore { } } + /** + * Returns the scenario run start time. + * + * @return start time in mills since start of epoch + */ + public long startTime() { + return startTime; + } + + /** + * Returns the scenario run end time or current time if the scenario + * is still running. + * + * @return end time (or current time) in mills since start of epoch + */ + public long endTime() { + return endTime > 0 ? endTime : System.currentTimeMillis(); + } } -- cgit 1.2.3-korg