Search in sources :

Example 41 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class SnippetUtils method addControllerServices.

/**
 * Finds all Controller Services that are referenced in the given Process Group (and child Process Groups, recursively), and
 * adds them to the given servicesByGroup map
 *
 * @param group the Process Group to start from
 * @param dto the DTO representation of the Process Group
 * @param allServicesReferenced a Set of all Controller Service DTO's that have already been referenced; used to dedupe services
 * @param contentsByGroup a Map of Process Group ID to the Process Group's contents
 * @param highestGroupId the UUID of the 'highest' process group in the snippet
 */
private void addControllerServices(final ProcessGroup group, final ProcessGroupDTO dto, final Set<ControllerServiceDTO> allServicesReferenced, final boolean includeControllerServices, final Set<String> visitedGroupIds, final Map<String, FlowSnippetDTO> contentsByGroup, final String highestGroupId) {
    final FlowSnippetDTO contents = dto.getContents();
    contentsByGroup.put(dto.getId(), contents);
    if (contents == null) {
        return;
    }
    // include this group in the ancestry for this snippet, services only get included if the includeControllerServices
    // flag is set or if the service is defined within this groups hierarchy within the snippet
    visitedGroupIds.add(group.getIdentifier());
    for (final ProcessorNode procNode : group.getProcessors()) {
        // Include all referenced services that are not already included in this snippet.
        getControllerServices(procNode.getProperties()).stream().filter(svc -> allServicesReferenced.add(svc)).filter(svc -> includeControllerServices || visitedGroupIds.contains(svc.getParentGroupId())).forEach(svc -> {
            final String svcGroupId = svc.getParentGroupId();
            final String destinationGroupId = contentsByGroup.containsKey(svcGroupId) ? svcGroupId : highestGroupId;
            svc.setParentGroupId(destinationGroupId);
            final FlowSnippetDTO snippetDto = contentsByGroup.get(destinationGroupId);
            if (snippetDto != null) {
                Set<ControllerServiceDTO> services = snippetDto.getControllerServices();
                if (services == null) {
                    snippetDto.setControllerServices(Collections.singleton(svc));
                } else {
                    services.add(svc);
                    snippetDto.setControllerServices(services);
                }
            }
        });
    }
    // Map child process group ID to the child process group for easy lookup
    final Map<String, ProcessGroupDTO> childGroupMap = contents.getProcessGroups().stream().collect(Collectors.toMap(childGroupDto -> childGroupDto.getId(), childGroupDto -> childGroupDto));
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        final ProcessGroupDTO childDto = childGroupMap.get(childGroup.getIdentifier());
        if (childDto == null) {
            continue;
        }
        addControllerServices(childGroup, childDto, allServicesReferenced, includeControllerServices, visitedGroupIds, contentsByGroup, highestGroupId);
    }
}
Also used : RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) ConnectableType(org.apache.nifi.connectable.ConnectableType) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) StringUtils(org.apache.commons.lang3.StringUtils) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ResourceType(org.apache.nifi.authorization.resource.ResourceType) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) SecureRandom(java.security.SecureRandom) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) PropertyDescriptorDTO(org.apache.nifi.web.api.dto.PropertyDescriptorDTO) TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) Map(java.util.Map) Connection(org.apache.nifi.connectable.Connection) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ComponentIdGenerator(org.apache.nifi.util.ComponentIdGenerator) Label(org.apache.nifi.controller.label.Label) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) AccessPolicyDAO(org.apache.nifi.web.dao.AccessPolicyDAO) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Snippet(org.apache.nifi.controller.Snippet) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) FlowController(org.apache.nifi.controller.FlowController) StandardCharsets(java.nio.charset.StandardCharsets) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ScheduledState(org.apache.nifi.controller.ScheduledState) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Entry(java.util.Map.Entry) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) DtoFactory(org.apache.nifi.web.api.dto.DtoFactory) Resource(org.apache.nifi.authorization.Resource) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Funnel(org.apache.nifi.connectable.Funnel) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccessPolicyDTO(org.apache.nifi.web.api.dto.AccessPolicyDTO) LinkedHashSet(java.util.LinkedHashSet) Logger(org.slf4j.Logger) RequestAction(org.apache.nifi.authorization.RequestAction) ComponentDTO(org.apache.nifi.web.api.dto.ComponentDTO) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) Collections(java.util.Collections) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)

Example 42 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardProcessGroup method verifyCanDelete.

@Override
public void verifyCanDelete(final Snippet snippet) throws IllegalStateException {
    readLock.lock();
    try {
        if (!id.equals(snippet.getParentGroupId())) {
            throw new IllegalStateException("Snippet belongs to ProcessGroup with ID " + snippet.getParentGroupId() + " but this ProcessGroup has id " + id);
        }
        if (!isDisconnected(snippet)) {
            throw new IllegalStateException("One or more components within the snippet is connected to a component outside of the snippet. Only a disconnected snippet may be moved.");
        }
        for (final String id : snippet.getConnections().keySet()) {
            final Connection connection = getConnection(id);
            if (connection == null) {
                throw new IllegalStateException("Snippet references Connection with ID " + id + ", which does not exist in this ProcessGroup");
            }
            connection.verifyCanDelete();
        }
        for (final String id : snippet.getFunnels().keySet()) {
            final Funnel funnel = getFunnel(id);
            if (funnel == null) {
                throw new IllegalStateException("Snippet references Funnel with ID " + id + ", which does not exist in this ProcessGroup");
            }
            funnel.verifyCanDelete(true);
        }
        for (final String id : snippet.getInputPorts().keySet()) {
            final Port port = getInputPort(id);
            if (port == null) {
                throw new IllegalStateException("Snippet references Input Port with ID " + id + ", which does not exist in this ProcessGroup");
            }
            port.verifyCanDelete(true);
        }
        for (final String id : snippet.getLabels().keySet()) {
            final Label label = getLabel(id);
            if (label == null) {
                throw new IllegalStateException("Snippet references Label with ID " + id + ", which does not exist in this ProcessGroup");
            }
        }
        for (final String id : snippet.getOutputPorts().keySet()) {
            final Port port = getOutputPort(id);
            if (port == null) {
                throw new IllegalStateException("Snippet references Output Port with ID " + id + ", which does not exist in this ProcessGroup");
            }
            port.verifyCanDelete(true);
        }
        for (final String id : snippet.getProcessGroups().keySet()) {
            final ProcessGroup group = getProcessGroup(id);
            if (group == null) {
                throw new IllegalStateException("Snippet references Process Group with ID " + id + ", which does not exist in this ProcessGroup");
            }
            group.verifyCanDelete(true);
        }
        for (final String id : snippet.getProcessors().keySet()) {
            final ProcessorNode processor = getProcessor(id);
            if (processor == null) {
                throw new IllegalStateException("Snippet references Processor with ID " + id + ", which does not exist in this ProcessGroup");
            }
            processor.verifyCanDelete(true);
        }
        for (final String id : snippet.getRemoteProcessGroups().keySet()) {
            final RemoteProcessGroup group = getRemoteProcessGroup(id);
            if (group == null) {
                throw new IllegalStateException("Snippet references Remote Process Group with ID " + id + ", which does not exist in this ProcessGroup");
            }
            group.verifyCanDelete(true);
        }
    } finally {
        readLock.unlock();
    }
}
Also used : VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) Funnel(org.apache.nifi.connectable.Funnel) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) ProcessorNode(org.apache.nifi.controller.ProcessorNode) RootGroupPort(org.apache.nifi.remote.RootGroupPort) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Port(org.apache.nifi.connectable.Port) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) LocalPort(org.apache.nifi.connectable.LocalPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) Label(org.apache.nifi.controller.label.Label) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)

Example 43 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardProcessGroup method shutdown.

private void shutdown(final ProcessGroup procGroup) {
    for (final ProcessorNode node : procGroup.getProcessors()) {
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(node.getProcessor().getClass(), node.getIdentifier())) {
            final StandardProcessContext processContext = new StandardProcessContext(node, controllerServiceProvider, encryptor, getStateManager(node.getIdentifier()), () -> false);
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, node.getProcessor(), processContext);
        }
    }
    for (final RemoteProcessGroup rpg : procGroup.getRemoteProcessGroups()) {
        rpg.shutdown();
    }
    // Recursively shutdown child groups.
    for (final ProcessGroup group : procGroup.getProcessGroups()) {
        shutdown(group);
    }
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext)

Example 44 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardProcessGroup method getConnectable.

@Override
public Connectable getConnectable(final String id) {
    readLock.lock();
    try {
        final ProcessorNode node = processors.get(id);
        if (node != null) {
            return node;
        }
        final Port inputPort = inputPorts.get(id);
        if (inputPort != null) {
            return inputPort;
        }
        final Port outputPort = outputPorts.get(id);
        if (outputPort != null) {
            return outputPort;
        }
        final Funnel funnel = funnels.get(id);
        if (funnel != null) {
            return funnel;
        }
        return null;
    } finally {
        readLock.unlock();
    }
}
Also used : VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) Funnel(org.apache.nifi.connectable.Funnel) ProcessorNode(org.apache.nifi.controller.ProcessorNode) RootGroupPort(org.apache.nifi.remote.RootGroupPort) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Port(org.apache.nifi.connectable.Port) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) LocalPort(org.apache.nifi.connectable.LocalPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort)

Example 45 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardProcessGroup method addProcessor.

private ProcessorNode addProcessor(final ProcessGroup destination, final VersionedProcessor proposed, final String componentIdSeed) throws ProcessorInstantiationException {
    final BundleCoordinate coordinate = toCoordinate(proposed.getBundle());
    final ProcessorNode procNode = flowController.createProcessor(proposed.getType(), generateUuid(proposed.getIdentifier(), destination.getIdentifier(), componentIdSeed), coordinate, true);
    procNode.setVersionedComponentId(proposed.getIdentifier());
    destination.addProcessor(procNode);
    updateProcessor(procNode, proposed);
    return procNode;
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate)

Aggregations

ProcessorNode (org.apache.nifi.controller.ProcessorNode)88 ProcessGroup (org.apache.nifi.groups.ProcessGroup)45 Port (org.apache.nifi.connectable.Port)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Connection (org.apache.nifi.connectable.Connection)22 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 HashSet (java.util.HashSet)20 Funnel (org.apache.nifi.connectable.Funnel)20 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)20 RootGroupPort (org.apache.nifi.remote.RootGroupPort)20 HashMap (java.util.HashMap)19 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)17 FlowController (org.apache.nifi.controller.FlowController)17 Map (java.util.Map)16 Connectable (org.apache.nifi.connectable.Connectable)16 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)16 LinkedHashSet (java.util.LinkedHashSet)15