JAMES-2004 ElasticSearch should try to connect locally when no configuration file
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b2a14253 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b2a14253 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b2a14253 Branch: refs/heads/master Commit: b2a1425376eac9f489835289f378b3d5a8915c66 Parents: b62d8b6 Author: benwa <btell...@linagora.com> Authored: Tue Apr 18 13:45:39 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Fri Apr 21 08:27:41 2017 +0700 ---------------------------------------------------------------------- .../mailbox/ElasticSearchMailboxModule.java | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/b2a14253/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 e114938..43ba8ff 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 @@ -42,6 +42,7 @@ import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex; import org.apache.james.mailbox.store.search.MessageSearchIndex; import org.apache.james.mailbox.tika.extractor.TikaTextExtractor; import org.apache.james.utils.RetryExecutorUtil; +import org.apache.james.utils.PropertiesProvider; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.NoNodeAvailableException; import org.slf4j.Logger; @@ -88,16 +89,6 @@ public class ElasticSearchMailboxModule extends AbstractModule { .get(); } - @Provides - @Singleton - ElasticSearchConfiguration getElasticSearchConfiguration(FileSystem fileSystem) { - return () -> getConfiguration(fileSystem); - } - - private PropertiesConfiguration getConfiguration(FileSystem fileSystem) throws FileNotFoundException, ConfigurationException { - return new PropertiesConfiguration(fileSystem.getFile(ES_CONFIG_FILE)); - } - private Client createIndexAndMapping(Client client, PropertiesConfiguration propertiesReader) { IndexCreationFactory.createIndex(client, MailboxElasticsearchConstants.MAILBOX_INDEX, @@ -116,6 +107,20 @@ public class ElasticSearchMailboxModule extends AbstractModule { return createIndexAndMapping(createClient(propertiesReader), propertiesReader); } + @Provides + @Singleton + private ElasticSearchConfiguration getElasticSearchConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException { + try { + PropertiesConfiguration configuration = propertiesProvider.getConfiguration("elasticsearch"); + return () -> configuration; + } catch (FileNotFoundException e) { + LOGGER.warn("Could not find elasticsearch configuration file. Using 127.0.0.1:9300 as contact point"); + PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); + propertiesConfiguration.addProperty(ELASTICSEARCH_HOSTS, "127.0.0.1"); + return () -> propertiesConfiguration; + } + } + private Client createClient(PropertiesConfiguration propertiesReader) throws ConfigurationException { Optional<String> monoHostAddress = Optional.ofNullable(propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, null)); Optional<Integer> monoHostPort = Optional.ofNullable(propertiesReader.getInteger(ELASTICSEARCH_PORT, null)); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org