NIFI-7037 Split off username and password fields for GetMongo processor#4231
NIFI-7037 Split off username and password fields for GetMongo processor#4231karthik-kadajji wants to merge 5 commits into
Conversation
| runner.removeProperty(AbstractMongoProcessor.URI); | ||
| runner.setVariable("uri", "mongodb://localhost:27017/?authSource="+DB_NAME); | ||
| runner.setProperty(AbstractMongoProcessor.URI, "${uri}"); | ||
| runner.setProperty(GetMongo.PASSWORD,password); |
There was a problem hiding this comment.
To stay consistent, add a space between the arguments. There are also other similar places in this class.
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Better would be to use a logger.
There was a problem hiding this comment.
I have dropped the entire line, since it is a test case, didnt need the "dropping user" message or log
HorizonNet
left a comment
There was a problem hiding this comment.
Left three minor NITs. LGTM overall.
|
|
||
| outgoingFlowFile = session.putAllAttributes(outgoingFlowFile, attributes); | ||
| session.getProvenanceReporter().receive(outgoingFlowFile, getURI(context)); | ||
| String uriPass=""; |
There was a problem hiding this comment.
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()))); | ||
|
|
| Assert.assertTrue(((String) parsed.get("date_field")).startsWith(format.format(CAL.getTime()))); | ||
|
|
||
| } | ||
|
|
| .build(); | ||
| static final PropertyDescriptor USER_NAME = new PropertyDescriptor.Builder() | ||
| .name("User Name") | ||
| .displayName("username") |
There was a problem hiding this comment.
I think the name and displayName values are switched.
There was a problem hiding this comment.
Thank you for pointing it out. I will add it
| .build(); | ||
|
|
||
| static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder() | ||
| .name("Password") |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Most of this method appears to duplicate AbstractMongoProcessor#createClient(). I suggest the duplicated code should be refactored.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
@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.
|
It looks like the |
|
@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. |
MikeThomsen
left a comment
There was a problem hiding this comment.
@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.
|
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. |
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
squashor use--forcewhen pushing to allow for clean monitoring of changes.For code changes:
mvn -Pcontrib-check clean installat the rootnififolder?LICENSEfile, including the mainLICENSEfile undernifi-assembly?NOTICEfile, including the mainNOTICEfile found undernifi-assembly?.displayNamein addition to .name (programmatic access) for each of the new properties?For documentation related changes:
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.