-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
removing background state update of Request object by RequestConverte… #40156
removing background state update of Request object by RequestConverte… #40156
Conversation
jenkins test this please |
Pinging @elastic/es-core-features |
builder.addCommaSeparatedPathParts(clearRealmCacheRequest.getRealms().toArray(Strings.EMPTY_ARRAY)); | ||
} else { | ||
builder.addPathPart("_all"); | ||
} | ||
final String endpoint = builder.addPathPartAsIs("_clear_cache").build(); | ||
Request request = new Request(HttpPost.METHOD_NAME, endpoint); | ||
if (clearRealmCacheRequest.getUsernames().isEmpty() == false) { | ||
RequestConverters.Params params = new RequestConverters.Params(request); | ||
if (!clearRealmCacheRequest.getUsernames().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please revert this change and all the similar ones? we tend to prefer the boolean == false
over !boolean
as the exclamation mark can easily be missed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please revert this?
@@ -50,6 +49,14 @@ public Request(String method, String endpoint) { | |||
this.endpoint = Objects.requireNonNull(endpoint, "endpoint cannot be null"); | |||
} | |||
|
|||
/** | |||
* Copy the parameters from {@literal RequestConverters.Params} into {@linkplain Request}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should just say "Set the parameters" , who sets them may change in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note that RequestConverters are part of the high-level REST client while Request is part of the low-level REST client which is used independently.
private final Map<String, String> requestParamsMap; | ||
|
||
Params() { | ||
this.requestParamsMap = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could initialize the map above and remove the default constructor.
@@ -50,6 +49,14 @@ public Request(String method, String endpoint) { | |||
this.endpoint = Objects.requireNonNull(endpoint, "endpoint cannot be null"); | |||
} | |||
|
|||
/** | |||
* Copy the parameters from {@literal RequestConverters.Params} into {@linkplain Request}. | |||
* @param requestConverterParams the request converter parameter map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove the mention of request converters here?
* Copy the parameters from {@literal RequestConverters.Params} into {@linkplain Request}. | ||
* @param requestConverterParams the request converter parameter map | ||
*/ | ||
public void setParameters(Map<String, String> requestConverterParams){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and rename the argument to not refer to request converters?
} | ||
|
||
Params putParam(String name, String value) { | ||
if (Strings.hasLength(value)) { | ||
request.addParameter(name, value); | ||
requestParamsMap.put(name, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this change we lose two checks that we were previously performing by calling Request#addParameter:
- check that the key is not null
- check that the param has not already been set (it would get overridden by default, but we prefer to throw error)
I think that we would want to keep these two checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javanna what error should i throw? i think that check would move to the copy method of Request class
requestParamsMap.put(name, value); | |
public void setParameters(Map<String, String> paramSource){ | |
paramSource.keySet().forEach(key -> { | |
if(this.parameters.get(key) != null){ | |
throw new Error(String.format("%s is already set", key)); | |
} | |
}); | |
this.parameters.putAll(paramSource); | |
} |
does this look good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you throw the same error that we throw in the Request class please? IllegalArgumentException?
thanks @kutty-kumar for opening this PR! I just did a first quick review and left some comments, also I started tests which are running. Let me know if you have any question on addressing the comments. |
@kutty-kumar it seems like there's a couple of failing tests. It's fine not to run all of our tests before submitting a PR, but in your case, could you run |
@javanna thanks for the initial review, i will work on resolving them and update the PR. |
@javanna i have made the required changes please review them also i am currently fixing the tests, will update here once done. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some more comments, let me know if you need help with the test failures.
client/rest/src/main/java/org/elasticsearch/client/Request.java
Outdated
Show resolved
Hide resolved
client/rest/src/main/java/org/elasticsearch/client/Request.java
Outdated
Show resolved
Hide resolved
client/rest-high-level/src/main/java/org/elasticsearch/client/WatcherRequestConverters.java
Outdated
Show resolved
Hide resolved
builder.addCommaSeparatedPathParts(clearRealmCacheRequest.getRealms().toArray(Strings.EMPTY_ARRAY)); | ||
} else { | ||
builder.addPathPart("_all"); | ||
} | ||
final String endpoint = builder.addPathPartAsIs("_clear_cache").build(); | ||
Request request = new Request(HttpPost.METHOD_NAME, endpoint); | ||
if (clearRealmCacheRequest.getUsernames().isEmpty() == false) { | ||
RequestConverters.Params params = new RequestConverters.Params(request); | ||
if (!clearRealmCacheRequest.getUsernames().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please revert this?
client/rest-high-level/src/main/java/org/elasticsearch/client/SecurityRequestConverters.java
Outdated
Show resolved
Hide resolved
client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java
Outdated
Show resolved
Hide resolved
client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java
Outdated
Show resolved
Hide resolved
client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java
Outdated
Show resolved
Hide resolved
@javanna yes i need some help in fixing the tests, not able to figure out where exactly they are failing, please direct me towards that, i will take care of the changes |
retest this please |
jenkins test this please |
@kutty-kumar the magic jenkins commands work only if you are part of the Elastic organization, for security reasons, I will run the tests again. |
retest this please |
@javanna i have started the gradle check process, its still running, doesn't seem to have any failures. Hence i wanted to test it on jenkins, thanks for the info :) |
@kutty-kumar there are still two failures:
would you mind having a look at those? You can run client tests only by executing |
done @javanna, please rebuild the source. |
retest this please |
`➜ rest-high-level git:(refactoring/requestConverterParams) ✗ ../../gradlew check
[ant:junit4] JVM J0: stderr was not empty, see: /Users/halodoc/Projects/elasticsearch1/client/rest-high-level/build/testrun/unitTest/temp/junit4-J0-20190326_162010_90016372490423214617704.syserr
HEARTBEAT J0 PID(12684@Kumards-MacBook-Pro.local): 2019-03-26T16:27:33, stalled for 10.7s at: SecurityDocumentationIT.testInvalidateToken
==> Test Summary: 45 suites, 490 tests Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. BUILD SUCCESSFUL in 13m 16s |
can you please merge master in @kutty-kumar ? |
@javanna its already up to date with master, please let me know what exactly i should do. |
retest this please |
@kutty-kumar it does not look up-to-date to me, could you pull latest master (doing |
@javanna can you please check now, my fork was behind the actual repository, hence the branch was behind, i have taken the changes from the actual repository and force pushed. Thanks |
retest this please |
@kutty-kumar some code needs updating now, as there are more users of the internal API that you have modified in your change. It should be straight-forward to address. |
hi @kutty-kumar have you had a chance to look into the needed changes? Do you need help with this? |
Hi @javanna i thought that i had to refactor a lot, hence i wanted your suggestions on doing this the right way. Please add in some thoughts which i could use to refine the code. |
@kutty-kumar as far as I can see, while you PR was getting reviewed, new API were added to the high-level REST client which use the mechanism that you were refactoring. You need to make the same changes to those newly added API. |
@kutty-kumar Are you interested in bringing this PR to completion? |
@jasontedor yes i will complete the PR by this weekend, sorry for the delay! |
This has stalled as no work has been done on it for a couple of months. Feel free to reopen or open a new PR when/if you get the time to work on it again. |
Changes required for removing background state update of request object by RequestConverters.Params object
#39666