This is an automated email from the ASF dual-hosted git repository.

thenatog pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 009d641576 NIFI-10787 - Cannot commit flows to nifi registry after 
updating our nifi release to 1.18.0  NifiRegistryFlowRegistryClient defines the 
PropertyDescriptor PROPERTY_URL  name as small case "url". The map bases on the 
name property of the PropertyDescriptor object. Here searching with uppercase 
value of "URL" causes the map lookup to fail and cause a NPE later on. 
Therefore, it is changed as "url"
009d641576 is described below

commit 009d641576499c5cdfb940a422996bbdce7dfda3
Author: sedadgn <[email protected]>
AuthorDate: Fri Nov 11 14:29:58 2022 +0100

    NIFI-10787 - Cannot commit flows to nifi registry after updating our nifi 
release to 1.18.0
     NifiRegistryFlowRegistryClient defines the PropertyDescriptor PROPERTY_URL 
 name as small case "url". The map bases on the name property of the 
PropertyDescriptor object. Here searching with uppercase value of "URL" causes 
the map lookup to fail and cause a NPE later on. Therefore, it is changed as 
"url"
    
    NIFI-10787 - Added constant for property descriptor "url" in 
NiFiRegistryFlowMapper to make it more clear.
    
    NIFI-10787 - Added change to unit test.
    
    NIFI-10787 - Updated unit test to validate that NiFi registry url is being 
set and retrieved.
    
    Signed-off-by: Nathan Gough <[email protected]>
    
    This closes #6655.
---
 .../registry/flow/mapping/NiFiRegistryFlowMapper.java |  5 ++++-
 .../flow/mapping/NiFiRegistryFlowMapperTest.java      | 19 ++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 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 f5b2a754c0..c04e94b6c2 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
@@ -17,6 +17,7 @@
 
 package org.apache.nifi.registry.flow.mapping;
 
+
 import org.apache.commons.lang3.ClassUtils;
 import org.apache.nifi.bundle.BundleCoordinate;
 import org.apache.nifi.components.PropertyDescriptor;
@@ -102,6 +103,7 @@ import java.util.stream.Collectors;
 public class NiFiRegistryFlowMapper {
     private static final String ENCRYPTED_PREFIX = "enc{";
     private static final String ENCRYPTED_SUFFIX = "}";
+    private static final String REGISTRY_URL_DESCRIPTOR_NAME = "url";
 
     private final ExtensionManager extensionManager;
     private final FlowMappingOptions flowMappingOptions;
@@ -193,7 +195,8 @@ public class NiFiRegistryFlowMapper {
 
     // This is specific for the {@code NifiRegistryFlowRegistryClient}, purely 
for backward compatibility
     private String getRegistryUrl(final FlowRegistryClientNode registry) {
-        return 
registry.getComponentType().equals("org.apache.nifi.registry.flow.NifiRegistryFlowRegistryClient")
 ? registry.getRawPropertyValue(registry.getPropertyDescriptor("URL")) : "";
+        return 
registry.getComponentType().endsWith("NifiRegistryFlowRegistryClient")
+               ? 
registry.getRawPropertyValue(registry.getPropertyDescriptor(REGISTRY_URL_DESCRIPTOR_NAME))
 : "";
     }
 
     private InstantiatedVersionedProcessGroup mapGroup(final ProcessGroup 
group, final ControllerServiceProvider serviceProvider,
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
index 9caded0063..fa5152a4a6 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.nifi.registry.flow.mapping;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.authorization.resource.ComponentAuthorizable;
 import org.apache.nifi.bundle.BundleCoordinate;
 import org.apache.nifi.components.PropertyDescriptor;
@@ -71,6 +72,7 @@ import org.apache.nifi.parameter.ParameterDescriptor;
 import org.apache.nifi.parameter.ParameterProvider;
 import org.apache.nifi.parameter.ParameterProviderConfiguration;
 import org.apache.nifi.parameter.StandardParameterProviderConfiguration;
+import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.registry.ComponentVariableRegistry;
 import org.apache.nifi.registry.VariableDescriptor;
 import org.apache.nifi.registry.flow.FlowRegistryClientNode;
@@ -133,8 +135,10 @@ public class NiFiRegistryFlowMapperTest {
     @Before
     public void setup() {
         final FlowRegistryClientNode flowRegistry = 
mock(FlowRegistryClientNode.class);
-        
Mockito.when(flowRegistry.getComponentType()).thenReturn("org.apache.nifi.registry.flow.NifiRegistryFlowRegistryClient");
+        
Mockito.when(flowRegistry.getComponentType()).thenReturn(TestNifiRegistryFlowRegistryClient.class.getName());
         
Mockito.when(flowRegistry.getRawPropertyValue(Mockito.any())).thenReturn("");
+        
Mockito.when(flowRegistry.getPropertyDescriptor(TestNifiRegistryFlowRegistryClient.PROPERTY_URL.getName())).thenReturn(TestNifiRegistryFlowRegistryClient.PROPERTY_URL);
+        
Mockito.when(flowRegistry.getRawPropertyValue(TestNifiRegistryFlowRegistryClient.PROPERTY_URL)).thenReturn("http://127.0.0.1:18080";);
 
         
when(flowManager.getFlowRegistryClient(anyString())).thenReturn(flowRegistry);
 
@@ -235,6 +239,9 @@ public class NiFiRegistryFlowMapperTest {
         final VersionedProcessGroup innerVersionedProcessGroup =
                 versionedProcessGroup.getProcessGroups().iterator().next();
 
+        // ensure the Registry URL has been set correctly in the flowManager
+        
assert(StringUtils.isNotEmpty(innerVersionedProcessGroup.getVersionedFlowCoordinates().getStorageLocation()));
+
         // verify root versioned process group contents only
         verifyVersionedProcessGroup(processGroup, 
versionedProcessGroup,false,false);
 
@@ -847,4 +854,14 @@ public class NiFiRegistryFlowMapperTest {
         assertEquals(propertyDescriptor.getDisplayName(), 
versionedPropertyDescriptor.getDisplayName());
         assertEquals(propertyDescriptor.isSensitive(), 
versionedPropertyDescriptor.isSensitive());
     }
+
+    private static class TestNifiRegistryFlowRegistryClient {
+        public static final PropertyDescriptor PROPERTY_URL = new 
PropertyDescriptor.Builder()
+                .name("url")
+                .displayName("URL")
+                .description("URL of the NiFi Registry")
+                .addValidator(StandardValidators.URL_VALIDATOR)
+                .required(true)
+                .build();
+    }
 }

Reply via email to