Search in sources :

Example 1 with InternalIngestException

use of ddf.catalog.source.InternalIngestException in project ddf by codice.

the class UpdateOperations method doUpdate.

//
// Private helper methods
//
private UpdateResponse doUpdate(UpdateRequest updateRequest) throws IngestException, SourceUnavailableException {
    updateRequest = queryOperations.setFlagsOnRequest(updateRequest);
    updateRequest = validateUpdateRequest(updateRequest);
    updateRequest = validateLocalSource(updateRequest);
    try {
        updateRequest = injectAttributes(updateRequest);
        updateRequest = setDefaultValues(updateRequest);
        updateRequest = populateMetacards(updateRequest);
        updateRequest = processPreAuthorizationPlugins(updateRequest);
        updateRequest = populateUpdateRequestPolicyMap(updateRequest);
        updateRequest = processPreUpdateAccessPlugins(updateRequest);
        updateRequest = processPreIngestPlugins(updateRequest);
        updateRequest = validateUpdateRequest(updateRequest);
        // Call the update on the catalog
        LOGGER.debug("Calling catalog.update() with {} updates.", updateRequest.getUpdates().size());
        UpdateResponse updateResponse = performLocalUpdate(updateRequest);
        updateResponse = performRemoteUpdate(updateRequest, updateResponse);
        // Handle the posting of messages to pubsub
        updateResponse = validateFixUpdateResponse(updateResponse, updateRequest);
        return updateResponse;
    } catch (StopProcessingException see) {
        throw new IngestException(PRE_INGEST_ERROR, see);
    } catch (RuntimeException re) {
        throw new InternalIngestException("Exception during runtime while performing update", re);
    }
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException)

Example 2 with InternalIngestException

use of ddf.catalog.source.InternalIngestException in project ddf by codice.

the class RESTEndpoint method addDocument.

/**
     * REST Post. Creates a new metadata entry in the catalog.
     *
     * @param message
     * @return
     */
@POST
@Consumes("multipart/*")
public Response addDocument(@Context HttpHeaders headers, @Context UriInfo requestUriInfo, @Context HttpServletRequest httpRequest, MultipartBody multipartBody, @QueryParam("transform") String transformerParam, InputStream message) {
    LOGGER.debug("POST");
    Response response;
    MimeType mimeType = getMimeType(headers);
    try {
        if (message != null) {
            CreateInfo createInfo = null;
            if (multipartBody != null) {
                List<Attachment> contentParts = multipartBody.getAllAttachments();
                if (contentParts != null && contentParts.size() > 0) {
                    createInfo = parseAttachments(contentParts, transformerParam);
                } else {
                    LOGGER.debug("No file contents attachment found");
                }
            }
            CreateResponse createResponse;
            if (createInfo == null) {
                CreateRequest createRequest = new CreateRequestImpl(generateMetacard(mimeType, null, message, transformerParam));
                createResponse = catalogFramework.create(createRequest);
            } else {
                CreateStorageRequest streamCreateRequest = new CreateStorageRequestImpl(Collections.singletonList(new IncomingContentItem(uuidGenerator, createInfo.getStream(), createInfo.getContentType(), createInfo.getFilename(), createInfo.getMetacard())), null);
                createResponse = catalogFramework.create(streamCreateRequest);
            }
            String id = createResponse.getCreatedMetacards().get(0).getId();
            LOGGER.debug("Create Response id [{}]", id);
            UriBuilder uriBuilder = requestUriInfo.getAbsolutePathBuilder().path("/" + id);
            ResponseBuilder responseBuilder = Response.created(uriBuilder.build());
            responseBuilder.header(Metacard.ID, id);
            response = responseBuilder.build();
            LOGGER.debug("Entry successfully saved, id: {}", id);
            if (INGEST_LOGGER.isInfoEnabled()) {
                INGEST_LOGGER.info("Entry successfully saved, id: {}", id);
            }
        } else {
            String errorMessage = "No content found, cannot do CREATE.";
            LOGGER.info(errorMessage);
            throw new ServerErrorException(errorMessage, Status.BAD_REQUEST);
        }
    } catch (SourceUnavailableException e) {
        String exceptionMessage = "Cannot create catalog entry because source is unavailable: ";
        LOGGER.info(exceptionMessage, e);
        // Catalog framework logs these exceptions to the ingest logger so we don't have to.
        throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
    } catch (InternalIngestException e) {
        String exceptionMessage = "Error while storing entry in catalog: ";
        LOGGER.info(exceptionMessage, e);
        // Catalog framework logs these exceptions to the ingest logger so we don't have to.
        throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
    } catch (MetacardCreationException | IngestException e) {
        String exceptionMessage = "Error while storing entry in catalog: ";
        LOGGER.info(exceptionMessage, e);
        // Catalog framework logs these exceptions to the ingest logger so we don't have to.
        throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
    } finally {
        IOUtils.closeQuietly(message);
    }
    return response;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) MetacardCreationException(ddf.catalog.data.MetacardCreationException) InternalIngestException(ddf.catalog.source.InternalIngestException) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) MimeType(javax.activation.MimeType) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) IngestException(ddf.catalog.source.IngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) UriBuilder(javax.ws.rs.core.UriBuilder) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 3 with InternalIngestException

use of ddf.catalog.source.InternalIngestException in project ddf by codice.

the class RESTEndpoint method deleteDocument.

/**
     * REST Delete. Deletes a record from the catalog.
     *
     * @param id
     * @return
     */
@DELETE
@Path("/{id}")
public Response deleteDocument(@PathParam("id") String id, @Context HttpServletRequest httpRequest) {
    LOGGER.debug("DELETE");
    Response response;
    try {
        if (id != null) {
            DeleteRequestImpl deleteReq = new DeleteRequestImpl(id);
            catalogFramework.delete(deleteReq);
            response = Response.ok(id).build();
            LOGGER.debug("Attempting to delete Metacard with id: {}", id);
        } else {
            String errorMessage = "ID of entry not specified, cannot do DELETE.";
            LOGGER.info(errorMessage);
            throw new ServerErrorException(errorMessage, Status.BAD_REQUEST);
        }
    } catch (SourceUnavailableException ce) {
        String exceptionMessage = "Could not delete entry from catalog since the source is unavailable: ";
        LOGGER.info(exceptionMessage, ce);
        throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
    } catch (InternalIngestException e) {
        String exceptionMessage = "Error deleting entry from catalog: ";
        LOGGER.info(exceptionMessage, e);
        throw new ServerErrorException(exceptionMessage, Status.INTERNAL_SERVER_ERROR);
    } catch (IngestException e) {
        String exceptionMessage = "Error deleting entry from catalog: ";
        LOGGER.info(exceptionMessage, e);
        throw new ServerErrorException(exceptionMessage, Status.BAD_REQUEST);
    }
    return response;
}
Also used : SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) InternalIngestException(ddf.catalog.source.InternalIngestException) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) IngestException(ddf.catalog.source.IngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 4 with InternalIngestException

use of ddf.catalog.source.InternalIngestException in project ddf by codice.

the class CreateOperations method doCreate.

//
// Private helper methods
//
private CreateResponse doCreate(CreateRequest createRequest) throws IngestException, SourceUnavailableException {
    CreateResponse createResponse = null;
    Exception ingestError = null;
    createRequest = queryOperations.setFlagsOnRequest(createRequest);
    createRequest = validateCreateRequest(createRequest);
    createRequest = validateLocalSource(createRequest);
    try {
        createRequest = injectAttributes(createRequest);
        createRequest = setDefaultValues(createRequest);
        createRequest = processPreAuthorizationPlugins(createRequest);
        createRequest = updateCreateRequestPolicyMap(createRequest);
        createRequest = processPrecreateAccessPlugins(createRequest);
        createRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.CREATE, Collections.emptyList()));
        createRequest = processPreIngestPlugins(createRequest);
        createRequest = validateCreateRequest(createRequest);
        createResponse = getCreateResponse(createRequest);
        createResponse = performRemoteCreate(createRequest, createResponse);
    } catch (IngestException iee) {
        INGEST_LOGGER.debug("Ingest error", iee);
        ingestError = iee;
        throw iee;
    } catch (StopProcessingException see) {
        ingestError = see;
        throw new IngestException(PRE_INGEST_ERROR, see);
    } catch (RuntimeException re) {
        ingestError = re;
        throw new InternalIngestException("Exception during runtime while performing create", re);
    } finally {
        if (ingestError != null && INGEST_LOGGER.isInfoEnabled()) {
            INGEST_LOGGER.info("Error on create operation. {} metacards failed to ingest. {}", createRequest.getMetacards().size(), buildIngestLog(createRequest), ingestError);
        }
    }
    try {
        createResponse = validateFixCreateResponse(createResponse, createRequest);
    } catch (RuntimeException re) {
        LOGGER.info("Exception during runtime while performing doing post create operations (plugins and pubsub)", re);
    }
    return createResponse;
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) InternalIngestException(ddf.catalog.source.InternalIngestException) CreateResponse(ddf.catalog.operation.CreateResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) StorageException(ddf.catalog.content.StorageException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) IOException(java.io.IOException)

Example 5 with InternalIngestException

use of ddf.catalog.source.InternalIngestException in project ddf by codice.

the class DeleteOperations method performLocalDelete.

private DeleteResponse performLocalDelete(DeleteRequest deleteRequest, DeleteStorageRequest deleteStorageRequest) throws IngestException {
    if (!Requests.isLocal(deleteRequest)) {
        return null;
    }
    try {
        sourceOperations.getStorage().delete(deleteStorageRequest);
    } catch (StorageException e) {
        LOGGER.info("Unable to delete stored content items. Not removing stored metacards", e);
        throw new InternalIngestException("Unable to delete stored content items. Not removing stored metacards.", e);
    }
    DeleteResponse deleteResponse = sourceOperations.getCatalog().delete(deleteRequest);
    deleteResponse = injectAttributes(deleteResponse);
    try {
        historian.version(deleteResponse);
    } catch (SourceUnavailableException e) {
        LOGGER.debug("Could not version deleted item!", e);
        throw new IngestException("Could not version deleted Item!");
    }
    return deleteResponse;
}
Also used : SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) DeleteResponse(ddf.catalog.operation.DeleteResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StorageException(ddf.catalog.content.StorageException)

Aggregations

IngestException (ddf.catalog.source.IngestException)7 InternalIngestException (ddf.catalog.source.InternalIngestException)7 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)5 CreateResponse (ddf.catalog.operation.CreateResponse)4 StorageException (ddf.catalog.content.StorageException)3 QueryResponse (ddf.catalog.operation.QueryResponse)3 SourceInfoResponse (ddf.catalog.operation.SourceInfoResponse)3 StopProcessingException (ddf.catalog.plugin.StopProcessingException)3 Response (javax.ws.rs.core.Response)3 MetacardCreationException (ddf.catalog.data.MetacardCreationException)2 DeleteResponse (ddf.catalog.operation.DeleteResponse)2 MimeType (javax.activation.MimeType)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)2 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 DeleteStorageRequest (ddf.catalog.content.operation.DeleteStorageRequest)1 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)1 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)1 DeleteStorageRequestImpl (ddf.catalog.content.operation.impl.DeleteStorageRequestImpl)1