Search in sources :

Example 76 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class StandardFlowFileQueue method createDropEvent.

private ProvenanceEventRecord createDropEvent(final FlowFileRecord flowFile, final String requestor) {
    final ProvenanceEventBuilder builder = provRepository.eventBuilder();
    builder.fromFlowFile(flowFile);
    builder.setEventType(ProvenanceEventType.DROP);
    builder.setLineageStartDate(flowFile.getLineageStartDate());
    builder.setComponentId(getIdentifier());
    builder.setComponentType("Connection");
    builder.setAttributes(flowFile.getAttributes(), Collections.<String, String>emptyMap());
    builder.setDetails("FlowFile Queue emptied by " + requestor);
    builder.setSourceQueueIdentifier(getIdentifier());
    final ContentClaim contentClaim = flowFile.getContentClaim();
    if (contentClaim != null) {
        final ResourceClaim resourceClaim = contentClaim.getResourceClaim();
        builder.setPreviousContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), contentClaim.getOffset(), flowFile.getSize());
    }
    return builder.build();
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) ProvenanceEventBuilder(org.apache.nifi.provenance.ProvenanceEventBuilder)

Example 77 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class FlowController method getContent.

public InputStream getContent(final ProvenanceEventRecord provEvent, final ContentDirection direction, final String requestor, final String requestUri) throws IOException {
    requireNonNull(provEvent);
    requireNonNull(direction);
    requireNonNull(requestor);
    requireNonNull(requestUri);
    final ContentClaim claim;
    final long size;
    final long offset;
    if (direction == ContentDirection.INPUT) {
        if (provEvent.getPreviousContentClaimContainer() == null || provEvent.getPreviousContentClaimSection() == null || provEvent.getPreviousContentClaimIdentifier() == null) {
            throw new IllegalArgumentException("Input Content Claim not specified");
        }
        final ResourceClaim resourceClaim = resourceClaimManager.newResourceClaim(provEvent.getPreviousContentClaimContainer(), provEvent.getPreviousContentClaimSection(), provEvent.getPreviousContentClaimIdentifier(), false, false);
        claim = new StandardContentClaim(resourceClaim, provEvent.getPreviousContentClaimOffset());
        offset = provEvent.getPreviousContentClaimOffset() == null ? 0L : provEvent.getPreviousContentClaimOffset();
        size = provEvent.getPreviousFileSize();
    } else {
        if (provEvent.getContentClaimContainer() == null || provEvent.getContentClaimSection() == null || provEvent.getContentClaimIdentifier() == null) {
            throw new IllegalArgumentException("Output Content Claim not specified");
        }
        final ResourceClaim resourceClaim = resourceClaimManager.newResourceClaim(provEvent.getContentClaimContainer(), provEvent.getContentClaimSection(), provEvent.getContentClaimIdentifier(), false, false);
        claim = new StandardContentClaim(resourceClaim, provEvent.getContentClaimOffset());
        offset = provEvent.getContentClaimOffset() == null ? 0L : provEvent.getContentClaimOffset();
        size = provEvent.getFileSize();
    }
    final InputStream rawStream = contentRepository.read(claim);
    final ResourceClaim resourceClaim = claim.getResourceClaim();
    // Register a Provenance Event to indicate that we replayed the data.
    final ProvenanceEventRecord sendEvent = new StandardProvenanceEventRecord.Builder().setEventType(ProvenanceEventType.DOWNLOAD).setFlowFileUUID(provEvent.getFlowFileUuid()).setAttributes(provEvent.getAttributes(), Collections.emptyMap()).setCurrentContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), offset, size).setTransitUri(requestUri).setEventTime(System.currentTimeMillis()).setFlowFileEntryDate(provEvent.getFlowFileEntryDate()).setLineageStartDate(provEvent.getLineageStartDate()).setComponentType(getName()).setComponentId(getRootGroupId()).setDetails("Download of " + (direction == ContentDirection.INPUT ? "Input" : "Output") + " Content requested by " + requestor + " for Provenance Event " + provEvent.getEventId()).build();
    provenanceRepository.registerEvent(sendEvent);
    return new LimitedInputStream(rawStream, size);
}
Also used : StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ByteArrayInputStream(java.io.ByteArrayInputStream) LimitingInputStream(org.apache.nifi.stream.io.LimitingInputStream) LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) InputStream(java.io.InputStream) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim)

Example 78 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class StandardFlowFileQueue method drop.

private QueueSize drop(final List<FlowFileRecord> flowFiles, final String requestor) throws IOException {
    // Create a Provenance Event and a FlowFile Repository record for each FlowFile
    final List<ProvenanceEventRecord> provenanceEvents = new ArrayList<>(flowFiles.size());
    final List<RepositoryRecord> flowFileRepoRecords = new ArrayList<>(flowFiles.size());
    for (final FlowFileRecord flowFile : flowFiles) {
        provenanceEvents.add(createDropEvent(flowFile, requestor));
        flowFileRepoRecords.add(createDeleteRepositoryRecord(flowFile));
    }
    long dropContentSize = 0L;
    for (final FlowFileRecord flowFile : flowFiles) {
        dropContentSize += flowFile.getSize();
        final ContentClaim contentClaim = flowFile.getContentClaim();
        if (contentClaim == null) {
            continue;
        }
        final ResourceClaim resourceClaim = contentClaim.getResourceClaim();
        if (resourceClaim == null) {
            continue;
        }
        resourceClaimManager.decrementClaimantCount(resourceClaim);
    }
    provRepository.registerEvents(provenanceEvents);
    flowFileRepository.updateRepository(flowFileRepoRecords);
    return new QueueSize(flowFiles.size(), dropContentSize);
}
Also used : QueueSize(org.apache.nifi.controller.queue.QueueSize) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ArrayList(java.util.ArrayList) RepositoryRecord(org.apache.nifi.controller.repository.RepositoryRecord) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord)

Example 79 with ContentClaim

use of org.apache.nifi.controller.repository.claim.ContentClaim in project nifi by apache.

the class SchemaRepositoryRecordSerde method populateContentClaim.

private void populateContentClaim(final StandardFlowFileRecord.Builder ffBuilder, final Record record) {
    final Object claimMap = record.getFieldValue(FlowFileSchema.CONTENT_CLAIM);
    if (claimMap == null) {
        return;
    }
    final Record claimRecord = (Record) claimMap;
    final ContentClaim contentClaim = ContentClaimFieldMap.getContentClaim(claimRecord, resourceClaimManager);
    final Long offset = ContentClaimFieldMap.getContentClaimOffset(claimRecord);
    ffBuilder.contentClaim(contentClaim);
    ffBuilder.contentClaimOffset(offset);
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) Record(org.apache.nifi.repository.schema.Record)

Aggregations

ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)79 StandardContentClaim (org.apache.nifi.controller.repository.claim.StandardContentClaim)51 Test (org.junit.Test)40 OutputStream (java.io.OutputStream)39 ByteArrayOutputStream (java.io.ByteArrayOutputStream)30 IOException (java.io.IOException)26 InputStream (java.io.InputStream)22 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 FlowFile (org.apache.nifi.flowfile.FlowFile)19 Path (java.nio.file.Path)18 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)14 Map (java.util.Map)13 FileOutputStream (java.io.FileOutputStream)12 FilterOutputStream (java.io.FilterOutputStream)12 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)12 FlowFileAccessException (org.apache.nifi.processor.exception.FlowFileAccessException)12 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)12