Skip to content

Commit

Permalink
dcache-bulk: add convenience admin command for state counts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alrossi committed Oct 2, 2023
1 parent 28b0beb commit 74bab64
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> {

@Override
public String call() {
Map<String, Long> requests = requestStore.countsByStatus();
Map<String, Long> 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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Long> countsByStatus();

/**
* @param filter optional filter on the request.
* @param limit max requests to return (can be <code>null</code>).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public int count(JdbcBulkRequestCriterion criterion) {
return utils.count(criterion, TABLE_NAME, this);
}

public Map<String, Long> countStatus() {
return utils.countGrouped(where().classifier("status"), TABLE_NAME, this);
}

/*
* Should delete the jobs by cascading on the request id.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ public int countNonTerminated(String user) throws BulkStorageException {
return count;
}

@Override
public Map<String, Long> countsByStatus() {
return requestDao.countStatus();
}

@Override
public Collection<BulkRequest> find(Optional<BulkRequestFilter> requestFilter, Integer limit)
throws BulkStorageException {
Expand Down

0 comments on commit 74bab64

Please sign in to comment.