adoroszlai commented on code in PR #10058:
URL: https://github.com/apache/ozone/pull/10058#discussion_r3055748310


##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -210,6 +235,7 @@ private void printDatanodeInfo(BasicDatanodeInfo dn) {
       }
     } else {
       pipelineListInfo.append("No pipelines in cluster.");
+      pipelineListInfo.append(System.getProperty("line.separator"));

Review Comment:
   Why is this needed?  `pipelineListInfo` is output with `println` below.



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -92,7 +98,8 @@ public void execute(ScmClient scmClient) throws IOException {
       Integer healthyVolumeCount = node.hasHealthyVolumeCount() ? 
node.getHealthyVolumeCount() : null;
       BasicDatanodeInfo singleNodeInfo = new BasicDatanodeInfo.Builder(
           DatanodeDetails.getFromProtoBuf(node.getNodeID()), 
node.getNodeOperationalStates(0),
-          node.getNodeStates(0)).withVolumeCounts(totalVolumeCount, 
healthyVolumeCount).build();
+          node.getNodeStates(0)).withVolumeCounts(totalVolumeCount, 
healthyVolumeCount)
+          .withFailedVolumes(getFailedVolumes(node)).build();

Review Comment:
   I'd like to suggest a small refactoring to reduce duplication of code 
related to `BasicDatanodeInfo` creation.
   
   
[HDDS-14990.patch](https://github.com/user-attachments/files/26590391/HDDS-14990.patch)
   



##########
hadoop-ozone/cli-admin/src/test/java/org/apache/hadoop/hdds/scm/cli/datanode/TestListInfoSubcommand.java:
##########
@@ -357,6 +357,50 @@ public void testVolumeCounters() throws Exception {
     assertTrue(output.contains("Healthy volume count:"), "Should display 
healthy volume count");
   }
 
+  @Test
+  public void testFailedVolumesFilter() throws Exception {
+    ScmClient scmClient = mock(ScmClient.class);
+    List<HddsProtos.Node> baseNodes = getNodeDetails();
+
+    List<HddsProtos.Node> nodes = new ArrayList<>();
+    // node 0: 1 failed volume
+    nodes.add(HddsProtos.Node.newBuilder(baseNodes.get(0))
+        .setTotalVolumeCount(4).setHealthyVolumeCount(3)
+        .addFailedVolumes("/data/disk2").build());
+    // node 1: healthy, no failed volumes
+    nodes.add(HddsProtos.Node.newBuilder(baseNodes.get(1))
+        .setTotalVolumeCount(4).setHealthyVolumeCount(4).build());
+    // node 2: 2 failed volumes
+    nodes.add(HddsProtos.Node.newBuilder(baseNodes.get(2))
+        .setTotalVolumeCount(6).setHealthyVolumeCount(4)
+        .addFailedVolumes("/data/disk1")
+        .addFailedVolumes("/data/disk5").build());
+    // node 3: healthy, no failed volumes
+    nodes.add(HddsProtos.Node.newBuilder(baseNodes.get(3))
+        .setTotalVolumeCount(4).setHealthyVolumeCount(4).build());
+
+    when(scmClient.queryNode(any(), any(), any(), any())).thenReturn(nodes);
+    when(scmClient.listPipelines()).thenReturn(new ArrayList<>());
+
+    CommandLine c = new CommandLine(cmd);
+    c.parseArgs("--failed-volumes");
+    cmd.execute(scmClient);
+    String output = outContent.toString(DEFAULT_ENCODING);
+
+    // Only 2 datanodes (those with failed volumes) should appear
+    Matcher m = Pattern.compile("^Datanode:", Pattern.MULTILINE)
+        .matcher(output);
+    int count = 0;
+    while (m.find()) {
+      count++;
+    }
+    assertEquals(2, count, "Only datanodes with failed volumes should be 
listed");
+    assertTrue(output.contains("Failed volume"));
+    assertTrue(output.contains("/data/disk2"));
+    assertTrue(output.contains("/data/disk1"));
+    assertTrue(output.contains("/data/disk5"));

Review Comment:
   nit: please use `assertThat(output).contains(...)` for better failure 
message (see HDDS-9951)



##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/hdds/scm/cli/datanode/ListInfoSubcommand.java:
##########
@@ -65,6 +66,11 @@ public class ListInfoSubcommand extends ScmSubcommand {
        defaultValue = "false")
   private boolean json;
 
+  @CommandLine.Option(names = {"--failed-volumes"},
+      description = "Only show datanodes that have at least one failed 
volume.",

Review Comment:
   Would `--with-failed-volume` be better?



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