use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.
the class HBaseStreamConsumerStateStoreFactory method create.
@Override
public synchronized StreamConsumerStateStore create(StreamConfig streamConfig) throws IOException {
NamespaceId namespace = streamConfig.getStreamId().getParent();
TableId streamStateStoreTableId = StreamUtils.getStateStoreTableId(namespace);
TableId hbaseTableId = tableUtil.createHTableId(new NamespaceId(streamStateStoreTableId.getNamespace()), streamStateStoreTableId.getTableName());
boolean tableExist;
try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
tableExist = tableUtil.tableExists(admin, hbaseTableId);
}
if (!tableExist) {
try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(hbaseTableId, cConf);
ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(QueueEntryRow.COLUMN_FAMILY), hConf);
tdBuilder.addColumnFamily(cfdBuilder.build());
ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
}
HTable hTable = tableUtil.createHTable(hConf, hbaseTableId);
hTable.setWriteBufferSize(Constants.Stream.HBASE_WRITE_BUFFER_SIZE);
hTable.setAutoFlushTo(false);
return new HBaseStreamConsumerStateStore(streamConfig, hTable);
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.
the class HBase10CDH550TableUpdater method createTableIfNotExists.
@Override
protected void createTableIfNotExists(Configuration conf) throws IOException {
try (HBaseAdmin admin = new HBaseAdmin(conf)) {
String tableName = StatusUtils.getReplicationStateTableName(conf);
if (admin.tableExists(tableName)) {
return;
}
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
htd.addFamily(new HColumnDescriptor(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY));
admin.createTable(htd);
LOG.info("Created Table {}.", tableName);
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.
the class HBaseQueueAdmin method upgradeQueues.
private Map<TableId, Future<?>> upgradeQueues(final NamespaceMeta namespaceMeta, ExecutorService executor) throws Exception {
try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
String hbaseNamespace = tableUtil.getHBaseNamespace(namespaceMeta);
List<TableId> tableIds = tableUtil.listTablesInNamespace(admin, hbaseNamespace);
List<TableId> stateStoreTableIds = Lists.newArrayList();
Map<TableId, Future<?>> futures = new HashMap<>();
for (final TableId tableId : tableIds) {
// It's important to skip config table enabled.
if (isDataTable(tableId)) {
Runnable runnable = new Runnable() {
public void run() {
try {
LOG.info("Upgrading queue table: {}", tableId);
Properties properties = new Properties();
HTableDescriptor desc = tableUtil.getHTableDescriptor(admin, tableId);
if (desc.getValue(HBaseQueueAdmin.PROPERTY_PREFIX_BYTES) == null) {
// It's the old queue table. Set the property prefix bytes to SALT_BYTES
properties.setProperty(HBaseQueueAdmin.PROPERTY_PREFIX_BYTES, Integer.toString(SaltedHBaseQueueStrategy.SALT_BYTES));
}
upgrade(tableId, properties);
LOG.info("Upgraded queue table: {}", tableId);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
Future<?> future = executor.submit(runnable);
futures.put(tableId, future);
} else if (isStateStoreTable(tableId)) {
stateStoreTableIds.add(tableId);
}
}
// Upgrade of state store table
for (final TableId tableId : stateStoreTableIds) {
Runnable runnable = new Runnable() {
public void run() {
try {
LOG.info("Upgrading queue state store: {}", tableId);
DatasetId stateStoreId = createStateStoreDataset(namespaceMeta.getName());
DatasetAdmin datasetAdmin = datasetFramework.getAdmin(stateStoreId, null);
if (datasetAdmin == null) {
LOG.error("No dataset admin available for {}", stateStoreId);
return;
}
datasetAdmin.upgrade();
LOG.info("Upgraded queue state store: {}", tableId);
} catch (Exception e) {
new RuntimeException(e);
}
}
};
Future<?> future = executor.submit(runnable);
futures.put(tableId, future);
}
return futures;
}
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.
the class AbstractHBaseTableUtilTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
hAdmin = new HBaseAdmin(TEST_HBASE.getConfiguration());
cConf = CConfiguration.create();
ddlExecutor = new HBaseDDLExecutorFactory(cConf, TEST_HBASE.getConfiguration()).get();
}
use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.
the class DistributedStorageProviderNamespaceAdmin method create.
@Override
public void create(NamespaceMeta namespaceMeta) throws IOException, ExploreException, SQLException {
// create filesystem directory
super.create(namespaceMeta);
// skip namespace creation in HBase for default namespace
if (NamespaceId.DEFAULT.equals(namespaceMeta.getNamespaceId())) {
return;
}
// create HBase namespace and set group C(reate) permission if a group is configured
String hbaseNamespace = tableUtil.getHBaseNamespace(namespaceMeta);
if (Strings.isNullOrEmpty(namespaceMeta.getConfig().getHbaseNamespace())) {
try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) {
boolean created = executor.createNamespaceIfNotExists(hbaseNamespace);
if (namespaceMeta.getConfig().getGroupName() != null) {
try {
executor.grantPermissions(hbaseNamespace, null, ImmutableMap.of("@" + namespaceMeta.getConfig().getGroupName(), "C"));
} catch (IOException | RuntimeException e) {
// don't leave a partial state behind, as this fails the create(), the namespace should be removed
if (created) {
try {
executor.deleteNamespaceIfExists(hbaseNamespace);
} catch (Throwable t) {
e.addSuppressed(t);
}
}
throw e;
}
}
} catch (Throwable t) {
try {
// if we failed to create a namespace in hbase then do clean up for above creations
super.delete(namespaceMeta.getNamespaceId());
} catch (Exception e) {
t.addSuppressed(e);
}
throw t;
}
}
try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
if (!tableUtil.hasNamespace(admin, hbaseNamespace)) {
throw new IOException(String.format("HBase namespace '%s' specified for new namespace '%s' does not" + " exist. Please specify an existing HBase namespace.", hbaseNamespace, namespaceMeta.getName()));
}
}
}
Aggregations