szetszwo commented on code in PR #1060:
URL: https://github.com/apache/ratis/pull/1060#discussion_r1552248180


##########
ratis-docs/src/site/markdown/cli.md:
##########
@@ -182,5 +182,5 @@ It has the following subcommands:
 ### local raftMetaConf
 Generate a new raft-meta.conf file based on original raft-meta.conf and new 
peers, which is used to move a raft node to a new node.
 ```
-$ ratis sh local raftMetaConf -peers 
<P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT> -path 
<PARENT_PATH_OF_RAFT_META_CONF>
+$ ratis sh local raftMetaConf -peers 
<P0_Id|P0_HOST:P0_PORT,P1_Id|P1_HOST:P1_PORT,P2_Id|P2_HOST:P2_PORT> -path 
<PARENT_PATH_OF_RAFT_META_CONF>

Review Comment:
   Let's add `[]` to indicate that id is option.
   ```
   [P0_Id|]P0_HOST:P0_PORT
   ```



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -69,11 +70,35 @@ public int run(CommandLine cl) throws IOException {
       printf("peers or path can't be empty.");
       return -1;
     }
+    Set<String> addresses = new HashSet<>();

Review Comment:
   Let's also check if the ids are duplicated.



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -69,11 +70,35 @@ public int run(CommandLine cl) throws IOException {
       printf("peers or path can't be empty.");
       return -1;
     }
+    Set<String> addresses = new HashSet<>();
     List<RaftPeerProto> raftPeerProtos = new ArrayList<>();
-    for (String address : peersStr.split(",")) {
-      String peerId = 
RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+    for (String idWithAddress : peersStr.split(",")) {
+      String[] peerIdWithAddressArray = idWithAddress.split(SEPARATOR);
+
+      if (peerIdWithAddressArray.length < 1 || peerIdWithAddressArray.length > 
2) {
+        printf("Please make sure to provide list of peers in format 
<P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT>, "
+          + "or 
<P0_Id|P0_HOST:P0_PORT,P1_Id|P1_HOST:P1_PORT,P2_Id|P2_HOST:P2_PORT>");
+        return -1;
+      }
+      String address = 
parseInetSocketAddress(peerIdWithAddressArray[peerIdWithAddressArray.length - 
1]).toString();
+      if (addresses.contains(address)) {
+        printf("Please make sure the addresses of peers have no duplicated 
value.");
+        return -1;
+      }
+      addresses.add(address);
+      
+      String peerId;
+      if (peerIdWithAddressArray.length == 2) {
+        // Peer ID is provided
+        peerId = 
RaftPeerId.getRaftPeerId(peerIdWithAddressArray[0]).toString();
+      } else {
+        // If peer ID is not provided, use host address as peerId value
+        peerId = 
RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+      }
+
       raftPeerProtos.add(RaftPeerProto.newBuilder()
-          
.setId(ByteString.copyFrom(peerId.getBytes(StandardCharsets.UTF_8))).setAddress(address)
+          .setId(ByteString.copyFrom(peerId.getBytes(StandardCharsets.UTF_8)))
+          
.setAddress(parseInetSocketAddress(peerIdWithAddressArray[1]).toString())

Review Comment:
   Use `address`.
   
   Should the test fail for `"host1:9872,host2:9872,host3:9872"`?



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -69,11 +70,35 @@ public int run(CommandLine cl) throws IOException {
       printf("peers or path can't be empty.");
       return -1;
     }
+    Set<String> addresses = new HashSet<>();
     List<RaftPeerProto> raftPeerProtos = new ArrayList<>();
-    for (String address : peersStr.split(",")) {
-      String peerId = 
RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+    for (String idWithAddress : peersStr.split(",")) {
+      String[] peerIdWithAddressArray = idWithAddress.split(SEPARATOR);
+
+      if (peerIdWithAddressArray.length < 1 || peerIdWithAddressArray.length > 
2) {
+        printf("Please make sure to provide list of peers in format 
<P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT>, "
+          + "or 
<P0_Id|P0_HOST:P0_PORT,P1_Id|P1_HOST:P1_PORT,P2_Id|P2_HOST:P2_PORT>");

Review Comment:
   Print also the values of `idWithAddress` and `peersStr`.



##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -69,11 +70,35 @@ public int run(CommandLine cl) throws IOException {
       printf("peers or path can't be empty.");
       return -1;
     }
+    Set<String> addresses = new HashSet<>();
     List<RaftPeerProto> raftPeerProtos = new ArrayList<>();
-    for (String address : peersStr.split(",")) {
-      String peerId = 
RaftUtils.getPeerId(parseInetSocketAddress(address)).toString();
+    for (String idWithAddress : peersStr.split(",")) {
+      String[] peerIdWithAddressArray = idWithAddress.split(SEPARATOR);
+
+      if (peerIdWithAddressArray.length < 1 || peerIdWithAddressArray.length > 
2) {
+        printf("Please make sure to provide list of peers in format 
<P0_HOST:P0_PORT,P1_HOST:P1_PORT,P2_HOST:P2_PORT>, "
+          + "or 
<P0_Id|P0_HOST:P0_PORT,P1_Id|P1_HOST:P1_PORT,P2_Id|P2_HOST:P2_PORT>");
+        return -1;
+      }
+      String address = 
parseInetSocketAddress(peerIdWithAddressArray[peerIdWithAddressArray.length - 
1]).toString();
+      if (addresses.contains(address)) {
+        printf("Please make sure the addresses of peers have no duplicated 
value.");

Review Comment:
   Print the value of `address`.



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