airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dimuthu...@apache.org
Subject [airavata] branch staging updated: Adding recursive directory creation method to adaptors
Date Tue, 10 Jul 2018 16:42:15 GMT
This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch staging
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/staging by this push:
     new 99d500a  Adding recursive directory creation method to adaptors
99d500a is described below

commit 99d500ad5a91c3ea5bb150c89fb5d506ab7c127f
Author: dimuthu <dimuthu.upeksha2@gmail.com>
AuthorDate: Tue Jul 10 12:42:06 2018 -0400

    Adding recursive directory creation method to adaptors
---
 .../org/apache/airavata/agents/api/AgentAdaptor.java |  2 ++
 .../airavata/helix/agent/ssh/SshAgentAdaptor.java    |  7 ++++++-
 .../airavata/helix/adaptor/SSHJAgentAdaptor.java     | 20 +++++++++++++++++++-
 .../airavata/helix/impl/task/env/EnvSetupTask.java   |  2 +-
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/modules/airavata-helix/agent-api/src/main/java/org/apache/airavata/agents/api/AgentAdaptor.java
b/modules/airavata-helix/agent-api/src/main/java/org/apache/airavata/agents/api/AgentAdaptor.java
index 0039826..bbeaf92 100644
--- a/modules/airavata-helix/agent-api/src/main/java/org/apache/airavata/agents/api/AgentAdaptor.java
+++ b/modules/airavata-helix/agent-api/src/main/java/org/apache/airavata/agents/api/AgentAdaptor.java
@@ -36,6 +36,8 @@ public interface AgentAdaptor {
 
     public void createDirectory(String path) throws AgentException;
 
+    public void createDirectory(String path, boolean recursive) throws AgentException;
+
     public void copyFileTo(String localFile, String remoteFile) throws AgentException;
 
     public void copyFileFrom(String remoteFile, String localFile) throws AgentException;
diff --git a/modules/airavata-helix/agent-impl/ssh-agent/src/main/java/org/apache/airavata/helix/agent/ssh/SshAgentAdaptor.java
b/modules/airavata-helix/agent-impl/ssh-agent/src/main/java/org/apache/airavata/helix/agent/ssh/SshAgentAdaptor.java
index 9c26f6a..ffa9109c 100644
--- a/modules/airavata-helix/agent-impl/ssh-agent/src/main/java/org/apache/airavata/helix/agent/ssh/SshAgentAdaptor.java
+++ b/modules/airavata-helix/agent-impl/ssh-agent/src/main/java/org/apache/airavata/helix/agent/ssh/SshAgentAdaptor.java
@@ -132,7 +132,12 @@ public class SshAgentAdaptor implements AgentAdaptor {
     }
 
     public void createDirectory(String path) throws AgentException {
-        String command = "mkdir -p " + path;
+        createDirectory(path, false);
+    }
+
+    @Override
+    public void createDirectory(String path, boolean recursive) throws AgentException {
+        String command = (recursive? "mkdir -p " : "mkdir ") + path;
         ChannelExec channelExec = null;
         try {
             channelExec = (ChannelExec)session.openChannel("exec");
diff --git a/modules/airavata-helix/agent-impl/sshj-agent/src/main/java/org/apache/airavata/helix/adaptor/SSHJAgentAdaptor.java
b/modules/airavata-helix/agent-impl/sshj-agent/src/main/java/org/apache/airavata/helix/adaptor/SSHJAgentAdaptor.java
index 375bab5..8b41db3 100644
--- a/modules/airavata-helix/agent-impl/sshj-agent/src/main/java/org/apache/airavata/helix/adaptor/SSHJAgentAdaptor.java
+++ b/modules/airavata-helix/agent-impl/sshj-agent/src/main/java/org/apache/airavata/helix/adaptor/SSHJAgentAdaptor.java
@@ -96,6 +96,15 @@ public class SSHJAgentAdaptor implements AgentAdaptor {
         sshjClient.auth(user, am);
     }
 
+    public void init(String user, String host, String publicKey, String privateKey, String
passphrase) throws AgentException {
+        try {
+            createPoolingSSHJClient(user, host, publicKey, privateKey, passphrase);
+        } catch (IOException e) {
+            logger.error("Error while initializing sshj agent for user " + user + " host
" + host + " for key starting with " + publicKey.substring(0,10), e);
+            throw new AgentException("Error while initializing sshj agent for user " + user
+ " host " + host + " for key starting with " + publicKey.substring(0,10), e);
+        }
+    }
+
     @Override
     public void init(String computeResource, String gatewayId, String userId, String token)
throws AgentException {
         try {
@@ -140,8 +149,17 @@ public class SSHJAgentAdaptor implements AgentAdaptor {
 
     @Override
     public void createDirectory(String path) throws AgentException {
+        createDirectory(path, false);
+    }
+
+    @Override
+    public void createDirectory(String path, boolean recursive) throws AgentException {
         try (SFTPClient sftpClient = sshjClient.newSFTPClientWrapper()) {
-            sftpClient.mkdir(path);
+            if (recursive) {
+                sftpClient.mkdirs(path);
+            } else {
+                sftpClient.mkdir(path);
+            }
         } catch (Exception e) {
             throw new AgentException(e);
         }
diff --git a/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/env/EnvSetupTask.java
b/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/env/EnvSetupTask.java
index 67d2acc..6be4383 100644
--- a/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/env/EnvSetupTask.java
+++ b/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/env/EnvSetupTask.java
@@ -48,7 +48,7 @@ public class EnvSetupTask extends AiravataTask {
             logger.info("Creating directory " + getTaskContext().getWorkingDir() + " on compute
resource " +
                     getTaskContext().getComputeResourceId() + " by user " + getTaskContext().getComputeResourceLoginUserName()
                     + " using token " + getTaskContext().getComputeResourceCredentialToken());
-            adaptor.createDirectory(getTaskContext().getWorkingDir());
+            adaptor.createDirectory(getTaskContext().getWorkingDir(), true);
             return onSuccess("Envi setup task successfully completed " + getTaskId());
 
         } catch (Exception e) {


Mime
View raw message