diff --git a/compute/src/main/java/org/jclouds/ssh/ExecResponse.java b/compute/src/main/java/org/jclouds/ssh/ExecResponse.java index 7e9ed9d85b..1ca0e9fbf8 100644 --- a/compute/src/main/java/org/jclouds/ssh/ExecResponse.java +++ b/compute/src/main/java/org/jclouds/ssh/ExecResponse.java @@ -25,10 +25,12 @@ public class ExecResponse { private final String error; private final String output; + private final int exitCode; - public ExecResponse(String output, String error) { + public ExecResponse(String output, String error, int exitCode) { this.output = output; this.error = error; + this.exitCode = exitCode; } public String getError() { @@ -41,7 +43,7 @@ public class ExecResponse { @Override public String toString() { - return "ExecResponse [error=" + error + ", output=" + output + "]"; + return "ExecResponse [output=" + output + ", error=" + error + ", exitCode=" + exitCode + "]"; } @Override @@ -49,6 +51,7 @@ public class ExecResponse { final int prime = 31; int result = 1; result = prime * result + ((error == null) ? 0 : error.hashCode()); + result = prime * result + exitCode; result = prime * result + ((output == null) ? 0 : output.hashCode()); return result; } @@ -67,6 +70,8 @@ public class ExecResponse { return false; } else if (!error.equals(other.error)) return false; + if (exitCode != other.exitCode) + return false; if (output == null) { if (other.output != null) return false; @@ -75,4 +80,8 @@ public class ExecResponse { return true; } + public int getExitCode() { + return exitCode; + } + } \ No newline at end of file diff --git a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java index ff962cfe5b..f117e81e8d 100644 --- a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java +++ b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java @@ -204,7 +204,7 @@ public class JschSshClient implements SshClient { try { executor.connect(); return new ExecResponse(Utils.toStringAndClose(executor.getInputStream()), error - .toString()); + .toString(), executor.getExitStatus()); } catch (Exception e) { throw new SshException(String.format("%s@%s:%d: Error executing command: ", username, host.getHostAddress(), port, command), e); diff --git a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java index 43f59f50fa..e0be7aeba8 100644 --- a/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java +++ b/extensions/ssh/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java @@ -82,7 +82,7 @@ public class JschSshClientLiveTest { public ExecResponse exec(String command) { if (command.equals("hostname")) { try { - return new ExecResponse(InetAddress.getLocalHost().getHostName(), ""); + return new ExecResponse(InetAddress.getLocalHost().getHostName(), "", 0); } catch (UnknownHostException e) { throw new RuntimeException(e); } diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index 1052cb819c..6af124be4b 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -39,6 +39,7 @@ import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.Template; import org.jclouds.compute.options.RunNodeOptions; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.tools.ant.logging.config.AntLoggingModule; import com.google.common.base.Function; @@ -74,9 +75,11 @@ public class ComputeTaskUtils { try { Properties props = new Properties(); props.putAll(projectProvider.get().getProperties()); - return new ComputeServiceContextFactory().createContext(from, ImmutableSet - .of((Module) new AntLoggingModule(projectProvider.get(), - ComputeServiceConstants.COMPUTE_LOGGER)), props); + return new ComputeServiceContextFactory().createContext(from, ImmutableSet.of( + (Module) new AntLoggingModule(projectProvider.get(), + ComputeServiceConstants.COMPUTE_LOGGER), + new JschSshClientModule()), + props); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java index c3fde5d4ef..dfde7d853b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java @@ -136,13 +136,16 @@ public class VCloudComputeService implements ComputeService, VCloudComputeClient ssh.put(scriptName, new ByteArrayInputStream(script)); ssh.exec("chmod 755 " + scriptName); if (node.getCredentials().account.equals("root")) { - logger.debug(ssh.exec("./" + scriptName).toString()); + logger.debug(">> running %s as %s", scriptName, node.getCredentials().account); + logger.debug("<< complete(%d)", ssh.exec("./" + scriptName).getExitCode()); } else if (isKeyBasedAuth(node)) { - logger.debug(ssh.exec("sudo ./" + scriptName).toString()); + logger.debug(">> running sudo %s as %s", scriptName, node.getCredentials().account); + logger.debug("<< complete(%d)", ssh.exec("sudo ./" + scriptName).getExitCode()); } else { - logger.debug(ssh.exec( + logger.debug(">> running sudo -S %s as %s", scriptName, node.getCredentials().account); + logger.debug("<< complete(%d)", ssh.exec( String.format("echo %s|sudo -S ./%s", node.getCredentials().key, scriptName)) - .toString()); + .getExitCode()); } } finally { if (ssh != null)