From fcc0461d09ab7effe519e3cd60e8a637d49b6d49 Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Sat, 28 Dec 2019 00:10:17 -0500 Subject: [PATCH] fix exception handling --- .../rancher/RancherNodeExecutorPlugin.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/bioraft/rundeck/rancher/RancherNodeExecutorPlugin.java b/src/main/java/com/bioraft/rundeck/rancher/RancherNodeExecutorPlugin.java index 4bdbaa7..ee4203a 100644 --- a/src/main/java/com/bioraft/rundeck/rancher/RancherNodeExecutorPlugin.java +++ b/src/main/java/com/bioraft/rundeck/rancher/RancherNodeExecutorPlugin.java @@ -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 { @@ -131,16 +138,12 @@ private String baseName(String[] command, Map 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(); }