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/10 06:50:35 UTC
[GitHub] [ozone] Tejaskriya opened a new pull request, #5038: HDDS-6668. scm roles CLI should provide JSON output option
Tejaskriya opened a new pull request, #5038:
URL: https://github.com/apache/ozone/pull/5038
## What changes were proposed in this pull request?
Add the option for the command `ozone admin scm roles` to output as JSON
## What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-6668
## How was this patch tested?
New robot test. Also verified the JSON out using a docker-compose cluster:
```
bash-4.2$ ozone admin scm roles --json
{
"scm2" : {
"address" : "9894",
"raftPeerRole" : "FOLLOWER",
"ID" : "55acae44-2881-48ef-ab47-0a3301e260c5",
"InetAddress" : "172.19.0.6"
},
"scm1" : {
"address" : "9894",
"raftPeerRole" : "LEADER",
"ID" : "4f307fcc-e256-4bbd-83e4-6786968d1936",
"InetAddress" : "172.19.0.5"
},
"scm3" : {
"address" : "9894",
"raftPeerRole" : "FOLLOWER",
"ID" : "4bd6dfb4-d3fc-4a3b-8e65-99ffca3c8096",
"InetAddress" : "172.19.0.3"
}
}
```
--
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
[GitHub] [ozone] adoroszlai merged pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai merged PR #5038:
URL: https://github.com/apache/ozone/pull/5038
--
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
[GitHub] [ozone] sadanand48 commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1260039801
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +45,45 @@ 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);
+ }
+ }
+ }
+
+ private 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(":");
+ 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) {
Review Comment:
although this would work for now, I feel a better way to solve this is by creating an Object that would capture these variables and then print it right away as a json.
Adding a new API like List<SCMRole> getScmRatisRoles() and directly print the object. I see OM is using a similar way using OMRoleInfo.
--
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
[GitHub] [ozone] ashishkumar50 commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "ashishkumar50 (via GitHub)" <gi...@apache.org>.
ashishkumar50 commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1257855274
##########
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:
Please check the size before accessing roles[1],roles[2],roles[3],roles[4].
##########
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(":");
Review Comment:
We need to consider [No Ratis](https://github.com/apache/ozone/blob/4f19af2e126d7454cfc5ba59c8e7cd7608d14084/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/SCMClientProtocolServer.java#L778) case as well or else it will fail to parse.
--
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
[GitHub] [ozone] Tejaskriya commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "Tejaskriya (via GitHub)" <gi...@apache.org>.
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
[GitHub] [ozone] ashishkumar50 commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "ashishkumar50 (via GitHub)" <gi...@apache.org>.
ashishkumar50 commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1259265584
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +45,45 @@ 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(
Review Comment:
Change method to private.
--
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
[GitHub] [ozone] adoroszlai commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1259788519
##########
hadoop-ozone/dist/src/main/smoketest/admincli/scmrole.robot:
##########
@@ -25,4 +25,8 @@ Test Timeout 5 minutes
*** Test Cases ***
Run scm roles
${output} = Execute ozone admin scm roles
- Should Match Regexp ${output} [scm:9894(:LEADER|)]
\ No newline at end of file
+ Should Match Regexp ${output} [scm:9894(:LEADER|)]
+
+List scm roles as JSON
+ ${output} = Execute ozone admin scm roles --json
+ Should contain ${output} "address" :
Review Comment:
We can check that output is valid JSON by passing through `jq`, e.g. find LEADER:
```suggestion
Execute echo '${output}' | jq -r '.[] | select(.raftPeerRole == "LEADER")'
```
--
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
[GitHub] [ozone] sadanand48 commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1262317551
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +45,45 @@ 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);
+ }
+ }
+ }
+
+ private 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(":");
+ 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) {
Review Comment:
> I think instead of creating new Map by parsing getScmRatisRoles() , we can use existing API and then use JsonUtils to print it.
`SCMNodeInfo.buildNodeInfo(new OzoneConfiguration())` constructs the result based on client config and does not have the correct ratis role details, There is no API like this that queries the SCM and returns such an Object currently. The existing API returns a String and if we need to change it/add another API , it would require a change in the proto structure too, I think we could solve it in another jira by refactoring the current API if really needed.
--
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
[GitHub] [ozone] sadanand48 commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "sadanand48 (via GitHub)" <gi...@apache.org>.
sadanand48 commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1260042276
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +45,45 @@ 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);
+ }
+ }
+ }
+
+ private 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(":");
+ 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) {
Review Comment:
I guess we could also solve this without modifying the current API a lot, Only on the server side introduce this API that returns an Object , json Stringify the object and return it to this current API.
--
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
[GitHub] [ozone] nilotpalnandi commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "nilotpalnandi (via GitHub)" <gi...@apache.org>.
nilotpalnandi commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1260917894
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +45,45 @@ 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);
+ }
+ }
+ }
+
+ private 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(":");
+ 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) {
Review Comment:
I think instead of creating new Map by parsing getScmRatisRoles() , we can use existing API and then use JsonUtils to print it. Something like -
```
List<SCMNodeInfo> scmNodeInfos = SCMNodeInfo.buildNodeInfo(new OzoneConfiguration());
System.out.print(JsonUtils.toJsonStringWithDefaultPrettyPrinter(scmNodeInfos));
```
--
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
[GitHub] [ozone] adoroszlai commented on pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "adoroszlai (via GitHub)" <gi...@apache.org>.
adoroszlai commented on PR #5038:
URL: https://github.com/apache/ozone/pull/5038#issuecomment-1634971660
Thanks @Tejaskriya for the patch, @ashishkumar50, @nilotpalnandi, @sadanand48 for the review.
--
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
[GitHub] [ozone] Tejaskriya commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "Tejaskriya (via GitHub)" <gi...@apache.org>.
Tejaskriya commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1262021632
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/admin/scm/GetScmRatisRolesSubcommand.java:
##########
@@ -38,11 +45,45 @@ 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);
+ }
+ }
+ }
+
+ private 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(":");
+ 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) {
Review Comment:
Creating a change on the server side either by stringifying a json object and storing it in peerRoles, or returning an object itself breaks the usage of this method in other places and many tests as well. Currently, everywhere that peerRoles are handled, it has been done by string operations itself. We can defer from making this change right now.
--
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
[GitHub] [ozone] Tejaskriya commented on a diff in pull request #5038: HDDS-6668. scm roles CLI should provide JSON output option
Posted by "Tejaskriya (via GitHub)" <gi...@apache.org>.
Tejaskriya commented on code in PR #5038:
URL: https://github.com/apache/ozone/pull/5038#discussion_r1262210915
##########
hadoop-ozone/dist/src/main/smoketest/admincli/scmrole.robot:
##########
@@ -25,4 +25,8 @@ Test Timeout 5 minutes
*** Test Cases ***
Run scm roles
${output} = Execute ozone admin scm roles
- Should Match Regexp ${output} [scm:9894(:LEADER|)]
\ No newline at end of file
+ Should Match Regexp ${output} [scm:9894(:LEADER|)]
+
+List scm roles as JSON
+ ${output} = Execute ozone admin scm roles --json
+ Should contain ${output} "address" :
Review Comment:
Thank you, I've incorporated your suggestion in my latest commit
--
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