Search in sources :

Example 16 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup 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 17 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardConnectionDAO method validateProposedConfiguration.

/**
 * Validates the proposed processor configuration.
 */
private List<String> validateProposedConfiguration(final String groupId, final ConnectionDTO connectionDTO) {
    List<String> validationErrors = new ArrayList<>();
    if (isNotNull(connectionDTO.getBackPressureObjectThreshold()) && connectionDTO.getBackPressureObjectThreshold() < 0) {
        validationErrors.add("Max queue size must be a non-negative integer");
    }
    if (isNotNull(connectionDTO.getFlowFileExpiration())) {
        Matcher expirationMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(connectionDTO.getFlowFileExpiration());
        if (!expirationMatcher.matches()) {
            validationErrors.add("Flow file expiration is not a valid time duration (ie 30 sec, 5 min)");
        }
    }
    if (isNotNull(connectionDTO.getLabelIndex())) {
        if (connectionDTO.getLabelIndex() < 0) {
            validationErrors.add("The label index must be positive.");
        }
    }
    // validation is required when connecting to a remote process group since each node in a
    // cluster may or may not be authorized
    final ConnectableDTO proposedDestination = connectionDTO.getDestination();
    if (proposedDestination != null && ConnectableType.REMOTE_INPUT_PORT.name().equals(proposedDestination.getType())) {
        // the group id must be specified
        if (proposedDestination.getGroupId() == null) {
            validationErrors.add("When the destination is a remote input port its group id is required.");
            return validationErrors;
        }
        // attempt to location the proprosed destination
        final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(proposedDestination.getGroupId());
        if (remoteProcessGroup == null) {
            validationErrors.add("Unable to find the specified remote process group.");
            return validationErrors;
        }
        // ensure the new destination was found
        final RemoteGroupPort remoteInputPort = remoteProcessGroup.getInputPort(proposedDestination.getId());
        if (remoteInputPort == null) {
            validationErrors.add("Unable to find the specified destination.");
            return validationErrors;
        }
    }
    return validationErrors;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Matcher(java.util.regex.Matcher) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 18 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup 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 19 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardProcessGroupDAO method updateProcessGroupFlow.

@Override
public ProcessGroup updateProcessGroupFlow(final String groupId, final NiFiUser user, final VersionedFlowSnapshot proposedSnapshot, final VersionControlInformationDTO versionControlInformation, final String componentIdSeed, final boolean verifyNotModified, final boolean updateSettings, final boolean updateDescendantVersionedFlows) {
    final ProcessGroup group = locateProcessGroup(flowController, groupId);
    group.updateFlow(proposedSnapshot, componentIdSeed, verifyNotModified, updateSettings, updateDescendantVersionedFlows);
    group.findAllRemoteProcessGroups().stream().forEach(RemoteProcessGroup::initialize);
    final StandardVersionControlInformation svci = StandardVersionControlInformation.Builder.fromDto(versionControlInformation).flowSnapshot(proposedSnapshot.getFlowContents()).build();
    group.setVersionControlInformation(svci, Collections.emptyMap());
    group.onComponentModified();
    return group;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) ProcessGroup(org.apache.nifi.groups.ProcessGroup) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup)

Example 20 with RemoteProcessGroup

use of org.apache.nifi.groups.RemoteProcessGroup in project nifi by apache.

the class StandardRemoteProcessGroupDAO method locateRemoteProcessGroup.

private RemoteProcessGroup locateRemoteProcessGroup(final String remoteProcessGroupId) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    final RemoteProcessGroup remoteProcessGroup = rootGroup.findRemoteProcessGroup(remoteProcessGroupId);
    if (remoteProcessGroup == null) {
        throw new ResourceNotFoundException(String.format("Unable to find remote process group with id '%s'.", remoteProcessGroupId));
    } else {
        return remoteProcessGroup;
    }
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Aggregations

RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)74 ProcessGroup (org.apache.nifi.groups.ProcessGroup)32 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)31 Action (org.apache.nifi.action.Action)27 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)26 ArrayList (java.util.ArrayList)20 Connection (org.apache.nifi.connectable.Connection)20 Port (org.apache.nifi.connectable.Port)19 Test (org.junit.Test)18 HashSet (java.util.HashSet)16 RootGroupPort (org.apache.nifi.remote.RootGroupPort)16 Funnel (org.apache.nifi.connectable.Funnel)15 Connectable (org.apache.nifi.connectable.Connectable)14 ProcessorNode (org.apache.nifi.controller.ProcessorNode)14 Label (org.apache.nifi.controller.label.Label)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)13 Collection (java.util.Collection)11 HashMap (java.util.HashMap)10 Snippet (org.apache.nifi.controller.Snippet)10 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)10