You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ratis.apache.org by GitBox <gi...@apache.org> on 2022/02/24 11:07:05 UTC

[GitHub] [ratis] codings-dan commented on a change in pull request #605: RATIS-1527. Add a ratis server demo for debug

codings-dan commented on a change in pull request #605:
URL: https://github.com/apache/ratis/pull/605#discussion_r813775789



##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/common/Common.java
##########
@@ -16,35 +16,55 @@
  * limitations under the License.
  */
 
-package org.apache.ratis.examples.counter;
+package org.apache.ratis.examples.common;
 
 import org.apache.ratis.protocol.RaftGroup;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftPeer;
 
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 import java.util.UUID;
 
 /**
  * Common Constant across servers and client
  */
-public final class CounterCommon {
+public final class Common {
   public static final List<RaftPeer> PEERS;
 
   static {
     List<RaftPeer> peers = new ArrayList<>(3);
-    peers.add(RaftPeer.newBuilder().setId("n1").setAddress("127.0.0.1:6000").build());
-    peers.add(RaftPeer.newBuilder().setId("n2").setAddress("127.0.0.1:6001").build());
-    peers.add(RaftPeer.newBuilder().setId("n3").setAddress("127.0.0.1:6002").build());
+    Properties properties = new Properties();
+
+    try(InputStream inputStream = new FileInputStream("ratis-examples/src/main/resources/conf.properties");
+        Reader reader = new InputStreamReader(inputStream, "UTF-8");
+        BufferedReader bufferedReader = new BufferedReader(reader)) {
+      properties.load(bufferedReader);
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    String[] address = properties.getProperty("raft.server.address").split(",");
+    if (address.length <= 0) {
+      throw new IllegalArgumentException("Can't get the ratis server address");
+    }
+    for (int i = 0; i < address.length; i++) {
+      peers.add(RaftPeer.newBuilder().setId("n" + i).setAddress(address[i]).build());
+    }

Review comment:
       done

##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/common/Common.java
##########
@@ -16,35 +16,55 @@
  * limitations under the License.
  */
 
-package org.apache.ratis.examples.counter;
+package org.apache.ratis.examples.common;
 
 import org.apache.ratis.protocol.RaftGroup;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftPeer;
 
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 import java.util.UUID;
 
 /**
  * Common Constant across servers and client
  */
-public final class CounterCommon {
+public final class Common {

Review comment:
       done




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

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