Search in sources :

Example 1 with NifiVisitableProcessGroup

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

the class DefaultNiFiFlowVisitorClient method getProcessorsForFlow.

public Set<ProcessorDTO> getProcessorsForFlow(String processGroupId) throws NifiComponentNotFoundException {
    NifiVisitableProcessGroup group = getFlowOrder(processGroupId, null);
    Set<ProcessorDTO> processors = new HashSet<>();
    for (NifiVisitableProcessor p : group.getStartingProcessors()) {
        processors.addAll(p.getProcessors());
    }
    return processors;
}
Also used : NifiVisitableProcessor(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessor) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) HashSet(java.util.HashSet)

Example 2 with NifiVisitableProcessGroup

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

the class DefaultNiFiFlowVisitorClient method getTemplateFeedFlow.

public NifiFlowProcessGroup getTemplateFeedFlow(TemplateDTO template) {
    ProcessGroupDTO parentProcessGroup = new ProcessGroupDTO();
    parentProcessGroup.setId(UUID.randomUUID().toString());
    parentProcessGroup.setParentGroupId(UUID.randomUUID().toString());
    parentProcessGroup.setName(template.getName());
    parentProcessGroup.setContents(template.getSnippet());
    NifiConnectionOrderVisitorCache cache = new NifiConnectionOrderVisitorCache();
    Collection<ProcessGroupDTO> groups = NifiProcessUtil.getProcessGroups(parentProcessGroup);
    cache.add(parentProcessGroup);
    // add the snippet as its own process group
    if (template.getSnippet().getProcessors() != null) {
        // find the first processor and get its parent group id
        Optional<ProcessorDTO> firstProcessor = template.getSnippet().getProcessors().stream().findFirst();
        if (firstProcessor.isPresent()) {
            String groupId = firstProcessor.get().getParentGroupId();
            ProcessGroupDTO snippetGroup = new ProcessGroupDTO();
            snippetGroup.setId(groupId);
            snippetGroup.setParentGroupId(template.getGroupId());
            snippetGroup.setContents(template.getSnippet());
            cache.add(snippetGroup);
        }
    }
    if (groups != null) {
        groups.stream().forEach(group -> cache.add(group));
    }
    // add any remote ProcessGroups
    if (template.getSnippet().getRemoteProcessGroups() != null) {
        template.getSnippet().getRemoteProcessGroups().stream().forEach(remoteProcessGroupDTO -> cache.add(remoteProcessGroupDTO));
    }
    NifiVisitableProcessGroup visitableGroup = getFlowOrder(parentProcessGroup, cache, false);
    NifiFlowProcessGroup flow = new NifiFlowBuilder().build(visitableGroup);
    return flow;
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) NifiFlowBuilder(com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowBuilder) NifiConnectionOrderVisitorCache(com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 3 with NifiVisitableProcessGroup

use of com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup 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 4 with NifiVisitableProcessGroup

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

the class NifiConnectionOrderVisitor method visitProcessGroup.

@Override
public void visitProcessGroup(NifiVisitableProcessGroup processGroup) {
    log.debug(" Visit Process Group: {}, ({}) ", processGroup.getDto().getName(), processGroup.getDto().getId());
    NifiVisitableProcessGroup group = visitedProcessGroups.get(processGroup.getDto().getId());
    if (group == null) {
        group = processGroup;
    }
    this.currentProcessGroup = group;
    if (processGroup.getParentProcessGroup() == null) {
        try {
            ProcessGroupDTO parent = fetchProcessGroupForNameAndIdentifier(processGroup.getDto().getParentGroupId());
            if (parent != null) {
                group.setParentProcessGroup(parent);
            }
        } catch (NifiComponentNotFoundException e) {
        // cant find the parent
        }
    }
    group.accept(this);
    this.visitedProcessGroups.put(group.getDto().getId(), group);
}
Also used : NifiComponentNotFoundException(com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 5 with NifiVisitableProcessGroup

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

the class DefaultNiFiFlowVisitorClient method getFlowOrder.

/**
 * @param processGroupEntity
 * @param cache
 * @param logRestAccessErrors
 * @return
 * @throws NifiComponentNotFoundException
 */
public NifiVisitableProcessGroup getFlowOrder(ProcessGroupDTO processGroupEntity, NifiConnectionOrderVisitorCache cache, boolean logRestAccessErrors) throws NifiComponentNotFoundException {
    if (cache == null) {
        cache = new NifiConnectionOrderVisitorCache();
    }
    final NifiConnectionOrderVisitorCache finalCache = cache;
    Optional<ProcessGroupDTO> cachedProcessGroup = cache.getProcessGroup(processGroupEntity.getId());
    if (!cachedProcessGroup.isPresent() && processGroupEntity.getContents() != null) {
        NifiProcessUtil.getProcessGroups(processGroupEntity).stream().forEach(processGroupDTO -> finalCache.add(processGroupDTO));
    }
    NifiVisitableProcessGroup group = null;
    if (processGroupEntity != null) {
        group = new NifiVisitableProcessGroup(processGroupEntity);
        NifiConnectionOrderVisitor orderVisitor = new NifiConnectionOrderVisitor(restClient, group, finalCache);
        try {
            Optional<ProcessGroupDTO> parent = cache.getProcessGroup(processGroupEntity.getParentGroupId());
            if (!parent.isPresent()) {
                parent = restClient.processGroups().findById(processGroupEntity.getParentGroupId(), false, false, logRestAccessErrors);
            }
            if (parent.isPresent()) {
                group.setParentProcessGroup(parent.get());
            }
        } catch (NifiComponentNotFoundException e) {
        // cant find the parent
        }
        group.accept(orderVisitor);
        finalCache.add(orderVisitor.toCachedItem());
    }
    return group;
}
Also used : NifiConnectionOrderVisitorCache(com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache) NifiVisitableProcessGroup(com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) NifiConnectionOrderVisitor(com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitor)

Aggregations

NifiVisitableProcessGroup (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessGroup)12 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)8 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)6 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)6 NifiVisitableProcessor (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableProcessor)4 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)4 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)4 NifiFlowProcessGroup (com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup)3 NifiFlowBuilder (com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowBuilder)3 NifiConnectionOrderVisitorCache (com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)2 NiFiRestClient (com.thinkbiganalytics.nifi.rest.client.NiFiRestClient)1 NifiFlowVisitor (com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowVisitor)1 NifiVisitableConnection (com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableConnection)1 NifiConnectionUtil (com.thinkbiganalytics.nifi.rest.support.NifiConnectionUtil)1 NifiProcessUtil (com.thinkbiganalytics.nifi.rest.support.NifiProcessUtil)1 NifiConnectionOrderVisitor (com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitor)1