You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by an...@apache.org on 2014/03/24 23:19:29 UTC
git commit: updated refs/heads/4.4 to b3ad419
Repository: cloudstack
Updated Branches:
refs/heads/4.4 d56b45a1c -> b3ad4192d
fixed ssh execution log
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b3ad4192
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b3ad4192
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b3ad4192
Branch: refs/heads/4.4
Commit: b3ad4192dd5611a1f4c1602388988831e8409df2
Parents: d56b45a
Author: Anthony Xu <an...@citrix.com>
Authored: Mon Mar 24 15:18:50 2014 -0700
Committer: Anthony Xu <an...@citrix.com>
Committed: Mon Mar 24 15:18:50 2014 -0700
----------------------------------------------------------------------
utils/src/com/cloud/utils/ssh/SSHCmdHelper.java | 33 ++++++++++++++------
1 file changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b3ad4192/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java b/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
index 10ada37..4a440ef 100644
--- a/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
+++ b/utils/src/com/cloud/utils/ssh/SSHCmdHelper.java
@@ -110,17 +110,28 @@ public class SSHCmdHelper {
InputStream stderr = sshSession.getStderr();
byte[] buffer = new byte[8192];
+ StringBuffer sbResult = new StringBuffer();
+
+ int currentReadBytes = 0;
while (true) {
if (stdout == null || stderr == null) {
throw new SshException("stdout or stderr of ssh session is null");
}
-
if ((stdout.available() == 0) && (stderr.available() == 0)) {
- int conditions = sshSession.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 120000);
+ int conditions = sshSession.waitForCondition(ChannelCondition.STDOUT_DATA
+ | ChannelCondition.STDERR_DATA | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS,
+ 120000);
if ((conditions & ChannelCondition.TIMEOUT) != 0) {
- s_logger.info("Timeout while waiting for data from peer.");
- break;
+ String msg = "Timed out in waiting SSH execution result";
+ s_logger.error(msg);
+ throw new Exception(msg);
+ }
+
+ if ((conditions & ChannelCondition.EXIT_STATUS) != 0) {
+ if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {
+ break;
+ }
}
if ((conditions & ChannelCondition.EOF) != 0) {
@@ -131,19 +142,21 @@ public class SSHCmdHelper {
}
while (stdout.available() > 0) {
- stdout.read(buffer);
+ currentReadBytes = stdout.read(buffer);
+ sbResult.append(new String(buffer, 0, currentReadBytes));
}
while (stderr.available() > 0) {
- stderr.read(buffer);
+ currentReadBytes = stderr.read(buffer);
+ sbResult.append(new String(buffer, 0, currentReadBytes));
}
}
- if (buffer[0] != 0)
- s_logger.debug(cmd + " output:" + new String(buffer));
+ String result = sbResult.toString();
+ if (result != null && !result.isEmpty())
+ s_logger.debug(cmd + " output:" + result);
- Thread.sleep(1000);
- return sshSession.getExitStatus();
+ return sshSession.getExitStatus();
} catch (Exception e) {
s_logger.debug("Ssh executed failed", e);
throw new SshException("Ssh executed failed " + e.getMessage());