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 <thenatog@gmail.com>

This closes #6655.
This commit is contained in:
sedadgn 2022-11-11 14:29:58 +01:00 committed by Nathan Gough
parent d7f2eb7c26
commit 009d641576
2 changed files with 22 additions and 2 deletions

View File

@ -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,

View File

@ -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();
}
}