AdyChechani commented on code in PR #10831:
URL: https://github.com/apache/ozone/pull/10831#discussion_r3748813161


##########
hadoop-ozone/cli-admin/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -92,20 +91,18 @@ private Map<String, Map<String, String>> parseScmRoles(
     Map<String, Map<String, String>> allRoles = new HashMap<>();
     for (String role : peerRoles) {
       Map<String, String> roleDetails = new HashMap<>();
-      String[] roles = role.split(":");
-      if (roles.length < 2) {
-        err.println("Invalid response received for ScmRatisRoles.");
-        return Collections.emptyMap();
-      }
-      // In case, there is no ratis, there is no ratis role.
-      // This will just print the hostname with ratis port as the address
-      roleDetails.put("address", roles[0].concat(":").concat(roles[1]));
-      if (roles.length == 5) {
-        roleDetails.put("raftPeerRole", roles[2]);
-        roleDetails.put("ID", roles[3]);
-        roleDetails.put("InetAddress", roles[4]);
+      try {
+        String[] fields = HddsUtils.parseRatisRoleString(role);
+        roleDetails.put("address", HddsUtils.getHostPortString(
+            fields[0], Integer.parseInt(fields[1])));
+        roleDetails.put("raftPeerRole", fields[2]);
+        roleDetails.put("ID", fields[3]);
+        roleDetails.put("InetAddress", fields[4]);
+        allRoles.put(fields[0], roleDetails);
+      } catch (IllegalArgumentException e) {
+        roleDetails.put("address", role);
+        allRoles.put(role, roleDetails);

Review Comment:
   Fixed 👍 The catch block retains parsing short non-Ratis strings with 
`HostAndPort.fromString()`, preserving the original column structure.
   
   Older table:
   ```
   +--------------------------------------------------------+
   |            Storage Container Manager Roles             |
   +-----------+------------+------+---------+--------------+
   | Host Name | Ratis Port | Role | Node ID | Host Address |
   +-----------+------------+------+---------+--------------+
   | host:9894 |            |      |         |              |
   +-----------+------------+------+---------+--------------+
   ```
   
   Now:
   ```
   +--------------------------------------------------------+
   |            Storage Container Manager Roles             |
   +-----------+------------+------+---------+--------------+
   | Host Name | Ratis Port | Role | Node ID | Host Address |
   +-----------+------------+------+---------+--------------+
   |   host    |    9894    |      |         |              |
   +-----------+------------+------+---------+--------------+
   ```



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