Search in sources :

Example 6 with RemoteProcessGroupPortDTO

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

the class FlowController method convertRemotePort.

/**
 * Converts a set of ports into a set of remote process group ports.
 *
 * @param ports ports
 * @return group descriptors
 */
private Set<RemoteProcessGroupPortDescriptor> convertRemotePort(final Set<RemoteProcessGroupPortDTO> ports) {
    Set<RemoteProcessGroupPortDescriptor> remotePorts = null;
    if (ports != null) {
        remotePorts = new LinkedHashSet<>(ports.size());
        for (final RemoteProcessGroupPortDTO port : ports) {
            final StandardRemoteProcessGroupPortDescriptor descriptor = new StandardRemoteProcessGroupPortDescriptor();
            descriptor.setId(port.getId());
            descriptor.setVersionedComponentId(port.getVersionedComponentId());
            descriptor.setTargetId(port.getTargetId());
            descriptor.setName(port.getName());
            descriptor.setComments(port.getComments());
            descriptor.setTargetRunning(port.isTargetRunning());
            descriptor.setConnected(port.isConnected());
            descriptor.setConcurrentlySchedulableTaskCount(port.getConcurrentlySchedulableTaskCount());
            descriptor.setTransmitting(port.isTransmitting());
            descriptor.setUseCompression(port.getUseCompression());
            final BatchSettingsDTO batchSettings = port.getBatchSettings();
            if (batchSettings != null) {
                descriptor.setBatchCount(batchSettings.getCount());
                descriptor.setBatchSize(batchSettings.getSize());
                descriptor.setBatchDuration(batchSettings.getDuration());
            }
            remotePorts.add(descriptor);
        }
    }
    return remotePorts;
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) RemoteProcessGroupPortDescriptor(org.apache.nifi.groups.RemoteProcessGroupPortDescriptor) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)

Example 7 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi-minifi by apache.

the class RemoteInputPortSchemaTest method setup.

@Before
public void setup() {
    dto = new RemoteProcessGroupPortDTO();
    dto.setId(testId);
    dto.setName(testName);
    dto.setComments(testComment);
    dto.setConcurrentlySchedulableTaskCount(testMaxConcurrentTasks);
    dto.setUseCompression(testUseCompression);
    map = new HashMap<>();
    map.put(CommonPropertyKeys.ID_KEY, testId);
    map.put(CommonPropertyKeys.NAME_KEY, testName);
    map.put(CommonPropertyKeys.COMMENT_KEY, testComment);
    map.put(CommonPropertyKeys.MAX_CONCURRENT_TASKS_KEY, testMaxConcurrentTasks);
    map.put(CommonPropertyKeys.USE_COMPRESSION_KEY, testUseCompression);
}
Also used : RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Before(org.junit.Before)

Example 8 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO 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 9 with RemoteProcessGroupPortDTO

use of org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO in project nifi-minifi by apache.

the class RemoteProcessGroupSchemaFunction method apply.

@Override
public RemoteProcessGroupSchema apply(RemoteProcessGroupDTO remoteProcessGroupDTO) {
    Map<String, Object> map = new HashMap<>();
    map.put(CommonPropertyKeys.ID_KEY, remoteProcessGroupDTO.getId());
    map.put(CommonPropertyKeys.NAME_KEY, remoteProcessGroupDTO.getName());
    map.put(RemoteProcessGroupSchema.URL_KEY, remoteProcessGroupDTO.getTargetUri());
    RemoteProcessGroupContentsDTO contents = remoteProcessGroupDTO.getContents();
    if (contents != null) {
        Set<RemoteProcessGroupPortDTO> inputPorts = contents.getInputPorts();
        if (inputPorts != null) {
            map.put(CommonPropertyKeys.INPUT_PORTS_KEY, inputPorts.stream().map(remotePortSchemaFunction).map(RemotePortSchema::toMap).collect(Collectors.toList()));
        }
        Set<RemoteProcessGroupPortDTO> outputPorts = contents.getOutputPorts();
        if (outputPorts != null) {
            map.put(CommonPropertyKeys.OUTPUT_PORTS_KEY, outputPorts.stream().map(remotePortSchemaFunction).map(RemotePortSchema::toMap).collect(Collectors.toList()));
        }
    }
    map.put(CommonPropertyKeys.COMMENT_KEY, remoteProcessGroupDTO.getComments());
    map.put(RemoteProcessGroupSchema.TIMEOUT_KEY, remoteProcessGroupDTO.getCommunicationsTimeout());
    map.put(CommonPropertyKeys.YIELD_PERIOD_KEY, remoteProcessGroupDTO.getYieldDuration());
    map.put(RemoteProcessGroupSchema.TRANSPORT_PROTOCOL_KEY, remoteProcessGroupDTO.getTransportProtocol());
    map.put(RemoteProcessGroupSchema.PROXY_HOST_KEY, remoteProcessGroupDTO.getProxyHost());
    map.put(RemoteProcessGroupSchema.PROXY_PORT_KEY, remoteProcessGroupDTO.getProxyPort());
    map.put(RemoteProcessGroupSchema.PROXY_USER_KEY, remoteProcessGroupDTO.getProxyUser());
    map.put(RemoteProcessGroupSchema.PROXY_PASSWORD_KEY, remoteProcessGroupDTO.getProxyPassword());
    map.put(RemoteProcessGroupSchema.LOCAL_NETWORK_INTERFACE_KEY, remoteProcessGroupDTO.getLocalNetworkInterface());
    return new RemoteProcessGroupSchema(map);
}
Also used : HashMap(java.util.HashMap) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) RemotePortSchema(org.apache.nifi.minifi.commons.schema.RemotePortSchema) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) RemoteProcessGroupSchema(org.apache.nifi.minifi.commons.schema.RemoteProcessGroupSchema)

Example 10 with RemoteProcessGroupPortDTO

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

the class RemoteProcessGroupEntityMerger method mergeDtos.

private static void mergeDtos(final RemoteProcessGroupDTO clientDto, final Map<NodeIdentifier, RemoteProcessGroupDTO> dtoMap) {
    // if unauthorized for the client dto, simple return
    if (clientDto == null) {
        return;
    }
    final RemoteProcessGroupContentsDTO remoteProcessGroupContents = clientDto.getContents();
    final Map<String, Set<NodeIdentifier>> authorizationErrorMap = new HashMap<>();
    final Map<String, Set<NodeIdentifier>> validationErrorMap = new HashMap<>();
    Boolean mergedIsTargetSecure = null;
    Set<RemoteProcessGroupPortDTO> mergedInputPorts = null;
    Set<RemoteProcessGroupPortDTO> mergedOutputPorts = null;
    for (final Map.Entry<NodeIdentifier, RemoteProcessGroupDTO> nodeEntry : dtoMap.entrySet()) {
        final RemoteProcessGroupDTO nodeRemoteProcessGroup = nodeEntry.getValue();
        // consider the node remote process group when authorized
        if (nodeRemoteProcessGroup != null) {
            final NodeIdentifier nodeId = nodeEntry.getKey();
            // merge the authorization errors
            ErrorMerger.mergeErrors(authorizationErrorMap, nodeId, nodeRemoteProcessGroup.getAuthorizationIssues());
            ErrorMerger.mergeErrors(validationErrorMap, nodeId, nodeRemoteProcessGroup.getValidationErrors());
            // use the first target secure flag since they will all be the same
            final Boolean nodeIsTargetSecure = nodeRemoteProcessGroup.isTargetSecure();
            if (mergedIsTargetSecure == null) {
                mergedIsTargetSecure = nodeIsTargetSecure;
            }
            // merge the ports in the contents
            final RemoteProcessGroupContentsDTO nodeRemoteProcessGroupContentsDto = nodeRemoteProcessGroup.getContents();
            if (remoteProcessGroupContents != null && nodeRemoteProcessGroupContentsDto != null) {
                final Set<RemoteProcessGroupPortDTO> nodeInputPorts = nodeRemoteProcessGroupContentsDto.getInputPorts();
                if (nodeInputPorts != null) {
                    if (mergedInputPorts == null) {
                        mergedInputPorts = new HashSet<>(nodeInputPorts);
                    } else {
                        mergedInputPorts.retainAll(nodeInputPorts);
                    }
                }
                final Set<RemoteProcessGroupPortDTO> nodeOutputPorts = nodeRemoteProcessGroupContentsDto.getOutputPorts();
                if (nodeOutputPorts != null) {
                    if (mergedOutputPorts == null) {
                        mergedOutputPorts = new HashSet<>(nodeOutputPorts);
                    } else {
                        mergedOutputPorts.retainAll(nodeOutputPorts);
                    }
                }
            }
        }
    }
    if (remoteProcessGroupContents != null) {
        if (mergedInputPorts != null && !mergedInputPorts.isEmpty()) {
            remoteProcessGroupContents.setInputPorts(mergedInputPorts);
        }
        if (mergedOutputPorts != null && !mergedOutputPorts.isEmpty()) {
            remoteProcessGroupContents.setOutputPorts(mergedOutputPorts);
        }
    }
    if (mergedIsTargetSecure != null) {
        clientDto.setTargetSecure(mergedIsTargetSecure);
    }
    // set the merged the validation errors
    clientDto.setAuthorizationIssues(ErrorMerger.normalizedMergedErrors(authorizationErrorMap, dtoMap.size()));
    clientDto.setValidationErrors(ErrorMerger.normalizedMergedErrors(validationErrorMap, dtoMap.size()));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RemoteProcessGroupContentsDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)18 Test (org.junit.Test)7 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)6 HashMap (java.util.HashMap)5 Action (org.apache.nifi.action.Action)5 RemoteProcessGroupContentsDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupContentsDTO)5 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)4 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 HashSet (java.util.HashSet)3 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)3 BatchSettingsDTO (org.apache.nifi.web.api.dto.BatchSettingsDTO)3 PermissionsDTO (org.apache.nifi.web.api.dto.PermissionsDTO)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Map (java.util.Map)2 Set (java.util.Set)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2