[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-30 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/nifi/pull/3112


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-30 Thread gardellajuanpablo
Github user gardellajuanpablo commented on a diff in the pull request:

https://github.com/apache/nifi/pull/3112#discussion_r229277738
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
 ---
@@ -297,16 +299,22 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } catch (StackOverflowError e) {
 // Some regular expressions can produce many matches on large 
input data size using recursive code
 // do not log the StackOverflowError stack trace
-logger.info("Transferred {} to 'failure' due to {}", new 
Object[] {flowFile, e.toString()});
-session.transfer(flowFile, REL_FAILURE);
+sendToFailure(session, flowFile, logger, e);
+return;
+} catch (IllegalAttributeException | 
AttributeExpressionLanguageException e) {
+sendToFailure(session, flowFile, logger, e);
 return;
 }
-
 logger.info("Transferred {} to 'success'", new Object[] 
{flowFile});
 session.getProvenanceReporter().modifyContent(flowFile, 
stopWatch.getElapsed(TimeUnit.MILLISECONDS));
 session.transfer(flowFile, REL_SUCCESS);
 }
 
+private static void sendToFailure(final ProcessSession session, 
FlowFile flowFile, final ComponentLog logger,
+Throwable e) {
+logger.info("Transferred {} to 'failure' due to {}", new Object[] 
{ flowFile, e.toString() });
--- End diff --

Thanks, good catch. Done!


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-29 Thread ijokarumawak
Github user ijokarumawak commented on a diff in the pull request:

https://github.com/apache/nifi/pull/3112#discussion_r229163268
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
 ---
@@ -297,16 +299,22 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } catch (StackOverflowError e) {
 // Some regular expressions can produce many matches on large 
input data size using recursive code
 // do not log the StackOverflowError stack trace
-logger.info("Transferred {} to 'failure' due to {}", new 
Object[] {flowFile, e.toString()});
-session.transfer(flowFile, REL_FAILURE);
+sendToFailure(session, flowFile, logger, e);
+return;
+} catch (IllegalAttributeException | 
AttributeExpressionLanguageException e) {
+sendToFailure(session, flowFile, logger, e);
 return;
 }
-
 logger.info("Transferred {} to 'success'", new Object[] 
{flowFile});
 session.getProvenanceReporter().modifyContent(flowFile, 
stopWatch.getElapsed(TimeUnit.MILLISECONDS));
 session.transfer(flowFile, REL_SUCCESS);
 }
 
+private static void sendToFailure(final ProcessSession session, 
FlowFile flowFile, final ComponentLog logger,
+Throwable e) {
+logger.info("Transferred {} to 'failure' due to {}", new Object[] 
{ flowFile, e.toString() });
--- End diff --

The existing logging code for `StackOverflowError` does not log exception 
stack trace intentionally it seems. But for the added EL related exceptions, we 
would like to see stack traces when it happens for further debugging. It can be 
done by passing the caught `e` as well to logger method.

Also, log level for EL related exceptions should be ERROR or at least WARN, 
instead of INFO.

Avoiding duplicated lines is generally a good idea, but because of these 
differences, each catch block should have logging and transfer code.


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-29 Thread gardellajuanpablo
Github user gardellajuanpablo commented on a diff in the pull request:

https://github.com/apache/nifi/pull/3112#discussion_r229159256
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml ---
@@ -24,6 +24,11 @@
 nifi-api
 provided
 
+
+org.apache.nifi
+nifi-expression-language
+provided
--- End diff --

Thanks, updated. 


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-29 Thread ijokarumawak
Github user ijokarumawak commented on a diff in the pull request:

https://github.com/apache/nifi/pull/3112#discussion_r229144580
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml ---
@@ -24,6 +24,11 @@
 nifi-api
 provided
 
+
+org.apache.nifi
+nifi-expression-language
+provided
--- End diff --

Please remove the `provided` scope. The `nifi-expression-language` needs to 
be bundled in nifi-standard-processors.nar. Causing following exception:
```
java.util.ServiceConfigurationError: org.apache.nifi.processor.Processor: 
Provider org.apache.nifi.processors.standard.ReplaceText could not be 
instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
at 
java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at 
org.apache.nifi.nar.ExtensionManager.loadExtensions(ExtensionManager.java:148)
at 
org.apache.nifi.nar.ExtensionManager.discoverExtensions(ExtensionManager.java:123)
at 
org.apache.nifi.web.server.JettyServer.start(JettyServer.java:838)
at org.apache.nifi.NiFi.(NiFi.java:157)
at org.apache.nifi.NiFi.(NiFi.java:71)
at org.apache.nifi.NiFi.main(NiFi.java:296)
Caused by: java.lang.NoClassDefFoundError: 
org/apache/nifi/attribute/expression/language/exception/IllegalAttributeException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at 
java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 8 common frames omitted
Caused by: java.lang.ClassNotFoundException: 
org.apache.nifi.attribute.expression.language.exception.IllegalAttributeException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 common frames omitted
```


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-29 Thread gardellajuanpablo
Github user gardellajuanpablo commented on a diff in the pull request:

https://github.com/apache/nifi/pull/3112#discussion_r228913385
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
 ---
@@ -297,16 +297,27 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } catch (StackOverflowError e) {
 // Some regular expressions can produce many matches on large 
input data size using recursive code
 // do not log the StackOverflowError stack trace
-logger.info("Transferred {} to 'failure' due to {}", new 
Object[] {flowFile, e.toString()});
-session.transfer(flowFile, REL_FAILURE);
+sendToFailure(session, flowFile, logger, e);
+return;
+} catch (RuntimeException e) {
--- End diff --

Done, thanks for the suggestion.


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-28 Thread ijokarumawak
Github user ijokarumawak commented on a diff in the pull request:

https://github.com/apache/nifi/pull/3112#discussion_r228781049
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
 ---
@@ -297,16 +297,27 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } catch (StackOverflowError e) {
 // Some regular expressions can produce many matches on large 
input data size using recursive code
 // do not log the StackOverflowError stack trace
-logger.info("Transferred {} to 'failure' due to {}", new 
Object[] {flowFile, e.toString()});
-session.transfer(flowFile, REL_FAILURE);
+sendToFailure(session, flowFile, logger, e);
+return;
+} catch (RuntimeException e) {
--- End diff --

Please use following code instead of using String.startWith:
```suggestion
} catch 
(AttributeExpressionLanguageException|IllegalAttributeException e) {
```

I assume the intent of using startWith is catching both 
AttributeExpressionLanguageException and IllegalAttributeException without 
adding nifi-expression-language dependency. But having explicit dependency is 
preferable as it's more maintainable.


---


[GitHub] nifi pull request #3112: NIFI-5761 ReplaceText processor can stop processing...

2018-10-26 Thread gardellajuanpablo
GitHub user gardellajuanpablo opened a pull request:

https://github.com/apache/nifi/pull/3112

NIFI-5761 ReplaceText processor can stop processing data if it evalua…

…tes invalid expressions

Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
 in the commit message?

- [ ] Does your PR title start with NIFI- where  is the JIRA number 
you are trying to resolve? Pay particular attention to the hyphen "-" character.

- [ ] Has your PR been rebased against the latest commit within the target 
branch (typically master)?

- [ ] Is your initial contribution a single, squashed commit?

### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via mvn 
-Pcontrib-check clean install at the root nifi folder?
- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
- [ ] If applicable, have you updated the LICENSE file, including the main 
LICENSE file under nifi-assembly?
- [ ] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found under nifi-assembly?
- [ ] If adding new Properties, have you added .displayName in addition to 
.name (programmatic access) for each of the new properties?

### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?

### Note:
Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/gardellajuanpablo/nifi NIFI-5761

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/nifi/pull/3112.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #3112


commit f26389e1f7f429f8fdc7f84938ff5b39658e1af1
Author: Gardella Juan Pablo 
Date:   2018-10-26T19:41:26Z

NIFI-5761 ReplaceText processor can stop processing data if it evaluates 
invalid expressions




---