use of org.apache.nifi.web.api.dto.ConnectableDTO in project kylo by Teradata.
the class NifiConnectionOrderVisitor method getSourceProcessors.
public List<NifiVisitableProcessor> getSourceProcessors(ConnectionDTO connection) {
ConnectableDTO source = connection.getSource();
List<NifiVisitableProcessor> sourceProcessors = new ArrayList<>();
if (source != null) {
if ("INPUT_PORT".equalsIgnoreCase(source.getType())) {
NifiVisitableProcessGroup group = visitedProcessGroups.get(source.getGroupId());
if (group == null) {
group = processGroup;
}
NifiVisitableProcessGroup parent = visitedProcessGroups.get(group.getDto().getParentGroupId());
// if the parent is null the parent is the starting process group
if (parent == null) {
parent = processGroup;
}
ConnectionDTO conn = parent.getConnectionMatchingDestinationId(source.getId());
if (conn == null) {
// if its null get it from the cache and process with that.
conn = cache.getProcessGroupCache().values().stream().flatMap(g -> g.getContents().getConnections().stream()).filter(connectionDTO -> connectionDTO.getDestination().getId().equalsIgnoreCase(source.getId())).findFirst().orElse(null);
}
if (conn != null && conn != connection) {
// get the processor whos source matches this connection Id
sourceProcessors = getSourceProcessors(conn);
// assign the inputPortProcessor == the the destination of this connection
}
List<NifiVisitableProcessor> inputProcessors = getDestinationProcessors(connection, false);
if (inputProcessors != null) {
for (NifiVisitableProcessor inputProcessor : inputProcessors) {
currentProcessGroup.addInputPortProcessor(source.getId(), inputProcessor);
}
}
} else if ("OUTPUT_PORT".equals(source.getType())) {
// get the sources group id then get the ending processor for that group
NifiVisitableProcessGroup group = visitedProcessGroups.get(source.getGroupId());
if (group != null) {
Set<NifiVisitableProcessor> sources = group.getOutputPortProcessors(source.getId());
if (sourceProcessors != null && sources != null) {
sourceProcessors.addAll(sources);
}
/*
If a process group is connected to another process group without any processors there will be no source processors
having sourceProcessors as null here is ok.
*/
}
} else if ("FUNNEL".equalsIgnoreCase(source.getType())) {
List<ConnectionDTO> passThroughConnections = NifiConnectionUtil.findConnectionsMatchingDestinationId(currentProcessGroup.getDto().getContents().getConnections(), connection.getSource().getId());
if (passThroughConnections != null) {
for (ConnectionDTO dto : passThroughConnections) {
ConnectionDTO newConnection = new ConnectionDTO();
newConnection.setSource(dto.getSource());
newConnection.setId(connection.getSource().getId());
newConnection.setDestination(connection.getDestination());
visitConnection(new NifiVisitableConnection(currentProcessGroup, newConnection));
}
}
} else if ("PROCESSOR".equals(source.getType())) {
NifiVisitableProcessor sourceProcessor = getConnectionProcessor(source.getGroupId(), source.getId());
sourceProcessors.add(sourceProcessor);
}
for (NifiVisitableProcessor sourceProcessor : sourceProcessors) {
sourceProcessor.addDestinationConnectionIdentifier(connection);
}
}
return sourceProcessors;
}
use of org.apache.nifi.web.api.dto.ConnectableDTO in project kylo by Teradata.
the class NifiConnectionOrderVisitor method getDestinationProcessors.
public List<NifiVisitableProcessor> getDestinationProcessors(ConnectionDTO connection, boolean getSource) {
ConnectableDTO dest = connection.getDestination();
List<NifiVisitableProcessor> destinationProcessors = new ArrayList<>();
if (dest != null) {
if ("INPUT_PORT".equalsIgnoreCase(dest.getType())) {
boolean isNew = false;
NifiVisitableProcessGroup group = visitedProcessGroups.get(dest.getGroupId());
if (group == null) {
group = fetchProcessGroup(dest.getGroupId());
}
ConnectionDTO conn = group.getConnectionMatchingSourceId(dest.getId());
if (conn != null) {
destinationProcessors = getDestinationProcessors(conn, getSource);
if (getSource) {
List<NifiVisitableProcessor> outputProcessors = getSourceProcessors(connection);
if (outputProcessors != null) {
for (NifiVisitableProcessor outputProcessor : outputProcessors) {
// outputProcessor.setOutputPortId(dest.getId());
currentProcessGroup.addOutputPortProcessor(dest.getId(), outputProcessor);
}
}
}
}
}
if ("REMOTE_INPUT_PORT".equalsIgnoreCase(dest.getType())) {
boolean isNew = false;
// treat this like a Processor for the connection graph
NifiVisitableProcessor processorDto = getRemoteProcessGroupAsVisitableProcessor(dest.getGroupId(), connection.getParentGroupId());
destinationProcessors.add(processorDto);
} else if ("OUTPUT_PORT".equals(dest.getType())) {
boolean isNew = false;
// get parent processgroup connection to input port
NifiVisitableProcessGroup group = visitedProcessGroups.get(dest.getGroupId());
if (group == null) {
group = fetchProcessGroup(dest.getGroupId());
}
ConnectionDTO conn = group.getConnectionMatchingSourceId(dest.getId());
if (conn == null) {
conn = searchConnectionMatchingSource(group.getDto().getParentGroupId(), dest.getId());
}
if (conn != null) {
// get the processor whos source matches this connection Id
List<NifiVisitableProcessor> destinations = getDestinationProcessors(conn, getSource);
if (destinations != null) {
destinationProcessors.addAll(destinations);
}
if (getSource) {
List<NifiVisitableProcessor> outputProcessors = getSourceProcessors(connection);
if (outputProcessors != null) {
for (NifiVisitableProcessor outputProcessor : outputProcessors) {
currentProcessGroup.addOutputPortProcessor(dest.getId(), outputProcessor);
}
}
}
}
} else if ("FUNNEL".equals(dest.getType())) {
List<ConnectionDTO> passThroughConnections = NifiConnectionUtil.findConnectionsMatchingSourceId(currentProcessGroup.getDto().getContents().getConnections(), connection.getDestination().getId());
if (passThroughConnections != null) {
for (ConnectionDTO dto : passThroughConnections) {
ConnectionDTO newConnection = new ConnectionDTO();
newConnection.setId(connection.getSource().getId());
newConnection.setSource(connection.getSource());
newConnection.setDestination(dto.getDestination());
List<NifiVisitableProcessor> destinations = getDestinationProcessors(newConnection, getSource);
if (destinations != null) {
// destinationProcessor.setOutputPortId(dest.getId());
destinationProcessors.addAll(destinations);
}
}
}
} else if ("PROCESSOR".equals(dest.getType())) {
NifiVisitableProcessor destinationProcessor = getConnectionProcessor(dest.getGroupId(), dest.getId());
destinationProcessors.add(destinationProcessor);
}
}
for (NifiVisitableProcessor destinationProcessor : destinationProcessors) {
destinationProcessor.addSourceConnectionIdentifier(connection);
}
return destinationProcessors;
}
use of org.apache.nifi.web.api.dto.ConnectableDTO in project kylo by Teradata.
the class NifiConnectionUtil method asConnectable.
public static ConnectableDTO asConnectable(PortDTO port) {
ConnectableDTO connectable = new ConnectableDTO();
connectable.setGroupId(port.getParentGroupId());
connectable.setId(port.getId());
connectable.setName(port.getName());
connectable.setType(port.getType());
return connectable;
}
use of org.apache.nifi.web.api.dto.ConnectableDTO in project kylo by Teradata.
the class LegacyNifiRestClient method connectFeedToGlobalTemplate.
/**
* Connect a Feed to a reusable Template
*/
public void connectFeedToGlobalTemplate(final String feedProcessGroupId, final String feedOutputName, final String categoryProcessGroupId, String reusableTemplateCategoryGroupId, String inputPortName) throws NifiComponentNotFoundException {
ProcessGroupDTO categoryProcessGroup = getProcessGroup(categoryProcessGroupId, false, false);
ProcessGroupDTO feedProcessGroup = getProcessGroup(feedProcessGroupId, false, false);
ProcessGroupDTO categoryParent = getProcessGroup(categoryProcessGroup.getParentGroupId(), false, false);
ProcessGroupDTO reusableTemplateCategoryGroup = getProcessGroup(reusableTemplateCategoryGroupId, false, false);
// Go into the Feed and find the output port that is to be associated with the global template
Set<PortDTO> outputPortsEntity = getOutputPorts(feedProcessGroupId);
PortDTO feedOutputPort = null;
if (outputPortsEntity != null) {
feedOutputPort = NifiConnectionUtil.findPortMatchingName(outputPortsEntity, feedOutputName);
}
if (feedOutputPort == null) {
// ERROR This feed needs to have an output port assigned on it to make the connection
}
Set<PortDTO> inputPortsEntity = getInputPorts(reusableTemplateCategoryGroupId);
PortDTO inputPort = NifiConnectionUtil.findPortMatchingName(inputPortsEntity, inputPortName);
String inputPortId = inputPort.getId();
final String categoryOutputPortName = categoryProcessGroup.getName() + " to " + inputPort.getName();
// Find or create the output port that will join to the globabl template at the Category Level
Set<PortDTO> categoryOutputPortsEntity = getOutputPorts(categoryProcessGroupId);
PortDTO categoryOutputPort = null;
if (categoryOutputPortsEntity != null) {
categoryOutputPort = NifiConnectionUtil.findPortMatchingName(categoryOutputPortsEntity, categoryOutputPortName);
}
if (categoryOutputPort == null) {
// create it
PortDTO portDTO = new PortDTO();
portDTO.setParentGroupId(categoryProcessGroupId);
portDTO.setName(categoryOutputPortName);
categoryOutputPort = client.processGroups().createOutputPort(categoryProcessGroupId, portDTO);
}
// Now create a connection from the Feed PRocessGroup to this outputPortEntity
ConnectionDTO feedOutputToCategoryOutputConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(categoryProcessGroupId), feedOutputPort.getId(), categoryOutputPort.getId());
if (feedOutputToCategoryOutputConnection == null) {
// CONNECT FEED OUTPUT PORT TO THE Category output port
ConnectableDTO source = new ConnectableDTO();
source.setGroupId(feedProcessGroupId);
source.setId(feedOutputPort.getId());
source.setName(feedProcessGroup.getName());
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());
createConnection(categoryProcessGroup.getId(), source, dest);
}
ConnectionDTO categoryToReusableTemplateConnection = NifiConnectionUtil.findConnection(findConnectionsForParent(categoryParent.getId()), categoryOutputPort.getId(), inputPortId);
// Now connect the category PRocessGroup to the global template
if (categoryToReusableTemplateConnection == null) {
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(inputPortId);
categoryToGlobalTemplate.setName(inputPortName);
categoryToGlobalTemplate.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name());
createConnection(categoryParent.getId(), categorySource, categoryToGlobalTemplate);
}
}
use of org.apache.nifi.web.api.dto.ConnectableDTO 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;
}
Aggregations