Committed by
Gerrit Code Review
Cosmetic stc fixes.
Change-Id: I00fdc0135c22c4b3872fe31dcf7d786af005f035
Showing
3 changed files
with
7 additions
and
12 deletions
| ... | @@ -25,7 +25,6 @@ import java.util.Map; | ... | @@ -25,7 +25,6 @@ import java.util.Map; |
| 25 | import java.util.Set; | 25 | import java.util.Set; |
| 26 | import java.util.concurrent.CountDownLatch; | 26 | import java.util.concurrent.CountDownLatch; |
| 27 | import java.util.concurrent.ExecutorService; | 27 | import java.util.concurrent.ExecutorService; |
| 28 | -import java.util.function.Function; | ||
| 29 | import java.util.regex.Matcher; | 28 | import java.util.regex.Matcher; |
| 30 | import java.util.regex.Pattern; | 29 | import java.util.regex.Pattern; |
| 31 | 30 | ||
| ... | @@ -54,7 +53,6 @@ public class Coordinator { | ... | @@ -54,7 +53,6 @@ public class Coordinator { |
| 54 | 53 | ||
| 55 | private static final Pattern PROP_ERE = Pattern.compile("^@stc ([a-zA-Z0-9_.]+)=(.*$)"); | 54 | private static final Pattern PROP_ERE = Pattern.compile("^@stc ([a-zA-Z0-9_.]+)=(.*$)"); |
| 56 | private final Map<String, String> properties = Maps.newConcurrentMap(); | 55 | private final Map<String, String> properties = Maps.newConcurrentMap(); |
| 57 | - private final Function<String, String> substitutor = this::substitute; | ||
| 58 | 56 | ||
| 59 | private final Set<StepProcessListener> listeners = Sets.newConcurrentHashSet(); | 57 | private final Set<StepProcessListener> listeners = Sets.newConcurrentHashSet(); |
| 60 | private File logDir; | 58 | private File logDir; |
| ... | @@ -224,7 +222,7 @@ public class Coordinator { | ... | @@ -224,7 +222,7 @@ public class Coordinator { |
| 224 | executeRoots(group); | 222 | executeRoots(group); |
| 225 | } else { | 223 | } else { |
| 226 | executor.execute(new StepProcessor(step, logDir, delegate, | 224 | executor.execute(new StepProcessor(step, logDir, delegate, |
| 227 | - substitutor)); | 225 | + substitute(step.command()))); |
| 228 | } | 226 | } |
| 229 | } else if (directive == SKIP) { | 227 | } else if (directive == SKIP) { |
| 230 | if (step instanceof Group) { | 228 | if (step instanceof Group) { | ... | ... |
| ... | @@ -23,7 +23,6 @@ import java.io.IOException; | ... | @@ -23,7 +23,6 @@ import java.io.IOException; |
| 23 | import java.io.InputStream; | 23 | import java.io.InputStream; |
| 24 | import java.io.InputStreamReader; | 24 | import java.io.InputStreamReader; |
| 25 | import java.io.PrintWriter; | 25 | import java.io.PrintWriter; |
| 26 | -import java.util.function.Function; | ||
| 27 | 26 | ||
| 28 | import static java.lang.String.format; | 27 | import static java.lang.String.format; |
| 29 | import static org.onlab.stc.Coordinator.Status.FAILED; | 28 | import static org.onlab.stc.Coordinator.Status.FAILED; |
| ... | @@ -46,7 +45,6 @@ class StepProcessor implements Runnable { | ... | @@ -46,7 +45,6 @@ class StepProcessor implements Runnable { |
| 46 | 45 | ||
| 47 | private Process process; | 46 | private Process process; |
| 48 | private StepProcessListener delegate; | 47 | private StepProcessListener delegate; |
| 49 | - private Function<String, String> substitutor; | ||
| 50 | 48 | ||
| 51 | /** | 49 | /** |
| 52 | * Creates a process monitor. | 50 | * Creates a process monitor. |
| ... | @@ -54,19 +52,18 @@ class StepProcessor implements Runnable { | ... | @@ -54,19 +52,18 @@ class StepProcessor implements Runnable { |
| 54 | * @param step step or group to be executed | 52 | * @param step step or group to be executed |
| 55 | * @param logDir directory where step process log should be stored | 53 | * @param logDir directory where step process log should be stored |
| 56 | * @param delegate process lifecycle listener | 54 | * @param delegate process lifecycle listener |
| 57 | - * @param substitutor function to substitute var reference in command | 55 | + * @param command actual command to execute |
| 58 | */ | 56 | */ |
| 59 | StepProcessor(Step step, File logDir, StepProcessListener delegate, | 57 | StepProcessor(Step step, File logDir, StepProcessListener delegate, |
| 60 | - Function<String, String> substitutor) { | 58 | + String command) { |
| 61 | this.step = step; | 59 | this.step = step; |
| 62 | this.logDir = logDir; | 60 | this.logDir = logDir; |
| 63 | this.delegate = delegate; | 61 | this.delegate = delegate; |
| 64 | - this.substitutor = substitutor; | 62 | + this.command = command; |
| 65 | } | 63 | } |
| 66 | 64 | ||
| 67 | @Override | 65 | @Override |
| 68 | public void run() { | 66 | public void run() { |
| 69 | - command = substitutor != null ? substitutor.apply(command()) : command(); | ||
| 70 | delegate.onStart(step, command); | 67 | delegate.onStart(step, command); |
| 71 | int code = execute(); | 68 | int code = execute(); |
| 72 | boolean ignoreCode = step.env() != null && step.env.equals(IGNORE_CODE); | 69 | boolean ignoreCode = step.env() != null && step.env.equals(IGNORE_CODE); |
| ... | @@ -81,7 +78,7 @@ class StepProcessor implements Runnable { | ... | @@ -81,7 +78,7 @@ class StepProcessor implements Runnable { |
| 81 | */ | 78 | */ |
| 82 | private int execute() { | 79 | private int execute() { |
| 83 | try (PrintWriter pw = new PrintWriter(logFile())) { | 80 | try (PrintWriter pw = new PrintWriter(logFile())) { |
| 84 | - process = Runtime.getRuntime().exec(command); | 81 | + process = Runtime.getRuntime().exec(command()); |
| 85 | processOutput(pw); | 82 | processOutput(pw); |
| 86 | 83 | ||
| 87 | // Wait for the process to complete and get its exit code. | 84 | // Wait for the process to complete and get its exit code. |
| ... | @@ -107,7 +104,7 @@ class StepProcessor implements Runnable { | ... | @@ -107,7 +104,7 @@ class StepProcessor implements Runnable { |
| 107 | return format("%s %s %s %s", launcher, | 104 | return format("%s %s %s %s", launcher, |
| 108 | step.env() != null ? step.env() : "-", | 105 | step.env() != null ? step.env() : "-", |
| 109 | step.cwd() != null ? step.cwd() : "-", | 106 | step.cwd() != null ? step.cwd() : "-", |
| 110 | - step.command()); | 107 | + command); |
| 111 | } | 108 | } |
| 112 | 109 | ||
| 113 | /** | 110 | /** | ... | ... |
| ... | @@ -51,7 +51,7 @@ public class StepProcessorTest { | ... | @@ -51,7 +51,7 @@ public class StepProcessorTest { |
| 51 | @Test | 51 | @Test |
| 52 | public void basics() { | 52 | public void basics() { |
| 53 | Step step = new Step("foo", "ls " + DIR.getAbsolutePath(), null, null, null); | 53 | Step step = new Step("foo", "ls " + DIR.getAbsolutePath(), null, null, null); |
| 54 | - StepProcessor processor = new StepProcessor(step, DIR, delegate, null); | 54 | + StepProcessor processor = new StepProcessor(step, DIR, delegate, step.command()); |
| 55 | processor.run(); | 55 | processor.run(); |
| 56 | assertTrue("should be started", delegate.started); | 56 | assertTrue("should be started", delegate.started); |
| 57 | assertTrue("should be stopped", delegate.stopped); | 57 | assertTrue("should be stopped", delegate.stopped); | ... | ... |
-
Please register or login to post a comment