DaveTeng0 commented on code in PR #1098:
URL: https://github.com/apache/ratis/pull/1098#discussion_r1635359021


##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/RaftUtils.java:
##########
@@ -86,4 +103,111 @@ public static RaftClient createClient(RaftGroup raftGroup) 
{
         .setRetryPolicy(retryPolicy)
         .build();
   }
+
+
+  /**
+   * Execute a given function with input parameter from the members of a list.
+   *
+   * @param list the input parameters
+   * @param function the function to be executed
+   * @param <T> parameter type
+   * @param <K> return value type
+   * @param <E> the exception type thrown by the given function.
+   * @return the value returned by the given function.
+   */
+  public static <T, K, E extends Throwable> K runFunction(Collection<T> list, 
CheckedFunction<T, K, E> function) {
+    for (T t : list) {
+      try {
+        K ret = function.apply(t);
+        if (ret != null) {
+          return ret;
+        }
+      } catch (Throwable e) {
+        e.printStackTrace();
+      }
+    }
+    return null;
+  }
+
+
+  public static List<RaftPeer> buildRaftPeersFromStr(String peers) {
+    List<InetSocketAddress> addresses = new ArrayList<>();
+    String[] peersArray = peers.split(",");
+    for (String peer : peersArray) {
+      addresses.add(parseInetSocketAddress(peer));
+    }
+
+    return addresses.stream()
+        .map(addr -> RaftPeer.newBuilder()
+            .setId(RaftUtils.getPeerId(addr))
+            .setAddress(addr)
+            .build()
+        ).collect(Collectors.toList());
+  }
+
+  public static RaftGroupId buildRaftGroupIdFromStr(String groupId) {
+    return (groupId != null && !groupId.equals("")) ? 
RaftGroupId.valueOf(UUID.fromString(groupId))
+        : DEFAULT_RAFT_GROUP_ID;
+  }
+
+  public static RaftGroupId retrieveRemoteGroupId(RaftGroupId 
raftGroupIdFromConfig,
+                                                  List<RaftPeer> peers,
+                                                  RaftClient client, 
PrintStream printStream) throws IOException {
+    RaftGroupId remoteGroupId;
+    if (raftGroupIdFromConfig != DEFAULT_RAFT_GROUP_ID) {

Review Comment:
   Yeah sure!!



-- 
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-unsubscr...@ratis.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to