You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by lj...@apache.org on 2020/04/06 13:11:16 UTC

[incubator-ratis] branch master updated: RATIS-774. Fix checkstyle violations in ratis-hadoop. Contributed by Dinesh Chitlangia.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0756da1  RATIS-774. Fix checkstyle violations in ratis-hadoop. Contributed by Dinesh Chitlangia.
0756da1 is described below

commit 0756da1a3e7c9a334f1e4c2f302e288712d0e186
Author: Lokesh Jain <lj...@apache.org>
AuthorDate: Mon Apr 6 18:40:56 2020 +0530

    RATIS-774. Fix checkstyle violations in ratis-hadoop. Contributed by Dinesh Chitlangia.
---
 .../apache/hadoop/ipc/ProtobufRpcEngineShaded.java | 60 +++++++++++-----------
 .../apache/ratis/hadooprpc/HadoopConstants.java    | 17 +++---
 ...mbinedClientProtocolServerSideTranslatorPB.java |  1 -
 .../ratis/hadooprpc/server/HadoopRpcService.java   |  5 +-
 4 files changed, 40 insertions(+), 43 deletions(-)

diff --git a/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java b/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java
index 9223562..c3a7a8a 100644
--- a/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java
+++ b/ratis-hadoop/src/main/java/org/apache/hadoop/ipc/ProtobufRpcEngineShaded.java
@@ -107,7 +107,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
                 factory)), false);
   }
 
-  private static class Invoker implements RpcInvocationHandler {
+  private static final class Invoker implements RpcInvocationHandler {
     private final Map<String, Message> returnTypes =
         new ConcurrentHashMap<String, Message>();
     private boolean isClosed = false;
@@ -117,6 +117,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
     private final String protocolName;
     private AtomicBoolean fallbackToSimpleAuth;
 
+    @SuppressWarnings("checkstyle:parameternumber")
     private Invoker(Class<?> protocol, InetSocketAddress addr,
         UserGroupInformation ticket, Configuration conf, SocketFactory factory,
         int rpcTimeout, RetryPolicy connectionRetryPolicy,
@@ -287,16 +288,15 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
    * Protobuf. Several methods on {@link org.apache.hadoop.ipc.Server and RPC}
    * use type Writable as a wrapper to work across multiple RpcEngine kinds.
    */
-  private static abstract class RpcMessageWithHeader<T extends GeneratedMessage>
-    implements RpcWrapper {
-    T requestHeader;
-    Message theRequest; // for clientSide, the request is here
-    byte[] theRequestRead; // for server side, the request is here
+  private abstract static class RpcMessageWithHeader<T extends GeneratedMessage> implements RpcWrapper {
+    private T requestHeader;
+    private Message theRequest; // for clientSide, the request is here
+    private byte[] theRequestRead; // for server side, the request is here
 
-    public RpcMessageWithHeader() {
+    RpcMessageWithHeader() {
     }
 
-    public RpcMessageWithHeader(T requestHeader, Message theRequest) {
+    RpcMessageWithHeader(T requestHeader, Message theRequest) {
       this.requestHeader = requestHeader;
       this.theRequest = theRequest;
     }
@@ -311,8 +311,8 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
 
     @Override
     public void readFields(DataInput in) throws IOException {
-      requestHeader = parseHeaderFrom(readVarintBytes(in));
-      theRequestRead = readMessageRequest(in);
+      this.requestHeader = parseHeaderFrom(readVarintBytes(in));
+      this.theRequestRead = readMessageRequest(in);
     }
 
     abstract T parseHeaderFrom(byte[] bytes) throws IOException;
@@ -328,12 +328,12 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
       return bytes;
     }
 
-    public T getMessageHeader() {
-      return requestHeader;
+    T getMessageHeader() {
+      return this.requestHeader;
     }
 
-    public byte[] getMessageBytes() {
-      return theRequestRead;
+    byte[] getMessageBytes() {
+      return this.theRequestRead;
     }
 
     @Override
@@ -353,13 +353,11 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
     }
   }
 
-  private static class RpcRequestWrapper
-  extends RpcMessageWithHeader<RequestHeaderProto> {
+  private static class RpcRequestWrapper extends RpcMessageWithHeader<RequestHeaderProto> {
     @SuppressWarnings("unused")
-    public RpcRequestWrapper() {}
+    RpcRequestWrapper() {}
 
-    public RpcRequestWrapper(
-        RequestHeaderProto requestHeader, Message theRequest) {
+    RpcRequestWrapper(RequestHeaderProto requestHeader, Message theRequest) {
       super(requestHeader, theRequest);
     }
 
@@ -370,14 +368,13 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
 
     @Override
     public String toString() {
-      return requestHeader.getDeclaringClassProtocolName() + "." +
-          requestHeader.getMethodName();
+      return getMessageHeader().getDeclaringClassProtocolName() + "." +
+          getMessageHeader().getMethodName();
     }
   }
 
   @InterfaceAudience.LimitedPrivate({"RPC"})
-  public static class RpcRequestMessageWrapper
-  extends RpcMessageWithHeader<RpcRequestHeaderProto> {
+  public static class RpcRequestMessageWrapper extends RpcMessageWithHeader<RpcRequestHeaderProto> {
     public RpcRequestMessageWrapper() {}
 
     public RpcRequestMessageWrapper(
@@ -392,8 +389,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
   }
 
   @InterfaceAudience.LimitedPrivate({"RPC"})
-  public static class RpcResponseMessageWrapper
-  extends RpcMessageWithHeader<RpcResponseHeaderProto> {
+  public static class RpcResponseMessageWrapper extends RpcMessageWithHeader<RpcResponseHeaderProto> {
     public RpcResponseMessageWrapper() {}
 
     public RpcResponseMessageWrapper(
@@ -404,7 +400,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
     @Override
     byte[] readMessageRequest(DataInput in) throws IOException {
       // error message contain no message body
-      switch (requestHeader.getStatus()) {
+      switch (getMessageHeader().getStatus()) {
         case ERROR:
         case FATAL:
           return null;
@@ -428,8 +424,8 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
    */
   @InterfaceAudience.LimitedPrivate({"RPC"}) // temporarily exposed
   public static class RpcResponseWrapper implements RpcWrapper {
-    Message theResponse; // for senderSide, the response is here
-    byte[] theResponseRead; // for receiver side, the response is here
+    private Message theResponse; // for senderSide, the response is here
+    private byte[] theResponseRead; // for receiver side, the response is here
 
     public RpcResponseWrapper() {
     }
@@ -492,6 +488,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
      * @param portRangeConfig A config parameter that can be used to restrict
      * the range of ports used when port is 0 (an ephemeral port)
      */
+    @SuppressWarnings("checkstyle:parameternumber")
     public Server(Class<?> protocolClass, Object protocolImpl,
         Configuration conf, String bindAddress, int port, int numHandlers,
         int numReaders, int queueSizePerHandler, boolean verbose,
@@ -552,12 +549,13 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
       public Writable call(RPC.Server server, String protocol,
           Writable writableRequest, long receiveTime) throws Exception {
         RpcRequestWrapper request = (RpcRequestWrapper) writableRequest;
-        RequestHeaderProto rpcRequest = request.requestHeader;
+        RequestHeaderProto rpcRequest = request.getMessageHeader();
         String methodName = rpcRequest.getMethodName();
         String protoName = rpcRequest.getDeclaringClassProtocolName();
         long clientVersion = rpcRequest.getClientProtocolVersion();
-        if (server.verbose)
+        if (server.verbose) {
           LOG.info("Call: protocol=" + protocol + ", method=" + methodName);
+        }
 
         ProtoClassProtoImpl protocolImpl = getProtocolImpl(server, protoName,
             clientVersion);
@@ -572,7 +570,7 @@ public class ProtobufRpcEngineShaded implements RpcEngine {
         }
         Message prototype = service.getRequestPrototype(methodDescriptor);
         Message param = prototype.newBuilderForType()
-            .mergeFrom(request.theRequestRead).build();
+            .mergeFrom(request.getMessageBytes()).build();
 
         Message result;
         long startTime = Time.now();
diff --git a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopConstants.java b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopConstants.java
index 1f9c15d..c1672bd 100644
--- a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopConstants.java
+++ b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/HadoopConstants.java
@@ -17,13 +17,12 @@
  */
 package org.apache.ratis.hadooprpc;
 
-public interface HadoopConstants {
-  String RAFT_SERVER_KERBEROS_PRINCIPAL_KEY
-      = "raft.server.kerberos.principal";
-  String RAFT_CLIENT_KERBEROS_PRINCIPAL_KEY
-      = "raft.client.kerberos.principal";
-  String RAFT_SERVER_PROTOCOL_NAME
-      = "org.apache.hadoop.raft.server.protocol.RaftServerProtocol";
-  String COMBINED_CLIENT_PROTOCOL_NAME
-      = "org.apache.ratis.hadooprpc.client.CombinedClientProtocol";
+public final class HadoopConstants {
+  private HadoopConstants() {
+    //Never constructed
+  }
+  public static final String RAFT_SERVER_KERBEROS_PRINCIPAL_KEY = "raft.server.kerberos.principal";
+  public static final String RAFT_CLIENT_KERBEROS_PRINCIPAL_KEY = "raft.client.kerberos.principal";
+  public static final String RAFT_SERVER_PROTOCOL_NAME = "org.apache.hadoop.raft.server.protocol.RaftServerProtocol";
+  public static final String COMBINED_CLIENT_PROTOCOL_NAME = "org.apache.ratis.hadooprpc.client.CombinedClientProtocol";
 }
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 9ebb88a..71621ae 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
@@ -21,7 +21,6 @@ import java.io.IOException;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.ratis.client.impl.ClientProtoUtils;
-import org.apache.ratis.proto.RaftProtos;
 import org.apache.ratis.protocol.*;
 import org.apache.ratis.server.RaftServer;
 import org.apache.ratis.thirdparty.com.google.protobuf.RpcController;
diff --git a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java
index f1d8b22..73c3a23 100644
--- a/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java
+++ b/ratis-hadoop/src/main/java/org/apache/ratis/hadooprpc/server/HadoopRpcService.java
@@ -52,12 +52,13 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 
 /** Server side Hadoop RPC service. */
-public class HadoopRpcService extends RaftServerRpcWithProxy<Proxy<RaftServerProtocolPB>, PeerProxyMap<Proxy<RaftServerProtocolPB>>> {
+public final class HadoopRpcService extends RaftServerRpcWithProxy<Proxy<RaftServerProtocolPB>,
+    PeerProxyMap<Proxy<RaftServerProtocolPB>>> {
   public static final Logger LOG = LoggerFactory.getLogger(HadoopRpcService.class);
   static final String CLASS_NAME = HadoopRpcService.class.getSimpleName();
   public static final String SEND_SERVER_REQUEST = CLASS_NAME + ".sendServerRequest";
 
-  public static class Builder extends RaftServerRpc.Builder<Builder, HadoopRpcService> {
+  public static final class Builder extends RaftServerRpc.Builder<Builder, HadoopRpcService> {
     private Configuration conf;
 
     private Builder() {}