use of org.apache.cassandra.tools.nodetool.formatter.TableBuilder in project cassandra by apache.
the class CompactionStats method reportCompactionTable.
public static void reportCompactionTable(List<Map<String, String>> compactions, int compactionThroughput, boolean humanReadable) {
if (!compactions.isEmpty()) {
long remainingBytes = 0;
TableBuilder table = new TableBuilder();
table.add("id", "compaction type", "keyspace", "table", "completed", "total", "unit", "progress");
for (Map<String, String> c : compactions) {
long total = Long.parseLong(c.get("total"));
long completed = Long.parseLong(c.get("completed"));
String taskType = c.get("taskType");
String keyspace = c.get("keyspace");
String columnFamily = c.get("columnfamily");
String completedStr = humanReadable ? FileUtils.stringifyFileSize(completed) : Long.toString(completed);
String totalStr = humanReadable ? FileUtils.stringifyFileSize(total) : Long.toString(total);
String unit = c.get("unit");
String percentComplete = total == 0 ? "n/a" : new DecimalFormat("0.00").format((double) completed / total * 100) + "%";
String id = c.get("compactionId");
table.add(id, taskType, keyspace, columnFamily, completedStr, totalStr, unit, percentComplete);
if (taskType.equals(OperationType.COMPACTION.toString()))
remainingBytes += total - completed;
}
table.printTo(System.out);
String remainingTime = "n/a";
if (compactionThroughput != 0) {
long remainingTimeInSecs = remainingBytes / (1024L * 1024L * compactionThroughput);
remainingTime = format("%dh%02dm%02ds", remainingTimeInSecs / 3600, (remainingTimeInSecs % 3600) / 60, (remainingTimeInSecs % 60));
}
System.out.printf("%25s%10s%n", "Active compaction remaining time : ", remainingTime);
}
}
use of org.apache.cassandra.tools.nodetool.formatter.TableBuilder in project cassandra by apache.
the class ListSnapshots method execute.
@Override
public void execute(NodeProbe probe) {
try {
System.out.println("Snapshot Details: ");
final Map<String, TabularData> snapshotDetails = probe.getSnapshotDetails();
if (snapshotDetails.isEmpty()) {
System.out.printf("There are no snapshots");
return;
}
final long trueSnapshotsSize = probe.trueSnapshotsSize();
TableBuilder table = new TableBuilder();
// display column names only once
final List<String> indexNames = snapshotDetails.entrySet().iterator().next().getValue().getTabularType().getIndexNames();
table.add(indexNames.toArray(new String[indexNames.size()]));
for (final Map.Entry<String, TabularData> snapshotDetail : snapshotDetails.entrySet()) {
Set<?> values = snapshotDetail.getValue().keySet();
for (Object eachValue : values) {
final List<?> value = (List<?>) eachValue;
table.add(value.toArray(new String[value.size()]));
}
}
table.printTo(System.out);
System.out.println("\nTotal TrueDiskSpaceUsed: " + FileUtils.stringifyFileSize(trueSnapshotsSize) + "\n");
} catch (Exception e) {
throw new RuntimeException("Error during list snapshot", e);
}
}
use of org.apache.cassandra.tools.nodetool.formatter.TableBuilder in project cassandra by apache.
the class ViewBuildStatus method execute.
protected void execute(NodeProbe probe) {
String keyspace = null, view = null;
if (args.size() == 2) {
keyspace = args.get(0);
view = args.get(1);
} else if (args.size() == 1) {
String[] input = args.get(0).split("\\.");
checkArgument(input.length == 2, "viewbuildstatus requires keyspace and view name arguments");
keyspace = input[0];
view = input[1];
} else {
checkArgument(false, "viewbuildstatus requires keyspace and view name arguments");
}
Map<String, String> buildStatus = probe.getViewBuildStatuses(keyspace, view);
boolean failed = false;
TableBuilder builder = new TableBuilder();
builder.add("Host", "Info");
for (Map.Entry<String, String> status : buildStatus.entrySet()) {
if (!status.getValue().equals(SUCCESS)) {
failed = true;
}
builder.add(status.getKey(), status.getValue());
}
if (failed) {
System.out.println(String.format("%s.%s has not finished building; node status is below.", keyspace, view));
System.out.println();
builder.printTo(System.out);
System.exit(1);
} else {
System.out.println(String.format("%s.%s has finished building", keyspace, view));
System.exit(0);
}
}
Aggregations