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

lahirujayathilake pushed a commit to branch expe-data-path-fix
in repository https://gitbox.apache.org/repos/asf/airavata.git


The following commit(s) were added to refs/heads/expe-data-path-fix by this 
push:
     new 6105c73fff Fix buildDestinationFilePath for different output storage 
resources
6105c73fff is described below

commit 6105c73fff86188b0ad0124049bdeb8a333f5fc5
Author: lahiruj <[email protected]>
AuthorDate: Fri Nov 14 00:22:48 2025 -0500

    Fix buildDestinationFilePath for different output storage resources
---
 .../helix/impl/task/staging/ArchiveTask.java       |  4 +-
 .../helix/impl/task/staging/DataStagingTask.java   | 48 ++++++++++++++--------
 .../impl/task/staging/OutputDataStagingTask.java   |  6 +--
 3 files changed, 36 insertions(+), 22 deletions(-)

diff --git 
a/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/ArchiveTask.java
 
b/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/ArchiveTask.java
index 46ed806e6f..ad764b305e 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/ArchiveTask.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/ArchiveTask.java
@@ -68,10 +68,10 @@ public class ArchiveTask extends DataStagingTask {
                     tarDirPath = sourceURI.getPath();
                 }
 
-                String inputPath = getTaskContext()
+                String outputStorageRoot = getTaskContext()
                         .getOutputGatewayStorageResourcePreference()
                         .getFileSystemRootLocation();
-                destFilePath = buildDestinationFilePath(inputPath, 
archiveFileName);
+                destFilePath = buildDestinationFilePath(outputStorageRoot, 
archiveFileName);
 
                 tarCreationAbsPath = tarDirPath + File.separator + 
archiveFileName;
             } catch (URISyntaxException e) {
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/DataStagingTask.java
 
b/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/DataStagingTask.java
index dacc55808a..756a17dd4f 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/DataStagingTask.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/DataStagingTask.java
@@ -197,26 +197,40 @@ public abstract class DataStagingTask extends 
AiravataTask {
         return localDataPath;
     }
 
-    protected String buildDestinationFilePath(String inputPath, String 
fileName) {
+    /**
+     * Builds the destination file path for data staging tasks.
+     * The method constructs the path as: targetStorageRoot + 
experimentDataDir + fileName
+     * If experimentDataDir is given as an absolute path (starts with '/'), 
the leading
+     * separator is stripped to make it relative to targetStorageRoot.
+     * If experimentDataDir is null or empty falls back to processId-based 
path.
+     *
+     * @param targetStorageRoot The file system root location of the target 
storage resource
+     * @param fileName          The name of the file to be staged
+     * @return The complete destination file path
+     */
+    protected String buildDestinationFilePath(String targetStorageRoot, String 
fileName) {
+        String targetRoot = targetStorageRoot.trim();
+        if (!targetRoot.endsWith(File.separator)) {
+            targetRoot += File.separator;
+        }
 
-        inputPath = (inputPath.endsWith(File.separator) ? inputPath : 
inputPath + File.separator);
         String experimentDataDir = getProcessModel().getExperimentDataDir();
-        String filePath;
-        // TODO : This logic is extremely dangerous. This was implemented 
expecting the input and output storage are
-        // same.
-        if (experimentDataDir != null && !experimentDataDir.isEmpty()) {
-            if (!experimentDataDir.endsWith(File.separator)) {
-                experimentDataDir += File.separator;
-            }
-            if (experimentDataDir.startsWith(File.separator)) {
-                filePath = experimentDataDir + fileName;
-            } else {
-                filePath = inputPath + experimentDataDir + fileName;
-            }
-        } else {
-            filePath = inputPath + getProcessId() + File.separator + fileName;
+
+        if (experimentDataDir == null || experimentDataDir.trim().isEmpty()) {
+            return targetRoot + getProcessId() + File.separator + fileName;
+        }
+
+        String normalizedDir = experimentDataDir.trim();
+        if (normalizedDir.startsWith(File.separator)) {
+            normalizedDir = normalizedDir.substring(1);
+            logger.debug("Stripped the leading separator from 
experimentDataDir to make it relative: {}", normalizedDir);
         }
-        return filePath;
+
+        if (!normalizedDir.endsWith(File.separator)) {
+            normalizedDir += File.separator;
+        }
+
+        return targetRoot + normalizedDir + fileName;
     }
 
     protected String escapeSpecialCharacters(String inputString) {
diff --git 
a/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
 
b/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
index 3aab8d3fa6..8a80da1f4b 100644
--- 
a/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
+++ 
b/airavata-api/src/main/java/org/apache/airavata/helix/impl/task/staging/OutputDataStagingTask.java
@@ -92,9 +92,9 @@ public class OutputDataStagingTask extends DataStagingTask {
 
                 if (dataStagingTaskModel.getDestination().startsWith("dummy")) 
{
                     StoragePreference outputStoragePref = 
getTaskContext().getOutputGatewayStorageResourcePreference();
-                    String inputPath = 
outputStoragePref.getFileSystemRootLocation();
-                    String destFilePath = buildDestinationFilePath(inputPath, 
sourceFileName);
-                    logger.info("Output storage path for task id " + 
getTaskId() + " is " + destFilePath);
+                    String outputStorageRoot = 
outputStoragePref.getFileSystemRootLocation();
+                    String destFilePath = 
buildDestinationFilePath(outputStorageRoot, sourceFileName);
+                    logger.info("Output storage path for task id {} is {}", 
getTaskId(), destFilePath);
                     destinationURI = new URI(
                             "file",
                             outputStoragePref.getLoginUserName(),

Reply via email to