diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckProcessingPlugin.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckProcessingPlugin.java index 62fe7bf8ec420179371bdd5379e48b22f183c6f4..91076bf6750322781a2fba22b51b9a4308a15608 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckProcessingPlugin.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/plugins/standard/DataSetAndPathInfoDBConsistencyCheckProcessingPlugin.java @@ -603,7 +603,7 @@ public class DataSetAndPathInfoDBConsistencyCheckProcessingPlugin implements IPr fileProvider = new HierarchicalContentProvider(ServiceProvider.getOpenBISService(), ServiceProvider.getShareIdManager(), - ServiceProvider.getConfigProvider(), + ServiceProvider.getConfigProvider(), ServiceProvider.getContentCache(), new DefaultFileBasedHierarchicalContentFactory(), null, null); } return fileProvider; @@ -624,8 +624,8 @@ public class DataSetAndPathInfoDBConsistencyCheckProcessingPlugin implements IPr pathInfoProvider = new HierarchicalContentProvider(ServiceProvider.getOpenBISService(), ServiceProvider.getShareIdManager(), - ServiceProvider.getConfigProvider(), pathInfoDBFactory, null, - null); + ServiceProvider.getConfigProvider(), + ServiceProvider.getContentCache(), pathInfoDBFactory, null, null); } } return pathInfoProvider; diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProvider.java index a1792d1e687a70fc5a18408a2dcef2b6d91f0c8a..1526f8f6dd706efb3ba9865f093be2be83750c46 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProvider.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProvider.java @@ -63,28 +63,26 @@ public class HierarchicalContentProvider implements IHierarchicalContentProvider private final boolean trustAllCertificates; - private File cacheWorkspace; - - private ContentCache cache; + private final ContentCache cache; public HierarchicalContentProvider(IEncapsulatedOpenBISService openbisService, - IShareIdManager shareIdManager, IConfigProvider configProvider, + IShareIdManager shareIdManager, IConfigProvider configProvider, ContentCache contentCache, ISessionTokenProvider sessionTokenProvider, ExposablePropertyPlaceholderConfigurer infoProvider) { this(openbisService, new DataSetDirectoryProvider(configProvider.getStoreRoot(), - shareIdManager), null, sessionTokenProvider, configProvider.getDataStoreCode(), + shareIdManager), null, contentCache, sessionTokenProvider, configProvider.getDataStoreCode(), infoProvider); } public HierarchicalContentProvider(IEncapsulatedOpenBISService openbisService, - IShareIdManager shareIdManager, IConfigProvider configProvider, + IShareIdManager shareIdManager, IConfigProvider configProvider, ContentCache contentCache, IHierarchicalContentFactory hierarchicalContentFactory, ISessionTokenProvider sessionTokenProvider, ExposablePropertyPlaceholderConfigurer infoProvider) { this(openbisService, new DataSetDirectoryProvider(configProvider.getStoreRoot(), - shareIdManager), hierarchicalContentFactory, sessionTokenProvider, configProvider + shareIdManager), hierarchicalContentFactory, contentCache, sessionTokenProvider, configProvider .getDataStoreCode(), infoProvider); } @@ -92,13 +90,14 @@ public class HierarchicalContentProvider implements IHierarchicalContentProvider public HierarchicalContentProvider(IEncapsulatedOpenBISService openbisService, IDataSetDirectoryProvider directoryProvider, IHierarchicalContentFactory hierarchicalContentFactory, - ISessionTokenProvider session, + ContentCache contentCache, ISessionTokenProvider session, String dataStoreCode, ExposablePropertyPlaceholderConfigurer infoProvider) { this.openbisService = openbisService; this.directoryProvider = directoryProvider; this.hierarchicalContentFactory = hierarchicalContentFactory; + this.cache = contentCache; this.sessionTokenProvider = session; this.dataStoreCode = dataStoreCode; if (infoProvider != null) @@ -106,19 +105,10 @@ public class HierarchicalContentProvider implements IHierarchicalContentProvider Properties properties = infoProvider.getResolvedProps(); String trust = properties.getProperty("trust-all-certificates"); trustAllCertificates = (trust != null && trust.equalsIgnoreCase("true")); - String sessionWorkspaceRoot = - infoProvider.getResolvedProps().getProperty("session-workspace-root-dir", - "data/sessionWorkspace"); - cacheWorkspace = new File(sessionWorkspaceRoot); - if (cacheWorkspace.exists() == false) - { - cacheWorkspace.mkdirs(); - } } else { trustAllCertificates = false; } - cache = new ContentCache(cacheWorkspace, true); } @Override diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java index 2e701ef698e68ab989d6254f77ea9bde1ee6d428..3830f3e3e0b04b30a9b82672048ff94ad55b5490 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/ServiceProvider.java @@ -26,6 +26,7 @@ import com.marathon.util.spring.StreamSupportingHttpInvokerServiceExporter; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; +import ch.systemsx.cisd.openbis.dss.generic.shared.content.ContentCache; import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; import ch.systemsx.cisd.openbis.generic.shared.dto.OpenBISSessionHolder; @@ -187,6 +188,11 @@ public class ServiceProvider } return result; } + + public static ContentCache getContentCache() + { + return (ContentCache) getApplicationContext().getBean("content-cache"); + } private ServiceProvider() { diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/ContentCache.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/ContentCache.java index 0dd02cb3fc126750c0fd4d5025be9a92419ed46d..c82fb40a95ca4338e5f49ac932c3180d784634a2 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/ContentCache.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/shared/content/ContentCache.java @@ -25,6 +25,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.HashMap; import java.util.Map; +import java.util.Properties; import java.util.concurrent.locks.ReentrantLock; import org.apache.commons.io.IOUtils; @@ -34,6 +35,7 @@ import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.filesystem.FileOperations; import ch.systemsx.cisd.common.filesystem.IFileOperations; +import ch.systemsx.cisd.openbis.dss.generic.server.plugins.tasks.IPluginTaskInfoProvider; import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric; import ch.systemsx.cisd.openbis.dss.generic.shared.dto.DataSetPathInfo; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IDatasetLocation; @@ -45,10 +47,28 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IDatasetLocation; */ public class ContentCache { + public static final String CACHE_WORKSPACE_FOLDER_KEY = "cache-workspace-folder"; + static final String CACHE_FOLDER = "cached"; static final String DOWNLOADING_FOLDER = "downloading"; + public static ContentCache create(Properties properties, IPluginTaskInfoProvider infoProvider) + { + String workspacePathOrNull = properties.getProperty(CACHE_WORKSPACE_FOLDER_KEY); + boolean sessionCache = workspacePathOrNull == null; + File cacheWorkspace; + if (sessionCache) + { + cacheWorkspace = infoProvider.getSessionWorkspaceRootDir(); + } else + { + cacheWorkspace = new File(workspacePathOrNull); + } + return new ContentCache(new DssServiceRpcGenericFactory(), cacheWorkspace, sessionCache, + FileOperations.getInstance()); + } + private final LockManager dataSetLockManager; private final LockManager fileLockManager; @@ -59,11 +79,6 @@ public class ContentCache private final File workspace; - public ContentCache(File cacheWorkspace, boolean sessionCache) - { - this(new DssServiceRpcGenericFactory(), cacheWorkspace, sessionCache, FileOperations.getInstance()); - } - ContentCache(IDssServiceRpcGenericFactory serviceFactory, File cacheWorkspace, boolean sessionCache, IFileOperations fileOperations) { diff --git a/datastore_server/source/java/dssApplicationContext.xml b/datastore_server/source/java/dssApplicationContext.xml index 0fb6d55962c8f4ae201317e50a69d0960dc9f2dd..6d475c1887065bd71882360a8ce737e9256c58f0 100644 --- a/datastore_server/source/java/dssApplicationContext.xml +++ b/datastore_server/source/java/dssApplicationContext.xml @@ -193,12 +193,19 @@ <bean id="data-source-provider" class="ch.systemsx.cisd.openbis.dss.generic.shared.DataSourceProvider" /> <bean id="config-provider" class="ch.systemsx.cisd.etlserver.ConfigProvider"/> + + <bean id="content-cache" class="ch.systemsx.cisd.openbis.dss.generic.shared.content.ContentCache" + factory-method="create"> + <constructor-arg ref="configProperties" /> + <constructor-arg ref="plugin-tasks" /> + </bean> <bean id="hierarchical-content-provider" class="ch.systemsx.cisd.openbis.dss.generic.shared.HierarchicalContentProvider"> <constructor-arg ref="openBIS-service" /> <constructor-arg ref="share-id-manager" /> <constructor-arg ref="config-provider" /> + <constructor-arg ref="content-cache" /> <constructor-arg ref="sessionHolder" /> <constructor-arg ref="propertyConfigurer" /> </bean> diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java index 2778ac46487b08446de19e59f039ef0f03684ccb..171615f3980175b4e51fe68da2e710ae9f195dc0 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DatasetDownloadServletTest.java @@ -172,7 +172,7 @@ public class DatasetDownloadServletTest new MockDataSetDirectoryProvider(TEST_FOLDER, DEFAULT_SHARE_ID, shareIdManager); hierarchicalContentProvider = new HierarchicalContentProvider(openbisService, dummyDirectoryProvider, - fileBasedContentFactory, null, "STANDARD", null); + fileBasedContentFactory, null, null, "STANDARD", null); httpSession = context.mock(HttpSession.class); TEST_FOLDER.mkdirs(); EXAMPLE_DATA_SET_FOLDER.mkdirs(); diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DssServiceRpcV1Test.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DssServiceRpcV1Test.java index f45a4eeaa34b11cf4c181fb457c671add2af2799..8e699d1d1187ab2587fecddcdb379d88c574847e 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DssServiceRpcV1Test.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/DssServiceRpcV1Test.java @@ -186,7 +186,7 @@ public class DssServiceRpcV1Test extends AbstractFileSystemTestCase new MockDataSetDirectoryProvider(storeDir, SHARE_ID, shareIdManager); contentProvider = new HierarchicalContentProvider(openBisService, dummyDirectoryProvider, - fileBasedContentFactory, null, "STANDARD", null); + fileBasedContentFactory, null, null, "STANDARD", null); setupGetExpectations(); diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProviderTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProviderTest.java index 17063386cfae42a2d19e27ec0801dc0500539b74..4c05631c301ad7cd451ef5e10e1683285f484516 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProviderTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/shared/HierarchicalContentProviderTest.java @@ -73,7 +73,7 @@ public class HierarchicalContentProviderTest extends AssertJUnit openbisService = context.mock(IEncapsulatedOpenBISService.class); hierarchicalContentProvider = new HierarchicalContentProvider(openbisService, directoryProvider, - hierarchicalContentFactory, null, "STANDARD", null); + hierarchicalContentFactory, null, null, "STANDARD", null); } @AfterMethod