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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations