Search in sources :

Example 11 with RegionCoprocessorHost

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

the class TestRegionObserverPreFlushAndPreCompact method getRegionCoprocessorHost.

private RegionCoprocessorHost getRegionCoprocessorHost() {
    // Make up an HRegion instance. Use the hbase:meta first region as our RegionInfo. Use
    // hbase:meta table name for building the TableDescriptor our mock returns when asked schema
    // down inside RegionCoprocessorHost. Pass in mocked RegionServerServices too.
    RegionInfo ri = RegionInfoBuilder.FIRST_META_REGIONINFO;
    HRegion mockedHRegion = Mockito.mock(HRegion.class);
    Mockito.when(mockedHRegion.getRegionInfo()).thenReturn(ri);
    TableDescriptor td = TableDescriptorBuilder.newBuilder(ri.getTable()).build();
    Mockito.when(mockedHRegion.getTableDescriptor()).thenReturn(td);
    RegionServerServices mockedServices = Mockito.mock(RegionServerServices.class);
    Configuration conf = HBaseConfiguration.create();
    // Load our test coprocessor defined above.
    conf.set(REGION_COPROCESSOR_CONF_KEY, TestRegionObserver.class.getName());
    return new RegionCoprocessorHost(mockedHRegion, mockedServices, conf);
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 12 with RegionCoprocessorHost

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

the class TestCoprocessorConfiguration method testRegionCoprocessorHostAllDisabled.

@Test
public void testRegionCoprocessorHostAllDisabled() throws Exception {
    Configuration conf = new Configuration(CONF);
    conf.setBoolean(CoprocessorHost.COPROCESSORS_ENABLED_CONF_KEY, false);
    HRegion region = mock(HRegion.class);
    when(region.getRegionInfo()).thenReturn(REGIONINFO);
    when(region.getTableDescriptor()).thenReturn(TABLEDESC);
    RegionServerServices rsServices = mock(RegionServerServices.class);
    systemCoprocessorLoaded.set(false);
    tableCoprocessorLoaded.set(false);
    new RegionCoprocessorHost(region, rsServices, conf);
    assertFalse("System coprocessors should not have been loaded", systemCoprocessorLoaded.get());
    assertFalse("Table coprocessors should not have been loaded", tableCoprocessorLoaded.get());
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) Test(org.junit.Test)

Example 13 with RegionCoprocessorHost

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

the class TestAccessController 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());
    int size = 0;
    try {
        size = AccessControlClient.getUserPermissions(systemUserConnection, TEST_TABLE.toString()).size();
    } catch (Throwable e) {
        LOG.error("error during call of AccessControlClient.getUserPermissions. ", e);
        fail("error during call of AccessControlClient.getUserPermissions.");
    }
    assertEquals(5, size);
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 14 with RegionCoprocessorHost

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

the class TestRegionObserverInterface method verifyMethodResult.

// check each region whether the coprocessor upcalls are called or not.
private void verifyMethodResult(Class<?> coprocessor, String[] methodName, TableName tableName, Object[] value) throws IOException {
    try {
        for (JVMClusterUtil.RegionServerThread t : cluster.getRegionServerThreads()) {
            if (!t.isAlive() || t.getRegionServer().isAborted() || t.getRegionServer().isStopping()) {
                continue;
            }
            for (RegionInfo r : ProtobufUtil.getOnlineRegions(t.getRegionServer().getRSRpcServices())) {
                if (!r.getTable().equals(tableName)) {
                    continue;
                }
                RegionCoprocessorHost cph = t.getRegionServer().getOnlineRegion(r.getRegionName()).getCoprocessorHost();
                Coprocessor cp = cph.findCoprocessor(coprocessor.getName());
                assertNotNull(cp);
                for (int i = 0; i < methodName.length; ++i) {
                    Method m = coprocessor.getMethod(methodName[i]);
                    Object o = m.invoke(cp);
                    assertTrue("Result of " + coprocessor.getName() + "." + methodName[i] + " is expected to be " + value[i].toString() + ", while we get " + o.toString(), o.equals(value[i]));
                }
            }
        }
    } catch (Exception e) {
        throw new IOException(e.toString());
    }
}
Also used : Coprocessor(org.apache.hadoop.hbase.Coprocessor) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Method(java.lang.reflect.Method) IOException(java.io.IOException) IOException(java.io.IOException)

Example 15 with RegionCoprocessorHost

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

the class TestRegionObserverScannerOpenHook method initHRegion.

HRegion initHRegion(byte[] tableName, String callingMethod, Configuration conf, byte[]... families) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName));
    for (byte[] family : families) {
        builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }
    TableDescriptor tableDescriptor = builder.build();
    ChunkCreator.initialize(MemStoreLAB.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null, MemStoreLAB.INDEX_CHUNK_SIZE_PERCENTAGE_DEFAULT);
    RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
    Path path = new Path(DIR + callingMethod);
    WAL wal = HBaseTestingUtil.createWal(conf, path, info);
    HRegion r = HRegion.createHRegion(info, path, conf, tableDescriptor, wal);
    // this following piece is a hack. currently a coprocessorHost
    // is secretly loaded at OpenRegionHandler. we don't really
    // start a region server here, so just manually create cphost
    // and set it to region.
    RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf);
    r.setCoprocessorHost(host);
    return r;
}
Also used : Path(org.apache.hadoop.fs.Path) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) WAL(org.apache.hadoop.hbase.wal.WAL) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) 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