Java Code Examples for org.apache.nifi.groups.ProcessGroup#getProcessors()

The following examples show how to use org.apache.nifi.groups.ProcessGroup#getProcessors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardParameterContextDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void verifyDelete(final String parameterContextId) {
    // Find all Process Groups that are bound to the Parameter Context
    final List<ProcessGroup> groupsReferencingParameterContext = getBoundProcessGroups(parameterContextId);

    // If any component is referencing a Parameter and is running/enabled then fail
    for (final ProcessGroup group : groupsReferencingParameterContext) {
        for (final ProcessorNode processor : group.getProcessors()) {
            if (processor.isReferencingParameter() && processor.isRunning()) {
                throw new IllegalStateException("Cannot delete Parameter Context with ID " + parameterContextId + " because it is in use by at least one Processor that is running");
            }
        }

        for (final ControllerServiceNode service : group.getControllerServices(false)) {
            if (service.isReferencingParameter() && service.getState() != ControllerServiceState.DISABLED) {
                throw new IllegalStateException("Cannot delete Parameter Context with ID " + parameterContextId + " because it is in use by at least one Controller Service that is enabled");
            }
        }
    }
}
 
Example 2
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<ProcessorNode> getProcessors(String groupId, boolean includeDescendants) {
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    if (includeDescendants) {
        return new HashSet<>(group.findAllProcessors());
    } else {
        return new HashSet<>(group.getProcessors());
    }
}
 
Example 3
Source File: TestFlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void purgeFlow() {
    final ProcessGroup processGroup = controller.getFlowManager().getRootGroup();
    for (final ProcessorNode procNode : processGroup.getProcessors()) {
        processGroup.removeProcessor(procNode);
    }
    for (final ControllerServiceNode serviceNode : controller.getFlowManager().getAllControllerServices()) {
        controller.getControllerServiceProvider().removeControllerService(serviceNode);
    }
}
 
Example 4
Source File: DtoFactory.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a ProcessGroupContentDTO from the specified ProcessGroup.
 *
 * @param group group
 * @param recurse recurse
 * @return dto
 */
private FlowSnippetDTO createProcessGroupContentsDto(final ProcessGroup group, final boolean recurse) {
    if (group == null) {
        return null;
    }

    final FlowSnippetDTO dto = new FlowSnippetDTO();

    for (final ProcessorNode procNode : group.getProcessors()) {
        dto.getProcessors().add(createProcessorDto(procNode));
    }

    for (final Connection connNode : group.getConnections()) {
        dto.getConnections().add(createConnectionDto(connNode));
    }

    for (final Label label : group.getLabels()) {
        dto.getLabels().add(createLabelDto(label));
    }

    for (final Funnel funnel : group.getFunnels()) {
        dto.getFunnels().add(createFunnelDto(funnel));
    }

    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        if (recurse) {
            dto.getProcessGroups().add(createProcessGroupDto(childGroup, recurse));
        } else {
            dto.getProcessGroups().add(createConciseProcessGroupDto(childGroup));
        }
    }

    for (final RemoteProcessGroup remoteProcessGroup : group.getRemoteProcessGroups()) {
        dto.getRemoteProcessGroups().add(createRemoteProcessGroupDto(remoteProcessGroup));
    }

    for (final Port inputPort : group.getInputPorts()) {
        dto.getInputPorts().add(createPortDto(inputPort));
    }

    for (final Port outputPort : group.getOutputPorts()) {
        dto.getOutputPorts().add(createPortDto(outputPort));
    }

    return dto;
}
 
Example 5
Source File: StandardProcessorDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Set<ProcessorNode> getProcessors(String groupId) {
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    return group.getProcessors();
}
 
Example 6
Source File: SnippetUtils.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * 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 Map<String, FlowSnippetDTO> contentsByGroup, final String highestGroupId) {

    final FlowSnippetDTO contents = dto.getContents();
    contentsByGroup.put(dto.getId(), contents);
    if (contents == null) {
        return;
    }


    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))
            .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, contentsByGroup, highestGroupId);
    }
}
 
Example 7
Source File: SnippetUtils.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * 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.getEffectivePropertyValues()).stream()
            .filter(allServicesReferenced::add)
            .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(ComponentDTO::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);
    }
}