aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src
diff options
context:
space:
mode:
authorDriptaroop Das <driptaroop.das@in.ibm.com>2019-03-18 00:37:21 +0530
committerPatrick Brady <patrick.brady@att.com>2019-03-19 06:26:00 +0000
commita699370368538fc5af70e2e34427fb93a1e25eb6 (patch)
treeee683ad0f12009b775c4dfe00b473e0a7aee12eb /appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src
parent5892287c4a8cdb9211a413d6be107e7150305269 (diff)
SshConnectionSshd - Sonar Fix
SshConnectionSshd - Sonar Fix Issue-ID: APPC-1543 Change-Id: Id02cd65f4dfeebb43c4eb637d50b649c684397c7 Signed-off-by: Driptaroop Das <driptaroop.das@in.ibm.com>
Diffstat (limited to 'appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src')
-rw-r--r--appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java20
1 files changed, 7 insertions, 13 deletions
diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java
index 299ad7755..ee446084b 100644
--- a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java
+++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshConnectionSshd.java
@@ -173,28 +173,22 @@ class SshConnectionSshd implements SshConnection {
}
private int execCommand(String cmd, OutputStream out, OutputStream err, boolean usePty) {
- try {
+ try(ChannelExec client = clientSession.createExecChannel(cmd)) {
if (logger.isDebugEnabled()) {
logger.debug("SSH: executing command");
}
- ChannelExec client = clientSession.createExecChannel(cmd);
client.setUsePty(usePty); // use pseudo-tty?
client.setOut(out);
client.setErr(err);
OpenFuture openFuture = client.open();
int exitStatus;
- try {
- client.waitFor(Arrays.asList(ClientChannelEvent.CLOSED), timeout);
- openFuture.verify();
- Integer exitStatusI = client.getExitStatus();
- if (exitStatusI == null) {
- throw new SshException("Error executing command [" + cmd + "] over SSH [" + username + "@" + host
- + ":" + port + "]. Operation timed out.");
- }
- exitStatus = exitStatusI;
- } finally {
- client.close(false);
+ client.waitFor(Arrays.asList(ClientChannelEvent.CLOSED), timeout);
+ openFuture.verify();
+ Integer exitStatusI = client.getExitStatus();
+ if (exitStatusI == null) {
+ throw new SshException("Error executing command [" + cmd + "] over SSH [" + username + "@" + host + ":" + port + "]. Operation timed out.");
}
+ exitStatus = exitStatusI;
return exitStatus;
} catch (RuntimeException e) {
throw e;