szetszwo commented on code in PR #1060:
URL: https://github.com/apache/ratis/pull/1060#discussion_r1557862543
##########
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:
> `[P1_Id]|P1_HOST:P1_PORT,[P2_Id]|P2_HOST:P2_PORT`
It should be [P1_Id`|]`P1_HOST:P1_PORT,[P2_Id`|]`P2_HOST:P2_PORT. (The one
for P0 is correct.)
##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/local/RaftMetaConfCommand.java:
##########
@@ -69,11 +74,50 @@ public int run(CommandLine cl) throws IOException {
printf("peers or path can't be empty.");
return -1;
}
+ Set<String> addresses = new HashSet<>();
+ Set<String> ids = 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) {
+ String message =
+ "Failed to parse peer's Id and address for: %s, " +
+ "from option: -peers %s. \n" +
+ "Please make sure to provide list of peers" +
+ " in format
<P0_Id|P0_HOST:P0_PORT,P1_Id|P1_HOST:P1_PORT,P2_Id|P2_HOST:P2_PORT> or " +
Review Comment:
To be consistent, let's use upper case `ID`.
Also, we should update the format string in the `getUsage()` method.
##########
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:
This is not yet updated. BTW, why not using `addressString`?
--
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]