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/18 13:43:34 UTC

[GitHub] [ratis] codings-dan opened a new pull request #605: RATIS-1527. Add a ratis server demo for debug in Intellij

codings-dan opened a new pull request #605:
URL: https://github.com/apache/ratis/pull/605


   ## What changes were proposed in this pull request?
   
   With this example, we can easily run three ratis server in Intellij, and debug it.
   
   ## What is the link to the Apache JIRA
   https://issues.apache.org/jira/browse/RATIS-1527
   
   ## How was this patch tested?
   No need
   


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan edited a comment on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1047777075


   @szetszwo With this demo, We can run `dev-support/intellij/install-runconfig.sh`, then, in the `.idea/runConfigurations`, there will be 3 xml files related to ratis server generated, And we can select the server application and run it. See below.
   ![image](https://user-images.githubusercontent.com/26144703/155138157-07fe3426-b7a6-4604-8c3f-1a1098accd46.png)
   
   Then, We can set breakpoints and debug it. BTW, If this demo is valuable, I will add corresponding docs to it later


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



[GitHub] [ratis] szetszwo merged pull request #605: RATIS-1527. Add a ratis server demo for debug

Posted by GitBox <gi...@apache.org>.
szetszwo merged pull request #605:
URL: https://github.com/apache/ratis/pull/605


   


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



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

Posted by GitBox <gi...@apache.org>.
szetszwo commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1047766020


   @codings-dan , sure.  Could you give some instructions for running the demo?


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1049752421


   @szetszwo PTAL, thx!


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan edited a comment on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1047777075


   @szetszwo With this demo, We can run `dev-support/intellij/install-runconfig.sh`, then, in the `.idea/runConfigurations`, there will be 3 xml files related to ratis server generated, And we can select the server application and run it. See below.
   ![image](https://user-images.githubusercontent.com/26144703/155138157-07fe3426-b7a6-4604-8c3f-1a1098accd46.png)
   
   Then, We can set breakpoints and debug it


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan closed pull request #605:
URL: https://github.com/apache/ratis/pull/605


   


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1047687370


   @szetszwo Can you help take a look at this MR, this demo can easily start 3 ratis server applications in Intellij IDEA and debug them.


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1048696739


   @szetszwo I remove intelliJ change related code, PTAL, thx!


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



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

Posted by GitBox <gi...@apache.org>.
szetszwo commented on a change in pull request #605:
URL: https://github.com/apache/ratis/pull/605#discussion_r813062137



##########
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:
       Let's call it `Constants`.

##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/common/StateMachine.java
##########
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ratis.examples.counter.server;
+package org.apache.ratis.examples.common;

Review comment:
       Let's don't change CounterStateMachine at all since this state machine is specific to the counter example.
   
   Later, we may let the user choose other state machines.

##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/debug/server/Server.java
##########
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ratis.examples.debug.server;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.examples.common.StateMachine;
+import org.apache.ratis.examples.common.Common;
+import org.apache.ratis.grpc.GrpcConfigKeys;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.RaftServerConfigKeys;
+import org.apache.ratis.util.NetUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * Simplest Ratis server, use a simple state machine {@link StateMachine}
+ * which maintain a counter across multi server.
+ *
+ * Run this application three times with three different parameter set-up a
+ * ratis cluster which maintain a counter value replicated in each server memory
+ */
+public final class Server {
+
+  private Server(){
+  }
+
+  public static void main(String[] args) throws IOException {
+    if (args.length < 1) {
+      System.err.println("Ratis sever address should be provided in the style <ip:port>");
+      System.exit(1);
+    }
+
+    //find current peer object based on application parameter
+    RaftPeer currentPeer =
+        Common.PEERS.stream()
+            .filter(raftPeer -> raftPeer.getAddress().equals(args[0]))
+            .findFirst().get();
+
+    //create a property object
+    RaftProperties properties = new RaftProperties();
+
+    //set the storage directory (different for each peer) in RaftProperty object
+    File raftStorageDir = new File("./" + currentPeer.getId().toString());
+    RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(raftStorageDir));
+
+    //set the port which server listen to in RaftProperty object
+    final int port = NetUtils.createSocketAddr(currentPeer.getAddress()).getPort();
+    GrpcConfigKeys.Server.setPort(properties, port);
+
+    //create the counter state machine which hold the counter value
+    StateMachine stateMachine = new StateMachine();
+
+    //create and start the Raft server
+    RaftServer server = RaftServer.newBuilder()
+        .setGroup(Common.RAFT_GROUP)
+        .setProperties(properties)
+        .setServerId(currentPeer.getId())
+        .setStateMachine(stateMachine)
+        .build();
+    server.start();

Review comment:
       Let's refactor the CounterServer so that we can reuse the code.

##########
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:
       - Let's print out the conf file and the key in the error messages.
   - Use Optional to handle null.
   ```
     static {
       final Properties properties = new Properties();
       final String conf = "ratis-examples/src/main/resources/conf.properties";
       try(InputStream inputStream = new FileInputStream(conf);
           Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
           BufferedReader bufferedReader = new BufferedReader(reader)) {
         properties.load(bufferedReader);
       } catch (IOException e) {
         throw new IllegalStateException("Failed to load " + conf, e);
       }
       final String key = "raft.server.address.list";
       final String[] addresses = Optional.ofNullable(properties.getProperty(key))
           .map(s -> s.split(","))
           .orElse(null);
       if (addresses == null || addresses.length == 0) {
         throw new IllegalArgumentException("Failed to get " + key + " from " + conf);
       }
   
       final List<RaftPeer> peers = new ArrayList<>(addresses.length);
       for (int i = 0; i < addresses.length; i++) {
         peers.add(RaftPeer.newBuilder().setId("n" + i).setAddress(addresses[i]).build());
       }
       PEERS = Collections.unmodifiableList(peers);
     }
   ```
   

##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/debug/server/Server.java
##########
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ratis.examples.debug.server;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.examples.common.StateMachine;
+import org.apache.ratis.examples.common.Common;
+import org.apache.ratis.grpc.GrpcConfigKeys;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.RaftServerConfigKeys;
+import org.apache.ratis.util.NetUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * Simplest Ratis server, use a simple state machine {@link StateMachine}
+ * which maintain a counter across multi server.
+ *
+ * Run this application three times with three different parameter set-up a
+ * ratis cluster which maintain a counter value replicated in each server memory
+ */
+public final class Server {
+
+  private Server(){
+  }
+
+  public static void main(String[] args) throws IOException {
+    if (args.length < 1) {
+      System.err.println("Ratis sever address should be provided in the style <ip:port>");
+      System.exit(1);
+    }
+
+    //find current peer object based on application parameter
+    RaftPeer currentPeer =
+        Common.PEERS.stream()
+            .filter(raftPeer -> raftPeer.getAddress().equals(args[0]))
+            .findFirst().get();
+
+    //create a property object
+    RaftProperties properties = new RaftProperties();
+
+    //set the storage directory (different for each peer) in RaftProperty object
+    File raftStorageDir = new File("./" + currentPeer.getId().toString());

Review comment:
       It should use a directory inside ./ratis-examples/target .  How about we pass the root path in args?




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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #605:
URL: https://github.com/apache/ratis/pull/605#discussion_r813776521



##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/common/StateMachine.java
##########
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ratis.examples.counter.server;
+package org.apache.ratis.examples.common;

Review comment:
       Done, We may develop a state machine to the debug server as well.




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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1047777075


   @szetszwo With this demo, We can run `dev-support/intellij/install-runconfig.sh`, then, in the `.idea/runConfigurations`, there will be 3 xml files related to ratis server generated, And we can select the server application and run it. See below.
   ![image](https://user-images.githubusercontent.com/26144703/155138157-07fe3426-b7a6-4604-8c3f-1a1098accd46.png)
   


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #605:
URL: https://github.com/apache/ratis/pull/605#discussion_r813778258



##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/debug/server/Server.java
##########
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ratis.examples.debug.server;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.examples.common.StateMachine;
+import org.apache.ratis.examples.common.Common;
+import org.apache.ratis.grpc.GrpcConfigKeys;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.RaftServerConfigKeys;
+import org.apache.ratis.util.NetUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * Simplest Ratis server, use a simple state machine {@link StateMachine}
+ * which maintain a counter across multi server.
+ *
+ * Run this application three times with three different parameter set-up a
+ * ratis cluster which maintain a counter value replicated in each server memory
+ */
+public final class Server {
+
+  private Server(){
+  }
+
+  public static void main(String[] args) throws IOException {
+    if (args.length < 1) {
+      System.err.println("Ratis sever address should be provided in the style <ip:port>");
+      System.exit(1);
+    }
+
+    //find current peer object based on application parameter
+    RaftPeer currentPeer =
+        Common.PEERS.stream()
+            .filter(raftPeer -> raftPeer.getAddress().equals(args[0]))
+            .findFirst().get();
+
+    //create a property object
+    RaftProperties properties = new RaftProperties();
+
+    //set the storage directory (different for each peer) in RaftProperty object
+    File raftStorageDir = new File("./" + currentPeer.getId().toString());
+    RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(raftStorageDir));
+
+    //set the port which server listen to in RaftProperty object
+    final int port = NetUtils.createSocketAddr(currentPeer.getAddress()).getPort();
+    GrpcConfigKeys.Server.setPort(properties, port);
+
+    //create the counter state machine which hold the counter value
+    StateMachine stateMachine = new StateMachine();
+
+    //create and start the Raft server
+    RaftServer server = RaftServer.newBuilder()
+        .setGroup(Common.RAFT_GROUP)
+        .setProperties(properties)
+        .setServerId(currentPeer.getId())
+        .setStateMachine(stateMachine)
+        .build();
+    server.start();

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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #605:
URL: https://github.com/apache/ratis/pull/605#discussion_r813778112



##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/debug/server/Server.java
##########
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ratis.examples.debug.server;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.examples.common.StateMachine;
+import org.apache.ratis.examples.common.Common;
+import org.apache.ratis.grpc.GrpcConfigKeys;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.RaftServerConfigKeys;
+import org.apache.ratis.util.NetUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * Simplest Ratis server, use a simple state machine {@link StateMachine}
+ * which maintain a counter across multi server.
+ *
+ * Run this application three times with three different parameter set-up a
+ * ratis cluster which maintain a counter value replicated in each server memory
+ */
+public final class Server {
+
+  private Server(){
+  }
+
+  public static void main(String[] args) throws IOException {
+    if (args.length < 1) {
+      System.err.println("Ratis sever address should be provided in the style <ip:port>");
+      System.exit(1);
+    }
+
+    //find current peer object based on application parameter
+    RaftPeer currentPeer =
+        Common.PEERS.stream()
+            .filter(raftPeer -> raftPeer.getAddress().equals(args[0]))
+            .findFirst().get();
+
+    //create a property object
+    RaftProperties properties = new RaftProperties();
+
+    //set the storage directory (different for each peer) in RaftProperty object
+    File raftStorageDir = new File("./" + currentPeer.getId().toString());

Review comment:
       I suggest adding a `raft.server.root.storage.path` configuration item to the `conf.properties` file, and the default path can be `./ratis-examples/target`




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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1044555430


   I will reopen this MR after the code change is complete


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan removed a comment on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1044555430


   I will reopen this MR after the code change is complete


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



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

Posted by GitBox <gi...@apache.org>.
szetszwo commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1048455004


   @codings-dan , I see the your point now.  Let's split this into two JIRAs:
   - example change
   - intelliJ change
   
   Thanks.


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on pull request #605:
URL: https://github.com/apache/ratis/pull/605#issuecomment-1048505675


   will do


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



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

Posted by GitBox <gi...@apache.org>.
codings-dan commented on a change in pull request #605:
URL: https://github.com/apache/ratis/pull/605#discussion_r813778112



##########
File path: ratis-examples/src/main/java/org/apache/ratis/examples/debug/server/Server.java
##########
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ratis.examples.debug.server;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.examples.common.StateMachine;
+import org.apache.ratis.examples.common.Common;
+import org.apache.ratis.grpc.GrpcConfigKeys;
+import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.server.RaftServer;
+import org.apache.ratis.server.RaftServerConfigKeys;
+import org.apache.ratis.util.NetUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+
+/**
+ * Simplest Ratis server, use a simple state machine {@link StateMachine}
+ * which maintain a counter across multi server.
+ *
+ * Run this application three times with three different parameter set-up a
+ * ratis cluster which maintain a counter value replicated in each server memory
+ */
+public final class Server {
+
+  private Server(){
+  }
+
+  public static void main(String[] args) throws IOException {
+    if (args.length < 1) {
+      System.err.println("Ratis sever address should be provided in the style <ip:port>");
+      System.exit(1);
+    }
+
+    //find current peer object based on application parameter
+    RaftPeer currentPeer =
+        Common.PEERS.stream()
+            .filter(raftPeer -> raftPeer.getAddress().equals(args[0]))
+            .findFirst().get();
+
+    //create a property object
+    RaftProperties properties = new RaftProperties();
+
+    //set the storage directory (different for each peer) in RaftProperty object
+    File raftStorageDir = new File("./" + currentPeer.getId().toString());

Review comment:
       I suggest adding a `raft.server.root.storage.path` configuration item to the conf.properties file, and the default path can be `./ratis-examples/target`




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