Search in sources :

Example 1 with FunnelDTO

use of org.apache.nifi.web.api.dto.FunnelDTO in project nifi by apache.

the class StandardNiFiServiceFacade method updateFunnel.

@Override
public FunnelEntity updateFunnel(final Revision revision, final FunnelDTO funnelDTO) {
    final Funnel funnelNode = funnelDAO.getFunnel(funnelDTO.getId());
    final RevisionUpdate<FunnelDTO> snapshot = updateComponent(revision, funnelNode, () -> funnelDAO.updateFunnel(funnelDTO), funnel -> dtoFactory.createFunnelDto(funnel));
    final PermissionsDTO permissions = dtoFactory.createPermissionsDto(funnelNode);
    return entityFactory.createFunnelEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions);
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO)

Example 2 with FunnelDTO

use of org.apache.nifi.web.api.dto.FunnelDTO in project nifi by apache.

the class NiFiWebApiTest method populateFlow.

public static void populateFlow(Client client, String baseUrl, NiFiTestUser user, String clientId) throws Exception {
    // -----------------------------------------------
    // Create a source processor
    // -----------------------------------------------
    // create the local selection processor
    ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setName("Pick up");
    processorDTO.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(clientId);
    revision.setVersion(0l);
    // create the local selection processor entity
    ProcessorEntity processorEntity = new ProcessorEntity();
    processorEntity.setRevision(revision);
    processorEntity.setComponent(processorDTO);
    // add the processor
    Response response = user.testPost(baseUrl + "/process-groups/root/processors", processorEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // get the processors id
    processorEntity = response.readEntity(ProcessorEntity.class);
    processorDTO = processorEntity.getComponent();
    String localSelectionId = processorDTO.getId();
    String localSelectionGroupId = processorDTO.getParentGroupId();
    // -----------------------------------------------
    // Create a termination processor
    // -----------------------------------------------
    // create the termination processor
    processorDTO = new ProcessorDTO();
    processorDTO.setName("End");
    processorDTO.setType(TerminationTestProcessor.class.getName());
    // create the termination processor entity
    processorEntity = new ProcessorEntity();
    processorEntity.setRevision(revision);
    processorEntity.setComponent(processorDTO);
    // add the processor
    response = user.testPost(baseUrl + "/process-groups/root/processors", processorEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // get the processors id
    processorEntity = response.readEntity(ProcessorEntity.class);
    processorDTO = processorEntity.getComponent();
    String terminationId = processorDTO.getId();
    String terminationGroupId = processorDTO.getParentGroupId();
    // -----------------------------------------------
    // Connect the two processors
    // -----------------------------------------------
    ConnectableDTO source = new ConnectableDTO();
    source.setId(localSelectionId);
    source.setGroupId(localSelectionGroupId);
    source.setType(ConnectableType.PROCESSOR.name());
    ConnectableDTO target = new ConnectableDTO();
    target.setId(terminationId);
    target.setGroupId(terminationGroupId);
    target.setType(ConnectableType.PROCESSOR.name());
    // create the relationships
    Set<String> relationships = new HashSet<>();
    relationships.add("success");
    // create the connection
    ConnectionDTO connectionDTO = new ConnectionDTO();
    connectionDTO.setSource(source);
    connectionDTO.setDestination(target);
    connectionDTO.setSelectedRelationships(relationships);
    // create the connection entity
    ConnectionEntity connectionEntity = new ConnectionEntity();
    connectionEntity.setRevision(revision);
    connectionEntity.setComponent(connectionDTO);
    // add the processor
    response = user.testPost(baseUrl + "/process-groups/root/connections", connectionEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a label
    // -----------------------------------------------
    // create the label
    LabelDTO labelDTO = new LabelDTO();
    labelDTO.setLabel("Test label");
    // create the label entity
    LabelEntity labelEntity = new LabelEntity();
    labelEntity.setRevision(revision);
    labelEntity.setComponent(labelDTO);
    // add the label
    response = user.testPost(baseUrl + "/process-groups/root/labels", labelEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a funnel
    // -----------------------------------------------
    // create the funnel
    FunnelDTO funnelDTO = new FunnelDTO();
    // create the funnel entity
    FunnelEntity funnelEntity = new FunnelEntity();
    funnelEntity.setRevision(revision);
    funnelEntity.setComponent(funnelDTO);
    // add the funnel
    response = user.testPost(baseUrl + "/process-groups/root/funnels", funnelEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a process group
    // -----------------------------------------------
    // create the process group
    ProcessGroupDTO processGroup = new ProcessGroupDTO();
    processGroup.setName("group name");
    // create the process group entity
    ProcessGroupEntity processGroupEntity = new ProcessGroupEntity();
    processGroupEntity.setRevision(revision);
    processGroupEntity.setComponent(processGroup);
    // add the process group
    response = user.testPost(baseUrl + "/process-groups/root/process-groups", processGroupEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create an input port
    // -----------------------------------------------
    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName("input");
    // create the input port entity
    PortEntity inputPortEntity = new PortEntity();
    inputPortEntity.setRevision(revision);
    inputPortEntity.setComponent(inputPort);
    // add the input port
    response = user.testPost(baseUrl + "/process-groups/root/input-ports", inputPortEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a output ports
    // -----------------------------------------------
    // create the process group
    PortDTO outputPort = new PortDTO();
    outputPort.setName("output");
    // create the process group entity
    PortEntity outputPortEntity = new PortEntity();
    outputPortEntity.setRevision(revision);
    outputPortEntity.setComponent(outputPort);
    // add the output port
    response = user.testPost(baseUrl + "/process-groups/root/output-ports", outputPortEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Response(javax.ws.rs.core.Response) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) TerminationTestProcessor(org.apache.nifi.integration.util.TerminationTestProcessor) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) SourceTestProcessor(org.apache.nifi.integration.util.SourceTestProcessor) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) HashSet(java.util.HashSet) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 3 with FunnelDTO

use of org.apache.nifi.web.api.dto.FunnelDTO in project nifi by apache.

the class ITFunnelAccessControl method createFunnel.

private FunnelEntity createFunnel() throws Exception {
    String url = helper.getBaseUrl() + "/process-groups/root/funnels";
    // create the funnel
    FunnelDTO funnel = new FunnelDTO();
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(READ_WRITE_CLIENT_ID);
    revision.setVersion(0L);
    // create the entity body
    FunnelEntity entity = new FunnelEntity();
    entity.setRevision(revision);
    entity.setComponent(funnel);
    // perform the request
    Response response = helper.getReadWriteUser().testPost(url, entity);
    // ensure the request is successful
    assertEquals(201, response.getStatus());
    // get the entity body
    return response.readEntity(FunnelEntity.class);
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Response(javax.ws.rs.core.Response) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO)

Example 4 with FunnelDTO

use of org.apache.nifi.web.api.dto.FunnelDTO in project nifi by apache.

the class StandardFlowSynchronizer method addProcessGroup.

private ProcessGroup addProcessGroup(final FlowController controller, final ProcessGroup parentGroup, final Element processGroupElement, final StringEncryptor encryptor, final FlowEncodingVersion encodingVersion) throws ProcessorInstantiationException {
    // get the parent group ID
    final String parentId = (parentGroup == null) ? null : parentGroup.getIdentifier();
    // add the process group
    final ProcessGroupDTO processGroupDTO = FlowFromDOMFactory.getProcessGroup(parentId, processGroupElement, encryptor, encodingVersion);
    final ProcessGroup processGroup = controller.createProcessGroup(processGroupDTO.getId());
    processGroup.setComments(processGroupDTO.getComments());
    processGroup.setVersionedComponentId(processGroupDTO.getVersionedComponentId());
    processGroup.setPosition(toPosition(processGroupDTO.getPosition()));
    processGroup.setName(processGroupDTO.getName());
    processGroup.setParent(parentGroup);
    if (parentGroup == null) {
        controller.setRootGroup(processGroup);
    } else {
        parentGroup.addProcessGroup(processGroup);
    }
    // Set the variables for the variable registry
    final Map<String, String> variables = new HashMap<>();
    final List<Element> variableElements = getChildrenByTagName(processGroupElement, "variable");
    for (final Element variableElement : variableElements) {
        final String variableName = variableElement.getAttribute("name");
        final String variableValue = variableElement.getAttribute("value");
        if (variableName == null || variableValue == null) {
            continue;
        }
        variables.put(variableName, variableValue);
    }
    processGroup.setVariables(variables);
    final VersionControlInformationDTO versionControlInfoDto = processGroupDTO.getVersionControlInformation();
    if (versionControlInfoDto != null) {
        final FlowRegistry flowRegistry = controller.getFlowRegistryClient().getFlowRegistry(versionControlInfoDto.getRegistryId());
        final String registryName = flowRegistry == null ? versionControlInfoDto.getRegistryId() : flowRegistry.getName();
        versionControlInfoDto.setState(VersionedFlowState.SYNC_FAILURE.name());
        versionControlInfoDto.setStateExplanation("Process Group has not yet been synchronized with the Flow Registry");
        final StandardVersionControlInformation versionControlInformation = StandardVersionControlInformation.Builder.fromDto(versionControlInfoDto).registryName(registryName).build();
        // pass empty map for the version control mapping because the VersionedComponentId has already been set on the components
        processGroup.setVersionControlInformation(versionControlInformation, Collections.emptyMap());
    }
    // Add Controller Services
    final List<Element> serviceNodeList = getChildrenByTagName(processGroupElement, "controllerService");
    if (!serviceNodeList.isEmpty()) {
        final Map<ControllerServiceNode, Element> controllerServices = ControllerServiceLoader.loadControllerServices(serviceNodeList, controller, processGroup, encryptor);
        ControllerServiceLoader.enableControllerServices(controllerServices, controller, encryptor, autoResumeState);
    }
    // add processors
    final List<Element> processorNodeList = getChildrenByTagName(processGroupElement, "processor");
    for (final Element processorElement : processorNodeList) {
        final ProcessorDTO processorDTO = FlowFromDOMFactory.getProcessor(processorElement, encryptor);
        BundleCoordinate coordinate;
        try {
            coordinate = BundleUtils.getCompatibleBundle(processorDTO.getType(), processorDTO.getBundle());
        } catch (final IllegalStateException e) {
            final BundleDTO bundleDTO = processorDTO.getBundle();
            if (bundleDTO == null) {
                coordinate = BundleCoordinate.UNKNOWN_COORDINATE;
            } else {
                coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion());
            }
        }
        final ProcessorNode procNode = controller.createProcessor(processorDTO.getType(), processorDTO.getId(), coordinate, false);
        procNode.setVersionedComponentId(processorDTO.getVersionedComponentId());
        processGroup.addProcessor(procNode);
        updateProcessor(procNode, processorDTO, processGroup, controller);
    }
    // add input ports
    final List<Element> inputPortNodeList = getChildrenByTagName(processGroupElement, "inputPort");
    for (final Element inputPortElement : inputPortNodeList) {
        final PortDTO portDTO = FlowFromDOMFactory.getPort(inputPortElement);
        final Port port;
        if (processGroup.isRootGroup()) {
            port = controller.createRemoteInputPort(portDTO.getId(), portDTO.getName());
        } else {
            port = controller.createLocalInputPort(portDTO.getId(), portDTO.getName());
        }
        port.setVersionedComponentId(portDTO.getVersionedComponentId());
        port.setPosition(toPosition(portDTO.getPosition()));
        port.setComments(portDTO.getComments());
        port.setProcessGroup(processGroup);
        final Set<String> userControls = portDTO.getUserAccessControl();
        if (userControls != null && !userControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add User Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setUserAccessControl(userControls);
        }
        final Set<String> groupControls = portDTO.getGroupAccessControl();
        if (groupControls != null && !groupControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add Group Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setGroupAccessControl(groupControls);
        }
        processGroup.addInputPort(port);
        if (portDTO.getConcurrentlySchedulableTaskCount() != null) {
            port.setMaxConcurrentTasks(portDTO.getConcurrentlySchedulableTaskCount());
        }
        final ScheduledState scheduledState = ScheduledState.valueOf(portDTO.getState());
        if (ScheduledState.RUNNING.equals(scheduledState)) {
            controller.startConnectable(port);
        } else if (ScheduledState.DISABLED.equals(scheduledState)) {
            processGroup.disableInputPort(port);
        }
    }
    // add output ports
    final List<Element> outputPortNodeList = getChildrenByTagName(processGroupElement, "outputPort");
    for (final Element outputPortElement : outputPortNodeList) {
        final PortDTO portDTO = FlowFromDOMFactory.getPort(outputPortElement);
        final Port port;
        if (processGroup.isRootGroup()) {
            port = controller.createRemoteOutputPort(portDTO.getId(), portDTO.getName());
        } else {
            port = controller.createLocalOutputPort(portDTO.getId(), portDTO.getName());
        }
        port.setVersionedComponentId(portDTO.getVersionedComponentId());
        port.setPosition(toPosition(portDTO.getPosition()));
        port.setComments(portDTO.getComments());
        port.setProcessGroup(processGroup);
        final Set<String> userControls = portDTO.getUserAccessControl();
        if (userControls != null && !userControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add User Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setUserAccessControl(userControls);
        }
        final Set<String> groupControls = portDTO.getGroupAccessControl();
        if (groupControls != null && !groupControls.isEmpty()) {
            if (!(port instanceof RootGroupPort)) {
                throw new IllegalStateException("Attempting to add Group Access Controls to " + port.getIdentifier() + ", but it is not a RootGroupPort");
            }
            ((RootGroupPort) port).setGroupAccessControl(groupControls);
        }
        processGroup.addOutputPort(port);
        if (portDTO.getConcurrentlySchedulableTaskCount() != null) {
            port.setMaxConcurrentTasks(portDTO.getConcurrentlySchedulableTaskCount());
        }
        final ScheduledState scheduledState = ScheduledState.valueOf(portDTO.getState());
        if (ScheduledState.RUNNING.equals(scheduledState)) {
            controller.startConnectable(port);
        } else if (ScheduledState.DISABLED.equals(scheduledState)) {
            processGroup.disableOutputPort(port);
        }
    }
    // add funnels
    final List<Element> funnelNodeList = getChildrenByTagName(processGroupElement, "funnel");
    for (final Element funnelElement : funnelNodeList) {
        final FunnelDTO funnelDTO = FlowFromDOMFactory.getFunnel(funnelElement);
        final Funnel funnel = controller.createFunnel(funnelDTO.getId());
        funnel.setVersionedComponentId(funnelDTO.getVersionedComponentId());
        funnel.setPosition(toPosition(funnelDTO.getPosition()));
        // Since this is called during startup, we want to add the funnel without enabling it
        // and then tell the controller to enable it. This way, if the controller is not fully
        // initialized, the starting of the funnel is delayed until the controller is ready.
        processGroup.addFunnel(funnel, false);
        controller.startConnectable(funnel);
    }
    // add labels
    final List<Element> labelNodeList = getChildrenByTagName(processGroupElement, "label");
    for (final Element labelElement : labelNodeList) {
        final LabelDTO labelDTO = FlowFromDOMFactory.getLabel(labelElement);
        final Label label = controller.createLabel(labelDTO.getId(), labelDTO.getLabel());
        label.setVersionedComponentId(labelDTO.getVersionedComponentId());
        label.setStyle(labelDTO.getStyle());
        label.setPosition(toPosition(labelDTO.getPosition()));
        label.setSize(new Size(labelDTO.getWidth(), labelDTO.getHeight()));
        processGroup.addLabel(label);
    }
    // add nested process groups (recursively)
    final List<Element> nestedProcessGroupNodeList = getChildrenByTagName(processGroupElement, "processGroup");
    for (final Element nestedProcessGroupElement : nestedProcessGroupNodeList) {
        addProcessGroup(controller, processGroup, nestedProcessGroupElement, encryptor, encodingVersion);
    }
    // add remote process group
    final List<Element> remoteProcessGroupNodeList = getChildrenByTagName(processGroupElement, "remoteProcessGroup");
    for (final Element remoteProcessGroupElement : remoteProcessGroupNodeList) {
        final RemoteProcessGroupDTO remoteGroupDto = FlowFromDOMFactory.getRemoteProcessGroup(remoteProcessGroupElement, encryptor);
        final RemoteProcessGroup remoteGroup = controller.createRemoteProcessGroup(remoteGroupDto.getId(), remoteGroupDto.getTargetUris());
        remoteGroup.setVersionedComponentId(remoteGroupDto.getVersionedComponentId());
        remoteGroup.setComments(remoteGroupDto.getComments());
        remoteGroup.setPosition(toPosition(remoteGroupDto.getPosition()));
        final String name = remoteGroupDto.getName();
        if (name != null && !name.trim().isEmpty()) {
            remoteGroup.setName(name);
        }
        remoteGroup.setProcessGroup(processGroup);
        remoteGroup.setCommunicationsTimeout(remoteGroupDto.getCommunicationsTimeout());
        if (remoteGroupDto.getYieldDuration() != null) {
            remoteGroup.setYieldDuration(remoteGroupDto.getYieldDuration());
        }
        final String transportProtocol = remoteGroupDto.getTransportProtocol();
        if (transportProtocol != null && !transportProtocol.trim().isEmpty()) {
            remoteGroup.setTransportProtocol(SiteToSiteTransportProtocol.valueOf(transportProtocol.toUpperCase()));
        }
        if (remoteGroupDto.getProxyHost() != null) {
            remoteGroup.setProxyHost(remoteGroupDto.getProxyHost());
        }
        if (remoteGroupDto.getProxyPort() != null) {
            remoteGroup.setProxyPort(remoteGroupDto.getProxyPort());
        }
        if (remoteGroupDto.getProxyUser() != null) {
            remoteGroup.setProxyUser(remoteGroupDto.getProxyUser());
        }
        if (remoteGroupDto.getProxyPassword() != null) {
            remoteGroup.setProxyPassword(remoteGroupDto.getProxyPassword());
        }
        if (StringUtils.isBlank(remoteGroupDto.getLocalNetworkInterface())) {
            remoteGroup.setNetworkInterface(null);
        } else {
            remoteGroup.setNetworkInterface(remoteGroupDto.getLocalNetworkInterface());
        }
        final Set<RemoteProcessGroupPortDescriptor> inputPorts = new HashSet<>();
        for (final Element portElement : getChildrenByTagName(remoteProcessGroupElement, "inputPort")) {
            inputPorts.add(FlowFromDOMFactory.getRemoteProcessGroupPort(portElement));
        }
        remoteGroup.setInputPorts(inputPorts, false);
        final Set<RemoteProcessGroupPortDescriptor> outputPorts = new HashSet<>();
        for (final Element portElement : getChildrenByTagName(remoteProcessGroupElement, "outputPort")) {
            outputPorts.add(FlowFromDOMFactory.getRemoteProcessGroupPort(portElement));
        }
        remoteGroup.setOutputPorts(outputPorts, false);
        processGroup.addRemoteProcessGroup(remoteGroup);
        for (final RemoteProcessGroupPortDescriptor remoteGroupPortDTO : outputPorts) {
            final RemoteGroupPort port = remoteGroup.getOutputPort(remoteGroupPortDTO.getId());
            if (Boolean.TRUE.equals(remoteGroupPortDTO.isTransmitting())) {
                controller.startTransmitting(port);
            }
        }
        for (final RemoteProcessGroupPortDescriptor remoteGroupPortDTO : inputPorts) {
            final RemoteGroupPort port = remoteGroup.getInputPort(remoteGroupPortDTO.getId());
            if (Boolean.TRUE.equals(remoteGroupPortDTO.isTransmitting())) {
                controller.startTransmitting(port);
            }
        }
    }
    // add connections
    final List<Element> connectionNodeList = getChildrenByTagName(processGroupElement, "connection");
    for (final Element connectionElement : connectionNodeList) {
        final ConnectionDTO dto = FlowFromDOMFactory.getConnection(connectionElement);
        final Connectable source;
        final ConnectableDTO sourceDto = dto.getSource();
        if (ConnectableType.REMOTE_OUTPUT_PORT.name().equals(sourceDto.getType())) {
            final RemoteProcessGroup remoteGroup = processGroup.getRemoteProcessGroup(sourceDto.getGroupId());
            source = remoteGroup.getOutputPort(sourceDto.getId());
        } else {
            final ProcessGroup sourceGroup = controller.getGroup(sourceDto.getGroupId());
            if (sourceGroup == null) {
                throw new RuntimeException("Found Invalid ProcessGroup ID for Source: " + dto.getSource().getGroupId());
            }
            source = sourceGroup.getConnectable(sourceDto.getId());
        }
        if (source == null) {
            throw new RuntimeException("Found Invalid Connectable ID for Source: " + dto.getSource().getId());
        }
        final Connectable destination;
        final ConnectableDTO destinationDto = dto.getDestination();
        if (ConnectableType.REMOTE_INPUT_PORT.name().equals(destinationDto.getType())) {
            final RemoteProcessGroup remoteGroup = processGroup.getRemoteProcessGroup(destinationDto.getGroupId());
            destination = remoteGroup.getInputPort(destinationDto.getId());
        } else {
            final ProcessGroup destinationGroup = controller.getGroup(destinationDto.getGroupId());
            if (destinationGroup == null) {
                throw new RuntimeException("Found Invalid ProcessGroup ID for Destination: " + dto.getDestination().getGroupId());
            }
            destination = destinationGroup.getConnectable(destinationDto.getId());
        }
        if (destination == null) {
            throw new RuntimeException("Found Invalid Connectable ID for Destination: " + dto.getDestination().getId());
        }
        final Connection connection = controller.createConnection(dto.getId(), dto.getName(), source, destination, dto.getSelectedRelationships());
        connection.setVersionedComponentId(dto.getVersionedComponentId());
        connection.setProcessGroup(processGroup);
        final List<Position> bendPoints = new ArrayList<>();
        for (final PositionDTO bend : dto.getBends()) {
            bendPoints.add(new Position(bend.getX(), bend.getY()));
        }
        connection.setBendPoints(bendPoints);
        final Long zIndex = dto.getzIndex();
        if (zIndex != null) {
            connection.setZIndex(zIndex);
        }
        if (dto.getLabelIndex() != null) {
            connection.setLabelIndex(dto.getLabelIndex());
        }
        List<FlowFilePrioritizer> newPrioritizers = null;
        final List<String> prioritizers = dto.getPrioritizers();
        if (prioritizers != null) {
            final List<String> newPrioritizersClasses = new ArrayList<>(prioritizers);
            newPrioritizers = new ArrayList<>();
            for (final String className : newPrioritizersClasses) {
                try {
                    newPrioritizers.add(controller.createPrioritizer(className));
                } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException e) {
                    throw new IllegalArgumentException("Unable to set prioritizer " + className + ": " + e);
                }
            }
        }
        if (newPrioritizers != null) {
            connection.getFlowFileQueue().setPriorities(newPrioritizers);
        }
        if (dto.getBackPressureObjectThreshold() != null) {
            connection.getFlowFileQueue().setBackPressureObjectThreshold(dto.getBackPressureObjectThreshold());
        }
        if (dto.getBackPressureDataSizeThreshold() != null) {
            connection.getFlowFileQueue().setBackPressureDataSizeThreshold(dto.getBackPressureDataSizeThreshold());
        }
        if (dto.getFlowFileExpiration() != null) {
            connection.getFlowFileQueue().setFlowFileExpiration(dto.getFlowFileExpiration());
        }
        processGroup.addConnection(connection);
    }
    final List<Element> templateNodeList = getChildrenByTagName(processGroupElement, "template");
    for (final Element templateNode : templateNodeList) {
        final TemplateDTO templateDTO = TemplateUtils.parseDto(templateNode);
        final Template template = new Template(templateDTO);
        processGroup.addTemplate(template);
    }
    return processGroup;
}
Also used : HashMap(java.util.HashMap) Size(org.apache.nifi.connectable.Size) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) ArrayList(java.util.ArrayList) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Connectable(org.apache.nifi.connectable.Connectable) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) HashSet(java.util.HashSet) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Position(org.apache.nifi.connectable.Position) PortDTO(org.apache.nifi.web.api.dto.PortDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Funnel(org.apache.nifi.connectable.Funnel) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Element(org.w3c.dom.Element) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) VersionControlInformationDTO(org.apache.nifi.web.api.dto.VersionControlInformationDTO) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connection(org.apache.nifi.connectable.Connection) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)

Example 5 with FunnelDTO

use of org.apache.nifi.web.api.dto.FunnelDTO in project nifi by apache.

the class FlowFromDOMFactory method getFunnel.

public static FunnelDTO getFunnel(final Element element) {
    final FunnelDTO dto = new FunnelDTO();
    dto.setId(getString(element, "id"));
    dto.setVersionedComponentId(getString(element, "versionedComponentId"));
    dto.setPosition(getPosition(DomUtils.getChild(element, "position")));
    return dto;
}
Also used : FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO)

Aggregations

FunnelDTO (org.apache.nifi.web.api.dto.FunnelDTO)15 ConnectionDTO (org.apache.nifi.web.api.dto.ConnectionDTO)7 PortDTO (org.apache.nifi.web.api.dto.PortDTO)7 ProcessGroupDTO (org.apache.nifi.web.api.dto.ProcessGroupDTO)7 ProcessorDTO (org.apache.nifi.web.api.dto.ProcessorDTO)7 HashSet (java.util.HashSet)6 Funnel (org.apache.nifi.connectable.Funnel)6 ConnectableDTO (org.apache.nifi.web.api.dto.ConnectableDTO)6 LabelDTO (org.apache.nifi.web.api.dto.LabelDTO)6 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)6 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)6 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Response (javax.ws.rs.core.Response)4 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 LinkedHashSet (java.util.LinkedHashSet)3 FlowSnippetDTO (org.apache.nifi.web.api.dto.FlowSnippetDTO)3 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)2 Connectable (org.apache.nifi.connectable.Connectable)2