From 3b2120e6c6ae2a50d4f1257e49ced1fc1992b349 Mon Sep 17 00:00:00 2001 From: EndzeitBegins <16666115+EndzeitBegins@users.noreply.github.com> Date: Wed, 10 Jul 2024 22:11:12 +0200 Subject: [PATCH] NIFI-13537 Do not include exception details in FlowFile attributes in DeleteFile This closes #9069 Signed-off-by: Mike Thomsen --- .../nifi/processors/standard/DeleteFile.java | 22 ------------------- .../processors/standard/TestDeleteFile.java | 8 ------- 2 files changed, 30 deletions(-) diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteFile.java index 4980e291d2..ae885ea2e4 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteFile.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeleteFile.java @@ -21,8 +21,6 @@ import org.apache.nifi.annotation.behavior.InputRequirement; import org.apache.nifi.annotation.behavior.Restricted; import org.apache.nifi.annotation.behavior.Restriction; import org.apache.nifi.annotation.behavior.SupportsBatching; -import org.apache.nifi.annotation.behavior.WritesAttribute; -import org.apache.nifi.annotation.behavior.WritesAttributes; import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.Tags; import org.apache.nifi.annotation.documentation.UseCase; @@ -60,17 +58,6 @@ import java.util.concurrent.TimeUnit; Using 'DeleteFile', delete the file from the filesystem only after the result has been stored. """ ) -@WritesAttributes({ - @WritesAttribute( - attribute = DeleteFile.ATTRIBUTE_FAILURE_REASON, - description = "Human-readable reason of failure. Only available if FlowFile is routed to relationship 'failure'."), - @WritesAttribute( - attribute = DeleteFile.ATTRIBUTE_EXCEPTION_CLASS, - description = "The class name of the exception thrown during processor execution. Only available if an exception caused the FlowFile to be routed to relationship 'failure'."), - @WritesAttribute( - attribute = DeleteFile.ATTRIBUTE_EXCEPTION_MESSAGE, - description = "The message of the exception thrown during processor execution. Only available if an exception caused the FlowFile to be routed to relationship 'failure'.") -}) @Restricted( restrictions = { @Restriction( @@ -83,10 +70,6 @@ import java.util.concurrent.TimeUnit; ) public class DeleteFile extends AbstractProcessor { - public static final String ATTRIBUTE_FAILURE_REASON = "DeleteFile.failure.reason"; - public static final String ATTRIBUTE_EXCEPTION_CLASS = "DeleteFile.failure.exception.class"; - public static final String ATTRIBUTE_EXCEPTION_MESSAGE = "DeleteFile.failure.exception.message"; - public static final Relationship REL_SUCCESS = new Relationship.Builder() .name("success") .description("All FlowFiles, for which an existing file has been deleted, are routed to this relationship") @@ -177,11 +160,6 @@ public class DeleteFile extends AbstractProcessor { private void handleFailure(ProcessSession session, FlowFile flowFile, String errorMessage, Throwable throwable) { getLogger().error(errorMessage, throwable); - session.putAttribute(flowFile, ATTRIBUTE_FAILURE_REASON, errorMessage); - if (throwable != null) { - session.putAttribute(flowFile, ATTRIBUTE_EXCEPTION_CLASS, throwable.getClass().toString()); - session.putAttribute(flowFile, ATTRIBUTE_EXCEPTION_MESSAGE, throwable.getMessage()); - } session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); } diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteFile.java index 461d359b51..bbe10dd404 100644 --- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteFile.java +++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeleteFile.java @@ -114,10 +114,6 @@ class TestDeleteFile { assertExists(fileToDelete); runner.assertAllFlowFilesTransferred(DeleteFile.REL_FAILURE); runner.assertPenalizeCount(1); - final MockFlowFile resultFlowFile = runner.getFlowFilesForRelationship(DeleteFile.REL_FAILURE).getFirst(); - resultFlowFile.assertAttributeExists(DeleteFile.ATTRIBUTE_FAILURE_REASON); - resultFlowFile.assertAttributeExists(DeleteFile.ATTRIBUTE_EXCEPTION_CLASS); - resultFlowFile.assertAttributeExists(DeleteFile.ATTRIBUTE_EXCEPTION_MESSAGE); } @Test @@ -133,10 +129,6 @@ class TestDeleteFile { assertExists(fileToDelete); runner.assertAllFlowFilesTransferred(DeleteFile.REL_FAILURE, 1); runner.assertPenalizeCount(1); - final MockFlowFile resultFlowFile = runner.getFlowFilesForRelationship(DeleteFile.REL_FAILURE).getFirst(); - resultFlowFile.assertAttributeExists(DeleteFile.ATTRIBUTE_FAILURE_REASON); - resultFlowFile.assertAttributeNotExists(DeleteFile.ATTRIBUTE_EXCEPTION_CLASS); - resultFlowFile.assertAttributeNotExists(DeleteFile.ATTRIBUTE_EXCEPTION_MESSAGE); } private MockFlowFile enqueue(String directoryPath, String filename) {