You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2017/07/19 15:52:07 UTC
nifi git commit: NIFI-11 - Capture Exception to prevent failed
evaluations from yielding processor - Further capture evaluation exceptions
as per PR feedback - Adjust jUnit to new exception behavior - This closes
#1644
Repository: nifi
Updated Branches:
refs/heads/master f87d2a2f5 -> 451a88df4
NIFI-11
- Capture Exception to prevent failed evaluations from yielding processor
- Further capture evaluation exceptions as per PR feedback
- Adjust jUnit to new exception behavior
- This closes #1644
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/451a88df
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/451a88df
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/451a88df
Branch: refs/heads/master
Commit: 451a88df438f1ea2ed14c862a95aaed13b8c1ee3
Parents: f87d2a2
Author: Andre F de Miranda <tr...@users.noreply.github.com>
Authored: Sat Apr 1 19:12:58 2017 +1100
Committer: Matt Gilman <ma...@gmail.com>
Committed: Wed Jul 19 11:50:48 2017 -0400
----------------------------------------------------------------------
.../processors/attributes/UpdateAttribute.java | 17 +++++++++------
.../update/attributes/TestUpdateAttribute.java | 22 +++++++++++++++++++-
2 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/451a88df/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java
index a64279d..1ea0b61 100644
--- a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java
+++ b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/main/java/org/apache/nifi/processors/attributes/UpdateAttribute.java
@@ -579,8 +579,9 @@ public class UpdateAttribute extends AbstractProcessor implements Searchable {
try {
// evaluate the expression for the given flow file
return getPropertyValue(condition.getExpression(), context).evaluateAttributeExpressions(flowfile, null, null, statefulAttributes).asBoolean();
- } catch (final ProcessException pe) {
- throw new ProcessException(String.format("Unable to evaluate condition '%s': %s.", condition.getExpression(), pe), pe);
+ } catch (final Exception e) {
+ getLogger().error(String.format("Could not evaluate the condition '%s' while processing Flowfile '%s'", condition.getExpression(), flowfile));
+ throw new ProcessException(String.format("Unable to evaluate condition '%s': %s.", condition.getExpression(), e), e);
}
}
@@ -643,8 +644,9 @@ public class UpdateAttribute extends AbstractProcessor implements Searchable {
// No point in updating if they will be removed
attributesToUpdate.keySet().removeAll(attributesToDelete);
}
- } catch (final ProcessException pe) {
- throw new ProcessException(String.format("Unable to delete attribute '%s': %s.", attribute, pe), pe);
+ } catch (final Exception e) {
+ logger.error(String.format("Unable to delete attribute '%s' while processing FlowFile '%s' .", attribute, flowfile));
+ throw new ProcessException(String.format("Unable to delete attribute '%s': %s.", attribute, e), e);
}
} else {
boolean notDeleted = !attributesToDelete.contains(attribute);
@@ -667,8 +669,11 @@ public class UpdateAttribute extends AbstractProcessor implements Searchable {
if (notDeleted) {
attributesToUpdate.put(attribute, newAttributeValue);
}
- } catch (final ProcessException pe) {
- throw new ProcessException(String.format("Unable to evaluate new value for attribute '%s': %s.", attribute, pe), pe);
+ // Capture Exception thrown when evaluating the Expression Language
+ } catch (final Exception e) {
+ logger.error(String.format("Could not evaluate the FlowFile '%s' against expression '%s' " +
+ "defined by DynamicProperty '%s' due to '%s'", flowfile, action.getValue(), attribute, e.getLocalizedMessage()));
+ throw new ProcessException(String.format("Unable to evaluate new value for attribute '%s': %s.", attribute, e), e);
}
}
}
http://git-wip-us.apache.org/repos/asf/nifi/blob/451a88df/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java
index 5c00a20..8d3499c 100644
--- a/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java
+++ b/nifi-nar-bundles/nifi-update-attribute-bundle/nifi-update-attribute-processor/src/test/java/org/apache/nifi/update/attributes/TestUpdateAttribute.java
@@ -29,6 +29,7 @@ import java.util.regex.PatternSyntaxException;
import org.apache.nifi.components.state.Scope;
import org.apache.nifi.processor.ProcessSessionFactory;
+import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.processors.attributes.UpdateAttribute;
import org.apache.nifi.state.MockStateManager;
import org.apache.nifi.update.attributes.serde.CriteriaSerDe;
@@ -36,6 +37,7 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.Assert;
import org.junit.Test;
import static org.apache.nifi.processors.attributes.UpdateAttribute.STORE_STATE_LOCALLY;
@@ -983,7 +985,25 @@ public class TestUpdateAttribute {
try {
runner.run();
} catch (Throwable t) {
- assertEquals(t.getCause().getClass(), PatternSyntaxException.class);
+ assertEquals(ProcessException.class, t.getCause().getClass());
}
}
+
+ @Test
+ public void testDataIsTooShort() {
+ final TestRunner runner = TestRunners.newTestRunner(new UpdateAttribute());
+ runner.setProperty("attribute.1", "${test:substring(1, 20)}");
+
+ runner.assertValid();
+
+ final Map<String, String> attributes = new HashMap<>();
+ attributes.put("test", "chocolate");
+ runner.enqueue(new byte[0], attributes);
+ try {
+ runner.run();
+ } catch (AssertionError e) {
+ Assert.assertTrue(e.getMessage().contains("org.apache.nifi.processor.exception.ProcessException"));
+ }
+ }
+
}