Search in sources :

Example 36 with ProcessGroup

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

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

the class ControllerSearchService method search.

private ComponentSearchResultDTO search(final String searchStr, final ProcessGroup group) {
    final List<String> matches = new ArrayList<>();
    final ProcessGroup parent = group.getParent();
    if (parent == null) {
        return null;
    }
    addIfAppropriate(searchStr, group.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, group.getVersionedComponentId().orElse(null), "Version Control ID", matches);
    addIfAppropriate(searchStr, group.getName(), "Name", matches);
    addIfAppropriate(searchStr, group.getComments(), "Comments", matches);
    final ComponentVariableRegistry varRegistry = group.getVariableRegistry();
    if (varRegistry != null) {
        final Map<VariableDescriptor, String> variableMap = varRegistry.getVariableMap();
        for (final Map.Entry<VariableDescriptor, String> entry : variableMap.entrySet()) {
            addIfAppropriate(searchStr, entry.getKey().getName(), "Variable Name", matches);
            addIfAppropriate(searchStr, entry.getValue(), "Variable Value", matches);
        }
    }
    if (matches.isEmpty()) {
        return null;
    }
    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(group.getIdentifier());
    result.setName(group.getName());
    result.setGroupId(parent.getIdentifier());
    result.setMatches(matches);
    return result;
}
Also used : ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Map(java.util.Map)

Example 38 with ProcessGroup

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

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

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

the class StandardControllerServiceDAO method updateControllerService.

@Override
public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // get the controller service
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());
    // ensure we can perform the update
    verifyUpdate(controllerService, controllerServiceDTO);
    // perform the update
    configureControllerService(controllerService, controllerServiceDTO);
    // attempt to change the underlying controller service if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(controllerService, controllerServiceDTO);
    // enable or disable as appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
        // only attempt an action if it is changing
        if (!purposedControllerServiceState.equals(controllerService.getState())) {
            if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                serviceProvider.enableControllerService(controllerService);
            } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                serviceProvider.disableControllerService(controllerService);
            }
        }
    }
    final ProcessGroup group = controllerService.getProcessGroup();
    if (group != null) {
        group.onComponentModified();
        // For any component that references this Controller Service, find the component's Process Group
        // and notify the Process Group that a component has been modified. This way, we know to re-calculate
        // whether or not the Process Group has local modifications.
        controllerService.getReferences().getReferencingComponents().stream().map(ConfiguredComponent::getProcessGroupIdentifier).filter(id -> !id.equals(group.getIdentifier())).forEach(groupId -> {
            final ProcessGroup descendant = group.findProcessGroup(groupId);
            if (descendant != null) {
                descendant.onComponentModified();
            }
        });
    }
    return controllerService;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ArrayList(java.util.ArrayList) ComponentStateDAO(org.apache.nifi.web.dao.ComponentStateDAO) ControllerServiceDAO(org.apache.nifi.web.dao.ControllerServiceDAO) ROOT_GROUP_ID_ALIAS(org.apache.nifi.controller.FlowController.ROOT_GROUP_ID_ALIAS) Scope(org.apache.nifi.components.state.Scope) Map(java.util.Map) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) Set(java.util.Set) BundleUtils(org.apache.nifi.util.BundleUtils) StateMap(org.apache.nifi.components.state.StateMap) FlowController(org.apache.nifi.controller.FlowController) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) List(java.util.List) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ExtensionManager(org.apache.nifi.nar.ExtensionManager) Collections(java.util.Collections) ValidationException(org.apache.nifi.controller.exception.ValidationException) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Aggregations

ProcessGroup (org.apache.nifi.groups.ProcessGroup)185 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)97 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)68 ProcessorNode (org.apache.nifi.controller.ProcessorNode)50 Port (org.apache.nifi.connectable.Port)40 RootGroupPort (org.apache.nifi.remote.RootGroupPort)37 Connection (org.apache.nifi.connectable.Connection)36 ArrayList (java.util.ArrayList)35 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)35 Test (org.junit.Test)35 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)34 HashSet (java.util.HashSet)32 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)32 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)29 FlowController (org.apache.nifi.controller.FlowController)27 Connectable (org.apache.nifi.connectable.Connectable)26 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)25 Funnel (org.apache.nifi.connectable.Funnel)24 List (java.util.List)22 Label (org.apache.nifi.controller.label.Label)22