Search in sources :

Example 6 with InstanceNotFoundException

use of io.cdap.cdap.api.dataset.InstanceNotFoundException in project cdap by cdapio.

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 7 with InstanceNotFoundException

use of io.cdap.cdap.api.dataset.InstanceNotFoundException in project cdap by cdapio.

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 8 with InstanceNotFoundException

use of io.cdap.cdap.api.dataset.InstanceNotFoundException in project cdap by cdapio.

the class BasicThrowableCodecTest method testCodec.

@Test
public void testCodec() {
    testCodec(new InstanceNotFoundException("myInstance"));
    testCodec(new IllegalArgumentException());
    testCodec(new NullPointerException());
    testCodec(new Exception(new RuntimeException("some error")));
}
Also used : InstanceNotFoundException(io.cdap.cdap.api.dataset.InstanceNotFoundException) InstanceNotFoundException(io.cdap.cdap.api.dataset.InstanceNotFoundException) Test(org.junit.Test)

Example 9 with InstanceNotFoundException

use of io.cdap.cdap.api.dataset.InstanceNotFoundException 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 10 with InstanceNotFoundException

use of io.cdap.cdap.api.dataset.InstanceNotFoundException in project cdap by cdapio.

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

InstanceNotFoundException (io.cdap.cdap.api.dataset.InstanceNotFoundException)12 DatasetDefinition (io.cdap.cdap.api.dataset.DatasetDefinition)6 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)6 DatasetSpecification (io.cdap.cdap.api.dataset.DatasetSpecification)6 AbstractDatasetDefinition (io.cdap.cdap.api.dataset.lib.AbstractDatasetDefinition)6 DatasetAdmin (io.cdap.cdap.api.dataset.DatasetAdmin)2 IncompatibleUpdateException (io.cdap.cdap.api.dataset.IncompatibleUpdateException)2 InstanceConflictException (io.cdap.cdap.api.dataset.InstanceConflictException)2 Updatable (io.cdap.cdap.api.dataset.Updatable)2 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)2 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)2 DatasetCreationSpec (io.cdap.cdap.internal.dataset.DatasetCreationSpec)2 DatasetId (io.cdap.cdap.proto.id.DatasetId)2 MapReduceManager (io.cdap.cdap.test.MapReduceManager)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Writer (java.io.Writer)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2