You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2014/09/29 20:08:06 UTC

git commit: Re-using gsi/ssh connections without creating them everytime for a given user/host/port

Repository: airavata
Updated Branches:
  refs/heads/master 94f5bcb7f -> 9018dc8b6


Re-using gsi/ssh connections without creating them everytime for a given user/host/port


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

Branch: refs/heads/master
Commit: 9018dc8b64994308597c85b3b64b790982ca990a
Parents: 94f5bcb
Author: lahiru <la...@apache.org>
Authored: Mon Sep 29 14:07:28 2014 -0400
Committer: lahiru <la...@apache.org>
Committed: Mon Sep 29 14:07:28 2014 -0400

----------------------------------------------------------------------
 .../client/samples/CreateLaunchExperiment.java  |  2 +-
 .../gfac/gsissh/util/GFACGSISSHUtils.java       | 61 ++++++++++++--------
 .../airavata/gfac/ssh/util/GFACSSHUtils.java    | 26 ++++++++-
 3 files changed, 63 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/9018dc8b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
index bbfc873..fcbec41 100644
--- a/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
+++ b/airavata-api/airavata-client-sdks/java-client-samples/src/main/java/org/apache/airavata/client/samples/CreateLaunchExperiment.java
@@ -46,7 +46,7 @@ public class CreateLaunchExperiment {
     private static final String DEFAULT_USER = "default.registry.user";
     private static final String DEFAULT_GATEWAY = "default.registry.gateway";
     private static Airavata.Client airavataClient;
-    private static String echoAppId = "Echo_38c5ad74-3a27-46d3-963b-d63f1c37b194";
+    private static String echoAppId = "Echo_a96fcc6c-70d8-4557-974f-def8205e8e75";
     private static String wrfAppId = "WRF_5f097c9c-7066-49ec-aed7-4e39607b3adc";
     private static String amberAppId = "Amber_89906be6-5678-49a6-9d04-a0604fbdef2e";
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/9018dc8b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/util/GFACGSISSHUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/util/GFACGSISSHUtils.java b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/util/GFACGSISSHUtils.java
index 40784df..2de1f2f 100644
--- a/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/util/GFACGSISSHUtils.java
+++ b/modules/gfac/gfac-gsissh/src/main/java/org/apache/airavata/gfac/gsissh/util/GFACGSISSHUtils.java
@@ -20,11 +20,7 @@
 */
 package org.apache.airavata.gfac.gsissh.util;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
+import java.util.*;
 
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.ServerSettings;
@@ -67,7 +63,7 @@ public class GFACGSISSHUtils {
     public static final String PBS_JOB_MANAGER = "pbs";
     public static final String SLURM_JOB_MANAGER = "slurm";
     public static final String SUN_GRID_ENGINE_JOB_MANAGER = "UGE";
-
+    public static Map<String, Cluster> clusters = new HashMap<String, Cluster>();
     public static void addSecurityContext(JobExecutionContext jobExecutionContext) throws GFacException, ApplicationSettingsException {
         HostDescription registeredHost = jobExecutionContext.getApplicationContext().getHostDescription();
         if (registeredHost.getType() instanceof GlobusHostType || registeredHost.getType() instanceof UnicoreHostType
@@ -82,27 +78,46 @@ public class GFACGSISSHUtils {
             try {
                 TokenizedMyProxyAuthInfo tokenizedMyProxyAuthInfo = new TokenizedMyProxyAuthInfo(requestData);
                 GsisshHostType gsisshHostType = (GsisshHostType) registeredHost.getType();
-                ServerInfo serverInfo = new ServerInfo(requestData.getMyProxyUserName(), registeredHost.getType().getHostAddress(),
-                        gsisshHostType.getPort());
-
-                JobManagerConfiguration jConfig = null;
-                String installedParentPath = ((HpcApplicationDeploymentType)
-                        jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType()).getInstalledParentPath();
-                String jobManager = ((GsisshHostType) registeredHost.getType()).getJobManager();
-                if (jobManager == null) {
-                    logger.error("No Job Manager is configured, so we are picking pbs as the default job manager");
-                    jConfig = CommonUtils.getPBSJobManager(installedParentPath);
+                String key = requestData.getMyProxyUserName() + registeredHost.getType().getHostAddress() +
+                        gsisshHostType.getPort();
+                boolean recreate = false;
+                if (clusters.containsKey(key) && clusters.get(key).getSession().isConnected()) {
+                    pbsCluster = (PBSCluster) clusters.get(key);
+                    try {
+                        pbsCluster.listDirectory("~/"); // its hard to trust isConnected method, so we try to connect if it works we are good,else we recreate
+                    } catch (Exception e) {
+                        logger.info("Connection found the connection map is expired, so we create from the scratch");
+                        recreate = true; // we make the pbsCluster to create again if there is any exception druing connection
+                    }
+                    logger.info("Re-using the same connection used with the connection string:" + key);
+                    context = new GSISecurityContext(tokenizedMyProxyAuthInfo.getCredentialReader(), requestData, pbsCluster);
                 } else {
-                    if (PBS_JOB_MANAGER.equalsIgnoreCase(jobManager)) {
+                    recreate = true;
+                }
+                if(recreate) {
+                    ServerInfo serverInfo = new ServerInfo(requestData.getMyProxyUserName(), registeredHost.getType().getHostAddress(),
+                            gsisshHostType.getPort());
+
+                    JobManagerConfiguration jConfig = null;
+                    String installedParentPath = ((HpcApplicationDeploymentType)
+                            jobExecutionContext.getApplicationContext().getApplicationDeploymentDescription().getType()).getInstalledParentPath();
+                    String jobManager = ((GsisshHostType) registeredHost.getType()).getJobManager();
+                    if (jobManager == null) {
+                        logger.error("No Job Manager is configured, so we are picking pbs as the default job manager");
                         jConfig = CommonUtils.getPBSJobManager(installedParentPath);
-                    } else if (SLURM_JOB_MANAGER.equalsIgnoreCase(jobManager)) {
-                        jConfig = CommonUtils.getSLURMJobManager(installedParentPath);
-                    } else if (SUN_GRID_ENGINE_JOB_MANAGER.equalsIgnoreCase(jobManager)) {
-                        jConfig = CommonUtils.getSGEJobManager(installedParentPath);
+                    } else {
+                        if (PBS_JOB_MANAGER.equalsIgnoreCase(jobManager)) {
+                            jConfig = CommonUtils.getPBSJobManager(installedParentPath);
+                        } else if (SLURM_JOB_MANAGER.equalsIgnoreCase(jobManager)) {
+                            jConfig = CommonUtils.getSLURMJobManager(installedParentPath);
+                        } else if (SUN_GRID_ENGINE_JOB_MANAGER.equalsIgnoreCase(jobManager)) {
+                            jConfig = CommonUtils.getSGEJobManager(installedParentPath);
+                        }
                     }
+                    pbsCluster = new PBSCluster(serverInfo, tokenizedMyProxyAuthInfo, jConfig);
+                    context = new GSISecurityContext(tokenizedMyProxyAuthInfo.getCredentialReader(), requestData, pbsCluster);
+                    clusters.put(key, pbsCluster);
                 }
-                pbsCluster = new PBSCluster(serverInfo, tokenizedMyProxyAuthInfo, jConfig);
-                context = new GSISecurityContext(tokenizedMyProxyAuthInfo.getCredentialReader(), requestData,pbsCluster);
             } catch (Exception e) {
                 throw new GFacException("An error occurred while creating GSI security context", e);
             }

http://git-wip-us.apache.org/repos/asf/airavata/blob/9018dc8b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java
index 8235725..a31eac1 100644
--- a/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java
+++ b/modules/gfac/gfac-ssh/src/main/java/org/apache/airavata/gfac/ssh/util/GFACSSHUtils.java
@@ -56,6 +56,8 @@ import java.util.*;
 public class GFACSSHUtils {
     private final static Logger logger = LoggerFactory.getLogger(GFACSSHUtils.class);
 
+    public static Map<String, Cluster> clusters = new HashMap<String, Cluster>();
+
     public static void addSecurityContext(JobExecutionContext jobExecutionContext) throws GFacException, ApplicationSettingsException {
         HostDescription registeredHost = jobExecutionContext.getApplicationContext().getHostDescription();
         if (registeredHost.getType() instanceof GlobusHostType || registeredHost.getType() instanceof UnicoreHostType) {
@@ -81,8 +83,28 @@ public class GFACSSHUtils {
                 serverInfo.setUserName(credentials.getPortalUserName());
                 jobExecutionContext.getExperiment().setUserName(credentials.getPortalUserName());
                 // inside the pbsCluser object
-                pbsCluster = new PBSCluster(serverInfo, tokenizedSSHAuthInfo,
-                        CommonUtils.getPBSJobManager(installedParentPath));
+
+                String key = credentials.getPortalUserName() + registeredHost.getType().getHostAddress() +
+                        serverInfo.getPort();
+                boolean recreate = false;
+                if (clusters.containsKey(key) && clusters.get(key).getSession().isConnected()) {
+                    pbsCluster = clusters.get(key);
+                    try {
+                        pbsCluster.listDirectory("~/"); // its hard to trust isConnected method, so we try to connect if it works we are good,else we recreate
+                        // its hard to trust isConnected method, so we try to connect if it works we are good,else we recreate
+                    }catch(Exception e){
+                        logger.info("Connection found the connection map is expired, so we create from the scratch");
+                        recreate = true; // we make the pbsCluster to create again if there is any exception druing connection
+                    }
+                }else{
+                    recreate = true;
+                }
+
+                if(recreate) {
+                    pbsCluster = new PBSCluster(serverInfo, tokenizedSSHAuthInfo,
+                            CommonUtils.getPBSJobManager(installedParentPath));
+                    clusters.put(key, pbsCluster);
+                }
             } catch (Exception e) {
                 e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
             }