Search in sources :

Example 66 with ProcessGroupDTO

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

the class AbstractNiFiProcessGroupsRestClient method findByName.

@Nonnull
@Override
public Optional<ProcessGroupDTO> findByName(@Nonnull final String parentGroupId, @Nonnull final String groupName, final boolean recursive, final boolean verbose) {
    final Set<ProcessGroupDTO> children = findAll(parentGroupId);
    final ProcessGroupDTO group = NifiProcessUtil.findFirstProcessGroupByName(children, groupName);
    if (group != null && verbose) {
        return findById(group.getId(), recursive, true);
    } else {
        return Optional.ofNullable(group);
    }
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) Nonnull(javax.annotation.Nonnull)

Example 67 with ProcessGroupDTO

use of org.apache.nifi.web.api.dto.ProcessGroupDTO 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)

Example 68 with ProcessGroupDTO

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

the class DefaultNiFiFlowVisitorClient method getFeedFlowForCategoryAndFeed.

public NifiFlowProcessGroup getFeedFlowForCategoryAndFeed(String categoryAndFeedName) {
    NifiFlowProcessGroup flow = null;
    String category = FeedNameUtil.category(categoryAndFeedName);
    String feed = FeedNameUtil.feed(categoryAndFeedName);
    // 1 find the ProcessGroup under "root" matching the name category
    ProcessGroupDTO processGroupEntity = restClient.processGroups().findRoot();
    ProcessGroupDTO root = processGroupEntity;
    ProcessGroupDTO categoryGroup = root.getContents().getProcessGroups().stream().filter(group -> category.equalsIgnoreCase(group.getName())).findAny().orElse(null);
    if (categoryGroup != null) {
        ProcessGroupDTO feedGroup = categoryGroup.getContents().getProcessGroups().stream().filter(group -> feed.equalsIgnoreCase(group.getName())).findAny().orElse(null);
        if (feedGroup != null) {
            flow = getFeedFlow(feedGroup.getId());
        }
    }
    return flow;
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO)

Example 69 with ProcessGroupDTO

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

the class DefaultNiFiFlowVisitorClient method getFeedFlows.

public List<NifiFlowProcessGroup> getFeedFlows(Collection<String> feedNames, final NifiConnectionOrderVisitorCache cache) {
    log.info("get Graph of Nifi Flows looking for {} ", feedNames == null ? "ALL Feeds " : feedNames);
    long start = System.currentTimeMillis();
    List<NifiFlowProcessGroup> feedFlows = new ArrayList<>();
    ProcessGroupDTO processGroupEntity = restClient.processGroups().findRoot();
    ProcessGroupDTO root = processGroupEntity;
    // first level is the category
    root.getContents().getProcessGroups().stream().sorted(new Comparator<ProcessGroupDTO>() {

        @Override
        public int compare(ProcessGroupDTO o1, ProcessGroupDTO o2) {
            if (TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME.equalsIgnoreCase(o1.getName())) {
                return -1;
            }
            if (TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME.equalsIgnoreCase(o2.getName())) {
                return -1;
            }
            return o1.getName().compareTo(o2.getName());
        }
    }).forEach(category -> {
        for (ProcessGroupDTO feedProcessGroup : category.getContents().getProcessGroups()) {
            // second level is the feed
            String feedName = FeedNameUtil.fullName(category.getName(), feedProcessGroup.getName());
            // if it is a versioned feed then strip the version to get the correct feed name
            feedName = TemplateCreationHelper.parseVersionedProcessGroupName(feedName);
            // if feednames are sent in, only add those that match or those in the reusable group
            if ((feedNames == null || feedNames.isEmpty()) || (feedNames != null && (feedNames.contains(feedName) || TemplateCreationHelper.REUSABLE_TEMPLATES_PROCESS_GROUP_NAME.equalsIgnoreCase(category.getName())))) {
                NifiFlowProcessGroup feedFlow = getFeedFlow(feedProcessGroup.getId(), cache);
                feedFlow.setFeedName(feedName);
                feedFlows.add(feedFlow);
            }
        }
    });
    long end = System.currentTimeMillis();
    log.info("finished Graph of Nifi Flows.  Returning {} flows, {} ", feedFlows.size(), (end - start) + " ms");
    return feedFlows;
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) Comparator(java.util.Comparator)

Example 70 with ProcessGroupDTO

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

the class LegacyNifiRestClient method removeProcessGroup.

public boolean removeProcessGroup(String processGroupId, String parentProcessGroupId) {
    // Now try to remove the processgroup associated with this template import
    ProcessGroupDTO e = null;
    try {
        e = getProcessGroup(processGroupId, false, false);
    } catch (NifiComponentNotFoundException notFound) {
    // if its not there then we already cleaned up :)
    }
    if (e != null) {
        try {
            stopAllProcessors(processGroupId, parentProcessGroupId);
            // remove connections
            removeConnectionsToProcessGroup(parentProcessGroupId, processGroupId);
            // remove output port connections
            removeConnectionsFromProcessGroup(parentProcessGroupId, processGroupId);
        } catch (Exception e2) {
        // this is ok. we are cleaning up the template so if an error occurs due to no connections it is fine since we ultimately want to remove this temp template.
        }
        try {
            // importTemplate.getTemplateResults().getProcessGroupEntity()
            deleteProcessGroup(e);
            return true;
        } catch (NifiComponentNotFoundException nfe) {
        // this is ok
        }
    }
    return false;
}
Also used : ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)96 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)35 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)32 ArrayList (java.util.ArrayList)29 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)29 PortDTO (org.apache.nifi.web.api.dto.PortDTO)27 HashSet (java.util.HashSet)25 HashMap (java.util.HashMap)20 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)18 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)18 NifiComponentNotFoundException (com.thinkbiganalytics.nifi.rest.client.NifiComponentNotFoundException)16 List (java.util.List)16 Set (java.util.Set)16 Collectors (java.util.stream.Collectors)15 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)15 Map (java.util.Map)14 NifiClientRuntimeException (com.thinkbiganalytics.nifi.rest.client.NifiClientRuntimeException)13 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13