diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java index 6c6b272a324..16b885252b8 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterCoprocessorHost.java @@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.master; import java.io.IOException; import java.util.List; +import org.apache.commons.lang.ClassUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -91,7 +92,8 @@ public class MasterCoprocessorHost public MasterEnvironment createEnvironment(final Class implClass, final Coprocessor instance, final int priority, final int seq, final Configuration conf) { - for (Class c : implClass.getInterfaces()) { + for (Object itf : ClassUtils.getAllInterfaces(implClass)) { + Class c = (Class) itf; if (CoprocessorService.class.isAssignableFrom(c)) { masterServices.registerService(((CoprocessorService)instance).getService()); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java index 13b83170a7b..a7d062715b2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java @@ -38,6 +38,7 @@ import com.google.protobuf.Service; import org.apache.commons.collections.map.AbstractReferenceMap; import org.apache.commons.collections.map.ReferenceMap; +import org.apache.commons.lang.ClassUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; @@ -370,7 +371,8 @@ public class RegionCoprocessorHost // uses a different way to be registered and executed. // It uses a visitor pattern to invoke registered Endpoint // method. - for (Class c : implClass.getInterfaces()) { + for (Object itf : ClassUtils.getAllInterfaces(implClass)) { + Class c = (Class) itf; if (CoprocessorService.class.isAssignableFrom(c)) { region.registerService( ((CoprocessorService)instance).getService() ); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerCoprocessorHost.java index ab8e948b35d..d96b2abde26 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionServerCoprocessorHost.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.Comparator; import java.util.List; +import org.apache.commons.lang.ClassUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.classification.InterfaceAudience; @@ -281,9 +282,11 @@ public class RegionServerCoprocessorHost extends final Configuration conf, final RegionServerServices services) { super(impl, priority, seq, conf); this.regionServerServices = services; - for (Class c : implClass.getInterfaces()) { + for (Object itf : ClassUtils.getAllInterfaces(implClass)) { + Class c = (Class) itf; if (SingletonCoprocessorService.class.isAssignableFrom(c)) { - this.regionServerServices.registerService(((SingletonCoprocessorService) impl).getService()); + this.regionServerServices.registerService( + ((SingletonCoprocessorService) impl).getService()); break; } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java index a72cf1c3059..a9556acb2e4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java @@ -29,6 +29,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; @@ -43,6 +44,10 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; +import org.apache.hadoop.hbase.coprocessor.RegionServerCoprocessorEnvironment; +import org.apache.hadoop.hbase.master.MasterCoprocessorHost; +import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.access.Permission.Action; import org.apache.hadoop.hbase.testclassification.LargeTests; @@ -466,6 +471,24 @@ public class TestAccessController2 extends SecureTestUtil { verifyDenied(TESTGROUP1_USER1, scanTableActionForGroupWithQualifierLevelAccess); } + public static class MyAccessController extends AccessController { + } + + @Test + public void testCoprocessorLoading() throws Exception { + MasterCoprocessorHost cpHost = + TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterCoprocessorHost(); + cpHost.load(MyAccessController.class, Coprocessor.PRIORITY_HIGHEST, conf); + AccessController ACCESS_CONTROLLER = (AccessController) cpHost.findCoprocessor( + MyAccessController.class.getName()); + MasterCoprocessorEnvironment CP_ENV = cpHost.createEnvironment( + MyAccessController.class, ACCESS_CONTROLLER, Coprocessor.PRIORITY_HIGHEST, 1, conf); + RegionServerCoprocessorHost rsHost = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0) + .getRegionServerCoprocessorHost(); + RegionServerCoprocessorEnvironment RSCP_ENV = rsHost.createEnvironment( + MyAccessController.class, ACCESS_CONTROLLER, Coprocessor.PRIORITY_HIGHEST, 1, conf); + } + @Test public void testACLZNodeDeletion() throws Exception { String baseAclZNode = "/hbase/acl/";