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

The following examples show how to use org.apache.nifi.groups.ProcessGroup#getProcessGroups() . 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: NiFiRegistryFlowMapper.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void mapParameterContexts(final ProcessGroup processGroup, final boolean mapDescendantVersionedFlows,
                                  final Map<String, VersionedParameterContext> parameterContexts) {
    final ParameterContext parameterContext = processGroup.getParameterContext();
    if (parameterContext != null) {
        // map this process group's parameter context and add to the collection
        final Set<VersionedParameter> parameters = parameterContext.getParameters().values().stream()
                .map(this::mapParameter)
                .collect(Collectors.toSet());

        final VersionedParameterContext versionedContext = new VersionedParameterContext();
        versionedContext.setName(parameterContext.getName());
        versionedContext.setParameters(parameters);
        parameterContexts.put(versionedContext.getName(), versionedContext);
    }

    for (final ProcessGroup child : processGroup.getProcessGroups()) {
        // only include child process group parameter contexts if boolean indicator is true or process group is unversioned
        if (mapDescendantVersionedFlows || child.getVersionControlInformation() == null) {
            mapParameterContexts(child, mapDescendantVersionedFlows, parameterContexts);
        }
    }
}
 
Example 2
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 3
Source File: StandardProcessGroupDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Set<ProcessGroup> getProcessGroups(String parentGroupId) {
    ProcessGroup group = locateProcessGroup(flowController, parentGroupId);
    return group.getProcessGroups();
}
 
Example 4
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 5
Source File: StandardProcessGroupDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Set<ProcessGroup> getProcessGroups(String parentGroupId) {
    ProcessGroup group = locateProcessGroup(flowController, parentGroupId);
    return group.getProcessGroups();
}
 
Example 6
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);
    }
}