Search in sources :

Example 1 with InstanceNotFoundException

use of co.cask.cdap.api.dataset.InstanceNotFoundException 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(co.cask.cdap.api.dataset.DatasetManagementException) InstanceConflictException(co.cask.cdap.api.dataset.InstanceConflictException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) Updatable(co.cask.cdap.api.dataset.Updatable) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) DatasetAdmin(co.cask.cdap.api.dataset.DatasetAdmin) AbstractDatasetDefinition(co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition) IncompatibleUpdateException(co.cask.cdap.api.dataset.IncompatibleUpdateException)

Example 2 with InstanceNotFoundException

use of co.cask.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(co.cask.cdap.api.dataset.DatasetManagementException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) AbstractDatasetDefinition(co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition)

Example 3 with InstanceNotFoundException

use of co.cask.cdap.api.dataset.InstanceNotFoundException 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(co.cask.cdap.api.dataset.DatasetManagementException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) DatasetSpecification(co.cask.cdap.api.dataset.DatasetSpecification) AbstractDatasetDefinition(co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition) DatasetDefinition(co.cask.cdap.api.dataset.DatasetDefinition)

Example 4 with InstanceNotFoundException

use of co.cask.cdap.api.dataset.InstanceNotFoundException in project cdap by caskdata.

the class WorkflowHttpHandler method deleteWorkflowLocalDatasets.

@DELETE
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/localdatasets")
public void deleteWorkflowLocalDatasets(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException {
    WorkflowSpecification workflowSpec = getWorkflowSpecForValidRun(namespaceId, applicationId, workflowId, runId);
    Set<String> errorOnDelete = new HashSet<>();
    for (Map.Entry<String, DatasetCreationSpec> localDatasetEntry : workflowSpec.getLocalDatasetSpecs().entrySet()) {
        String mappedDatasetName = localDatasetEntry.getKey() + "." + runId;
        // try best to delete the local datasets.
        try {
            datasetFramework.deleteInstance(new DatasetId(namespaceId, mappedDatasetName));
        } catch (InstanceNotFoundException e) {
        // Dataset instance is already deleted. so its no-op.
        } catch (Throwable t) {
            errorOnDelete.add(mappedDatasetName);
            LOG.error("Failed to delete the Workflow local dataset {}. Reason - {}", mappedDatasetName, t.getMessage());
        }
    }
    if (errorOnDelete.isEmpty()) {
        responder.sendStatus(HttpResponseStatus.OK);
        return;
    }
    String errorMessage = "Failed to delete Workflow local datasets - " + Joiner.on(",").join(errorOnDelete);
    throw new RuntimeException(errorMessage);
}
Also used : InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) DatasetCreationSpec(co.cask.cdap.internal.dataset.DatasetCreationSpec) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) DatasetId(co.cask.cdap.proto.id.DatasetId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with InstanceNotFoundException

use of co.cask.cdap.api.dataset.InstanceNotFoundException in project cdap by caskdata.

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(co.cask.cdap.api.dataset.InstanceNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) Test(org.junit.Test)

Aggregations

InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)6 DatasetDefinition (co.cask.cdap.api.dataset.DatasetDefinition)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 DatasetSpecification (co.cask.cdap.api.dataset.DatasetSpecification)3 AbstractDatasetDefinition (co.cask.cdap.api.dataset.lib.AbstractDatasetDefinition)3 HashSet (java.util.HashSet)2 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)1 IncompatibleUpdateException (co.cask.cdap.api.dataset.IncompatibleUpdateException)1 InstanceConflictException (co.cask.cdap.api.dataset.InstanceConflictException)1 Updatable (co.cask.cdap.api.dataset.Updatable)1 PartitionedFileSet (co.cask.cdap.api.dataset.lib.PartitionedFileSet)1 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)1 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)1 RunRecord (co.cask.cdap.proto.RunRecord)1 DatasetId (co.cask.cdap.proto.id.DatasetId)1 MapReduceManager (co.cask.cdap.test.MapReduceManager)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1