Search in sources :

Example 21 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.

the class ConfigurationWriter method createTableIfNecessary.

/**
 * Creates the configuration HBase table if it does not exist.
 */
@VisibleForTesting
void createTableIfNecessary() throws IOException {
    try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) {
        HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
        TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, TABLE_NAME);
        ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(FAMILY), hConf);
        TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
        ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
    }
}
Also used : HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) TableId(io.cdap.cdap.data2.util.TableId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 22 with HBaseDDLExecutor

use of io.cdap.cdap.spi.hbase.HBaseDDLExecutor in project cdap by cdapio.

the class HBaseTableFactory method createMetadataTable.

@Override
public MetadataTable createMetadataTable() throws IOException {
    TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, metadataTableName);
    Table table = null;
    // If the table descriptor is in the cache, we assume the table exists.
    if (!tableDescriptors.containsKey(tableId)) {
        synchronized (this) {
            if (!tableDescriptors.containsKey(tableId)) {
                try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
                    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf);
                    TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build());
                    ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
                    table = tableUtil.createTable(hConf, tableId);
                    tableDescriptors.put(tableId, table.getTableDescriptor());
                }
            }
        }
    }
    if (table == null) {
        table = tableUtil.createTable(hConf, tableId);
    }
    return new HBaseMetadataTable(tableUtil, table, COLUMN_FAMILY, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId));
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) HBaseDDLExecutor(io.cdap.cdap.spi.hbase.HBaseDDLExecutor) MetadataTable(io.cdap.cdap.messaging.store.MetadataTable) MessageTable(io.cdap.cdap.messaging.store.MessageTable) PayloadTable(io.cdap.cdap.messaging.store.PayloadTable) Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptorBuilder(io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder) HTableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder) TableDescriptorBuilder(io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder)

Aggregations

HBaseDDLExecutor (io.cdap.cdap.spi.hbase.HBaseDDLExecutor)22 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)10 IOException (java.io.IOException)8 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)8 TableId (io.cdap.cdap.data2.util.TableId)6 ColumnFamilyDescriptorBuilder (io.cdap.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder)6 TableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.TableDescriptorBuilder)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 ProjectInfo (io.cdap.cdap.common.utils.ProjectInfo)4 ExploreException (io.cdap.cdap.explore.service.ExploreException)4 MessageTable (io.cdap.cdap.messaging.store.MessageTable)4 MetadataTable (io.cdap.cdap.messaging.store.MetadataTable)4 PayloadTable (io.cdap.cdap.messaging.store.PayloadTable)4 SQLException (java.sql.SQLException)4 Map (java.util.Map)4 Table (org.apache.hadoop.hbase.client.Table)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 SimpleNamespaceQueryAdmin (io.cdap.cdap.common.namespace.SimpleNamespaceQueryAdmin)2 HBaseDDLExecutorFactory (io.cdap.cdap.data2.util.hbase.HBaseDDLExecutorFactory)2 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)2