hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1245774 - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/filter/ main/java/org/apache/hadoop/hbase/thrift/ test/java/org/apache/hadoop/hbase/filter/ test/java/org/apache/hadoop/hbase/thrift/
Date Fri, 17 Feb 2012 21:39:31 GMT
Author: stack
Date: Fri Feb 17 21:39:30 2012
New Revision: 1245774

URL: http://svn.apache.org/viewvc?rev=1245774&view=rev
Log:
HBASE-5428 Allow for custom filters to be registered within the Thrift interface

Modified:
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java
    hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java
    hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java?rev=1245774&r1=1245773&r2=1245774&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/filter/ParseFilter.java Fri Feb 17 21:39:30
2012
@@ -23,12 +23,10 @@ import java.lang.reflect.InvocationTarge
 import java.lang.reflect.Method;
 import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
-import java.util.ArrayList;
-import java.util.EmptyStackException;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.Stack;
+import java.util.*;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
 import org.apache.hadoop.hbase.util.Bytes;
@@ -43,6 +41,7 @@ import org.apache.hadoop.hbase.util.Byte
  * Filter Language can be found at: https://issues.apache.org/jira/browse/HBASE-4176
  */
 public class ParseFilter {
+  private static final Log LOG = LogFactory.getLog(ParseFilter.class);
 
   private static HashMap<ByteBuffer, Integer> operatorPrecedenceHashMap;
   private static HashMap<String, String> filterHashMap;
@@ -832,4 +831,26 @@ public class ParseFilter {
   public Set<String> getSupportedFilters () {
     return filterHashMap.keySet();
   }
+
+  /**
+   * Returns all known filters
+   * @return an unmodifiable map of filters
+   */
+  public static Map<String, String> getAllFilters() {
+    return Collections.unmodifiableMap(filterHashMap);
+  }
+
+  /**
+   * Register a new filter with the parser.  If the filter is already registered,
+   * an IllegalArgumentException will be thrown.
+   *
+   * @param name a name for the filter
+   * @param filterClass fully qualified class name
+   */
+  public static void registerFilter(String name, String filterClass) {
+    if(LOG.isInfoEnabled())
+      LOG.info("Registering new filter " + name);
+
+    filterHashMap.put(name, filterClass);
+  }
 }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java?rev=1245774&r1=1245773&r2=1245774&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java Fri Feb
17 21:39:30 2012
@@ -365,6 +365,8 @@ public class ThriftServerRunner implemen
       User.login(conf, "hbase.thrift.keytab.file",
           "hbase.thrift.kerberos.principal", machineName);
     }
+
+    registerFilters(conf);
   }
 
   ExecutorService createExecutor(BlockingQueue<Runnable> callQueue,
@@ -1340,4 +1342,18 @@ public class ThriftServerRunner implemen
       op.setAttribute(name, value);
     }
   }
+
+  public 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]);
+        }
+      }
+    }
+  }
 }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java?rev=1245774&r1=1245773&r2=1245774&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/filter/TestParseFilter.java Fri Feb
17 21:39:30 2012
@@ -650,6 +650,13 @@ public class TestParseFilter {
     FirstKeyOnlyFilter firstKeyOnlyFilter =
       doTestFilter(filterString, FirstKeyOnlyFilter.class);
   }
+  
+  @Test
+  public void testRegisterFilter() {
+    ParseFilter.registerFilter("MyFilter", "some.class");
+    
+    assertTrue(f.getSupportedFilters().contains("MyFilter"));
+  }
 
   private <T extends Filter> T doTestFilter(String filterString, Class<T> clazz)
throws IOException {
     byte [] filterStringAsByteArray = Bytes.toBytes(filterString);

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java?rev=1245774&r1=1245773&r2=1245774&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/thrift/TestThriftServer.java Fri Feb
17 21:39:30 2012
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Collection;
 
+import org.apache.hadoop.hbase.filter.ParseFilter;
 import org.junit.experimental.categories.Category;
 import org.junit.Test;
 import org.junit.BeforeClass;
@@ -102,6 +103,7 @@ public class TestThriftServer {
     doTestTableTimestampsAndColumns();
     doTestTableScanners();
     doTestGetTableRegions();
+    doTestFilterRegistration();
   }
 
   /**
@@ -428,6 +430,18 @@ public class TestThriftServer {
     assertEquals("non-existing table should have 0 region, " +
             "but found " + regionCount, regionCount, 0);
   }
+  
+  public void doTestFilterRegistration() throws Exception {
+    Configuration conf = UTIL.getConfiguration();
+    
+    conf.set("hbase.thrift.filters", "MyFilter:filterclass");
+
+    ThriftServerRunner.registerFilters(conf);
+    
+    Map<String, String> registeredFilters = ParseFilter.getAllFilters();
+    
+    assertEquals("filterclass", registeredFilters.get("MyFilter"));
+  }
 
   /**
    *



Mime
View raw message