Search in sources :

Example 81 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class StandardSnippetDAO method createSnippet.

@Override
public Snippet createSnippet(final SnippetDTO snippetDTO) {
    // create the snippet request
    final StandardSnippet snippet = new StandardSnippet();
    snippet.setId(snippetDTO.getId());
    snippet.setParentGroupId(snippetDTO.getParentGroupId());
    snippet.addProcessors(mapDtoToRevision(snippetDTO.getProcessors()));
    snippet.addProcessGroups(mapDtoToRevision(snippetDTO.getProcessGroups()));
    snippet.addRemoteProcessGroups(mapDtoToRevision(snippetDTO.getRemoteProcessGroups()));
    snippet.addInputPorts(mapDtoToRevision(snippetDTO.getInputPorts()));
    snippet.addOutputPorts(mapDtoToRevision(snippetDTO.getOutputPorts()));
    snippet.addConnections(mapDtoToRevision(snippetDTO.getConnections()));
    snippet.addLabels(mapDtoToRevision(snippetDTO.getLabels()));
    snippet.addFunnels(mapDtoToRevision(snippetDTO.getFunnels()));
    // ensure this snippet isn't empty
    if (snippet.isEmpty()) {
        throw new IllegalArgumentException("Cannot create an empty snippet.");
    }
    // ensure the parent group exist
    final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
    if (processGroup == null) {
        throw new IllegalArgumentException("The specified parent process group could not be found.");
    }
    // store the snippet
    flowController.getSnippetManager().addSnippet(snippet);
    return snippet;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Example 82 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class StandardSnippetDAO method verifyDeleteSnippetComponents.

@Override
public void verifyDeleteSnippetComponents(String snippetId) {
    final Snippet snippet = locateSnippet(snippetId);
    // ensure the parent group exist
    final ProcessGroup processGroup = flowController.getGroup(snippet.getParentGroupId());
    if (processGroup == null) {
        throw new IllegalArgumentException("The specified parent process group could not be found.");
    }
    // verify the processGroup can remove the snippet
    processGroup.verifyCanDelete(snippet);
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) Snippet(org.apache.nifi.controller.Snippet) StandardSnippet(org.apache.nifi.controller.StandardSnippet)

Example 83 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class StandardTemplateDAO method instantiateTemplate.

@Override
public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String encodingVersion, FlowSnippetDTO requestSnippet, String idGenerationSeed) {
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    try {
        // copy the template which pre-processes all ids
        FlowSnippetDTO snippet = snippetUtils.copy(requestSnippet, group, idGenerationSeed, false);
        // calculate scaling factors based on the template encoding version attempt to parse the encoding version.
        // get the major version, or 0 if no version could be parsed
        final FlowEncodingVersion templateEncodingVersion = FlowEncodingVersion.parse(encodingVersion);
        int templateEncodingMajorVersion = templateEncodingVersion != null ? templateEncodingVersion.getMajorVersion() : 0;
        // based on the major version < 1, use the default scaling factors.  Otherwise, don't scale (use factor of 1.0)
        double factorX = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_X : 1.0;
        double factorY = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_Y : 1.0;
        // reposition and scale the template contents
        org.apache.nifi.util.SnippetUtils.moveAndScaleSnippet(snippet, originX, originY, factorX, factorY);
        // find all the child process groups in each process group in the top level of this snippet
        final List<ProcessGroupDTO> childProcessGroups = org.apache.nifi.util.SnippetUtils.findAllProcessGroups(snippet);
        // scale (but don't reposition) child process groups
        childProcessGroups.stream().forEach(processGroup -> org.apache.nifi.util.SnippetUtils.scaleSnippet(processGroup.getContents(), factorX, factorY));
        // instantiate the template into this group
        flowController.instantiateSnippet(group, snippet);
        return snippet;
    } catch (ProcessorInstantiationException pie) {
        throw new NiFiCoreException(String.format("Unable to instantiate template because processor type '%s' is unknown to this NiFi.", StringUtils.substringAfterLast(pie.getMessage(), ".")));
    }
}
Also used : FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) FlowEncodingVersion(org.apache.nifi.controller.serialization.FlowEncodingVersion)

Example 84 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class StandardTemplateDAO method createTemplate.

@Override
public Template createTemplate(TemplateDTO templateDTO, String groupId) {
    final ProcessGroup processGroup = flowController.getGroup(groupId);
    if (processGroup == null) {
        throw new ResourceNotFoundException("Could not find Process Group with ID " + groupId);
    }
    verifyAdd(templateDTO.getName(), processGroup);
    TemplateUtils.scrubTemplate(templateDTO);
    final Template template = new Template(templateDTO);
    processGroup.addTemplate(template);
    return template;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) Template(org.apache.nifi.controller.Template)

Example 85 with ProcessGroup

use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.

the class SnippetUtils method resolveNameConflicts.

private void resolveNameConflicts(final FlowSnippetDTO snippetContents, final ProcessGroup group) {
    // get a list of all names of ports so that we can rename the ports as needed.
    final List<String> existingPortNames = new ArrayList<>();
    for (final Port inputPort : group.getInputPorts()) {
        existingPortNames.add(inputPort.getName());
    }
    for (final Port outputPort : group.getOutputPorts()) {
        existingPortNames.add(outputPort.getName());
    }
    // rename ports
    if (snippetContents.getInputPorts() != null) {
        for (final PortDTO portDTO : snippetContents.getInputPorts()) {
            String portName = portDTO.getName();
            while (existingPortNames.contains(portName)) {
                portName = "Copy of " + portName;
            }
            portDTO.setName(portName);
            existingPortNames.add(portDTO.getName());
        }
    }
    if (snippetContents.getOutputPorts() != null) {
        for (final PortDTO portDTO : snippetContents.getOutputPorts()) {
            String portName = portDTO.getName();
            while (existingPortNames.contains(portName)) {
                portName = "Copy of " + portName;
            }
            portDTO.setName(portName);
            existingPortNames.add(portDTO.getName());
        }
    }
    // get a list of all names of process groups so that we can rename as needed.
    final Set<String> groupNames = new HashSet<>();
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        groupNames.add(childGroup.getName());
    }
    if (snippetContents.getProcessGroups() != null) {
        for (final ProcessGroupDTO groupDTO : snippetContents.getProcessGroups()) {
            // 'Copy of...' so we do this only if there is no Version Control Information present.
            if (groupDTO.getVersionControlInformation() == null) {
                String groupName = groupDTO.getName();
                while (groupNames.contains(groupName)) {
                    groupName = "Copy of " + groupName;
                }
                groupDTO.setName(groupName);
            }
            groupNames.add(groupDTO.getName());
        }
    }
}
Also used : RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) 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) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ProcessGroup (org.apache.nifi.groups.ProcessGroup)185 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)97 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)68 ProcessorNode (org.apache.nifi.controller.ProcessorNode)50 Port (org.apache.nifi.connectable.Port)40 RootGroupPort (org.apache.nifi.remote.RootGroupPort)37 Connection (org.apache.nifi.connectable.Connection)36 ArrayList (java.util.ArrayList)35 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)35 Test (org.junit.Test)35 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)34 HashSet (java.util.HashSet)32 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)32 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)29 FlowController (org.apache.nifi.controller.FlowController)27 Connectable (org.apache.nifi.connectable.Connectable)26 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)25 Funnel (org.apache.nifi.connectable.Funnel)24 List (java.util.List)22 Label (org.apache.nifi.controller.label.Label)22