Search in sources :

Example 1 with NifiConnectionOrderVisitorCache

use of com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache 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 2 with NifiConnectionOrderVisitorCache

use of com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache 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)2 NifiConnectionOrderVisitorCache (com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitorCache)2 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)2 NifiFlowProcessGroup (com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup)1 NifiFlowBuilder (com.thinkbiganalytics.nifi.rest.model.visitor.NifiFlowBuilder)1 NifiConnectionOrderVisitor (com.thinkbiganalytics.nifi.rest.visitor.NifiConnectionOrderVisitor)1 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)1