Search in sources :

Example 41 with PortDTO

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);
}
Also used : NifiFlowProcessGroup(com.thinkbiganalytics.nifi.rest.model.flow.NifiFlowProcessGroup) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ImportTemplate(com.thinkbiganalytics.feedmgr.service.template.importing.model.ImportTemplate) ReusableTemplateConnectionInfo(com.thinkbiganalytics.feedmgr.rest.model.ReusableTemplateConnectionInfo) URL(java.net.URL)

Example 42 with PortDTO

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));
}
Also used : RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) ConnectableType(org.apache.nifi.connectable.ConnectableType) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) StringUtil(org.apache.nifi.minifi.commons.schema.common.StringUtil) Map(java.util.Map) Collection(java.util.Collection) Set(java.util.Set) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ComponentDTO(org.apache.nifi.web.api.dto.ComponentDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) List(java.util.List) Stream(java.util.stream.Stream) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) Optional(java.util.Optional) CollectionUtil.nullToEmpty(org.apache.nifi.minifi.commons.schema.common.CollectionUtil.nullToEmpty) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) HashMap(java.util.HashMap) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 43 with PortDTO

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);
}
Also used : PortDTO(org.apache.nifi.web.api.dto.PortDTO)

Example 44 with 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);
}
Also used : PortDTO(org.apache.nifi.web.api.dto.PortDTO)

Example 45 with 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);
    }
}
Also used : PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Aggregations

PortDTO (org.apache.nifi.web.api.dto.PortDTO)71 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)30 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)29 HashSet (java.util.HashSet)28 ArrayList (java.util.ArrayList)27 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)26 HashMap (java.util.HashMap)24 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)22 Map (java.util.Map)21 Set (java.util.Set)20 List (java.util.List)18 Collectors (java.util.stream.Collectors)18 TemplateDTO (org.apache.nifi.web.api.dto.TemplateDTO)18 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)15 Collection (java.util.Collection)14 Optional (java.util.Optional)14 PortEntity (org.apache.nifi.web.api.entity.PortEntity)14