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: [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]