Search in sources :

Example 21 with ResourceClaim

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

the class StandardProcessSession method enrich.

private StandardProvenanceEventRecord enrich(final ProvenanceEventRecord rawEvent, final Map<String, FlowFileRecord> flowFileRecordMap, final Map<FlowFileRecord, StandardRepositoryRecord> records, final boolean updateAttributes) {
    final StandardProvenanceEventRecord.Builder recordBuilder = new StandardProvenanceEventRecord.Builder().fromEvent(rawEvent);
    final FlowFileRecord eventFlowFile = flowFileRecordMap.get(rawEvent.getFlowFileUuid());
    if (eventFlowFile != null) {
        final StandardRepositoryRecord repoRecord = records.get(eventFlowFile);
        if (repoRecord.getCurrent() != null && repoRecord.getCurrentClaim() != null) {
            final ContentClaim currentClaim = repoRecord.getCurrentClaim();
            final long currentOffset = repoRecord.getCurrentClaimOffset();
            final long size = eventFlowFile.getSize();
            final ResourceClaim resourceClaim = currentClaim.getResourceClaim();
            recordBuilder.setCurrentContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), currentOffset + currentClaim.getOffset(), size);
        }
        if (repoRecord.getOriginal() != null && repoRecord.getOriginalClaim() != null) {
            final ContentClaim originalClaim = repoRecord.getOriginalClaim();
            final long originalOffset = repoRecord.getOriginal().getContentClaimOffset();
            final long originalSize = repoRecord.getOriginal().getSize();
            final ResourceClaim resourceClaim = originalClaim.getResourceClaim();
            recordBuilder.setPreviousContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), originalOffset + originalClaim.getOffset(), originalSize);
        }
        final FlowFileQueue originalQueue = repoRecord.getOriginalQueue();
        if (originalQueue != null) {
            recordBuilder.setSourceQueueIdentifier(originalQueue.getIdentifier());
        }
    }
    if (updateAttributes) {
        final FlowFileRecord flowFileRecord = flowFileRecordMap.get(rawEvent.getFlowFileUuid());
        if (flowFileRecord != null) {
            final StandardRepositoryRecord record = records.get(flowFileRecord);
            if (record != null) {
                recordBuilder.setAttributes(record.getOriginalAttributes(), record.getUpdatedAttributes());
            }
        }
    }
    return recordBuilder.build();
}
Also used : StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue)

Example 22 with ResourceClaim

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

the class VolatileContentRepository method createLossTolerant.

private ContentClaim createLossTolerant() {
    final long id = idGenerator.getAndIncrement();
    final ResourceClaim resourceClaim = claimManager.newResourceClaim(CONTAINER_NAME, "section", String.valueOf(id), true, false);
    final ContentClaim claim = new StandardContentClaim(resourceClaim, 0L);
    final ContentBlock contentBlock = new ContentBlock(claim, repoSize);
    claimManager.incrementClaimantCount(resourceClaim, true);
    claimMap.put(claim, contentBlock);
    logger.debug("Created {} and mapped to {}", claim, contentBlock);
    return claim;
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim)

Example 23 with ResourceClaim

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

the class WriteAheadFlowFileRepository method onSync.

@Override
public void onSync(final int partitionIndex) {
    final BlockingQueue<ResourceClaim> claimQueue = claimsAwaitingDestruction.get(Integer.valueOf(partitionIndex));
    if (claimQueue == null) {
        return;
    }
    final Set<ResourceClaim> claimsToDestroy = new HashSet<>();
    claimQueue.drainTo(claimsToDestroy);
    for (final ResourceClaim claim : claimsToDestroy) {
        markDestructable(claim);
    }
}
Also used : ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) HashSet(java.util.HashSet)

Example 24 with ResourceClaim

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

the class TestSchemaSwapSerializerDeserializer method testRoundTripSerializeDeserializeSummary.

@Test
public void testRoundTripSerializeDeserializeSummary() throws IOException {
    final ResourceClaimManager resourceClaimManager = new StandardResourceClaimManager();
    final ResourceClaim firstResourceClaim = resourceClaimManager.newResourceClaim("container", "section", "id", true, false);
    resourceClaimManager.incrementClaimantCount(firstResourceClaim);
    final List<FlowFileRecord> toSwap = new ArrayList<>(10000);
    final Map<String, String> attrs = new HashMap<>();
    long size = 0L;
    final ContentClaim firstClaim = MockFlowFile.createContentClaim("id", resourceClaimManager);
    for (int i = 0; i < 10000; i++) {
        attrs.put("i", String.valueOf(i));
        final FlowFileRecord ff = i < 2 ? new MockFlowFile(attrs, i, firstClaim) : new MockFlowFile(attrs, i, resourceClaimManager);
        toSwap.add(ff);
        size += i;
    }
    final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
    Mockito.when(flowFileQueue.getIdentifier()).thenReturn("87bb99fe-412c-49f6-a441-d1b0af4e20b4");
    final String swapLocation = "target/testRoundTrip.swap";
    final File swapFile = new File(swapLocation);
    Files.deleteIfExists(swapFile.toPath());
    final SwapSerializer serializer = new SchemaSwapSerializer();
    try (final FileOutputStream fos = new FileOutputStream(swapFile)) {
        serializer.serializeFlowFiles(toSwap, flowFileQueue, swapLocation, fos);
    }
    final SwapDeserializer deserializer = new SchemaSwapDeserializer();
    final SwapSummary swapSummary;
    try (final FileInputStream fis = new FileInputStream(swapFile);
        final DataInputStream dis = new DataInputStream(fis)) {
        swapSummary = deserializer.getSwapSummary(dis, swapLocation, resourceClaimManager);
    }
    assertEquals(10000, swapSummary.getQueueSize().getObjectCount());
    assertEquals(size, swapSummary.getQueueSize().getByteCount());
    assertEquals(9999, swapSummary.getMaxFlowFileId().intValue());
    final List<ResourceClaim> resourceClaims = swapSummary.getResourceClaims();
    assertEquals(10000, resourceClaims.size());
    assertFalse(resourceClaims.stream().anyMatch(claim -> claim == null));
    assertEquals(2, resourceClaims.stream().filter(claim -> claim.getId().equals("id")).collect(Collectors.counting()).intValue());
    final Set<ResourceClaim> uniqueClaims = new HashSet<>(resourceClaims);
    assertEquals(9999, uniqueClaims.size());
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) DataInputStream(java.io.DataInputStream) BufferedInputStream(java.io.BufferedInputStream) SwapContents(org.apache.nifi.controller.repository.SwapContents) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) HashMap(java.util.HashMap) BufferedOutputStream(java.io.BufferedOutputStream) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) Map(java.util.Map) Before(org.junit.Before) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.nifi.stream.io.NullOutputStream) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) Files(java.nio.file.Files) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) SwapSummary(org.apache.nifi.controller.repository.SwapSummary) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) Mockito(org.mockito.Mockito) List(java.util.List) Ignore(org.junit.Ignore) Assert.assertFalse(org.junit.Assert.assertFalse) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ResourceClaimManager(org.apache.nifi.controller.repository.claim.ResourceClaimManager) SwapSummary(org.apache.nifi.controller.repository.SwapSummary) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) HashSet(java.util.HashSet) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) FileOutputStream(java.io.FileOutputStream) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) File(java.io.File) Test(org.junit.Test)

Example 25 with ResourceClaim

use of org.apache.nifi.controller.repository.claim.ResourceClaim 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)

Aggregations

ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)33 ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)17 StandardContentClaim (org.apache.nifi.controller.repository.claim.StandardContentClaim)12 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)9 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)6 StandardProvenanceEventRecord (org.apache.nifi.provenance.StandardProvenanceEventRecord)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 QueueSize (org.apache.nifi.controller.queue.QueueSize)5 SwapSummary (org.apache.nifi.controller.repository.SwapSummary)5 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)5 File (java.io.File)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Connection (org.apache.nifi.connectable.Connection)4 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3