Search in sources :

Example 1 with ConnectableComponent

use of org.apache.nifi.registry.flow.ConnectableComponent in project nifi by apache.

the class NiFiRegistryFlowMapper method mapConnectable.

public ConnectableComponent mapConnectable(final Connectable connectable) {
    final ConnectableComponent component = new InstantiatedConnectableComponent(connectable.getIdentifier(), connectable.getProcessGroupIdentifier());
    final Optional<String> versionedId = connectable.getVersionedComponentId();
    if (versionedId.isPresent()) {
        component.setId(versionedId.get());
    } else {
        final String resolved = versionedComponentIds.get(connectable.getIdentifier());
        if (resolved == null) {
            throw new IllegalArgumentException("Unable to map Connectable Component with identifier " + connectable.getIdentifier() + " to any version-controlled component");
        }
        component.setId(resolved);
    }
    component.setComments(connectable.getComments());
    if (connectable instanceof RemoteGroupPort) {
        final RemoteGroupPort port = (RemoteGroupPort) connectable;
        final RemoteProcessGroup rpg = port.getRemoteProcessGroup();
        final Optional<String> rpgVersionedId = rpg.getVersionedComponentId();
        final String groupId;
        if (rpgVersionedId.isPresent()) {
            groupId = rpgVersionedId.get();
        } else {
            final String resolved = versionedComponentIds.get(rpg.getIdentifier());
            if (resolved == null) {
                throw new IllegalArgumentException("Unable to find the Versioned Component ID for Remote Process Group that " + connectable + " belongs to");
            }
            groupId = resolved;
        }
        component.setGroupId(groupId);
    } else {
        component.setGroupId(connectable.getProcessGroupIdentifier());
    }
    component.setName(connectable.getName());
    component.setType(ConnectableComponentType.valueOf(connectable.getConnectableType().name()));
    return component;
}
Also used : VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort)

Example 2 with ConnectableComponent

use of org.apache.nifi.registry.flow.ConnectableComponent in project nifi-minifi by apache.

the class VersionedProcessGroupEnricher method enrich.

public void enrich(final VersionedProcessGroup versionedProcessGroup) {
    List<VersionedProcessGroup> allVersionedProcessGroups = getAllVersionedProcessGroups(versionedProcessGroup);
    Set<VersionedRemoteProcessGroup> remoteProcessGroups = getAll(allVersionedProcessGroups, VersionedProcessGroup::getRemoteProcessGroups).collect(Collectors.toSet());
    Map<String, String> connectableNameMap = getAll(allVersionedProcessGroups, VersionedProcessGroup::getProcessors).collect(Collectors.toMap(VersionedComponent::getIdentifier, VersionedComponent::getName));
    Map<String, String> rpgIdToTargetIdMap = new HashMap<>();
    for (VersionedRemoteProcessGroup remoteProcessGroup : remoteProcessGroups) {
        final Set<VersionedRemoteGroupPort> rpgInputPorts = nullToEmpty(remoteProcessGroup.getInputPorts());
        final Set<VersionedRemoteGroupPort> rpgOutputPorts = nullToEmpty(remoteProcessGroup.getOutputPorts());
        // Map all port DTOs to their respective targetIds
        rpgIdToTargetIdMap.putAll(Stream.concat(rpgInputPorts.stream(), rpgOutputPorts.stream()).collect(Collectors.toMap(VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getTargetId)));
        addConnectables(connectableNameMap, rpgInputPorts, VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getIdentifier);
        addConnectables(connectableNameMap, rpgOutputPorts, VersionedRemoteGroupPort::getIdentifier, VersionedRemoteGroupPort::getIdentifier);
    }
    addConnectables(connectableNameMap, getAll(allVersionedProcessGroups, VersionedProcessGroup::getInputPorts).collect(Collectors.toList()), VersionedPort::getIdentifier, VersionedPort::getName);
    addConnectables(connectableNameMap, getAll(allVersionedProcessGroups, VersionedProcessGroup::getOutputPorts).collect(Collectors.toList()), VersionedPort::getIdentifier, VersionedPort::getName);
    final Set<VersionedConnection> connections = getAll(allVersionedProcessGroups, VersionedProcessGroup::getConnections).collect(Collectors.toSet());
    // Enrich connection endpoints using known names and overriding with targetIds for remote ports
    for (VersionedConnection 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() == ConnectableComponentType.REMOTE_OUTPUT_PORT || connectable.getType() == ConnectableComponentType.REMOTE_INPUT_PORT)).forEach(connectable -> connectable.setId(Optional.ofNullable(rpgIdToTargetIdMap.get(connectable.getId())).orElse(connectable.getId())));
    // Establish unique names for connections
    for (VersionedConnection connection : connections) {
        if (StringUtil.isNullOrEmpty(connection.getName())) {
            StringBuilder name = new StringBuilder();
            ConnectableComponent 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("/");
            ConnectableComponent connectionDestination = connection.getDestination();
            name.append(determineValueForConnectable(connectionDestination, rpgIdToTargetIdMap));
            connection.setName(name.toString());
        }
    }
    nullToEmpty(versionedProcessGroup.getProcessGroups()).stream().forEach(pg -> enrich(pg));
}
Also used : ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) Collection(java.util.Collection) Set(java.util.Set) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) StringUtil(org.apache.nifi.minifi.commons.schema.common.StringUtil) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Optional(java.util.Optional) CollectionUtil.nullToEmpty(org.apache.nifi.minifi.commons.schema.common.CollectionUtil.nullToEmpty) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) ConnectableComponentType(org.apache.nifi.registry.flow.ConnectableComponentType) HashMap(java.util.HashMap) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection)

Aggregations

ConnectableComponent (org.apache.nifi.registry.flow.ConnectableComponent)2 VersionedRemoteGroupPort (org.apache.nifi.registry.flow.VersionedRemoteGroupPort)2 VersionedRemoteProcessGroup (org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 StringUtils (org.apache.commons.lang3.StringUtils)1 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)1 CollectionUtil.nullToEmpty (org.apache.nifi.minifi.commons.schema.common.CollectionUtil.nullToEmpty)1 StringUtil (org.apache.nifi.minifi.commons.schema.common.StringUtil)1 ConnectableComponentType (org.apache.nifi.registry.flow.ConnectableComponentType)1 VersionedComponent (org.apache.nifi.registry.flow.VersionedComponent)1