From 28b9f6fc020616ac5d1f99a2477fe456458560a8 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Tue, 31 Jan 2023 11:00:55 -0500 Subject: [PATCH] NIFI-11118: This closes #6909. When changing version of a versioned flow, ensure that we properly set the Version Control Information's StorageLocation for the NiFi Registry client in order to maintain backward compatibility Signed-off-by: Joe Witt --- .../flow/mapping/NiFiRegistryFlowMapper.java | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java index ca5754c59e..d6e7c19f21 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/main/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapper.java @@ -19,6 +19,7 @@ package org.apache.nifi.registry.flow.mapping; import org.apache.commons.lang3.ClassUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.nifi.bundle.BundleCoordinate; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.resource.ResourceCardinality; @@ -169,7 +170,9 @@ public class NiFiRegistryFlowMapper { } coordinates.setRegistryUrl(getRegistryUrl(registry)); - coordinates.setStorageLocation(versionControlInfo.getStorageLocation() == null ?getRegistryUrl(registry) : versionControlInfo.getStorageLocation()); + + final String storageLocation = determineStorageLocation(registry, versionControlInfo); + coordinates.setStorageLocation(storageLocation); coordinates.setBucketId(versionControlInfo.getBucketIdentifier()); coordinates.setFlowId(versionControlInfo.getFlowIdentifier()); coordinates.setVersion(versionControlInfo.getVersion()); @@ -193,12 +196,33 @@ public class NiFiRegistryFlowMapper { } + private boolean isNiFiRegistryClient(final FlowRegistryClientNode clientNode) { + return clientNode.getComponentType().endsWith("NifiRegistryFlowRegistryClient"); + } + // This is specific for the {@code NifiRegistryFlowRegistryClient}, purely for backward compatibility private String getRegistryUrl(final FlowRegistryClientNode registry) { - return registry.getComponentType().endsWith("NifiRegistryFlowRegistryClient") - ? registry.getRawPropertyValue(registry.getPropertyDescriptor(REGISTRY_URL_DESCRIPTOR_NAME)) : ""; + return isNiFiRegistryClient(registry) ? registry.getRawPropertyValue(registry.getPropertyDescriptor(REGISTRY_URL_DESCRIPTOR_NAME)) : ""; } + private String determineStorageLocation(final FlowRegistryClientNode registryClient, final VersionControlInformation versionControlInformation) { + final String explicitStorageLocation = versionControlInformation.getStorageLocation(); + if (!StringUtils.isEmpty(explicitStorageLocation)) { + return explicitStorageLocation; + } + + final String registryUrl = getRegistryUrl(registryClient); + if (StringUtils.isEmpty(registryUrl)) { + return ""; + } + + final String bucketId = versionControlInformation.getBucketIdentifier(); + final String flowId = versionControlInformation.getFlowIdentifier(); + final int version = versionControlInformation.getVersion(); + return String.format("%s/nifi-registry-api/buckets/%s/flows/%s/versions/%s", registryUrl, bucketId, flowId, version); + } + + private InstantiatedVersionedProcessGroup mapGroup(final ProcessGroup group, final ControllerServiceProvider serviceProvider, final BiFunction applyVersionControlInfo) { final Set allIncludedGroupsIds = group.findAllProcessGroups().stream()