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 2021/06/02 19:46:25 UTC

[airavata-mft] branch develop updated: Using absolute paths for child paths

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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 7f34810  Using absolute paths for child paths
7f34810 is described below

commit 7f34810e821fbcb3728f6ddaec5480ce59ab6c5f
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Wed Jun 2 15:41:27 2021 -0400

    Using absolute paths for child paths
---
 .../airavata/mft/api/ApiServiceApplication.java    |  5 +-
 .../mft/transport/scp/SCPMetadataCollector.java    | 65 ++++++++++------------
 .../airavata/mft/transport/scp/SCPReceiver.java    | 31 +++++------
 .../airavata/mft/transport/scp/SCPSender.java      | 32 +++++------
 4 files changed, 64 insertions(+), 69 deletions(-)

diff --git a/api/service/src/main/java/org/apache/airavata/mft/api/ApiServiceApplication.java b/api/service/src/main/java/org/apache/airavata/mft/api/ApiServiceApplication.java
index 94f78bd..d88a331 100644
--- a/api/service/src/main/java/org/apache/airavata/mft/api/ApiServiceApplication.java
+++ b/api/service/src/main/java/org/apache/airavata/mft/api/ApiServiceApplication.java
@@ -18,6 +18,7 @@
 package org.apache.airavata.mft.api;
 
 import org.springframework.boot.SpringApplication;
+import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
 
@@ -25,6 +26,8 @@ import org.springframework.context.annotation.ComponentScan;
 @ComponentScan(basePackages = {"org.apache.airavata.mft"})
 public class ApiServiceApplication {
     public static void main(String args[]) {
-        SpringApplication.run(ApiServiceApplication.class, args);
+        SpringApplication app = new SpringApplication(ApiServiceApplication.class);
+        app.setWebApplicationType(WebApplicationType.NONE);
+        app.run(args);
     }
 }
diff --git a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPMetadataCollector.java b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPMetadataCollector.java
index 0645112..4f72151 100644
--- a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPMetadataCollector.java
+++ b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPMetadataCollector.java
@@ -138,36 +138,33 @@ public class SCPMetadataCollector implements MetadataCollector {
         SecretServiceClient secretClient = SecretServiceClientBuilder.buildClient(secretServiceHost, secretServicePort);
         SCPSecret scpSecret = secretClient.scp().getSCPSecret(SCPSecretGetRequest.newBuilder().setSecretId(credentialToken).build());
 
-        String resourcePath = null;
+        boolean isChildPath = false;
+        if (childResourcePath != null && !"".equals(childResourcePath)) {
+            isChildPath = true;
+        }
 
+        String resourcePath = null;
         switch (resource.getResourceCase()){
             case FILE:
+                if (isChildPath){
+                    throw new Exception("A child path can not be associated with a file parent");
+                }
                 resourcePath = resource.getFile().getResourcePath();
                 break;
             case DIRECTORY:
                 resourcePath = resource.getDirectory().getResourcePath();
+                if (isChildPath) {
+                    if (!childResourcePath.startsWith(resourcePath)) {
+                        throw new Exception("Child path " + childResourcePath + " is not in the parent path " + resourcePath);
+                    }
+                    resourcePath = childResourcePath;
+                }
+
                 break;
             case RESOURCE_NOT_SET:
                 throw new Exception("Resource was not set in resource with id " + parentResourceId);
         }
 
-        if (childResourcePath != null && !"".equals(childResourcePath)) {
-            if (resourcePath.startsWith("/")) {
-                // Linux
-                resourcePath = resourcePath.endsWith("/") ?
-                        resourcePath + childResourcePath : resourcePath + "/" + childResourcePath;
-            } else if (resourcePath.contains("\\")) {
-                // Windows
-                resourcePath = resourcePath.endsWith("\\") ?
-                        resourcePath + childResourcePath : resourcePath + "\\" + childResourcePath;
-            } else {
-                logger.error("Couldn't detect path seperator to append child path {} resource path {}",
-                        childResourcePath, resourcePath);
-                throw new Exception("Couldn't detect path seperator to append child path " + childResourcePath
-                        +" resource path " + resourcePath);
-            }
-        }
-
         GenericResource scpResource2 = GenericResource.newBuilder()
                                         .setFile(FileResource.newBuilder()
                                         .setResourcePath(resourcePath).build())
@@ -240,36 +237,34 @@ public class SCPMetadataCollector implements MetadataCollector {
         SecretServiceClient secretClient = SecretServiceClientBuilder.buildClient(secretServiceHost, secretServicePort);
         SCPSecret scpSecret = secretClient.scp().getSCPSecret(SCPSecretGetRequest.newBuilder().setSecretId(credentialToken).build());
 
+        boolean isChildPath = false;
+        if (childResourcePath != null && !"".equals(childResourcePath)) {
+            isChildPath = true;
+        }
+
         String resourcePath = null;
 
         switch (resource.getResourceCase()){
             case FILE:
+                if (isChildPath){
+                    throw new Exception("A child path can not be associated with a file parent");
+                }
                 resourcePath = resource.getFile().getResourcePath();
                 break;
             case DIRECTORY:
                 resourcePath = resource.getDirectory().getResourcePath();
+                if (isChildPath) {
+                    if (!resourcePath.startsWith(childResourcePath)) {
+                        throw new Exception("Child path " + childResourcePath + " is not in the parent path " + resourcePath);
+                    }
+                    resourcePath = childResourcePath;
+                }
+
                 break;
             case RESOURCE_NOT_SET:
                 throw new Exception("Resource was not set in resource with id " + parentResourceId);
         }
 
-        if (childResourcePath != null && !"".equals(childResourcePath)) {
-            if (resourcePath.startsWith("/")) {
-                // Linux
-                resourcePath = resourcePath.endsWith("/") ?
-                        resourcePath + childResourcePath : resourcePath + "/" + childResourcePath;
-            } else if (resourcePath.contains("\\")) {
-                // Windows
-                resourcePath = resourcePath.endsWith("\\") ?
-                        resourcePath + childResourcePath : resourcePath + "\\" + childResourcePath;
-            } else {
-                logger.error("Couldn't detect path seperator to append child path {} resource path {}",
-                        childResourcePath, resourcePath);
-                throw new Exception("Couldn't detect path seperator to append child path " + childResourcePath
-                        +" resource path " + resourcePath);
-            }
-        }
-
         GenericResource scpResource = GenericResource.newBuilder()
                 .setDirectory(DirectoryResource.newBuilder().setResourcePath(resourcePath).build())
                 .setScpStorage(resource.getScpStorage()).build();
diff --git a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java
index 233f3b7..a7eed5b 100644
--- a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java
+++ b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPReceiver.java
@@ -119,34 +119,33 @@ public class SCPReceiver implements Connector {
             throw new Exception("Session can not be null. Make sure that SCP Receiver is properly initialized");
         }
 
+        boolean isChildPath = false;
+        if (childResourcePath != null && !"".equals(childResourcePath)) {
+            isChildPath = true;
+        }
+
         String resourcePath = null;
         switch (resource.getResourceCase()){
             case FILE:
+                if (isChildPath){
+                    throw new Exception("A child path can not be associated with a file parent");
+                }
                 resourcePath = resource.getFile().getResourcePath();
                 break;
             case DIRECTORY:
                 resourcePath = resource.getDirectory().getResourcePath();
+                if (isChildPath) {
+                    if (!childResourcePath.startsWith(resourcePath)) {
+                        throw new Exception("Child path " + childResourcePath + " is not in the parent path " + resourcePath);
+                    }
+                    resourcePath = childResourcePath;
+                }
+
                 break;
             case RESOURCE_NOT_SET:
                 throw new Exception("Resource was not set in resource with id " + resourceId);
         }
 
-        if (childResourcePath != null && !"".equals(childResourcePath)) {
-            if (resourcePath.startsWith("/")) {
-                // Linux
-                resourcePath = resourcePath.endsWith("/") ?
-                        resourcePath + childResourcePath : resourcePath + "/" + childResourcePath;
-            } else if (resourcePath.contains("\\")) {
-                // Windows
-                resourcePath = resourcePath.endsWith("\\") ?
-                        resourcePath + childResourcePath : resourcePath + "\\" + childResourcePath;
-            } else {
-                logger.error("Couldn't detect path seperator to append child path {} resource path {}",
-                        childResourcePath, resourcePath);
-                throw new Exception("Couldn't detect path seperator to append child path " + childResourcePath
-                        +" resource path " + resourcePath);
-            }
-        }
         transferRemoteToStream(session, resourcePath, context.getStreamBuffer());
         logger.info("SCP Receive completed. Transfer {}", context.getTransferId());
     }
diff --git a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java
index 4df432c..291bfcd 100644
--- a/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java
+++ b/transport/scp-transport/src/main/java/org/apache/airavata/mft/transport/scp/SCPSender.java
@@ -118,35 +118,33 @@ public class SCPSender implements Connector {
             throw new Exception("Session can not be null. Make sure that SCP Sender is properly initialized");
         }
 
+        boolean isChildPath = false;
+        if (childResourcePath != null && !"".equals(childResourcePath)) {
+            isChildPath = true;
+        }
+
         String resourcePath = null;
         switch (resource.getResourceCase()){
             case FILE:
+                if (isChildPath){
+                    throw new Exception("A child path can not be associated with a file parent");
+                }
                 resourcePath = resource.getFile().getResourcePath();
                 break;
             case DIRECTORY:
                 resourcePath = resource.getDirectory().getResourcePath();
+                if (isChildPath) {
+                    if (!childResourcePath.startsWith(resourcePath)) {
+                        throw new Exception("Child path " + childResourcePath + " is not in the parent path " + resourcePath);
+                    }
+                    resourcePath = childResourcePath;
+                }
+
                 break;
             case RESOURCE_NOT_SET:
                 throw new Exception("Resource was not set in resource with id " + resourceId);
         }
 
-        if (childResourcePath != null && !"".equals(childResourcePath)) {
-            if (resourcePath.startsWith("/")) {
-                // Linux
-                resourcePath = resourcePath.endsWith("/") ?
-                        resourcePath + childResourcePath : resourcePath + "/" + childResourcePath;
-            } else if (resourcePath.contains("\\")) {
-                // Windows
-                resourcePath = resourcePath.endsWith("\\") ?
-                        resourcePath + childResourcePath : resourcePath + "\\" + childResourcePath;
-            } else {
-                logger.error("Couldn't detect path seperator to append child path {} resource path {}",
-                        childResourcePath, resourcePath);
-                throw new Exception("Couldn't detect path seperator to append child path " + childResourcePath
-                        +" resource path " + resourcePath);
-            }
-        }
-
         try {
             copyLocalToRemote(this.session,
                     resourcePath,