Java Code Examples for org.apache.nifi.web.api.dto.FlowSnippetDTO#getProcessGroups()

The following examples show how to use org.apache.nifi.web.api.dto.FlowSnippetDTO#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: StandardFlowSnippet.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void verifyControllerServicesInSnippet(final FlowSnippetDTO templateContents, final Map<String, Set<BundleCoordinate>> supportedTypes) {
    if (templateContents.getControllerServices() != null) {
        templateContents.getControllerServices().forEach(controllerService -> {
            if (supportedTypes.containsKey(controllerService.getType())) {
                if (controllerService.getBundle() == null) {
                    throw new IllegalArgumentException("Controller Service bundle must be specified.");
                }

                verifyBundleInSnippet(controllerService.getBundle(), supportedTypes.get(controllerService.getType()));
            } else {
                throw new IllegalStateException("Invalid Controller Service Type: " + controllerService.getType());
            }
        });
    }

    if (templateContents.getProcessGroups() != null) {
        templateContents.getProcessGroups().forEach(processGroup -> verifyControllerServicesInSnippet(processGroup.getContents(), supportedTypes));
    }
}
 
Example 2
Source File: NiFiClientUtil.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void waitForProcessorsStopped(final ProcessGroupDTO group) throws IOException, NiFiClientException {
    final FlowSnippetDTO groupContents = group.getContents();
    if (groupContents == null) {
        return;
    }

    for (final ProcessorDTO processor : groupContents.getProcessors()) {
        try {
            waitForStoppedProcessor(processor.getId());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new NiFiClientException("Interrupted while waiting for Processor with ID " + processor.getId() + " to stop");
        }
    }

    for (final ProcessGroupDTO child : groupContents.getProcessGroups()) {
        waitForProcessorsStopped(child);
    }
}
 
Example 3
Source File: StandardFlowSnippet.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void verifyProcessorsInSnippet(final FlowSnippetDTO templateContents, final Map<String, Set<BundleCoordinate>> supportedTypes) {
    if (templateContents.getProcessors() != null) {
        templateContents.getProcessors().forEach(processor -> {
            if (processor.getBundle() == null) {
                throw new IllegalArgumentException("Processor bundle must be specified.");
            }

            if (supportedTypes.containsKey(processor.getType())) {
                verifyBundleInSnippet(processor.getBundle(), supportedTypes.get(processor.getType()));
            } else {
                throw new IllegalStateException("Invalid Processor Type: " + processor.getType());
            }
        });
    }

    if (templateContents.getProcessGroups() != null) {
        templateContents.getProcessGroups().forEach(processGroup -> verifyProcessorsInSnippet(processGroup.getContents(), supportedTypes));
    }
}
 
Example 4
Source File: StandardSnippetDAO.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void lookupSensitiveProperties(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            lookupSensitiveProcessorProperties(snippet.getProcessors());
        }

        if (snippet.getControllerServices() != null) {
            lookupSensitiveControllerServiceProperties(snippet.getControllerServices());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            for (final ProcessGroupDTO group : snippet.getProcessGroups()) {
                lookupSensitiveProperties(group.getContents());
            }
        }
    }
}
 
Example 5
Source File: StandardSnippetDAO.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void lookupSensitiveProperties(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            lookupSensitiveProcessorProperties(snippet.getProcessors());
        }

        if (snippet.getControllerServices() != null) {
            lookupSensitiveControllerServiceProperties(snippet.getControllerServices());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            for (final ProcessGroupDTO group : snippet.getProcessGroups()) {
                lookupSensitiveProperties(group.getContents());
            }
        }
    }
}
 
Example 6
Source File: StandardAuthorizableLookup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates temporary instances of all processors and controller services found in the specified snippet.
 *
 * @param snippet               snippet
 * @param processors            processors
 * @param controllerServices    controller services
 */
private void createTemporaryProcessorsAndControllerServices(final FlowSnippetDTO snippet,
                                                            final Set<ConfigurableComponentAuthorizable> processors,
                                                            final Set<ConfigurableComponentAuthorizable> controllerServices) {

    if (snippet == null) {
        return;
    }

    if (snippet.getProcessors() != null) {
        processors.addAll(snippet.getProcessors().stream().map(processor -> getProcessorByType(processor.getType())).collect(Collectors.toSet()));
    }

    if (snippet.getControllerServices() != null) {
        controllerServices.addAll(snippet.getControllerServices().stream().map(controllerService -> getControllerServiceByType(controllerService.getType())).collect(Collectors.toSet()));
    }

    if (snippet.getProcessGroups() != null) {
        snippet.getProcessGroups().stream().forEach(group -> createTemporaryProcessorsAndControllerServices(group.getContents(), processors, controllerServices));
    }
}
 
Example 7
Source File: SnippetUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets all components, but not connections, that are part of the specified template.
 *
 * @param contents snippet
 * @return component dtos
 */
private static Collection<ComponentDTO> getComponents(FlowSnippetDTO contents) {
    final Collection<ComponentDTO> components = new HashSet<>();

    // add all components
    if (contents.getInputPorts() != null) {
        components.addAll(contents.getInputPorts());
    }
    if (contents.getLabels() != null) {
        components.addAll(contents.getLabels());
    }
    if (contents.getOutputPorts() != null) {
        components.addAll(contents.getOutputPorts());
    }
    if (contents.getProcessGroups() != null) {
        components.addAll(contents.getProcessGroups());
    }
    if (contents.getProcessors() != null) {
        components.addAll(contents.getProcessors());
    }
    if (contents.getFunnels() != null) {
        components.addAll(contents.getFunnels());
    }
    if (contents.getRemoteProcessGroups() != null) {
        components.addAll(contents.getRemoteProcessGroups());
    }

    return components;
}
 
Example 8
Source File: SnippetUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all {@link ProcessGroupDTO}s in the given {@link FlowSnippetDTO}.
 * @param snippet containing the child {@link ProcessGroupDTO}s to be returned
 * @return List of child {@link ProcessGroupDTO}s found in the given {@link FlowSnippetDTO}.
 */
public static List<ProcessGroupDTO> findAllProcessGroups(FlowSnippetDTO snippet) {
    final List<ProcessGroupDTO> allProcessGroups = new ArrayList<>(snippet.getProcessGroups());
    for (final ProcessGroupDTO childGroup : snippet.getProcessGroups()) {
        allProcessGroups.addAll(findAllProcessGroups(childGroup.getContents()));
    }
    return allProcessGroups;
}
 
Example 9
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void updateControllerServiceIdentifiers(final FlowSnippetDTO snippet, final Map<String, String> serviceIdMap) {
    final Set<ProcessorDTO> processors = snippet.getProcessors();
    if (processors != null) {
        for (final ProcessorDTO processor : processors) {
            updateControllerServiceIdentifiers(processor.getConfig(), serviceIdMap);
        }
    }

    for (final ProcessGroupDTO processGroupDto : snippet.getProcessGroups()) {
        updateControllerServiceIdentifiers(processGroupDto.getContents(), serviceIdMap);
    }
}
 
Example 10
Source File: TemplateUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private static void scrubSnippet(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            scrubProcessors(snippet.getProcessors());
        }

        // go through each connection if specified
        if (snippet.getConnections() != null) {
            scrubConnections(snippet.getConnections());
        }

        // go through each remote process group if specified
        if (snippet.getRemoteProcessGroups() != null) {
            scrubRemoteProcessGroups(snippet.getRemoteProcessGroups());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            scrubProcessGroups(snippet.getProcessGroups());
        }

        // go through each controller service if specified
        if (snippet.getControllerServices() != null) {
            scrubControllerServices(snippet.getControllerServices());
        }
    }
}
 
Example 11
Source File: TemplateUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void escapeParameterReferences(final FlowSnippetDTO flowSnippetDTO) {
    flowSnippetDTO.getProcessors().forEach(TemplateUtils::escapeParameterReferences);
    flowSnippetDTO.getControllerServices().forEach(TemplateUtils::escapeParameterReferences);

    for (final ProcessGroupDTO groupDto : flowSnippetDTO.getProcessGroups()) {
        escapeParameterReferences(groupDto.getContents());
    }
}
 
Example 12
Source File: TemplateUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void scrubSnippet(final FlowSnippetDTO snippet) {
    // ensure that contents have been specified
    if (snippet != null) {
        // go through each processor if specified
        if (snippet.getProcessors() != null) {
            scrubProcessors(snippet.getProcessors());
        }

        // go through each connection if specified
        if (snippet.getConnections() != null) {
            scrubConnections(snippet.getConnections());
        }

        // go through each remote process group if specified
        if (snippet.getRemoteProcessGroups() != null) {
            scrubRemoteProcessGroups(snippet.getRemoteProcessGroups());
        }

        // go through each process group if specified
        if (snippet.getProcessGroups() != null) {
            scrubProcessGroups(snippet.getProcessGroups());
        }

        // go through each controller service if specified
        if (snippet.getControllerServices() != null) {
            scrubControllerServices(snippet.getControllerServices());
        }
    }
}
 
Example 13
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Finds all {@link ProcessGroupDTO}s in the given {@link FlowSnippetDTO}.
 * @param snippet containing the child {@link ProcessGroupDTO}s to be returned
 * @return List of child {@link ProcessGroupDTO}s found in the given {@link FlowSnippetDTO}.
 */
public static List<ProcessGroupDTO> findAllProcessGroups(FlowSnippetDTO snippet) {
    final List<ProcessGroupDTO> allProcessGroups = new ArrayList<>(snippet.getProcessGroups());
    for (final ProcessGroupDTO childGroup : snippet.getProcessGroups()) {
        allProcessGroups.addAll(findAllProcessGroups(childGroup.getContents()));
    }
    return allProcessGroups;
}
 
Example 14
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Gets all components, but not connections, that are part of the specified template.
 *
 * @param contents snippet
 * @return component dtos
 */
private static Collection<ComponentDTO> getComponents(FlowSnippetDTO contents) {
    final Collection<ComponentDTO> components = new HashSet<>();

    // add all components
    if (contents.getInputPorts() != null) {
        components.addAll(contents.getInputPorts());
    }
    if (contents.getLabels() != null) {
        components.addAll(contents.getLabels());
    }
    if (contents.getOutputPorts() != null) {
        components.addAll(contents.getOutputPorts());
    }
    if (contents.getProcessGroups() != null) {
        components.addAll(contents.getProcessGroups());
    }
    if (contents.getProcessors() != null) {
        components.addAll(contents.getProcessors());
    }
    if (contents.getFunnels() != null) {
        components.addAll(contents.getFunnels());
    }
    if (contents.getRemoteProcessGroups() != null) {
        components.addAll(contents.getRemoteProcessGroups());
    }

    return components;
}
 
Example 15
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static void verifyNoVersionControlConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup destination) {
    final List<VersionControlInformationDTO> vcis = new ArrayList<>();
    for (final ProcessGroupDTO childGroup : snippetContents.getProcessGroups()) {
        findAllVersionControlInfo(childGroup, vcis);
    }

    verifyNoDuplicateVersionControlInfoDtos(destination, vcis);
}
 
Example 16
Source File: SnippetUtils.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static void findAllVersionControlInfo(final ProcessGroupDTO dto, final List<VersionControlInformationDTO> found) {
    final VersionControlInformationDTO vci = dto.getVersionControlInformation();
    if (vci != null) {
        found.add(vci);
    }

    final FlowSnippetDTO contents = dto.getContents();
    if (contents != null) {
        for (final ProcessGroupDTO child : contents.getProcessGroups()) {
            findAllVersionControlInfo(child, found);
        }
    }
}
 
Example 17
Source File: SnippetUtils.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void updateControllerServiceIdentifiers(final FlowSnippetDTO snippet, final Map<String, String> serviceIdMap) {
    final Set<ProcessorDTO> processors = snippet.getProcessors();
    if (processors != null) {
        for (final ProcessorDTO processor : processors) {
            updateControllerServiceIdentifiers(processor.getConfig(), serviceIdMap);
        }
    }

    for (final ProcessGroupDTO processGroupDto : snippet.getProcessGroups()) {
        updateControllerServiceIdentifiers(processGroupDto.getContents(), serviceIdMap);
    }
}
 
Example 18
Source File: StandardFlowServiceTest.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void assertEquals(FlowSnippetDTO expected, FlowSnippetDTO actual) {
    if (expected == null && actual == null) {
        return;
    }

    // check connections
    Assert.assertEquals(expected.getConnections().size(), actual.getConnections().size());
    List<ConnectionDTO> expectedConnections = new ArrayList<>(expected.getConnections());
    List<ConnectionDTO> actualConnections = new ArrayList<>(actual.getConnections());
    for (int i = 0; i < expectedConnections.size(); i++) {
        assertEquals(expectedConnections.get(i), actualConnections.get(i));
    }

    // check groups
    Assert.assertEquals(expected.getProcessGroups().size(), actual.getProcessGroups().size());
    List<ProcessGroupDTO> expectedProcessGroups = new ArrayList<>(expected.getProcessGroups());
    List<ProcessGroupDTO> actualProcessGroups = new ArrayList<>(actual.getProcessGroups());
    for (int i = 0; i < expectedProcessGroups.size(); i++) {
        assertEquals(expectedProcessGroups.get(i), actualProcessGroups.get(i));
    }

    // check input ports
    Assert.assertEquals(expected.getInputPorts().size(), actual.getInputPorts().size());
    List<PortDTO> expectedInputPorts = new ArrayList<>(expected.getInputPorts());
    List<PortDTO> actualInputPort = new ArrayList<>(actual.getInputPorts());
    for (int i = 0; i < expectedInputPorts.size(); i++) {
        assertEquals(expectedInputPorts.get(i), actualInputPort.get(i));
    }

    // check labels
    Assert.assertEquals(expected.getLabels().size(), actual.getLabels().size());
    List<LabelDTO> expectedLabels = new ArrayList<>(expected.getLabels());
    List<LabelDTO> actualLabels = new ArrayList<>(actual.getLabels());
    for (int i = 0; i < expectedLabels.size(); i++) {
        assertEquals(expectedLabels.get(i), actualLabels.get(i));
    }

    // check output ports
    Assert.assertEquals(expected.getOutputPorts().size(), actual.getOutputPorts().size());
    List<PortDTO> expectedOutputPorts = new ArrayList<>(expected.getOutputPorts());
    List<PortDTO> actualOutputPort = new ArrayList<>(actual.getOutputPorts());
    for (int i = 0; i < expectedOutputPorts.size(); i++) {
        assertEquals(expectedOutputPorts.get(i), actualOutputPort.get(i));
    }

    // check processors
    Assert.assertEquals(expected.getProcessors().size(), actual.getProcessors().size());
    List<ProcessorDTO> expectedProcessors = new ArrayList<>(expected.getProcessors());
    List<ProcessorDTO> actualProcessors = new ArrayList<>(actual.getProcessors());
    for (int i = 0; i < expectedProcessors.size(); i++) {
        assertEquals(expectedProcessors.get(i), actualProcessors.get(i));
    }
}
 
Example 19
Source File: StandardFlowServiceTest.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void assertEquals(FlowSnippetDTO expected, FlowSnippetDTO actual) {
    if (expected == null && actual == null) {
        return;
    }

    // check connections
    Assert.assertEquals(expected.getConnections().size(), actual.getConnections().size());
    List<ConnectionDTO> expectedConnections = new ArrayList<>(expected.getConnections());
    List<ConnectionDTO> actualConnections = new ArrayList<>(actual.getConnections());
    for (int i = 0; i < expectedConnections.size(); i++) {
        assertEquals(expectedConnections.get(i), actualConnections.get(i));
    }

    // check groups
    Assert.assertEquals(expected.getProcessGroups().size(), actual.getProcessGroups().size());
    List<ProcessGroupDTO> expectedProcessGroups = new ArrayList<>(expected.getProcessGroups());
    List<ProcessGroupDTO> actualProcessGroups = new ArrayList<>(actual.getProcessGroups());
    for (int i = 0; i < expectedProcessGroups.size(); i++) {
        assertEquals(expectedProcessGroups.get(i), actualProcessGroups.get(i));
    }

    // check input ports
    Assert.assertEquals(expected.getInputPorts().size(), actual.getInputPorts().size());
    List<PortDTO> expectedInputPorts = new ArrayList<>(expected.getInputPorts());
    List<PortDTO> actualInputPort = new ArrayList<>(actual.getInputPorts());
    for (int i = 0; i < expectedInputPorts.size(); i++) {
        assertEquals(expectedInputPorts.get(i), actualInputPort.get(i));
    }

    // check labels
    Assert.assertEquals(expected.getLabels().size(), actual.getLabels().size());
    List<LabelDTO> expectedLabels = new ArrayList<>(expected.getLabels());
    List<LabelDTO> actualLabels = new ArrayList<>(actual.getLabels());
    for (int i = 0; i < expectedLabels.size(); i++) {
        assertEquals(expectedLabels.get(i), actualLabels.get(i));
    }

    // check output ports
    Assert.assertEquals(expected.getOutputPorts().size(), actual.getOutputPorts().size());
    List<PortDTO> expectedOutputPorts = new ArrayList<>(expected.getOutputPorts());
    List<PortDTO> actualOutputPort = new ArrayList<>(actual.getOutputPorts());
    for (int i = 0; i < expectedOutputPorts.size(); i++) {
        assertEquals(expectedOutputPorts.get(i), actualOutputPort.get(i));
    }

    // check processors
    Assert.assertEquals(expected.getProcessors().size(), actual.getProcessors().size());
    List<ProcessorDTO> expectedProcessors = new ArrayList<>(expected.getProcessors());
    List<ProcessorDTO> actualProcessors = new ArrayList<>(actual.getProcessors());
    for (int i = 0; i < expectedProcessors.size(); i++) {
        assertEquals(expectedProcessors.get(i), actualProcessors.get(i));
    }
}