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

mattyb149 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 47f75651bb NIFI-9911: Fixed checking HDFS URI in ListHDFS' Directory 
property
47f75651bb is described below

commit 47f75651bb49d7868f63b02668300f702cbde3ea
Author: Peter Turcsanyi <[email protected]>
AuthorDate: Tue Apr 12 09:57:33 2022 +0200

    NIFI-9911: Fixed checking HDFS URI in ListHDFS' Directory property
    
    Signed-off-by: Matthew Burgess <[email protected]>
    
    This closes #5957
---
 .../processors/hadoop/AbstractHadoopProcessor.java |  2 +-
 .../nifi/processors/hadoop/AbstractHadoopTest.java | 26 ++++++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git 
a/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
 
b/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
index 7c574a72f8..f7c082bf12 100644
--- 
a/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
+++ 
b/nifi-nar-bundles/nifi-extension-utils/nifi-hadoop-utils/src/main/java/org/apache/nifi/processors/hadoop/AbstractHadoopProcessor.java
@@ -696,7 +696,7 @@ public abstract class AbstractHadoopProcessor extends 
AbstractProcessor implemen
         final String path;
 
         if (uri.getScheme() != null) {
-            if (!uri.getScheme().equals(fileSystemUri.getScheme()) || 
!uri.getAuthority().equals(fileSystemUri.getAuthority())) {
+            if (!uri.getScheme().equals(fileSystemUri.getScheme()) || 
(uri.getAuthority() != null && 
!uri.getAuthority().equals(fileSystemUri.getAuthority()))) {
                 if (propertyName.isPresent()) {
                     getLogger().warn(NORMALIZE_ERROR_WITH_PROPERTY, 
propertyName, uri, fileSystemUri);
                 } else {
diff --git 
a/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/AbstractHadoopTest.java
 
b/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/AbstractHadoopTest.java
index ff07d26854..ce5ef02f46 100644
--- 
a/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/AbstractHadoopTest.java
+++ 
b/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/test/java/org/apache/nifi/processors/hadoop/AbstractHadoopTest.java
@@ -294,9 +294,9 @@ public class AbstractHadoopTest {
     }
 
     @Test
-    public void testGetNormalizedPathWithIncorrectFileSystem() throws 
URISyntaxException {
+    public void testGetNormalizedPathWithIncorrectScheme() throws 
URISyntaxException {
         AbstractHadoopProcessor processor = 
initProcessorForTestGetNormalizedPath("abfs://container3@storageaccount3");
-        TestRunner runner = initTestRunnerForTestGetNormalizedPath(processor, 
"abfs://container*@storageaccount*/dir3");
+        TestRunner runner = initTestRunnerForTestGetNormalizedPath(processor, 
"hdfs://container3@storageaccount3/dir3");
 
         Path path = processor.getNormalizedPath(runner.getProcessContext(), 
AbstractHadoopProcessor.DIRECTORY);
 
@@ -304,6 +304,28 @@ public class AbstractHadoopTest {
         assertFalse(runner.getLogger().getWarnMessages().isEmpty());
     }
 
+    @Test
+    public void testGetNormalizedPathWithIncorrectAuthority() throws 
URISyntaxException {
+        AbstractHadoopProcessor processor = 
initProcessorForTestGetNormalizedPath("abfs://container4@storageaccount4");
+        TestRunner runner = initTestRunnerForTestGetNormalizedPath(processor, 
"abfs://container*@storageaccount*/dir4");
+
+        Path path = processor.getNormalizedPath(runner.getProcessContext(), 
AbstractHadoopProcessor.DIRECTORY);
+
+        assertEquals("/dir4", path.toString());
+        assertFalse(runner.getLogger().getWarnMessages().isEmpty());
+    }
+
+    @Test
+    public void testGetNormalizedPathWithoutAuthority() throws 
URISyntaxException {
+        AbstractHadoopProcessor processor = 
initProcessorForTestGetNormalizedPath("hdfs://myhost:9000");
+        TestRunner runner = initTestRunnerForTestGetNormalizedPath(processor, 
"hdfs:///dir5");
+
+        Path path = processor.getNormalizedPath(runner.getProcessContext(), 
AbstractHadoopProcessor.DIRECTORY);
+
+        assertEquals("/dir5", path.toString());
+        assertTrue(runner.getLogger().getWarnMessages().isEmpty());
+    }
+
     private AbstractHadoopProcessor 
initProcessorForTestGetNormalizedPath(String fileSystemUri) throws 
URISyntaxException {
         final FileSystem fileSystem = mock(FileSystem.class);
         when(fileSystem.getUri()).thenReturn(new URI(fileSystemUri));

Reply via email to