Search in sources :

Example 41 with FlowFileQueue

use of org.apache.nifi.controller.queue.FlowFileQueue in project nifi by apache.

the class WriteAheadRepositoryRecordSerde method deserializeRecord.

@Override
public StandardRepositoryRecord deserializeRecord(final DataInputStream in, final int version) throws IOException {
    final int action = in.read();
    if (action == -1) {
        return null;
    }
    final long recordId = in.readLong();
    if (action == ACTION_DELETE) {
        final StandardFlowFileRecord.Builder ffBuilder = new StandardFlowFileRecord.Builder().id(recordId);
        if (version > 4) {
            deserializeClaim(in, version, ffBuilder);
        }
        final FlowFileRecord flowFileRecord = ffBuilder.build();
        final StandardRepositoryRecord record = new StandardRepositoryRecord((FlowFileQueue) null, flowFileRecord);
        record.markForDelete();
        return record;
    }
    // if action was not delete, it must be create/swap in
    final StandardFlowFileRecord.Builder ffBuilder = new StandardFlowFileRecord.Builder();
    final long entryDate = in.readLong();
    if (version > 1) {
        // read the lineage identifiers and lineage start date, which were added in version 2.
        if (version < 9) {
            final int numLineageIds = in.readInt();
            for (int i = 0; i < numLineageIds; i++) {
                // skip identifiers
                in.readUTF();
            }
        }
        final long lineageStartDate = in.readLong();
        final long lineageStartIndex;
        if (version > 7) {
            lineageStartIndex = in.readLong();
        } else {
            lineageStartIndex = 0L;
        }
        ffBuilder.lineageStart(lineageStartDate, lineageStartIndex);
        if (version > 5) {
            final long lastQueueDate = in.readLong();
            final long queueDateIndex;
            if (version > 7) {
                queueDateIndex = in.readLong();
            } else {
                queueDateIndex = 0L;
            }
            ffBuilder.lastQueued(lastQueueDate, queueDateIndex);
        }
    }
    final long size = in.readLong();
    final String connectionId = readString(in);
    logger.debug("{} -> {}", new Object[] { recordId, connectionId });
    ffBuilder.id(recordId);
    ffBuilder.entryDate(entryDate);
    ffBuilder.size(size);
    deserializeClaim(in, version, ffBuilder);
    final int attributesChanged = in.read();
    if (attributesChanged == 1) {
        final int numAttributes = in.readInt();
        final Map<String, String> attributes = new HashMap<>();
        for (int i = 0; i < numAttributes; i++) {
            final String key = readString(in);
            final String value = readString(in);
            attributes.put(key, value);
        }
        ffBuilder.addAttributes(attributes);
    } else if (attributesChanged == -1) {
        throw new EOFException();
    } else if (attributesChanged != 0) {
        throw new IOException("Attribute Change Qualifier not found in stream; found value: " + attributesChanged + " after successfully restoring " + recordsRestored + " records");
    }
    final FlowFileRecord flowFile = ffBuilder.build();
    String swapLocation = null;
    if (action == ACTION_SWAPPED_IN) {
        swapLocation = in.readUTF();
    }
    final StandardRepositoryRecord record;
    final FlowFileQueue queue = getFlowFileQueue(connectionId);
    record = new StandardRepositoryRecord(queue, flowFile);
    if (swapLocation != null) {
        record.setSwapLocation(swapLocation);
    }
    if (connectionId.isEmpty()) {
        logger.warn("{} does not have a FlowFile Queue associated with it; this record will be discarded", flowFile);
        record.markForAbort();
    } else if (queue == null) {
        logger.warn("{} maps to unknown FlowFile Queue {}; this record will be discarded", flowFile, connectionId);
        record.markForAbort();
    }
    recordsRestored++;
    return record;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) EOFException(java.io.EOFException)

Example 42 with FlowFileQueue

use of org.apache.nifi.controller.queue.FlowFileQueue in project nifi by apache.

the class DtoFactory method createConnectionDiagnosticsDto.

private ConnectionDiagnosticsDTO createConnectionDiagnosticsDto(final Connection connection) {
    final ConnectionDiagnosticsDTO dto = new ConnectionDiagnosticsDTO();
    dto.setConnection(createConnectionDto(connection));
    final FlowFileQueue queue = connection.getFlowFileQueue();
    final QueueSize totalSize = queue.size();
    dto.setTotalByteCount(totalSize.getByteCount());
    dto.setTotalFlowFileCount(totalSize.getObjectCount());
    final QueueSize activeSize = queue.getActiveQueueSize();
    dto.setActiveQueueByteCount(activeSize.getByteCount());
    dto.setActiveQueueFlowFileCount(activeSize.getObjectCount());
    final QueueSize inFlightSize = queue.getUnacknowledgedQueueSize();
    dto.setInFlightByteCount(inFlightSize.getByteCount());
    dto.setInFlightFlowFileCount(inFlightSize.getObjectCount());
    final QueueSize swapSize = queue.getSwapQueueSize();
    dto.setSwapByteCount(swapSize.getByteCount());
    dto.setSwapFlowFileCount(swapSize.getObjectCount());
    dto.setSwapFiles(queue.getSwapFileCount());
    dto.setAllActiveQueueFlowFilesPenalized(queue.isAllActiveFlowFilesPenalized());
    dto.setAnyActiveQueueFlowFilesPenalized(queue.isAnyActiveFlowFilePenalized());
    return dto;
}
Also used : QueueSize(org.apache.nifi.controller.queue.QueueSize) ConnectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ConnectionDiagnosticsDTO) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue)

Example 43 with FlowFileQueue

use of org.apache.nifi.controller.queue.FlowFileQueue in project nifi by apache.

the class StandardConnectionDAO method verifyList.

@Override
public void verifyList(String id) {
    final Connection connection = locateConnection(id);
    final FlowFileQueue queue = connection.getFlowFileQueue();
    verifyList(queue);
}
Also used : Connection(org.apache.nifi.connectable.Connection) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue)

Example 44 with FlowFileQueue

use of org.apache.nifi.controller.queue.FlowFileQueue in project nifi by apache.

the class StandardConnectionDAO method createFlowFileListingRequest.

@Override
public ListFlowFileStatus createFlowFileListingRequest(String id, String listingRequestId) {
    final Connection connection = locateConnection(id);
    final FlowFileQueue queue = connection.getFlowFileQueue();
    // ensure we can list
    verifyList(queue);
    return queue.listFlowFiles(listingRequestId, 100);
}
Also used : Connection(org.apache.nifi.connectable.Connection) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue)

Example 45 with FlowFileQueue

use of org.apache.nifi.controller.queue.FlowFileQueue in project nifi by apache.

the class StandardConnectionDAO method getFlowFile.

@Override
public FlowFileRecord getFlowFile(String id, String flowFileUuid) {
    try {
        final Connection connection = locateConnection(id);
        final FlowFileQueue queue = connection.getFlowFileQueue();
        final FlowFileRecord flowFile = queue.getFlowFile(flowFileUuid);
        if (flowFile == null) {
            throw new ResourceNotFoundException(String.format("The FlowFile with UUID %s is no longer in the active queue.", flowFileUuid));
        }
        // get the attributes and ensure appropriate access
        final Map<String, String> attributes = flowFile.getAttributes();
        final Authorizable dataAuthorizable = new DataAuthorizable(connection.getSourceAuthorizable());
        dataAuthorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser(), attributes);
        return flowFile;
    } catch (final IOException ioe) {
        logger.error(String.format("Unable to get the flowfile (%s) at this time.", flowFileUuid), ioe);
        throw new IllegalStateException("Unable to get the FlowFile at this time.");
    }
}
Also used : DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) Connection(org.apache.nifi.connectable.Connection) DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) IOException(java.io.IOException) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Aggregations

FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)46 Connection (org.apache.nifi.connectable.Connection)25 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)15 IOException (java.io.IOException)14 Test (org.junit.Test)12 List (java.util.List)10 Map (java.util.Map)10 Connectable (org.apache.nifi.connectable.Connectable)10 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)10 ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)10 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)10 HashSet (java.util.HashSet)9 Set (java.util.Set)8 StandardResourceClaimManager (org.apache.nifi.controller.repository.claim.StandardResourceClaimManager)8 OutputStream (java.io.OutputStream)7 ResourceClaimManager (org.apache.nifi.controller.repository.claim.ResourceClaimManager)7 Relationship (org.apache.nifi.processor.Relationship)7 InputStream (java.io.InputStream)6 TimeUnit (java.util.concurrent.TimeUnit)6