JAMES-2589 bind Swift in cassandra-rabbit product

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/579c8739
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/579c8739
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/579c8739

Branch: refs/heads/master
Commit: 579c873979f66db49e7d5cbb2c59e31e16500af0
Parents: 4d07616
Author: Matthieu Baechler <matth...@apache.org>
Authored: Mon Nov 12 17:15:26 2018 +0100
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Wed Nov 14 11:19:34 2018 +0700

----------------------------------------------------------------------
 .../ObjectStorageBlobStoreModule.java           | 11 +++--
 .../guice/DockerSwiftTestRule.java              | 21 +++++----
 .../guice/cassandra-rabbitmq-guice/pom.xml      |  6 +++
 .../james/CassandraRabbitMQJamesServerMain.java |  7 ++-
 .../james/CassandraRabbitMQJamesServerTest.java |  2 +
 .../CassandraRabbitMQJmapJamesServerTest.java   |  2 +
 .../james/modules/SwiftBlobStoreExtension.java  | 46 ++++++++++++++++++++
 7 files changed, 79 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/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
index d31ec08..4c020f8 100644
--- 
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
@@ -19,19 +19,24 @@
 
 package org.apache.james.modules.objectstorage;
 
-import org.apache.james.blob.api.BlobId;
 import org.apache.james.blob.api.BlobStore;
-import org.apache.james.blob.api.HashBlobId;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
 
 public class ObjectStorageBlobStoreModule extends AbstractModule {
 
     @Override
     protected void configure() {
         install(new ObjectStorageDependenciesModule());
-        bind(BlobStore.class).to(ObjectStorageBlobsDAO.class);
     }
 
+    @Provides
+    @Singleton
+    private BlobStore provideBlobStore(ObjectStorageBlobsDAO dao, 
ObjectStorageBlobConfiguration configuration) {
+        dao.createContainer(configuration.getNamespace());
+        return dao;
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
index 82c56af..b9e42a9 100644
--- 
a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
+++ 
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/guice/DockerSwiftTestRule.java
@@ -47,6 +47,7 @@ import com.google.inject.util.Modules;
 
 public class DockerSwiftTestRule implements GuiceModuleTestRule {
 
+    private final PayloadCodecFactory payloadCodecFactory;
     private org.apache.james.blob.objectstorage.DockerSwiftRule swiftContainer 
=
         new org.apache.james.blob.objectstorage.DockerSwiftRule();
     private PayloadCodec payloadCodec;
@@ -56,7 +57,7 @@ public class DockerSwiftTestRule implements 
GuiceModuleTestRule {
     }
 
     public DockerSwiftTestRule(PayloadCodecFactory payloadCodecFactory) {
-        //Will be fixed in next commit
+        this.payloadCodecFactory = payloadCodecFactory;
     }
 
     @Override
@@ -70,7 +71,7 @@ public class DockerSwiftTestRule implements 
GuiceModuleTestRule {
 
     @Override
     public Module getModule() {
-        SwiftKeystone2ObjectStorage.Configuration configuration = 
SwiftKeystone2ObjectStorage.configBuilder()
+        SwiftKeystone2ObjectStorage.Configuration authConfiguration = 
SwiftKeystone2ObjectStorage.configBuilder()
             .credentials(Credentials.of("demo"))
             .tenantName(TenantName.of("test"))
             .userName(UserName.of("demo"))
@@ -78,14 +79,16 @@ public class DockerSwiftTestRule implements 
GuiceModuleTestRule {
             .build();
 
         ContainerName containerName = 
ContainerName.of(UUID.randomUUID().toString());
-        ObjectStorageBlobsDAO dao = 
SwiftKeystone2ObjectStorage.daoBuilder(configuration)
+        ObjectStorageBlobConfiguration configuration = 
ObjectStorageBlobConfiguration.builder()
+            .codec(payloadCodecFactory)
+            .swift()
             .container(containerName)
-            .blobIdFactory(new HashBlobId.Factory())
-            .payloadCodec(payloadCodec)
+            .keystone2(authConfiguration)
+            .aesSalt("c603a7327ee3dcbc031d8d34b1096c605feca5e1")
+            .aesPassword("dockerSwiftEncryption".toCharArray())
             .build();
 
-        Throwing.supplier(() -> 
dao.createContainer(containerName).get()).sneakyThrow().get();
-        return Modules.combine((binder) -> 
binder.bind(BlobStore.class).toInstance(dao));
+        return binder -> 
binder.bind(ObjectStorageBlobConfiguration.class).toInstance(configuration);
     }
 
 
@@ -97,8 +100,4 @@ public class DockerSwiftTestRule implements 
GuiceModuleTestRule {
         swiftContainer.stop();
     }
 
-    public GenericContainer<?> getRawContainer() {
-        return swiftContainer.getRawContainer();
-    }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/server/container/guice/cassandra-rabbitmq-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-guice/pom.xml 
b/server/container/guice/cassandra-rabbitmq-guice/pom.xml
index 79ded79..c0477fb 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/pom.xml
+++ b/server/container/guice/cassandra-rabbitmq-guice/pom.xml
@@ -83,6 +83,12 @@
         </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
+            <artifactId>blob-objectstorage</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
             <artifactId>blob-objectstorage-guice</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
 
b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
index da0a1a0..6a2038c 100644
--- 
a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
+++ 
b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/CassandraRabbitMQJamesServerMain.java
@@ -21,6 +21,7 @@ package org.apache.james;
 
 import static 
org.apache.james.CassandraJamesServerMain.ALL_BUT_JMX_CASSANDRA_MODULE;
 
+import org.apache.james.modules.objectstorage.ObjectStorageBlobStoreModule;
 import org.apache.james.modules.rabbitmq.RabbitMQModule;
 import org.apache.james.modules.server.JMXServerModule;
 import org.apache.james.server.core.configuration.Configuration;
@@ -29,8 +30,10 @@ import com.google.inject.Module;
 import com.google.inject.util.Modules;
 
 public class CassandraRabbitMQJamesServerMain {
-    public static final Module MODULES = 
Modules.override(ALL_BUT_JMX_CASSANDRA_MODULE)
-        .with(new RabbitMQModule());
+    public static final Module MODULES =
+        Modules
+            .override(Modules.combine(ALL_BUT_JMX_CASSANDRA_MODULE))
+            .with(new RabbitMQModule(), new ObjectStorageBlobStoreModule());
 
     public static void main(String[] args) throws Exception {
         Configuration configuration = Configuration.builder()

http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
index d925ebb..64c4e8a 100644
--- 
a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
+++ 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJamesServerTest.java
@@ -23,6 +23,7 @@ import static 
org.awaitility.Duration.ONE_HUNDRED_MILLISECONDS;
 
 import org.apache.james.core.Domain;
 import org.apache.james.modules.RabbitMQExtension;
+import org.apache.james.modules.SwiftBlobStoreExtension;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.apache.james.modules.protocols.ImapGuiceProbe;
 import org.apache.james.modules.protocols.SmtpGuiceProbe;
@@ -57,6 +58,7 @@ class CassandraRabbitMQJamesServerTest implements 
JmapJamesServerContract {
             .extension(new EmbeddedElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new RabbitMQExtension())
+            .extension(new SwiftBlobStoreExtension())
             .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
                     .combineWith(CassandraRabbitMQJamesServerMain.MODULES)
                     .overrideWith(new 
TestJMAPServerModule(LIMIT_TO_10_MESSAGES))

http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJmapJamesServerTest.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJmapJamesServerTest.java
 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJmapJamesServerTest.java
index 0cb02b7..775bc3d 100644
--- 
a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJmapJamesServerTest.java
+++ 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQJmapJamesServerTest.java
@@ -20,6 +20,7 @@
 package org.apache.james;
 
 import org.apache.james.modules.RabbitMQExtension;
+import org.apache.james.modules.SwiftBlobStoreExtension;
 import org.apache.james.modules.TestJMAPServerModule;
 import org.junit.jupiter.api.extension.RegisterExtension;
 
@@ -31,6 +32,7 @@ public class CassandraRabbitMQJmapJamesServerTest implements 
JmapJamesServerCont
             .extension(new EmbeddedElasticSearchExtension())
             .extension(new CassandraExtension())
             .extension(new RabbitMQExtension())
+            .extension(new SwiftBlobStoreExtension())
             .server(configuration -> 
GuiceJamesServer.forConfiguration(configuration)
                     .combineWith(CassandraRabbitMQJamesServerMain.MODULES)
                     .overrideWith(new 
TestJMAPServerModule(LIMIT_TO_10_MESSAGES))

http://git-wip-us.apache.org/repos/asf/james-project/blob/579c8739/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
new file mode 100644
index 0000000..5d7b25f
--- /dev/null
+++ 
b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/SwiftBlobStoreExtension.java
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.modules.objectstorage.guice.DockerSwiftTestRule;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+import com.google.inject.Module;
+
+public class SwiftBlobStoreExtension implements GuiceModuleTestExtension {
+
+    private final DockerSwiftTestRule swiftRule = new DockerSwiftTestRule();
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        swiftRule.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        swiftRule.stop();
+    }
+
+    @Override
+    public Module getModule() {
+        return swiftRule.getModule();
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to