Search in sources :

Example 11 with Connection

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

the class StandardConnectionDAO method deleteConnection.

@Override
public void deleteConnection(final String id) {
    final Connection connection = locateConnection(id);
    connection.getProcessGroup().removeConnection(connection);
}
Also used : Connection(org.apache.nifi.connectable.Connection)

Example 12 with Connection

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

Example 13 with Connection

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

the class StandardConnectionDAO method deleteFlowFileListingRequest.

@Override
public ListFlowFileStatus deleteFlowFileListingRequest(String connectionId, String listingRequestId) {
    final Connection connection = locateConnection(connectionId);
    final FlowFileQueue queue = connection.getFlowFileQueue();
    final ListFlowFileStatus listFlowFileStatus = queue.cancelListFlowFileRequest(listingRequestId);
    if (listFlowFileStatus == null) {
        throw new ResourceNotFoundException(String.format("Unable to find listing request with id '%s'.", listingRequestId));
    }
    return listFlowFileStatus;
}
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 14 with Connection

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

the class StandardConnectionDAO method updateConnection.

@Override
public Connection updateConnection(final ConnectionDTO connectionDTO) {
    final Connection connection = locateConnection(connectionDTO.getId());
    final ProcessGroup group = connection.getProcessGroup();
    // ensure we can update
    verifyUpdate(connection, connectionDTO);
    final Collection<Relationship> newProcessorRelationships = new ArrayList<>();
    Connectable newDestination = null;
    // ensure that the source ID is correct, if specified.
    final Connectable existingSource = connection.getSource();
    if (isNotNull(connectionDTO.getSource()) && !existingSource.getIdentifier().equals(connectionDTO.getSource().getId())) {
        throw new IllegalStateException("Connection with ID " + connectionDTO.getId() + " has conflicting Source ID");
    }
    // determine any new relationships
    final Set<String> relationships = connectionDTO.getSelectedRelationships();
    if (isNotNull(relationships)) {
        if (relationships.isEmpty()) {
            throw new IllegalArgumentException("Cannot remove all relationships from Connection with ID " + connection.getIdentifier() + " -- remove the Connection instead");
        }
        if (existingSource == null) {
            throw new IllegalArgumentException("Cannot specify new relationships without including the source.");
        }
        for (final String relationship : relationships) {
            final Relationship processorRelationship = existingSource.getRelationship(relationship);
            if (processorRelationship == null) {
                throw new IllegalArgumentException("Unable to locate " + relationship + " relationship.");
            }
            newProcessorRelationships.add(processorRelationship);
        }
    }
    // determine if the destination changed
    final ConnectableDTO proposedDestination = connectionDTO.getDestination();
    if (proposedDestination != null) {
        final Connectable currentDestination = connection.getDestination();
        // handle remote input port differently
        if (ConnectableType.REMOTE_INPUT_PORT.name().equals(proposedDestination.getType())) {
            // the group id must be specified
            if (proposedDestination.getGroupId() == null) {
                throw new IllegalArgumentException("When the destination is a remote input port its group id is required.");
            }
            // if the current destination is a remote input port
            boolean isDifferentRemoteProcessGroup = false;
            if (currentDestination.getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) {
                RemoteGroupPort remotePort = (RemoteGroupPort) currentDestination;
                if (!proposedDestination.getGroupId().equals(remotePort.getRemoteProcessGroup().getIdentifier())) {
                    isDifferentRemoteProcessGroup = true;
                }
            }
            // if the destination is changing or the previous destination was a different remote process group
            if (!proposedDestination.getId().equals(currentDestination.getIdentifier()) || isDifferentRemoteProcessGroup) {
                final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, group.getIdentifier());
                final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(proposedDestination.getGroupId());
                // ensure the remote process group was found
                if (remoteProcessGroup == null) {
                    throw new IllegalArgumentException("Unable to find the specified remote process group.");
                }
                final RemoteGroupPort remoteInputPort = remoteProcessGroup.getInputPort(proposedDestination.getId());
                // ensure the new destination was found
                if (remoteInputPort == null) {
                    throw new IllegalArgumentException("Unable to find the specified destination.");
                }
                // ensure the remote port actually exists
                if (!remoteInputPort.getTargetExists()) {
                    throw new IllegalArgumentException("The specified remote input port does not exist.");
                } else {
                    newDestination = remoteInputPort;
                }
            }
        } else {
            // if there is a different destination id
            if (!proposedDestination.getId().equals(currentDestination.getIdentifier())) {
                // if the destination connectable's group id has not been set, its inferred to be the current group
                if (proposedDestination.getGroupId() == null) {
                    proposedDestination.setGroupId(group.getIdentifier());
                }
                final ProcessGroup destinationGroup = locateProcessGroup(flowController, proposedDestination.getGroupId());
                newDestination = destinationGroup.getConnectable(proposedDestination.getId());
                // ensure the new destination was found
                if (newDestination == null) {
                    throw new IllegalArgumentException("Unable to find the specified destination.");
                }
            }
        }
    }
    // configure the connection
    configureConnection(connection, connectionDTO);
    // update the relationships if necessary
    if (!newProcessorRelationships.isEmpty()) {
        connection.setRelationships(newProcessorRelationships);
    }
    // update the destination if necessary
    if (isNotNull(newDestination)) {
        connection.setDestination(newDestination);
    }
    return connection;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Connectable(org.apache.nifi.connectable.Connectable) Relationship(org.apache.nifi.processor.Relationship) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 15 with Connection

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

the class StandardConnectionDAO method verifyDelete.

@Override
public void verifyDelete(String id) {
    final Connection connection = locateConnection(id);
    connection.verifyCanDelete();
}
Also used : Connection(org.apache.nifi.connectable.Connection)

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