From 2cc4d77a9ac6a88a5335639144d64c627882bf41 Mon Sep 17 00:00:00 2001
From: jakubs <jakubs>
Date: Mon, 29 Sep 2014 12:58:29 +0000
Subject: [PATCH] SSDM-912 Allow to configure temp folder used by sanity check

SVN: 32521
---
 .../standard/AbstractArchiverProcessingPlugin.java | 13 +++++++++++++
 .../server/plugins/standard/RsyncArchiver.java     | 14 +++++++++++++-
 .../server/plugins/standard/TarArchiver.java       |  2 +-
 .../server/plugins/standard/TarPackageManager.java | 10 +++++++++-
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java
index 57fed1f8dce..6924297f5e2 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/AbstractArchiverProcessingPlugin.java
@@ -85,12 +85,16 @@ public abstract class AbstractArchiverProcessingPlugin extends AbstractDatastore
 
     public static final String BATCH_SIZE_IN_BYTES = "batch-size-in-bytes";
 
+    public static final String TEMP_FOLDER = "temp-folder";
+
     private final IStatusChecker archivePrerequisiteOrNull;
 
     private final IStatusChecker unarchivePrerequisiteOrNull;
 
     private final boolean synchronizeArchive;
 
+    private final File tempFolder;
+
     private transient IShareIdManager shareIdManager;
 
     private transient IEncapsulatedOpenBISService service;
@@ -110,6 +114,7 @@ public abstract class AbstractArchiverProcessingPlugin extends AbstractDatastore
         this.unarchivePrerequisiteOrNull = unarchivePrerequisiteOrNull;
         this.synchronizeArchive = PropertyUtils.getBoolean(properties, SYNCHRONIZE_ARCHIVE, true);
         this.maximumBatchSizeInBytes = PropertyUtils.getInt(properties, BATCH_SIZE_IN_BYTES, 1024 * 1024 * 1024);
+        this.tempFolder = PropertyUtils.getDirectory(properties, TEMP_FOLDER, null);
     }
 
     /**
@@ -631,6 +636,14 @@ public abstract class AbstractArchiverProcessingPlugin extends AbstractDatastore
         return shareIdManager;
     }
 
+    /**
+     * Temporary folder specified by "temp-folder" property of archive. Default is null.
+     */
+    protected File getTemporaryFolder()
+    {
+        return tempFolder;
+    }
+
     private IShareFinder getShareFinder()
     {
         Properties props =
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/RsyncArchiver.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/RsyncArchiver.java
index d32cea85e91..d975a911b00 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/RsyncArchiver.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/RsyncArchiver.java
@@ -193,7 +193,19 @@ public class RsyncArchiver extends AbstractArchiverProcessingPlugin
         this.fileOperationsManagerFactory = fileOperationsManagerFactory;
         this.deleteAction = deleteAction;
         this.checksumVerificationCondition = checksumVerificationCondition;
+    }
 
+    private File getTempRoot()
+    {
+        File tempFolderProperty = getTemporaryFolder();
+        if (tempFolderProperty != null)
+        {
+            return tempFolderProperty;
+        }
+        else
+        {
+            return storeRoot;
+        }
     }
 
     @Override
@@ -215,7 +227,7 @@ public class RsyncArchiver extends AbstractArchiverProcessingPlugin
                 try
                 {
                     content = context.getHierarchicalContentProvider().asContentWithoutModifyingAccessTimestamp(dataSetCode);
-                    temp = new File(storeRoot, STAGING_FOLDER + "/" + dataSetCode);
+                    temp = new File(getTempRoot(), STAGING_FOLDER + "/" + dataSetCode);
                     temp.mkdirs();
                     // We want to perform the check if the archived content is correct
                     // (filesizes/checksums)
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarArchiver.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarArchiver.java
index 3fe0b067d68..fdf6d52a0cd 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarArchiver.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarArchiver.java
@@ -44,7 +44,7 @@ public class TarArchiver extends RsyncArchiver
         @Override
         public IDataSetFileOperationsManager create()
         {
-            return new DistributedPackagingDataSetFileOperationsManager(properties, new TarPackageManager());
+            return new DistributedPackagingDataSetFileOperationsManager(properties, new TarPackageManager(properties));
         }
     }
 
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarPackageManager.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarPackageManager.java
index a3504bf4163..e31d9c86c08 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarPackageManager.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/TarPackageManager.java
@@ -26,6 +26,7 @@ import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
 import ch.systemsx.cisd.common.exceptions.Status;
 import ch.systemsx.cisd.common.filesystem.FileUtilities;
 import ch.systemsx.cisd.common.filesystem.tar.Untar;
+import ch.systemsx.cisd.common.properties.PropertyUtils;
 import ch.systemsx.cisd.common.time.TimingParameters;
 import ch.systemsx.cisd.openbis.common.io.hierarchical_content.TarBasedHierarchicalContent;
 import ch.systemsx.cisd.openbis.common.io.hierarchical_content.api.IHierarchicalContent;
@@ -49,6 +50,13 @@ public class TarPackageManager implements IPackageManager
 
     private transient IDataSetDirectoryProvider directoryProvider;
 
+    private final File tempFolder;
+
+    public TarPackageManager(Properties properties)
+    {
+        this.tempFolder = PropertyUtils.getDirectory(properties, RsyncArchiver.TEMP_FOLDER, null);
+    }
+
     @Override
     public String getName(IDatasetLocation dataSetLocation)
     {
@@ -118,7 +126,7 @@ public class TarPackageManager implements IPackageManager
     @Override
     public IHierarchicalContent asHierarchialContent(File packageFile)
     {
-        return new TarBasedHierarchicalContent(packageFile);
+        return new TarBasedHierarchicalContent(packageFile, tempFolder);
     }
 
     private IHierarchicalContentProvider getContentProvider()
-- 
GitLab