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);
}
}
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();
}
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());
}
}
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);
}
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);
}
}
}
Aggregations