anuragp010 commented on code in PR #11866:
URL: https://github.com/apache/ozone/pull/11866#discussion_r4537400933
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerAssessmentSubcommand.java:
##########
@@ -272,36 +338,62 @@ private static void
printJsonReport(ContainerBalancerClusterSnapshot snapshot, d
result.put("upperLimitPercentage",
toJsonPercent(snapshot.getUpperLimit()));
result.put("lowerLimitPercentage",
toJsonPercent(snapshot.getLowerLimit()));
- Map<String, Object> sourceNodes = new LinkedHashMap<>();
- sourceNodes.put("count", snapshot.getSourceCount());
- sourceNodes.put("nodes", snapshot.getTopSourceNodes().stream()
- .map(node -> {
- Map<String, Object> nodeMap = new LinkedHashMap<>();
- nodeMap.put("hostname", node.getHostname());
- nodeMap.put("utilizationPercentage",
toJsonPercent(node.getUtilization()));
- return nodeMap;
- })
- .collect(Collectors.toList()));
- result.put("sourceNodes", sourceNodes);
-
- Map<String, Object> targetNodes = new LinkedHashMap<>();
- targetNodes.put("count", snapshot.getTargetCount());
- targetNodes.put("nodes", snapshot.getBottomTargetNodes().stream()
- .map(node -> {
- Map<String, Object> nodeMap = new LinkedHashMap<>();
- nodeMap.put("hostname", node.getHostname());
- nodeMap.put("utilizationPercentage",
toJsonPercent(node.getUtilization()));
- return nodeMap;
- })
- .collect(Collectors.toList()));
- result.put("targetNodes", targetNodes);
+ boolean typed = !snapshot.getStorageTypeSnapshots().isEmpty();
+ result.put(typed ? "sourceNodesAcrossStorageTypes" : "sourceNodes",
+ jsonNodes(snapshot.getSourceCount(),
snapshot.getTopSourceNodesAcrossStorageTypes()));
+ result.put(typed ? "targetNodesAcrossStorageTypes" : "targetNodes",
+ jsonNodes(snapshot.getTargetCount(),
snapshot.getBottomTargetNodesAcrossStorageTypes()));
double movementRatio = snapshot.getClusterCapacityBytes() == 0 ? 0
- : (double) snapshot.getBytesToMove() /
snapshot.getClusterCapacityBytes();
+ : (double) snapshot.getTotalBytesToMove() /
snapshot.getClusterCapacityBytes();
+ result.put(typed ? "totalBytesToMove" : "bytesToMove",
snapshot.getTotalBytesToMove());
+ result.put("movementRatioPercentage", toJsonPercent(movementRatio));
+
+ if (!snapshot.getStorageTypeSnapshots().isEmpty()) {
+ result.put("maxStorageTypeImbalancePercentage",
toJsonPercent(snapshot.getMaxImbalance()));
+ result.put("mostImbalancedStorageType",
snapshot.getMostImbalancedStorageType().name());
+ Map<String, Object> storageTypes = new LinkedHashMap<>();
+ snapshot.getStorageTypeSnapshots().forEach((type, usage) ->
+ storageTypes.put(type.name(), jsonReport(usage, thresholdRatio)));
+ result.put("storageTypes", storageTypes);
+ result.put("incompleteStorageTypeUsage",
snapshot.hasIncompleteStorageTypeUsage());
+ }
+ return result;
+ }
+
+ private static Map<String, Object> jsonReport(StorageTypeSnapshot snapshot,
double thresholdRatio) {
+ Map<String, Object> result = new LinkedHashMap<>();
+ result.put("totalEligibleDatanodes", snapshot.getEligibleDatanodes());
+ result.put("thresholdPercentage", toJsonPercent(thresholdRatio));
+ result.put("averageUtilizationPercentage",
toJsonPercent(snapshot.getAverageUtilization()));
+ result.put("driftPercentage", toJsonPercent(snapshot.getImbalance()));
+ result.put("maxUtilizationPercentage",
toJsonPercent(snapshot.getMaxUtilization()));
+ result.put("minUtilizationPercentage",
toJsonPercent(snapshot.getMinUtilization()));
+ result.put("upperLimitPercentage",
toJsonPercent(snapshot.getUpperLimit()));
+ result.put("lowerLimitPercentage",
toJsonPercent(snapshot.getLowerLimit()));
+ result.put("sourceNodes", jsonNodes(snapshot.getSourceCount(),
snapshot.getTopSourceNodes()));
+ result.put("targetNodes", jsonNodes(snapshot.getTargetCount(),
snapshot.getBottomTargetNodes()));
result.put("bytesToMove", snapshot.getBytesToMove());
+ double movementRatio = snapshot.getCapacityBytes() == 0 ? 0
+ : (double) snapshot.getBytesToMove() / snapshot.getCapacityBytes();
result.put("movementRatioPercentage", toJsonPercent(movementRatio));
+ return result;
+ }
- System.out.println(JsonUtils.toJsonStringWithDefaultPrettyPrinter(result));
+ private static Map<String, Object> jsonNodes(int count,
Review Comment:
nit: should we rename this to `jsonNodesSummary`?
##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/ContainerBalancerAssessmentSubcommand.java:
##########
@@ -272,36 +338,62 @@ private static void
printJsonReport(ContainerBalancerClusterSnapshot snapshot, d
result.put("upperLimitPercentage",
toJsonPercent(snapshot.getUpperLimit()));
result.put("lowerLimitPercentage",
toJsonPercent(snapshot.getLowerLimit()));
- Map<String, Object> sourceNodes = new LinkedHashMap<>();
- sourceNodes.put("count", snapshot.getSourceCount());
- sourceNodes.put("nodes", snapshot.getTopSourceNodes().stream()
- .map(node -> {
- Map<String, Object> nodeMap = new LinkedHashMap<>();
- nodeMap.put("hostname", node.getHostname());
- nodeMap.put("utilizationPercentage",
toJsonPercent(node.getUtilization()));
- return nodeMap;
- })
- .collect(Collectors.toList()));
- result.put("sourceNodes", sourceNodes);
-
- Map<String, Object> targetNodes = new LinkedHashMap<>();
- targetNodes.put("count", snapshot.getTargetCount());
- targetNodes.put("nodes", snapshot.getBottomTargetNodes().stream()
- .map(node -> {
- Map<String, Object> nodeMap = new LinkedHashMap<>();
- nodeMap.put("hostname", node.getHostname());
- nodeMap.put("utilizationPercentage",
toJsonPercent(node.getUtilization()));
- return nodeMap;
- })
- .collect(Collectors.toList()));
- result.put("targetNodes", targetNodes);
+ boolean typed = !snapshot.getStorageTypeSnapshots().isEmpty();
+ result.put(typed ? "sourceNodesAcrossStorageTypes" : "sourceNodes",
Review Comment:
`combineStorageTypes` adds every type's source and target IDs to the
combined sets, even for a type whose `bytesToMove` is 0 because it has no
source/target pair.
For example, in
`testSourcesAndTargetsOnDifferentStorageTypesCannotBePaired`, `first` is a
source for SSD and a target for DISK. Neither type has a pair, so `bytesToMove`
is 0. The combined snapshot still has `sourceCount == 1` and `targetCount == 1`.
In the json output, those counts (`sourceNodesAcrossStorageTypes.count`)
next to `totalBytesToMove: 0`.
Would it be clearer to add a type's IDs to the combined sets only when that
type has `bytesToMove > 0`?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]