You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Tejaskriya (via GitHub)" <gi...@apache.org> on 2023/07/11 05:59:57 UTC

[GitHub] [ozone] Tejaskriya commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option

Tejaskriya commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1259224560


##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +42,37 @@ public class GetScmRatisRolesSubcommand extends ScmSubcommand {
   @CommandLine.ParentCommand
   private ScmAdmin parent;
 
+  @CommandLine.Option(names = { "--json" },
+      defaultValue = "false",
+      description = "Format output as JSON")
+  private boolean json;
+
   @Override
   protected void execute(ScmClient scmClient) throws IOException {
-    List<String> roles = scmClient.getScmRatisRoles();
-    for (String role: roles) {
-      System.out.println(role);
+    List<String> ratisRoles = scmClient.getScmRatisRoles();
+    if (json) {
+      Map<String, Map<String, String>> scmRoles = parseScmRoles(ratisRoles);
+      System.out.print(
+      JsonUtils.toJsonStringWithDefaultPrettyPrinter(scmRoles));
+    } else {
+      for (String role: ratisRoles) {
+        System.out.println(role);
+      }
+    }
+  }
+
+  protected Map<String, Map<String, String>> parseScmRoles(
+      List<String> ratisRoles) {
+    Map<String, Map<String, String>> allRoles = new HashMap<>();
+    for (String role : ratisRoles) {
+      Map<String, String> roleDetails = new HashMap<>();
+      String[] roles = role.split(":");
+      roleDetails.put("address",roles[1]);
+      roleDetails.put("raftPeerRole",roles[2]);
+      roleDetails.put("ID",roles[3]);
+      roleDetails.put("InetAddress",roles[4]);

Review Comment:
   I have fixed this in my latest commit. Thank you.



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org