Search in sources :

Example 1 with FlowFileQueue

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

the class ControllerSearchService method search.

private ComponentSearchResultDTO search(final String searchStr, final Connection connection) {
    final List<String> matches = new ArrayList<>();
    // search id and name
    addIfAppropriate(searchStr, connection.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, connection.getVersionedComponentId().orElse(null), "Version Control ID", matches);
    addIfAppropriate(searchStr, connection.getName(), "Name", matches);
    // search relationships
    for (final Relationship relationship : connection.getRelationships()) {
        addIfAppropriate(searchStr, relationship.getName(), "Relationship", matches);
    }
    // search prioritizers
    final FlowFileQueue queue = connection.getFlowFileQueue();
    for (final FlowFilePrioritizer comparator : queue.getPriorities()) {
        addIfAppropriate(searchStr, comparator.getClass().getName(), "Prioritizer", matches);
    }
    // search expiration
    if (StringUtils.containsIgnoreCase("expires", searchStr) || StringUtils.containsIgnoreCase("expiration", searchStr)) {
        final int expirationMillis = connection.getFlowFileQueue().getFlowFileExpiration(TimeUnit.MILLISECONDS);
        if (expirationMillis > 0) {
            matches.add("FlowFile expiration: " + connection.getFlowFileQueue().getFlowFileExpiration());
        }
    }
    // search back pressure
    if (StringUtils.containsIgnoreCase("back pressure", searchStr) || StringUtils.containsIgnoreCase("pressure", searchStr)) {
        final String backPressureDataSize = connection.getFlowFileQueue().getBackPressureDataSizeThreshold();
        final Double backPressureBytes = DataUnit.parseDataSize(backPressureDataSize, DataUnit.B);
        if (backPressureBytes > 0) {
            matches.add("Back pressure data size: " + backPressureDataSize);
        }
        final long backPressureCount = connection.getFlowFileQueue().getBackPressureObjectThreshold();
        if (backPressureCount > 0) {
            matches.add("Back pressure count: " + backPressureCount);
        }
    }
    // search the source
    final Connectable source = connection.getSource();
    addIfAppropriate(searchStr, source.getIdentifier(), "Source id", matches);
    addIfAppropriate(searchStr, source.getName(), "Source name", matches);
    addIfAppropriate(searchStr, source.getComments(), "Source comments", matches);
    // search the destination
    final Connectable destination = connection.getDestination();
    addIfAppropriate(searchStr, destination.getIdentifier(), "Destination id", matches);
    addIfAppropriate(searchStr, destination.getName(), "Destination name", matches);
    addIfAppropriate(searchStr, destination.getComments(), "Destination comments", matches);
    if (matches.isEmpty()) {
        return null;
    }
    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(connection.getIdentifier());
    // determine the name of the search match
    if (StringUtils.isNotBlank(connection.getName())) {
        result.setName(connection.getName());
    } else if (!connection.getRelationships().isEmpty()) {
        final List<String> relationships = new ArrayList<>(connection.getRelationships().size());
        for (final Relationship relationship : connection.getRelationships()) {
            if (StringUtils.isNotBlank(relationship.getName())) {
                relationships.add(relationship.getName());
            }
        }
        if (!relationships.isEmpty()) {
            result.setName(StringUtils.join(relationships, ", "));
        }
    }
    // ensure a name is added
    if (result.getName() == null) {
        result.setName("From source " + connection.getSource().getName());
    }
    result.setMatches(matches);
    return result;
}
Also used : ArrayList(java.util.ArrayList) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) Connectable(org.apache.nifi.connectable.Connectable) Relationship(org.apache.nifi.processor.Relationship) ArrayList(java.util.ArrayList) List(java.util.List) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer)

Example 2 with FlowFileQueue

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

the class StandardConnectionDAO method deleteFlowFileDropRequest.

@Override
public DropFlowFileStatus deleteFlowFileDropRequest(String connectionId, String dropRequestId) {
    final Connection connection = locateConnection(connectionId);
    final FlowFileQueue queue = connection.getFlowFileQueue();
    final DropFlowFileStatus dropFlowFileStatus = queue.cancelDropFlowFileRequest(dropRequestId);
    if (dropFlowFileStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to find drop request with id '%s'.", dropRequestId));
    }
    return dropFlowFileStatus;
}
Also used : Connection(org.apache.nifi.connectable.Connection) DropFlowFileStatus(org.apache.nifi.controller.queue.DropFlowFileStatus) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 3 with FlowFileQueue

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

the class StandardConnectionDAO method getContent.

@Override
public DownloadableContent getContent(String id, String flowFileUuid, String requestUri) {
    try {
        final NiFiUser user = NiFiUserUtils.getNiFiUser();
        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, user, attributes);
        // get the filename and fall back to the identifier (should never happen)
        String filename = attributes.get(CoreAttributes.FILENAME.key());
        if (filename == null) {
            filename = flowFileUuid;
        }
        // get the mime-type
        final String type = attributes.get(CoreAttributes.MIME_TYPE.key());
        // get the content
        final InputStream content = flowController.getContent(flowFile, user.getIdentity(), requestUri);
        return new DownloadableContent(filename, type, content);
    } catch (final ContentNotFoundException cnfe) {
        throw new ResourceNotFoundException("Unable to find the specified content.");
    } catch (final IOException ioe) {
        logger.error(String.format("Unable to get the content for flowfile (%s) at this time.", flowFileUuid), ioe);
        throw new IllegalStateException("Unable to get the content at this time.");
    }
}
Also used : DownloadableContent(org.apache.nifi.web.DownloadableContent) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ContentNotFoundException(org.apache.nifi.controller.repository.ContentNotFoundException) InputStream(java.io.InputStream) Connection(org.apache.nifi.connectable.Connection) IOException(java.io.IOException) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) DataAuthorizable(org.apache.nifi.authorization.resource.DataAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 4 with FlowFileQueue

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

the class StandardConnectionDAO method getFlowFileListingRequest.

@Override
public ListFlowFileStatus getFlowFileListingRequest(String connectionId, String listingRequestId) {
    final Connection connection = locateConnection(connectionId);
    final FlowFileQueue queue = connection.getFlowFileQueue();
    final ListFlowFileStatus listRequest = queue.getListFlowFileStatus(listingRequestId);
    if (listRequest == null) {
        throw new ResourceNotFoundException(String.format("Unable to find listing request with id '%s'.", listingRequestId));
    }
    return listRequest;
}
Also used : ListFlowFileStatus(org.apache.nifi.controller.queue.ListFlowFileStatus) Connection(org.apache.nifi.connectable.Connection) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 5 with FlowFileQueue

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

the class StandardConnectionDAO method getFlowFileDropRequest.

@Override
public DropFlowFileStatus getFlowFileDropRequest(String connectionId, String dropRequestId) {
    final Connection connection = locateConnection(connectionId);
    final FlowFileQueue queue = connection.getFlowFileQueue();
    final DropFlowFileStatus dropRequest = queue.getDropFlowFileStatus(dropRequestId);
    if (dropRequest == null) {
        throw new ResourceNotFoundException(String.format("Unable to find drop request with id '%s'.", dropRequestId));
    }
    return dropRequest;
}
Also used : Connection(org.apache.nifi.connectable.Connection) DropFlowFileStatus(org.apache.nifi.controller.queue.DropFlowFileStatus) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) 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