Search in sources :

Example 6 with ResourceClaim

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

the class FileSystemRepository method removeIncompleteContent.

private void removeIncompleteContent(final String containerName, final Path containerPath, final Path fileToRemove) {
    if (Files.isDirectory(fileToRemove)) {
        final Path lastPathName = fileToRemove.subpath(1, fileToRemove.getNameCount());
        final String fileName = lastPathName.toFile().getName();
        if (fileName.equals(ARCHIVE_DIR_NAME)) {
            return;
        }
        final File[] children = fileToRemove.toFile().listFiles();
        if (children != null) {
            for (final File child : children) {
                removeIncompleteContent(containerName, containerPath, child.toPath());
            }
        }
        return;
    }
    final Path relativePath = containerPath.relativize(fileToRemove);
    final Path sectionPath = relativePath.subpath(0, 1);
    if (relativePath.getNameCount() < 2) {
        return;
    }
    final Path idPath = relativePath.subpath(1, relativePath.getNameCount());
    final String id = idPath.toFile().getName();
    final String sectionName = sectionPath.toFile().getName();
    final ResourceClaim resourceClaim = resourceClaimManager.newResourceClaim(containerName, sectionName, id, false, false);
    if (resourceClaimManager.getClaimantCount(resourceClaim) == 0) {
        removeIncompleteContent(fileToRemove);
    }
}
Also used : Path(java.nio.file.Path) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) File(java.io.File)

Example 7 with ResourceClaim

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

the class StandardProcessSession method enrich.

@Override
public StandardProvenanceEventRecord enrich(final ProvenanceEventRecord rawEvent, final FlowFile flowFile) {
    verifyTaskActive();
    final StandardRepositoryRecord repoRecord = records.get(flowFile);
    if (repoRecord == null) {
        throw new FlowFileHandlingException(flowFile + " is not known in this session (" + toString() + ")");
    }
    final StandardProvenanceEventRecord.Builder recordBuilder = new StandardProvenanceEventRecord.Builder().fromEvent(rawEvent);
    if (repoRecord.getCurrent() != null && repoRecord.getCurrentClaim() != null) {
        final ContentClaim currentClaim = repoRecord.getCurrentClaim();
        final long currentOffset = repoRecord.getCurrentClaimOffset();
        final long size = flowFile.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());
    }
    recordBuilder.setAttributes(repoRecord.getOriginalAttributes(), repoRecord.getUpdatedAttributes());
    return recordBuilder.build();
}
Also used : StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) FlowFileHandlingException(org.apache.nifi.processor.exception.FlowFileHandlingException) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue)

Example 8 with ResourceClaim

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

the class StandardProcessSession method updateEventContentClaims.

private void updateEventContentClaims(final ProvenanceEventBuilder builder, final FlowFile flowFile, final StandardRepositoryRecord repoRecord) {
    final ContentClaim originalClaim = repoRecord.getOriginalClaim();
    if (originalClaim == null) {
        builder.setCurrentContentClaim(null, null, null, null, 0L);
    } else {
        final ResourceClaim resourceClaim = originalClaim.getResourceClaim();
        builder.setCurrentContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), repoRecord.getOriginal().getContentClaimOffset() + originalClaim.getOffset(), repoRecord.getOriginal().getSize());
        builder.setPreviousContentClaim(resourceClaim.getContainer(), resourceClaim.getSection(), resourceClaim.getId(), repoRecord.getOriginal().getContentClaimOffset() + originalClaim.getOffset(), repoRecord.getOriginal().getSize());
    }
}
Also used : ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim)

Example 9 with ResourceClaim

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

the class VolatileFlowFileRepository method markDestructable.

private void markDestructable(final ContentClaim contentClaim) {
    if (contentClaim == null) {
        return;
    }
    final ResourceClaim resourceClaim = contentClaim.getResourceClaim();
    if (resourceClaim == null) {
        return;
    }
    claimManager.markDestructable(resourceClaim);
}
Also used : ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim)

Example 10 with ResourceClaim

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

the class WriteAheadFlowFileRepository method onGlobalSync.

@Override
public void onGlobalSync() {
    for (final BlockingQueue<ResourceClaim> claimQueue : claimsAwaitingDestruction.values()) {
        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)

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