This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new b57be79  RATIS-1486. Add take snapshot hadoop and netty related 
request and proto (#576)
b57be79 is described below

commit b57be797fe97c00abc0e3d7353d30e1b2961714d
Author: Yaolong Liu <[email protected]>
AuthorDate: Thu Jan 13 17:01:18 2022 +0800

    RATIS-1486. Add take snapshot hadoop and netty related request and proto 
(#576)
---
 .../client/CombinedClientProtocolClientSideTranslatorPB.java  |  7 +++++--
 .../client/CombinedClientProtocolServerSideTranslatorPB.java  | 11 +++++++++++
 .../org/apache/ratis/hadooprpc/client/HadoopClientRpc.java    |  2 ++
 ratis-hadoop/src/main/proto/HadoopCompatability.proto         |  1 +
 .../ratis/hadooprpc/TestSnapshotManagementWithHadoopRpc.java  | 11 ++++-------
 .../java/org/apache/ratis/netty/client/NettyClientRpc.java    |  5 +++++
 .../java/org/apache/ratis/netty/server/NettyRpcService.java   |  9 +++++++++
 ratis-proto/src/main/proto/Hadoop.proto                       |  3 +++
 ratis-proto/src/main/proto/Netty.proto                        |  1 +
 .../org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java |  9 +++------
 .../TestSnapshotManagementWithNetty.java}                     | 11 ++++-------
 11 files changed, 48 insertions(+), 22 deletions(-)

diff --git 
a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolClientSideTranslatorPB.java
 
b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolClientSideTranslatorPB.java
index 4f10d26..ac0f30d 100644
--- 
a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolClientSideTranslatorPB.java
+++ 
b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolClientSideTranslatorPB.java
@@ -100,8 +100,11 @@ public class CombinedClientProtocolClientSideTranslatorPB
 
   @Override
   public RaftClientReply snapshotManagement(SnapshotManagementRequest request) 
throws IOException {
-    //todo(codings-dan): add proto related to hadoop
-    return null;
+    return handleRequest(request,
+        ClientProtoUtils::toSnapshotManagementRequestProto,
+        ClientProtoUtils::toRaftClientReply,
+        ClientOps.snapshotManagement,
+        RaftProtos.RaftClientReplyProto::parseFrom);
   }
 
   @Override
diff --git 
a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolServerSideTranslatorPB.java
 
b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolServerSideTranslatorPB.java
index 5999507..47d85f8 100644
--- 
a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolServerSideTranslatorPB.java
+++ 
b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/CombinedClientProtocolServerSideTranslatorPB.java
@@ -40,6 +40,7 @@ import org.apache.ratis.proto.RaftProtos.GroupListReplyProto;
 import org.apache.ratis.proto.RaftProtos.GroupInfoRequestProto;
 import org.apache.ratis.proto.RaftProtos.GroupInfoReplyProto;
 import org.apache.ratis.proto.RaftProtos.TransferLeadershipRequestProto;
+import org.apache.ratis.proto.RaftProtos.SnapshotManagementRequestProto;
 import org.apache.ratis.thirdparty.com.google.protobuf.GeneratedMessageV3;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,6 +82,9 @@ public class CombinedClientProtocolServerSideTranslatorPB
       case transferLeadership:
         response = 
transferLeadership(TransferLeadershipRequestProto.parseFrom(buf));
         break;
+      case snapshotManagement:
+        response = 
snapshotManagement(SnapshotManagementRequestProto.parseFrom(buf));
+        break;
       default:
         String message = "Internal error, all response types are not being 
handled as expected. " +
                          "Developer: check that all response types have 
appropriate handlers.";
@@ -137,4 +141,11 @@ public class CombinedClientProtocolServerSideTranslatorPB
     final RaftClientReply reply = impl.transferLeadership(request);
     return ClientProtoUtils.toRaftClientReplyProto(reply);
   }
+
+  public RaftClientReplyProto 
snapshotManagement(SnapshotManagementRequestProto proto)
+      throws IOException {
+    final SnapshotManagementRequest request = 
ClientProtoUtils.toSnapshotManagementRequest(proto);
+    final RaftClientReply reply = impl.snapshotManagement(request);
+    return ClientProtoUtils.toRaftClientReplyProto(reply);
+  }
 }
diff --git 
a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/HadoopClientRpc.java
 
b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/HadoopClientRpc.java
index e7c4442..36a5adc 100644
--- 
a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/HadoopClientRpc.java
+++ 
b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/client/HadoopClientRpc.java
@@ -54,6 +54,8 @@ public class HadoopClientRpc extends 
RaftClientRpcWithProxy<CombinedClientProtoc
         return proxy.getGroupInfo((GroupInfoRequest) request);
       } else if (request instanceof TransferLeadershipRequest) {
         return proxy.transferLeadership((TransferLeadershipRequest) request);
+      } else if (request instanceof SnapshotManagementRequest) {
+        return proxy.snapshotManagement((SnapshotManagementRequest) request);
       } else {
         return proxy.submitClientRequest(request);
       }
diff --git a/ratis-hadoop/src/main/proto/HadoopCompatability.proto 
b/ratis-hadoop/src/main/proto/HadoopCompatability.proto
index 1b67755..f17fa2b 100644
--- a/ratis-hadoop/src/main/proto/HadoopCompatability.proto
+++ b/ratis-hadoop/src/main/proto/HadoopCompatability.proto
@@ -54,6 +54,7 @@ enum ClientOps {
     groupList = 4;
     groupInfo = 5;
     transferLeadership = 6;
+    snapshotManagement = 7;
 }
 
 message ClientRequestProto {
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
 
b/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/TestSnapshotManagementWithHadoopRpc.java
similarity index 74%
copy from 
ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
copy to 
ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/TestSnapshotManagementWithHadoopRpc.java
index a1a7346..7f1b85d 100644
--- 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
+++ 
b/ratis-hadoop/src/test/java/org/apache/ratis/hadooprpc/TestSnapshotManagementWithHadoopRpc.java
@@ -15,14 +15,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.ratis.grpc;
+package org.apache.ratis.hadooprpc;
 
-import org.apache.ratis.server.impl.MiniRaftCluster;
 import org.apache.ratis.statemachine.SnapshotManagementTest;
 
-public class TestSnapshotManagementWithGrpc extends SnapshotManagementTest {
-  @Override
-  public MiniRaftCluster.Factory<? extends MiniRaftCluster> getFactory() {
-    return MiniRaftClusterWithGrpc.FACTORY;
-  }
+public class TestSnapshotManagementWithHadoopRpc
+    extends SnapshotManagementTest<MiniRaftClusterWithHadoopRpc>
+    implements MiniRaftClusterWithHadoopRpc.Factory.Get {
 }
\ No newline at end of file
diff --git 
a/ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientRpc.java 
b/ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientRpc.java
index 12ef0c1..7ac04a2 100644
--- 
a/ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientRpc.java
+++ 
b/ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientRpc.java
@@ -68,6 +68,11 @@ public class NettyClientRpc extends 
RaftClientRpcWithProxy<NettyRpcProxy> {
           (TransferLeadershipRequest)request);
       b.setTransferLeadershipRequest(proto);
       rpcRequest = proto.getRpcRequest();
+    } else if (request instanceof SnapshotManagementRequest) {
+      final RaftProtos.SnapshotManagementRequestProto proto = 
ClientProtoUtils.toSnapshotManagementRequestProto(
+          (SnapshotManagementRequest) request);
+      b.setSnapshotManagementRequest(proto);
+      rpcRequest = proto.getRpcRequest();
     } else {
       final RaftClientRequestProto proto = 
ClientProtoUtils.toRaftClientRequestProto(request);
       b.setRaftClientRequest(proto);
diff --git 
a/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java 
b/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java
index 50279d6..b80649f 100644
--- 
a/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java
+++ 
b/ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyRpcService.java
@@ -191,6 +191,15 @@ public final class NettyRpcService extends 
RaftServerRpcWithProxy<NettyRpcProxy,
               server.startLeaderElection(startLeaderElectionRequest);
           return 
RaftNettyServerReplyProto.newBuilder().setStartLeaderElectionReply(startLeaderElectionReply).build();
 
+        case SNAPSHOTMANAGEMENTREQUEST:
+          final SnapshotManagementRequestProto snapshotManagementRequest = 
proto.getSnapshotManagementRequest();
+          rpcRequest = snapshotManagementRequest.getRpcRequest();
+          final RaftClientReply snapshotManagementReply = 
server.snapshotManagement(
+              
ClientProtoUtils.toSnapshotManagementRequest(snapshotManagementRequest));
+          return RaftNettyServerReplyProto.newBuilder()
+              
.setRaftClientReply(ClientProtoUtils.toRaftClientReplyProto(snapshotManagementReply))
+              .build();
+
         case APPENDENTRIESREQUEST:
           final AppendEntriesRequestProto appendEntriesRequest = 
proto.getAppendEntriesRequest();
           rpcRequest = appendEntriesRequest.getServerRequest();
diff --git a/ratis-proto/src/main/proto/Hadoop.proto 
b/ratis-proto/src/main/proto/Hadoop.proto
index a9a2b12..439b17c 100644
--- a/ratis-proto/src/main/proto/Hadoop.proto
+++ b/ratis-proto/src/main/proto/Hadoop.proto
@@ -42,6 +42,9 @@ service CombinedClientProtocolService {
 
   rpc transferLeadership(ratis.common.TransferLeadershipRequestProto)
       returns(ratis.common.RaftClientReplyProto);
+
+  rpc snapshotManagement(ratis.common.SnapshotManagementRequestProto)
+      returns(ratis.common.RaftClientReplyProto);
 }
 
 service RaftServerProtocolService {
diff --git a/ratis-proto/src/main/proto/Netty.proto 
b/ratis-proto/src/main/proto/Netty.proto
index cea3ada..ec8a0fc 100644
--- a/ratis-proto/src/main/proto/Netty.proto
+++ b/ratis-proto/src/main/proto/Netty.proto
@@ -40,6 +40,7 @@ message RaftNettyServerRequestProto {
     ratis.common.GroupInfoRequestProto groupInfoRequest = 8;
     ratis.common.TransferLeadershipRequestProto transferLeadershipRequest = 9;
     ratis.common.StartLeaderElectionRequestProto startLeaderElectionRequest = 
10;
+    ratis.common.SnapshotManagementRequestProto snapshotManagementRequest = 11;
   }
 }
 
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
 
b/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
index a1a7346..62c8f3b 100644
--- 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
+++ 
b/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
@@ -17,12 +17,9 @@
  */
 package org.apache.ratis.grpc;
 
-import org.apache.ratis.server.impl.MiniRaftCluster;
 import org.apache.ratis.statemachine.SnapshotManagementTest;
 
-public class TestSnapshotManagementWithGrpc extends SnapshotManagementTest {
-  @Override
-  public MiniRaftCluster.Factory<? extends MiniRaftCluster> getFactory() {
-    return MiniRaftClusterWithGrpc.FACTORY;
-  }
+public class TestSnapshotManagementWithGrpc
+    extends SnapshotManagementTest<MiniRaftClusterWithGrpc>
+    implements MiniRaftClusterWithGrpc.FactoryGet {
 }
\ No newline at end of file
diff --git 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
 
b/ratis-test/src/test/java/org/apache/ratis/netty/TestSnapshotManagementWithNetty.java
similarity index 74%
copy from 
ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
copy to 
ratis-test/src/test/java/org/apache/ratis/netty/TestSnapshotManagementWithNetty.java
index a1a7346..44b98f6 100644
--- 
a/ratis-test/src/test/java/org/apache/ratis/grpc/TestSnapshotManagementWithGrpc.java
+++ 
b/ratis-test/src/test/java/org/apache/ratis/netty/TestSnapshotManagementWithNetty.java
@@ -15,14 +15,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.ratis.grpc;
+package org.apache.ratis.netty;
 
-import org.apache.ratis.server.impl.MiniRaftCluster;
 import org.apache.ratis.statemachine.SnapshotManagementTest;
 
-public class TestSnapshotManagementWithGrpc extends SnapshotManagementTest {
-  @Override
-  public MiniRaftCluster.Factory<? extends MiniRaftCluster> getFactory() {
-    return MiniRaftClusterWithGrpc.FACTORY;
-  }
+public class TestSnapshotManagementWithNetty
+    extends SnapshotManagementTest<MiniRaftClusterWithNetty>
+    implements MiniRaftClusterWithNetty.FactoryGet {
 }
\ No newline at end of file

Reply via email to