From a95a9edb5eb62de2c6c6c47d2a9787f5a47e4044 Mon Sep 17 00:00:00 2001 From: Albert Louis Rossi Date: Mon, 2 Oct 2023 08:29:10 -0500 Subject: [PATCH] dcache-bulk: add convenience admin command for state counts Motivation: Counts of requests and targets by state are useful to have, especially when testing and debugging, but generally for the admin as well. These currently require a `ls` command with options. More convenient would be a single command that just delivers them. Modification: Added the command and a few method calls to the underlying db utility which already exists. Result: Much handier retrieval of this info. Target: master Request: 9.2 Patch: https://rb.dcache.org/r/14116/ Requires-notes: yes Acked-by: Tigran --- .../services/bulk/BulkServiceCommands.java | 23 +++++++++++++++++++ .../services/bulk/store/BulkRequestStore.java | 6 +++++ .../jdbc/request/JdbcBulkRequestDao.java | 4 ++++ .../jdbc/request/JdbcBulkRequestStore.java | 5 ++++ 4 files changed, 38 insertions(+) diff --git a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/BulkServiceCommands.java b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/BulkServiceCommands.java index 339675c7d4c..c483acbfe5a 100644 --- a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/BulkServiceCommands.java +++ b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/BulkServiceCommands.java @@ -86,6 +86,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING import java.util.Comparator; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; @@ -1145,6 +1146,28 @@ public String call() { } } + @Command(name = "status counts", + hint = "Display counts for requests and targets in various states.", + description = "Runs two database queries for actual counts.") + class StatusCounts implements Callable { + + @Override + public String call() { + Map requests = requestStore.countsByStatus(); + Map targets = targetStore.countsByState(); + + return new StringBuilder() + .append("---------- REQUESTS ----------\n") + .append(String.format(FORMAT_COUNTS + "\n", "STATUS", "COUNT")) + .append(requests.entrySet().stream().map(e -> String.format(FORMAT_COUNTS, + e.getKey(), e.getValue())).collect(joining("\n"))) + .append("\n\n---------- TARGETS -----------\n") + .append(String.format(FORMAT_COUNTS + "\n", "STATE", "COUNT")) + .append(targets.entrySet().stream().map(e -> String.format(FORMAT_COUNTS, + e.getKey(), e.getValue())).collect(joining("\n"))).toString(); + } + } + @Command(name = "target cancel", hint = "Cancel a job bound to a single target.", description = "Signals the manager to cancel a single target.") diff --git a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/BulkRequestStore.java b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/BulkRequestStore.java index 7130d466364..1531759c495 100644 --- a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/BulkRequestStore.java +++ b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/BulkRequestStore.java @@ -62,6 +62,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING import com.google.common.collect.ListMultimap; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.NoSuchElementException; import java.util.Optional; import java.util.Set; @@ -155,6 +156,11 @@ void clearWhenTerminated(Subject subject, String requestId) */ int countNonTerminated(String user) throws BulkStorageException; + /** + * @return a map of the combined results of target counts grouped by state. + */ + Map countsByStatus(); + /** * @param filter optional filter on the request. * @param limit max requests to return (can be null). diff --git a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestDao.java b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestDao.java index 25b64dec381..8b385125833 100644 --- a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestDao.java +++ b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestDao.java @@ -134,6 +134,10 @@ public int count(JdbcBulkRequestCriterion criterion) { return utils.count(criterion, TABLE_NAME, this); } + public Map countStatus() { + return utils.countGrouped(where().classifier("status"), TABLE_NAME, this); + } + /* * Should delete the jobs by cascading on the request id. */ diff --git a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestStore.java b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestStore.java index ae9b3c7bbc9..8151646c4e5 100644 --- a/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestStore.java +++ b/modules/dcache-bulk/src/main/java/org/dcache/services/bulk/store/jdbc/request/JdbcBulkRequestStore.java @@ -295,6 +295,11 @@ public int countNonTerminated(String user) throws BulkStorageException { return count; } + @Override + public Map countsByStatus() { + return requestDao.countStatus(); + } + @Override public Collection find(Optional requestFilter, Integer limit) throws BulkStorageException {