Skip to content

Commit

Permalink
dcache-bulk: add count and clear to archive admin commands
Browse files Browse the repository at this point in the history
Motivation:

Convenience (not having to run query on the database
interpreter).

Modification:

Add commands to display the count instead of the
actual entry (as with requests and targets), and
also a command to clear/delete from the archive
table.

Result:

Friendlier admin interface.

Target: master
Request: 9.2
Patch: https://rb.dcache.org/r/14119/
Requires-notes: yes
Acked-by: Lea
  • Loading branch information
alrossi authored and lemora committed Oct 11, 2023
1 parent 95f53d8 commit 2013599
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Expand Up @@ -110,6 +110,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import org.dcache.services.bulk.manager.BulkRequestManager;
import org.dcache.services.bulk.store.BulkRequestStore;
import org.dcache.services.bulk.store.BulkTargetStore;
import org.dcache.services.bulk.store.jdbc.request.JdbcArchivedBulkRequestCriterion;
import org.dcache.services.bulk.store.jdbc.request.JdbcBulkArchiveDao;
import org.dcache.services.bulk.store.jdbc.request.JdbcBulkRequestArchiver;
import org.dcache.services.bulk.util.BulkRequestFilter;
Expand Down Expand Up @@ -667,10 +668,53 @@ public String call() throws Exception {
}
}

@Command(name = "request archived clear",
hint = "Clear archived requests",
description = ".")
class RequestArchivedClear implements Callable<String> {
@Option(name = "owner",
separator = ",",
usage = "The owner of the request.")
String[] owner;

@Option(name = "before",
valueSpec = DATE_FORMAT,
usage = "Select requests with last modified date-time before date-time.")
String before;

@Option(name = "after",
valueSpec = DATE_FORMAT,
usage = "Select requests with last modified date-time after date-time.")
String after;

@Option(name = "activity",
separator = ",",
usage = "The request activity.")
String[] activity;

@Option(name = "status",
valueSpec = "COMPLETED|CANCELLED",
separator = ",",
usage = "Status of the request.")
String[] status;

@Override
public String call() throws Exception {
JdbcArchivedBulkRequestCriterion criterion =
archiveDao.where().modifiedBefore(getTimestamp(before))
.modifiedAfter(getTimestamp(after)).owner(owner).activity(activity)
.status(status);

int count = archiveDao.count(criterion);
executor.submit(() -> archiveDao.delete(criterion));
return "Removing " + count + " archived requests.";
}
}

@Command(name = "request archived ls",
hint = "List archived requests",
description = "Display the uid, owner, last modified, activity and status for"
+ " the archived request.")
+ " the archived request, or just counts if option is true.")
class RequestArchivedLs implements Callable<String> {

@Option(name = "owner",
Expand Down Expand Up @@ -699,12 +743,23 @@ class RequestArchivedLs implements Callable<String> {
usage = "Status of the request.")
String[] status;

@Option(name = "count",
usage = "return only the count of the matching requests.")
Boolean count = false;

@Option(name = "limit",
usage = "Return maximum of this many entries.")
Integer limit = 5000;

@Override
public String call() throws Exception {
if (count) {
return String.valueOf(
archiveDao.count(archiveDao.where().modifiedBefore(getTimestamp(before))
.modifiedAfter(getTimestamp(after)).owner(owner).activity(activity)
.status(status)));
}

List<BulkArchivedSummaryInfo> list =
archiveDao.list(archiveDao.where().modifiedBefore(getTimestamp(before))
.modifiedAfter(getTimestamp(after)).owner(owner).activity(activity)
Expand Down
Expand Up @@ -132,6 +132,10 @@ public int count(JdbcArchivedBulkRequestCriterion criterion) {
return utils.count(criterion, TABLE_NAME, this);
}

public int delete(JdbcArchivedBulkRequestCriterion criterion) {
return utils.delete(criterion, TABLE_NAME, this);
}

public List<BulkArchivedRequestInfo> get(JdbcArchivedBulkRequestCriterion criterion, int limit) {
return utils.get(SELECT_INFO, criterion, limit, TABLE_NAME, this, infoRowMapper);
}
Expand Down

0 comments on commit 2013599

Please sign in to comment.