Search in sources :

Example 1 with NifiVisitableConnection

use of com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableConnection in project kylo by Teradata.

the class NifiConnectionOrderVisitor method getSourceProcessors.

public List<NifiVisitableProcessor> getSourceProcessors(ConnectionDTO connection) {
    ConnectableDTO source = connection.getSource();
    List<NifiVisitableProcessor> sourceProcessors = new ArrayList<>();
    if (source != null) {
        if ("INPUT_PORT".equalsIgnoreCase(source.getType())) {
            NifiVisitableProcessGroup group = visitedProcessGroups.get(source.getGroupId());
            if (group == null) {
                group = processGroup;
            }
            NifiVisitableProcessGroup parent = visitedProcessGroups.get(group.getDto().getParentGroupId());
            // if the parent is null the parent is the starting process group
            if (parent == null) {
                parent = processGroup;
            }
            ConnectionDTO conn = parent.getConnectionMatchingDestinationId(source.getId());
            if (conn == null) {
                // if its null get it from the cache and process with that.
                conn = cache.getProcessGroupCache().values().stream().flatMap(g -> g.getContents().getConnections().stream()).filter(connectionDTO -> connectionDTO.getDestination().getId().equalsIgnoreCase(source.getId())).findFirst().orElse(null);
            }
            if (conn != null && conn != connection) {
                // get the processor whos source matches this connection Id
                sourceProcessors = getSourceProcessors(conn);
            // assign the inputPortProcessor == the the destination of this connection
            }
            List<NifiVisitableProcessor> inputProcessors = getDestinationProcessors(connection, false);
            if (inputProcessors != null) {
                for (NifiVisitableProcessor inputProcessor : inputProcessors) {
                    currentProcessGroup.addInputPortProcessor(source.getId(), inputProcessor);
                }
            }
        } else if ("OUTPUT_PORT".equals(source.getType())) {
            // get the sources group id then get the ending processor for that group
            NifiVisitableProcessGroup group = visitedProcessGroups.get(source.getGroupId());
            if (group != null) {
                Set<NifiVisitableProcessor> sources = group.getOutputPortProcessors(source.getId());
                if (sourceProcessors != null && sources != null) {
                    sourceProcessors.addAll(sources);
                }
            /*
                   If a process group is connected to another process group without any processors there will be no source processors
                    having sourceProcessors as null here is ok.
                    */
            }
        } else if ("FUNNEL".equalsIgnoreCase(source.getType())) {
            List<ConnectionDTO> passThroughConnections = NifiConnectionUtil.findConnectionsMatchingDestinationId(currentProcessGroup.getDto().getContents().getConnections(), connection.getSource().getId());
            if (passThroughConnections != null) {
                for (ConnectionDTO dto : passThroughConnections) {
                    ConnectionDTO newConnection = new ConnectionDTO();
                    newConnection.setSource(dto.getSource());
                    newConnection.setId(connection.getSource().getId());
                    newConnection.setDestination(connection.getDestination());
                    visitConnection(new NifiVisitableConnection(currentProcessGroup, newConnection));
                }
            }
        } else if ("PROCESSOR".equals(source.getType())) {
            NifiVisitableProcessor sourceProcessor = getConnectionProcessor(source.getGroupId(), source.getId());
            sourceProcessors.add(sourceProcessor);
        }
        for (NifiVisitableProcessor sourceProcessor : sourceProcessors) {
            sourceProcessor.addDestinationConnectionIdentifier(connection);
        }
    }
    return sourceProcessors;
}
Also used : RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) Logger(org.slf4j.Logger) ProcessorConfigDTO(org.apache.nifi.web.api.dto.ProcessorConfigDTO) LoggerFactory(org.slf4j.LoggerFactory) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) Set(java.util.Set) NifiProcessUtil(com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil) HashMap(java.util.HashMap) NifiVisitableProcessor(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionUtil(com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil) NifiVisitableConnection(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableConnection) Map(java.util.Map) NifiFlowVisitor(com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowVisitor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) NifiVisitableProcessor(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessor) Set(java.util.Set) HashSet(java.util.HashSet) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ArrayList(java.util.ArrayList) NifiVisitableConnection(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableConnection) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Aggregations

NiFiRestClient (com.thinkbiganalytics.nifi.rest.client.NiFiRestClient)1 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)1 NifiFlowVisitor (com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowVisitor)1 NifiVisitableConnection (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableConnection)1 NifiVisitableProcessGroup (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup)1 NifiVisitableProcessor (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessor)1 NifiConnectionUtil (com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil)1 NifiProcessUtil (com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)1 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)1 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)1 ProcessorConfigDTO (org.apache.nifi.web.api.dto.ProcessorConfigDTO)1 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)1 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)1