hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject svn commit: r1584190 - in /hbase/branches/0.89-fb/src: main/java/org/apache/hadoop/hbase/HConstants.java main/java/org/apache/hadoop/hbase/ipc/thrift/ThriftClientObjectFactory.java test/java/org/apache/hadoop/hbase/thrift/swift/TestSocksProxy.java
Date Wed, 02 Apr 2014 21:10:56 GMT
Author: liyin
Date: Wed Apr  2 21:10:56 2014
New Revision: 1584190

URL: http://svn.apache.org/r1584190
Log:
[HBASE-10891] Adding config option for SocksProxy on the thrift client config

Author: manukranthk

Summary: This exposes the socks proxy functionality via the configuration.

Test Plan: Unit test

Reviewers: liyintang, aaiyer

Reviewed By: liyintang

CC: hbase-eng@, andrewcox, nileema

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

Task ID: 4025730

Added:
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/thrift/swift/TestSocksProxy.java
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/thrift/ThriftClientObjectFactory.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=1584190&r1=1584189&r2=1584190&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 Wed Apr 
2 21:10:56 2014
@@ -1084,6 +1084,8 @@ public final class HConstants {
   public static final String REGIONSERVER_LEASE_THREAD_WAKE_FREQUENCY =
       "hbase.regionserver.thread.wakefrequency";
 
+  public static final String SWIFT_CLIENT_SOCKS_PROXY_HOST_AND_PORT =
+      "hbase.client.swift.socks.proxy.hostAndPort";
   private HConstants() {
     // Can't be instantiated with this constructor.
   }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/thrift/ThriftClientObjectFactory.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/thrift/ThriftClientObjectFactory.java?rev=1584190&r1=1584189&r2=1584190&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/thrift/ThriftClientObjectFactory.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/ipc/thrift/ThriftClientObjectFactory.java
Wed Apr  2 21:10:56 2014
@@ -27,6 +27,8 @@ import com.facebook.nifty.header.protoco
 import com.facebook.swift.service.ThriftClient;
 import com.facebook.swift.service.ThriftClientConfig;
 import com.facebook.swift.service.ThriftClientManager;
+import com.google.common.net.HostAndPort;
+
 import io.airlift.units.Duration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -40,7 +42,7 @@ import java.util.concurrent.TimeUnit;
 
 public class ThriftClientObjectFactory extends
     BasePoolableObjectFactory<ThriftClientInterface> {
-  private final Log LOG = LogFactory.getLog(ThriftClientObjectFactory.class);
+  private static final Log LOG = LogFactory.getLog(ThriftClientObjectFactory.class);
   private final InetSocketAddress address;
   private final Class<? extends ThriftClientInterface> clazz;
   private final ThriftClientManager clientManager;
@@ -63,6 +65,23 @@ public class ThriftClientObjectFactory e
       .setConnectTimeout(
         new Duration(conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY,
           HConstants.DEFAULT_HBASE_RPC_TIMEOUT), TimeUnit.MILLISECONDS));
+    setSocksProxy(this.thriftClientConfig, this.conf);
+  }
+
+  public static void setSocksProxy(ThriftClientConfig thriftClientConfig,
+      Configuration conf) {
+    String socksProxyString =
+        conf.get(HConstants.SWIFT_CLIENT_SOCKS_PROXY_HOST_AND_PORT);
+    HostAndPort socksProxy = null;
+    try {
+      socksProxy = HostAndPort.fromString(socksProxyString);
+    } catch (IllegalArgumentException e) {
+      LOG.error("Socks proxy host and port invalid.");
+      socksProxy = null;
+    }
+    if (socksProxy != null && socksProxy.hasPort()) {
+      thriftClientConfig.setSocksProxy(socksProxy);
+    }
   }
 
   /**

Added: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/thrift/swift/TestSocksProxy.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/thrift/swift/TestSocksProxy.java?rev=1584190&view=auto
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/thrift/swift/TestSocksProxy.java
(added)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/thrift/swift/TestSocksProxy.java
Wed Apr  2 21:10:56 2014
@@ -0,0 +1,35 @@
+package org.apache.hadoop.hbase.thrift.swift;
+
+import static org.junit.Assert.*;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.ipc.thrift.ThriftClientObjectFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.facebook.swift.service.ThriftClientConfig;
+
+public class TestSocksProxy {
+  @Test
+  public void test() {
+    ThriftClientConfig config = new ThriftClientConfig();
+    Configuration conf = HBaseConfiguration.create();
+    conf.set(HConstants.SWIFT_CLIENT_SOCKS_PROXY_HOST_AND_PORT,
+        "localhost:8091");
+    ThriftClientObjectFactory.setSocksProxy(config, conf);
+    assertEquals("Hostname parsed correctly",
+        config.getSocksProxy().getHostText(), "localhost");
+    assertEquals("Port number parse correctly",
+        config.getSocksProxy().getPort(), 8091);
+
+    config = new ThriftClientConfig();
+    conf.set(HConstants.SWIFT_CLIENT_SOCKS_PROXY_HOST_AND_PORT,
+        "localhost");
+    ThriftClientObjectFactory.setSocksProxy(config, conf);
+    assertNull("Null values expected for the host and port. "
+        + config.getSocksProxy(), config.getSocksProxy());
+  }
+}



Mime
View raw message