dlmarion commented on code in PR #5332:
URL: https://github.com/apache/accumulo/pull/5332#discussion_r1964103516
##########
server/base/src/main/java/org/apache/accumulo/server/util/ECAdmin.java:
##########
@@ -153,43 +165,115 @@ private void listCompactorsByQueue(ServerContext
context) {
}
}
- private void runningCompactions(ServerContext context, boolean details) {
+ private void runningCompactions(ServerContext context, boolean details,
String format) {
CompactionCoordinatorService.Client coordinatorClient = null;
- TExternalCompactionList running;
+ Map<String,TExternalCompaction> runningCompactionsMap = new HashMap<>();
+
+ // Default to "plain" format if null or empty
+ if (format == null || format.trim().isEmpty()) {
+ format = "plain";
+ }
+
+ // Validate format
+ Set<String> validFormats = Set.of("plain", "csv", "json");
+ if (!validFormats.contains(format.toLowerCase())) {
+ throw new IllegalArgumentException(
+ "Invalid format: " + format + ". Expected: plain, csv, or json.");
+ }
Review Comment:
I don't think you need to re-validate the format if you are setting it to a
known value.
```suggestion
if (format == null || format.trim().isEmpty()) {
format = "plain";
} else {
// Validate format
Set<String> validFormats = Set.of("plain", "csv", "json");
if (!validFormats.contains(format.toLowerCase())) {
throw new IllegalArgumentException(
"Invalid format: " + format + ". Expected: plain, csv, or
json.");
}
}
```
##########
server/base/src/main/java/org/apache/accumulo/server/util/ECAdmin.java:
##########
@@ -153,43 +165,115 @@ private void listCompactorsByQueue(ServerContext
context) {
}
}
- private void runningCompactions(ServerContext context, boolean details) {
+ private void runningCompactions(ServerContext context, boolean details,
String format) {
CompactionCoordinatorService.Client coordinatorClient = null;
- TExternalCompactionList running;
+ Map<String,TExternalCompaction> runningCompactionsMap = new HashMap<>();
+
+ // Default to "plain" format if null or empty
+ if (format == null || format.trim().isEmpty()) {
+ format = "plain";
+ }
+
+ // Validate format
+ Set<String> validFormats = Set.of("plain", "csv", "json");
+ if (!validFormats.contains(format.toLowerCase())) {
+ throw new IllegalArgumentException(
+ "Invalid format: " + format + ". Expected: plain, csv, or json.");
+ }
+
try {
coordinatorClient = getCoordinatorClient(context);
- running = coordinatorClient.getRunningCompactions(TraceUtil.traceInfo(),
context.rpcCreds());
- if (running == null) {
+
+ // Fetch running compactions as a list and convert to a map
+ TExternalCompactionList running =
+ coordinatorClient.getRunningCompactions(TraceUtil.traceInfo(),
context.rpcCreds());
+
+ if (running == null || running.getCompactions().isEmpty()) {
System.out.println("No running compactions found.");
return;
}
- var ecidMap = running.getCompactions();
- if (ecidMap == null) {
- System.out.println("No running compactions found.");
- return;
+
+ // Convert the list to a map
+ for (Map.Entry<String,TExternalCompaction> entry :
running.getCompactions().entrySet()) {
+ runningCompactionsMap.put(entry.getKey(), entry.getValue());
}
- ecidMap.forEach((ecid, ec) -> {
- if (ec != null) {
- var runningCompaction = new RunningCompaction(ec);
- var addr = runningCompaction.getCompactorAddress();
- var kind = runningCompaction.getJob().kind;
- var queue = runningCompaction.getQueueName();
- var ke = KeyExtent.fromThrift(runningCompaction.getJob().extent);
- System.out.format("%s %s %s %s TableId: %s\n", ecid, addr, kind,
queue, ke.tableId());
- if (details) {
- var runningCompactionInfo = new RunningCompactionInfo(ec);
- var status = runningCompactionInfo.status;
- var last = runningCompactionInfo.lastUpdate;
- var duration = runningCompactionInfo.duration;
- var numFiles = runningCompactionInfo.numFiles;
- var progress = runningCompactionInfo.progress;
- System.out.format(" %s Last Update: %dms Duration: %dms Files: %d
Progress: %.2f%%\n",
- status, last, duration, numFiles, progress);
- }
+
+ // Print CSV header if format is CSV
+ if ("csv".equalsIgnoreCase(format)) {
+ System.out.println(
+
"ECID,Compactor,Kind,Queue,TableId,Status,LastUpdate,Duration,NumFiles,Progress");
+ }
+
+ for (Map.Entry<String,TExternalCompaction> entry :
runningCompactionsMap.entrySet()) {
+ TExternalCompaction ec = entry.getValue();
+ if (ec == null) {
+ continue;
+ }
+
+ var runningCompaction = new RunningCompaction(ec);
+ String ecid = runningCompaction.getJob().getExternalCompactionId();
+ var addr = runningCompaction.getCompactorAddress();
+ var kind = runningCompaction.getJob().kind;
+ var queueName = runningCompaction.getQueueName();
+ var ke = KeyExtent.fromThrift(runningCompaction.getJob().extent);
+ String tableId = ke.tableId().canonical();
+
+ String status = "";
+ long lastUpdate = 0, duration = 0;
+ int numFiles = 0;
+ double progress = 0.0;
+
+ if (details) {
+ var runningCompactionInfo = new RunningCompactionInfo(ec);
+ status = runningCompactionInfo.status;
+ lastUpdate = runningCompactionInfo.lastUpdate;
+ duration = runningCompactionInfo.duration;
+ numFiles = runningCompactionInfo.numFiles;
+ progress = runningCompactionInfo.progress;
+ }
+
+ // Output handling
+ switch (format.toLowerCase()) {
+ case "plain":
+ System.out.format("%s %s %s %s TableId: %s\n", ecid, addr, kind,
queueName, tableId);
+ if (details) {
+ System.out.format(
+ " %s Last Update: %dms Duration: %dms Files: %d Progress:
%.2f%%\n", status,
+ lastUpdate, duration, numFiles, progress);
+ }
+ break;
+ case "csv":
+
System.out.println(String.format("%s,%s,%s,%s,%s,%s,%d,%d,%d,%.2f", ecid, addr,
kind,
+ queueName, tableId, status, lastUpdate, duration, numFiles,
progress));
+ break;
+ case "json":
+ // Print JSON entry-by-entry immediately
Review Comment:
I think previously you were aggregating the json objects into a list, then
serlializing the list at the end to make valid json. I believe my suggestion
for not aggregating was for the non-json formats. We probably want to output
valid json in the case that the user asks for json.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]