Search in sources :

Example 1 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class StandardNiFiServiceFacade method isRemoteGroupPortConnected.

@Override
public boolean isRemoteGroupPortConnected(final String remoteProcessGroupId, final String remotePortId) {
    final RemoteProcessGroup rpg = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);
    RemoteGroupPort port = rpg.getInputPort(remotePortId);
    if (port != null) {
        return port.hasIncomingConnection();
    }
    port = rpg.getOutputPort(remotePortId);
    if (port != null) {
        return !port.getConnections().isEmpty();
    }
    throw new ResourceNotFoundException("Could not find Port with ID " + remotePortId + " as a child of RemoteProcessGroup with ID " + remoteProcessGroupId);
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort)

Example 2 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class DtoFactory method createRemoteProcessGroupDto.

/**
 * Creates a RemoteProcessGroupDTO from the specified RemoteProcessGroup.
 *
 * @param group group
 * @return dto
 */
public RemoteProcessGroupDTO createRemoteProcessGroupDto(final RemoteProcessGroup group) {
    if (group == null) {
        return null;
    }
    final Set<RemoteProcessGroupPortDTO> inputPorts = new HashSet<>();
    final Set<RemoteProcessGroupPortDTO> outputPorts = new HashSet<>();
    int activeRemoteInputPortCount = 0;
    int inactiveRemoteInputPortCount = 0;
    for (final Port port : group.getInputPorts()) {
        inputPorts.add(createRemoteProcessGroupPortDto((RemoteGroupPort) port));
        if (port.hasIncomingConnection()) {
            if (port.isRunning()) {
                activeRemoteInputPortCount++;
            } else {
                inactiveRemoteInputPortCount++;
            }
        }
    }
    int activeRemoteOutputPortCount = 0;
    int inactiveRemoteOutputPortCount = 0;
    for (final Port port : group.getOutputPorts()) {
        outputPorts.add(createRemoteProcessGroupPortDto((RemoteGroupPort) port));
        if (!port.getConnections().isEmpty()) {
            if (port.isRunning()) {
                activeRemoteOutputPortCount++;
            } else {
                inactiveRemoteOutputPortCount++;
            }
        }
    }
    final RemoteProcessGroupContentsDTO contents = new RemoteProcessGroupContentsDTO();
    contents.setInputPorts(inputPorts);
    contents.setOutputPorts(outputPorts);
    final RemoteProcessGroupDTO dto = new RemoteProcessGroupDTO();
    dto.setId(group.getIdentifier());
    dto.setName(group.getName());
    dto.setPosition(createPositionDto(group.getPosition()));
    dto.setComments(group.getComments());
    dto.setTransmitting(group.isTransmitting());
    dto.setCommunicationsTimeout(group.getCommunicationsTimeout());
    dto.setYieldDuration(group.getYieldDuration());
    dto.setParentGroupId(group.getProcessGroup().getIdentifier());
    dto.setTargetUris(group.getTargetUris());
    dto.setFlowRefreshed(group.getLastRefreshTime());
    dto.setContents(contents);
    dto.setTransportProtocol(group.getTransportProtocol().name());
    dto.setProxyHost(group.getProxyHost());
    dto.setProxyPort(group.getProxyPort());
    dto.setProxyUser(group.getProxyUser());
    if (!StringUtils.isEmpty(group.getProxyPassword())) {
        dto.setProxyPassword(SENSITIVE_VALUE_MASK);
    }
    // only specify the secure flag if we know the target system has site to site enabled
    if (group.isSiteToSiteEnabled()) {
        dto.setTargetSecure(group.getSecureFlag());
    }
    if (group.getAuthorizationIssue() != null) {
        dto.setAuthorizationIssues(Arrays.asList(group.getAuthorizationIssue()));
    }
    final Collection<ValidationResult> validationErrors = group.validate();
    if (validationErrors != null && !validationErrors.isEmpty()) {
        final List<String> errors = new ArrayList<>();
        for (final ValidationResult validationResult : validationErrors) {
            errors.add(validationResult.toString());
        }
        dto.setValidationErrors(errors);
    }
    dto.setLocalNetworkInterface(group.getNetworkInterface());
    dto.setActiveRemoteInputPortCount(activeRemoteInputPortCount);
    dto.setInactiveRemoteInputPortCount(inactiveRemoteInputPortCount);
    dto.setActiveRemoteOutputPortCount(activeRemoteOutputPortCount);
    dto.setInactiveRemoteOutputPortCount(inactiveRemoteOutputPortCount);
    dto.setVersionedComponentId(group.getVersionedComponentId().orElse(null));
    final RemoteProcessGroupCounts counts = group.getCounts();
    if (counts != null) {
        dto.setInputPortCount(counts.getInputPortCount());
        dto.setOutputPortCount(counts.getOutputPortCount());
    }
    return dto;
}
Also used : RemoteProcessGroupCounts(org.apache.nifi.groups.RemoteProcessGroupCounts) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) InstantiatedVersionedPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort) ArrayList(java.util.ArrayList) ValidationResult(org.apache.nifi.components.ValidationResult) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class DtoFactory method createConnectableDto.

/**
 * Creates a ConnectableDTO from the specified Connectable.
 *
 * @param connectable connectable
 * @return dto
 */
public ConnectableDTO createConnectableDto(final Connectable connectable) {
    if (connectable == null) {
        return null;
    }
    boolean isAuthorized = connectable.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    final ConnectableDTO dto = new ConnectableDTO();
    dto.setId(connectable.getIdentifier());
    dto.setName(isAuthorized ? connectable.getName() : connectable.getIdentifier());
    dto.setType(connectable.getConnectableType().name());
    dto.setVersionedComponentId(connectable.getVersionedComponentId().orElse(null));
    if (connectable instanceof RemoteGroupPort) {
        final RemoteGroupPort remoteGroupPort = (RemoteGroupPort) connectable;
        final RemoteProcessGroup remoteGroup = remoteGroupPort.getRemoteProcessGroup();
        dto.setGroupId(remoteGroup.getIdentifier());
        dto.setRunning(remoteGroupPort.isTargetRunning());
        dto.setTransmitting(remoteGroupPort.isRunning());
        dto.setExists(remoteGroupPort.getTargetExists());
        if (isAuthorized) {
            dto.setComments(remoteGroup.getComments());
        }
    } else {
        dto.setGroupId(connectable.getProcessGroup().getIdentifier());
        dto.setRunning(connectable.isRunning());
        if (isAuthorized) {
            dto.setComments(connectable.getComments());
        }
    }
    return dto;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort)

Example 4 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class StandardConnectionDAO method validateProposedConfiguration.

/**
 * Validates the proposed processor configuration.
 */
private List<String> validateProposedConfiguration(final String groupId, final ConnectionDTO connectionDTO) {
    List<String> validationErrors = new ArrayList<>();
    if (isNotNull(connectionDTO.getBackPressureObjectThreshold()) && connectionDTO.getBackPressureObjectThreshold() < 0) {
        validationErrors.add("Max queue size must be a non-negative integer");
    }
    if (isNotNull(connectionDTO.getFlowFileExpiration())) {
        Matcher expirationMatcher = FormatUtils.TIME_DURATION_PATTERN.matcher(connectionDTO.getFlowFileExpiration());
        if (!expirationMatcher.matches()) {
            validationErrors.add("Flow file expiration is not a valid time duration (ie 30 sec, 5 min)");
        }
    }
    if (isNotNull(connectionDTO.getLabelIndex())) {
        if (connectionDTO.getLabelIndex() < 0) {
            validationErrors.add("The label index must be positive.");
        }
    }
    // validation is required when connecting to a remote process group since each node in a
    // cluster may or may not be authorized
    final ConnectableDTO proposedDestination = connectionDTO.getDestination();
    if (proposedDestination != null && ConnectableType.REMOTE_INPUT_PORT.name().equals(proposedDestination.getType())) {
        // the group id must be specified
        if (proposedDestination.getGroupId() == null) {
            validationErrors.add("When the destination is a remote input port its group id is required.");
            return validationErrors;
        }
        // attempt to location the proprosed destination
        final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, groupId);
        final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(proposedDestination.getGroupId());
        if (remoteProcessGroup == null) {
            validationErrors.add("Unable to find the specified remote process group.");
            return validationErrors;
        }
        // ensure the new destination was found
        final RemoteGroupPort remoteInputPort = remoteProcessGroup.getInputPort(proposedDestination.getId());
        if (remoteInputPort == null) {
            validationErrors.add("Unable to find the specified destination.");
            return validationErrors;
        }
    }
    return validationErrors;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Matcher(java.util.regex.Matcher) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Example 5 with RemoteGroupPort

use of org.apache.nifi.remote.RemoteGroupPort in project nifi by apache.

the class StandardConnectionDAO method updateConnection.

@Override
public Connection updateConnection(final ConnectionDTO connectionDTO) {
    final Connection connection = locateConnection(connectionDTO.getId());
    final ProcessGroup group = connection.getProcessGroup();
    // ensure we can update
    verifyUpdate(connection, connectionDTO);
    final Collection<Relationship> newProcessorRelationships = new ArrayList<>();
    Connectable newDestination = null;
    // ensure that the source ID is correct, if specified.
    final Connectable existingSource = connection.getSource();
    if (isNotNull(connectionDTO.getSource()) && !existingSource.getIdentifier().equals(connectionDTO.getSource().getId())) {
        throw new IllegalStateException("Connection with ID " + connectionDTO.getId() + " has conflicting Source ID");
    }
    // determine any new relationships
    final Set<String> relationships = connectionDTO.getSelectedRelationships();
    if (isNotNull(relationships)) {
        if (relationships.isEmpty()) {
            throw new IllegalArgumentException("Cannot remove all relationships from Connection with ID " + connection.getIdentifier() + " -- remove the Connection instead");
        }
        if (existingSource == null) {
            throw new IllegalArgumentException("Cannot specify new relationships without including the source.");
        }
        for (final String relationship : relationships) {
            final Relationship processorRelationship = existingSource.getRelationship(relationship);
            if (processorRelationship == null) {
                throw new IllegalArgumentException("Unable to locate " + relationship + " relationship.");
            }
            newProcessorRelationships.add(processorRelationship);
        }
    }
    // determine if the destination changed
    final ConnectableDTO proposedDestination = connectionDTO.getDestination();
    if (proposedDestination != null) {
        final Connectable currentDestination = connection.getDestination();
        // handle remote input port differently
        if (ConnectableType.REMOTE_INPUT_PORT.name().equals(proposedDestination.getType())) {
            // the group id must be specified
            if (proposedDestination.getGroupId() == null) {
                throw new IllegalArgumentException("When the destination is a remote input port its group id is required.");
            }
            // if the current destination is a remote input port
            boolean isDifferentRemoteProcessGroup = false;
            if (currentDestination.getConnectableType() == ConnectableType.REMOTE_INPUT_PORT) {
                RemoteGroupPort remotePort = (RemoteGroupPort) currentDestination;
                if (!proposedDestination.getGroupId().equals(remotePort.getRemoteProcessGroup().getIdentifier())) {
                    isDifferentRemoteProcessGroup = true;
                }
            }
            // if the destination is changing or the previous destination was a different remote process group
            if (!proposedDestination.getId().equals(currentDestination.getIdentifier()) || isDifferentRemoteProcessGroup) {
                final ProcessGroup destinationParentGroup = locateProcessGroup(flowController, group.getIdentifier());
                final RemoteProcessGroup remoteProcessGroup = destinationParentGroup.getRemoteProcessGroup(proposedDestination.getGroupId());
                // ensure the remote process group was found
                if (remoteProcessGroup == null) {
                    throw new IllegalArgumentException("Unable to find the specified remote process group.");
                }
                final RemoteGroupPort remoteInputPort = remoteProcessGroup.getInputPort(proposedDestination.getId());
                // ensure the new destination was found
                if (remoteInputPort == null) {
                    throw new IllegalArgumentException("Unable to find the specified destination.");
                }
                // ensure the remote port actually exists
                if (!remoteInputPort.getTargetExists()) {
                    throw new IllegalArgumentException("The specified remote input port does not exist.");
                } else {
                    newDestination = remoteInputPort;
                }
            }
        } else {
            // if there is a different destination id
            if (!proposedDestination.getId().equals(currentDestination.getIdentifier())) {
                // if the destination connectable's group id has not been set, its inferred to be the current group
                if (proposedDestination.getGroupId() == null) {
                    proposedDestination.setGroupId(group.getIdentifier());
                }
                final ProcessGroup destinationGroup = locateProcessGroup(flowController, proposedDestination.getGroupId());
                newDestination = destinationGroup.getConnectable(proposedDestination.getId());
                // ensure the new destination was found
                if (newDestination == null) {
                    throw new IllegalArgumentException("Unable to find the specified destination.");
                }
            }
        }
    }
    // configure the connection
    configureConnection(connection, connectionDTO);
    // update the relationships if necessary
    if (!newProcessorRelationships.isEmpty()) {
        connection.setRelationships(newProcessorRelationships);
    }
    // update the destination if necessary
    if (isNotNull(newDestination)) {
        connection.setDestination(newDestination);
    }
    return connection;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Connectable(org.apache.nifi.connectable.Connectable) Relationship(org.apache.nifi.processor.Relationship) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO)

Aggregations

RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)41 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 ProcessGroup (org.apache.nifi.groups.ProcessGroup)11 ArrayList (java.util.ArrayList)9 Connectable (org.apache.nifi.connectable.Connectable)9 Action (org.apache.nifi.action.Action)8 Port (org.apache.nifi.connectable.Port)8 Connection (org.apache.nifi.connectable.Connection)7 RootGroupPort (org.apache.nifi.remote.RootGroupPort)7 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Funnel (org.apache.nifi.connectable.Funnel)6 Authorizable (org.apache.nifi.authorization.resource.Authorizable)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)5 Collection (java.util.Collection)4 Position (org.apache.nifi.connectable.Position)4 Element (org.w3c.dom.Element)4 IOException (java.io.IOException)3