Repository: nifi
Updated Branches:
  refs/heads/master 60da897e1 -> ed035f85e


NIFI-2928 added support to validate accessibility of the file system

NIFI-2928 polishing

This closes #1160


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/ed035f85
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/ed035f85
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/ed035f85

Branch: refs/heads/master
Commit: ed035f85e38f7c9efe6ac84c8f13c9a455f7014c
Parents: 60da897
Author: Oleg Zhurakousky <[email protected]>
Authored: Wed Oct 26 12:57:37 2016 -0400
Committer: Matt Burgess <[email protected]>
Committed: Thu Nov 3 12:25:31 2016 -0400

----------------------------------------------------------------------
 .../org/apache/nifi/processors/standard/FetchFile.java |  9 +++++++--
 .../apache/nifi/processors/standard/TestFetchFile.java | 13 +++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/ed035f85/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFile.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFile.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFile.java
index 04675c9..afdd6cf 100644
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFile.java
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFile.java
@@ -183,8 +183,13 @@ public class FetchFile extends AbstractProcessor {
         final LogLevel levelPermDenied = 
LogLevel.valueOf(context.getProperty(PERM_DENIED_LOG_LEVEL).getValue());
         final File file = new File(filename);
 
-        // Verify that file exists
-        if (!file.exists()) {
+        // Verify that file system is reachable and file exists
+        Path filePath = file.toPath();
+        if (!Files.exists(filePath) && !Files.notExists(filePath)){ // see 
https://docs.oracle.com/javase/tutorial/essential/io/check.html for more details
+            getLogger().log(levelFileNotFound, "Could not fetch file {} from 
file system for {} because the existence of the file cannot be verified; 
routing to failure", new Object[] {file, flowFile});
+            session.transfer(session.penalize(flowFile), REL_FAILURE);
+            return;
+        } else if (!Files.exists(filePath)) {
             getLogger().log(levelFileNotFound, "Could not fetch file {} from 
file system for {} because the file does not exist; routing to not.found", new 
Object[] {file, flowFile});
             session.getProvenanceReporter().route(flowFile, REL_NOT_FOUND);
             session.transfer(session.penalize(flowFile), REL_NOT_FOUND);

http://git-wip-us.apache.org/repos/asf/nifi/blob/ed035f85/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
index 0e69216..cfced0a 100644
--- 
a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
+++ 
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
@@ -48,6 +48,19 @@ public class TestFetchFile {
     }
 
     @Test
+    public void notFound() throws IOException {
+        final File sourceFile = new File("notFound");
+
+        final TestRunner runner = TestRunners.newTestRunner(new FetchFile());
+        runner.setProperty(FetchFile.FILENAME, sourceFile.getAbsolutePath());
+        runner.setProperty(FetchFile.COMPLETION_STRATEGY, 
FetchFile.COMPLETION_NONE.getValue());
+
+        runner.enqueue(new byte[0]);
+        runner.run();
+        runner.assertAllFlowFilesTransferred(FetchFile.REL_NOT_FOUND, 1);
+    }
+
+    @Test
     public void testSimpleSuccess() throws IOException {
         final File sourceFile = new File("target/1.txt");
         final byte[] content = "Hello, World!".getBytes();

Reply via email to