Search in sources :

Example 31 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class AlignProcessGroupComponents method createLayoutGroups.

/**
 * Group the items together to create the various LayoutGroups needed for different Rendering
 */
private void createLayoutGroups() {
    Map<String, Set<ProcessGroupDTO>> outputPortIdToGroup = new HashMap<String, Set<ProcessGroupDTO>>();
    groupIdToOutputPorts = new HashMap<>();
    Map<String, Set<ProcessGroupDTO>> inputPortIdToGroup = new HashMap<String, Set<ProcessGroupDTO>>();
    groupIdToInputPorts = new HashMap<>();
    Map<String, Set<String>> groupIdToGroup = new HashMap<>();
    List<ProcessGroupDTO> connectedGroups = new LinkedList<>();
    parentProcessGroup.getContents().getConnections().stream().filter(connectionDTO -> (isOutputPortToGroupConnection(connectionDTO) || isGroupToGroupConnection(connectionDTO) || isInputPortToGroupConnection(connectionDTO))).forEach(connectionDTO -> {
        PortDTO outputPort = outputPortMap.get(connectionDTO.getDestination().getId()) == null ? outputPortMap.get(connectionDTO.getSource().getId()) : outputPortMap.get(connectionDTO.getDestination().getId());
        PortDTO inputPort = inputPortMap.get(connectionDTO.getSource().getId()) == null ? inputPortMap.get(connectionDTO.getDestination().getId()) : inputPortMap.get(connectionDTO.getSource().getId());
        ProcessGroupDTO destinationGroup = processGroupDTOMap.get(connectionDTO.getDestination().getGroupId());
        ProcessGroupDTO sourceGroup = processGroupDTOMap.get(connectionDTO.getSource().getGroupId());
        if (outputPort != null) {
            ProcessGroupDTO processGroup = destinationGroup == null ? sourceGroup : destinationGroup;
            outputPortIdToGroup.computeIfAbsent(outputPort.getId(), (key) -> new HashSet<ProcessGroupDTO>()).add(processGroup);
            groupIdToOutputPorts.computeIfAbsent(processGroup.getId(), (key) -> new HashSet<PortDTO>()).add(outputPort);
            if (processGroupWithConnectionsMap.containsKey(processGroup.getId())) {
                processGroupWithConnectionsMap.get(processGroup.getId()).addConnection(connectionDTO).addPort(outputPort);
            }
        }
        if (inputPort != null) {
            ProcessGroupDTO processGroup = destinationGroup == null ? sourceGroup : destinationGroup;
            inputPortIdToGroup.computeIfAbsent(inputPort.getId(), (key) -> new HashSet<ProcessGroupDTO>()).add(processGroup);
            groupIdToInputPorts.computeIfAbsent(processGroup.getId(), (key) -> new HashSet<PortDTO>()).add(inputPort);
            if (processGroupWithConnectionsMap.containsKey(processGroup.getId())) {
                processGroupWithConnectionsMap.get(processGroup.getId()).addConnection(connectionDTO).addPort(outputPort);
            }
        } else if (destinationGroup != null && sourceGroup != null) {
            groupIdToGroup.computeIfAbsent(sourceGroup.getId(), (key) -> new HashSet<String>()).add(destinationGroup.getId());
        }
    });
    // group port connections together
    groupIdToOutputPorts.entrySet().stream().forEach(entry -> {
        String processGroupId = entry.getKey();
        String portKey = entry.getValue().stream().map(portDTO -> portDTO.getId()).sorted().collect(Collectors.joining(","));
        portKey = "AAA" + portKey;
        layoutGroups.computeIfAbsent(portKey, (key) -> new ProcessGroupToOutputPort(entry.getValue())).add(processGroupDTOMap.get(processGroupId));
    });
    // group port connections together
    groupIdToInputPorts.entrySet().stream().forEach(entry -> {
        String processGroupId = entry.getKey();
        String portKey = entry.getValue().stream().map(portDTO -> portDTO.getId()).sorted().collect(Collectors.joining(","));
        portKey = "BBB" + portKey;
        layoutGroups.computeIfAbsent(portKey, (key) -> new InputPortToProcessGroup(entry.getValue())).add(processGroupDTOMap.get(processGroupId));
    });
    groupIdToGroup.entrySet().stream().forEach(entry -> {
        String sourceGroupId = entry.getKey();
        String processGroupKey = entry.getValue().stream().sorted().collect(Collectors.joining(","));
        processGroupKey = "CCC" + processGroupKey;
        layoutGroups.computeIfAbsent(processGroupKey, (key) -> new ProcessGroupToProcessGroup(entry.getValue())).add(processGroupDTOMap.get(entry.getKey()));
    });
    // add in any groups that dont have connections to ports
    processGroupDTOMap.values().stream().filter(processGroupDTO -> !groupIdToGroup.values().stream().flatMap(set -> set.stream()).collect(Collectors.toSet()).contains(processGroupDTO.getId()) && !groupIdToInputPorts.containsKey(processGroupDTO.getId()) && !groupIdToOutputPorts.containsKey(processGroupDTO.getId()) && !groupIdToGroup.containsKey(processGroupDTO.getId())).forEach(group -> {
        layoutGroups.computeIfAbsent("NO_PORTS", (key) -> new ProcessGroupWithoutConnections()).add(group);
    });
    // identify the sequence of processgroups if they are connected to each other
    List<String> startingProcessorIds = groupIdToGroup.keySet().stream().filter(id -> !groupIdToGroup.values().stream().anyMatch(ids -> ids.contains(id))).collect(Collectors.toList());
    connectedProcessGroups = new ArrayList<>();
    // start with these and attempt to create flows
    startingProcessorIds.forEach(id -> {
        LayoutOrder layoutOrder = new LayoutOrder(0, 0, processGroupDTOMap.get(id), new LinkedList<>());
        addPorts(layoutOrder, id);
        connectedProcessGroups.add(layoutOrder);
        buildLayoutOrder(layoutOrder, processGroupDTOMap.get(id), groupIdToGroup);
        ConnectedProcessGroup connectedProcessGroup = new ConnectedProcessGroup(layoutOrder);
        connectedProcessGroupsLayouts.add(connectedProcessGroup);
    });
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) Set(java.util.Set) TemplateCreationHelper(com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) HashSet(java.util.HashSet) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) Map(java.util.Map) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) LinkedList(java.util.LinkedList) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PortDTO(org.apache.nifi.web.api.dto.PortDTO) LinkedList(java.util.LinkedList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) HashSet(java.util.HashSet)

Example 32 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class AlignProcessGroupComponents method buildLayoutOrder.

private void buildLayoutOrder(LayoutOrder layoutOrder, ProcessGroupDTO group, Map<String, Set<String>> groupIdToGroup) {
    Set<String> next = groupIdToGroup.get(group.getId());
    if (next != null) {
        int nextLevel = layoutOrder.getLevel() + 1;
        List<ProcessGroupDTO> levelGroups = new LinkedList<>();
        next.forEach(dest -> {
            if (!processedProcessGroups.contains(dest)) {
                processedProcessGroups.add(dest);
                int order = 0;
                ProcessGroupDTO groupDTO = processGroupDTOMap.get(dest);
                levelGroups.add(groupDTO);
                LayoutOrder nextOrder = new LayoutOrder(nextLevel, order, groupDTO, levelGroups);
                addPorts(nextOrder, dest);
                layoutOrder.addNext(nextOrder);
                order++;
                buildLayoutOrder(nextOrder, groupDTO, groupIdToGroup);
            }
        });
    }
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) LinkedList(java.util.LinkedList)

Example 33 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class NifiConnectionOrderVisitor method searchConnectionMatchingSource.

private ConnectionDTO searchConnectionMatchingSource(String parentGroupId, String destinationId) {
    // search up to find the connection that matches this dest id
    try {
        ProcessGroupDTO parent = null;
        try {
            log.debug("fetch ProcessGroup for searchConnectionMatchingSource {} ", parentGroupId);
            parent = getGroup(parentGroupId);
        } catch (NifiComponentNotFoundException e) {
            log.debug("Exception searching Connection matching the source. Parent Group ID: " + parentGroupId + ", and destinationId of  " + destinationId);
        }
        if (parent != null) {
            // processGroup.getDto().setParent(parentParent.getProcessGroup());
            // get Contents of this parent
            NifiVisitableProcessGroup visitableProcessGroup = new NifiVisitableProcessGroup(parent);
            ConnectionDTO conn = visitableProcessGroup.getConnectionMatchingSourceId(destinationId);
            if (conn != null) {
                return conn;
            }
            if (conn == null && parent.getParentGroupId() != null) {
                return searchConnectionMatchingSource(parent.getParentGroupId(), destinationId);
            }
        }
    } catch (Exception e) {
        log.error("Exception searching Connection matching the source.  Parent Group ID: " + parentGroupId + ", and destinationId of  " + destinationId);
    }
    return null;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)

Example 34 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class NifiConnectionOrderVisitor method fetchProcessGroupForNameAndIdentifier.

private ProcessGroupDTO fetchProcessGroupForNameAndIdentifier(String groupId) {
    // fetch it
    ProcessGroupDTO processGroupEntity = null;
    try {
        try {
            log.debug("fetchProcessGroup {} ", groupId);
            processGroupEntity = getGroup(groupId);
        } catch (NifiComponentNotFoundException e) {
            log.debug("Unable to find the process group " + groupId);
        }
    } catch (Exception e) {
        log.error("Exception fetching the process group " + groupId);
    }
    return processGroupEntity;
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)

Example 35 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO in project kylo by Teradata.

the class NifiVisitableProcessGroup method accept.

/**
 * Visit this process group using the supplied visitor
 *
 * @param nifiVisitor the visitor
 */
@Override
public void accept(NifiFlowVisitor nifiVisitor) {
    if (dto.getContents() != null) {
        if (dto.getContents().getProcessors() != null) {
            for (ProcessorDTO processorDTO : dto.getContents().getProcessors()) {
                NifiVisitableProcessor processor = getOrCreateProcessor(nifiVisitor, processorDTO);
                nifiVisitor.visitProcessor(processor);
            }
        }
        if (dto.getContents().getProcessGroups() != null) {
            for (ProcessGroupDTO processGroupDTO : dto.getContents().getProcessGroups()) {
                if (processGroupDTO != null) {
                    nifiVisitor.visitProcessGroup(getOrCreateProcessGroup(nifiVisitor, processGroupDTO));
                }
            }
        }
        if (dto.getContents().getConnections() != null) {
            for (ConnectionDTO connectionDTO : dto.getContents().getConnections()) {
                nifiVisitor.visitConnection(new NifiVisitableConnection(this, connectionDTO));
            }
        }
        populateStartingAndEndingProcessors();
    }
}
Also used : ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Aggregations

ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)102 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)43 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)34 ArrayList (java.util.ArrayList)32 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)30 PortDTO (org.apache.nifi.web.api.dto.PortDTO)29 HashSet (java.util.HashSet)28 HashMap (java.util.HashMap)21 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)20 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)19 List (java.util.List)18 Set (java.util.Set)18 Collectors (java.util.stream.Collectors)17 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)17 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)16 Map (java.util.Map)15 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)14 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)14