Search in sources :

Example 1 with ComponentSearchResultDTO

use of org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO in project kylo by Teradata.

the class LegacyNifiRestClient method findProcessorById.

public ProcessorDTO findProcessorById(String processorId) {
    SearchResultsDTO results = search(processorId);
    // log this
    if (results != null && results.getProcessorResults() != null && !results.getProcessorResults().isEmpty()) {
        log.info("Attempt to find processor by id {}. Processors Found: {} ", processorId, results.getProcessorResults().size());
        ComponentSearchResultDTO processorResult = results.getProcessorResults().get(0);
        String id = processorResult.getId();
        String groupId = processorResult.getGroupId();
        ProcessorDTO processorEntity = getProcessor(groupId, id);
        if (processorEntity != null) {
            return processorEntity;
        }
    } else {
        log.info("Unable to find Processor in Nifi for id: {}", processorId);
    }
    return null;
}
Also used : SearchResultsDTO(org.apache.nifi.web.api.dto.search.SearchResultsDTO) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO)

Example 2 with ComponentSearchResultDTO

use of org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO 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 3 with ComponentSearchResultDTO

use of org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO in project nifi by apache.

the class ControllerSearchService method search.

private ComponentSearchResultDTO search(final String searchStr, final ProcessorNode procNode) {
    final List<String> matches = new ArrayList<>();
    final Processor processor = procNode.getProcessor();
    addIfAppropriate(searchStr, procNode.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, procNode.getVersionedComponentId().orElse(null), "Version Control ID", matches);
    addIfAppropriate(searchStr, procNode.getName(), "Name", matches);
    addIfAppropriate(searchStr, procNode.getComments(), "Comments", matches);
    // consider scheduling strategy
    if (SchedulingStrategy.EVENT_DRIVEN.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("event", searchStr)) {
        matches.add("Scheduling strategy: Event driven");
    } else if (SchedulingStrategy.TIMER_DRIVEN.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("timer", searchStr)) {
        matches.add("Scheduling strategy: Timer driven");
    } else if (SchedulingStrategy.PRIMARY_NODE_ONLY.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("primary", searchStr)) {
        // PRIMARY_NODE_ONLY has been deprecated as a SchedulingStrategy and replaced by PRIMARY as an ExecutionNode.
        matches.add("Scheduling strategy: On primary node");
    }
    // consider execution node
    if (ExecutionNode.PRIMARY.equals(procNode.getExecutionNode()) && StringUtils.containsIgnoreCase("primary", searchStr)) {
        matches.add("Execution node: primary");
    }
    // consider scheduled state
    if (ScheduledState.DISABLED.equals(procNode.getScheduledState())) {
        if (StringUtils.containsIgnoreCase("disabled", searchStr)) {
            matches.add("Run status: Disabled");
        }
    } else {
        if (StringUtils.containsIgnoreCase("invalid", searchStr) && !procNode.isValid()) {
            matches.add("Run status: Invalid");
        } else if (ScheduledState.RUNNING.equals(procNode.getScheduledState()) && StringUtils.containsIgnoreCase("running", searchStr)) {
            matches.add("Run status: Running");
        } else if (ScheduledState.STOPPED.equals(procNode.getScheduledState()) && StringUtils.containsIgnoreCase("stopped", searchStr)) {
            matches.add("Run status: Stopped");
        }
    }
    for (final Relationship relationship : procNode.getRelationships()) {
        addIfAppropriate(searchStr, relationship.getName(), "Relationship", matches);
    }
    // Add both the actual class name and the component type. This allows us to search for 'Ghost'
    // to search for components that could not be instantiated.
    addIfAppropriate(searchStr, processor.getClass().getSimpleName(), "Type", matches);
    addIfAppropriate(searchStr, procNode.getComponentType(), "Type", matches);
    for (final Map.Entry<PropertyDescriptor, String> entry : procNode.getProperties().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();
        addIfAppropriate(searchStr, descriptor.getName(), "Property name", matches);
        addIfAppropriate(searchStr, descriptor.getDescription(), "Property description", matches);
        // never include sensitive properties values in search results
        if (descriptor.isSensitive()) {
            continue;
        }
        String value = entry.getValue();
        // if unset consider default value
        if (value == null) {
            value = descriptor.getDefaultValue();
        }
        // evaluate if the value matches the search criteria
        if (StringUtils.containsIgnoreCase(value, searchStr)) {
            matches.add("Property value: " + descriptor.getName() + " - " + value);
        }
    }
    // consider searching the processor directly
    if (processor instanceof Searchable) {
        final Searchable searchable = (Searchable) processor;
        final SearchContext context = new StandardSearchContext(searchStr, procNode, flowController, variableRegistry);
        // search the processor using the appropriate thread context classloader
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(processor.getClass(), processor.getIdentifier())) {
            final Collection<SearchResult> searchResults = searchable.search(context);
            if (CollectionUtils.isNotEmpty(searchResults)) {
                for (final SearchResult searchResult : searchResults) {
                    matches.add(searchResult.getLabel() + ": " + searchResult.getMatch());
                }
            }
        } catch (final Throwable t) {
        // log this as error
        }
    }
    if (matches.isEmpty()) {
        return null;
    }
    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(procNode.getIdentifier());
    result.setMatches(matches);
    result.setName(procNode.getName());
    return result;
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) Processor(org.apache.nifi.processor.Processor) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) SearchContext(org.apache.nifi.search.SearchContext) SearchResult(org.apache.nifi.search.SearchResult) Relationship(org.apache.nifi.processor.Relationship) Searchable(org.apache.nifi.search.Searchable) Map(java.util.Map)

Example 4 with ComponentSearchResultDTO

use of org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO 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 5 with ComponentSearchResultDTO

use of org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO 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)

Aggregations

ComponentSearchResultDTO (org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO)8 ArrayList (java.util.ArrayList)6 Map (java.util.Map)2 ProcessGroup (org.apache.nifi.groups.ProcessGroup)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2 Relationship (org.apache.nifi.processor.Relationship)2 RootGroupPort (org.apache.nifi.remote.RootGroupPort)2 List (java.util.List)1 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1 Connectable (org.apache.nifi.connectable.Connectable)1 Connection (org.apache.nifi.connectable.Connection)1 Funnel (org.apache.nifi.connectable.Funnel)1 Port (org.apache.nifi.connectable.Port)1 ProcessorNode (org.apache.nifi.controller.ProcessorNode)1 FlowFileQueue (org.apache.nifi.controller.queue.FlowFileQueue)1 FlowFilePrioritizer (org.apache.nifi.flowfile.FlowFilePrioritizer)1 NarCloseable (org.apache.nifi.nar.NarCloseable)1 Processor (org.apache.nifi.processor.Processor)1 ComponentVariableRegistry (org.apache.nifi.registry.ComponentVariableRegistry)1