Repository: james-project Updated Branches: refs/heads/master 7c490edb8 -> b1f1077e8
JAMES-2202 Configurable index name for ElasticSearch Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/aebca5fb Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/aebca5fb Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/aebca5fb Branch: refs/heads/master Commit: aebca5fbdd13755f7dc3b003081dc186751f64ac Parents: 73deadf Author: benwa <btell...@linagora.com> Authored: Wed Oct 25 10:26:31 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Wed Nov 1 17:53:02 2017 +0700 ---------------------------------------------------------------------- .../org/apache/james/backends/es/IndexName.java | 17 ++++++++ .../MailboxElasticsearchConstants.java | 2 +- .../search/ElasticSearchSearcher.java | 21 +++++++--- .../ElasticSearchIntegrationTest.java | 15 ++++--- .../host/ElasticSearchHostSystem.java | 15 +++---- .../smtp/host/CassandraJamesSmtpHostSystem.java | 2 +- .../mailbox/ElasticSearchMailboxModule.java | 30 ++++++++++---- .../apache/james/EmbeddedElasticSearchRule.java | 2 +- .../james/JamesCapabilitiesServerTest.java | 2 +- .../james/modules/TestElasticSearchModule.java | 10 ++--- .../mailbox/ElasticSearchMailboxModuleTest.java | 41 ++++++++++++++++++++ .../cassandra/cucumber/CassandraStepdefs.java | 2 +- src/site/xdoc/server/config-elasticsearch.xml | 2 + 13 files changed, 124 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java ---------------------------------------------------------------------- diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java index 8936bb2..4541f48 100644 --- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java +++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/IndexName.java @@ -19,6 +19,8 @@ package org.apache.james.backends.es; +import java.util.Objects; + public class IndexName { private final String value; @@ -29,4 +31,19 @@ public class IndexName { public String getValue() { return value; } + + @Override + public final boolean equals(Object o) { + if (o instanceof IndexName) { + IndexName indexName = (IndexName) o; + + return Objects.equals(this.value, indexName.value); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(value); + } } http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java ---------------------------------------------------------------------- diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java index 4cf9bd1..9539e53 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/MailboxElasticsearchConstants.java @@ -23,6 +23,6 @@ import org.apache.james.backends.es.IndexName; import org.apache.james.backends.es.TypeName; public interface MailboxElasticsearchConstants { - IndexName MAILBOX_INDEX = new IndexName("mailbox"); + IndexName DEFAULT_MAILBOX_INDEX = new IndexName("mailbox"); TypeName MESSAGE_TYPE = new TypeName("message"); } http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java ---------------------------------------------------------------------- diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java index f253001..330d363 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java @@ -25,9 +25,10 @@ import java.util.stream.Stream; import javax.inject.Inject; +import org.apache.james.backends.es.IndexName; +import org.apache.james.backends.es.TypeName; import org.apache.james.backends.es.search.ScrollIterable; import org.apache.james.mailbox.MessageUid; -import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants; import org.apache.james.mailbox.elasticsearch.json.JsonMessageConstants; import org.apache.james.mailbox.elasticsearch.query.QueryConverter; import org.apache.james.mailbox.elasticsearch.query.SortConverter; @@ -57,18 +58,26 @@ public class ElasticSearchSearcher { private final int size; private final MailboxId.Factory mailboxIdFactory; private final MessageId.Factory messageIdFactory; + private final IndexName indexName; + private final TypeName typeName; @Inject - public ElasticSearchSearcher(Client client, QueryConverter queryConverter, MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory) { - this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory); + public ElasticSearchSearcher(Client client, QueryConverter queryConverter, + MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory, + IndexName indexName, TypeName typeName) { + this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory, indexName, typeName); } - public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size, MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory) { + public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size, + MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory, + IndexName indexName, TypeName typeName) { this.client = client; this.queryConverter = queryConverter; this.size = size; this.mailboxIdFactory = mailboxIdFactory; this.messageIdFactory = messageIdFactory; + this.indexName = indexName; + this.typeName = typeName; } public Stream<MessageSearchIndex.SearchResult> search(Collection<MailboxId> mailboxIds, SearchQuery query, @@ -86,8 +95,8 @@ public class ElasticSearchSearcher { return query.getSorts() .stream() .reduce( - client.prepareSearch(MailboxElasticsearchConstants.MAILBOX_INDEX.getValue()) - .setTypes(MailboxElasticsearchConstants.MESSAGE_TYPE.getValue()) + client.prepareSearch(indexName.getValue()) + .setTypes(typeName.getValue()) .setScroll(TIMEOUT) .addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID, JsonMessageConstants.MESSAGE_ID) .setQuery(queryConverter.from(users, query)) http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/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 bb6adb8..eaf7764 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 @@ -83,7 +83,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest private static final boolean IS_RECENT = true; private TemporaryFolder temporaryFolder = new TemporaryFolder(); - private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX); + private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); @Rule public RuleChain ruleChain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch); @@ -112,8 +112,8 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest Client client = NodeMappingFactory.applyMapping( IndexCreationFactory.createIndex( new TestingClientProvider(embeddedElasticSearch.getNode()).get(), - MailboxElasticsearchConstants.MAILBOX_INDEX), - MailboxElasticsearchConstants.MAILBOX_INDEX, + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX), + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE, MailboxMappingFactory.getMappingContent()); @@ -125,11 +125,14 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), BATCH_SIZE, - MailboxElasticsearchConstants.MAILBOX_INDEX, + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), - MailboxElasticsearchConstants.MAILBOX_INDEX, + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, + MailboxElasticsearchConstants.MESSAGE_TYPE), + new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE, + new InMemoryId.Factory(), messageIdFactory, + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), - new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE, new InMemoryId.Factory(), messageIdFactory), new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES)); storeMailboxManager = new InMemoryMailboxManager( mapperFactory, http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/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 12a854a..948acd8 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 @@ -82,7 +82,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem { public void beforeTest() throws Exception { super.beforeTest(); this.tempDirectory = Files.createTempDirectory("elasticsearch"); - this.embeddedElasticSearch = new EmbeddedElasticSearch(tempDirectory, MailboxElasticsearchConstants.MAILBOX_INDEX); + this.embeddedElasticSearch = new EmbeddedElasticSearch(tempDirectory, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); embeddedElasticSearch.before(); initFields(); } @@ -95,19 +95,20 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem { private void initFields() { Client client = NodeMappingFactory.applyMapping( - IndexCreationFactory.createIndex(new TestingClientProvider(embeddedElasticSearch.getNode()).get(), MailboxElasticsearchConstants.MAILBOX_INDEX), - MailboxElasticsearchConstants.MAILBOX_INDEX, + IndexCreationFactory.createIndex(new TestingClientProvider(embeddedElasticSearch.getNode()).get(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX), + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE, - MailboxMappingFactory.getMappingContent() - ); + MailboxMappingFactory.getMappingContent()); InMemoryMailboxSessionMapperFactory factory = new InMemoryMailboxSessionMapperFactory(); InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory(); ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex( factory, - new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), MailboxElasticsearchConstants.MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), - new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory), + new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), + new ElasticSearchSearcher(client, + new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory, + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE), new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(), IndexAttachments.YES)); MailboxACLResolver aclResolver = new UnionMailboxACLResolver(); http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java index 97a5f55..7b958f2 100644 --- a/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java +++ b/mpt/impl/smtp/cassandra/src/test/java/org/apache/james/mpt/smtp/host/CassandraJamesSmtpHostSystem.java @@ -83,7 +83,7 @@ public class CassandraJamesSmtpHostSystem extends ExternalSessionFactory impleme inMemoryDNSService = new InMemoryDNSService(); folder = new TemporaryFolder(); folder.create(); - embeddedElasticSearch = new EmbeddedElasticSearch(folder.getRoot().toPath(), MailboxElasticsearchConstants.MAILBOX_INDEX); + embeddedElasticSearch = new EmbeddedElasticSearch(folder.getRoot().toPath(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); embeddedElasticSearch.before(); jamesServer = createJamesServer(); jamesServer.start(); http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/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 f567d20..dee84b5 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 @@ -68,7 +68,6 @@ public class ElasticSearchMailboxModule extends AbstractModule { @Override protected void configure() { - bind(IndexName.class).toInstance(MailboxElasticsearchConstants.MAILBOX_INDEX); bind(TypeName.class).toInstance(MailboxElasticsearchConstants.MESSAGE_TYPE); bind(ElasticSearchListeningMessageSearchIndex.class).in(Scopes.SINGLETON); bind(MessageSearchIndex.class).to(ElasticSearchListeningMessageSearchIndex.class); @@ -76,33 +75,48 @@ public class ElasticSearchMailboxModule extends AbstractModule { } @Provides + protected IndexName provideIndexName(ElasticSearchConfiguration elasticSearchConfiguration) throws ConfigurationException { + try { + return Optional.ofNullable(elasticSearchConfiguration.getConfiguration() + .getString("elasticsearch.index.name")) + .map(IndexName::new) + .orElse(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); + } catch (FileNotFoundException e) { + LOGGER.info("Could not find ElasticSearch configuration file. Using default index {}", MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX.getValue()); + return MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX; + } + } + + @Provides @Singleton - protected Client provideClientProvider(ElasticSearchConfiguration elasticSearchConfiguration, AsyncRetryExecutor executor) throws ConfigurationException, FileNotFoundException, ExecutionException, InterruptedException { + protected Client provideClientProvider(ElasticSearchConfiguration elasticSearchConfiguration, + IndexName indexName, + AsyncRetryExecutor executor) throws ConfigurationException, FileNotFoundException, ExecutionException, InterruptedException { PropertiesConfiguration propertiesReader = elasticSearchConfiguration.getConfiguration(); int maxRetries = propertiesReader.getInt("elasticsearch.retryConnection.maxRetries", DEFAULT_CONNECTION_MAX_RETRIES); int minDelay = propertiesReader.getInt("elasticsearch.retryConnection.minDelay", DEFAULT_CONNECTION_MIN_DELAY); return RetryExecutorUtil.retryOnExceptions(executor, maxRetries, minDelay, NoNodeAvailableException.class) - .getWithRetry(context -> connectToCluster(propertiesReader)) + .getWithRetry(context -> connectToCluster(propertiesReader, indexName)) .get(); } - private Client createIndexAndMapping(Client client, PropertiesConfiguration propertiesReader) { + private Client createIndexAndMapping(Client client, IndexName indexName, PropertiesConfiguration propertiesReader) { IndexCreationFactory.createIndex(client, - MailboxElasticsearchConstants.MAILBOX_INDEX, + indexName, 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.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE, MailboxMappingFactory.getMappingContent()); return client; } - private Client connectToCluster(PropertiesConfiguration propertiesReader) throws ConfigurationException { + private Client connectToCluster(PropertiesConfiguration propertiesReader, IndexName indexName) throws ConfigurationException { LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now()); - return createIndexAndMapping(createClient(propertiesReader), propertiesReader); + return createIndexAndMapping(createClient(propertiesReader), indexName, propertiesReader); } @Provides http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java index 8c300da..5bef22e 100644 --- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/EmbeddedElasticSearchRule.java @@ -34,7 +34,7 @@ import com.google.inject.Module; public class EmbeddedElasticSearchRule implements GuiceModuleTestRule { private final TemporaryFolder temporaryFolder = new TemporaryFolder(); - private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX); + private final EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); private final RuleChain chain = RuleChain .outerRule(temporaryFolder) http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java index 48eca9d..383d781 100644 --- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java @@ -45,7 +45,7 @@ public class JamesCapabilitiesServerTest { private GuiceJamesServer server; private TemporaryFolder temporaryFolder = new TemporaryFolder(); - private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX); + private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); private DockerCassandraRule cassandraServer = new DockerCassandraRule(); @Rule http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/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 e9a89cd..7a984ec 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 @@ -19,8 +19,7 @@ package org.apache.james.modules; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; +import javax.inject.Singleton; import org.apache.james.backends.es.EmbeddedElasticSearch; import org.apache.james.backends.es.IndexCreationFactory; @@ -30,7 +29,8 @@ import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants; import org.apache.james.mailbox.elasticsearch.MailboxMappingFactory; import org.elasticsearch.client.Client; -import javax.inject.Singleton; +import com.google.inject.AbstractModule; +import com.google.inject.Provides; public class TestElasticSearchModule extends AbstractModule{ @@ -49,9 +49,9 @@ public class TestElasticSearchModule extends AbstractModule{ @Singleton protected Client provideClientProvider() { Client client = new TestingClientProvider(embeddedElasticSearch.getNode()).get(); - IndexCreationFactory.createIndex(client, MailboxElasticsearchConstants.MAILBOX_INDEX); + IndexCreationFactory.createIndex(client, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); return NodeMappingFactory.applyMapping(client, - MailboxElasticsearchConstants.MAILBOX_INDEX, + MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE, MailboxMappingFactory.getMappingContent()); } http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java index dd22797..dc590a9 100644 --- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java @@ -24,11 +24,14 @@ import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTI import static org.apache.james.modules.mailbox.ElasticSearchMailboxModule.ELASTICSEARCH_PORT; import static org.assertj.core.api.Assertions.assertThat; +import java.io.FileNotFoundException; import java.util.Optional; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.james.backends.es.IndexName; import org.apache.james.mailbox.elasticsearch.IndexAttachments; +import org.apache.james.mailbox.elasticsearch.MailboxElasticsearchConstants; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -39,6 +42,44 @@ public class ElasticSearchMailboxModuleTest { public ExpectedException expectedException = ExpectedException.none(); @Test + public void provideIndexNameShouldRetrievedConfiguredIndexName() throws ConfigurationException { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + String name = "name"; + configuration.addProperty("elasticsearch.index.name", name); + + ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule(); + + IndexName indexName = testee.provideIndexName(() -> configuration); + + assertThat(indexName) + .isEqualTo(new IndexName(name)); + } + + @Test + public void provideIndexNameShouldReturnDefaultIndexNameWhenNone() throws ConfigurationException { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + + ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule(); + + IndexName indexName = testee.provideIndexName(() -> configuration); + + assertThat(indexName) + .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); + } + + @Test + public void provideIndexNameShouldReturnDefaultIndexNameWhenError() throws ConfigurationException { + ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule(); + + IndexName indexName = testee.provideIndexName(() -> { + throw new FileNotFoundException(); + }); + + assertThat(indexName) + .isEqualTo(MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); + } + + @Test public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsTrueInConfiguration() { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.addProperty("elasticsearch.indexAttachments", true); http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java index 066dc75..684bf3b 100644 --- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraStepdefs.java @@ -46,7 +46,7 @@ public class CassandraStepdefs { private final MainStepdefs mainStepdefs; private TemporaryFolder temporaryFolder = new TemporaryFolder(); - private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.MAILBOX_INDEX); + private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX); private DockerCassandraRule cassandraServer = CucumberCassandraSingleton.cassandraServer; @Inject http://git-wip-us.apache.org/repos/asf/james-project/blob/aebca5fb/src/site/xdoc/server/config-elasticsearch.xml ---------------------------------------------------------------------- diff --git a/src/site/xdoc/server/config-elasticsearch.xml b/src/site/xdoc/server/config-elasticsearch.xml index c554e4c..94420c2 100644 --- a/src/site/xdoc/server/config-elasticsearch.xml +++ b/src/site/xdoc/server/config-elasticsearch.xml @@ -56,6 +56,8 @@ <dd>Number of shards for index provisionned by James</dd> <dt><strong>elasticsearch.nb.replica</strong></dt> <dd>Number of replica for index provisionned by James</dd> + <dt><strong>elasticsearch.index.name</strong></dt> + <dd>Name of the index to use with Apache James. It will be created if missing.</dd> <dt><strong>elasticsearch.retryConnection.maxRetries</strong></dt> <dd>Number of retries when connecting the cluster</dd> <dt><strong>elasticsearch.retryConnection.minDelay</strong></dt> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org