use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class ImportConnectedReusableTemplateIT method registerConnectedReusableTemplate.
public ConnectedTemplate registerConnectedReusableTemplate() {
URL resource = IntegrationTestBase.class.getResource("connecting_reusable_flow.xml");
ImportTemplate template1 = importReusableFlowXmlTemplate(resource.getPath(), null);
String template1ProcessGroupId = template1.getTemplateResults().getProcessGroupEntity().getId();
// Now import a reusable flow that has additional output ports in it.
// Kylo will prompt to connect this to another reusable flow
URL resource2 = IntegrationTestBase.class.getResource("reusable-flow1.xml");
ImportTemplate template2 = importReusableFlowXmlTemplate(resource2.getPath(), null);
// verify it failed
Assert.assertFalse(template2.isSuccess());
Assert.assertTrue(template2.isReusableFlowOutputPortConnectionsNeeded());
// reassign the connections to connect to template1
ReusableTemplateConnectionInfo connectionInfo = template2.getReusableTemplateConnections().stream().filter(conn -> "to another flow".equalsIgnoreCase(conn.getFeedOutputPortName())).findFirst().orElse(null);
// Obtain the reusable connection input ports
// get v1/feedmgr/nifi/reusable-input-ports
PortDTO[] reusableInputPorts = getReusableInputPorts();
// the 'connecting_reusable_flow.xml' has an input port named 'from reusable port'.
// find it and try to connect it to this one
PortDTO connectingPort = Arrays.stream(reusableInputPorts).filter(portDTO -> portDTO.getName().equalsIgnoreCase("from reusable port")).findFirst().orElse(null);
if (connectingPort != null) {
connectionInfo.setInputPortDisplayName(connectingPort.getName());
connectionInfo.setReusableTemplateInputPortName(connectingPort.getName());
connectionInfo.setReusableTemplateProcessGroupName(template1.getTemplateResults().getProcessGroupEntity().getName());
}
template2 = importReusableFlowXmlTemplate(resource2.getPath(), connectionInfo);
Assert.assertTrue(template2.isSuccess());
Assert.assertFalse(template2.isReusableFlowOutputPortConnectionsNeeded());
// get the flow for the parent processor and verify it is connected to the other reusable flow
NifiFlowProcessGroup flow = getFlow(template2.getTemplateResults().getProcessGroupEntity().getId());
Assert.assertNotNull(flow);
boolean testUpdate2ProcessorExists = flow.getProcessorMap().values().stream().anyMatch(p -> "test-update2".equalsIgnoreCase(p.getName()));
Assert.assertTrue(testUpdate2ProcessorExists);
return new ConnectedTemplate(template1, template2);
}
use of org.apache.nifi.web.api.dto.PortDTO in project nifi-minifi by apache.
the class FlowSnippetDTOEnricher method enrich.
public void enrich(FlowSnippetDTO flowSnippetDTO, final String encodingVersion) {
List<FlowSnippetDTO> allFlowSnippets = getAllFlowSnippets(flowSnippetDTO);
Set<RemoteProcessGroupDTO> remoteProcessGroups = getAll(allFlowSnippets, FlowSnippetDTO::getRemoteProcessGroups).collect(Collectors.toSet());
Map<String, String> connectableNameMap = getAll(allFlowSnippets, FlowSnippetDTO::getProcessors).collect(Collectors.toMap(ComponentDTO::getId, ProcessorDTO::getName));
Map<String, String> rpgIdToTargetIdMap = new HashMap<>();
for (RemoteProcessGroupDTO remoteProcessGroupDTO : remoteProcessGroups) {
final RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents();
final Set<RemoteProcessGroupPortDTO> rpgInputPortDtos = nullToEmpty(contents.getInputPorts());
final Set<RemoteProcessGroupPortDTO> rpgOutputPortDtos = nullToEmpty(contents.getOutputPorts());
switch(encodingVersion) {
case "1.2":
// Map all port DTOs to their respective targetIds
rpgIdToTargetIdMap.putAll(Stream.concat(rpgInputPortDtos.stream(), rpgOutputPortDtos.stream()).collect(Collectors.toMap(RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getTargetId)));
break;
default:
break;
}
addConnectables(connectableNameMap, rpgInputPortDtos, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId);
addConnectables(connectableNameMap, rpgOutputPortDtos, RemoteProcessGroupPortDTO::getId, RemoteProcessGroupPortDTO::getId);
}
addConnectables(connectableNameMap, getAll(allFlowSnippets, FlowSnippetDTO::getInputPorts).collect(Collectors.toList()), PortDTO::getId, PortDTO::getName);
addConnectables(connectableNameMap, getAll(allFlowSnippets, FlowSnippetDTO::getOutputPorts).collect(Collectors.toList()), PortDTO::getId, PortDTO::getName);
final Set<ConnectionDTO> connections = getAll(allFlowSnippets, FlowSnippetDTO::getConnections).collect(Collectors.toSet());
// Enrich connection endpoints using known names and overriding with targetIds for remote ports
for (ConnectionDTO connection : connections) {
setName(connectableNameMap, connection.getSource(), rpgIdToTargetIdMap);
setName(connectableNameMap, connection.getDestination(), rpgIdToTargetIdMap);
}
// Override any ids that are for Remote Ports to use their target Ids where available
connections.stream().flatMap(connectionDTO -> Stream.of(connectionDTO.getSource(), connectionDTO.getDestination())).filter(connectable -> connectable.getType().equals(ConnectableType.REMOTE_OUTPUT_PORT.toString()) || connectable.getType().equals(ConnectableType.REMOTE_INPUT_PORT.toString())).forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId())));
// Establish unique names for connections
for (ConnectionDTO connection : connections) {
if (StringUtil.isNullOrEmpty(connection.getName())) {
StringBuilder name = new StringBuilder();
ConnectableDTO connectionSource = connection.getSource();
name.append(determineValueForConnectable(connectionSource, rpgIdToTargetIdMap));
name.append("/");
if (connection.getSelectedRelationships() != null && connection.getSelectedRelationships().size() > 0) {
name.append(connection.getSelectedRelationships().iterator().next());
}
name.append("/");
ConnectableDTO connectionDestination = connection.getDestination();
name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap));
connection.setName(name.toString());
}
}
nullToEmpty(flowSnippetDTO.getProcessGroups()).stream().map(ProcessGroupDTO::getContents).forEach(snippetDTO -> enrich(snippetDTO, encodingVersion));
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class LegacyNifiRestClient method stopOutputPort.
public PortDTO stopOutputPort(String groupId, String portId) throws NifiClientRuntimeException {
PortDTO portDTO = new PortDTO();
portDTO.setId(portId);
portDTO.setState(NifiProcessUtil.PROCESS_STATE.STOPPED.name());
return client.ports().updateOutputPort(groupId, portDTO);
}
use of org.apache.nifi.web.api.dto.PortDTO in project kylo by Teradata.
the class LegacyNifiRestClient method startOutputPort.
public PortDTO startOutputPort(String groupId, String portId) throws NifiClientRuntimeException {
PortDTO portDTO = new PortDTO();
portDTO.setId(portId);
portDTO.setState(NifiProcessUtil.PROCESS_STATE.RUNNING.name());
return client.ports().updateOutputPort(groupId, portDTO);
}
use of org.apache.nifi.web.api.dto.PortDTO 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);
}
}
Aggregations