Search in sources :

Example 1 with DatasetAdmin

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);
}
Also used : TableAlreadyExistsException(io.cdap.cdap.spi.data.TableAlreadyExistsException) DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin)

Example 2 with DatasetAdmin

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();
    }
}
Also used : DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin)

Example 3 with DatasetAdmin

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));
}
Also used : ObjectStore(io.cdap.cdap.api.dataset.lib.ObjectStore) IndexedObjectStore(io.cdap.cdap.api.dataset.lib.IndexedObjectStore) Table(io.cdap.cdap.api.dataset.table.Table) InMemoryTable(io.cdap.cdap.data2.dataset2.lib.table.inmemory.InMemoryTable) CounterTimeseriesTable(io.cdap.cdap.api.dataset.lib.CounterTimeseriesTable) TimeseriesTable(io.cdap.cdap.api.dataset.lib.TimeseriesTable) IndexedTable(io.cdap.cdap.api.dataset.lib.IndexedTable) KeyValueTable(io.cdap.cdap.api.dataset.lib.KeyValueTable) DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin) InMemoryTableDefinition(io.cdap.cdap.data2.dataset2.lib.table.inmemory.InMemoryTableDefinition) CounterTimeseriesTableDefinition(io.cdap.cdap.api.dataset.lib.CounterTimeseriesTableDefinition) IndexedTableDefinition(io.cdap.cdap.api.dataset.lib.IndexedTableDefinition) KeyValueTable(io.cdap.cdap.api.dataset.lib.KeyValueTable) IndexedObjectStoreDefinition(io.cdap.cdap.api.dataset.lib.IndexedObjectStoreDefinition) KeyValueTableDefinition(io.cdap.cdap.api.dataset.lib.KeyValueTableDefinition) IndexedObjectStoreDefinition(io.cdap.cdap.api.dataset.lib.IndexedObjectStoreDefinition) TimeseriesTableDefinition(io.cdap.cdap.api.dataset.lib.TimeseriesTableDefinition) CounterTimeseriesTableDefinition(io.cdap.cdap.api.dataset.lib.CounterTimeseriesTableDefinition)

Example 4 with DatasetAdmin

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));
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) TableName(org.apache.hadoop.hbase.TableName) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 5 with DatasetAdmin

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();
}
Also used : ConstantClassLoaderProvider(io.cdap.cdap.data2.datafabric.dataset.type.ConstantClassLoaderProvider) DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin) DatasetType(io.cdap.cdap.data2.datafabric.dataset.DatasetType)

Aggregations

DatasetAdmin (io.cdap.cdap.api.dataset.DatasetAdmin)56 Test (org.junit.Test)30 Table (io.cdap.cdap.api.dataset.table.Table)27 Transaction (org.apache.tephra.Transaction)27 TransactionAware (org.apache.tephra.TransactionAware)23 HBaseTable (io.cdap.cdap.data2.dataset2.lib.table.hbase.HBaseTable)21 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)10 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)8 Get (io.cdap.cdap.api.dataset.table.Get)8 Put (io.cdap.cdap.api.dataset.table.Put)7 Row (io.cdap.cdap.api.dataset.table.Row)6 IOException (java.io.IOException)6 TransactionConflictException (org.apache.tephra.TransactionConflictException)5 Updatable (io.cdap.cdap.api.dataset.Updatable)4 Scan (io.cdap.cdap.api.dataset.table.Scan)4 DatasetType (io.cdap.cdap.data2.datafabric.dataset.DatasetType)4 BufferingTableTest (io.cdap.cdap.data2.dataset2.lib.table.BufferingTableTest)4 AbstractModule (com.google.inject.AbstractModule)3 TypeLiteral (com.google.inject.TypeLiteral)3 DatasetContext (io.cdap.cdap.api.dataset.DatasetContext)3