This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit b01790c5540dad12569ed459feffc581065896cb
Author: LanKhuat <khuatdang...@gmail.com>
AuthorDate: Thu May 21 15:13:59 2020 +0700

    JAMES-3184 Update routes with RunningOptions parameter
---
 .../james/webadmin/routes/MailboxesRoutes.java     | 23 +++++++++--
 .../webadmin/routes/RunningOptionsParser.java      | 44 ++++++++++++++++++++++
 .../james/webadmin/routes/UserMailboxesRoutes.java |  2 +-
 3 files changed, 65 insertions(+), 4 deletions(-)

diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MailboxesRoutes.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MailboxesRoutes.java
index 72ad721..512d26d 100644
--- 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MailboxesRoutes.java
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/MailboxesRoutes.java
@@ -84,6 +84,14 @@ public class MailboxesRoutes implements Routes {
                 example = "?task=reIndex",
                 value = "Compulsory. Only supported value is `reIndex`"),
             @ApiImplicitParam(
+                required = false,
+                name = "messagesPerSecond",
+                paramType = "query parameter",
+                dataType = "Integer",
+                defaultValue = "none",
+                example = "?messagesPerSecond=100",
+                value = "If present, determine the number of messages being 
processed in one second."),
+            @ApiImplicitParam(
                 name = "reIndexFailedMessagesOf",
                 paramType = "query parameter",
                 dataType = "String",
@@ -101,9 +109,10 @@ public class MailboxesRoutes implements Routes {
             boolean indexingCorrection = 
!Strings.isNullOrEmpty(request.queryParams(RE_INDEX_FAILED_MESSAGES_QUERY_PARAM));
             if (indexingCorrection) {
                 IndexingDetailInformation indexingDetailInformation = 
retrieveIndexingExecutionDetails(previousReIndexingService, request);
-                return reIndexer.reIndex(indexingDetailInformation.failures());
+                return reIndexer.reIndex(indexingDetailInformation.failures(), 
RunningOptionsParser.parse(request));
             }
-            return reIndexer.reIndex();
+
+            return reIndexer.reIndex(RunningOptionsParser.parse(request));
         }
 
         private static IndexingDetailInformation 
retrieveIndexingExecutionDetails(PreviousReIndexingService 
previousReIndexingService, Request request) {
@@ -161,6 +170,14 @@ public class MailboxesRoutes implements Routes {
                 example = "?task=reIndex",
                 value = "Compulsory. Only supported value is `reIndex`"),
             @ApiImplicitParam(
+                required = false,
+                name = "messagesPerSecond",
+                paramType = "query parameter",
+                dataType = "Integer",
+                defaultValue = "none",
+                example = "?messagesPerSecond=100",
+                value = "If present, determine the number of messages being 
processed in one second."),
+            @ApiImplicitParam(
                 required = true,
                 name = "mailboxId",
                 paramType = "path parameter",
@@ -174,7 +191,7 @@ public class MailboxesRoutes implements Routes {
             @ApiResponse(code = HttpStatus.BAD_REQUEST_400, message = "Bad 
request - details in the returned error message")
         })
         private static TaskFromRequest toTask(ReIndexer reIndexer, 
MailboxId.Factory mailboxIdFactory) {
-            return wrap(request -> 
reIndexer.reIndex(extractMailboxId(mailboxIdFactory, request)));
+            return wrap(request -> 
reIndexer.reIndex(extractMailboxId(mailboxIdFactory, request), 
RunningOptionsParser.parse(request)));
         }
     }
 
diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/RunningOptionsParser.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/RunningOptionsParser.java
new file mode 100644
index 0000000..733c7f5
--- /dev/null
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/RunningOptionsParser.java
@@ -0,0 +1,44 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.webadmin.routes;
+
+import java.util.Optional;
+
+import org.apache.james.mailbox.indexer.ReIndexer.RunningOptions;
+
+import spark.Request;
+
+public class RunningOptionsParser {
+    public static RunningOptions parse(Request request) {
+        return intQueryParameter(request, "messagesPerSecond")
+            .map(RunningOptions::new)
+            .orElse(RunningOptions.DEFAULT);
+    }
+
+    public static Optional<Integer> intQueryParameter(Request request, String 
queryParameter) {
+        try {
+            return Optional.ofNullable(request.queryParams(queryParameter))
+                .map(Integer::parseInt);
+        } catch (NumberFormatException e) {
+            throw new IllegalArgumentException(String.format("Illegal value 
supplied for query parameter '%s', expecting a " +
+                "strictly positive optional integer", queryParameter), e);
+        }
+    }
+}
\ No newline at end of file
diff --git 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
index ddaef99..55f950c 100644
--- 
a/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
+++ 
b/server/protocols/webadmin/webadmin-mailbox/src/main/java/org/apache/james/webadmin/routes/UserMailboxesRoutes.java
@@ -74,7 +74,7 @@ public class UserMailboxesRoutes implements Routes {
     public static class UserReIndexingTaskRegistration extends 
TaskRegistration {
         @Inject
         public UserReIndexingTaskRegistration(ReIndexer reIndexer) {
-            super(RE_INDEX, request -> 
reIndexer.reIndex(getUsernameParam(request)));
+            super(RE_INDEX, request -> 
reIndexer.reIndex(getUsernameParam(request), 
RunningOptionsParser.parse(request)));
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to