szetszwo commented on a change in pull request #564:
URL: https://github.com/apache/ratis/pull/564#discussion_r769537671



##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupListCommand.java
##########
@@ -51,15 +53,25 @@ public String getCommandName() {
   @Override
   public int run(CommandLine cl) throws IOException {
     super.run(cl);
-    String strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
-    final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
-    final RaftPeerId peerId = RaftUtils.getPeerId(serverAddress);
+    RaftPeerId peerId = null;
+    String strAddr = null;
+    if(cl.hasOption(SERVER_ADDRESS_OPTION_NAME)) {
+      strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
+      final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
+      peerId = RaftUtils.getPeerId(serverAddress);
+    } else if (cl.hasOption(PEER_ID_OPTION_NAME)) {

Review comment:
       Let's check PEER_ID_OPTION_NAME before SERVER_ADDRESS_OPTION_NAME.

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupListCommand.java
##########
@@ -51,15 +53,25 @@ public String getCommandName() {
   @Override
   public int run(CommandLine cl) throws IOException {
     super.run(cl);
-    String strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
-    final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
-    final RaftPeerId peerId = RaftUtils.getPeerId(serverAddress);
+    RaftPeerId peerId = null;
+    String strAddr = null;
+    if(cl.hasOption(SERVER_ADDRESS_OPTION_NAME)) {
+      strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
+      final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
+      peerId = RaftUtils.getPeerId(serverAddress);
+    } else if (cl.hasOption(PEER_ID_OPTION_NAME)) {
+      peerId = 
RaftPeerId.getRaftPeerId(cl.getOptionValue(PEER_ID_OPTION_NAME));
+      strAddr = getRaftGroup().getPeer(peerId).getAddress();
+    }

Review comment:
       Add an else-clause to throw IllegalArgumentException.

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupListCommand.java
##########
@@ -51,15 +53,25 @@ public String getCommandName() {
   @Override
   public int run(CommandLine cl) throws IOException {
     super.run(cl);
-    String strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
-    final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
-    final RaftPeerId peerId = RaftUtils.getPeerId(serverAddress);
+    RaftPeerId peerId = null;
+    String strAddr = null;

Review comment:
       Let's change both variables to final.

##########
File path: 
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupListCommand.java
##########
@@ -51,15 +53,25 @@ public String getCommandName() {
   @Override
   public int run(CommandLine cl) throws IOException {
     super.run(cl);
-    String strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
-    final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
-    final RaftPeerId peerId = RaftUtils.getPeerId(serverAddress);
+    RaftPeerId peerId = null;
+    String strAddr = null;
+    if(cl.hasOption(SERVER_ADDRESS_OPTION_NAME)) {
+      strAddr = cl.getOptionValue(SERVER_ADDRESS_OPTION_NAME);
+      final InetSocketAddress serverAddress = parseInetSocketAddress(strAddr);
+      peerId = RaftUtils.getPeerId(serverAddress);
+    } else if (cl.hasOption(PEER_ID_OPTION_NAME)) {
+      peerId = 
RaftPeerId.getRaftPeerId(cl.getOptionValue(PEER_ID_OPTION_NAME));
+      strAddr = getRaftGroup().getPeer(peerId).getAddress();
+    }
 
     try(final RaftClient raftClient = RaftUtils.createClient(getRaftGroup())) {
       GroupListReply reply = raftClient.getGroupManagementApi(peerId).list();
-      processReply(reply, () -> String.format("Failed to get group information 
of server %s", strAddr));
-      printf(String.format("The server %s is in %d groups, and the groupIds 
is: %s",
-              strAddr, reply.getGroupIds().size(), reply.getGroupIds()));
+      String finalStrAddr = strAddr;
+      RaftPeerId finalPeerId = peerId;
+      processReply(reply, () -> String.format("Failed to get group information 
of peerId %s (server %s)",
+              finalPeerId, finalStrAddr));

Review comment:
       Use strAddr and peerId directly.   Remove finalPeerId and finalStrAddr.




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


Reply via email to