Search in sources :

Example 31 with ResourceClaim

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

the class WriteAheadRepositoryRecordSerde method deserializeClaim.

private void deserializeClaim(final DataInputStream in, final int serializationVersion, final StandardFlowFileRecord.Builder ffBuilder) throws IOException {
    // determine current Content Claim.
    final int claimExists = in.read();
    if (claimExists == 1) {
        final String claimId;
        if (serializationVersion < 4) {
            claimId = String.valueOf(in.readLong());
        } else {
            claimId = readString(in);
        }
        final String container = readString(in);
        final String section = readString(in);
        final long resourceOffset;
        final long resourceLength;
        if (serializationVersion < 7) {
            resourceOffset = 0L;
            resourceLength = -1L;
        } else {
            resourceOffset = in.readLong();
            resourceLength = in.readLong();
        }
        final long claimOffset = in.readLong();
        final boolean lossTolerant;
        if (serializationVersion >= 3) {
            lossTolerant = in.readBoolean();
        } else {
            lossTolerant = false;
        }
        final ResourceClaim resourceClaim = claimManager.newResourceClaim(container, section, claimId, lossTolerant, false);
        final StandardContentClaim contentClaim = new StandardContentClaim(resourceClaim, resourceOffset);
        contentClaim.setLength(resourceLength);
        ffBuilder.contentClaim(contentClaim);
        ffBuilder.contentClaimOffset(claimOffset);
    } else if (claimExists == -1) {
        throw new EOFException();
    } else if (claimExists != 0) {
        throw new IOException("Claim Existence Qualifier not found in stream; found value: " + claimExists + " after successfully restoring " + recordsRestored + " records");
    }
}
Also used : StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) EOFException(java.io.EOFException) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) IOException(java.io.IOException)

Example 32 with ResourceClaim

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

the class ContentClaimFieldMap method getContentClaim.

public static ContentClaim getContentClaim(final Record claimRecord, final ResourceClaimManager resourceClaimManager) {
    final Record resourceClaimRecord = (Record) claimRecord.getFieldValue(ContentClaimSchema.RESOURCE_CLAIM);
    final String container = (String) resourceClaimRecord.getFieldValue(ContentClaimSchema.CLAIM_CONTAINER);
    final String section = (String) resourceClaimRecord.getFieldValue(ContentClaimSchema.CLAIM_SECTION);
    final String identifier = (String) resourceClaimRecord.getFieldValue(ContentClaimSchema.CLAIM_IDENTIFIER);
    final Boolean lossTolerant = (Boolean) resourceClaimRecord.getFieldValue(ContentClaimSchema.LOSS_TOLERANT);
    final Long length = (Long) claimRecord.getFieldValue(ContentClaimSchema.CONTENT_CLAIM_LENGTH);
    final Long resourceOffset = (Long) claimRecord.getFieldValue(ContentClaimSchema.RESOURCE_CLAIM_OFFSET);
    // Make sure that we preserve the existing ResourceClaim, if there is already one held by the Resource Claim Manager
    // because we need to honor its determination of whether or not the claim is writable. If the Resource Claim Manager
    // does not have a copy of this Resource Claim, then we can go ahead and just create one and assume that it is not
    // writable (because if it were writable, then the Resource Claim Manager would know about it).
    ResourceClaim resourceClaim = resourceClaimManager.getResourceClaim(container, section, identifier);
    if (resourceClaim == null) {
        resourceClaim = resourceClaimManager.newResourceClaim(container, section, identifier, lossTolerant, false);
    }
    final StandardContentClaim contentClaim = new StandardContentClaim(resourceClaim, resourceOffset);
    contentClaim.setLength(length);
    return contentClaim;
}
Also used : StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) Record(org.apache.nifi.repository.schema.Record) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim)

Example 33 with ResourceClaim

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

the class ResourceClaimFieldMap method getResourceClaim.

public static ResourceClaim getResourceClaim(final Record record, final ResourceClaimManager claimManager) {
    final String container = (String) record.getFieldValue(ContentClaimSchema.CLAIM_CONTAINER);
    final String section = (String) record.getFieldValue(ContentClaimSchema.CLAIM_SECTION);
    final String identifier = (String) record.getFieldValue(ContentClaimSchema.CLAIM_IDENTIFIER);
    final Boolean lossTolerant = (Boolean) record.getFieldValue(ContentClaimSchema.LOSS_TOLERANT);
    // Make sure that we preserve the existing ResourceClaim, if there is already one held by the Resource Claim Manager
    // because we need to honor its determination of whether or not the claim is writable. If the Resource Claim Manager
    // does not have a copy of this Resource Claim, then we can go ahead and just create one and assume that it is not
    // writable (because if it were writable, then the Resource Claim Manager would know about it).
    ResourceClaim resourceClaim = claimManager.getResourceClaim(container, section, identifier);
    if (resourceClaim == null) {
        resourceClaim = claimManager.newResourceClaim(container, section, identifier, lossTolerant, false);
    }
    return resourceClaim;
}
Also used : ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim)

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