Search in sources :

Example 6 with Connection

use of org.apache.nifi.connectable.Connection in project nifi by apache.

the class ControllerFacade method getConnectionStatus.

/**
 * Gets the status for the specified connection.
 *
 * @param connectionId connection id
 * @return the status for the specified connection
 */
public ConnectionStatus getConnectionStatus(final String connectionId) {
    final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
    final Connection connection = root.findConnection(connectionId);
    // ensure the connection was found
    if (connection == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }
    // calculate the process group status
    final String groupId = connection.getProcessGroup().getIdentifier();
    final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
    if (processGroupStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
    }
    final ConnectionStatus status = processGroupStatus.getConnectionStatus().stream().filter(connectionStatus -> connectionId.equals(connectionStatus.getId())).findFirst().orElse(null);
    if (status == null) {
        throw new ResourceNotFoundException(String.format("Unable to locate connection with id '%s'.", connectionId));
    }
    return status;
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Connection(org.apache.nifi.connectable.Connection) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus)

Example 7 with Connection

use of org.apache.nifi.connectable.Connection in project nifi by apache.

the class ControllerSearchService method search.

/**
 * Searches term in the controller beginning from a given process group.
 *
 * @param results Search results
 * @param search The search term
 * @param group The init process group
 */
public void search(final SearchResultsDTO results, final String search, final ProcessGroup group) {
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (group.isAuthorized(authorizer, RequestAction.READ, user)) {
        final ComponentSearchResultDTO groupMatch = search(search, group);
        if (groupMatch != null) {
            // get the parent group, not the current one
            groupMatch.setParentGroup(buildResultGroup(group.getParent(), user));
            groupMatch.setVersionedGroup(buildVersionedGroup(group.getParent(), user));
            results.getProcessGroupResults().add(groupMatch);
        }
    }
    for (final ProcessorNode procNode : group.getProcessors()) {
        if (procNode.isAuthorized(authorizer, RequestAction.READ, user)) {
            final ComponentSearchResultDTO match = search(search, procNode);
            if (match != null) {
                match.setGroupId(group.getIdentifier());
                match.setParentGroup(buildResultGroup(group, user));
                match.setVersionedGroup(buildVersionedGroup(group, user));
                results.getProcessorResults().add(match);
            }
        }
    }
    for (final Connection connection : group.getConnections()) {
        if (connection.isAuthorized(authorizer, RequestAction.READ, user)) {
            final ComponentSearchResultDTO match = search(search, connection);
            if (match != null) {
                match.setGroupId(group.getIdentifier());
                match.setParentGroup(buildResultGroup(group, user));
                match.setVersionedGroup(buildVersionedGroup(group, user));
                results.getConnectionResults().add(match);
            }
        }
    }
    for (final RemoteProcessGroup remoteGroup : group.getRemoteProcessGroups()) {
        if (remoteGroup.isAuthorized(authorizer, RequestAction.READ, user)) {
            final ComponentSearchResultDTO match = search(search, remoteGroup);
            if (match != null) {
                match.setGroupId(group.getIdentifier());
                match.setParentGroup(buildResultGroup(group, user));
                match.setVersionedGroup(buildVersionedGroup(group, user));
                results.getRemoteProcessGroupResults().add(match);
            }
        }
    }
    for (final Port port : group.getInputPorts()) {
        if (port.isAuthorized(authorizer, RequestAction.READ, user)) {
            final ComponentSearchResultDTO match = search(search, port);
            if (match != null) {
                match.setGroupId(group.getIdentifier());
                match.setParentGroup(buildResultGroup(group, user));
                match.setVersionedGroup(buildVersionedGroup(group, user));
                results.getInputPortResults().add(match);
            }
        }
    }
    for (final Port port : group.getOutputPorts()) {
        if (port.isAuthorized(authorizer, RequestAction.READ, user)) {
            final ComponentSearchResultDTO match = search(search, port);
            if (match != null) {
                match.setGroupId(group.getIdentifier());
                match.setParentGroup(buildResultGroup(group, user));
                match.setVersionedGroup(buildVersionedGroup(group, user));
                results.getOutputPortResults().add(match);
            }
        }
    }
    for (final Funnel funnel : group.getFunnels()) {
        if (funnel.isAuthorized(authorizer, RequestAction.READ, user)) {
            final ComponentSearchResultDTO match = search(search, funnel);
            if (match != null) {
                match.setGroupId(group.getIdentifier());
                match.setParentGroup(buildResultGroup(group, user));
                match.setVersionedGroup(buildVersionedGroup(group, user));
                results.getFunnelResults().add(match);
            }
        }
    }
    for (final ProcessGroup processGroup : group.getProcessGroups()) {
        search(results, search, processGroup);
    }
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Funnel(org.apache.nifi.connectable.Funnel) ProcessorNode(org.apache.nifi.controller.ProcessorNode) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) Connection(org.apache.nifi.connectable.Connection) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup)

Example 8 with Connection

use of org.apache.nifi.connectable.Connection 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 9 with Connection

use of org.apache.nifi.connectable.Connection 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 10 with Connection

use of org.apache.nifi.connectable.Connection 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)

Aggregations

Connection (org.apache.nifi.connectable.Connection)95 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 VersionedConnection (org.apache.nifi.registry.flow.VersionedConnection)30 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)28 Connectable (org.apache.nifi.connectable.Connectable)27 ProcessGroup (org.apache.nifi.groups.ProcessGroup)26 Relationship (org.apache.nifi.processor.Relationship)23 Port (org.apache.nifi.connectable.Port)21 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)21 ProcessorNode (org.apache.nifi.controller.ProcessorNode)19 RootGroupPort (org.apache.nifi.remote.RootGroupPort)19 LinkedHashSet (java.util.LinkedHashSet)18 Set (java.util.Set)17 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)17 Funnel (org.apache.nifi.connectable.Funnel)16 HashMap (java.util.HashMap)15 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)15 IOException (java.io.IOException)14 Map (java.util.Map)14