Skip to content

Commit

Permalink
Merge pull request #7368 from alrossi/feature/9.2/bulk-counts-cmd
Browse files Browse the repository at this point in the history
dcache-bulk:  add convenience admin command for state counts
  • Loading branch information
svemeyer authored Oct 4, 2023
2 parents 576c9dd + 74bab64 commit 8ade537
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 @@ -295,6 +295,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 8ade537

Please sign in to comment.