james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [james-project] 02/06: JAMES-2741 Implement new save method for Strings in BlobStore
Date Mon, 29 Apr 2019 08:09:34 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit c496a877aada006b8f868f11b56739f6699e44a9
Author: Rene Cordier <rcordier@linagora.com>
AuthorDate: Thu Apr 18 17:53:41 2019 +0700

    JAMES-2741 Implement new save method for Strings in BlobStore
---
 .../src/main/java/org/apache/james/blob/api/BlobStore.java  |  5 +++++
 .../org/apache/james/blob/cassandra/CassandraBlobsDAO.java  |  1 +
 .../james/blob/objectstorage/ObjectStorageBlobsDAO.java     |  1 +
 .../java/org/apache/james/blob/union/UnionBlobStore.java    | 13 +++++++++++++
 .../org/apache/james/blob/union/UnionBlobStoreTest.java     | 10 ++++++++++
 5 files changed, 30 insertions(+)

diff --git a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java
index 3d28ab5..d22be29 100644
--- a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java
+++ b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java
@@ -19,6 +19,7 @@
 package org.apache.james.blob.api;
 
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 
 import reactor.core.publisher.Mono;
 
@@ -31,4 +32,8 @@ public interface BlobStore {
     Mono<byte[]> readBytes(BlobId blobId);
 
     InputStream read(BlobId blobId);
+
+    default Mono<BlobId> save(String data) {
+        return save(data.getBytes(StandardCharsets.UTF_8));
+    }
 }
diff --git a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
index 3a9d88d..b637601 100644
--- a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
+++ b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
@@ -51,6 +51,7 @@ import com.datastax.driver.core.Session;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.Bytes;
+
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 import reactor.core.scheduler.Schedulers;
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
index 857553d..6000680 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
@@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Preconditions;
 import com.google.common.hash.Hashing;
 import com.google.common.hash.HashingInputStream;
+
 import reactor.core.publisher.Mono;
 
 public class ObjectStorageBlobsDAO implements BlobStore {
diff --git a/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
b/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
index ee02c8d..07d0830 100644
--- a/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
+++ b/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
 import com.github.fge.lambdas.Throwing;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
+
 import reactor.core.publisher.Mono;
 
 public class UnionBlobStore implements BlobStore {
@@ -92,6 +93,18 @@ public class UnionBlobStore implements BlobStore {
     }
 
     @Override
+    public Mono<BlobId> save(String data) {
+        try {
+            return saveToCurrentFallbackIfFails(
+                Mono.defer(() -> currentBlobStore.save(data)),
+                () -> Mono.defer(() -> legacyBlobStore.save(data)));
+        } catch (Exception e) {
+            LOGGER.error("exception directly happens while saving String data, fall back
to legacy blob store", e);
+            return legacyBlobStore.save(data);
+        }
+    }
+
+    @Override
     public Mono<BlobId> save(InputStream data, long contentLength) {
         try {
             return saveToCurrentFallbackIfFails(
diff --git a/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
b/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
index f044606..f2f875e 100644
--- a/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
+++ b/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
@@ -61,6 +61,11 @@ class UnionBlobStoreTest implements BlobStoreContract {
         }
 
         @Override
+        public Mono<BlobId> save(String data) {
+            return Mono.error(new RuntimeException("broken everywhere"));
+        }
+
+        @Override
         public Mono<BlobId> save(InputStream data, long contentLength) {
             return Mono.error(new RuntimeException("broken everywhere"));
         }
@@ -90,6 +95,11 @@ class UnionBlobStoreTest implements BlobStoreContract {
         }
 
         @Override
+        public Mono<BlobId> save(String data) {
+            throw new RuntimeException("broken everywhere");
+        }
+
+        @Override
         public Mono<BlobId> save(InputStream data, long contentLength) {
             throw new RuntimeException("broken everywhere");
         }


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


Mime
View raw message