Skip to content

Commit

Permalink
fix exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl DeBisschop committed Dec 28, 2019
1 parent 3a5a4da commit fcc0461
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ public NodeExecutorResult executeCommand(final ExecutionContext context, final S
return NodeExecutorResultImpl.createFailure(StepFailureReason.Interrupted, e.getMessage(), node);
}

String[] pidFile = this.readLogFile(temp + ".pid", url).split(" +");
String[] pidFile;
try {
pidFile = this.readLogFile(temp + ".pid", url).split(" +");
} catch (IOException e) {
return NodeExecutorResultImpl.createFailure(StepFailureReason.IOFailure, e.getMessage(), node);
} catch (InterruptedException e) {
return NodeExecutorResultImpl.createFailure(StepFailureReason.Interrupted, e.getMessage(), node);
}
if (pidFile.length > 1 && Integer.parseInt(pidFile[1]) == 0) {
return NodeExecutorResultImpl.createSuccess(node);
} else {
Expand Down Expand Up @@ -131,16 +138,12 @@ private String baseName(String[] command, Map<String, String> jobContext) {
* @param file The full path to the file.
* @param url The URL for executing jobs on the desired container.
* @return The contents of the file as a string.
* @throws InterruptedException
* @throws IOException
*/
private String readLogFile(String file, String url) {
private String readLogFile(String file, String url) throws IOException, InterruptedException {
StringBuilder output = new StringBuilder();
try {
RancherWebSocketListener.getFile(url, accessKey, secretKey, output, file);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
RancherWebSocketListener.getFile(url, accessKey, secretKey, output, file);
return output.toString();
}

Expand Down

0 comments on commit fcc0461

Please sign in to comment.