james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [07/15] james-project git commit: JAMES-2266 Adding 'progress' context information
Date Fri, 05 Jan 2018 09:17:33 GMT
JAMES-2266 Adding 'progress' context information


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

Branch: refs/heads/master
Commit: ff18af477ae2bb00edee27838c9e574920fb06fb
Parents: 7596420
Author: benwa <btellier@linagora.com>
Authored: Wed Jan 3 15:21:18 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Jan 5 16:07:01 2018 +0700

----------------------------------------------------------------------
 .../mail/CassandraMailboxCounterDAO.java        |  6 +-
 .../cassandra/mail/task/MailboxMergingTask.java | 66 ++++++++++++++++++--
 .../mail/task/MailboxMergingTaskRunner.java     | 12 ++--
 .../apache/james/FixingGhostMailboxTest.java    |  3 +
 .../routes/CassandraMailboxMergingRoutes.java   |  8 ++-
 src/site/markdown/server/manage-webadmin.md     |  5 +-
 6 files changed, 87 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/ff18af47/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
index a5a499c..f2e2fce 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
@@ -89,7 +89,11 @@ public class CassandraMailboxCounterDAO {
     public CompletableFuture<Optional<Long>> countMessagesInMailbox(Mailbox mailbox)
throws MailboxException {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
 
-        return cassandraAsyncExecutor.executeSingleRow(bindWithMailbox(mailboxId, readStatement))
+        return countMessagesInMailbox(mailboxId);
+    }
+
+    public CompletableFuture<Optional<Long>> countMessagesInMailbox(CassandraId
cassandraId) {
+        return cassandraAsyncExecutor.executeSingleRow(bindWithMailbox(cassandraId, readStatement))
             .thenApply(optional -> optional.map(row -> row.getLong(CassandraMailboxCountersTable.COUNT)));
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff18af47/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java
index 62af99a..c0849f9 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTask.java
@@ -20,8 +20,10 @@
 package org.apache.james.mailbox.cassandra.mail.task;
 
 import java.util.Optional;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
+import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
 import org.apache.james.task.Task;
 import org.apache.james.task.TaskExecutionDetails;
 
@@ -31,10 +33,17 @@ public class MailboxMergingTask implements Task {
     public static class Details implements TaskExecutionDetails.AdditionalInformation {
         private final CassandraId oldMailboxId;
         private final CassandraId newMailboxId;
+        private final long totalMessageCount;
+        private final long messageMovedCount;
+        private final long messageFailedCount;
 
-        public Details(CassandraId oldId, CassandraId newId) {
+
+        public Details(CassandraId oldId, CassandraId newId, long totalMessageCount, long
messageMovedCount, long messageFailedCount) {
             this.oldMailboxId = oldId;
             this.newMailboxId = newId;
+            this.totalMessageCount = totalMessageCount;
+            this.messageMovedCount = messageMovedCount;
+            this.messageFailedCount = messageFailedCount;
         }
 
         public String getOldMailboxId() {
@@ -44,21 +53,67 @@ public class MailboxMergingTask implements Task {
         public String getNewMailboxId() {
             return newMailboxId.serialize();
         }
+
+        public long getTotalMessageCount() {
+            return totalMessageCount;
+        }
+
+        public long getMessageMovedCount() {
+            return messageMovedCount;
+        }
+
+        public long getMessageFailedCount() {
+            return messageFailedCount;
+        }
+    }
+
+    public static class Context {
+        private final long totalMessageCount;
+        private final AtomicLong totalMessageMoved;
+        private final AtomicLong totalMessageFailed;
+
+        public Context(long totalMessagesCount) {
+            this.totalMessageCount = totalMessagesCount;
+            this.totalMessageMoved = new AtomicLong(0L);
+            this.totalMessageFailed = new AtomicLong(0L);
+        }
+
+        public long getTotalMessageCount() {
+            return totalMessageCount;
+        }
+
+        public long getMessageMovedCount() {
+            return totalMessageMoved.get();
+        }
+
+        public long getMessageFailedCount() {
+            return totalMessageFailed.get();
+        }
+
+        public void incrementMovedCount() {
+            totalMessageMoved.incrementAndGet();
+        }
+
+        public void incrementFailedCount() {
+            totalMessageFailed.incrementAndGet();
+        }
     }
 
     private final MailboxMergingTaskRunner taskRunner;
     private final CassandraId oldMailboxId;
     private final CassandraId newMailboxId;
+    private final Context context;
 
-    public MailboxMergingTask(MailboxMergingTaskRunner taskRunner, CassandraId oldMailboxId,
CassandraId newMailboxId) {
+    public MailboxMergingTask(MailboxMergingTaskRunner taskRunner, long totalMessagesToMove,
CassandraId oldMailboxId, CassandraId newMailboxId) {
         this.taskRunner = taskRunner;
         this.oldMailboxId = oldMailboxId;
         this.newMailboxId = newMailboxId;
+        this.context = new Context(totalMessagesToMove);
     }
 
     @Override
     public Result run() {
-        return taskRunner.run(oldMailboxId, newMailboxId);
+        return taskRunner.run(oldMailboxId, newMailboxId, context);
     }
 
     @Override
@@ -68,6 +123,9 @@ public class MailboxMergingTask implements Task {
 
     @Override
     public Optional<TaskExecutionDetails.AdditionalInformation> details() {
-        return Optional.of(new Details(oldMailboxId, newMailboxId));
+        return Optional.of(new Details(oldMailboxId, newMailboxId,
+            context.getTotalMessageCount(),
+            context.getMessageMovedCount(),
+            context.getMessageFailedCount()));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff18af47/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
index 8a29274..f22d24c 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/task/MailboxMergingTaskRunner.java
@@ -61,27 +61,29 @@ public class MailboxMergingTaskRunner {
         this.cassandraACLMapper = cassandraACLMapper;
     }
 
-    public Task.Result run(CassandraId oldMailboxId, CassandraId newMailboxId) {
-        return moveMessages(oldMailboxId, newMailboxId, mailboxSession)
+    public Task.Result run(CassandraId oldMailboxId, CassandraId newMailboxId, MailboxMergingTask.Context
context) {
+        return moveMessages(oldMailboxId, newMailboxId, mailboxSession, context)
             .onComplete(
                 () -> mergeRights(oldMailboxId, newMailboxId),
                 () -> mailboxDAO.delete(oldMailboxId).join());
     }
 
-    private Task.Result moveMessages(CassandraId oldMailboxId, CassandraId newMailboxId,
MailboxSession session) {
+    private Task.Result moveMessages(CassandraId oldMailboxId, CassandraId newMailboxId,
MailboxSession session, MailboxMergingTask.Context context) {
         return cassandraMessageIdDAO.retrieveMessages(oldMailboxId, MessageRange.all())
             .join()
             .map(ComposedMessageIdWithMetaData::getComposedMessageId)
-            .map(messageId -> moveMessage(newMailboxId, messageId, session))
+            .map(messageId -> moveMessage(newMailboxId, messageId, session, context))
             .reduce(Task.Result.COMPLETED, Task::combine);
     }
 
-    private Task.Result moveMessage(CassandraId newMailboxId, ComposedMessageId composedMessageId,
MailboxSession session) {
+    private Task.Result moveMessage(CassandraId newMailboxId, ComposedMessageId composedMessageId,
MailboxSession session, MailboxMergingTask.Context context) {
         try {
             messageIdManager.setInMailboxesNoCheck(composedMessageId.getMessageId(), newMailboxId,
session);
+            context.incrementMovedCount();
             return Task.Result.COMPLETED;
         } catch (MailboxException e) {
             LOGGER.warn("Failed moving message {}", composedMessageId.getMessageId(), e);
+            context.incrementFailedCount();
             return Task.Result.PARTIAL;
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff18af47/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
index 62a4b30..9b3220b 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/FixingGhostMailboxTest.java
@@ -308,6 +308,9 @@ public class FixingGhostMailboxTest {
             .body("taskId", is(taskId))
             .body("additionalInformation.oldMailboxId", is(aliceGhostInboxId.serialize()))
             .body("additionalInformation.newMailboxId", is(newAliceInbox.getMailboxId().serialize()))
+            .body("additionalInformation.totalMessageCount", is(1))
+            .body("additionalInformation.messageMovedCount", is(1))
+            .body("additionalInformation.messageFailedCount", is(0))
             .body("type", is(MailboxMergingTask.MAILBOX_MERGING))
             .body("submitDate", is(not(nullValue())))
             .body("startedDate", is(not(nullValue())))

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff18af47/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMailboxMergingRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMailboxMergingRoutes.java
b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMailboxMergingRoutes.java
index 9ac36a6..a2ba151 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMailboxMergingRoutes.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMailboxMergingRoutes.java
@@ -25,6 +25,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 
 import org.apache.james.mailbox.cassandra.ids.CassandraId;
+import org.apache.james.mailbox.cassandra.mail.CassandraMailboxCounterDAO;
 import org.apache.james.mailbox.cassandra.mail.task.MailboxMergingTask;
 import org.apache.james.mailbox.cassandra.mail.task.MailboxMergingTaskRunner;
 import org.apache.james.task.TaskId;
@@ -66,13 +67,15 @@ public class CassandraMailboxMergingRoutes implements Routes {
     private final JsonExtractor<MailboxMergingRequest> jsonExtractor;
     private final TaskManager taskManager;
     private final JsonTransformer jsonTransformer;
+    private final CassandraMailboxCounterDAO counterDAO;
 
     @Inject
-    public CassandraMailboxMergingRoutes(MailboxMergingTaskRunner mailboxMergingTaskRunner,
CassandraId.Factory mailboxIdFactory, TaskManager taskManager, JsonTransformer jsonTransformer)
{
+    public CassandraMailboxMergingRoutes(MailboxMergingTaskRunner mailboxMergingTaskRunner,
CassandraId.Factory mailboxIdFactory, TaskManager taskManager, JsonTransformer jsonTransformer,
CassandraMailboxCounterDAO counterDAO) {
         this.mailboxMergingTaskRunner = mailboxMergingTaskRunner;
         this.mailboxIdFactory = mailboxIdFactory;
         this.taskManager = taskManager;
         this.jsonTransformer = jsonTransformer;
+        this.counterDAO = counterDAO;
         this.jsonExtractor = new JsonExtractor<>(MailboxMergingRequest.class);
     }
 
@@ -108,7 +111,8 @@ public class CassandraMailboxMergingRoutes implements Routes {
             CassandraId originId = mailboxIdFactory.fromString(mailboxMergingRequest.getMergeOrigin());
             CassandraId destinationId = mailboxIdFactory.fromString(mailboxMergingRequest.getMergeDestination());
 
-            MailboxMergingTask task = new MailboxMergingTask(mailboxMergingTaskRunner, originId,
destinationId);
+            long totalMessagesToMove = counterDAO.countMessagesInMailbox(originId).join().orElse(0L);
+            MailboxMergingTask task = new MailboxMergingTask(mailboxMergingTaskRunner, totalMessagesToMove,
originId, destinationId);
             TaskId taskId = taskManager.submit(task);
             return TaskIdDto.respond(response, taskId);
         } catch (JsonExtractException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/ff18af47/src/site/markdown/server/manage-webadmin.md
----------------------------------------------------------------------
diff --git a/src/site/markdown/server/manage-webadmin.md b/src/site/markdown/server/manage-webadmin.md
index ed67ae0..337c1c0 100644
--- a/src/site/markdown/server/manage-webadmin.md
+++ b/src/site/markdown/server/manage-webadmin.md
@@ -506,7 +506,10 @@ The scheduled task will have the following type `mailboxMerging` and
the followi
 ```
 {
   "oldMailboxId":"5641376-02ed-47bd-bcc7-76ff6262d92a",
-  "newMailboxId":"4555159-52ae-895f-ccb7-586a4412fb50"
+  "newMailboxId":"4555159-52ae-895f-ccb7-586a4412fb50",
+  "totalMessageCount": 1,
+  "messageMovedCount": 1,
+  "messageFailedCount": 0
 }
 ```
 


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