james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [08/15] james-project git commit: JAMES-2202 Handle a read and a write alias
Date Wed, 01 Nov 2017 11:00:06 GMT
JAMES-2202 Handle a read and a write alias


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

Branch: refs/heads/master
Commit: 27fe978053a1e0a829c34f49f6767a4839861041
Parents: fc927f0
Author: benwa <btellier@linagora.com>
Authored: Thu Oct 26 09:02:26 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Nov 1 17:55:04 2017 +0700

----------------------------------------------------------------------
 .../james/backends/es/IndexCreationFactory.java | 13 +++---
 .../backends/es/ElasticSearchIndexerTest.java   |  2 +-
 .../backends/es/IndexCreationFactoryTest.java   | 46 +++++++++++++++++++-
 .../backends/es/NodeMappingFactoryTest.java     |  2 +-
 .../backends/es/search/ScrollIterableTest.java  |  2 +-
 .../ElasticSearchIntegrationTest.java           |  6 +--
 .../host/ElasticSearchHostSystem.java           |  2 +-
 .../mailbox/ElasticSearchConfiguration.java     | 22 +++++-----
 .../mailbox/ElasticSearchMailboxModule.java     |  2 +-
 .../james/modules/TestElasticSearchModule.java  |  2 +-
 10 files changed, 71 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
index a4bcc84..3fedaea 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexCreationFactory.java
@@ -22,6 +22,7 @@ package org.apache.james.backends.es;
 import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Optional;
 
 import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
@@ -33,7 +34,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
 
 public class IndexCreationFactory {
 
@@ -43,18 +43,18 @@ public class IndexCreationFactory {
     public static final String CASE_INSENSITIVE = "case_insensitive";
 
     private IndexName indexName;
-    private ImmutableList.Builder<AliasName> aliases;
+    private ArrayList<AliasName> aliases;
     private Optional<Integer> nbShards;
     private Optional<Integer> nbReplica;
 
     public IndexCreationFactory() {
         indexName = null;
-        aliases = ImmutableList.builder();
+        aliases = new ArrayList<>();
         nbShards = Optional.empty();
         nbReplica = Optional.empty();
     }
 
-    public IndexCreationFactory onIndex(IndexName indexName) {
+    public IndexCreationFactory useIndex(IndexName indexName) {
         Preconditions.checkNotNull(indexName);
         this.indexName = indexName;
         return this;
@@ -67,11 +67,13 @@ public class IndexCreationFactory {
     }
 
     public IndexCreationFactory nbShards(int nbShards) {
+        Preconditions.checkArgument(nbShards > 0, "You need the number of shards to be
strictly positive");
         this.nbShards = Optional.of(nbShards);
         return this;
     }
 
     public IndexCreationFactory nbReplica(int nbReplica) {
+        Preconditions.checkArgument(nbReplica >= 0, "You need the number of replica to
be positive");
         this.nbReplica = Optional.of(nbReplica);
         return this;
     }
@@ -82,8 +84,7 @@ public class IndexCreationFactory {
             createIndexIfNeeded(client, indexName, generateSetting(
                 nbShards.orElse(DEFAULT_NB_SHARDS),
                 nbReplica.orElse(DEFAULT_NB_REPLICA)));
-            aliases.build()
-                .forEach(alias -> createAliasIfNeeded(client, indexName, alias));
+            aliases.forEach(alias -> createAliasIfNeeded(client, indexName, alias));
         } catch (IOException e) {
             LOGGER.error("Error while creating index : ", e);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
index a3a6d9c..1b7a3e3 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchIndexerTest.java
@@ -59,7 +59,7 @@ public class ElasticSearchIndexerTest {
         node = embeddedElasticSearch.getNode();
         TestingClientProvider clientProvider = new TestingClientProvider(node);
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
         DeleteByQueryPerformer deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider.get(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
index 7735eb9..f02048d 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/IndexCreationFactoryTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.backends.es;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 import org.apache.james.backends.es.utils.TestingClientProvider;
 import org.junit.Before;
 import org.junit.Rule;
@@ -42,7 +44,7 @@ public class IndexCreationFactoryTest {
     public void setUp() {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
     }
@@ -50,8 +52,48 @@ public class IndexCreationFactoryTest {
     @Test
     public void createIndexAndAliasShouldNotThrowWhenCalledSeveralTime() {
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
     }
+
+    @Test
+    public void useIndexShouldThrowWhenNull() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .useIndex(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void addAliasShouldThrowWhenNull() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .addAlias(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    public void nbReplicaShouldThrowWhenNegative() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .nbReplica(-1))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    public void nbShardsShouldThrowWhenNegative() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .nbShards(-1))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    public void nbShardsShouldThrowWhenZero() {
+        assertThatThrownBy(() ->
+            new IndexCreationFactory()
+                .nbShards(0))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
index 1e0eb79..42a403f 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/NodeMappingFactoryTest.java
@@ -47,7 +47,7 @@ public class NodeMappingFactoryTest {
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
         NodeMappingFactory.applyMapping(clientProvider.get(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
index b296b8e..dbba300 100644
--- a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
+++ b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/search/ScrollIterableTest.java
@@ -68,7 +68,7 @@ public class ScrollIterableTest {
     public void setUp() throws Exception {
         clientProvider = new TestingClientProvider(embeddedElasticSearch.getNode());
         new IndexCreationFactory()
-            .onIndex(INDEX_NAME)
+            .useIndex(INDEX_NAME)
             .addAlias(ALIAS_NAME)
             .createIndexAndAliases(clientProvider.get());
         embeddedElasticSearch.awaitForElasticSearch();

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index e380864..cf3a9cc 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -111,9 +111,9 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     protected void initializeMailboxManager() throws Exception {
         Client client = NodeMappingFactory.applyMapping(
             new IndexCreationFactory()
-                .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
-                .addAlias( MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
-                .addAlias( MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
+                .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+                .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
+                .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
                 .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),
             MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX,
             MailboxElasticSearchConstants.MESSAGE_TYPE,

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 0817c25..4d6d184 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -96,7 +96,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
     private void initFields() {
         Client client = NodeMappingFactory.applyMapping(
             new IndexCreationFactory()
-                .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+                .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
                 .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
                 .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
                 .createIndexAndAliases(new TestingClientProvider(embeddedElasticSearch.getNode()).get()),

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
index 8d95228..3fc502f 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchConfiguration.java
@@ -91,35 +91,35 @@ public class ElasticSearchConfiguration {
     }
 
     private static ImmutableList<Host> getHosts(PropertiesConfiguration propertiesReader)
throws ConfigurationException {
-        Optional<String> monoHostAddress = Optional.ofNullable(
+        Optional<String> masterHost = Optional.ofNullable(
             propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, null));
-        Optional<Integer> monoHostPort = Optional.ofNullable(
+        Optional<Integer> masterPort = Optional.ofNullable(
             propertiesReader.getInteger(ELASTICSEARCH_PORT, null));
         Optional<String> multiHosts = Optional.ofNullable(
             propertiesReader.getString(ELASTICSEARCH_HOSTS, null));
 
-        validateHostsConfigurationOptions(monoHostAddress, monoHostPort, multiHosts);
+        validateHostsConfigurationOptions(masterHost, masterPort, multiHosts);
 
-        if (monoHostAddress.isPresent()) {
+        if (masterHost.isPresent()) {
             return ImmutableList.of(
-                Host.from(monoHostAddress.get(),
-                monoHostPort.get()));
+                Host.from(masterHost.get(),
+                masterPort.get()));
         } else {
             return Host.parseHosts(multiHosts.get(), DEFAULT_PORT);
         }
     }
 
     @VisibleForTesting
-    static void validateHostsConfigurationOptions(Optional<String> monoHostAddress,
-                                                  Optional<Integer> monoHostPort,
+    static void validateHostsConfigurationOptions(Optional<String> masterHost,
+                                                  Optional<Integer> masterPort,
                                                   Optional<String> multiHosts) throws
ConfigurationException {
-        if (monoHostAddress.isPresent() != monoHostPort.isPresent()) {
+        if (masterHost.isPresent() != masterPort.isPresent()) {
             throw new ConfigurationException(ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT
+ " should be specified together");
         }
-        if (multiHosts.isPresent() && monoHostAddress.isPresent()) {
+        if (multiHosts.isPresent() && masterHost.isPresent()) {
             throw new ConfigurationException("You should choose between mono host set up
and " + ELASTICSEARCH_HOSTS);
         }
-        if (!multiHosts.isPresent() && !monoHostAddress.isPresent()) {
+        if (!multiHosts.isPresent() && !masterHost.isPresent()) {
             throw new ConfigurationException("You should specify either (" + ELASTICSEARCH_MASTER_HOST
+ " and " + ELASTICSEARCH_PORT + ") or " + ELASTICSEARCH_HOSTS);
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
index bab0ae3..82f27a4 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
@@ -100,7 +100,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     @Singleton
     protected IndexCreationFactory provideIndexCreationFactory(ElasticSearchConfiguration
configuration) {
         return new IndexCreationFactory()
-            .onIndex(configuration.getIndexName())
+            .useIndex(configuration.getIndexName())
             .addAlias(configuration.getReadAliasName())
             .addAlias(configuration.getWriteAliasName())
             .nbShards(configuration.getNbShards())

http://git-wip-us.apache.org/repos/asf/james-project/blob/27fe9780/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
index 8cd728c..428f160 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java
@@ -51,7 +51,7 @@ public class TestElasticSearchModule extends AbstractModule{
         Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get();
 
         new IndexCreationFactory()
-            .onIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
+            .useIndex(MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX)
             .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_READ_ALIAS)
             .addAlias(MailboxElasticSearchConstants.DEFAULT_MAILBOX_WRITE_ALIAS)
             .createIndexAndAliases(client);


---------------------------------------------------------------------
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