Search in sources :

Example 6 with LimitedInputStream

use of org.apache.nifi.controller.repository.io.LimitedInputStream 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 7 with LimitedInputStream

use of org.apache.nifi.controller.repository.io.LimitedInputStream in project nifi-minifi by apache.

the class ConfigMainTest method testTransformErrorTransformingTemplate.

@Test
public void testTransformErrorTransformingTemplate() throws FileNotFoundException {
    when(pathInputStreamFactory.create(testInput)).thenAnswer(invocation -> new LimitedInputStream(ConfigMainTest.class.getClassLoader().getResourceAsStream("TemplateWithFunnel.xml"), 25));
    assertEquals(ConfigMain.ERR_UNABLE_TO_READ_TEMPLATE, configMain.execute(new String[] { ConfigMain.TRANSFORM, testInput, testOutput }));
}
Also used : LimitedInputStream(org.apache.nifi.controller.repository.io.LimitedInputStream) Test(org.junit.Test)

Aggregations

LimitedInputStream (org.apache.nifi.controller.repository.io.LimitedInputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 DisableOnCloseInputStream (org.apache.nifi.controller.repository.io.DisableOnCloseInputStream)4 FlowFileAccessInputStream (org.apache.nifi.controller.repository.io.FlowFileAccessInputStream)4 TaskTerminationInputStream (org.apache.nifi.controller.repository.io.TaskTerminationInputStream)4 FlowFileAccessException (org.apache.nifi.processor.exception.FlowFileAccessException)4 ByteCountingInputStream (org.apache.nifi.stream.io.ByteCountingInputStream)4 ProcessException (org.apache.nifi.processor.exception.ProcessException)3 ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)1 StandardContentClaim (org.apache.nifi.controller.repository.claim.StandardContentClaim)1 DisableOnCloseOutputStream (org.apache.nifi.controller.repository.io.DisableOnCloseOutputStream)1 FlowFileAccessOutputStream (org.apache.nifi.controller.repository.io.FlowFileAccessOutputStream)1 TaskTerminationOutputStream (org.apache.nifi.controller.repository.io.TaskTerminationOutputStream)1