Search in sources :

Example 26 with RegionCoprocessorHost

use of org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost in project hbase by apache.

the class TestCoprocessorInterface method initHRegion.

HRegion initHRegion(TableName tableName, String callingMethod, Configuration conf, Class<?>[] implClasses, byte[][] families) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    for (byte[] family : families) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }
    ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
    RegionInfo info = RegionInfoBuilder.newBuilder(tableName).setStartKey(null).setEndKey(null).setSplit(false).build();
    Path path = new Path(DIR + callingMethod);
    HRegion r = HBaseTestingUtil.createRegionAndWAL(info, path, conf, builder.build());
    // this following piece is a hack.
    RegionCoprocessorHost host = new RegionCoprocessorHost(r, Mockito.mock(RegionServerServices.class), conf);
    r.setCoprocessorHost(host);
    for (Class<?> implClass : implClasses) {
        host.load(implClass.asSubclass(RegionCoprocessor.class), Coprocessor.PRIORITY_USER, conf);
        Coprocessor c = host.findCoprocessor(implClass.getName());
        assertNotNull(c);
    }
    // Here we have to call pre and postOpen explicitly.
    host.preOpen();
    host.postOpen();
    return r;
}
Also used : Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) Coprocessor(org.apache.hadoop.hbase.Coprocessor) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 27 with RegionCoprocessorHost

use of org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost in project hbase by apache.

the class TestAccessController3 method setUpTableAndUserPermissions.

private static void setUpTableAndUserPermissions() throws Exception {
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TEST_TABLE).setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(TEST_FAMILY).setMaxVersions(100).build()).build();
    createTable(TEST_UTIL, USER_OWNER, tableDescriptor, new byte[][] { Bytes.toBytes("s") });
    HRegion region = TEST_UTIL.getHBaseCluster().getRegions(TEST_TABLE).get(0);
    RegionCoprocessorHost rcpHost = region.getCoprocessorHost();
    RCP_ENV = rcpHost.createEnvironment(ACCESS_CONTROLLER, Coprocessor.PRIORITY_HIGHEST, 1, conf);
    // Set up initial grants
    grantGlobal(TEST_UTIL, USER_ADMIN.getShortName(), Permission.Action.ADMIN, Permission.Action.CREATE, Permission.Action.READ, Permission.Action.WRITE);
    grantOnTable(TEST_UTIL, USER_RW.getShortName(), TEST_TABLE, TEST_FAMILY, null, Permission.Action.READ, Permission.Action.WRITE);
    // USER_CREATE is USER_RW plus CREATE permissions
    grantOnTable(TEST_UTIL, USER_CREATE.getShortName(), TEST_TABLE, null, null, Permission.Action.CREATE, Permission.Action.READ, Permission.Action.WRITE);
    grantOnTable(TEST_UTIL, USER_RO.getShortName(), TEST_TABLE, TEST_FAMILY, null, Permission.Action.READ);
    grantOnTable(TEST_UTIL, USER_ADMIN_CF.getShortName(), TEST_TABLE, TEST_FAMILY, null, Permission.Action.ADMIN, Permission.Action.CREATE);
    grantGlobal(TEST_UTIL, toGroupEntry(GROUP_ADMIN), Permission.Action.ADMIN);
    grantGlobal(TEST_UTIL, toGroupEntry(GROUP_CREATE), Permission.Action.CREATE);
    grantGlobal(TEST_UTIL, toGroupEntry(GROUP_READ), Permission.Action.READ);
    grantGlobal(TEST_UTIL, toGroupEntry(GROUP_WRITE), Permission.Action.WRITE);
    assertEquals(5, PermissionStorage.getTablePermissions(conf, TEST_TABLE).size());
    try {
        assertEquals(5, AccessControlClient.getUserPermissions(systemUserConnection, TEST_TABLE.toString()).size());
    } catch (Throwable e) {
        LOG.error("error during call of AccessControlClient.getUserPermissions. ", e);
    }
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Aggregations

RegionCoprocessorHost (org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost)27 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)16 Test (org.junit.Test)16 Configuration (org.apache.hadoop.conf.Configuration)10 RegionServerServices (org.apache.hadoop.hbase.regionserver.RegionServerServices)8 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)6 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)5 HStore (org.apache.hadoop.hbase.regionserver.HStore)4 ScanInfo (org.apache.hadoop.hbase.regionserver.ScanInfo)4 Path (org.apache.hadoop.fs.Path)3 Coprocessor (org.apache.hadoop.hbase.Coprocessor)3 Put (org.apache.hadoop.hbase.client.Put)3 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)3 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)2 Get (org.apache.hadoop.hbase.client.Get)2 Result (org.apache.hadoop.hbase.client.Result)2 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 CoprocessorEnvironment (org.apache.hadoop.hbase.CoprocessorEnvironment)1