Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-4082

Enable nifi expression language for GetMongo - Query property

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.3.0
    • Fix Version/s: 1.4.0
    • Component/s: Extensions
    • Labels:
      None

      Description

      Currently the `Query` property of the `GetMongo` processor does not support expression language.
      That disables query parametrization.

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user pvillard31 opened a pull request:

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

          NIFI-4082 - Added EL on GetMongo properties

          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:

              1. 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-XXXX where XXXX 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?
              1. 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?
              1. For documentation related changes:
          • [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
              1. 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/pvillard31/nifi NIFI-4082

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

          https://github.com/apache/nifi/pull/1969.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 #1969


          commit 89c2a35886b5d7f622fbe552c53e235c9b96f32b
          Author: Pierre Villard <pierre.villard.fr@gmail.com>
          Date: 2017-06-30T18:43:50Z

          NIFI-4082 - Added EL on GetMongo properties


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user pvillard31 opened a pull request: https://github.com/apache/nifi/pull/1969 NIFI-4082 - Added EL on GetMongo properties 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-XXXX where XXXX 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/pvillard31/nifi NIFI-4082 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/nifi/pull/1969.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 #1969 commit 89c2a35886b5d7f622fbe552c53e235c9b96f32b Author: Pierre Villard <pierre.villard.fr@gmail.com> Date: 2017-06-30T18:43:50Z NIFI-4082 - Added EL on GetMongo properties
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jfrazee commented on the issue:

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

          @pvillard31 I think we can add EL to collection without having to do anything fancy since getCollection() in AbstractMongoProcessor re-uses the mongoClient already.

          That said, is it worth also adding EL support for URI and DB in this PR? The simple case will mean it'll get eval'd against the variable registry, which is definitely useful for migrating from env to env.

          There's another case though in being able to eval against a FlowFile for PutMongo so you can route to different DBs if you're doing some application-level sharding. But that would mean we'd have to manage a pool/map of connections since the mongoClient currently is set with @OnScheduled. Makes sense if you think that's for another PR though.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jfrazee commented on the issue: https://github.com/apache/nifi/pull/1969 @pvillard31 I think we can add EL to collection without having to do anything fancy since getCollection() in AbstractMongoProcessor re-uses the mongoClient already. That said, is it worth also adding EL support for URI and DB in this PR? The simple case will mean it'll get eval'd against the variable registry, which is definitely useful for migrating from env to env. There's another case though in being able to eval against a FlowFile for PutMongo so you can route to different DBs if you're doing some application-level sharding. But that would mean we'd have to manage a pool/map of connections since the mongoClient currently is set with @OnScheduled. Makes sense if you think that's for another PR though.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user pvillard31 commented on the issue:

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

          @jfrazee - I just pushed a new commit and added support for expression language with FFs evaluation on DB and Collection name, and without FFs evaluation on URI. Regarding this very subject, what are your thoughts about NIFI-4149 and how this could solve this kind of need?

          Show
          githubbot ASF GitHub Bot added a comment - Github user pvillard31 commented on the issue: https://github.com/apache/nifi/pull/1969 @jfrazee - I just pushed a new commit and added support for expression language with FFs evaluation on DB and Collection name, and without FFs evaluation on URI. Regarding this very subject, what are your thoughts about NIFI-4149 and how this could solve this kind of need?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jfrazee commented on the issue:

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

          @pvillard31 I left some comments on NIFI-4149(https://issues.apache.org/jira/browse/NIFI-4149). I think it'd be a step in the right direction.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jfrazee commented on the issue: https://github.com/apache/nifi/pull/1969 @pvillard31 I left some comments on NIFI-4149 ( https://issues.apache.org/jira/browse/NIFI-4149 ). I think it'd be a step in the right direction.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jfrazee commented on a diff in the pull request:

          https://github.com/apache/nifi/pull/1969#discussion_r127808068

          — Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java —
          @@ -59,14 +59,21 @@
          public static final Validator DOCUMENT_VALIDATOR = new Validator() {
          @Override
          public ValidationResult validate(final String subject, final String value, final ValidationContext context) {
          + final ValidationResult.Builder builder = new ValidationResult.Builder();
          + builder.subject(subject).input(value);
          +
          + if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value))

          { + return builder.valid(true).explanation("Contains Expression Language").build(); + }

          +
          String reason = null;
          try

          { Document.parse(value); }

          catch (final RuntimeException e) {
          reason = e.getClass().getName();
          — End diff –

          Seems like this should be `e.getMessage()` or `get.getClass().getName() + ": " + e.getMessage()` if you want the underlying exception class.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jfrazee commented on a diff in the pull request: https://github.com/apache/nifi/pull/1969#discussion_r127808068 — Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java — @@ -59,14 +59,21 @@ public static final Validator DOCUMENT_VALIDATOR = new Validator() { @Override public ValidationResult validate(final String subject, final String value, final ValidationContext context) { + final ValidationResult.Builder builder = new ValidationResult.Builder(); + builder.subject(subject).input(value); + + if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(value)) { + return builder.valid(true).explanation("Contains Expression Language").build(); + } + String reason = null; try { Document.parse(value); } catch (final RuntimeException e) { reason = e.getClass().getName(); — End diff – Seems like this should be `e.getMessage()` or `get.getClass().getName() + ": " + e.getMessage()` if you want the underlying exception class.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user jfrazee commented on the issue:

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

          @pvillard31 I think this needs more updates to the tests. Since you've added URI, collection, and DB, we should probably add that to the Get test. And, I think there are similar changes that make sense for the Put and Abstract processor.

          Show
          githubbot ASF GitHub Bot added a comment - Github user jfrazee commented on the issue: https://github.com/apache/nifi/pull/1969 @pvillard31 I think this needs more updates to the tests. Since you've added URI, collection, and DB, we should probably add that to the Get test. And, I think there are similar changes that make sense for the Put and Abstract processor.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user pvillard31 commented on the issue:

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

          @jfrazee just pushed a commit to address your last comment: changed the exception message for the custom document validator, and added unit tests for the expression language evaluation on URI, database name and collection name properties.

          Show
          githubbot ASF GitHub Bot added a comment - Github user pvillard31 commented on the issue: https://github.com/apache/nifi/pull/1969 @jfrazee just pushed a commit to address your last comment: changed the exception message for the custom document validator, and added unit tests for the expression language evaluation on URI, database name and collection name properties.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user nicholasmhughes commented on the issue:

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

          @pvillard31 @jfrazee I'm very interested in this functionality. The Jira for this issue doesn't have a fix version identified. Do you think it will make it into 1.4.0 (or the next formal release)?

          Show
          githubbot ASF GitHub Bot added a comment - Github user nicholasmhughes commented on the issue: https://github.com/apache/nifi/pull/1969 @pvillard31 @jfrazee I'm very interested in this functionality. The Jira for this issue doesn't have a fix version identified. Do you think it will make it into 1.4.0 (or the next formal release)?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user mattyb149 commented on the issue:

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

          +1 LGTM, ran builds/tests and tested GetMongo and PutMongo with EL for all fields, talked to Joey and he's cool with me merging too. Thanks for the improvements! Merging to master

          Show
          githubbot ASF GitHub Bot added a comment - Github user mattyb149 commented on the issue: https://github.com/apache/nifi/pull/1969 +1 LGTM, ran builds/tests and tested GetMongo and PutMongo with EL for all fields, talked to Joey and he's cool with me merging too. Thanks for the improvements! Merging to master
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 8b54c2604cde4f3516d89a0f48650f7c30e34c3b in nifi's branch refs/heads/master from Pierre Villard
          [ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=8b54c26 ]

          NIFI-4082 - Added EL on GetMongo properties

          NIFI-4082 - Added EL on DB, URI and Collection

          NIFI-4082 - Added UT for EL evaluation (URI, DB, Collection) and fixed ex. message for document validator.

          This closes #1969

          Show
          jira-bot ASF subversion and git services added a comment - Commit 8b54c2604cde4f3516d89a0f48650f7c30e34c3b in nifi's branch refs/heads/master from Pierre Villard [ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=8b54c26 ] NIFI-4082 - Added EL on GetMongo properties NIFI-4082 - Added EL on DB, URI and Collection NIFI-4082 - Added UT for EL evaluation (URI, DB, Collection) and fixed ex. message for document validator. This closes #1969
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 8b54c2604cde4f3516d89a0f48650f7c30e34c3b in nifi's branch refs/heads/master from Pierre Villard
          [ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=8b54c26 ]

          NIFI-4082 - Added EL on GetMongo properties

          NIFI-4082 - Added EL on DB, URI and Collection

          NIFI-4082 - Added UT for EL evaluation (URI, DB, Collection) and fixed ex. message for document validator.

          This closes #1969

          Show
          jira-bot ASF subversion and git services added a comment - Commit 8b54c2604cde4f3516d89a0f48650f7c30e34c3b in nifi's branch refs/heads/master from Pierre Villard [ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=8b54c26 ] NIFI-4082 - Added EL on GetMongo properties NIFI-4082 - Added EL on DB, URI and Collection NIFI-4082 - Added UT for EL evaluation (URI, DB, Collection) and fixed ex. message for document validator. This closes #1969
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 8b54c2604cde4f3516d89a0f48650f7c30e34c3b in nifi's branch refs/heads/master from Pierre Villard
          [ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=8b54c26 ]

          NIFI-4082 - Added EL on GetMongo properties

          NIFI-4082 - Added EL on DB, URI and Collection

          NIFI-4082 - Added UT for EL evaluation (URI, DB, Collection) and fixed ex. message for document validator.

          This closes #1969

          Show
          jira-bot ASF subversion and git services added a comment - Commit 8b54c2604cde4f3516d89a0f48650f7c30e34c3b in nifi's branch refs/heads/master from Pierre Villard [ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=8b54c26 ] NIFI-4082 - Added EL on GetMongo properties NIFI-4082 - Added EL on DB, URI and Collection NIFI-4082 - Added UT for EL evaluation (URI, DB, Collection) and fixed ex. message for document validator. This closes #1969
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

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

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/nifi/pull/1969

            People

            • Assignee:
              pvillard Pierre Villard
              Reporter:
              dlukyanov Dmitry Lukyanov
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development