Skip to content
Snippets Groups Projects
Commit 6ee4a32a authored by René Schöne's avatar René Schöne
Browse files

small fixes to coordinator

- inheritIO for docker compose
- wait shortly for script to check for failures
- use return value of start to set status to "failedStart" if it is false
parent 6549a67f
No related branches found
No related tags found
No related merge requests found
...@@ -68,23 +68,11 @@ aspect Manipulation { ...@@ -68,23 +68,11 @@ aspect Manipulation {
return true; return true;
} }
System.out.println("Starting " + Arrays.toString(args)); System.out.println("Starting " + Arrays.toString(args));
ProcessBuilder builder = new ProcessBuilder(args); ProcessBuilder builder = new ProcessBuilder(args).inheritIO();
Process process = builder.start(); Process process = builder.start();
process.waitFor(); process.waitFor();
try (java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()))) {
System.out.println("Out of " + java.util.Arrays.toString(args) + ":\n" + reader.lines().collect(java.util.stream.Collectors.joining("\n")));
} catch (IOException e) {
e.printStackTrace();
}
try (java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getErrorStream()))) {
System.out.println("Err of " + java.util.Arrays.toString(args) + ":\n" + reader.lines().collect(java.util.stream.Collectors.joining("\n")));
} catch (IOException e) {
e.printStackTrace();
}
return process.exitValue() == 0; return process.exitValue() == 0;
} }
return false; return false;
...@@ -104,7 +92,13 @@ aspect Manipulation { ...@@ -104,7 +92,13 @@ aspect Manipulation {
} }
Process process = builder.start(); Process process = builder.start();
// Do not wait for process to be finished
// check if process has crashed within a short time
if (process.waitFor(2, java.util.concurrent.TimeUnit.SECONDS) && process.exitValue() != 0) {
process.getErrorStream().transferTo(System.err);
process.getInputStream().transferTo(System.out);
return false;
}
return true; return true;
} }
......
...@@ -101,8 +101,8 @@ public class MainCoordinator implements Callable<Integer> { ...@@ -101,8 +101,8 @@ public class MainCoordinator implements Callable<Integer> {
commandTopic = "coordinator/" + comp.getName(); commandTopic = "coordinator/" + comp.getName();
mainHandler.newConnection(commandTopic, bytes -> { mainHandler.newConnection(commandTopic, bytes -> {
try { try {
comp.getStartStrategy().start(); boolean successfullyStarted = comp.getStartStrategy().start();
comp.setStatus("ready"); comp.setStatus(successfullyStarted ? "ready" : "failedStart");
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
comp.setStatus("failedStart"); comp.setStatus("failedStart");
e.printStackTrace(); e.printStackTrace();
...@@ -127,7 +127,10 @@ public class MainCoordinator implements Callable<Integer> { ...@@ -127,7 +127,10 @@ public class MainCoordinator implements Callable<Integer> {
} }
} }
if (!alreadyRunning.contains(comp) && !comp.getStartAsUp()) { if (!alreadyRunning.contains(comp) && !comp.getStartAsUp()) {
comp.getStartStrategy().start(); if (!comp.getStartStrategy().start()) {
// component has failed to start
comp.setStatus("failedStart");
}
if (comp.hasAutoSetStatus()) { if (comp.hasAutoSetStatus()) {
scheduleAutoSetStatus(comp); scheduleAutoSetStatus(comp);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment