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 {