hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject svn commit: r1596349 - in /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase: HConstants.java ipc/HBaseRPC.java
Date Tue, 20 May 2014 18:18:41 GMT
Author: liyin
Date: Tue May 20 18:18:41 2014
New Revision: 1596349

URL: http://svn.apache.org/r1596349
Log:
[HBASE-10891] Setup Socks Proxy in HBaseRPC for HadoopRPC

Author: manukranthk

Summary: This diff attempts to setup Socks Proxy support to talk to master.

Test Plan: Test on Calypso.

Reviewers: liyintang, nileema, adela, daviddeng

Reviewed By: daviddeng

Subscribers: hbase-eng@

Differential Revision: https://phabricator.fb.com/D1295350

Tasks: 4165944

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java?rev=1596349&r1=1596348&r2=1596349&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java Tue May 20
18:18:41 2014
@@ -1098,6 +1098,12 @@ public final class HConstants {
 
   public static final String SWIFT_CLIENT_SOCKS_PROXY_HOST_AND_PORT =
       "hbase.client.swift.socks.proxy.hostAndPort";
+
+  public static final String HADOOPRPC_CLIENT_SOCKS_PROXY_HOSTNAME =
+      "hbase.client.socks.proxy.host.name";
+  public static final String HADOOPRPC_CLIENT_SOCKS_PROXY_PORT =
+      "hbase.client.socks.proxy.port";
+
   /**
    * Key of the number of store-files for blocking flush
    */

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java?rev=1596349&r1=1596348&r2=1596349&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java Tue May
20 18:18:41 2014
@@ -28,6 +28,7 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.InetSocketAddress;
+import java.net.Proxy.Type;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -50,9 +51,12 @@ import org.apache.hadoop.hbase.util.Byte
 import org.apache.hadoop.hbase.util.ParamFormatHelper;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.ipc.VersionedProtocol;
+import org.apache.hadoop.net.SocksSocketFactory;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.codehaus.jackson.map.ObjectMapper;
 
+import com.google.common.net.HostAndPort;
+
 /** A simple RPC mechanism.
  *
  * This is a local hbase copy of the hadoop RPC so we can do things like
@@ -393,6 +397,28 @@ public class HBaseRPC {
                               (long) serverVersion);
   }
 
+  public static SocketFactory getSocksProxySocketFactoryFromConf(
+      Configuration conf) {
+    String socksProxyHostName =
+        conf.get(HConstants.HADOOPRPC_CLIENT_SOCKS_PROXY_HOSTNAME, "");
+    int socksProxyPort =
+        conf.getInt(HConstants.HADOOPRPC_CLIENT_SOCKS_PROXY_PORT, 0);
+    SocketFactory socketFactory = null;
+    if (!socksProxyHostName.isEmpty() && socksProxyPort != 0) {
+      try {
+        java.net.Proxy proxy = new java.net.Proxy(Type.SOCKS,
+            new InetSocketAddress(socksProxyHostName, socksProxyPort));
+        socketFactory = new SocksSocketFactory(proxy);
+      } catch (Exception e) {
+        LOG.warn("Proxy resolution failed", e);
+      }
+    }
+    if (socketFactory == null) {
+      socketFactory = SocketFactory.getDefault();
+    }
+    return socketFactory;
+  }
+
   /**
    * Construct a client-side proxy object with the default SocketFactory
    *
@@ -409,8 +435,8 @@ public class HBaseRPC {
       int rpcTimeout, HBaseRPCOptions options)
       throws IOException {
 
-    return getProxy(protocol, clientVersion, addr, conf, 
-        SocketFactory.getDefault(), rpcTimeout, options);
+    return getProxy(protocol, clientVersion, addr, conf,
+        getSocksProxySocketFactoryFromConf(conf), rpcTimeout, options);
   }
   
   /* this is needed for unit tests. some tests start multiple



Mime
View raw message