Thomas Vachuska
Committed by Gerrit Code Review

Cosmetic stc fixes.

Change-Id: I00fdc0135c22c4b3872fe31dcf7d786af005f035
......@@ -25,7 +25,6 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -54,7 +53,6 @@ public class Coordinator {
private static final Pattern PROP_ERE = Pattern.compile("^@stc ([a-zA-Z0-9_.]+)=(.*$)");
private final Map<String, String> properties = Maps.newConcurrentMap();
private final Function<String, String> substitutor = this::substitute;
private final Set<StepProcessListener> listeners = Sets.newConcurrentHashSet();
private File logDir;
......@@ -224,7 +222,7 @@ public class Coordinator {
executeRoots(group);
} else {
executor.execute(new StepProcessor(step, logDir, delegate,
substitutor));
substitute(step.command())));
}
} else if (directive == SKIP) {
if (step instanceof Group) {
......
......@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.function.Function;
import static java.lang.String.format;
import static org.onlab.stc.Coordinator.Status.FAILED;
......@@ -46,7 +45,6 @@ class StepProcessor implements Runnable {
private Process process;
private StepProcessListener delegate;
private Function<String, String> substitutor;
/**
* Creates a process monitor.
......@@ -54,19 +52,18 @@ class StepProcessor implements Runnable {
* @param step step or group to be executed
* @param logDir directory where step process log should be stored
* @param delegate process lifecycle listener
* @param substitutor function to substitute var reference in command
* @param command actual command to execute
*/
StepProcessor(Step step, File logDir, StepProcessListener delegate,
Function<String, String> substitutor) {
String command) {
this.step = step;
this.logDir = logDir;
this.delegate = delegate;
this.substitutor = substitutor;
this.command = command;
}
@Override
public void run() {
command = substitutor != null ? substitutor.apply(command()) : command();
delegate.onStart(step, command);
int code = execute();
boolean ignoreCode = step.env() != null && step.env.equals(IGNORE_CODE);
......@@ -81,7 +78,7 @@ class StepProcessor implements Runnable {
*/
private int execute() {
try (PrintWriter pw = new PrintWriter(logFile())) {
process = Runtime.getRuntime().exec(command);
process = Runtime.getRuntime().exec(command());
processOutput(pw);
// Wait for the process to complete and get its exit code.
......@@ -107,7 +104,7 @@ class StepProcessor implements Runnable {
return format("%s %s %s %s", launcher,
step.env() != null ? step.env() : "-",
step.cwd() != null ? step.cwd() : "-",
step.command());
command);
}
/**
......
......@@ -51,7 +51,7 @@ public class StepProcessorTest {
@Test
public void basics() {
Step step = new Step("foo", "ls " + DIR.getAbsolutePath(), null, null, null);
StepProcessor processor = new StepProcessor(step, DIR, delegate, null);
StepProcessor processor = new StepProcessor(step, DIR, delegate, step.command());
processor.run();
assertTrue("should be started", delegate.started);
assertTrue("should be stopped", delegate.stopped);
......