hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From larsgeo...@apache.org
Subject svn commit: r1501209 - in /hbase/trunk/hbase-server/src: main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
Date Tue, 09 Jul 2013 12:05:34 GMT
Author: larsgeorge
Date: Tue Jul  9 12:05:34 2013
New Revision: 1501209

URL: http://svn.apache.org/r1501209
Log:
HBASE-8819 Port HBASE-5428 to Thrift 2

Modified:
    hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java

Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java?rev=1501209&r1=1501208&r2=1501209&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java
(original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/thrift2/ThriftServer.java
Tue Jul  9 12:05:34 2013
@@ -40,6 +40,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.filter.ParseFilter;
 import org.apache.hadoop.hbase.thrift.CallQueue;
 import org.apache.hadoop.hbase.thrift.CallQueue.Call;
 import org.apache.hadoop.hbase.thrift.ThriftMetrics;
@@ -129,7 +130,7 @@ public class ThriftServer {
   }
 
   /*
-   * If bindValue is null, we don't bind. 
+   * If bindValue is null, we don't bind.
    */
   private static InetSocketAddress bindToPort(String bindValue, int listenPort)
       throws UnknownHostException {
@@ -194,8 +195,27 @@ public class ThriftServer {
   }
 
   /**
+   * Adds the option to pre-load filters at startup.
+   *
+   * @param conf  The current configuration instance.
+   */
+  protected static void registerFilters(Configuration conf) {
+    String[] filters = conf.getStrings("hbase.thrift.filters");
+    if(filters != null) {
+      for(String filterClass: filters) {
+        String[] filterPart = filterClass.split(":");
+        if(filterPart.length != 2) {
+          log.warn("Invalid filter specification " + filterClass + " - skipping");
+        } else {
+          ParseFilter.registerFilter(filterPart[0], filterPart[1]);
+        }
+      }
+    }
+  }
+
+  /**
    * Start up the Thrift2 server.
-   * 
+   *
    * @param args
    */
   public static void main(String[] args) throws Exception {
@@ -237,6 +257,7 @@ public class ThriftServer {
 
       conf.set("hbase.regionserver.thrift.server.type", implType);
       conf.setInt("hbase.regionserver.thrift.port", listenPort);
+      registerFilters(conf);
 
       // Construct correct ProtocolFactory
       boolean compact = cmd.hasOption("compact");

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java?rev=1501209&r1=1501208&r2=1501209&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java
Tue Jul  9 12:05:34 2013
@@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.HColumnDe
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.MediumTests;
 import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.filter.ParseFilter;
 import org.apache.hadoop.hbase.test.MetricsAssertHelper;
 import org.apache.hadoop.hbase.thrift.ThriftMetrics;
 import org.apache.hadoop.hbase.thrift2.generated.TColumn;
@@ -55,6 +56,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Map;
 
 import static org.junit.Assert.*;
 import static java.nio.ByteBuffer.wrap;
@@ -625,7 +627,6 @@ public class TestThriftHBaseServiceHandl
     int scanId = handler.openScanner(table, scan);
     List<TResult> results = null;
     for (int i = 0; i < 10; i++) {
-      System.out.println("batch: " + i);
       // get batch for single row (10x10 is what we expect)
       results = handler.getScannerRows(scanId, 1);
       assertEquals(1, results.size());
@@ -636,7 +637,6 @@ public class TestThriftHBaseServiceHandl
       for (int y = 0; y < 10; y++) {
         int colNum = y + (10 * i);
         String colNumPad = pad(colNum, (byte) 3);
-        System.out.println("col" + colNumPad + ": " + new String(cols.get(y).getQualifier()));
         assertArrayEquals(("col" + colNumPad).getBytes(), cols.get(y).getQualifier());
       }
     }
@@ -655,6 +655,15 @@ public class TestThriftHBaseServiceHandl
   }
 
   @Test
+  public void testFilterRegistration() throws Exception {
+    Configuration conf = UTIL.getConfiguration();
+    conf.set("hbase.thrift.filters", "MyFilter:filterclass");
+    ThriftServer.registerFilters(conf);
+    Map<String, String> registeredFilters = ParseFilter.getAllFilters();
+    assertEquals("filterclass", registeredFilters.get("MyFilter"));
+  }
+
+  @Test
   public void testMetrics() throws Exception {
     Configuration conf = UTIL.getConfiguration();
     ThriftMetrics metrics = getMetrics(conf);



Mime
View raw message