use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class NoSqlStructuredTableAdmin method create.
@Override
public void create(StructuredTableSpecification spec) throws IOException, TableAlreadyExistsException {
if (exists(spec.getTableId())) {
throw new TableAlreadyExistsException(spec.getTableId());
}
LOG.info("Creating table {} in namespace {}", spec, NamespaceId.SYSTEM);
DatasetAdmin indexTableAdmin = indexTableDefinition.getAdmin(SYSTEM_CONTEXT, indexTableSpec, null);
if (!indexTableAdmin.exists()) {
LOG.info("Creating dataset indexed table {} in namespace {}", indexTableSpec.getName(), NamespaceId.SYSTEM);
indexTableAdmin.create();
}
registry.registerSpecification(spec);
}
use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class NoSqlStructuredTableAdmin method drop.
@Override
public void drop(StructuredTableId tableId) throws IOException {
LOG.info("Dropping table {} in namespace {}", tableId.getName(), NamespaceId.SYSTEM);
registry.removeSpecification(tableId);
if (registry.isEmpty()) {
DatasetAdmin admin = indexTableDefinition.getAdmin(SYSTEM_CONTEXT, indexTableSpec, null);
LOG.info("Dropping dataset indexed table {} in namespace {}", indexTableSpec.getName(), NamespaceId.SYSTEM);
admin.drop();
}
}
use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class CoreDatasetsModule method register.
@Override
public void register(DatasetDefinitionRegistry registry) {
DatasetDefinition<Table, DatasetAdmin> tableDef = registry.get("table");
DatasetDefinition<KeyValueTable, DatasetAdmin> kvTableDef = new KeyValueTableDefinition(KeyValueTable.TYPE, tableDef);
registry.add(kvTableDef);
registry.add(new KeyValueTableDefinition(KeyValueTable.class.getName(), tableDef));
DatasetDefinition<ObjectStore, DatasetAdmin> objectStoreDef = new ObjectStoreDefinition(ObjectStore.TYPE, kvTableDef);
registry.add(new ObjectStoreDefinition(ObjectStore.TYPE, kvTableDef));
registry.add(new ObjectStoreDefinition(ObjectStore.class.getName(), kvTableDef));
registry.add(new IndexedObjectStoreDefinition(IndexedObjectStore.TYPE, tableDef, objectStoreDef));
registry.add(new IndexedObjectStoreDefinition(IndexedObjectStore.class.getName(), tableDef, objectStoreDef));
registry.add(new IndexedTableDefinition(IndexedTable.TYPE, tableDef));
registry.add(new IndexedTableDefinition(IndexedTable.class.getName(), tableDef));
registry.add(new TimeseriesTableDefinition(TimeseriesTable.TYPE, tableDef));
registry.add(new TimeseriesTableDefinition(TimeseriesTable.class.getName(), tableDef));
registry.add(new CounterTimeseriesTableDefinition(CounterTimeseriesTable.TYPE, tableDef));
registry.add(new CounterTimeseriesTableDefinition(CounterTimeseriesTable.class.getName(), tableDef));
// in-memory table
registry.add(new InMemoryTableDefinition(InMemoryTable.TYPE));
}
use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class MetricHBaseTableUtilTest method testGetVersion.
@Test
public void testGetVersion() throws Exception {
// Verify new metric datasets are properly recognized as 2.8+ version from now on
HBaseMetricsTableDefinition definition = new HBaseMetricsTableDefinition("foo", TEST_HBASE.getConfiguration(), () -> hBaseTableUtil, new FileContextLocationFactory(TEST_HBASE.getConfiguration()), cConf);
DatasetSpecification spec = definition.configure("metricV2.8", DatasetProperties.EMPTY);
DatasetAdmin admin = definition.getAdmin(DatasetContext.from(NamespaceId.SYSTEM.getNamespace()), spec, null);
admin.create();
MetricHBaseTableUtil util = new MetricHBaseTableUtil(hBaseTableUtil);
HBaseAdmin hAdmin = TEST_HBASE.getHBaseAdmin();
TableId hTableId = hBaseTableUtil.createHTableId(NamespaceId.SYSTEM, spec.getName());
HTableDescriptor desc = hBaseTableUtil.getHTableDescriptor(hAdmin, hTableId);
desc.addFamily(new HColumnDescriptor("c"));
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_8_OR_HIGHER, util.getVersion(desc));
// Verify HBase table without coprocessor is properly recognized as 2.6- version
TableName table26 = TableName.valueOf("metricV2.6");
hAdmin.createTable(new HTableDescriptor(table26).addFamily(new HColumnDescriptor("c")));
desc = hAdmin.getTableDescriptor(table26);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_6_OR_LOWER, util.getVersion(desc));
// Verify HBase table with IncrementHandler coprocessor but without cdap.version on it is properly recognized as
// 2.7 version
TableName table27 = TableName.valueOf("metricV2.7");
desc = new HTableDescriptor(table27).addFamily(new HColumnDescriptor("c"));
desc.addCoprocessor(hBaseTableUtil.getIncrementHandlerClassForVersion().getName());
hAdmin.createTable(desc);
desc = hAdmin.getTableDescriptor(table27);
Assert.assertEquals(MetricHBaseTableUtil.Version.VERSION_2_7, util.getVersion(desc));
}
use of io.cdap.cdap.api.dataset.DatasetAdmin in project cdap by caskdata.
the class InMemoryDatasetOpExecutor method drop.
@Override
public void drop(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetSpecification spec) throws Exception {
DatasetType type = client.getDatasetType(typeMeta, null, new ConstantClassLoaderProvider());
if (type == null) {
throw new IllegalArgumentException("Dataset type cannot be instantiated for provided type meta: " + typeMeta);
}
DatasetAdmin admin = type.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec);
admin.drop();
}
Aggregations