use of co.cask.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);
}
use of co.cask.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 co.cask.cdap.api.dataset.DatasetDefinition in project cdap by caskdata.
the class InMemoryDatasetFramework method addInstance.
@Override
public void addInstance(String datasetType, DatasetId datasetInstanceId, DatasetProperties props) throws DatasetManagementException, IOException {
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 co.cask.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();
}
}
use of co.cask.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();
}
}
Aggregations