-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Add support for indices exists to REST high level client #27384
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@karmi Done! |
return new IndicesExistsResponse(response.getStatusLine().getStatusCode() == 200); | ||
} | ||
|
||
public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener<IndicesExistsResponse> listener, Header... headers) throws IOException { |
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.
Async version needed?
@@ -373,12 +377,12 @@ static Request search(SearchRequest searchRequest) throws IOException { | |||
|
|||
static Request searchScroll(SearchScrollRequest searchScrollRequest) throws IOException { | |||
HttpEntity entity = createEntity(searchScrollRequest, REQUEST_BODY_CONTENT_TYPE); | |||
return new Request("GET", "/_search/scroll", Collections.emptyMap(), entity); | |||
return new Request("GET", "/_search/scroll", emptyMap(), entity); |
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 can remove this, if needed.
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.
yes please, I commented above about it, before seeing your question ;)
@@ -410,10 +414,16 @@ static String endpoint(String... parts) { | |||
* @return the {@link ContentType} | |||
*/ | |||
@SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") | |||
public static ContentType createContentType(final XContentType xContentType) { | |||
public static <Req extends ActionRequest> ContentType createContentType(final XContentType xContentType) { |
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 will revert.
@@ -72,7 +72,7 @@ protected static RestHighLevelClient highLevelClient() { | |||
|
|||
@FunctionalInterface | |||
protected interface AsyncMethod<Request, Response> { | |||
void execute(Request request, ActionListener<Response> listener, Header... headers); | |||
void execute(Request request, ActionListener<Response> listener, Header... headers) throws IOException; |
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.
Most probably this is not needed, I'll remove.
return null; | ||
} | ||
|
||
public static IndicesExistsResponse fromXContent(XContentParser xContentParser) { |
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 believe none of this is really needed...
); | ||
} | ||
|
||
private IndicesExistsResponse parseIndicesExistResp(Response response) { |
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.
It might have been better to move this method into IndicesExistsResponse
, but Response
is not visible from IndicesExistsResponse
.
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.
use the already existing convertExistsResponse from RestHighLevelClient, you can see how this is done in the ping method for instance.
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.
hi @hariso , this looks pretty good, I will remove the WIP label. If you can add docs and address the few comments I left, I will merge this. Thanks!
On your questions: naming is good as-is. We do need the async version I think, which you have already added, so nothing to do there. The behaviour of the API when multiple indices are passed in can be controlled through indices options which are currently not supported in your PR, you'll see a comment about that. Once you support those you just have to return true if 200 and false if 404.
); | ||
} | ||
|
||
private IndicesExistsResponse parseIndicesExistResp(Response response) { |
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.
use the already existing convertExistsResponse from RestHighLevelClient, you can see how this is done in the ping method for instance.
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
import static java.util.Collections.emptySet; |
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: can you revert the addition of the static import? It affects also other methods that you are not changing and that causes some noise in the PR.
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.
Will do 👍
@@ -67,6 +69,8 @@ | |||
import java.util.Objects; | |||
import java.util.StringJoiner; | |||
|
|||
import static java.util.Collections.emptyMap; |
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: can you revert the addition of the static import? It affects also other methods that you are not changing and that causes some noise in the PR.
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.
Will do 👍
@@ -373,12 +377,12 @@ static Request search(SearchRequest searchRequest) throws IOException { | |||
|
|||
static Request searchScroll(SearchScrollRequest searchScrollRequest) throws IOException { | |||
HttpEntity entity = createEntity(searchScrollRequest, REQUEST_BODY_CONTENT_TYPE); | |||
return new Request("GET", "/_search/scroll", Collections.emptyMap(), entity); | |||
return new Request("GET", "/_search/scroll", emptyMap(), entity); |
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.
yes please, I commented above about it, before seeing your question ;)
@@ -414,6 +418,12 @@ public static ContentType createContentType(final XContentType xContentType) { | |||
return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); | |||
} | |||
|
|||
static Request indicesExist(IndicesExistsRequest request) { | |||
String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); | |||
|
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 remove this empty line please?
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.
Will do 👍
import org.elasticsearch.rest.RestStatus; | ||
|
||
import java.io.IOException; | ||
|
||
public class IndicesClientIT extends ESRestHighLevelClientTestCase { | ||
|
||
public void testIndexExists_IndexPresent() throws IOException { |
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 would prefer not using underscore as part of method names if possible. can you remove this one and the following ones please?
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.
Done!
final Request request = Request.indicesExist(indicesExistRequest); | ||
assertEquals("/" + index1 + "," + index2, request.getEndpoint()); | ||
assertEquals("HEAD", request.getMethod()); | ||
} |
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 one test here is enough. test it with a random number of indices ?
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.
Done! Test is now using up to 10 indices with random names.
static Request indicesExist(IndicesExistsRequest request) { | ||
String endpoint = endpoint(request.indices(), Strings.EMPTY_ARRAY, ""); | ||
|
||
return new Request(HttpHead.METHOD_NAME, endpoint, emptyMap(), null); |
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.
we should add support here for some missing parameters, see https://github.com/elastic/elasticsearch/blob/master/rest-api-spec/src/main/resources/rest-api-spec/api/indices.exists.json .
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 I implemented this. Two values I could extract from IndicesExistsRequest I did. Please double check, since I have the feeling I missed something.
listener, emptySet(), headers); | ||
} | ||
|
||
public IndicesExistsResponse exists(IndicesExistsRequest indicesExistsRequest, Header... headers) throws IOException { |
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 make this final?
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 guess you mean the method and not parameters ("this" and not "these"), but I'd like to double check.: )
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.
yes the method.
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.
Done.
return new IndicesExistsResponse(response.getStatusLine().getStatusCode() == 200); | ||
} | ||
|
||
public void existsAsync(IndicesExistsRequest indicesExistsRequest, ActionListener<IndicesExistsResponse> listener, Header... headers) { |
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 make this final?
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.
Done.
hi @hariso do you think you'll have time to get back to this PR, merge master in and make the requested changes above? Thanks! |
@javanna Thanks a lot for the feedback! I did a few small refactorings in the tests. I'll now address the other comments and let you once all of that is done. |
@@ -1230,6 +1178,34 @@ private static void setRandomIndicesOptions(Consumer<IndicesOptions> setter, Sup | |||
} | |||
} | |||
|
|||
private static void setRandomIncludeDefaults(GetIndexRequest request, Map<String, String> expectedParams) { | |||
if (randomBoolean()) { | |||
request.includeDefaults(true); |
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 also randomize the value, just to test what we do when the value is explicitly set to false? It is the default value but I would prefer to test that codepath too. Same for the other new methods.
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.
Done!
request.local(true); | ||
expectedParams.put("local", Boolean.TRUE.toString()); | ||
} | ||
} |
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.
good work!
@javanna Another batch of changes is in!
This is obviously the two new fields, |
|
||
assertEquals(HttpHead.METHOD_NAME, request.getMethod()); | ||
assertEquals("/" + String.join(",", indices), request.getEndpoint()); | ||
assertThat(expectedParams, equalTo(request.getParameters())); |
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: can you assert that request.getEntity is null please?
@@ -99,6 +98,8 @@ public static Feature fromId(byte id) { | |||
private static final Feature[] DEFAULT_FEATURES = new Feature[] { Feature.ALIASES, Feature.MAPPINGS, Feature.SETTINGS }; | |||
private Feature[] features = DEFAULT_FEATURES; | |||
private boolean humanReadable = false; | |||
private boolean flatSettings = false; | |||
private boolean includeDefaults = false; |
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.
the point that you make on these not being serializable is a good one. I think that is a good choice, if we want to make it more explicit we could mark these transient
<2> Return result in a format suitable for humans. | ||
<3> Whether to return all default setting for each of the indices. | ||
<4> Return settings in flat format. | ||
<5> Controls how unavailable indices are resolved and how wildcard expressions are expanded. |
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: can you remove the punctuation mark at the end of these notes?
include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[indices-exists-async] | ||
-------------------------------------------------- | ||
<1> Called when the execution is successfully completed. The response is provided as an argument. | ||
<2> Called in case of failure. The raised exception is provided as an argument. |
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.
remove the final punctuation marks?
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.
this is ready @hariso . I left a couple of very minor comments. Docs look good. if you can address the last few comments I will merge this.
@javanna Docs and tests updated. I just realized one thing, and that is that it may be good to combine three different tests for Indices Exists API from |
include::delete_index.asciidoc[] | ||
>>>>>>> master |
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.
could you fix this? A merge gone wrong I think
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.
include::deleteindex.asciidoc[] should go, it's been replaced by include::delete_index.asciidoc[]
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.
Fixed, thanks for noticing it!
thanks a lot @hariso ! |
Thank you for all the stuff I learnt here! No wonder Elasticsearch is such a great piece of software! |
This is obviously work in progress, but I opened the PR to ask a few questions: