JAMES-2525 Provider and bindings for ObjectStorageDAO
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8ecd8bbf Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8ecd8bbf Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8ecd8bbf Branch: refs/heads/master Commit: 8ecd8bbf967970bd0c19b3eeea61283d5ea008a3 Parents: a4872d6 Author: Jean Helou <j...@codamens.fr> Authored: Wed Sep 5 15:34:36 2018 +0200 Committer: Benoit Tellier <btell...@linagora.com> Committed: Thu Oct 11 09:26:14 2018 +0700 ---------------------------------------------------------------------- .../swift/SwiftKeystone2ObjectStorage.java | 2 + .../swift/SwiftKeystone3ObjectStorage.java | 2 + .../swift/SwiftTempAuthObjectStorage.java | 2 + .../ObjectStorageBlobStoreModule.java | 35 ++++++ .../ObjectStorageBlobsDAOProvider.java | 116 +++++++++++++++++++ 5 files changed, 157 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/8ecd8bbf/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java index bf75bcd..fcb1833 100644 --- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone2ObjectStorage.java @@ -38,6 +38,8 @@ import com.google.common.collect.ImmutableSet; import com.google.inject.Module; public class SwiftKeystone2ObjectStorage { + public static final String AUTH_API_NAME = "keystone2"; + private static final Iterable<Module> JCLOUDS_MODULES = ImmutableSet.of(new SLF4JLoggingModule()); http://git-wip-us.apache.org/repos/asf/james-project/blob/8ecd8bbf/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java index c0dcee3..13350ea 100644 --- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftKeystone3ObjectStorage.java @@ -40,6 +40,8 @@ import com.google.common.collect.ImmutableSet; import com.google.inject.Module; public class SwiftKeystone3ObjectStorage { + public static final String AUTH_API_NAME = "keystone2"; + private static final Iterable<Module> JCLOUDS_MODULES = ImmutableSet.of(new SLF4JLoggingModule()); http://git-wip-us.apache.org/repos/asf/james-project/blob/8ecd8bbf/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java ---------------------------------------------------------------------- diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java index b5b1c22..631d63d 100644 --- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java +++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/swift/SwiftTempAuthObjectStorage.java @@ -39,6 +39,8 @@ import com.google.common.collect.ImmutableSet; import com.google.inject.Module; public class SwiftTempAuthObjectStorage { + public static final String AUTH_API_NAME = "tmpauth"; + private static final Iterable<Module> JCLOUDS_MODULES = ImmutableSet.of(new SLF4JLoggingModule()); http://git-wip-us.apache.org/repos/asf/james-project/blob/8ecd8bbf/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java new file mode 100644 index 0000000..85cebf3 --- /dev/null +++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java @@ -0,0 +1,35 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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 org.apache.james.modules.objectstorage; + +import org.apache.james.blob.api.BlobStore; +import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; + +public class ObjectStorageBlobStoreModule extends AbstractModule { + + @Override + protected void configure() { + bind(ObjectStorageBlobsDAO.class).toProvider(ObjectStorageBlobsDAOProvider.class).in(Scopes.SINGLETON); + bind(BlobStore.class).to(ObjectStorageBlobsDAO.class); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/8ecd8bbf/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobsDAOProvider.java ---------------------------------------------------------------------- diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobsDAOProvider.java b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobsDAOProvider.java new file mode 100644 index 0000000..acc98e6 --- /dev/null +++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobsDAOProvider.java @@ -0,0 +1,116 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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 org.apache.james.modules.objectstorage; + +import java.io.FileNotFoundException; +import java.util.function.Function; + +import javax.inject.Inject; +import javax.inject.Provider; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.blob.api.BlobId; +import org.apache.james.blob.objectstorage.ContainerName; +import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO; +import org.apache.james.blob.objectstorage.swift.SwiftKeystone2ObjectStorage; +import org.apache.james.blob.objectstorage.swift.SwiftKeystone3ObjectStorage; +import org.apache.james.blob.objectstorage.swift.SwiftTempAuthObjectStorage; +import org.apache.james.utils.PropertiesProvider; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; + +public class ObjectStorageBlobsDAOProvider implements Provider<ObjectStorageBlobsDAO> { + private static final String OBJECTSTORAGE_CONFIGURATION_NAME = "objectstorage"; + + private static final String OBJECTSTORAGE_NAMESPACE = "objectstorage.namespace"; + private static final String OBJECTSTORAGE_PROVIDER = "objectstorage.provider"; + private static final String OBJECTSTORAGE_SWIFT_AUTH_API = "objectstorage.swift.authapi"; + + public static final String OBJECTSTORAGE_PROVIDER_SWIFT = "swift"; + + private final Configuration configuration; + private final BlobId.Factory blobIdFactory; + private final ImmutableMap<String, Function<ContainerName, ObjectStorageBlobsDAO>> providersByName; + private final ImmutableMap<String, Function<ContainerName, ObjectStorageBlobsDAO>> swiftAuthApiByName; + + @Inject + public ObjectStorageBlobsDAOProvider(PropertiesProvider propertiesProvider, + BlobId.Factory blobIdFactory) throws ConfigurationException { + providersByName = ImmutableMap.<String, Function<ContainerName, ObjectStorageBlobsDAO>>builder() + .put(OBJECTSTORAGE_PROVIDER_SWIFT, this::getSwiftObjectStorageBlobsDao) + .build(); + swiftAuthApiByName = ImmutableMap.<String, Function<ContainerName, ObjectStorageBlobsDAO>>builder() + .put(SwiftTempAuthObjectStorage.AUTH_API_NAME, this::getTempAuthBlobsDao) + .put(SwiftKeystone2ObjectStorage.AUTH_API_NAME, this::getKeystone2BlobsDao) + .put(SwiftKeystone3ObjectStorage.AUTH_API_NAME, this::getKeystone3Configuration) + .build(); + + this.blobIdFactory = blobIdFactory; + try { + this.configuration = propertiesProvider.getConfiguration(OBJECTSTORAGE_CONFIGURATION_NAME); + } catch (FileNotFoundException e) { + throw new ConfigurationException(OBJECTSTORAGE_CONFIGURATION_NAME + " configuration " + + "was not found"); + } + } + + @Override + public ObjectStorageBlobsDAO get() { + String provider = configuration.getString(OBJECTSTORAGE_PROVIDER, null); + String namespace = configuration.getString(OBJECTSTORAGE_NAMESPACE, null); + Preconditions.checkArgument(provider != null, + "Mandatory configuration value " + OBJECTSTORAGE_PROVIDER + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration"); + Preconditions.checkArgument(namespace != null, + "Mandatory configuration value " + OBJECTSTORAGE_NAMESPACE + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration"); + + return providersByName.get(provider).apply(ContainerName.of(namespace)); + } + + private ObjectStorageBlobsDAO getSwiftObjectStorageBlobsDao(ContainerName containerName) { + String authApi = configuration.getString(OBJECTSTORAGE_SWIFT_AUTH_API, null); + Preconditions.checkArgument(authApi != null, + "Mandatory configuration value " + OBJECTSTORAGE_PROVIDER + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration"); + return swiftAuthApiByName.get(authApi).apply(containerName); + } + + private ObjectStorageBlobsDAO getTempAuthBlobsDao(ContainerName containerName) { + return ObjectStorageBlobsDAO.builder(SwiftTmpAuthConfigurationReader.readSwiftConfiguration(configuration)) + .blobIdFactory(blobIdFactory) + .container(containerName) + .build(); + + } + + private ObjectStorageBlobsDAO getKeystone2BlobsDao(ContainerName containerName) { + return ObjectStorageBlobsDAO.builder(SwiftKeystone2ConfigurationReader.readSwiftConfiguration(configuration)) + .blobIdFactory(blobIdFactory) + .container(containerName) + .build(); + } + + private ObjectStorageBlobsDAO getKeystone3Configuration(ContainerName containerName) { + return ObjectStorageBlobsDAO.builder(SwiftKeystone3ConfigurationReader.readSwiftConfiguration(configuration)) + .blobIdFactory(blobIdFactory) + .container(containerName) + .build(); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org