Search in sources :

Example 46 with HBaseTableUtil

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtil in project cdap by caskdata.

the class IncrementSummingScannerTest method createRegion.

static HRegion createRegion(Configuration hConf, CConfiguration cConf, TableId tableId, HColumnDescriptor cfd) throws Exception {
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    HTableDescriptorBuilder htd = tableUtil.buildHTableDescriptor(tableId);
    cfd.setMaxVersions(Integer.MAX_VALUE);
    cfd.setKeepDeletedCells(true);
    htd.addFamily(cfd);
    htd.addCoprocessor(IncrementHandler.class.getName());
    HTableDescriptor desc = htd.build();
    String tableName = desc.getNameAsString();
    Path tablePath = new Path("/tmp/" + tableName);
    Path hlogPath = new Path("/tmp/hlog-" + tableName);
    FileSystem fs = FileSystem.get(hConf);
    assertTrue(fs.mkdirs(tablePath));
    WALFactory walFactory = new WALFactory(hConf, null, hlogPath.toString());
    WAL hLog = walFactory.getWAL(new byte[] { 1 });
    HRegionInfo regionInfo = new HRegionInfo(desc.getTableName());
    HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(hConf, fs, tablePath, regionInfo);
    return new HRegion(regionFS, hLog, hConf, desc, new LocalRegionServerServices(hConf, ServerName.valueOf(InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
Also used : Path(org.apache.hadoop.fs.Path) HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) WAL(org.apache.hadoop.hbase.wal.WAL) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) WALFactory(org.apache.hadoop.hbase.wal.WALFactory)

Example 47 with HBaseTableUtil

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtil in project cdap by caskdata.

the class IncrementHandlerTest method createTable.

@Override
public Table createTable(TableId tableId) throws Exception {
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    HTableDescriptorBuilder tableDesc = tableUtil.buildHTableDescriptor(tableId);
    HColumnDescriptor columnDesc = new HColumnDescriptor(FAMILY);
    columnDesc.setMaxVersions(Integer.MAX_VALUE);
    columnDesc.setValue(IncrementHandlerState.PROPERTY_TRANSACTIONAL, "false");
    tableDesc.addFamily(columnDesc);
    tableDesc.addCoprocessor(IncrementHandler.class.getName());
    HTableDescriptor htd = tableDesc.build();
    TEST_HBASE.getHBaseAdmin().createTable(htd);
    TEST_HBASE.waitUntilTableAvailable(htd.getName(), 5000);
    return tableUtil.createTable(conf, tableId);
}
Also used : HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 48 with HBaseTableUtil

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtil in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testListAllInNamespace.

@Test
public void testListAllInNamespace() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    Set<TableId> fooNamespaceTableIds = ImmutableSet.of(TableId.from("foo", "some.table1"), TableId.from("foo", "other.table"), TableId.from("foo", "some.table2"));
    String fooNamespaceInHbase = String.format("%s_foo", getPrefix());
    Set<TableId> fooNamespaceHTableIds = ImmutableSet.of(TableId.from(fooNamespaceInHbase, "some.table1"), TableId.from(fooNamespaceInHbase, "other.table"), TableId.from(fooNamespaceInHbase, "some.table2"));
    createNamespace("foo");
    createNamespace("foo_bar");
    TableId tableIdInOtherNamespace = TableId.from("foo_bar", "my.dataset");
    TableId hTableIdInOtherNamespace = TableId.from(String.format("%s_foo_bar", getPrefix()), "my.dataset");
    List<ListenableFuture<TableId>> createFutures = new ArrayList<>();
    for (TableId tableId : fooNamespaceTableIds) {
        createFutures.add(createAsync(tableId));
    }
    createFutures.add(createAsync(tableIdInOtherNamespace));
    Futures.allAsList(createFutures).get(60, TimeUnit.SECONDS);
    Set<TableId> retrievedTableIds = ImmutableSet.copyOf(tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("foo"))));
    Assert.assertEquals(fooNamespaceHTableIds, retrievedTableIds);
    Set<TableId> allTableIds = ImmutableSet.<TableId>builder().addAll(fooNamespaceHTableIds).add(hTableIdInOtherNamespace).build();
    Assert.assertEquals(allTableIds, ImmutableSet.copyOf(tableUtil.listTables(hAdmin)));
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foo")), hAdmin.getConfiguration());
    Assert.assertEquals(1, hAdmin.listTables().length);
    drop(tableIdInOtherNamespace);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("foo_bar");
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 49 with HBaseTableUtil

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtil in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testDropAllInOtherNamespaceWithPrefix.

@Test
public void testDropAllInOtherNamespaceWithPrefix() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    createNamespace("foonamespace");
    createNamespace("barnamespace");
    TableId tableIdWithOtherPrefix = TableId.from("foonamespace", "other.table");
    TableId tableIdInOtherNamespace = TableId.from("default", "some.table1");
    Futures.allAsList(createAsync(TableId.from("foonamespace", "some.table1")), createAsync(tableIdWithOtherPrefix), createAsync(TableId.from("foonamespace", "some.table2")), createAsync(tableIdInOtherNamespace)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foonamespace")), hAdmin.getConfiguration(), new Predicate<TableId>() {

        @Override
        public boolean apply(TableId input) {
            return input.getTableName().startsWith("some");
        }
    });
    Assert.assertEquals(2, hAdmin.listTables().length);
    Futures.allAsList(dropAsync(tableIdInOtherNamespace), dropAsync(tableIdWithOtherPrefix)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("foonamespace");
    deleteNamespace("barnamespace");
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 50 with HBaseTableUtil

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtil in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testDropAllInDefaultNamespace.

@Test
public void testDropAllInDefaultNamespace() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId tableIdInOtherNamespace = TableId.from("default2", "my.dataset");
    createNamespace("default2");
    Futures.allAsList(createAsync(TableId.from("default", "some.table1")), createAsync(TableId.from("default", "other.table")), createAsync(TableId.from("default", "some.table2")), createAsync(tableIdInOtherNamespace)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, NamespaceId.DEFAULT.getEntityName(), hAdmin.getConfiguration());
    Assert.assertEquals(1, hAdmin.listTables().length);
    drop(tableIdInOtherNamespace);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("default2");
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) Test(org.junit.Test)

Aggregations

HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)28 TableId (io.cdap.cdap.data2.util.TableId)21 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)19 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)18 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)16 HBaseTableUtilFactory (io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory)16 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)15 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)14 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)13 FileSystem (org.apache.hadoop.fs.FileSystem)12 Path (org.apache.hadoop.fs.Path)12 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)12 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)12 HRegionFileSystem (org.apache.hadoop.hbase.regionserver.HRegionFileSystem)12 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)11 Test (org.junit.Test)11 WAL (org.apache.hadoop.hbase.wal.WAL)10 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)10 IOException (java.io.IOException)7 Result (org.apache.hadoop.hbase.client.Result)6