use of co.cask.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.
the class HBaseDDLExecutorFactory method get.
@Override
public HBaseDDLExecutor get() {
// Check if HBaseDDLExecutor extension is provided
Map<String, HBaseDDLExecutor> extensions = hBaseDDLExecutorLoader.getAll();
HBaseDDLExecutor executor;
if (!extensions.isEmpty()) {
// HBase DDL executor extension is provided.
executor = extensions.values().iterator().next();
} else {
if (extensionDir != null) {
// Extension directory is provided but the extension is not loaded
throw new RuntimeException(String.format("HBaseDDLExecutor extension cannot be loaded from directory '%s'." + " Please make sure jar is available at that location with " + "appropriate permissions.", extensionDir));
}
// Return the version specific executor instance.
executor = super.get();
}
executor.initialize(context);
return executor;
}
use of co.cask.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.
the class MetricHBaseTableUtilTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
cConf = CConfiguration.create();
hBaseTableUtil = new HBaseTableUtilFactory(cConf, new SimpleNamespaceQueryAdmin()).get();
HBaseDDLExecutor executor = new HBaseDDLExecutorFactory(cConf, TEST_HBASE.getHBaseAdmin().getConfiguration()).get();
executor.createNamespaceIfNotExists(hBaseTableUtil.getHBaseNamespace(NamespaceId.SYSTEM));
}
use of co.cask.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.
the class HBaseStreamConsumerStateStoreFactory method dropAllInNamespace.
@Override
public synchronized void dropAllInNamespace(NamespaceId namespace) throws IOException {
try (HBaseDDLExecutor executor = ddlExecutorFactory.get();
HBaseAdmin admin = new HBaseAdmin(hConf)) {
TableId tableId = StreamUtils.getStateStoreTableId(namespace);
TableId hbaseTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
if (tableUtil.tableExists(admin, hbaseTableId)) {
tableUtil.dropTable(executor, hbaseTableId);
}
}
}
use of co.cask.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.
the class DistributedStorageProviderNamespaceAdmin method delete.
@SuppressWarnings("ConstantConditions")
@Override
public void delete(NamespaceId namespaceId) throws IOException, ExploreException, SQLException {
// delete namespace directory from filesystem
super.delete(namespaceId);
if (NamespaceId.DEFAULT.equals(namespaceId)) {
return;
}
// delete HBase namespace
NamespaceConfig namespaceConfig;
try {
namespaceConfig = namespaceQueryAdmin.get(namespaceId).getConfig();
} catch (Exception ex) {
throw new IOException("Could not fetch custom HBase mapping.", ex);
}
if (!Strings.isNullOrEmpty(namespaceConfig.getHbaseNamespace())) {
// custom namespace mapping is set for HBase, hence don't do anything during delete since the lifecycle of the
// namespace will be managed by the user
LOG.debug("Custom HBase mapping {} was found while deleting {}. Hence skipping deletion of HBase namespace", namespaceConfig.getHbaseNamespace(), namespaceId);
return;
}
// delete HBase namespace
String namespace = tableUtil.getHBaseNamespace(namespaceId);
try (HBaseDDLExecutor executor = hBaseDDLExecutorFactory.get()) {
executor.deleteNamespaceIfExists(namespace);
}
}
use of co.cask.cdap.spi.hbase.HBaseDDLExecutor in project cdap by caskdata.
the class HBaseQueueAdmin method dropAllInNamespace.
@Override
public void dropAllInNamespace(NamespaceId namespaceId) throws Exception {
Set<QueueConstants.QueueType> queueTypes = EnumSet.of(QueueConstants.QueueType.QUEUE, QueueConstants.QueueType.SHARDED_QUEUE);
try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
for (QueueConstants.QueueType queueType : queueTypes) {
// Note: The trailing "." is crucial, since otherwise nsId could match nsId1, nsIdx etc
// It's important to keep config table enabled while disabling and dropping queue tables.
final String queueTableNamePrefix = String.format("%s.%s.", NamespaceId.SYSTEM.getNamespace(), queueType);
final String hbaseNamespace = tableUtil.getHBaseNamespace(namespaceId);
final TableId configTableId = TableId.from(hbaseNamespace, getConfigTableName());
tableUtil.deleteAllInNamespace(ddlExecutor, hbaseNamespace, hConf, new Predicate<TableId>() {
@Override
public boolean apply(TableId tableId) {
// It's a bit hacky here since we know how the Dataset System names tables
return (tableId.getTableName().startsWith(queueTableNamePrefix)) && !tableId.equals(configTableId);
}
});
}
}
// Delete the state store in the namespace
DatasetId id = getStateStoreId(namespaceId.getEntityName());
if (datasetFramework.hasInstance(id)) {
datasetFramework.deleteInstance(id);
}
}
Aggregations