james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [10/10] james-project git commit: MAILBOX-351 Remove mailboxPath information from reIndexing tasks
Date Thu, 29 Nov 2018 03:53:24 GMT
MAILBOX-351 Remove mailboxPath information from reIndexing tasks


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

Branch: refs/heads/master
Commit: 39572158b4e57b5d507985b1f6252d2765602f2d
Parents: c88e353
Author: Benoit Tellier <btellier@linagora.com>
Authored: Tue Nov 27 16:55:43 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 29 10:52:45 2018 +0700

----------------------------------------------------------------------
 .../mailbox/tools/indexer/ReIndexerImpl.java    | 32 ++++++++------
 .../tools/indexer/ReIndexerPerformer.java       | 45 +++++++++-----------
 .../indexer/SingleMailboxReindexingTask.java    | 23 +++++-----
 .../indexer/SingleMessageReindexingTask.java    | 26 +++++------
 .../indexer/CassandraReIndexerImplTest.java     |  3 +-
 .../tools/indexer/ReIndexerImplTest.java        |  3 +-
 .../webadmin/routes/ReindexingRoutesTest.java   |  4 --
 7 files changed, 64 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
index 761a6cb..9f4b49d 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -30,7 +30,6 @@ import org.apache.james.mailbox.indexer.ReIndexer;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.task.Task;
 
 /**
@@ -57,16 +56,18 @@ public class ReIndexerImpl implements ReIndexer {
 
     @Override
     public Task reIndex(MailboxPath path) throws MailboxException {
-        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
-        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
-        return new SingleMailboxReindexingTask(reIndexerPerformer, mailbox);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser());
+
+        MailboxId mailboxId = mailboxManager.getMailbox(path, mailboxSession).getId();
+
+        return new SingleMailboxReindexingTask(reIndexerPerformer, mailboxId);
     }
 
     @Override
     public Task reIndex(MailboxId mailboxId) throws MailboxException {
-        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
-        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
-        return new SingleMailboxReindexingTask(reIndexerPerformer, mailbox);
+        validateIdExists(mailboxId);
+
+        return new SingleMailboxReindexingTask(reIndexerPerformer, mailboxId);
     }
 
     @Override
@@ -81,15 +82,22 @@ public class ReIndexerImpl implements ReIndexer {
 
     @Override
     public Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException {
-        MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
-        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
-        return new SingleMessageReindexingTask(reIndexerPerformer, mailbox, uid);
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser());
+
+        MailboxId mailboxId = mailboxManager.getMailbox(path, mailboxSession).getId();
+
+        return new SingleMessageReindexingTask(reIndexerPerformer, mailboxId, uid);
     }
 
     @Override
     public Task reIndex(MailboxId mailboxId, MessageUid uid) throws MailboxException {
+        validateIdExists(mailboxId);
+
+        return new SingleMessageReindexingTask(reIndexerPerformer, mailboxId, uid);
+    }
+
+    private void validateIdExists(MailboxId mailboxId) throws MailboxException {
         MailboxSession mailboxSession = mailboxManager.createSystemSession("ReIndexingImap");
-        Mailbox mailbox = mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
-        return new SingleMessageReindexingTask(reIndexerPerformer, mailbox, uid);
+        mapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index 4e49f33..ffa623d 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -65,8 +65,23 @@ public class ReIndexerPerformer {
         this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
     }
 
-    Task.Result reIndex(Mailbox mailbox, ReprocessingContext reprocessingContext) throws
MailboxException {
-        return reIndexSingleMailbox(mailbox.getMailboxId(), reprocessingContext);
+    Task.Result reIndex(MailboxId mailboxId, ReprocessingContext reprocessingContext) throws
MailboxException {
+        LOGGER.info("Intend to reindex mailbox with mailboxId {}", mailboxId.serialize());
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(RE_INDEXING);
+        Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
+        messageSearchIndex.deleteAll(mailboxSession, mailbox);
+        try {
+            return Iterators.toStream(
+                mailboxSessionMapperFactory.getMessageMapper(mailboxSession)
+                    .findInMailbox(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata,
NO_LIMIT))
+                .map(MailboxMessage::getUid)
+                .map(uid -> handleMessageReIndexing(mailboxSession, mailbox, uid))
+                .peek(reprocessingContext::updateAccordingToReprocessingResult)
+                .reduce(Task::combine)
+                .orElse(Task.Result.COMPLETED);
+        } finally {
+            LOGGER.info("Finish to reindex mailbox with mailboxId {}", mailboxId.serialize());
+        }
     }
 
     Task.Result reIndex(ReprocessingContext reprocessingContext) throws MailboxException
{
@@ -98,9 +113,10 @@ public class ReIndexerPerformer {
         }
     }
 
-    Task.Result handleMessageReIndexing(Mailbox mailbox, MessageUid uid) throws MailboxException
{
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(mailbox.getUser());
+    Task.Result handleMessageReIndexing(MailboxId mailboxId, MessageUid uid) throws MailboxException
{
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(RE_INDEXING);
 
+        Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
         return handleMessageReIndexing(mailboxSession, mailbox, uid);
     }
 
@@ -108,7 +124,7 @@ public class ReIndexerPerformer {
         return mailboxIds
             .map(mailboxId -> {
                 try {
-                    return reIndexSingleMailbox(mailboxId, reprocessingContext);
+                    return reIndex(mailboxId, reprocessingContext);
                 } catch (Throwable e) {
                     LOGGER.error("Error while proceeding to full reindexing on mailbox with
mailboxId {}", mailboxId.serialize(), e);
                     return Task.Result.PARTIAL;
@@ -118,25 +134,6 @@ public class ReIndexerPerformer {
             .orElse(Task.Result.COMPLETED);
     }
 
-    private Task.Result reIndexSingleMailbox(MailboxId mailboxId, ReprocessingContext reprocessingContext)
throws MailboxException {
-        LOGGER.info("Intend to reindex mailbox with mailboxId {}", mailboxId.serialize());
-        MailboxSession mailboxSession = mailboxManager.createSystemSession(RE_INDEXING);
-        Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxById(mailboxId);
-        messageSearchIndex.deleteAll(mailboxSession, mailbox);
-        try {
-            return Iterators.toStream(
-                mailboxSessionMapperFactory.getMessageMapper(mailboxSession)
-                    .findInMailbox(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata,
NO_LIMIT))
-                .map(MailboxMessage::getUid)
-                .map(uid -> handleMessageReIndexing(mailboxSession, mailbox, uid))
-                .peek(reprocessingContext::updateAccordingToReprocessingResult)
-                .reduce(Task::combine)
-                .orElse(Task.Result.COMPLETED);
-        } finally {
-            LOGGER.info("Finish to reindex mailbox with mailboxId {}", mailboxId.serialize());
-        }
-    }
-
     private Task.Result handleMessageReIndexing(MailboxSession mailboxSession, Mailbox mailbox,
MessageUid uid) {
         try {
             Optional.of(uid)

http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
index c3f024b..00f771b 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMailboxReindexingTask.java
@@ -24,7 +24,7 @@ import java.util.Optional;
 import javax.inject.Inject;
 
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskExecutionDetails;
 
@@ -33,20 +33,17 @@ public class SingleMailboxReindexingTask implements Task {
     public static final String MAILBOX_RE_INDEXING = "mailboxReIndexing";
 
     public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation
{
-        private final Mailbox mailbox;
+        private final MailboxId mailboxId;
         private final ReprocessingContext reprocessingContext;
 
-        AdditionalInformation(Mailbox mailbox, ReprocessingContext reprocessingContext) {
-            this.mailbox = mailbox;
+        AdditionalInformation(MailboxId mailboxId, ReprocessingContext reprocessingContext)
{
+            this.mailboxId = mailboxId;
             this.reprocessingContext = reprocessingContext;
         }
 
-        public String getMailboxPath() {
-            return mailbox.generateAssociatedPath().asString();
-        }
 
         public String getMailboxId() {
-            return mailbox.getMailboxId().serialize();
+            return mailboxId.serialize();
         }
 
         public int getSuccessfullyReprocessMailCount() {
@@ -59,22 +56,22 @@ public class SingleMailboxReindexingTask implements Task {
     }
 
     private final ReIndexerPerformer reIndexerPerformer;
-    private final Mailbox mailbox;
+    private final MailboxId mailboxId;
     private final AdditionalInformation additionalInformation;
     private final ReprocessingContext reprocessingContext;
 
     @Inject
-    public SingleMailboxReindexingTask(ReIndexerPerformer reIndexerPerformer, Mailbox mailbox)
{
+    public SingleMailboxReindexingTask(ReIndexerPerformer reIndexerPerformer, MailboxId mailboxId)
{
         this.reIndexerPerformer = reIndexerPerformer;
-        this.mailbox = mailbox;
+        this.mailboxId = mailboxId;
         this.reprocessingContext = new ReprocessingContext();
-        this.additionalInformation = new AdditionalInformation(mailbox, reprocessingContext);
+        this.additionalInformation = new AdditionalInformation(mailboxId, reprocessingContext);
     }
 
     @Override
     public Result run() {
         try {
-            return reIndexerPerformer.reIndex(mailbox, reprocessingContext);
+            return reIndexerPerformer.reIndex(mailboxId, reprocessingContext);
         } catch (MailboxException e) {
             return Result.PARTIAL;
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
index ef6aa07..749bf36 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
@@ -25,7 +25,7 @@ import javax.inject.Inject;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskExecutionDetails;
 import org.slf4j.Logger;
@@ -37,20 +37,16 @@ public class SingleMessageReindexingTask implements Task {
     public static final String MESSAGE_RE_INDEXING = "messageReIndexing";
 
     public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation
{
-        private final Mailbox mailbox;
+        private final MailboxId mailboxId;
         private final MessageUid uid;
 
-        AdditionalInformation(Mailbox mailbox, MessageUid uid) {
-            this.mailbox = mailbox;
+        AdditionalInformation(MailboxId mailboxId, MessageUid uid) {
+            this.mailboxId = mailboxId;
             this.uid = uid;
         }
 
-        public String getMailboxPath() {
-            return mailbox.generateAssociatedPath().asString();
-        }
-
         public String getMailboxId() {
-            return mailbox.getMailboxId().serialize();
+            return mailboxId.serialize();
         }
 
         public long getUid() {
@@ -59,24 +55,24 @@ public class SingleMessageReindexingTask implements Task {
     }
 
     private final ReIndexerPerformer reIndexerPerformer;
-    private final Mailbox mailbox;
+    private final MailboxId mailboxId;
     private final MessageUid uid;
     private final AdditionalInformation additionalInformation;
 
     @Inject
-    public SingleMessageReindexingTask(ReIndexerPerformer reIndexerPerformer, Mailbox mailbox,
MessageUid uid) {
+    public SingleMessageReindexingTask(ReIndexerPerformer reIndexerPerformer, MailboxId mailboxId,
MessageUid uid) {
         this.reIndexerPerformer = reIndexerPerformer;
-        this.mailbox = mailbox;
+        this.mailboxId = mailboxId;
         this.uid = uid;
-        this.additionalInformation = new AdditionalInformation(mailbox, uid);
+        this.additionalInformation = new AdditionalInformation(mailboxId, uid);
     }
 
     @Override
     public Result run() {
         try {
-            return reIndexerPerformer.handleMessageReIndexing(mailbox, uid);
+            return reIndexerPerformer.handleMessageReIndexing(mailboxId, uid);
         } catch (MailboxException e) {
-            LOGGER.warn("Error encounteres while reindexing {} {} : {}", mailbox.getMailboxId(),
mailbox.generateAssociatedPath(), uid, e);
+            LOGGER.warn("Error encounteres while reindexing {} : {}",mailboxId, uid, e);
             return Result.PARTIAL;
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
index 8a95a85..7161b38 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/CassandraReIndexerImplTest.java
@@ -65,8 +65,7 @@ public class CassandraReIndexerImplTest {
         MailboxSessionMapperFactory mailboxSessionMapperFactory = mailboxManager.getMapperFactory();
         messageSearchIndex = mock(ListeningMessageSearchIndex.class);
         reIndexer = new ReIndexerImpl(new ReIndexerPerformer(mailboxManager, messageSearchIndex,
mailboxSessionMapperFactory),
-            mailboxManager,
-            mailboxSessionMapperFactory);
+            mailboxManager, mailboxSessionMapperFactory);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
index 1f187d3..80bcecd 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
@@ -63,8 +63,7 @@ public class ReIndexerImplTest {
         MailboxSessionMapperFactory mailboxSessionMapperFactory = mailboxManager.getMapperFactory();
         messageSearchIndex = mock(ListeningMessageSearchIndex.class);
         reIndexer = new ReIndexerImpl(new ReIndexerPerformer(mailboxManager, messageSearchIndex,
mailboxSessionMapperFactory),
-            mailboxManager,
-            mailboxSessionMapperFactory);
+            mailboxManager, mailboxSessionMapperFactory);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/39572158/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
index a6ddc4e..f5e9382 100644
--- a/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox/src/test/java/org/apache/james/webadmin/routes/ReindexingRoutesTest.java
@@ -443,7 +443,6 @@ class ReindexingRoutesTest {
                     .body("status", is("completed"))
                     .body("taskId", is(notNullValue()))
                     .body("type", is(SingleMailboxReindexingTask.MAILBOX_RE_INDEXING))
-                    .body("additionalInformation.mailboxPath", is("#private:benwa@apache.org:INBOX"))
                     .body("additionalInformation.mailboxId", is(mailboxId.serialize()))
                     .body("additionalInformation.successfullyReprocessMailCount", is(0))
                     .body("additionalInformation.failedReprocessedMailCount", is(0))
@@ -474,7 +473,6 @@ class ReindexingRoutesTest {
                     .body("status", is("completed"))
                     .body("taskId", is(notNullValue()))
                     .body("type", is(SingleMailboxReindexingTask.MAILBOX_RE_INDEXING))
-                    .body("additionalInformation.mailboxPath", is("#private:benwa@apache.org:INBOX"))
                     .body("additionalInformation.mailboxId", is(mailboxId.serialize()))
                     .body("additionalInformation.successfullyReprocessMailCount", is(1))
                     .body("additionalInformation.failedReprocessedMailCount", is(0))
@@ -610,7 +608,6 @@ class ReindexingRoutesTest {
                     .body("status", is("completed"))
                     .body("taskId", is(notNullValue()))
                     .body("type", is(SingleMessageReindexingTask.MESSAGE_RE_INDEXING))
-                    .body("additionalInformation.mailboxPath", is("#private:benwa@apache.org:INBOX"))
                     .body("additionalInformation.mailboxId", is(mailboxId.serialize()))
                     .body("additionalInformation.uid", is(1))
                     .body("startedDate", is(notNullValue()))
@@ -641,7 +638,6 @@ class ReindexingRoutesTest {
                     .body("status", is("completed"))
                     .body("taskId", is(notNullValue()))
                     .body("type", is(SingleMessageReindexingTask.MESSAGE_RE_INDEXING))
-                    .body("additionalInformation.mailboxPath", is("#private:benwa@apache.org:INBOX"))
                     .body("additionalInformation.mailboxId", is(mailboxId.serialize()))
                     .body("additionalInformation.uid", is((int) composedMessageId.getUid().asLong()))
                     .body("startedDate", is(notNullValue()))


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