Search in sources :

Example 21 with HBaseTableUtil

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

the class AbstractHBaseTableUtilTest method testBackwardCompatibility.

@Test
public void testBackwardCompatibility() throws IOException, InterruptedException {
    HBaseTableUtil tableUtil = getTableUtil();
    String tablePrefix = cConf.get(Constants.Dataset.TABLE_PREFIX);
    TableId tableId = TableId.from("default", "my.dataset");
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    create(tableId);
    TableId resultTableId = getTableId("default", "my.dataset");
    Assert.assertNotNull(resultTableId);
    Assert.assertEquals("default", resultTableId.getNamespace());
    Assert.assertEquals("cdap.user.my.dataset", HTableNameConverter.toHBaseTableName(tablePrefix, resultTableId));
    Assert.assertEquals(getTableNameAsString(tableId), Bytes.toString(tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId).getTableDescriptor().getTableName().getName()));
    drop(tableId);
    tableId = TableId.from("default", "system.queue.config");
    hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    create(tableId);
    resultTableId = getTableId("default", "system.queue.config");
    Assert.assertEquals("default", resultTableId.getNamespace());
    Assert.assertEquals("cdap.system.queue.config", HTableNameConverter.toHBaseTableName(tablePrefix, resultTableId));
    Assert.assertEquals(getTableNameAsString(tableId), Bytes.toString(tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId).getTableDescriptor().getTableName().getName()));
    drop(tableId);
    tableId = TableId.from("myspace", "could.be.any.table.name");
    hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    createNamespace("myspace");
    create(tableId);
    resultTableId = getTableId("myspace", "could.be.any.table.name");
    Assert.assertEquals("cdap_myspace", resultTableId.getNamespace());
    Assert.assertEquals("could.be.any.table.name", HTableNameConverter.toHBaseTableName(tablePrefix, resultTableId));
    Assert.assertEquals(getTableNameAsString(hTableId), Bytes.toString(tableUtil.createTable(TEST_HBASE.getConfiguration(), hTableId).getTableDescriptor().getTableName().getName()));
    drop(tableId);
    deleteNamespace("myspace");
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 22 with HBaseTableUtil

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

the class AbstractHBaseTableUtilTest method getTableStats.

private HBaseTableUtil.TableStats getTableStats(String namespace, String tableName) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    // todo : should support custom table-prefix
    TableId tableId = tableUtil.createHTableId(new NamespaceId(namespace), tableName);
    Map<TableId, HBaseTableUtil.TableStats> statsMap = tableUtil.getTableStats(hAdmin);
    return statsMap.get(tableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 23 with HBaseTableUtil

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

the class AbstractHBaseTableUtilTest method create.

private void create(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId htableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder("d", hAdmin.getConfiguration());
    TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(htableId, cConf);
    tdBuilder.addColumnFamily(cfdBuilder.build());
    ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

Example 24 with HBaseTableUtil

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

the class AbstractHBaseTableUtilTest method testHTableDescriptor.

@Test
public void testHTableDescriptor() throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId tableId = TableId.from("default", "test.dataset");
    create(tableId);
    HTableDescriptor tableDescriptor = tableUtil.getHTableDescriptor(hAdmin, tableId);
    Assert.assertEquals(ProjectInfo.getVersion().toString(), tableDescriptor.getValue(HBaseTableUtil.CDAP_VERSION));
    Assert.assertEquals(getPrefix(), tableDescriptor.getValue(Constants.Dataset.TABLE_PREFIX));
    TableName tableName = HTableNameConverter.toTableName(getPrefix(), tableId);
    ddlExecutor.disableTableIfEnabled(tableName.getNamespaceAsString(), tableName.getQualifierAsString());
    tableUtil.deleteTable(ddlExecutor, tableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) TableName(org.apache.hadoop.hbase.TableName) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 25 with HBaseTableUtil

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

the class AbstractHBaseTableUtilTest method drop.

private void drop(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId hTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    tableUtil.dropTable(ddlExecutor, hTableId);
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) NamespaceId(io.cdap.cdap.proto.id.NamespaceId)

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