Repository: airavata
Updated Branches:
  refs/heads/develop 22ae02616 -> 2a30f80e6


Retry 3 times if jsch channel issue with execute command


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/38c64239
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/38c64239
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/38c64239

Branch: refs/heads/develop
Commit: 38c64239e436b619c39416864dca15caea9a854d
Parents: 7781ff8
Author: Shameera Rathnayaka <[email protected]>
Authored: Fri Apr 22 15:27:45 2016 -0400
Committer: Shameera Rathnayaka <[email protected]>
Committed: Fri Apr 22 15:27:45 2016 -0400

----------------------------------------------------------------------
 .../airavata/gfac/impl/HPCRemoteCluster.java    | 31 ++++++++++++++------
 1 file changed, 22 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/38c64239/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
----------------------------------------------------------------------
diff --git 
a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
 
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
index cdd0500..725b6d0 100644
--- 
a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
+++ 
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
@@ -310,18 +310,31 @@ public class HPCRemoteCluster extends 
AbstractRemoteCluster{
 
        private void executeCommand(CommandInfo commandInfo, CommandOutput 
commandOutput) throws SSHApiException {
                String command = commandInfo.getCommand();
+               int retryCount = 0;
                ChannelExec channelExec = null;
                try {
-                       session = Factory.getSSHSession(authenticationInfo, 
serverInfo);
-                       channelExec = ((ChannelExec) 
session.openChannel("exec"));
-                       channelExec.setCommand(command);
-                   channelExec.setInputStream(null);
-                       
channelExec.setErrStream(commandOutput.getStandardError());
-                       log.info("Executing command {}", 
commandInfo.getCommand());
-                       channelExec.connect();
-                       commandOutput.onOutput(channelExec);
+                       while (retryCount < MAX_RETRY_COUNT) {
+                               retryCount++;
+                               try {
+                                       session = 
Factory.getSSHSession(authenticationInfo, serverInfo);
+                                       channelExec = ((ChannelExec) 
session.openChannel("exec"));
+                                       channelExec.setCommand(command);
+                                       channelExec.setInputStream(null);
+                                       
channelExec.setErrStream(commandOutput.getStandardError());
+                                       channelExec.connect();
+                                       log.info("Executing command {}", 
commandInfo.getCommand());
+                                       commandOutput.onOutput(channelExec);
+                                       break; // exit from while loop
+                               } catch (JSchException e) {
+                                       if (retryCount == MAX_RETRY_COUNT) {
+                                               log.error("Retry count " + 
MAX_RETRY_COUNT + " exceeded for executing command : " + command, e);
+                                               throw e;
+                                       }
+                                       log.error("Issue with jsch, Retry 
executing command : " + command, e);
+                               }
+                       }
                } catch (JSchException | AiravataException e) {
-                       throw new SSHApiException("Unable to execute command - 
", e);
+                       throw new SSHApiException("Unable to execute command - 
" + command, e);
                } finally {
                        //Only disconnecting the channel, session can be reused
                        if (channelExec != null) {

Reply via email to