mirror of https://github.com/apache/jclouds.git
Do not try to connect to ssh if already connected
This commit is contained in:
parent
449c6d8d84
commit
7dc73ee0bf
|
@ -71,7 +71,9 @@ public class SudoAwareInitManager {
|
|||
public ExecResponse refreshAndRunAction(String action) {
|
||||
checkState(ssh != null, "please call init() before invoking call");
|
||||
try {
|
||||
ssh.connect();
|
||||
if (!ssh.isConnected()) {
|
||||
ssh.connect();
|
||||
}
|
||||
return runAction(action);
|
||||
} finally {
|
||||
if (ssh != null)
|
||||
|
|
|
@ -61,6 +61,8 @@ public interface SshClient {
|
|||
|
||||
void disconnect();
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
void put(String path, String contents);
|
||||
|
||||
}
|
||||
|
|
|
@ -339,11 +339,17 @@ public class JschSshClient implements SshClient {
|
|||
return toString;
|
||||
}
|
||||
|
||||
@Override
|
||||
@PreDestroy
|
||||
public void disconnect() {
|
||||
sessionConnection.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return sessionConnection.getSession().isConnected();
|
||||
}
|
||||
|
||||
protected ConnectionWithStreams<ChannelExec> execConnection(final String command) {
|
||||
checkNotNull(command, "command");
|
||||
return new ConnectionWithStreams<ChannelExec>() {
|
||||
|
|
|
@ -86,6 +86,10 @@ public class JschSshClientLiveTest {
|
|||
public void disconnect() {
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Payload get(String path) {
|
||||
if (path.equals("/etc/passwd")) {
|
||||
return Payloads.newStringPayload("root");
|
||||
|
|
|
@ -410,6 +410,15 @@ public class SshjSshClient implements SshClient {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
try {
|
||||
return sshClientConnection.getSSHClient().isConnected();
|
||||
} catch (Exception e) {
|
||||
throw Throwables.propagate(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected Connection<Session> execConnection() {
|
||||
|
||||
return new Connection<Session>() {
|
||||
|
|
|
@ -75,6 +75,10 @@ public class SshjSshClientLiveTest {
|
|||
public void disconnect() {
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Payload get(String path) {
|
||||
if (path.equals("/etc/passwd")) {
|
||||
return Payloads.newStringPayload("root");
|
||||
|
|
Loading…
Reference in New Issue