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

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

commit a7b2cf7b74ca19c4a3391b03514a4e0b18eff1f3
Author: Matthieu Baechler <matth...@apache.org>
AuthorDate: Wed Jun 19 15:49:22 2019 +0200

    JAMES-2803 ElasticSearch cluster name is no longer useful when using REST 
API
---
 .../james/backends/es/ClientProviderImpl.java      | 11 ------
 .../backends/es/ElasticSearchConfiguration.java    | 21 +---------
 .../es/ElasticSearchConfigurationTest.java         | 46 ----------------------
 3 files changed, 2 insertions(+), 76 deletions(-)

diff --git 
a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
 
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
index 7816e8d..98611df 100644
--- 
a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
+++ 
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ClientProviderImpl.java
@@ -22,9 +22,7 @@ import org.apache.http.HttpHost;
 import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestClientBuilder;
 import org.elasticsearch.client.RestHighLevelClient;
-import org.elasticsearch.common.settings.Settings;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
 public class ClientProviderImpl implements ClientProvider {
@@ -34,7 +32,6 @@ public class ClientProviderImpl implements ClientProvider {
         return new ClientProviderImpl(configuration);
     }
 
-    private static final String CLUSTER_NAME_SETTING = "cluster.name";
     private static final String HTTP_HOST_SCHEME = "http";
     private final ElasticSearchConfiguration configuration;
 
@@ -54,12 +51,4 @@ public class ClientProviderImpl implements ClientProvider {
             
.setMaxRetryTimeoutMillis(Math.toIntExact(configuration.getRequestTimeout().toMillis()));
         return new RestHighLevelClient(restClient);
     }
-
-    @VisibleForTesting Settings settings() {
-        return configuration.getClusterName()
-            .map(clusterName -> Settings.builder()
-                .put(CLUSTER_NAME_SETTING, clusterName)
-                .build())
-            .orElse(Settings.EMPTY);
-    }
 }
diff --git 
a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConfiguration.java
 
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConfiguration.java
index ed3199d..24635f5 100644
--- 
a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConfiguration.java
+++ 
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchConfiguration.java
@@ -42,7 +42,6 @@ public class ElasticSearchConfiguration {
     public static class Builder {
 
         private final ImmutableList.Builder<Host> hosts;
-        private Optional<String> clusterName;
         private Optional<Integer> nbShards;
         private Optional<Integer> nbReplica;
         private Optional<Integer> minDelay;
@@ -51,7 +50,6 @@ public class ElasticSearchConfiguration {
 
         public Builder() {
             hosts = ImmutableList.builder();
-            clusterName = Optional.empty();
             nbShards = Optional.empty();
             nbReplica = Optional.empty();
             minDelay = Optional.empty();
@@ -64,11 +62,6 @@ public class ElasticSearchConfiguration {
             return this;
         }
 
-        public Builder clusterName(String clusterName) {
-            this.clusterName = Optional.ofNullable(clusterName);
-            return this;
-        }
-
         public Builder addHosts(Collection<Host> hosts) {
             this.hosts.addAll(hosts);
             return this;
@@ -106,7 +99,6 @@ public class ElasticSearchConfiguration {
             Preconditions.checkState(!hosts.isEmpty(), "You need to specify 
ElasticSearch host");
             return new ElasticSearchConfiguration(
                 hosts,
-                clusterName,
                 nbShards.orElse(DEFAULT_NB_SHARDS),
                 nbReplica.orElse(DEFAULT_NB_REPLICA),
                 minDelay.orElse(DEFAULT_CONNECTION_MIN_DELAY),
@@ -120,7 +112,6 @@ public class ElasticSearchConfiguration {
     }
 
     public static final String ELASTICSEARCH_HOSTS = "elasticsearch.hosts";
-    public static final String ELASTICSEARCH_CLUSTER_NAME = 
"elasticsearch.clusterName";
     public static final String ELASTICSEARCH_MASTER_HOST = 
"elasticsearch.masterHost";
     public static final String ELASTICSEARCH_PORT = "elasticsearch.port";
     public static final String ELASTICSEARCH_NB_REPLICA = 
"elasticsearch.nb.replica";
@@ -144,7 +135,6 @@ public class ElasticSearchConfiguration {
     public static ElasticSearchConfiguration fromProperties(Configuration 
configuration) throws ConfigurationException {
         return builder()
             .addHosts(getHosts(configuration))
-            .clusterName(configuration.getString(ELASTICSEARCH_CLUSTER_NAME))
             .nbShards(configuration.getInteger(ELASTICSEARCH_NB_SHARDS, 
DEFAULT_NB_SHARDS))
             .nbReplica(configuration.getInteger(ELASTICSEARCH_NB_REPLICA, 
DEFAULT_NB_REPLICA))
             
.minDelay(Optional.ofNullable(configuration.getInteger(ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY,
 null)))
@@ -189,16 +179,14 @@ public class ElasticSearchConfiguration {
     }
 
     private final ImmutableList<Host> hosts;
-    private final Optional<String> clusterName;
     private final int nbShards;
     private final int nbReplica;
     private final int minDelay;
     private final int maxRetries;
     private final Duration requestTimeout;
 
-    private ElasticSearchConfiguration(ImmutableList<Host> hosts, 
Optional<String> clusterName, int nbShards, int nbReplica, int minDelay, int 
maxRetries, Duration requestTimeout) {
+    private ElasticSearchConfiguration(ImmutableList<Host> hosts, int 
nbShards, int nbReplica, int minDelay, int maxRetries, Duration requestTimeout) 
{
         this.hosts = hosts;
-        this.clusterName = clusterName;
         this.nbShards = nbShards;
         this.nbReplica = nbReplica;
         this.minDelay = minDelay;
@@ -210,10 +198,6 @@ public class ElasticSearchConfiguration {
         return hosts;
     }
 
-    public Optional<String> getClusterName() {
-        return clusterName;
-    }
-
     public int getNbShards() {
         return nbShards;
     }
@@ -240,7 +224,6 @@ public class ElasticSearchConfiguration {
             ElasticSearchConfiguration that = (ElasticSearchConfiguration) o;
 
             return Objects.equals(this.nbShards, that.nbShards)
-                && Objects.equals(this.clusterName, that.clusterName)
                 && Objects.equals(this.nbReplica, that.nbReplica)
                 && Objects.equals(this.minDelay, that.minDelay)
                 && Objects.equals(this.maxRetries, that.maxRetries)
@@ -252,6 +235,6 @@ public class ElasticSearchConfiguration {
 
     @Override
     public final int hashCode() {
-        return Objects.hash(hosts, clusterName, nbShards, nbReplica, minDelay, 
maxRetries, requestTimeout);
+        return Objects.hash(hosts, nbShards, nbReplica, minDelay, maxRetries, 
requestTimeout);
     }
 }
diff --git 
a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
 
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
index c970bd3..18167a1 100644
--- 
a/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
+++ 
b/backends-common/elasticsearch/src/test/java/org/apache/james/backends/es/ElasticSearchConfigurationTest.java
@@ -30,7 +30,6 @@ import org.apache.james.util.Host;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
-
 import nl.jqno.equalsverifier.EqualsVerifier;
 
 public class ElasticSearchConfigurationTest {
@@ -192,51 +191,6 @@ public class ElasticSearchConfigurationTest {
     }
 
     @Test
-    public void clusterNameShouldBeEmptyWhenNotGiven() throws 
ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        String hostname = "myHost";
-        configuration.addProperty("elasticsearch.masterHost", hostname);
-        int port = 9200;
-        configuration.addProperty("elasticsearch.port", port);
-
-        ElasticSearchConfiguration elasticSearchConfiguration = 
ElasticSearchConfiguration.fromProperties(configuration);
-
-        assertThat(elasticSearchConfiguration.getClusterName())
-                .isEmpty();
-    }
-
-    @Test
-    public void clusterNameShouldBeEmptyWhenNull() throws 
ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        String hostname = "myHost";
-        configuration.addProperty("elasticsearch.masterHost", hostname);
-        int port = 9200;
-        configuration.addProperty("elasticsearch.port", port);
-        configuration.addProperty("elasticsearch.clusterName", null);
-
-        ElasticSearchConfiguration elasticSearchConfiguration = 
ElasticSearchConfiguration.fromProperties(configuration);
-
-        assertThat(elasticSearchConfiguration.getClusterName())
-                .isEmpty();
-    }
-
-    @Test
-    public void clusterNameShouldKeepTheValueWhenGiven() throws 
ConfigurationException {
-        PropertiesConfiguration configuration = new PropertiesConfiguration();
-        String hostname = "myHost";
-        configuration.addProperty("elasticsearch.masterHost", hostname);
-        int port = 9200;
-        configuration.addProperty("elasticsearch.port", port);
-        String clusterName = "myClusterName";
-        configuration.addProperty("elasticsearch.clusterName", clusterName);
-
-        ElasticSearchConfiguration elasticSearchConfiguration = 
ElasticSearchConfiguration.fromProperties(configuration);
-
-        assertThat(elasticSearchConfiguration.getClusterName())
-                .contains(clusterName);
-    }
-
-    @Test
     public void 
validateHostsConfigurationOptionsShouldThrowWhenNoHostSpecify() {
         assertThatThrownBy(() ->
             ElasticSearchConfiguration.validateHostsConfigurationOptions(


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