aryangupta1998 commented on code in PR #8520:
URL: https://github.com/apache/ozone/pull/8520#discussion_r2197986104


##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -135,6 +149,37 @@ public void execute(ScmClient scmClient) throws 
IOException {
 
   private List<DatanodeWithAttributes> getAllNodes(ScmClient scmClient)
       throws IOException {
+
+    // If sorting is requested
+    if (usageSortingOptions != null && (usageSortingOptions.mostUsed || 
usageSortingOptions.leastUsed)) {
+      boolean sortByMostUsed = usageSortingOptions.mostUsed;
+      List<HddsProtos.DatanodeUsageInfoProto> usageInfos = 
scmClient.getDatanodeUsageInfo(sortByMostUsed, 
+          Integer.MAX_VALUE);
+
+      return usageInfos.stream()
+          .map(p -> {
+            String uuidStr = p.getNode().getUuid();
+            UUID parsedUuid = UUID.fromString(uuidStr);
+
+            try {
+              HddsProtos.Node node = scmClient.queryNode(parsedUuid);
+              long capacity = p.getCapacity();
+              long used = capacity - p.getRemaining();
+              double percentUsed = (capacity > 0) ? (used * 100.0) / capacity 
: 0.0;
+              return new DatanodeWithAttributes(
+                  DatanodeDetails.getFromProtoBuf(node.getNodeID()),
+                  node.getNodeOperationalStates(0),
+                  node.getNodeStates(0),
+                  used,
+                  capacity,
+                  percentUsed);
+            } catch (IOException e) {
+              return null;
+            }
+          })
+          .collect(Collectors.toList());

Review Comment:
   ```suggestion
             .filter(Objects::nonNull)
             .collect(Collectors.toList());
   ```



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -177,12 +222,23 @@ private void printDatanodeInfo(DatanodeWithAttributes 
dna) {
     System.out.println("Operational State: " + dna.getOpState());
     System.out.println("Health State: " + dna.getHealthState());
     System.out.println("Related pipelines:\n" + pipelineListInfo);
+
+    if (dna.getUsed() != null && dna.getCapacity() != null && dna.getUsed() >= 
0 && dna.getCapacity() > 0) {
+      System.out.println("Used: " + dna.getUsed());
+      System.out.println("Capacity: " + dna.getCapacity() + "\n");

Review Comment:
   ```suggestion
         System.out.println("Capacity: " + dna.getCapacity() + "\n");
         System.out.printf("Used %%: %.2f%%\n\n", dna.getPercentUsed());
   ```



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -78,11 +79,24 @@ public class ListInfoSubcommand extends ScmSubcommand {
        defaultValue = "false")
   private boolean json;
 
+  @CommandLine.ArgGroup(exclusive = true, multiplicity = "0..1")
+  private UsageSortingOptions usageSortingOptions;
+
   @CommandLine.Mixin
   private ListLimitOptions listLimitOptions;
 
   private List<Pipeline> pipelines;
 
+  static class UsageSortingOptions {
+    @CommandLine.Option(names = {"--most-used"},
+        description = "Show datanodes sorted by highest usage.")

Review Comment:
   ```suggestion
           description = "Show datanodes sorted by percentage of space used 
(most to least).")
   ```



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -78,11 +79,24 @@ public class ListInfoSubcommand extends ScmSubcommand {
        defaultValue = "false")
   private boolean json;
 
+  @CommandLine.ArgGroup(exclusive = true, multiplicity = "0..1")
+  private UsageSortingOptions usageSortingOptions;
+
   @CommandLine.Mixin
   private ListLimitOptions listLimitOptions;
 
   private List<Pipeline> pipelines;
 
+  static class UsageSortingOptions {
+    @CommandLine.Option(names = {"--most-used"},
+        description = "Show datanodes sorted by highest usage.")
+    private boolean mostUsed;
+
+    @CommandLine.Option(names = {"--least-used"},
+        description = "Show datanodes sorted by lowest usage.")

Review Comment:
   ```suggestion
           description = "Show datanodes sorted by percentage of space used 
(least to most).")
   ```



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -135,6 +149,37 @@ public void execute(ScmClient scmClient) throws 
IOException {
 
   private List<DatanodeWithAttributes> getAllNodes(ScmClient scmClient)
       throws IOException {
+
+    // If sorting is requested
+    if (usageSortingOptions != null && (usageSortingOptions.mostUsed || 
usageSortingOptions.leastUsed)) {
+      boolean sortByMostUsed = usageSortingOptions.mostUsed;
+      List<HddsProtos.DatanodeUsageInfoProto> usageInfos = 
scmClient.getDatanodeUsageInfo(sortByMostUsed, 
+          Integer.MAX_VALUE);
+
+      return usageInfos.stream()
+          .map(p -> {
+            String uuidStr = p.getNode().getUuid();
+            UUID parsedUuid = UUID.fromString(uuidStr);
+
+            try {
+              HddsProtos.Node node = scmClient.queryNode(parsedUuid);
+              long capacity = p.getCapacity();
+              long used = capacity - p.getRemaining();
+              double percentUsed = (capacity > 0) ? (used * 100.0) / capacity 
: 0.0;
+              return new DatanodeWithAttributes(
+                  DatanodeDetails.getFromProtoBuf(node.getNodeID()),
+                  node.getNodeOperationalStates(0),
+                  node.getNodeStates(0),
+                  used,
+                  capacity,
+                  percentUsed);
+            } catch (IOException e) {
+              return null;

Review Comment:
   ```suggestion
                 LOG.warn("Failed to fetch node info for UUID {}: {}", 
parsedUuid, e.getMessage());
                 return null;
   ```



-- 
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]

Reply via email to