Search in sources :

Example 11 with DatasetDefinition

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

the class InMemoryDatasetFramework method deleteInstance.

@Override
public void deleteInstance(DatasetId instanceId) throws DatasetManagementException, IOException {
    writeLock.lock();
    try {
        DatasetSpecification spec = instances.remove(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).drop();
        publishAudit(instanceId, AuditType.DELETE);
    } 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)

Example 12 with DatasetDefinition

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

the class InMemoryDatasetFramework method addInstance.

@Override
public void addInstance(String datasetType, DatasetId datasetInstanceId, DatasetProperties props, @Nullable KerberosPrincipalId ownerPrincipal) throws DatasetManagementException, IOException {
    if (ownerPrincipal != null) {
        throw new UnsupportedOperationException("Creating dataset with owner is not supported");
    }
    writeLock.lock();
    try {
        if (instances.contains(datasetInstanceId.getParent(), datasetInstanceId)) {
            throw new InstanceConflictException(String.format("Dataset instance '%s' already exists.", datasetInstanceId));
        }
        DatasetDefinition def = getDefinitionForType(datasetInstanceId.getParent(), datasetType);
        if (def == null) {
            throw new DatasetManagementException(String.format("Dataset type '%s' is neither registered in the '%s' namespace nor in the system namespace", datasetType, datasetInstanceId.getParent()));
        }
        DatasetSpecification spec = def.configure(datasetInstanceId.getEntityName(), props);
        spec = spec.setOriginalProperties(props);
        if (props.getDescription() != null) {
            spec = spec.setDescription(props.getDescription());
        }
        def.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec, null).create();
        instances.put(datasetInstanceId.getParent(), datasetInstanceId, spec);
        publishAudit(datasetInstanceId, AuditType.CREATE);
        LOG.info("Created dataset {} of type {}", datasetInstanceId, datasetType);
    } finally {
        writeLock.unlock();
    }
}
Also used : DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) InstanceConflictException(io.cdap.cdap.api.dataset.InstanceConflictException) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetDefinition(io.cdap.cdap.api.dataset.DatasetDefinition) AbstractDatasetDefinition(io.cdap.cdap.api.dataset.lib.AbstractDatasetDefinition)

Example 13 with DatasetDefinition

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

the class TestDatasetModule method register.

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

Example 14 with DatasetDefinition

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

the class DatasetDefinitionRegistryWithDefaultModules method testPFSReconfigure.

@Test
public void testPFSReconfigure() throws IncompatibleUpdateException {
    DatasetDefinition pfsDef = registry.get(PartitionedFileSet.class.getName());
    Assert.assertTrue(pfsDef instanceof Reconfigurable);
    DatasetProperties props = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addIntField("i").addStringField("s").build()).build();
    DatasetSpecification spec = pfsDef.configure("pfs", props);
    DatasetProperties noIprops = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).build();
    try {
        ((Reconfigurable) pfsDef).reconfigure("pfs", noIprops, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    DatasetProperties longIprops = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addLongField("i").addStringField("s").build()).build();
    try {
        ((Reconfigurable) pfsDef).reconfigure("pfs", longIprops, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    DatasetProperties revProps = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").addIntField("i").build()).build();
    try {
        ((Reconfigurable) pfsDef).reconfigure("pfs", revProps, spec);
        Assert.fail("reconfigure should have thrown exception");
    } catch (IncompatibleUpdateException e) {
    // expected
    }
    // test reconfiguring a PFS created before CDAP-13120, with no defaulted base path
    // no base path should be set for the reconfigured dataset either
    DatasetProperties oldProps = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).add(PartitionedFileSetDefinition.NAME_AS_BASE_PATH_DEFAULT, "false").build();
    DatasetSpecification oldSpec = pfsDef.configure("pfs", oldProps);
    DatasetSpecification newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", oldProps, oldSpec);
    // make sure base path is not set
    Assert.assertNull(newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
    // test reconfiguring a PFS created after CDAP-13120, where base path is default to the dataset name
    props = PartitionedFileSetProperties.builder().setPartitioning(Partitioning.builder().addStringField("s").build()).build();
    oldSpec = pfsDef.configure("pfs", props);
    newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", props, oldSpec);
    // make sure base path is similarly set, even when not explicitly given
    Assert.assertEquals("pfs", newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
    // make sure it is set for subsequent reconfigures as well
    newSpec = ((Reconfigurable) pfsDef).reconfigure("pfs", props, oldSpec);
    // make sure base path is similarly set, even when not explicitly given
    Assert.assertEquals("pfs", newSpec.getSpecification("files").getProperty(FileSetProperties.BASE_PATH));
}
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)

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