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;
}
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));
}
Aggregations