use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class LegacyNifiRestClient method createReusableTemplateInputPort.
/**
* Creates an INPUT Port and verifys/creates the connection from it to the child processgroup input port
*/
public PortDTO createReusableTemplateInputPort(String reusableTemplateCategoryGroupId, String reusableTemplateGroupId, String inputPortName) {
// ProcessGroupEntity reusableTemplateGroup = getProcessGroup(reusableTemplateGroupId, false, false);
Set<PortDTO> inputPortsEntity = getInputPorts(reusableTemplateCategoryGroupId);
PortDTO inputPort = NifiConnectionUtil.findPortMatchingName(inputPortsEntity, inputPortName);
if (inputPort == null) {
// 1 create the inputPort on the Category Group
PortDTO portDTO = new PortDTO();
portDTO.setParentGroupId(reusableTemplateCategoryGroupId);
portDTO.setName(inputPortName);
inputPort = client.processGroups().createInputPort(reusableTemplateCategoryGroupId, portDTO);
}
// 2 check and create the connection frmo the inputPort to the actual templateGroup
PortDTO templateInputPort = null;
Set<PortDTO> templatePorts = getInputPorts(reusableTemplateGroupId);
templateInputPort = NifiConnectionUtil.findPortMatchingName(templatePorts, inputPortName);
ConnectionDTO inputToTemplateConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(reusableTemplateCategoryGroupId), inputPort.getId(), templateInputPort.getId());
if (inputToTemplateConnection == null) {
// create the connection
ConnectableDTO source = new ConnectableDTO();
source.setGroupId(reusableTemplateCategoryGroupId);
source.setId(inputPort.getId());
source.setName(inputPortName);
source.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
ConnectableDTO dest = new ConnectableDTO();
dest.setGroupId(reusableTemplateGroupId);
dest.setName(inputPortName);
dest.setId(templateInputPort.getId());
dest.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
createConnection(reusableTemplateCategoryGroupId, source, dest);
}
return inputPort;
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class LegacyNifiRestClient method getPortsForProcessGroup.
public Set<PortDTO> getPortsForProcessGroup(String processGroupId) throws NifiComponentNotFoundException {
Set<PortDTO> ports = new HashSet<>();
ProcessGroupDTO processGroupEntity = getProcessGroup(processGroupId, false, true);
Set<PortDTO> inputPorts = processGroupEntity.getContents().getInputPorts();
if (inputPorts != null) {
ports.addAll(inputPorts);
}
Set<PortDTO> outputPorts = processGroupEntity.getContents().getOutputPorts();
if (outputPorts != null) {
ports.addAll(outputPorts);
}
return ports;
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class AlignProcessGroupComponents method alignOutputPorts.
private void alignOutputPorts(ProcessGroupToOutputPort layoutGroup, AbstractRenderer renderer) {
layoutGroup.getPorts().values().stream().forEach(port -> {
PortDTO positionPort = new PortDTO();
positionPort.setId(port.getId());
PositionDTO lastPosition = renderer.getLastPosition();
PositionDTO newPosition = renderer.getNextPosition(lastPosition);
positionPort.setPosition(newPosition);
niFiRestClient.ports().updateOutputPort(parentProcessGroupId, positionPort);
log.debug("Aligned Port {} at {},{}", port.getName(), positionPort.getPosition().getX(), positionPort.getPosition().getY());
});
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class DefaultFeedManagerTemplateService method getRegisteredTemplateProcessors.
@Override
public List<RegisteredTemplate.Processor> getRegisteredTemplateProcessors(String templateId, boolean includeReusableProcessors) {
List<RegisteredTemplate.Processor> processorProperties = new ArrayList<>();
RegisteredTemplate template = registeredTemplateService.findRegisteredTemplate(new RegisteredTemplateRequest.Builder().templateId(templateId).nifiTemplateId(templateId).includeAllProperties(true).build());
if (template != null) {
template.initializeProcessors();
processorProperties.addAll(template.getInputProcessors());
processorProperties.addAll(template.getNonInputProcessors());
if (includeReusableProcessors && template.getReusableTemplateConnections() != null && !template.getReusableTemplateConnections().isEmpty()) {
// 1 fetch ports in reusable templates
Map<String, PortDTO> reusableTemplateInputPorts = new HashMap<>();
Set<PortDTOWithGroupInfo> ports = getReusableFeedInputPorts();
if (ports != null) {
ports.stream().forEach(portDTO -> reusableTemplateInputPorts.put(portDTO.getName(), portDTO));
}
// match to the name
List<String> matchingPortIds = template.getReusableTemplateConnections().stream().filter(conn -> reusableTemplateInputPorts.containsKey(conn.getReusableTemplateInputPortName())).map(reusableTemplateConnectionInfo -> reusableTemplateInputPorts.get(reusableTemplateConnectionInfo.getReusableTemplateInputPortName()).getId()).collect(Collectors.toList());
List<RegisteredTemplate.Processor> reusableProcessors = getReusableTemplateProcessorsForInputPorts(matchingPortIds);
processorProperties.addAll(reusableProcessors);
}
}
return processorProperties;
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class TemplateConnectionUtil method connectFeedToReusableTemplate.
public void connectFeedToReusableTemplate(ProcessGroupDTO feedProcessGroup, ProcessGroupDTO categoryProcessGroup, List<InputOutputPort> inputOutputPorts) throws NifiComponentNotFoundException {
Stopwatch stopwatch = Stopwatch.createStarted();
String categoryProcessGroupId = categoryProcessGroup.getId();
String categoryParentGroupId = categoryProcessGroup.getParentGroupId();
String categoryProcessGroupName = categoryProcessGroup.getName();
String feedProcessGroupId = feedProcessGroup.getId();
String feedProcessGroupName = feedProcessGroup.getName();
ProcessGroupDTO reusableTemplateCategory = niFiObjectCache.getReusableTemplateCategoryProcessGroup();
if (reusableTemplateCategory == null) {
throw new NifiClientRuntimeException("Unable to find the Reusable Template Group. Please ensure NiFi has the 'reusable_templates' processgroup and appropriate reusable flow for this feed." + " You may need to import the base reusable template for this feed.");
}
String reusableTemplateCategoryGroupId = reusableTemplateCategory.getId();
stopwatch.stop();
log.debug("Time to get reusableTemplateCategory: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
Stopwatch totalStopWatch = Stopwatch.createUnstarted();
for (InputOutputPort port : inputOutputPorts) {
totalStopWatch.start();
stopwatch.start();
PortDTO reusableTemplatePort = niFiObjectCache.getReusableTemplateInputPort(port.getInputPortName());
stopwatch.stop();
log.debug("Time to get reusableTemplate inputPort {} : {} ", port.getInputPortName(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
if (reusableTemplatePort != null) {
String categoryOutputPortName = categoryProcessGroupName + " to " + port.getInputPortName();
stopwatch.start();
PortDTO categoryOutputPort = niFiObjectCache.getCategoryOutputPort(categoryProcessGroupId, categoryOutputPortName);
if (categoryOutputPort != null) {
// ensure it exists
try {
categoryOutputPort = restClient.getNiFiRestClient().ports().getOutputPort(categoryOutputPort.getId());
} catch (Exception e) {
categoryOutputPort = null;
}
}
stopwatch.stop();
log.debug("Time to get categoryOutputPort {} : {} ", categoryOutputPortName, stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
if (categoryOutputPort == null) {
stopwatch.start();
// create it
PortDTO portDTO = new PortDTO();
portDTO.setParentGroupId(categoryProcessGroupId);
portDTO.setName(categoryOutputPortName);
categoryOutputPort = restClient.getNiFiRestClient().processGroups().createOutputPort(categoryProcessGroupId, portDTO);
niFiObjectCache.addCategoryOutputPort(categoryProcessGroupId, categoryOutputPort);
stopwatch.stop();
log.debug("Time to create categoryOutputPort {} : {} ", categoryOutputPortName, stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
}
stopwatch.start();
Set<PortDTO> feedOutputPorts = feedProcessGroup.getContents().getOutputPorts();
String feedOutputPortName = port.getOutputPortName();
if (feedOutputPorts == null || feedOutputPorts.isEmpty()) {
feedOutputPorts = restClient.getNiFiRestClient().processGroups().getOutputPorts(feedProcessGroup.getId());
}
PortDTO feedOutputPort = NifiConnectionUtil.findPortMatchingName(feedOutputPorts, feedOutputPortName);
stopwatch.stop();
log.debug("Time to create feedOutputPort {} : {} ", feedOutputPortName, stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
if (feedOutputPort != null) {
stopwatch.start();
// make the connection on the category from feed to category
ConnectionDTO feedOutputToCategoryOutputConnection = niFiObjectCache.getConnection(categoryProcessGroupId, feedOutputPort.getId(), categoryOutputPort.getId());
stopwatch.stop();
log.debug("Time to get feedOutputToCategoryOutputConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
if (feedOutputToCategoryOutputConnection == null) {
stopwatch.start();
// CONNECT FEED OUTPUT PORT TO THE Category output port
ConnectableDTO source = new ConnectableDTO();
source.setGroupId(feedProcessGroupId);
source.setId(feedOutputPort.getId());
source.setName(feedProcessGroupName);
source.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
ConnectableDTO dest = new ConnectableDTO();
dest.setGroupId(categoryProcessGroupId);
dest.setName(categoryOutputPort.getName());
dest.setId(categoryOutputPort.getId());
dest.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
// ensure the port exists
niFiObjectCache.addCategoryOutputPort(categoryProcessGroupId, categoryOutputPort);
feedOutputToCategoryOutputConnection = restClient.createConnection(categoryProcessGroupId, source, dest);
niFiObjectCache.addConnection(categoryProcessGroupId, feedOutputToCategoryOutputConnection);
nifiFlowCache.addConnectionToCache(feedOutputToCategoryOutputConnection);
stopwatch.stop();
log.debug("Time to create feedOutputToCategoryOutputConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
}
stopwatch.start();
// connection made on parent (root) to reusable template
ConnectionDTO categoryToReusableTemplateConnection = niFiObjectCache.getConnection(categoryProcessGroup.getParentGroupId(), categoryOutputPort.getId(), reusableTemplatePort.getId());
stopwatch.stop();
log.debug("Time to get categoryToReusableTemplateConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
// Now connect the category ProcessGroup to the global template
if (categoryToReusableTemplateConnection == null) {
stopwatch.start();
ConnectableDTO categorySource = new ConnectableDTO();
categorySource.setGroupId(categoryProcessGroupId);
categorySource.setId(categoryOutputPort.getId());
categorySource.setName(categoryOutputPortName);
categorySource.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name());
ConnectableDTO categoryToGlobalTemplate = new ConnectableDTO();
categoryToGlobalTemplate.setGroupId(reusableTemplateCategoryGroupId);
categoryToGlobalTemplate.setId(reusableTemplatePort.getId());
categoryToGlobalTemplate.setName(reusableTemplatePort.getName());
categoryToGlobalTemplate.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
categoryToReusableTemplateConnection = restClient.createConnection(categoryParentGroupId, categorySource, categoryToGlobalTemplate);
niFiObjectCache.addConnection(categoryParentGroupId, categoryToReusableTemplateConnection);
nifiFlowCache.addConnectionToCache(categoryToReusableTemplateConnection);
stopwatch.stop();
log.debug("Time to create categoryToReusableTemplateConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS));
stopwatch.reset();
}
}
}
totalStopWatch.stop();
log.debug("Time to connect feed to {} port. ElapsedTime: {} ", port.getInputPortName(), totalStopWatch.elapsed(TimeUnit.MILLISECONDS));
totalStopWatch.reset();
}
}
Aggregations