Search in sources :

Example 11 with HBaseDDLExecutor

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;
}
Also used : HBaseDDLExecutor(co.cask.cdap.spi.hbase.HBaseDDLExecutor)

Example 12 with HBaseDDLExecutor

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));
}
Also used : HBaseDDLExecutor(co.cask.cdap.spi.hbase.HBaseDDLExecutor) SimpleNamespaceQueryAdmin(co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin) HBaseDDLExecutorFactory(co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory) HBaseTableUtilFactory(co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory) BeforeClass(org.junit.BeforeClass)

Example 13 with HBaseDDLExecutor

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);
        }
    }
}
Also used : HBaseDDLExecutor(co.cask.cdap.spi.hbase.HBaseDDLExecutor) TableId(co.cask.cdap.data2.util.TableId) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 14 with HBaseDDLExecutor

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);
    }
}
Also used : NamespaceConfig(co.cask.cdap.proto.NamespaceConfig) HBaseDDLExecutor(co.cask.cdap.spi.hbase.HBaseDDLExecutor) IOException(java.io.IOException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ExploreException(co.cask.cdap.explore.service.ExploreException)

Example 15 with HBaseDDLExecutor

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);
    }
}
Also used : HBaseDDLExecutor(co.cask.cdap.spi.hbase.HBaseDDLExecutor) TableId(co.cask.cdap.data2.util.TableId) QueueConstants(co.cask.cdap.data2.transaction.queue.QueueConstants) DatasetId(co.cask.cdap.proto.id.DatasetId)

Aggregations

HBaseDDLExecutor (co.cask.cdap.spi.hbase.HBaseDDLExecutor)15 TableId (co.cask.cdap.data2.util.TableId)7 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)7 ColumnFamilyDescriptorBuilder (co.cask.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder)5 TableDescriptorBuilder (co.cask.cdap.data2.util.hbase.TableDescriptorBuilder)5 IOException (java.io.IOException)5 HTable (org.apache.hadoop.hbase.client.HTable)5 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 NamespaceId (co.cask.cdap.proto.id.NamespaceId)3 ProjectInfo (co.cask.cdap.common.utils.ProjectInfo)2 ExploreException (co.cask.cdap.explore.service.ExploreException)2 RowKeyDistributorByHashPrefix (co.cask.cdap.hbase.wd.RowKeyDistributorByHashPrefix)2 SQLException (java.sql.SQLException)2 Map (java.util.Map)2 SimpleNamespaceQueryAdmin (co.cask.cdap.common.namespace.SimpleNamespaceQueryAdmin)1 QueueConstants (co.cask.cdap.data2.transaction.queue.QueueConstants)1 HBaseDDLExecutorFactory (co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory)1 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)1 HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)1