From fcaeab8f67da0152992f45d5f6fee718c3d93738 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Tue, 24 Mar 2009 12:27:15 +0000 Subject: [PATCH] LMS-779 CIFEX URL is provided by openBIS, bugs fixed SVN: 10336 --- datastore_server/dist/etc/service.properties | 3 - datastore_server/etc/service.properties | 3 - .../source/java/applicationContext.xml | 1 - .../dss/generic/server/DataStoreService.java | 68 ++++++++++++------- .../server/DataStoreServiceLogger.java | 5 +- .../server/ICIFEXRPCServiceFactory.java | 31 +++++++++ .../dss/generic/server/UploadingCommand.java | 26 ++++--- 7 files changed, 91 insertions(+), 46 deletions(-) create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ICIFEXRPCServiceFactory.java diff --git a/datastore_server/dist/etc/service.properties b/datastore_server/dist/etc/service.properties index 56cc0500b03..120c6634351 100644 --- a/datastore_server/dist/etc/service.properties +++ b/datastore_server/dist/etc/service.properties @@ -39,9 +39,6 @@ notify-successful-registration = false # The URL of the openBIS server server-url = https://localhost:8443/openbis/openbis -# The URL of the CIFEX server -cifex-url = https://cifex.ethz.ch/ - # The username to use when contacting the openBIS server username = etlserver diff --git a/datastore_server/etc/service.properties b/datastore_server/etc/service.properties index 37c5a198256..36f8e8ab563 100644 --- a/datastore_server/etc/service.properties +++ b/datastore_server/etc/service.properties @@ -37,9 +37,6 @@ notify-successful-registration = false # The URL of the openBIS server server-url = http://localhost:8080/openbis -# The URL of the CIFEX server -cifex-url = https://cifex.ethz.ch/ - # The username to use when contacting the openBIS server username = etlserver diff --git a/datastore_server/source/java/applicationContext.xml b/datastore_server/source/java/applicationContext.xml index 4a1b06b3c56..b0b93201769 100644 --- a/datastore_server/source/java/applicationContext.xml +++ b/datastore_server/source/java/applicationContext.xml @@ -32,7 +32,6 @@ <property name="service"> <bean class="ch.systemsx.cisd.openbis.dss.generic.server.DataStoreService"> <constructor-arg ref="session-token-manager" /> - <constructor-arg value="${cifex-url}"/> <property name="storeRoot" value="${storeroot-dir}"/> </bean> </property> diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreService.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreService.java index cfde5c35271..f17ab8f445a 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreService.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreService.java @@ -26,11 +26,13 @@ import org.springframework.beans.factory.InitializingBean; import ch.systemsx.cisd.cifex.rpc.ICIFEXRPCService; import ch.systemsx.cisd.cifex.rpc.client.RPCServiceFactory; import ch.systemsx.cisd.cifex.shared.basic.Constants; +import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.InvalidAuthenticationException; import ch.systemsx.cisd.common.exceptions.InvalidSessionException; import ch.systemsx.cisd.common.exceptions.WrappedIOException; import ch.systemsx.cisd.common.spring.AbstractServiceWithLogger; import ch.systemsx.cisd.openbis.generic.shared.IDataStoreService; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUploadContext; /** * Implementation of {@link IDataStoreService} which will be accessed remotely by the opneBIS @@ -41,21 +43,6 @@ import ch.systemsx.cisd.openbis.generic.shared.IDataStoreService; public class DataStoreService extends AbstractServiceWithLogger<IDataStoreService> implements IDataStoreService, InitializingBean { - private static ICIFEXRPCService createCIFEXService(String baseURL) - { - final String serviceURL = baseURL + Constants.CIFEX_RPC_PATH; - final ICIFEXRPCService service = - RPCServiceFactory.createServiceProxy(serviceURL, true); - final int serverVersion = service.getVersion(); - if (ICIFEXRPCService.VERSION != serverVersion) - { - System.err.println("This client has the wrong service version for the server (client: " - + ICIFEXRPCService.VERSION + ", server: " + serverVersion + ")."); - return null; - } - return service; - } - private final SessionTokenManager sessionTokenManager; private final IDataSetCommandExecutorFactory commandExecutorFactory; @@ -64,25 +51,22 @@ public class DataStoreService extends AbstractServiceWithLogger<IDataStoreServic private IDataSetCommandExecutor commandExecuter; - private final ICIFEXRPCService cifexService; - - public DataStoreService(SessionTokenManager sessionTokenManager, String baseURL) + public DataStoreService(SessionTokenManager sessionTokenManager) { this(sessionTokenManager, new IDataSetCommandExecutorFactory() { public IDataSetCommandExecutor create(File store) { - return new DataSetCommandExecuter(new File(store, "commandQueue")); + return new DataSetCommandExecuter(store); } - }, createCIFEXService(baseURL)); + }); } DataStoreService(SessionTokenManager sessionTokenManager, - IDataSetCommandExecutorFactory commandExecutorFactory, ICIFEXRPCService cifexService) + IDataSetCommandExecutorFactory commandExecutorFactory) { this.sessionTokenManager = sessionTokenManager; this.commandExecutorFactory = commandExecutorFactory; - this.cifexService = cifexService; } public final void setStoreRoot(File storeRoot) @@ -162,16 +146,48 @@ public class DataStoreService extends AbstractServiceWithLogger<IDataStoreServic } public void uploadDataSetsToCIFEX(String sessionToken, List<String> dataSetLocations, - String comment, String userID, String password) throws InvalidAuthenticationException + DataSetUploadContext context) throws InvalidAuthenticationException { sessionTokenManager.assertValidSessionToken(sessionToken); - if (cifexService.login(userID, password) == null) + CIFEXRPCServiceFactory serviceFactory = new CIFEXRPCServiceFactory(context.getCifexURL()); + ICIFEXRPCService service = serviceFactory.createService(); + String userID = context.getUserID(); + String password = context.getPassword(); + if (service.login(userID, password) == null) { throw new InvalidSessionException("User couldn't be authenticated at CIFEX."); } - commandExecuter.scheduleCommand(new UploadingCommand(cifexService, dataSetLocations, - comment, userID, password)); + commandExecuter.scheduleCommand(new UploadingCommand(serviceFactory, dataSetLocations, context)); } + private static final class CIFEXRPCServiceFactory implements ICIFEXRPCServiceFactory + { + private static final long serialVersionUID = 1L; + private final String cifexURL; + + private transient ICIFEXRPCService service; + + CIFEXRPCServiceFactory(String cifexURL) + { + this.cifexURL = cifexURL; + } + + public ICIFEXRPCService createService() + { + if (service == null) + { + final String serviceURL = cifexURL + Constants.CIFEX_RPC_PATH; + service = RPCServiceFactory.createServiceProxy(serviceURL, true); + final int serverVersion = service.getVersion(); + if (ICIFEXRPCService.VERSION != serverVersion) + { + throw new EnvironmentFailureException("The version of the CIFEX server is not " + + ICIFEXRPCService.VERSION + " but " + serverVersion + "."); + } + } + return service; + } + } + } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServiceLogger.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServiceLogger.java index acd78f75995..f4b7ca8cba3 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServiceLogger.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServiceLogger.java @@ -22,6 +22,7 @@ import org.apache.log4j.Logger; import ch.systemsx.cisd.common.exceptions.InvalidAuthenticationException; import ch.systemsx.cisd.openbis.generic.shared.IDataStoreService; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUploadContext; /** * @@ -83,9 +84,9 @@ class DataStoreServiceLogger implements IDataStoreService } public void uploadDataSetsToCIFEX(String sessionToken, List<String> dataSetLocations, - String comment, String userID, String password) throws InvalidAuthenticationException + DataSetUploadContext context) throws InvalidAuthenticationException { - log("upload_data_sets", "LOCATIONS(%s) USER(%s) COMMENT(%s)", dataSetLocations, userID, comment); + log("upload_data_sets", "LOCATIONS(%s) USER(%s)", dataSetLocations, context.getUserID()); } } diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ICIFEXRPCServiceFactory.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ICIFEXRPCServiceFactory.java new file mode 100644 index 00000000000..4414a198317 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/ICIFEXRPCServiceFactory.java @@ -0,0 +1,31 @@ +/* + * Copyright 2009 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.dss.generic.server; + +import java.io.Serializable; + +import ch.systemsx.cisd.cifex.rpc.ICIFEXRPCService; + +/** + * + * + * @author Franz-Josef Elmer + */ +public interface ICIFEXRPCServiceFactory extends Serializable +{ + public ICIFEXRPCService createService(); +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java index dd00ef5f85b..026a74554c2 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/UploadingCommand.java @@ -36,6 +36,7 @@ import ch.systemsx.cisd.cifex.shared.basic.Constants; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.utilities.TokenGenerator; +import ch.systemsx.cisd.openbis.generic.shared.dto.DataSetUploadContext; /** * @@ -98,21 +99,21 @@ class UploadingCommand implements IDataSetCommand private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, UploadingCommand.class); - private final ICIFEXRPCService cifexService; + private final ICIFEXRPCServiceFactory cifexServiceFactory; private final List<String> dataSetLocations; private final String comment; private final String userID; private final String password; private final TokenGenerator tokenGenerator; - UploadingCommand(ICIFEXRPCService cifexService, List<String> dataSetLocations, String comment, - String userID, String password) + UploadingCommand(ICIFEXRPCServiceFactory cifexServiceFactory, List<String> dataSetLocations, + DataSetUploadContext context) { - this.cifexService = cifexService; + this.cifexServiceFactory = cifexServiceFactory; this.dataSetLocations = dataSetLocations; - this.userID = userID; - this.password = password; - this.comment = comment; + this.userID = context.getUserID(); + this.password = context.getPassword(); + this.comment = context.getComment(); tokenGenerator = new TokenGenerator(); } @@ -130,6 +131,7 @@ class UploadingCommand implements IDataSetCommand operationLog.info("Zip file " + zipFile + " with " + dataSetLocations.size() + " data sets has been successfully created."); } + ICIFEXRPCService cifexService = cifexServiceFactory.createService(); String sessionToken = cifexService.login(userID, password); Uploader uploader = new Uploader(cifexService, sessionToken); uploader.addProgressListener(new ProgressListener(zipFile)); @@ -199,11 +201,13 @@ class UploadingCommand implements IDataSetCommand IOUtils.closeQuietly(in); zipOutputStream.closeEntry(); } - } - File[] files = file.listFiles(); - for (File childFile : files) + } else { - addTo(zipOutputStream, childFile); + File[] files = file.listFiles(); + for (File childFile : files) + { + addTo(zipOutputStream, childFile); + } } } -- GitLab