Thomas Vachuska
Committed by Gerrit Code Review

Adding support for SKIPPED state to STC.

Change-Id: I5a90bedb6272f0bb1d76f0bc5e19e67e8d05eec8
......@@ -23,5 +23,5 @@
<dependency name="Archetypes" requires="Setup"/>
<import file="${ONOS_ROOT}/tools/test/scenarios/wrapup.xml"/>
<dependency name="Wrapup" requires="~Archetypes,Setup"/>
<dependency name="Wrapup" requires="~Archetypes,~Setup"/>
</scenario>
......
......@@ -204,19 +204,20 @@ public class Coordinator {
*/
private synchronized void execute(Step step) {
Directive directive = nextAction(step);
if (directive == RUN || directive == SKIP) {
if (directive == RUN) {
store.markStarted(step);
if (step instanceof Group) {
Group group = (Group) step;
delegate.onStart(group);
if (directive == RUN) {
executeRoots(group);
} else {
group.children().forEach(child -> delegate.onCompletion(child, 1));
}
executeRoots(group);
} else {
executor.execute(new StepProcessor(step, directive == SKIP,
logDir, delegate));
executor.execute(new StepProcessor(step, logDir, delegate));
}
} else if (directive == SKIP) {
if (step instanceof Group) {
Group group = (Group) step;
group.children().forEach(child -> delegate.onCompletion(child, SKIPPED));
delegate.onCompletion(step, SKIPPED);
}
}
}
......@@ -237,7 +238,8 @@ public class Coordinator {
Status depStatus = store.getStatus(dependency.dst());
if (depStatus == WAITING || depStatus == IN_PROGRESS) {
return NOOP;
} else if (depStatus == FAILED && !dependency.isSoft()) {
} else if ((depStatus == FAILED || depStatus == SKIPPED) &&
!dependency.isSoft()) {
return SKIP;
}
}
......@@ -270,7 +272,7 @@ public class Coordinator {
failed = failed || status == FAILED;
}
if (done) {
delegate.onCompletion(group, failed ? 1 : 0);
delegate.onCompletion(group, failed ? FAILED : SUCCEEDED);
}
}
}
......@@ -296,9 +298,9 @@ public class Coordinator {
}
@Override
public void onCompletion(Step step, int exitCode) {
store.markComplete(step, exitCode == 0 ? SUCCEEDED : FAILED);
listeners.forEach(listener -> listener.onCompletion(step, exitCode));
public void onCompletion(Step step, Status status) {
store.markComplete(step, status);
listeners.forEach(listener -> listener.onCompletion(step, status));
executeSucessors(step);
latch.countDown();
}
......
......@@ -172,8 +172,8 @@ public final class Main {
}
@Override
public void onCompletion(Step step, int exitCode) {
logStatus(currentTimeMillis(), step.name(), exitCode == 0 ? SUCCEEDED : FAILED);
public void onCompletion(Step step, Status status) {
logStatus(currentTimeMillis(), step.name(), status);
}
@Override
......
......@@ -31,10 +31,10 @@ public interface StepProcessListener {
/**
* Indicates that process step has completed.
*
* @param step subject step
* @param exitCode step process exit exitCode
* @param step subject step
* @param status step completion status
*/
default void onCompletion(Step step, int exitCode) {
default void onCompletion(Step step, Coordinator.Status status) {
}
/**
......
......@@ -15,6 +15,8 @@
*/
package org.onlab.stc;
import org.onlab.stc.Coordinator.Status;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
......@@ -23,6 +25,8 @@ import java.io.InputStreamReader;
import java.io.PrintWriter;
import static java.lang.String.format;
import static org.onlab.stc.Coordinator.Status.FAILED;
import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
import static org.onlab.stc.Coordinator.print;
/**
......@@ -30,12 +34,12 @@ import static org.onlab.stc.Coordinator.print;
*/
class StepProcessor implements Runnable {
private static final String IGNORE_CODE = "~";
private static final int FAIL = -1;
static String launcher = "stc-launcher ";
private final Step step;
private final boolean skip;
private final File logDir;
private Process process;
......@@ -45,25 +49,22 @@ class StepProcessor implements Runnable {
* Creates a process monitor.
*
* @param step step or group to be executed
* @param skip indicates the process should not actually execute
* @param logDir directory where step process log should be stored
* @param delegate process lifecycle listener
*/
StepProcessor(Step step, boolean skip, File logDir, StepProcessListener delegate) {
StepProcessor(Step step, File logDir, StepProcessListener delegate) {
this.step = step;
this.skip = skip;
this.logDir = logDir;
this.delegate = delegate;
}
@Override
public void run() {
int code = FAIL;
delegate.onStart(step);
if (!skip) {
code = execute();
}
delegate.onCompletion(step, code);
int code = execute();
boolean ignoreCode = step.env() != null && step.env.equals(IGNORE_CODE);
Status status = ignoreCode || code == 0 ? SUCCEEDED : FAILED;
delegate.onCompletion(step, status);
}
/**
......
......@@ -68,8 +68,8 @@ public class CoordinatorTest {
}
@Override
public void onCompletion(Step step, int exitCode) {
print("< %s: %s", step.name(), exitCode == 0 ? "completed" : "failed");
public void onCompletion(Step step, Coordinator.Status status) {
print("< %s: %s", step.name(), status == Coordinator.Status.SUCCEEDED ? "completed" : "failed");
}
@Override
......
......@@ -23,7 +23,9 @@ import org.onlab.util.Tools;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
/**
* Test of the step processor.
......@@ -46,31 +48,19 @@ public class StepProcessorTest {
}
@Test
public void executed() {
public void basics() {
Step step = new Step("foo", "ls /tmp", null, null, null);
StepProcessor processor = new StepProcessor(step, false, DIR, delegate);
StepProcessor processor = new StepProcessor(step, DIR, delegate);
processor.run();
assertTrue("should be started", delegate.started);
assertTrue("should have output", delegate.output);
assertTrue("should be stopped", delegate.stopped);
assertEquals("incorrect code", 0, delegate.code);
}
@Test
public void skipped() {
Step step = new Step("foo", "ls /tmp", null, null, null);
StepProcessor processor = new StepProcessor(step, true, DIR, delegate);
processor.run();
assertTrue("should be started", delegate.started);
assertFalse("should have output", delegate.output);
assertTrue("should be stopped", delegate.stopped);
assertEquals("incorrect code", -1, delegate.code);
assertEquals("incorrect status", SUCCEEDED, delegate.status);
}
private class Listener implements StepProcessListener {
private int code = 123;
private Coordinator.Status status;
private boolean started, stopped, output;
@Override
......@@ -79,9 +69,9 @@ public class StepProcessorTest {
}
@Override
public void onCompletion(Step step, int exitCode) {
public void onCompletion(Step step, Coordinator.Status status) {
stopped = true;
this.code = exitCode;
this.status = status;
}
@Override
......