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();
}
}
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();
}
}
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);
}
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));
}
Aggregations