Search in sources :

Example 1 with DatasetDefinition

use of io.cdap.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class PrefixedTable method register.

@Override
public void register(DatasetDefinitionRegistry registry) {
    DatasetDefinition<KeyValueTable, DatasetAdmin> kvTableDef = registry.get("keyValueTable");
    DatasetDefinition definition = new PrefixedTableDefinition("prefixedTable", kvTableDef);
    registry.add(definition);
}
Also used : DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition)

Example 2 with DatasetDefinition

use of io.cdap.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class DatasetDefinitionRegistryWithDefaultModules method testIndexedTableReconfigure.

@Test
public void testIndexedTableReconfigure() throws IncompatibleUpdateException {
    DatasetDefinition indexedTableDef = registry.get(IndexedTable.class.getName());
    Assert.assertTrue(indexedTableDef instanceof Reconfigurable);
    DatasetProperties props = TableProperties.builder().setReadlessIncrementSupport(false).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "a,b,c").build();
    DatasetSpecification spec = indexedTableDef.configure("idxtb", props);
    DatasetProperties compat = TableProperties.builder().setReadlessIncrementSupport(// turning on is ok
    true).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "c,b,a").build();
    spec = ((Reconfigurable) indexedTableDef).reconfigure("idxtb", compat, spec);
    DatasetProperties incompat = TableProperties.builder().setReadlessIncrementSupport(true).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "a,d").build();
    try {
        ((Reconfigurable) indexedTableDef).reconfigure("idxtb", incompat, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    incompat = TableProperties.builder().setReadlessIncrementSupport(// turning off is not ok
    false).add(IndexedTable.INDEX_COLUMNS_CONF_KEY, "a,b,c").build();
    try {
        ((Reconfigurable) indexedTableDef).reconfigure("idxtb", incompat, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
}
Also used : DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition) Reconfigurable(io.cdap.cdap.api.dataset.Reconfigurable) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Test(org.junit.Test)

Example 3 with DatasetDefinition

use of io.cdap.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class DatasetsUtilTest method testFix.

private void testFix(String type, DatasetProperties props) {
    DatasetDefinition def = DatasetFrameworkTestUtil.getDatasetDefinition(inMemoryDatasetFramework, NamespaceId.DEFAULT, type);
    Assert.assertNotNull(def);
    DatasetSpecification spec = def.configure("nn", props);
    Map<String, String> originalProperties = DatasetsUtil.fixOriginalProperties(spec).getOriginalProperties();
    Assert.assertEquals(props.getProperties(), originalProperties);
}
Also used : DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition)

Example 4 with DatasetDefinition

use of io.cdap.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class InMemoryDatasetFramework method updateInstance.

@Override
public void updateInstance(DatasetId datasetInstanceId, DatasetProperties props) throws DatasetManagementException, IOException {
    writeLock.lock();
    try {
        DatasetSpecification oldSpec = instances.get(datasetInstanceId.getParent(), datasetInstanceId);
        if (oldSpec == null) {
            throw new InstanceNotFoundException(datasetInstanceId.getEntityName());
        }
        DatasetDefinition def = getDefinitionForType(datasetInstanceId.getParent(), oldSpec.getType());
        if (def == null) {
            throw new DatasetManagementException(String.format("Dataset type '%s' is neither registered in the '%s' namespace nor in the system namespace", oldSpec.getType(), datasetInstanceId.getParent()));
        }
        DatasetSpecification spec = AbstractDatasetDefinition.reconfigure(def, datasetInstanceId.getEntityName(), props, oldSpec).setOriginalProperties(props);
        if (props.getDescription() != null) {
            spec = spec.setDescription(props.getDescription());
        }
        instances.put(datasetInstanceId.getParent(), datasetInstanceId, spec);
        DatasetAdmin admin = def.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec, null);
        if (admin instanceof Updatable) {
            ((Updatable) admin).update(oldSpec);
        } else {
            admin.upgrade();
        }
        publishAudit(datasetInstanceId, AuditType.UPDATE);
    } catch (IncompatibleUpdateException e) {
        throw new InstanceConflictException("Update failed for dataset instance " + datasetInstanceId, e);
    } finally {
        writeLock.unlock();
    }
}
Also used : DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) InstanceConflictException(io.cdap.cdap.api.dataset.InstanceConflictException) InstanceNotFoundException(io.cdap.cdap.api.dataset.InstanceNotFoundException) Updatable(io.cdap.cdap.api.dataset.Updatable) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetAdmin(io.cdap.cdap.api.dataset.DatasetAdmin) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition) AbstractDatasetDefinition(io.cdap.cdap.api.dataset.lib.AbstractDatasetDefinition) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException)

Example 5 with DatasetDefinition

use of io.cdap.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.

the class InMemoryDatasetFramework method truncateInstance.

@Override
public void truncateInstance(DatasetId instanceId) throws DatasetManagementException, IOException {
    writeLock.lock();
    try {
        DatasetSpecification spec = instances.get(instanceId.getParent(), instanceId);
        if (spec == null) {
            throw new InstanceNotFoundException(instanceId.getEntityName());
        }
        DatasetDefinition def = getDefinitionForType(instanceId.getParent(), spec.getType());
        if (def == null) {
            throw new DatasetManagementException(String.format("Dataset type '%s' is neither registered in the '%s' namespace nor in the system namespace", spec.getType(), instanceId.getParent()));
        }
        def.getAdmin(DatasetContext.from(instanceId.getNamespace()), spec, null).truncate();
        publishAudit(instanceId, AuditType.TRUNCATE);
    } finally {
        writeLock.unlock();
    }
}
Also used : DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) InstanceNotFoundException(io.cdap.cdap.api.dataset.InstanceNotFoundException) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition) AbstractDatasetDefinition(io.cdap.cdap.api.dataset.lib.AbstractDatasetDefinition)

Aggregations

DatasetDefinition (io.cdap.cdap.api.dataset.DatasetDefinition)14 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)11 AbstractDatasetDefinition (io.cdap.cdap.api.dataset.lib.AbstractDatasetDefinition)7 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)5 DatasetAdmin (io.cdap.cdap.api.dataset.DatasetAdmin)3 IncompatibleUpdateException (io.cdap.cdap.api.dataset.IncompatibleUpdateException)3 InstanceNotFoundException (io.cdap.cdap.api.dataset.InstanceNotFoundException)3 DatasetContext (io.cdap.cdap.api.dataset.DatasetContext)2 DatasetProperties (io.cdap.cdap.api.dataset.DatasetProperties)2 InstanceConflictException (io.cdap.cdap.api.dataset.InstanceConflictException)2 Reconfigurable (io.cdap.cdap.api.dataset.Reconfigurable)2 Nullable (javax.annotation.Nullable)2 Test (org.junit.Test)2 Dataset (io.cdap.cdap.api.dataset.Dataset)1 Updatable (io.cdap.cdap.api.dataset.Updatable)1 CompositeDatasetDefinition (io.cdap.cdap.api.dataset.lib.CompositeDatasetDefinition)1 IndexedTableDefinition (io.cdap.cdap.api.dataset.lib.IndexedTableDefinition)1 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)1 DatasetType (io.cdap.cdap.api.dataset.module.DatasetType)1 EmbeddedDataset (io.cdap.cdap.api.dataset.module.EmbeddedDataset)1