Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-4184: PutHDFS Processor Expression language TRUE on REMOTE_GROUP & REMOTE_OWNER #2007

Closed
wants to merge 3 commits into from

Conversation

panelladavide
Copy link
Contributor

@panelladavide panelladavide commented Jul 13, 2017

I needed to put some attributes on REMOTE_GROUP and REMOTE_OWNER, in order to achieve it i put expressionLanguageSupported(true) on the PropertyDescriptor of REMOTE_GROUP and REMOTE_OWNER

Signed-off-by: Davide davidde85@hotmail.it

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?
  • 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.

…order to achieve it i put expressionLanguageSupported(true) on the PropertyDescriptor of REMOTE_GROUP and REMOTE_OWNER

Signed-off-by: Davide <davidde85@hotmail.it>
@panelladavide panelladavide changed the title I needed to put some attributes on REMOTE_GROUP and REMOTE_OWNER, in … NIFI-4184 Jul 13, 2017
@panelladavide panelladavide changed the title NIFI-4184 NIFI-4184: PutHDFS Processor Jul 13, 2017
@panelladavide panelladavide changed the title NIFI-4184: PutHDFS Processor NIFI-4184: PutHDFS Processor (expression language TRUE on REMOTE_GROUP & REMOTE_OWNER) Jul 13, 2017
@panelladavide panelladavide changed the title NIFI-4184: PutHDFS Processor (expression language TRUE on REMOTE_GROUP & REMOTE_OWNER) NIFI-4184: PutHDFS Processor Expression language TRUE on REMOTE_GROUP & REMOTE_OWNER Jul 13, 2017
@ijokarumawak
Copy link
Member

Hi @panelladavide thanks for your contribution!

In order to enable Expression Language, setting expressionLanguageSupported to true is not enough. You also need to evaluate the configured EL. Plus, if you need to support EL to use FlowFile attribute, you need to pass a FlowFile (the incoming FlowFile in most cases) when EL is evaluated.

Specifically, you need to modify changeOwner method:

  • Add EL evaluation like:
    String owner = context.getProperty(REMOTE_OWNER).evaluateAttributeExpressions(flowFile).getValue();
    
  • Add FlowFile argument, so that it can be passed to evaluateAttributeExpressions(flowFile)

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-hadoop-bundle/nifi-hdfs-processors/src/main/java/org/apache/nifi/processors/hadoop/PutHDFS.java#L389

@panelladavide
Copy link
Contributor Author

panelladavide commented Jul 18, 2017

@ijokarumawak Thank you so much!
As soon as I have time to code I will update my branch.

I have a question. Why did not you enable the EL in PutHDFS REMOTE_OWNER and GROUP_OWNER?
Is there a specific reason?

@ijokarumawak
Copy link
Member

@panelladavide I don't know any reason for not supporting EL with REMOTE_OWNER/GROUP. I think applying EL at incoming FlowFile level is safe, and wouldn't break anything because it just sets owner for a specific path.

It would be problematic if it changes FileSystem or HdfsResources instance state those are reused from every onTrigger call. But again, setting owner should just affect the specified path, so it should be fine.

I guess it's just written that way at the initial contribution and haven't been requested until now.

…order to achieve it i put expressionLanguageSupported(true) on the PropertyDescriptor of REMOTE_GROUP and REMOTE_OWNER

Signed-off-by: Davide <davidde85@hotmail.it>
@panelladavide
Copy link
Contributor Author

Thank you so much!

Copy link
Member

@ijokarumawak ijokarumawak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panelladavide Thanks for the updates! I tested with my Hadoop cluster, basically it works as expected, but I found minor issue with EL returning an empty string. Please update it once again, and it will be ready to be merged. Thanks a lot!

@@ -352,7 +354,7 @@ public void process(InputStream in) throws IOException {
+ " to its final filename");
}

changeOwner(context, hdfs, copyFile);
changeOwner(context, hdfs, copyFile,flowFile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial, please add a whitespace between arguments.

String owner = context.getProperty(REMOTE_OWNER).getValue();
String group = context.getProperty(REMOTE_GROUP).getValue();
// String owner = context.getProperty(REMOTE_OWNER).getValue();
// String group = context.getProperty(REMOTE_GROUP).getValue();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these old lines. We don't have to keep old code unless if there's a strong needs.

// String group = context.getProperty(REMOTE_GROUP).getValue();
String owner = context.getProperty(REMOTE_OWNER).evaluateAttributeExpressions(flowFile).getValue();
String group = context.getProperty(REMOTE_GROUP).evaluateAttributeExpressions(flowFile).getValue();

if (owner != null || group != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tested with an expression that returns no value, e.g. specify an attribute name which does not exist, then the group string became an Empty string. And the file was updated with an empty group. To avoid that, Could you add following code before this if statement? to make empty string into null:

            owner = owner == null || owner.isEmpty() ? null : owner;
            group = group == null || group.isEmpty() ? null : group;

image

…order to achieve it i put expressionLanguageSupported(true) on the PropertyDescriptor of REMOTE_GROUP and REMOTE_OWNER

Signed-off-by: Davide <davidde85@hotmail.it>
@ijokarumawak
Copy link
Member

@panelladavide LGTM, +1. I'm going to merge. Thanks for your contribution!

@panelladavide
Copy link
Contributor Author

Thanks for your help and for your patience! Why AppVeyor build failed? When Nifi release a new release?

@ijokarumawak
Copy link
Member

AppVeyor build has been failing. There are many unit tests those are not working well on Windows. We've been trying to improve it but not completed.

@asfgit asfgit closed this in d334532 Jul 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants