Search in sources :

Example 26 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardOutputPortDAO method updatePort.

@Override
public Port updatePort(PortDTO portDTO) {
    Port outputPort = locatePort(portDTO.getId());
    // ensure we can do this update
    verifyUpdate(outputPort, portDTO);
    // handle state transition
    if (portDTO.getState() != null) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(portDTO.getState());
        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(outputPort.getScheduledState())) {
            try {
                // perform the appropriate action
                switch(purposedScheduledState) {
                    case RUNNING:
                        outputPort.getProcessGroup().startOutputPort(outputPort);
                        break;
                    case STOPPED:
                        switch(outputPort.getScheduledState()) {
                            case RUNNING:
                                outputPort.getProcessGroup().stopOutputPort(outputPort);
                                break;
                            case DISABLED:
                                outputPort.getProcessGroup().enableOutputPort(outputPort);
                                break;
                        }
                        break;
                    case DISABLED:
                        outputPort.getProcessGroup().disableOutputPort(outputPort);
                        break;
                }
            } catch (IllegalStateException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            }
        }
    }
    if (outputPort instanceof RootGroupPort) {
        final RootGroupPort rootPort = (RootGroupPort) outputPort;
        if (isNotNull(portDTO.getGroupAccessControl())) {
            rootPort.setGroupAccessControl(portDTO.getGroupAccessControl());
        }
        if (isNotNull(portDTO.getUserAccessControl())) {
            rootPort.setUserAccessControl(portDTO.getUserAccessControl());
        }
    }
    // perform the configuration
    final String name = portDTO.getName();
    final String comments = portDTO.getComments();
    final Integer concurrentTasks = portDTO.getConcurrentlySchedulableTaskCount();
    if (isNotNull(portDTO.getPosition())) {
        outputPort.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    if (isNotNull(name)) {
        outputPort.setName(name);
    }
    if (isNotNull(comments)) {
        outputPort.setComments(comments);
    }
    if (isNotNull(concurrentTasks)) {
        outputPort.setMaxConcurrentTasks(concurrentTasks);
    }
    outputPort.getProcessGroup().onComponentModified();
    return outputPort;
}
Also used : NiFiCoreException(org.apache.nifi.web.NiFiCoreException) ScheduledState(org.apache.nifi.controller.ScheduledState) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Position(org.apache.nifi.connectable.Position) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort)

Example 27 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardOutputPortDAO method createPort.

@Override
public Port createPort(String groupId, PortDTO portDTO) {
    if (isNotNull(portDTO.getParentGroupId()) && !flowController.areGroupsSame(groupId, portDTO.getParentGroupId())) {
        throw new IllegalArgumentException("Cannot specify a different Parent Group ID than the Group to which the OutputPort is being added.");
    }
    // ensure the name has been specified
    if (portDTO.getName() == null) {
        throw new IllegalArgumentException("Port name must be specified.");
    }
    // get the desired group
    ProcessGroup group = locateProcessGroup(flowController, groupId);
    // determine if this is the root group
    Port port;
    if (group.getParent() == null) {
        port = flowController.createRemoteOutputPort(portDTO.getId(), portDTO.getName());
    } else {
        port = flowController.createLocalOutputPort(portDTO.getId(), portDTO.getName());
    }
    // ensure we can perform the update before we add the processor to the flow
    verifyUpdate(port, portDTO);
    // configure
    if (portDTO.getPosition() != null) {
        port.setPosition(new Position(portDTO.getPosition().getX(), portDTO.getPosition().getY()));
    }
    port.setComments(portDTO.getComments());
    // add the port
    group.addOutputPort(port);
    return port;
}
Also used : Position(org.apache.nifi.connectable.Position) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 28 with Position

use of org.apache.nifi.connectable.Position in project nifi by apache.

the class StandardRemoteProcessGroupDAO method updateRemoteProcessGroup.

private RemoteProcessGroup updateRemoteProcessGroup(RemoteProcessGroup remoteProcessGroup, RemoteProcessGroupDTO remoteProcessGroupDTO) {
    // verify the update request
    verifyUpdate(remoteProcessGroup, remoteProcessGroupDTO);
    // configure the remote process group
    final String targetUris = remoteProcessGroupDTO.getTargetUris();
    final String name = remoteProcessGroupDTO.getName();
    final String comments = remoteProcessGroupDTO.getComments();
    final String communicationsTimeout = remoteProcessGroupDTO.getCommunicationsTimeout();
    final String yieldDuration = remoteProcessGroupDTO.getYieldDuration();
    final String proxyHost = remoteProcessGroupDTO.getProxyHost();
    final Integer proxyPort = remoteProcessGroupDTO.getProxyPort();
    final String proxyUser = remoteProcessGroupDTO.getProxyUser();
    final String proxyPassword = remoteProcessGroupDTO.getProxyPassword();
    final String transportProtocol = remoteProcessGroupDTO.getTransportProtocol();
    final String localNetworkInterface = remoteProcessGroupDTO.getLocalNetworkInterface();
    if (isNotNull(targetUris)) {
        remoteProcessGroup.setTargetUris(targetUris);
    }
    if (isNotNull(name)) {
        remoteProcessGroup.setName(name);
    }
    if (isNotNull(comments)) {
        remoteProcessGroup.setComments(comments);
    }
    if (isNotNull(communicationsTimeout)) {
        remoteProcessGroup.setCommunicationsTimeout(communicationsTimeout);
    }
    if (isNotNull(yieldDuration)) {
        remoteProcessGroup.setYieldDuration(yieldDuration);
    }
    if (isNotNull(remoteProcessGroupDTO.getPosition())) {
        remoteProcessGroup.setPosition(new Position(remoteProcessGroupDTO.getPosition().getX(), remoteProcessGroupDTO.getPosition().getY()));
    }
    if (isNotNull(transportProtocol)) {
        remoteProcessGroup.setTransportProtocol(SiteToSiteTransportProtocol.valueOf(transportProtocol.toUpperCase()));
        // No null check because these proxy settings have to be clear if not specified.
        // But when user Enable/Disable transmission, only isTransmitting is sent.
        // To prevent clearing these values in that case, set these only if transportProtocol is sent,
        // assuming UI sends transportProtocol always for update.
        remoteProcessGroup.setProxyHost(proxyHost);
        remoteProcessGroup.setProxyPort(proxyPort);
        remoteProcessGroup.setProxyUser(proxyUser);
        // specify empty String to clear password.
        if (isNotNull(proxyPassword) && !DtoFactory.SENSITIVE_VALUE_MASK.equals(proxyPassword)) {
            remoteProcessGroup.setProxyPassword(proxyPassword);
        }
    }
    if (localNetworkInterface != null) {
        if (StringUtils.isBlank(localNetworkInterface)) {
            remoteProcessGroup.setNetworkInterface(null);
        } else {
            remoteProcessGroup.setNetworkInterface(localNetworkInterface);
        }
    }
    final Boolean isTransmitting = remoteProcessGroupDTO.isTransmitting();
    if (isNotNull(isTransmitting)) {
        // start or stop as necessary
        if (!remoteProcessGroup.isTransmitting() && isTransmitting) {
            remoteProcessGroup.startTransmitting();
        } else if (remoteProcessGroup.isTransmitting() && !isTransmitting) {
            remoteProcessGroup.stopTransmitting();
        }
    }
    final ProcessGroup group = remoteProcessGroup.getProcessGroup();
    if (group != null) {
        group.onComponentModified();
    }
    return remoteProcessGroup;
}
Also used : Position(org.apache.nifi.connectable.Position) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup)

Aggregations

Position (org.apache.nifi.connectable.Position)28 Port (org.apache.nifi.connectable.Port)10 ProcessGroup (org.apache.nifi.groups.ProcessGroup)10 RootGroupPort (org.apache.nifi.remote.RootGroupPort)10 ArrayList (java.util.ArrayList)9 Size (org.apache.nifi.connectable.Size)9 FlowFilePrioritizer (org.apache.nifi.flowfile.FlowFilePrioritizer)9 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)9 HashSet (java.util.HashSet)7 Funnel (org.apache.nifi.connectable.Funnel)7 Label (org.apache.nifi.controller.label.Label)7 Relationship (org.apache.nifi.processor.Relationship)7 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)6 Connection (org.apache.nifi.connectable.Connection)5 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)5 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 Element (org.w3c.dom.Element)5 URL (java.net.URL)4