You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2023/11/03 07:05:29 UTC

(james-project) 02/04: JAMES-3953 Guice injections for File blob store

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit c704a8f7464c151a9fe207654902336f70f97af6
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Sun Oct 29 21:21:36 2023 +0100

    JAMES-3953 Guice injections for File blob store
---
 pom.xml                                            |  5 +++++
 .../apache/james/blob/file/FileBlobStoreDAO.java   |  3 +++
 server/container/guice/distributed/pom.xml         |  4 ++++
 .../modules/blobstore/BlobStoreConfiguration.java  |  5 +++++
 .../modules/blobstore/BlobStoreModulesChooser.java | 12 +++++++++++
 .../blobstore/BlobStoreConfigurationTest.java      | 25 ++++++++++++++++++----
 6 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9a51b77cb9..048c9bf723 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1115,6 +1115,11 @@
                 <version>${project.version}</version>
                 <type>test-jar</type>
             </dependency>
+            <dependency>
+                <groupId>${james.groupId}</groupId>
+                <artifactId>blob-file</artifactId>
+                <version>${project.version}</version>
+            </dependency>
             <dependency>
                 <groupId>${james.groupId}</groupId>
                 <artifactId>blob-memory</artifactId>
diff --git a/server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java b/server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java
index 4e4908fc01..7a56929735 100644
--- a/server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java
+++ b/server/blob/blob-file/src/main/java/org/apache/james/blob/file/FileBlobStoreDAO.java
@@ -34,6 +34,8 @@ import java.nio.file.NoSuchFileException;
 import java.time.Duration;
 import java.util.Collection;
 
+import javax.inject.Inject;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.blob.api.BlobId;
@@ -58,6 +60,7 @@ public class FileBlobStoreDAO implements BlobStoreDAO {
     private final File root;
     private final  BlobId.Factory blobIdFactory;
 
+    @Inject
     public FileBlobStoreDAO(FileSystem fileSystem, BlobId.Factory blobIdFactory) throws FileNotFoundException {
         root = fileSystem.getFile("file://var/blob");
         this.blobIdFactory = blobIdFactory;
diff --git a/server/container/guice/distributed/pom.xml b/server/container/guice/distributed/pom.xml
index d593089fd8..f8c2c965de 100644
--- a/server/container/guice/distributed/pom.xml
+++ b/server/container/guice/distributed/pom.xml
@@ -59,6 +59,10 @@
             <groupId>${james.groupId}</groupId>
             <artifactId>blob-deduplication-gc-guice</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>blob-file</artifactId>
+        </dependency>
         <dependency>
             <groupId>${james.groupId}</groupId>
             <artifactId>blob-s3-guice</artifactId>
diff --git a/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreConfiguration.java b/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreConfiguration.java
index ba9a3834fb..5b344994e6 100644
--- a/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreConfiguration.java
+++ b/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreConfiguration.java
@@ -52,6 +52,10 @@ public class BlobStoreConfiguration {
             return implementation(BlobStoreImplName.CASSANDRA);
         }
 
+        default RequireCache file() {
+            return implementation(BlobStoreImplName.FILE);
+        }
+
         default RequireCache s3() {
             return implementation(BlobStoreImplName.S3);
         }
@@ -103,6 +107,7 @@ public class BlobStoreConfiguration {
 
     public enum BlobStoreImplName {
         CASSANDRA("cassandra"),
+        FILE("file"),
         S3("s3");
 
         static String supportedImplNames() {
diff --git a/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java b/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
index ccb4625c41..eed9361f89 100644
--- a/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
+++ b/server/container/guice/distributed/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
@@ -29,6 +29,7 @@ import org.apache.james.blob.api.BlobStoreDAO;
 import org.apache.james.blob.api.ObjectStorageHealthCheck;
 import org.apache.james.blob.cassandra.CassandraBlobStoreDAO;
 import org.apache.james.blob.cassandra.cache.CachedBlobStore;
+import org.apache.james.blob.file.FileBlobStoreDAO;
 import org.apache.james.blob.objectstorage.aws.S3BlobStoreDAO;
 import org.apache.james.core.healthcheck.HealthCheck;
 import org.apache.james.modules.blobstore.validation.BlobStoreConfigurationValidationStartUpCheck.StorageStrategySupplier;
@@ -75,6 +76,15 @@ public class BlobStoreModulesChooser {
         }
     }
 
+    static class FileBlobStoreDAODeclarationModule extends AbstractModule {
+        @Override
+        protected void configure() {
+            install(new CassandraBucketModule());
+
+            bind(BlobStoreDAO.class).annotatedWith(Names.named(UNENCRYPTED)).to(FileBlobStoreDAO.class);
+        }
+    }
+
     static class NoEncryptionModule extends AbstractModule {
         @Provides
         @Singleton
@@ -119,6 +129,8 @@ public class BlobStoreModulesChooser {
                 return new CassandraBlobStoreDAODeclarationModule();
             case S3:
                 return new ObjectStorageBlobStoreDAODeclarationModule();
+            case FILE:
+                return new FileBlobStoreDAODeclarationModule();
             default:
                 throw new RuntimeException("Unsupported blobStore implementation " + implementation);
         }
diff --git a/server/container/guice/distributed/src/test/java/org/apache/james/modules/blobstore/BlobStoreConfigurationTest.java b/server/container/guice/distributed/src/test/java/org/apache/james/modules/blobstore/BlobStoreConfigurationTest.java
index a0c7ef9301..4bd6ea3ece 100644
--- a/server/container/guice/distributed/src/test/java/org/apache/james/modules/blobstore/BlobStoreConfigurationTest.java
+++ b/server/container/guice/distributed/src/test/java/org/apache/james/modules/blobstore/BlobStoreConfigurationTest.java
@@ -217,13 +217,30 @@ class BlobStoreConfigurationTest {
                     .noCryptoConfig());
     }
 
+    @Test
+    void provideChoosingConfigurationShouldReturnFileFactoryWhenConfigurationImplIsFile() throws Exception {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        configuration.addProperty("implementation", BlobStoreConfiguration.BlobStoreImplName.FILE.getName());
+        configuration.addProperty("deduplication.enable", "false");
+        FakePropertiesProvider propertyProvider = FakePropertiesProvider.builder()
+            .register(ConfigurationComponent.NAME, configuration)
+            .build();
+
+        assertThat(parse(propertyProvider))
+            .isEqualTo(BlobStoreConfiguration.builder()
+                    .file()
+                    .disableCache()
+                    .passthrough()
+                    .noCryptoConfig());
+    }
+
     @Test
     void fromShouldThrowWhenBlobStoreImplIsMissing() {
         PropertiesConfiguration configuration = new PropertiesConfiguration();
 
         assertThatThrownBy(() -> BlobStoreConfiguration.from(configuration))
             .isInstanceOf(IllegalStateException.class)
-            .hasMessage("implementation property is missing please use one of supported values in: cassandra, s3");
+            .hasMessage("implementation property is missing please use one of supported values in: cassandra, file, s3");
     }
 
     @Test
@@ -233,7 +250,7 @@ class BlobStoreConfigurationTest {
 
         assertThatThrownBy(() -> BlobStoreConfiguration.from(configuration))
             .isInstanceOf(IllegalStateException.class)
-            .hasMessage("implementation property is missing please use one of supported values in: cassandra, s3");
+            .hasMessage("implementation property is missing please use one of supported values in: cassandra, file, s3");
     }
 
     @Test
@@ -243,7 +260,7 @@ class BlobStoreConfigurationTest {
 
         assertThatThrownBy(() -> BlobStoreConfiguration.from(configuration))
             .isInstanceOf(IllegalStateException.class)
-            .hasMessage("implementation property is missing please use one of supported values in: cassandra, s3");
+            .hasMessage("implementation property is missing please use one of supported values in: cassandra, file, s3");
     }
 
     @Test
@@ -253,7 +270,7 @@ class BlobStoreConfigurationTest {
 
         assertThatThrownBy(() -> BlobStoreConfiguration.from(configuration))
             .isInstanceOf(IllegalArgumentException.class)
-            .hasMessage("un_supported is not a valid name of BlobStores, please use one of supported values in: cassandra, s3");
+            .hasMessage("un_supported is not a valid name of BlobStores, please use one of supported values in: cassandra, file, s3");
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org