You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/04/21 03:57:08 UTC

[09/17] james-project git commit: JAMES-2004 Adding default options for ElasticSearch shards and replica

JAMES-2004 Adding default options for ElasticSearch shards and replica


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

Branch: refs/heads/master
Commit: e0f2a4c53ef779bfdeab044d08f64361fac77c9a
Parents: b2a1425
Author: benwa <bt...@linagora.com>
Authored: Tue Apr 18 13:46:21 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Apr 21 08:27:41 2017 +0700

----------------------------------------------------------------------
 .../mailbox/ElasticSearchMailboxModule.java        | 17 ++++++++++-------
 .../modules/server/ESMetricReporterModule.java     | 13 ++++---------
 2 files changed, 14 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e0f2a4c5/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 43ba8ff..d1b124b 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
@@ -57,13 +57,16 @@ import com.nurkiewicz.asyncretry.AsyncRetryExecutor;
 public class ElasticSearchMailboxModule extends AbstractModule {
     private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchMailboxModule.class);
 
-    public static final String ES_CONFIG_FILE = FileSystem.FILE_PROTOCOL_AND_CONF + "elasticsearch.properties";
+    public static final String ELASTICSEARCH_CONFIGURATION_NAME = "elasticsearch";
     public static final String ELASTICSEARCH_HOSTS = "elasticsearch.hosts";
     public static final String ELASTICSEARCH_MASTER_HOST = "elasticsearch.masterHost";
     public static final String ELASTICSEARCH_PORT = "elasticsearch.port";
     private static final int DEFAULT_CONNECTION_MAX_RETRIES = 7;
     private static final int DEFAULT_CONNECTION_MIN_DELAY = 3000;
     private static final boolean DEFAULT_INDEX_ATTACHMENTS = true;
+    private static final int DEFAULT_NB_SHARDS = 1;
+    private static final int DEFAULT_NB_REPLICA = 0;
+    private static final String LOCALHOST = "127.0.0.1";
 
     @Override
     protected void configure() {
@@ -92,8 +95,8 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     private Client createIndexAndMapping(Client client, PropertiesConfiguration propertiesReader) {
         IndexCreationFactory.createIndex(client,
             MailboxElasticsearchConstants.MAILBOX_INDEX,
-            propertiesReader.getInt("elasticsearch.nb.shards"),
-            propertiesReader.getInt("elasticsearch.nb.replica"));
+            propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.shards", DEFAULT_NB_SHARDS),
+            propertiesReader.getInt(ELASTICSEARCH_CONFIGURATION_NAME + ".nb.replica", DEFAULT_NB_REPLICA));
         NodeMappingFactory.applyMapping(client,
             MailboxElasticsearchConstants.MAILBOX_INDEX,
             MailboxElasticsearchConstants.MESSAGE_TYPE,
@@ -111,12 +114,12 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     @Singleton
     private ElasticSearchConfiguration getElasticSearchConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
         try {
-            PropertiesConfiguration configuration = propertiesProvider.getConfiguration("elasticsearch");
+            PropertiesConfiguration configuration = propertiesProvider.getConfiguration(ELASTICSEARCH_CONFIGURATION_NAME);
             return () -> configuration;
         } catch (FileNotFoundException e) {
-            LOGGER.warn("Could not find elasticsearch configuration file. Using 127.0.0.1:9300 as contact point");
+            LOGGER.warn("Could not find " + ELASTICSEARCH_CONFIGURATION_NAME + " configuration file. Using 127.0.0.1:9300 as contact point");
             PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
-            propertiesConfiguration.addProperty(ELASTICSEARCH_HOSTS, "127.0.0.1");
+            propertiesConfiguration.addProperty(ELASTICSEARCH_HOSTS, LOCALHOST);
             return () -> propertiesConfiguration;
         }
     }
@@ -153,7 +156,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
     @Provides
     @Singleton
     public IndexAttachments provideIndexAttachments(PropertiesConfiguration configuration) {
-        if (configuration.getBoolean("elasticsearch.indexAttachments", DEFAULT_INDEX_ATTACHMENTS)) {
+        if (configuration.getBoolean(ELASTICSEARCH_CONFIGURATION_NAME + ".indexAttachments", DEFAULT_INDEX_ATTACHMENTS)) {
             return IndexAttachments.YES;
         }
         return IndexAttachments.NO;

http://git-wip-us.apache.org/repos/asf/james-project/blob/e0f2a4c5/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
index d0229dd..b6906bc 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/server/ESMetricReporterModule.java
@@ -26,12 +26,12 @@ import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.lang.NotImplementedException;
-import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.metrics.es.ESMetricReporter;
 import org.apache.james.metrics.es.ESReporterConfiguration;
 import org.apache.james.modules.mailbox.ElasticSearchMailboxModule;
 import org.apache.james.utils.ConfigurationPerformer;
+import org.apache.james.utils.PropertiesProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,9 +54,9 @@ public class ESMetricReporterModule extends AbstractModule {
     }
 
     @Provides
-    public ESReporterConfiguration provideConfiguration(FileSystem fileSystem) throws ConfigurationException {
+    public ESReporterConfiguration provideConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
         try {
-            PropertiesConfiguration propertiesReader = getPropertiesConfiguration(fileSystem);
+            PropertiesConfiguration propertiesReader = propertiesProvider.getConfiguration(ElasticSearchMailboxModule.ELASTICSEARCH_CONFIGURATION_NAME);
 
             if (isMetricEnable(propertiesReader)) {
                 return ESReporterConfiguration.builder()
@@ -68,7 +68,7 @@ public class ESMetricReporterModule extends AbstractModule {
                     .build();
             }
         } catch (FileNotFoundException e) {
-            LOGGER.info("Can not locate " + ElasticSearchMailboxModule.ES_CONFIG_FILE);
+            LOGGER.info("Can not locate " + ElasticSearchMailboxModule.ELASTICSEARCH_CONFIGURATION_NAME + " configuration");
         }
         return ESReporterConfiguration.builder()
             .disabled()
@@ -84,11 +84,6 @@ public class ESMetricReporterModule extends AbstractModule {
         return propertiesReader.getBoolean("elasticsearch.metrics.reports.enabled", DEFAULT_DISABLE);
     }
 
-    private PropertiesConfiguration getPropertiesConfiguration(FileSystem fileSystem) throws ConfigurationException, FileNotFoundException {
-        return new PropertiesConfiguration(
-                    fileSystem.getFile(ElasticSearchMailboxModule.ES_CONFIG_FILE));
-    }
-
     @Singleton
     public static class ESMetricReporterStarter implements ConfigurationPerformer, Configurable {
 


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