You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2019/12/06 20:27:16 UTC

[airavata] 01/01: Supporting cascading wildcards

This is an automated email from the ASF dual-hosted git repository.

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

commit d08780b44af28543e9b46cf9140f14b021c17298
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Fri Dec 6 15:27:02 2019 -0500

    Supporting cascading wildcards
---
 .../apache/airavata/helix/adaptor/SSHJAgentAdaptor.java   | 15 ++++++++++++++-
 .../helix/impl/task/staging/OutputDataStagingTask.java    |  6 +++---
 2 files changed, 17 insertions(+), 4 deletions(-)

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 05ce146..8cf0b9d 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
@@ -344,12 +344,25 @@ public class SSHJAgentAdaptor implements AgentAdaptor {
     @Override
     public List<String> getFileNameFromExtension(String fileName, String parentPath) throws AgentException {
 
-        try (SFTPClient sftpClient = sshjClient.newSFTPClientWrapper()) {
+        /*try (SFTPClient sftpClient = sshjClient.newSFTPClientWrapper()) {
             List<RemoteResourceInfo> ls = sftpClient.ls(parentPath, resource -> isMatch(resource.getName(), fileName));
             return ls.stream().map(RemoteResourceInfo::getPath).collect(Collectors.toList());
         } catch (Exception e) {
             throw new AgentException(e);
+        }*/
+        if (fileName.endsWith("*")) {
+            throw new AgentException("Wildcards that ends with * does not support for security reasons. Specify an extension");
+        }
+
+        CommandOutput commandOutput = executeCommand("ls " + fileName, parentPath); // This has a risk of returning folders also
+        String[] filesTmp = commandOutput.getStdOut().split("\n");
+        List<String> files = new ArrayList<>();
+        for (String f: filesTmp) {
+            if (!f.isEmpty()) {
+                files.add(f);
+            }
         }
+        return files;
     }
 
     @Override
diff --git a/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java b/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
index af43cef..a5d9d74 100644
--- a/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
+++ b/modules/airavata-helix/helix-spectator/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
@@ -137,11 +137,11 @@ public class OutputDataStagingTask extends DataStagingTask {
                         logger.warn("Ignoring file transfer as filename is empty or null");
                         continue;
                     }
-                    sourceFileName = new File(subFilePath).getName();
+                    sourceFileName = subFilePath;
                     if (destParentPath.endsWith(File.separator)) {
-                        destinationURI = new URI(destParentPath + sourceFileName);
+                        destinationURI = new URI(destParentPath + subFilePath);
                     } else {
-                        destinationURI = new URI(destParentPath + File.separator + sourceFileName);
+                        destinationURI = new URI(destParentPath + File.separator + subFilePath);
                     }
 
                     URI newSourceURI = new URI((sourceParentPath.endsWith(File.separator) ?