airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shame...@apache.org
Subject [2/2] airavata git commit: HPCRemoteCluster imple use Factory class in gfac impl to get ssh sessions
Date Mon, 21 Mar 2016 18:23:35 GMT
HPCRemoteCluster imple use Factory class in gfac impl to get ssh sessions


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

Branch: refs/heads/master
Commit: 8496ae6c195edde0b1358aba182ca640a25c831a
Parents: 47409ba
Author: Shameera Rathnayaka <shameerainfo@gmail.com>
Authored: Mon Mar 21 14:18:59 2016 -0400
Committer: Shameera Rathnayaka <shameerainfo@gmail.com>
Committed: Mon Mar 21 14:18:59 2016 -0400

----------------------------------------------------------------------
 .../org/apache/airavata/gfac/impl/Factory.java  |  6 +-
 .../airavata/gfac/impl/HPCRemoteCluster.java    | 62 +++++++-------------
 2 files changed, 25 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/8496ae6c/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
index 310fb12..ddc744f 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
@@ -474,9 +474,13 @@ public abstract class Factory {
 
 	}
 
+	public static void disconnectSSHSession(ServerInfo serverInfo) {
+		// TODO - remove session from map and call disconnect
+	}
+
 	private static boolean testChannelCreation(Session session) {
 
-		String command = "ls ";
+		String command = "pwd ";
 		Channel channel = null;
 		try {
 			channel = session.openChannel("exec");

http://git-wip-us.apache.org/repos/asf/airavata/blob/8496ae6c/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 06a611b..2e5c3a7 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
@@ -108,20 +108,16 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 		int retry = 3;
 		while (retry > 0) {
 			try {
-				if (!session.isConnected()) {
-					session = Factory.getSSHSession(authenticationInfo, serverInfo);
-				}
+				session = Factory.getSSHSession(authenticationInfo, serverInfo);
 				log.info("Transferring localhost:" + localFile  + " to " + serverInfo.getHost() + ":"
+ remoteFile);
 				SSHUtils.scpTo(localFile, remoteFile, session);
 				retry = 0;
 			} catch (Exception e) {
 				retry--;
-				if (!session.isConnected()) {
-					try {
-						session = Factory.getSSHSession(authenticationInfo, serverInfo);
-					} catch (AiravataException e1) {
-						throw new SSHApiException("JSch Session connection failed", e1);
-					}
+				try {
+					session = Factory.getSSHSession(authenticationInfo, serverInfo);
+				} catch (AiravataException e1) {
+					throw new SSHApiException("JSch Session connection failed", e1);
 				}
 				if (retry == 0) {
 					throw new SSHApiException("Failed to scp localhost:" + localFile + " to " + serverInfo.getHost()
+
@@ -139,20 +135,16 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 		int retry = 3;
 		while(retry>0) {
 			try {
-				if (!session.isConnected()) {
-					session = Factory.getSSHSession(authenticationInfo, serverInfo);
-				}
+				session = Factory.getSSHSession(authenticationInfo, serverInfo);
 				log.info("Transferring " + serverInfo.getHost() + ":" + remoteFile + " To localhost:"
+ localFile);
 				SSHUtils.scpFrom(remoteFile, localFile, session);
 				retry=0;
 			} catch (Exception e) {
 				retry--;
-				if (!session.isConnected()) {
-					try {
-						session = Factory.getSSHSession(authenticationInfo, serverInfo);
-					} catch (AiravataException e1) {
-						throw new SSHApiException("JSch Session connection failed", e1);
-					}
+				try {
+					session = Factory.getSSHSession(authenticationInfo, serverInfo);
+				} catch (AiravataException e1) {
+					throw new SSHApiException("JSch Session connection failed", e1);
 				}
 				if (retry == 0) {
 					throw new SSHApiException("Failed to scp " + serverInfo.getHost() + ":" + remoteFile
+ " to " +
@@ -167,14 +159,7 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 	@Override
 	public void scpThirdParty(String sourceFile, String destinationFile, Session clientSession,
DIRECTION direction, boolean ignoreEmptyFile) throws SSHApiException {
 		try {
-			if (!session.isConnected()) {
-				// FIXME - move following info log to debug
-				log.info("Reinitialize a new SSH session for key :" + serverInfo.getUserName() + "-"
+ serverInfo.getHost() + "-" + serverInfo.getPort());
-				session = Factory.getSSHSession(authenticationInfo, serverInfo);
-			} else {
-				// FIXME - move following info logs to debug
-				log.info("Reuse SSH session for key :" + serverInfo.getUserName() + "-" + serverInfo.getHost()
+ "-" + serverInfo.getPort());
-			}
+			session = Factory.getSSHSession(authenticationInfo, serverInfo);
 			log.info("Transferring from:" + sourceFile + " To: " + destinationFile);
             if (direction == DIRECTION.TO) {
                 SSHUtils.scpThirdParty(sourceFile, clientSession, destinationFile, session,
ignoreEmptyFile);
@@ -190,14 +175,7 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 	@Override
 	public void makeDirectory(String directoryPath) throws SSHApiException {
 		try {
-			if (!session.isConnected()) {
-				// FIXME - move following info log to debug
-				log.info("Reinitialize a new SSH session for key :" + serverInfo.getUserName() + "-"
+ serverInfo.getHost() + "-" + serverInfo.getPort());
-				session = Factory.getSSHSession(authenticationInfo, serverInfo);
-			} else {
-				// FIXME - move following info log to debug
-				log.info("Reuse SSH session for key :" + serverInfo.getUserName() + "-" + serverInfo.getHost()
+ "-" + serverInfo.getPort());
-			}
+			session = Factory.getSSHSession(authenticationInfo, serverInfo);
 			log.info("Creating directory: " + serverInfo.getHost() + ":" + directoryPath);
 			SSHUtils.makeDirectory(directoryPath, session);
 		} catch (JSchException | AiravataException | IOException e) {
@@ -245,9 +223,7 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 	@Override
 	public List<String> listDirectory(String directoryPath) throws SSHApiException {
 		try {
-			if (!session.isConnected()) {
-				session = Factory.getSSHSession(authenticationInfo, serverInfo);
-			}
+			session = Factory.getSSHSession(authenticationInfo, serverInfo);
 			log.info("Creating directory: " + serverInfo.getHost() + ":" + directoryPath);
 			return SSHUtils.listDirectory(directoryPath, session);
 		} catch (JSchException | AiravataException | IOException e) {
@@ -264,12 +240,16 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 
 	@Override
 	public Session getSession() throws SSHApiException {
-		return session;
+		try {
+			return Factory.getSSHSession(authenticationInfo, serverInfo);
+		} catch (AiravataException e) {
+			throw new SSHApiException("Error!",e);
+		}
 	}
 
 	@Override
 	public void disconnect() throws SSHApiException {
-		session.disconnect();
+		Factory.disconnectSSHSession(serverInfo);
 	}
 
 	/**
@@ -296,9 +276,7 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 		String command = commandInfo.getCommand();
 		ChannelExec channelExec = null;
 		try {
-			if (!session.isConnected()) {
-				session = Factory.getSSHSession(authenticationInfo, serverInfo);
-			}
+			session = Factory.getSSHSession(authenticationInfo, serverInfo);
 			channelExec = ((ChannelExec) session.openChannel("exec"));
 			channelExec.setCommand(command);
 		    channelExec.setInputStream(null);


Mime
View raw message