Repository: airavata
Updated Branches:
  refs/heads/master 5c389b977 -> 1090843d7


move the cluster connection out. AIRAVATA-1456

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

Branch: refs/heads/master
Commit: 1090843d77a4301d83474ac7c96346cd4d1a2c41
Parents: 5c389b9
Author: raminder <ramin...@apache.org>
Authored: Sun Sep 28 10:57:27 2014 -0400
Committer: raminder <ramin...@apache.org>
Committed: Sun Sep 28 10:57:27 2014 -0400

----------------------------------------------------------------------
 .../gfac/gsissh/handler/GSISSHInputHandler.java | 48 ++++++++++----------
 1 file changed, 25 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/1090843d/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
----------------------------------------------------------------------
diff --git 
a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
 
b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
index 039ddab..2f0bb70 100644
--- 
a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
+++ 
b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/handler/GSISSHInputHandler.java
@@ -64,8 +64,21 @@ public class GSISSHInputHandler extends 
AbstractRecoverableHandler {
         DataTransferDetails detail = new DataTransferDetails();
         TransferStatus status = new TransferStatus();
         StringBuffer data = new StringBuffer("|");
+        Cluster cluster = null;
+        
         try {
-            String pluginData = GFacUtils.getPluginData(jobExecutionContext, 
this.getClass().getName());
+               if 
(jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)
 != null) {
+                cluster = ((GSISecurityContext) 
jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+            } else {
+                cluster = ((GSISecurityContext) 
jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
+            }
+            if (cluster == null) {
+                throw new GFacException("Security context is not set 
properly");
+            } else {
+                log.info("Successfully retrieved the Security Context");
+            }
+           
+               String pluginData = 
GFacUtils.getPluginData(jobExecutionContext, this.getClass().getName());
             if (pluginData != null) {
                 try {
                     oldIndex = 
Integer.parseInt(pluginData.split("\\|")[0].trim());
@@ -107,7 +120,7 @@ public class GSISSHInputHandler extends 
AbstractRecoverableHandler {
                         ((URIParameterType) 
actualParameter.getType()).setValue(oldFiles.get(index));
                         data.append(oldFiles.get(index++)).append(","); // we 
get already transfered file and increment the index
                     } else {
-                        String stageInputFile = 
stageInputFiles(jobExecutionContext, paramValue);
+                        String stageInputFile = stageInputFiles(cluster, 
jobExecutionContext, paramValue);
                         ((URIParameterType) 
actualParameter.getType()).setValue(stageInputFile);
                         StringBuffer temp = new 
StringBuffer(data.append(stageInputFile).append(",").toString());
                         status.setTransferState(TransferState.UPLOAD);
@@ -126,7 +139,7 @@ public class GSISSHInputHandler extends 
AbstractRecoverableHandler {
                             newFiles.add(oldFiles.get(index));
                             data.append(oldFiles.get(index++)).append(",");
                         } else {
-                            String stageInputFiles = 
stageInputFiles(jobExecutionContext, paramValueEach);
+                            String stageInputFiles = stageInputFiles(cluster, 
jobExecutionContext, paramValueEach);
                             status.setTransferState(TransferState.UPLOAD);
                             detail.setTransferStatus(status);
                             detail.setTransferDescription("Input Data Staged: 
" + stageInputFiles);
@@ -153,22 +166,19 @@ public class GSISSHInputHandler extends 
AbstractRecoverableHandler {
                 throw new GFacHandlerException("Error persisting status", e1, 
e1.getLocalizedMessage());
             }
             throw new GFacHandlerException("Error while input File Staging", 
e, e.getLocalizedMessage());
+        }finally {
+            if (cluster != null) {
+                try {
+                    cluster.disconnect();
+                } catch (SSHApiException e) {
+                    throw new GFacHandlerException(e.getMessage(), e);
+                }
+            }
         }
         jobExecutionContext.setInMessageContext(inputNew);
     }
 
-    private static String stageInputFiles(JobExecutionContext 
jobExecutionContext, String paramValue) throws IOException, GFacException {
-        Cluster cluster = null;
-        if 
(jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)
 != null) {
-            cluster = ((GSISecurityContext) 
jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
-        } else {
-            cluster = ((GSISecurityContext) 
jobExecutionContext.getSecurityContext(GSISecurityContext.GSI_SECURITY_CONTEXT)).getPbsCluster();
-        }
-        if (cluster == null) {
-            throw new GFacException("Security context is not set properly");
-        } else {
-            log.info("Successfully retrieved the Security Context");
-        }
+    private static String stageInputFiles(Cluster cluster, JobExecutionContext 
jobExecutionContext, String paramValue) throws IOException, GFacException {
         ApplicationDeploymentDescriptionType app = 
jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType();
         int i = paramValue.lastIndexOf(File.separator);
         String substring = paramValue.substring(i + 1);
@@ -195,14 +205,6 @@ public class GSISSHInputHandler extends 
AbstractRecoverableHandler {
             return targetFile;
         } catch (Exception e) {
             throw new GFacHandlerException("Error while input File Staging", 
e, e.getLocalizedMessage());
-        }finally {
-            if (cluster != null) {
-                try {
-                    cluster.disconnect();
-                } catch (SSHApiException e) {
-                    throw new GFacHandlerException(e.getMessage(), e);
-                }
-            }
         }
     }
 

Reply via email to