Skip to content
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 Open Index API to the high level REST client #27574

Merged
merged 5 commits into from
Dec 7, 2017

Conversation

olcbean
Copy link
Contributor

@olcbean olcbean commented Nov 28, 2017

Add _open to the high level REST client

Relates to #27205

@elasticmachine
Copy link
Collaborator

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?

@DaveCTurner
Copy link
Contributor

@elasticmachine please test this

@javanna javanna self-assigned this Dec 1, 2017
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

thanks a lot @olcbean I left a few comments, looks good though. I will merge this once you addressed those.

*/
public final void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) {
performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent, listener,
Collections.singleton(404), headers);
Copy link
Member

Choose a reason for hiding this comment

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

we need these only in IndicesClient, so that users can do client.indices().openIndex() . No need to add them here too.

OpenIndexRequest openIndexRequest = new OpenIndexRequest(indexName);
OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::openIndex,
highLevelClient().indices()::openIndexAsync);
assertTrue(openIndexResponse.isAcknowledged());
Copy link
Member

Choose a reason for hiding this comment

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

maybe it would be good to close the index first using the low-level REST client, then verify that opening it actually does something?


ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
Copy link
Member

Choose a reason for hiding this comment

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

maybe also test the API against multiple indices?

Map<String, String> expectedParams = new HashMap<>();
setRandomTimeout(openIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
setRandomMasterTimeout(openIndexRequest, expectedParams);
setRandomIndicesOptions(openIndexRequest::indicesOptions, openIndexRequest::indicesOptions, expectedParams);
Copy link
Member

Choose a reason for hiding this comment

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

can we also add the set wait for active shards ?

boolean humanReadable = randomBoolean();
final XContentType xContentType = randomFrom(XContentType.values());
BytesReference originalBytes = toShuffledXContent(openIndexResponse, xContentType, ToXContent.EMPTY_PARAMS, humanReadable);

Copy link
Member

Choose a reason for hiding this comment

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

can you also add here an insertRandomFields step to verify forward compatibility (as we ignore any unknown fields rather than throwing errors)

final XContentType xContentType = randomFrom(XContentType.values());
BytesReference originalBytes = toShuffledXContent(openIndexResponse, xContentType, ToXContent.EMPTY_PARAMS, humanReadable);

OpenIndexResponse parsedCreateIndexResponse;
Copy link
Member

Choose a reason for hiding this comment

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

rename this variable?

@olcbean
Copy link
Contributor Author

olcbean commented Dec 3, 2017

@javanna thanks for the review. Ready for a second round ;)

@javanna
Copy link
Member

javanna commented Dec 4, 2017

test this please

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

thanks @olcbean I left a few more comments, nothing major. The important bit is removing the new methods from RestHighLevelClient.

@@ -281,7 +283,7 @@ public final GetResponse get(GetRequest getRequest, Header... headers) throws IO
*
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html">Get API on elastic.co</a>
*/
public void getAsync(GetRequest getRequest, ActionListener<GetResponse> listener, Header... headers) {
public final void getAsync(GetRequest getRequest, ActionListener<GetResponse> listener, Header... headers) {
Copy link
Member

Choose a reason for hiding this comment

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

thank you, seems like I left this out :)

public final void openIndexAsync(OpenIndexRequest openIndexRequest, ActionListener<OpenIndexResponse> listener, Header... headers) {
performRequestAsyncAndParseEntity(openIndexRequest, Request::openIndex, OpenIndexResponse::fromXContent, listener, emptySet(),
headers);
}
Copy link
Member

Choose a reason for hiding this comment

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

we don't need these two methods, they are already in IndicesClient. Can you remove them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

facepalm

return randomIndices(0, 5);
}

private String[] randomIndices(int minIndicesNum, int maxIndicesNum) {
Copy link
Member

Choose a reason for hiding this comment

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

make this static?

assertEquals(RestStatus.NOT_FOUND, exception.status());
}

private String[] randomIndices() {
Copy link
Member

Choose a reason for hiding this comment

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

maybe we can remove this method and always call the other one?

assertTrue(openIndexResponse.isAcknowledged());

for (String index : indices) {
client().performRequest("GET", index + "/_search");
Copy link
Member

Choose a reason for hiding this comment

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

check that 200 was returned?

OpenIndexRequest openIndexRequest = new OpenIndexRequest(nonExistentIndices);
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(openIndexRequest, highLevelClient().indices()::openIndex, highLevelClient().indices()::openIndexAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
Copy link
Member

Choose a reason for hiding this comment

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

would you mind checking also that with IndicesOptions.lenientExpandOpen we don't get back an error?

@olcbean
Copy link
Contributor Author

olcbean commented Dec 4, 2017

@javanna my bad! Ready for another round ;)

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

LGTM thanks @olcbean

@javanna
Copy link
Member

javanna commented Dec 6, 2017

test this please

@javanna
Copy link
Member

javanna commented Dec 6, 2017

retest this please

@javanna
Copy link
Member

javanna commented Dec 7, 2017

heya @olcbean I took the liberty to merge master in as there were conflicts and push to your remote. Running tests one last time and then merging. Thanks a lot!

@javanna
Copy link
Member

javanna commented Dec 7, 2017

retest this please

@olcbean
Copy link
Contributor Author

olcbean commented Dec 7, 2017

Thanks @javanna!
I will continue with _close ( if nobody is working on it )

@javanna
Copy link
Member

javanna commented Dec 7, 2017

sounds great @olcbean thank you!

@javanna javanna merged commit bcc33f3 into elastic:master Dec 7, 2017
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Dec 8, 2017
* master: (414 commits)
  Set ACK timeout on indices service test
  Implement byte array reusage in `NioTransport` (elastic#27696)
  [TEST] Remove leftover ES temp directories before Vagrant tests (elastic#27722)
  Cleanup split strings by comma method
  Remove unused import from AliasResolveRoutingIT
  Add read timeouts to http module (elastic#27713)
  Fix routing with leading or trailing whitespace
  remove await fix from FullClusterRestartIT.testRecovery
  Add missing 's' to tmpdir name (elastic#27721)
  [Issue-27716]: CONTRIBUTING.md IntelliJ configurations settings are confusing. (elastic#27717)
  [TEST] Now actually wait for merges
  Test out of order delivery of append only index and retry with an intermediate delete
  [TEST] remove code duplications in RequestTests
  [Tests] Add test for GeoShapeFieldType#setStrategyName (elastic#27703)
  Remove unused *Commit* classes (elastic#27714)
  Add test for writer operation buffer accounting (elastic#27707)
  [TEST] Wait for merging to complete before testing breaker
  Add Open Index API to the high level REST client (elastic#27574)
  Correcting some minor typos in comments
  Add unreleased v5.6.6 version
  ...
javanna pushed a commit that referenced this pull request Dec 10, 2017
Add _open to the high level REST client

Relates to #27205
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants