REST Client: Add Request object flavored methods#29623
REST Client: Add Request object flavored methods#29623nik9000 merged 29 commits intoelastic:masterfrom
Conversation
This reverts commit 1cf984f.
The test looks like it is asserting stuff about the request but that duplicates what is in `HighLevelRequestsTests`.
|
Pinging @elastic/es-core-infra |
javanna
left a comment
There was a problem hiding this comment.
I left some comments but they are all minor. LGTM otherwise. I wonder if we should take out the deprecations and include them in a followup PR that can have the deprecation label and more visibility. Also, this will go 6.x too right?
|
|
||
| public final class Request { | ||
|
|
||
| final class HighLevelRequests { |
There was a problem hiding this comment.
++ also on the visibility change
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Request to Elasticsearch. |
| private final String method; | ||
| private final String endpoint; | ||
|
|
||
| private Map<String, String> parameters = Collections.<String, String>emptyMap(); |
There was a problem hiding this comment.
nit: shall we also make the parameters final? We could expose an add method if we want to rather than set. not too sure myself though about this, do what you prefer, just an idea.
| } catch (Exception e) { | ||
| responseListener.onFailure(e); | ||
| return; | ||
| } |
There was a problem hiding this comment.
shall we have a small private method that allows to build the request given all the different params and incorporates the catch as well?
There was a problem hiding this comment.
I didn't do that because each method sets different stuff.
| assertArrayEquals(headers, request.getHeaders()); | ||
| } | ||
|
|
||
| // TODO equals and hashcode |
There was a problem hiding this comment.
++ I have been wondering if we could make add a test dep to our test-framework. I think the reason why we haven't done it before is the java7 requirement.
There was a problem hiding this comment.
Yeah, the java 7 requirement is it I think.
| `performRequest` or `performRequestAsync`. `performRequest` is synchronous and | ||
| will block the calling thread and return the `Response` when the request is | ||
| complete. `performRequestAsync` is asynchronous and accepts a `ResponseListener` | ||
| argument that it will call with the request is complete or fails. |
There was a problem hiding this comment.
this last sentence doesn't compile
| callback instance per request attempt. Controls how the response body gets | ||
| streamed from a non-blocking HTTP connection on the client side. When not | ||
| provided, the default implementation is used which buffers the whole response | ||
| body in heap memory, up to 100 MB. |
There was a problem hiding this comment.
part of this explanation was useful I think, like the explanation of the default limit, which says why you may need to provide your own impl. Thoughts?
There was a problem hiding this comment.
I've added the explanation back.
There was a problem hiding this comment.
have you removed the link to the HttpAsyncResponseConsumer javadocs on purpose? You think it was not useful?
| import java.util.Objects; | ||
| import java.util.StringJoiner; | ||
|
|
||
| public final class Request { |
There was a problem hiding this comment.
one more thing, not too convinced about naming, given that what these methods do is convert from high-level requests to low-level requests. maybe rather Requests or RequestUtils? not a big deal though.
There was a problem hiding this comment.
I'll rename it to RequestConverters. OK?
| @@ -1370,143 +1343,115 @@ private static void assertToXContentBody(ToXContent expectedBody, HttpEntity act | |||
| assertEquals(expectedBytes, new BytesArray(EntityUtils.toByteArray(actualEntity))); | |||
| } | |||
|
|
|||
| public void testParams() { | |||
There was a problem hiding this comment.
This behavior has all been migrated to the Request object and has a test in the low level REST client.
|
@javanna, I've worked through most of your comments. The one about using a |
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack:core` project to use the new versions.
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack/plugin/monitoring` project to use the new versions.
In #29623 we added `Request` object flavored requests to the low level REST client and in #30315 we deprecated the old `performRequest`s. This changes all calls in the `qa/full-cluster-restart` project to use the new versions. It also fixes a small bug in the test for explain on the `_all` field that was causing it to not properly invoke `_explain`.
In #29623 we added `Request` object flavored requests to the low level REST client and in #30315 we deprecated the old `performRequest`s. This changes all calls in the `qa/full-cluster-restart` project to use the new versions. It also fixes a small bug in the test for explain on the `_all` field that was causing it to not properly invoke `_explain`.
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack/plugin/security` project to use the new versions.
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack:qa:full-cluster-restart` project to use the new versions.
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack/plugin` project to use the new versions.
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack:qa:rolling-upgrade*` projects to use the new versions.
In elastic#29623 we added `Request` object flavored requests to the low level REST client and in elastic#30315 we deprecated the old `performRequest`s. This changes all calls in the `x-pack/qa/security-example-spi-extension` project to use the new versions.
Adds two new methods to
RestClientthat take aRequestobject. Thesemethods will allows us to add more per-request customizable options
without creating more and more and more overloads of the
performRequestand
performRequestAsyncmethods. These new methods look like:and
This change doesn't add any actual features but enables adding things like
per request timeouts and per request node selectors. This change does
rework the
HighLevelRestClientand its tests to use these newRequestobjects and it does update the docs.