mirror of https://github.com/apache/jclouds.git
Issue 129: tidied up ssh output for ant/compute commands
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2714 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
bc1c1fd793
commit
56116204df
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue