Skip to content

NIFI-7037 Split off username and password fields for GetMongo processor#4231

Closed
karthik-kadajji wants to merge 5 commits into
apache:masterfrom
karthik-kadajji:NIFI-7037
Closed

NIFI-7037 Split off username and password fields for GetMongo processor#4231
karthik-kadajji wants to merge 5 commits into
apache:masterfrom
karthik-kadajji:NIFI-7037

Conversation

@karthik-kadajji
Copy link
Copy Markdown
Contributor

Thank you for submitting a contribution to Apache NiFi.

Please provide a short description of the PR here:

Description of PR

Enables X functionality; fixes bug NIFI-YYYY.

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? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not squash or use --force when pushing to allow for clean monitoring of changes.

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?
  • [ X] Have you written or updated unit tests to verify your changes?
  • Have you verified that the full build is successful on both JDK 8 and JDK 11?
  • 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?
  • [ X] 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.

runner.removeProperty(AbstractMongoProcessor.URI);
runner.setVariable("uri", "mongodb://localhost:27017/?authSource="+DB_NAME);
runner.setProperty(AbstractMongoProcessor.URI, "${uri}");
runner.setProperty(GetMongo.PASSWORD,password);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To stay consistent, add a space between the arguments. There are also other similar places in this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the spacing . Thank you

new Document("_id", "doc_1").append("a", 1).append("b", 2).append("c", 3),
new Document("_id", "doc_2").append("a", 1).append("b", 2).append("c", 4).append("date_field", CAL.getTime()),
new Document("_id", "doc_3").append("a", 1).append("b", 3)
new Document("_id", "doc_1").append("a", 1).append("b", 2).append("c", 3),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was this done by IDE auto-indentation or because the earlier version did not match the general indentation? There are also similar places in the other classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is due to earlier version mismatch, for continuous indentation it is 8 spaces in some places and 4 at some. However, I have indented as before.

ArrayList users = (ArrayList) result.get("users");
if (!users.isEmpty()) {
db.runCommand(dropUserCommand);
System.out.println("dropping user");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Better would be to use a logger.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have dropped the entire line, since it is a test case, didnt need the "dropping user" message or log

Copy link
Copy Markdown
Contributor

@HorizonNet HorizonNet left a comment

Choose a reason for hiding this comment

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

Left three minor NITs. LGTM overall.


outgoingFlowFile = session.putAllAttributes(outgoingFlowFile, attributes);
session.getProvenanceReporter().receive(outgoingFlowFile, getURI(context));
String uriPass="";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add spaces around the equals sing.


Assert.assertTrue(parsed.get("date_field").getClass() == String.class);
Assert.assertTrue(((String) parsed.get("date_field")).startsWith(format.format(CAL.getTime())));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove empty line.

Assert.assertTrue(((String) parsed.get("date_field")).startsWith(format.format(CAL.getTime())));

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ditto.

.build();
static final PropertyDescriptor USER_NAME = new PropertyDescriptor.Builder()
.name("User Name")
.displayName("username")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the name and displayName values are switched.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing it out. I will add it

.build();

static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
.name("Password")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The name value should match the formatting of the username field and a displayName should also be present.

session.getProvenanceReporter().receive(outgoingFlowFile, getURI(context));
String uriPass = "";
if (context.getProperty(USER_NAME).getValue() != null) {
uriPass = "mongodb://" + context.getProperty(USER_NAME).getValue() + ":" + context.getProperty(PASSWORD).getValue() + "@" + getURI(context).substring(10);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't believe the URI is validated anywhere to ensure it starts with mongodb://, so arbitrarily starting the index at 10 isn't guaranteed to produce the expected outcome.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, there is a note in the MongoDB docs regarding usernames and passwords that contain special characters:

If the username or password includes the at sign @, colon :, slash /, or the percent sign % character, use percent encoding.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will add in the validation for the starting 10 characters for the URI.

I did see the MongoDB doc, for percent encoding which would be better:
a) forcing the user to handle the percent encoding and printing it in the description as a note for user.
b) explicitly handling of it by the processor.

current implementation is goes the first way. But if you think It is better for processor to handle, I will look into it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not something I would expect the user to do manually. It should be done automatically by the processor.

}

@OnScheduled
public void createClient(ProcessContext context) throws IOException {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Most of this method appears to duplicate AbstractMongoProcessor#createClient(). I suggest the duplicated code should be refactored.

Copy link
Copy Markdown
Contributor Author

@karthik-kadajji karthik-kadajji Apr 28, 2020

Choose a reason for hiding this comment

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

It is true I could have done the changes in AbstractMongoProcessor, but it would end up affecting the components of PutMongo. Also Since request was for just getMongo I did it this way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think all 6 of the MongoDB processors need this change if one does, so it should be made in a consistent manner. It appears the Jira is incomplete as it only indicates the GetMongo processor, but that's what this review process is intended to mitigate. Requirements gathering is notoriously difficult and a single user's request has to be balanced against the ongoing needs of the project as a whole. Any code changes introduced need to be well-understood, complete, tested, sustainable, and maintainable. I use the analogy from camping of "leave it better than you found it."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@alopresto We started moving toward using a controller service to manage the client connection I think ~3 releases ago. The best place for these changes might be there, so we can start moving toward deprecating per-processor connection management altogether.

@alopresto
Copy link
Copy Markdown
Contributor

It looks like the PutMongo and DeleteMongo processors (as well as GetMongoRecord, PutMongoRecord, and DeleteMongoRecord) could also take advantage of these new property descriptors, and therefore the better location for them is in AbstractMongoProcessor.

@MikeThomsen
Copy link
Copy Markdown
Contributor

@karthik-kadajji It would be easier to apply this change to the Mongo controller service. If you look at all of the processors, you'll see that they have "client service" as an option. In the long run, I'm planning to start deprecating the current configuration options and have the Mongo processors use that because it matches our design patterns better.

Copy link
Copy Markdown
Contributor

@MikeThomsen MikeThomsen left a comment

Choose a reason for hiding this comment

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

@karthik-kadajji I'm -1 on merging because this needs to be in the controller service, as the goal is to deprecate the configuration fields in each processor in favor of using a controller service to act as the connection pool.

@github-actions
Copy link
Copy Markdown

We're marking this PR as stale due to lack of updates in the past few months. If after another couple of weeks the stale label has not been removed this PR will be closed. This stale marker and eventual auto close does not indicate a judgement of the PR just lack of reviewer bandwidth and helps us keep the PR queue more manageable. If you would like this PR re-opened you can do so and a committer can remove the stale tag. Or you can open a new PR. Try to help review other PRs to increase PR review bandwidth which in turn helps yours.

@github-actions github-actions Bot added the Stale label Apr 25, 2021
@github-actions github-actions Bot closed this May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants