james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/15] james-project git commit: JAMES-2202 All ElasticSearch operation should be performed on the Alias
Date Wed, 01 Nov 2017 11:00:02 GMT
JAMES-2202 All ElasticSearch operation should be performed on the 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/e3e00e1a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e3e00e1a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e3e00e1a

Branch: refs/heads/master
Commit: e3e00e1ad2439668acb22e2bd451de85765149e4
Parents: deb93a7
Author: benwa <btellier@linagora.com>
Authored: Wed Oct 25 11:52:46 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Wed Nov 1 17:54:21 2017 +0700

----------------------------------------------------------------------
 .../james/backends/es/DeleteByQueryPerformer.java     | 14 +++++++-------
 .../james/backends/es/ElasticSearchIndexer.java       | 12 ++++++------
 .../james/backends/es/ElasticSearchIndexerTest.java   |  7 +++++--
 .../elasticsearch/search/ElasticSearchSearcher.java   | 14 +++++++-------
 .../elasticsearch/ElasticSearchIntegrationTest.java   |  6 +++---
 .../elasticsearch/host/ElasticSearchHostSystem.java   |  7 +++++--
 6 files changed, 33 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
index 6a44754..0ccea46 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/DeleteByQueryPerformer.java
@@ -43,20 +43,20 @@ public class DeleteByQueryPerformer {
     private final Client client;
     private final ExecutorService executor;
     private final int batchSize;
-    private final IndexName indexName;
+    private final AliasName aliasName;
     private final TypeName typeName;
 
     @Inject
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, IndexName indexName, TypeName typeName) {
-        this(client, executor, DEFAULT_BATCH_SIZE, indexName, typeName);
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, AliasName aliasName, TypeName typeName) {
+        this(client, executor, DEFAULT_BATCH_SIZE, aliasName, typeName);
     }
 
     @VisibleForTesting
-    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, int batchSize, IndexName indexName, TypeName typeName) {
+    public DeleteByQueryPerformer(Client client, @Named("AsyncExecutor") ExecutorService
executor, int batchSize, AliasName aliasName, TypeName typeName) {
         this.client = client;
         this.executor = executor;
         this.batchSize = batchSize;
-        this.indexName = indexName;
+        this.aliasName = aliasName;
         this.typeName = typeName;
     }
 
@@ -66,7 +66,7 @@ public class DeleteByQueryPerformer {
 
     protected void doDeleteByQuery(QueryBuilder queryBuilder) {
         new ScrollIterable(client,
-            client.prepareSearch(indexName.getValue())
+            client.prepareSearch(aliasName.getValue())
                 .setTypes(typeName.getValue())
                 .setScroll(TIMEOUT)
                 .setNoFields()
@@ -80,7 +80,7 @@ public class DeleteByQueryPerformer {
         BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
         for (SearchHit hit : searchResponse.getHits()) {
             bulkRequestBuilder.add(client.prepareDelete()
-                .setIndex(indexName.getValue())
+                .setIndex(aliasName.getValue())
                 .setType(typeName.getValue())
                 .setId(hit.getId()));
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
index 2716e89..d162a0c 100644
--- a/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
+++ b/backends-common/elasticsearch/src/main/java/org/apache/james/backends/es/ElasticSearchIndexer.java
@@ -88,14 +88,14 @@ public class ElasticSearchIndexer {
     
     private final Client client;
     private final DeleteByQueryPerformer deleteByQueryPerformer;
-    private final IndexName indexName;
+    private final AliasName aliasName;
     private final TypeName typeName;
 
     @Inject
-    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer,
IndexName indexName, TypeName typeName) {
+    public ElasticSearchIndexer(Client client, DeleteByQueryPerformer deleteByQueryPerformer,
AliasName aliasName, TypeName typeName) {
         this.client = client;
         this.deleteByQueryPerformer = deleteByQueryPerformer;
-        this.indexName = indexName;
+        this.aliasName = aliasName;
         this.typeName = typeName;
     }
     
@@ -104,7 +104,7 @@ public class ElasticSearchIndexer {
         if (LOGGER.isDebugEnabled()) {
             LOGGER.debug("Indexing {}: {}", id, StringUtils.left(content, DEBUG_MAX_LENGTH_CONTENT));
         }
-        return client.prepareIndex(indexName.getValue(), typeName.getValue(), id)
+        return client.prepareIndex(aliasName.getValue(), typeName.getValue(), id)
             .setSource(content)
             .get();
     }
@@ -115,7 +115,7 @@ public class ElasticSearchIndexer {
             BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
             updatedDocumentParts.forEach(updatedDocumentPart -> bulkRequestBuilder.add(
                 client.prepareUpdate(
-                    indexName.getValue(),
+                    aliasName.getValue(),
                     typeName.getValue(),
                     updatedDocumentPart.getId())
                 .setDoc(updatedDocumentPart.getUpdatedDocumentPart())));
@@ -131,7 +131,7 @@ public class ElasticSearchIndexer {
             BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
             ids.forEach(id -> bulkRequestBuilder.add(
                 client.prepareDelete(
-                    indexName.getValue(),
+                    aliasName.getValue(),
                     typeName.getValue(),
                     id)));
             return Optional.of(bulkRequestBuilder.get());

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/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 6855622..a4f9aca 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
@@ -43,6 +43,7 @@ public class ElasticSearchIndexerTest {
 
     private static final int MINIMUM_BATCH_SIZE = 1;
     private static final IndexName INDEX_NAME = new IndexName("index_name");
+    private static final AliasName ALIAS_NAME = new AliasName("alias_name");
     private static final TypeName TYPE_NAME = new TypeName("type_name");
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch= new EmbeddedElasticSearch(temporaryFolder,
INDEX_NAME);
@@ -57,17 +58,19 @@ public class ElasticSearchIndexerTest {
     public void setup() throws IOException {
         node = embeddedElasticSearch.getNode();
         TestingClientProvider clientProvider = new TestingClientProvider(node);
+        IndexCreationFactory.createIndexAndAlias(clientProvider.get(),
+            INDEX_NAME, ALIAS_NAME);
         DeleteByQueryPerformer deleteByQueryPerformer = new DeleteByQueryPerformer(clientProvider.get(),
             Executors.newSingleThreadExecutor(),
             MINIMUM_BATCH_SIZE,
-            INDEX_NAME,
+            ALIAS_NAME,
             TYPE_NAME) {
             @Override
             public void perform(QueryBuilder queryBuilder) {
                 doDeleteByQuery(queryBuilder);
             }
         };
-        testee = new ElasticSearchIndexer(clientProvider.get(), deleteByQueryPerformer, INDEX_NAME,
TYPE_NAME);
+        testee = new ElasticSearchIndexer(clientProvider.get(), deleteByQueryPerformer, ALIAS_NAME,
TYPE_NAME);
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/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 330d363..cc330e8 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,7 +25,7 @@ import java.util.stream.Stream;
 
 import javax.inject.Inject;
 
-import org.apache.james.backends.es.IndexName;
+import org.apache.james.backends.es.AliasName;
 import org.apache.james.backends.es.TypeName;
 import org.apache.james.backends.es.search.ScrollIterable;
 import org.apache.james.mailbox.MessageUid;
@@ -58,25 +58,25 @@ public class ElasticSearchSearcher {
     private final int size;
     private final MailboxId.Factory mailboxIdFactory;
     private final MessageId.Factory messageIdFactory;
-    private final IndexName indexName;
+    private final AliasName aliasName;
     private final TypeName typeName;
 
     @Inject
     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);
+                                 AliasName aliasName, TypeName typeName) {
+        this(client, queryConverter, DEFAULT_SIZE, mailboxIdFactory, messageIdFactory, aliasName,
typeName);
     }
 
     public ElasticSearchSearcher(Client client, QueryConverter queryConverter, int size,
                                  MailboxId.Factory mailboxIdFactory, MessageId.Factory messageIdFactory,
-                                 IndexName indexName, TypeName typeName) {
+                                 AliasName aliasName, TypeName typeName) {
         this.client = client;
         this.queryConverter = queryConverter;
         this.size = size;
         this.mailboxIdFactory = mailboxIdFactory;
         this.messageIdFactory = messageIdFactory;
-        this.indexName = indexName;
+        this.aliasName = aliasName;
         this.typeName = typeName;
     }
 
@@ -95,7 +95,7 @@ public class ElasticSearchSearcher {
         return query.getSorts()
             .stream()
             .reduce(
-                client.prepareSearch(indexName.getValue())
+                client.prepareSearch(aliasName.getValue())
                     .setTypes(typeName.getValue())
                     .setScroll(TIMEOUT)
                     .addFields(JsonMessageConstants.UID, JsonMessageConstants.MAILBOX_ID,
JsonMessageConstants.MESSAGE_ID)

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/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 cab06e5..f32f895 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
@@ -126,13 +126,13 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
                 new DeleteByQueryPerformer(client,
                     Executors.newSingleThreadExecutor(),
                     BATCH_SIZE,
-                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                    MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
                     MailboxElasticsearchConstants.MESSAGE_TYPE),
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()),
SEARCH_SIZE,
                 new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX,
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
                 MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES));
         storeMailboxManager = new InMemoryMailboxManager(

http://git-wip-us.apache.org/repos/asf/james-project/blob/e3e00e1a/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 2a90a99..cc6b435 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
@@ -108,10 +108,13 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
 
         ElasticSearchListeningMessageSearchIndex searchIndex = new ElasticSearchListeningMessageSearchIndex(
             factory,
-            new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(),
MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
+            new ElasticSearchIndexer(client,
+                new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS,
+                MailboxElasticsearchConstants.MESSAGE_TYPE),
             new ElasticSearchSearcher(client,
                 new QueryConverter(new CriterionConverter()), new InMemoryId.Factory(), messageIdFactory,
-                MailboxElasticsearchConstants.DEFAULT_MAILBOX_INDEX, MailboxElasticsearchConstants.MESSAGE_TYPE),
+                MailboxElasticsearchConstants.DEFAULT_MAILBOX_ALIAS, MailboxElasticsearchConstants.MESSAGE_TYPE),
             new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.systemDefault(),
IndexAttachments.YES));
 
         MailboxACLResolver aclResolver = new UnionMailboxACLResolver();


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