slfan1989 commented on code in PR #7266:
URL: https://github.com/apache/ozone/pull/7266#discussion_r2105504662


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -1633,4 +1639,89 @@ public String getMetrics(String query) throws 
IOException {
       throw ex;
     }
   }
+
+  @Override
+  public GetVolumeInfosResponseProto getVolumeInfos(String displayMode, String 
uuid,
+      String hostName, int pageSize, String startItem) throws IOException {
+
+    GetVolumeInfosResponseProto.Builder getVolumeInfosResponseBuilder =
+        GetVolumeInfosResponseProto.newBuilder();
+
+    NodeManager scmNodeManager = scm.getScmNodeManager();
+    List<? extends DatanodeDetails> allNodes = scmNodeManager.getAllNodes();
+
+    // If the UUID is not empty,
+    // we will filter the DNs that meet the UUID requirements.
+    if (StringUtils.isNotBlank(uuid)) {
+      allNodes = allNodes.stream().filter(filter ->
+                      StringUtils.equals(filter.getUuid().toString(), uuid)).
+              collect(Collectors.toList());
+    }
+
+    // If the hostName is not empty,
+    // we will filter the DNs that meet the hostName requirements.
+    if (StringUtils.isNotBlank(hostName)) {
+      allNodes = allNodes.stream().filter(filter ->
+                      StringUtils.equals(filter.getHostName(), hostName)).
+              collect(Collectors.toList());
+    }
+
+    // If the filtered list is empty, we will return directly.
+    if (CollectionUtils.isEmpty(allNodes)) {
+      return getVolumeInfosResponseBuilder.build();
+    }
+
+    // We convert it to a list of VolumeInfoProto.
+    List<VolumeInfoProto> volumeInfos = convertToVolumeInfos(allNodes);
+    switch (displayMode.toUpperCase()) {
+    case "FAILED":
+      // Display only failed volumes
+      volumeInfos = volumeInfos.stream().filter(filter -> filter.getFailed()).
+          collect(Collectors.toList());
+      break;
+    case "NORMAL":
+      // Display only normal volumes
+      volumeInfos = volumeInfos.stream().filter(filter -> !filter.getFailed()).
+          collect(Collectors.toList());
+      break;
+    case "ALL":
+    default:
+      break;
+    }
+
+    // If startItem is specified, find its position in the volumeInfos list

Review Comment:
   I added logic to skip startItem in this part of the code, but after thinking 
it through, I realized it’s better to use the server’s hostname or UUID as 
startItem instead of a disk prefix. That’s because many machines name their 
disks like data0 to data9, and using a disk name could lead to unexpected 
filtering behavior.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java:
##########
@@ -1633,4 +1639,89 @@ public String getMetrics(String query) throws 
IOException {
       throw ex;
     }
   }
+
+  @Override
+  public GetVolumeInfosResponseProto getVolumeInfos(String displayMode, String 
uuid,
+      String hostName, int pageSize, String startItem) throws IOException {
+
+    GetVolumeInfosResponseProto.Builder getVolumeInfosResponseBuilder =
+        GetVolumeInfosResponseProto.newBuilder();
+
+    NodeManager scmNodeManager = scm.getScmNodeManager();
+    List<? extends DatanodeDetails> allNodes = scmNodeManager.getAllNodes();
+
+    // If the UUID is not empty,
+    // we will filter the DNs that meet the UUID requirements.
+    if (StringUtils.isNotBlank(uuid)) {
+      allNodes = allNodes.stream().filter(filter ->
+                      StringUtils.equals(filter.getUuid().toString(), uuid)).
+              collect(Collectors.toList());
+    }
+
+    // If the hostName is not empty,
+    // we will filter the DNs that meet the hostName requirements.
+    if (StringUtils.isNotBlank(hostName)) {
+      allNodes = allNodes.stream().filter(filter ->
+                      StringUtils.equals(filter.getHostName(), hostName)).
+              collect(Collectors.toList());
+    }
+
+    // If the filtered list is empty, we will return directly.
+    if (CollectionUtils.isEmpty(allNodes)) {
+      return getVolumeInfosResponseBuilder.build();
+    }
+
+    // We convert it to a list of VolumeInfoProto.
+    List<VolumeInfoProto> volumeInfos = convertToVolumeInfos(allNodes);
+    switch (displayMode.toUpperCase()) {
+    case "FAILED":
+      // Display only failed volumes
+      volumeInfos = volumeInfos.stream().filter(filter -> filter.getFailed()).
+          collect(Collectors.toList());
+      break;
+    case "NORMAL":
+      // Display only normal volumes
+      volumeInfos = volumeInfos.stream().filter(filter -> !filter.getFailed()).
+          collect(Collectors.toList());
+      break;
+    case "ALL":
+    default:
+      break;
+    }
+
+    // If startItem is specified, find its position in the volumeInfos list
+    int startIndex = 0;
+    if (StringUtils.isNotBlank(startItem)) {
+      for (int i = 0; i < volumeInfos.size(); i++) {
+        if (volumeInfos.get(i).getUuid().equals(startItem) ||
+            volumeInfos.get(i).getHostName().equals(startItem)) {
+          startIndex = i + 1; // skip the startItem itself
+          break;
+        }
+      }
+    }

Review Comment:
   @adoroszlai I added logic to skip startItem in this part of the code, but 
after thinking it through, I realized it’s better to use the server’s hostname 
or UUID as startItem instead of a disk prefix. That’s because many machines 
name their disks like data0 to data9, and using a disk name could lead to 
unexpected filtering behavior.



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