You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by klinvill <gi...@git.apache.org> on 2016/12/02 16:09:18 UTC

[GitHub] nifi pull request #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route...

GitHub user klinvill opened a pull request:

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

    Fix NIFI-3142: ExtractHL7Attribute processor: Route a flowfile to REL_FAILURE if processing the flow\u2026

    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:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [x] 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?
    - [n/a] 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)? 
    - [n/a] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [n/a] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [n/a] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [n/a] 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.
    
    \u2026 file throws an exception that is not an HL7Exception for the ExtractHL7Attribute processor.
    
    Fixed by changing the catch block to catch a throwable object instead of an HL7Exception object in the onTrigger method.

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

    $ git pull https://github.com/klinvill/nifi NIFI-3142

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

    https://github.com/apache/nifi/pull/1290.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 #1290
    
----
commit 2f4a12e083be6acb8e5d2958c572e3428dc87458
Author: Kirby Linvill <ki...@teradata.com>
Date:   2016-12-02T14:08:03Z

    Fix NIFI-3142: Route a flowfile to REL_FAILURE if processing the flow file throws an exception that is not an HL7Exception for the ExtractHL7Attribute processor.
    
    Fixed by changing the catch block to catch a throwable object instead of an HL7Exception object in the onTrigger method.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route a flow...

Posted by jfrazee <gi...@git.apache.org>.
Github user jfrazee commented on the issue:

    https://github.com/apache/nifi/pull/1290
  
    @klinvill Do you know what version of NiFi you were running against? The NumberFormatException error was fixed in 1.1.0 by [NIFI-2887](https://issues.apache.org/jira/browse/NIFI-2887) and a relevant segment added to the unit tests. [NIFI-3142](https://issues.apache.org/jira/browse/NIFI-3142) suggests you ran into this against 1.0.0, and given the time you reported it at NiFi 1.1.0 had only been out for a short time so I wouldn't be surprised if you hadn't upgraded yet. Is this right? As for the NPE, I'll see if I can reproduce it but I don't know if I exactly follow the scenario. Is it an unrecognized segment name as in it's just bad HL7 or a segment that's unsupported for a particular version?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route...

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1290#discussion_r90924068
  
    --- Diff: nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java ---
    @@ -196,8 +196,8 @@ public void process(final InputStream in) throws IOException {
                 final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields);
                 flowFile = session.putAllAttributes(flowFile, attributes);
                 getLogger().debug("Added the following attributes for {}: {}", new Object[]{flowFile, attributes});
    -        } catch (final HL7Exception e) {
    -            getLogger().error("Failed to extract attributes from {} due to {}", new Object[]{flowFile, e});
    +        } catch (final Throwable t) {
    --- End diff --
    
    Where in the code do the NPE and NFE happen? If they are in NiFi code we should be catching both (possibly throwing a new exception we can expect/handle).
    
    I see what you're saying about avoiding backups of flow files that could be processed successfully, but if they can be processed successfully then the processor should be able to know what is going on in order to make a smart decision about how to handle the flow files. Catching Throwable means you would try to handle a flow file as "failed" when it is perfectly fine as input but something else is going on under the hood. This could keep the flow running even though something bad is going on having nothing to do with flow files, and could lead to data loss or non-delivery (which is why the session is being rolled back on these exceptions, to preserve the data/flow).
    
    I think we should capture non-happy-paths at the business logic level where possible (such as the NPE and NFE you mention). If you can demonstrate additional errors that could occur based on the business logic (HL7 library or NiFi itself), we should catch those too (all could be handled in the same block). I realize if we miss one then we'll have yet another Jira to fix it, but I think it's good to try to avoid the catch-everything block.
    
    Probably good to get some more opinions, I'll tag @markap14 and @JPercivall for additional input here :)



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route...

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1290#discussion_r90893970
  
    --- Diff: nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java ---
    @@ -196,8 +196,8 @@ public void process(final InputStream in) throws IOException {
                 final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields);
                 flowFile = session.putAllAttributes(flowFile, attributes);
                 getLogger().debug("Added the following attributes for {}: {}", new Object[]{flowFile, attributes});
    -        } catch (final HL7Exception e) {
    -            getLogger().error("Failed to extract attributes from {} due to {}", new Object[]{flowFile, e});
    +        } catch (final Throwable t) {
    --- End diff --
    
    Do you have an example / reproduction path of an exception that isn't an HL7Exception? I'm a bit wary of changing this to Throwable as the error might have come from the NiFi framework, and routing any possible error to a block that transfers a flow file might not be the best idea. If the callback passed to session.read() throws an IOException, then read() will throw a ProcessException with the IOException as the cause. You could check for that possibility, or (since you are just filling a buffer in the callback) you could retrieve the InputStream using [session.read(flowFile)](https://github.com/apache/nifi/blob/master/nifi-api/src/main/java/org/apache/nifi/processor/ProcessSession.java#L570) then call StreamUtils.fillBuffer() on that (although take care to perhaps wrap the InputStream in a BufferedInputStream, and you'll have to close it yourself, see the javadoc for more details).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route...

Posted by klinvill <gi...@git.apache.org>.
Github user klinvill closed the pull request at:

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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route...

Posted by JPercivall <gi...@git.apache.org>.
Github user JPercivall commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1290#discussion_r91182574
  
    --- Diff: nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java ---
    @@ -196,8 +196,8 @@ public void process(final InputStream in) throws IOException {
                 final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields);
                 flowFile = session.putAllAttributes(flowFile, attributes);
                 getLogger().debug("Added the following attributes for {}: {}", new Object[]{flowFile, attributes});
    -        } catch (final HL7Exception e) {
    -            getLogger().error("Failed to extract attributes from {} due to {}", new Object[]{flowFile, e});
    +        } catch (final Throwable t) {
    --- End diff --
    
    Along the lines of what @mattyb149 has stated, catching "throwable" just feels like a band-aid/blind-fold to cover up shortcomings in other validation or improper logic. I'd prefer to fix the 
    processor and framework.
    
    The NPEs should never be thrown and we should definitely track them down, can you elaborate more? The NumberFormatExceptions, were these a problem with malformed data or logic errors in the processor?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route a flow...

Posted by klinvill <gi...@git.apache.org>.
Github user klinvill commented on the issue:

    https://github.com/apache/nifi/pull/1290
  
    @jfrazee Apologies for the delayed response. I was running it against NiFi 1.0.0. The client I was working for at the time was using a few non-standard HL7 messages that were resulting in exceptions. The exceptions weren't really the problem (the failed messages just require specialized processing). The real problem was that the exceptions thrown were not HL7Exceptions so the NiFi processor didn't know where to route the message and the flowfile stayed in the queue to be processed at a later time. We were handling a large volume of these messages so the processor quickly got overloaded with the flowfile backlog. We ended up fixing this locally by simply routing all exceptions to failure so that the flowfiles would be moved out of the queue. I understand @mattyb149's point about how catching all exceptions could lead to data loss. Unfortunately I no longer have access to the messages or workflows that are failing so I'll go ahead and close this request. Thank you all for the help,
  if I run into this situation again I'll add in additional business logic and submit it back as a pull request.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route a flow...

Posted by trixpan <gi...@git.apache.org>.
Github user trixpan commented on the issue:

    https://github.com/apache/nifi/pull/1290
  
    @klinvill 
    
    Is this PR still needed or was it identified as a data quality issue?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1290: Fix NIFI-3142: ExtractHL7Attribute processor: Route...

Posted by klinvill <gi...@git.apache.org>.
Github user klinvill commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1290#discussion_r90904513
  
    --- Diff: nifi-nar-bundles/nifi-hl7-bundle/nifi-hl7-processors/src/main/java/org/apache/nifi/processors/hl7/ExtractHL7Attributes.java ---
    @@ -196,8 +196,8 @@ public void process(final InputStream in) throws IOException {
                 final Map<String, String> attributes = getAttributes(message, useSegmentNames, parseSegmentFields);
                 flowFile = session.putAllAttributes(flowFile, attributes);
                 getLogger().debug("Added the following attributes for {}: {}", new Object[]{flowFile, attributes});
    -        } catch (final HL7Exception e) {
    -            getLogger().error("Failed to extract attributes from {} due to {}", new Object[]{flowFile, e});
    +        } catch (final Throwable t) {
    --- End diff --
    
    Thanks for taking a look Matt. The two exceptions I was seeing were a java.lang.NullPointerException (when using a non-recognized segment name) and a java.lang.NumberFormatException (when the first field after the segment name had a code such as RE instead of a sequence number). Both of these exceptions were due to how the processor tries to process the HL7 segments and both were causing the processor to backup after enough messages failed to process and were not routed to failure (or anywhere for that matter). I could catch these two exceptions explicitly but I'd prefer that any error (even an error coming from nifi) cause the flowfile to be routed to failure so that it doesn't backup any of the flowfiles that could be processed successfully. I thought catching at the throwable level would work out well since it looks like that's how the PutHDFS processor checks for failure. Do you disagree?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---