Skip to content

Commit 049966a

Browse files
authored
Check that client methods match API defined in the REST spec (#31825)
We have been encountering name mismatches between API defined in our REST spec and method names that have been added to the high-level REST client. We should check this automatically to prevent furher mismatches, and correct all the current ones. This commit adds a test for this and corrects the issues found by it.
1 parent 9e529d9 commit 049966a

21 files changed

+359
-86
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.elasticsearch.gradle.VersionProperties
2424
import org.gradle.api.DefaultTask
2525
import org.gradle.api.Project
2626
import org.gradle.api.Task
27-
import org.gradle.api.Transformer
2827
import org.gradle.api.execution.TaskExecutionAdapter
2928
import org.gradle.api.internal.tasks.options.Option
3029
import org.gradle.api.provider.Property
@@ -217,7 +216,7 @@ public class RestIntegTestTask extends DefaultTask {
217216
* @param project The project to add the copy task to
218217
* @param includePackagedTests true if the packaged tests should be copied, false otherwise
219218
*/
220-
private static Task createCopyRestSpecTask(Project project, Provider<Boolean> includePackagedTests) {
219+
static Task createCopyRestSpecTask(Project project, Provider<Boolean> includePackagedTests) {
221220
project.configurations {
222221
restSpec
223222
}

client/rest-high-level/build.gradle

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919

2020
import org.elasticsearch.gradle.precommit.PrecommitTasks
21-
import org.gradle.api.XmlProvider
22-
import org.gradle.api.publish.maven.MavenPublication
21+
import org.elasticsearch.gradle.test.RestIntegTestTask
22+
import org.gradle.api.internal.provider.Providers
2323

2424
buildscript {
2525
repositories {
@@ -41,6 +41,10 @@ apply plugin: 'com.github.johnrengelman.shadow'
4141
group = 'org.elasticsearch.client'
4242
archivesBaseName = 'elasticsearch-rest-high-level-client'
4343

44+
//we need to copy the yaml spec so we can check naming (see RestHighlevelClientTests#testApiNamingConventions)
45+
Task copyRestSpec = RestIntegTestTask.createCopyRestSpecTask(project, Providers.FALSE)
46+
test.dependsOn(copyRestSpec)
47+
4448
publishing {
4549
publications {
4650
nebula(MavenPublication) {
@@ -102,6 +106,8 @@ dependencies {
102106
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
103107
testCompile "junit:junit:${versions.junit}"
104108
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
109+
//this is needed to make RestHighLevelClientTests#testApiNamingConventions work from IDEs
110+
testCompile "org.elasticsearch:rest-api-spec:${version}"
105111
}
106112

107113
dependencyLicenses {

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

+32-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void putMappingAsync(PutMappingRequest putMappingRequest, RequestOptions
174174
* @return the response
175175
* @throws IOException in case there is a problem sending the request or parsing back the response
176176
*/
177-
public GetMappingsResponse getMappings(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
177+
public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
178178
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest, RequestConverters::getMappings, options,
179179
GetMappingsResponse::fromXContent, emptySet());
180180
}
@@ -187,8 +187,8 @@ public GetMappingsResponse getMappings(GetMappingsRequest getMappingsRequest, Re
187187
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
188188
* @param listener the listener to be notified upon request completion
189189
*/
190-
public void getMappingsAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
191-
ActionListener<GetMappingsResponse> listener) {
190+
public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
191+
ActionListener<GetMappingsResponse> listener) {
192192
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest, RequestConverters::getMappings, options,
193193
GetMappingsResponse::fromXContent, listener, emptySet());
194194
}
@@ -474,8 +474,23 @@ public void getAsync(GetIndexRequest getIndexRequest, RequestOptions options,
474474
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
475475
* @return the response
476476
* @throws IOException in case there is a problem sending the request or parsing back the response
477+
* @deprecated use {@link #forcemerge(ForceMergeRequest, RequestOptions)} instead
477478
*/
479+
@Deprecated
478480
public ForceMergeResponse forceMerge(ForceMergeRequest forceMergeRequest, RequestOptions options) throws IOException {
481+
return forcemerge(forceMergeRequest, options);
482+
}
483+
484+
/**
485+
* Force merge one or more indices using the Force Merge API.
486+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
487+
* Force Merge API on elastic.co</a>
488+
* @param forceMergeRequest the request
489+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
490+
* @return the response
491+
* @throws IOException in case there is a problem sending the request or parsing back the response
492+
*/
493+
public ForceMergeResponse forcemerge(ForceMergeRequest forceMergeRequest, RequestOptions options) throws IOException {
479494
return restHighLevelClient.performRequestAndParseEntity(forceMergeRequest, RequestConverters::forceMerge, options,
480495
ForceMergeResponse::fromXContent, emptySet());
481496
}
@@ -487,8 +502,22 @@ public ForceMergeResponse forceMerge(ForceMergeRequest forceMergeRequest, Reques
487502
* @param forceMergeRequest the request
488503
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
489504
* @param listener the listener to be notified upon request completion
505+
* @deprecated use {@link #forcemergeAsync(ForceMergeRequest, RequestOptions, ActionListener)} instead
490506
*/
507+
@Deprecated
491508
public void forceMergeAsync(ForceMergeRequest forceMergeRequest, RequestOptions options, ActionListener<ForceMergeResponse> listener) {
509+
forcemergeAsync(forceMergeRequest, options, listener);
510+
}
511+
512+
/**
513+
* Asynchronously force merge one or more indices using the Force Merge API.
514+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
515+
* Force Merge API on elastic.co</a>
516+
* @param forceMergeRequest the request
517+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
518+
* @param listener the listener to be notified upon request completion
519+
*/
520+
public void forcemergeAsync(ForceMergeRequest forceMergeRequest, RequestOptions options, ActionListener<ForceMergeResponse> listener) {
492521
restHighLevelClient.performRequestAsyncAndParseEntity(forceMergeRequest, RequestConverters::forceMerge, options,
493522
ForceMergeResponse::fromXContent, listener, emptySet());
494523
}

client/rest-high-level/src/main/java/org/elasticsearch/client/IngestClient.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void deletePipelineAsync(DeletePipelineRequest request, RequestOptions op
139139
* @return the response
140140
* @throws IOException in case there is a problem sending the request or parsing back the response
141141
*/
142-
public SimulatePipelineResponse simulatePipeline(SimulatePipelineRequest request, RequestOptions options) throws IOException {
142+
public SimulatePipelineResponse simulate(SimulatePipelineRequest request, RequestOptions options) throws IOException {
143143
return restHighLevelClient.performRequestAndParseEntity( request, RequestConverters::simulatePipeline, options,
144144
SimulatePipelineResponse::fromXContent, emptySet());
145145
}
@@ -154,9 +154,9 @@ public SimulatePipelineResponse simulatePipeline(SimulatePipelineRequest request
154154
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
155155
* @param listener the listener to be notified upon request completion
156156
*/
157-
public void simulatePipelineAsync(SimulatePipelineRequest request,
158-
RequestOptions options,
159-
ActionListener<SimulatePipelineResponse> listener) {
157+
public void simulateAsync(SimulatePipelineRequest request,
158+
RequestOptions options,
159+
ActionListener<SimulatePipelineResponse> listener) {
160160
restHighLevelClient.performRequestAsyncAndParseEntity( request, RequestConverters::simulatePipeline, options,
161161
SimulatePipelineResponse::fromXContent, listener, emptySet());
162162
}

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

+95-7
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,23 @@ public final void getAsync(GetRequest getRequest, RequestOptions options, Action
384384
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
385385
* @return the response
386386
* @throws IOException in case there is a problem sending the request or parsing back the response
387+
* @deprecated use {@link #mget(MultiGetRequest, RequestOptions)} instead
387388
*/
389+
@Deprecated
388390
public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
391+
return mget(multiGetRequest, options);
392+
}
393+
394+
395+
/**
396+
* Retrieves multiple documents by id using the Multi Get API.
397+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
398+
* @param multiGetRequest the request
399+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
400+
* @return the response
401+
* @throws IOException in case there is a problem sending the request or parsing back the response
402+
*/
403+
public final MultiGetResponse mget(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
389404
return performRequestAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent,
390405
singleton(404));
391406
}
@@ -396,8 +411,21 @@ public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, RequestO
396411
* @param multiGetRequest the request
397412
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
398413
* @param listener the listener to be notified upon request completion
414+
* @deprecated use {@link #mgetAsync(MultiGetRequest, RequestOptions, ActionListener)} instead
399415
*/
416+
@Deprecated
400417
public final void multiGetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
418+
mgetAsync(multiGetRequest, options, listener);
419+
}
420+
421+
/**
422+
* Asynchronously retrieves multiple documents by id using the Multi Get API.
423+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
424+
* @param multiGetRequest the request
425+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
426+
* @param listener the listener to be notified upon request completion
427+
*/
428+
public final void mgetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
401429
performRequestAsyncAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent, listener,
402430
singleton(404));
403431
}
@@ -531,8 +559,23 @@ public final void searchAsync(SearchRequest searchRequest, RequestOptions option
531559
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
532560
* @return the response
533561
* @throws IOException in case there is a problem sending the request or parsing back the response
562+
* @deprecated use {@link #msearch(MultiSearchRequest, RequestOptions)} instead
534563
*/
564+
@Deprecated
535565
public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
566+
return msearch(multiSearchRequest, options);
567+
}
568+
569+
/**
570+
* Executes a multi search using the msearch API.
571+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
572+
* elastic.co</a>
573+
* @param multiSearchRequest the request
574+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
575+
* @return the response
576+
* @throws IOException in case there is a problem sending the request or parsing back the response
577+
*/
578+
public final MultiSearchResponse msearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
536579
return performRequestAndParseEntity(multiSearchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
537580
emptySet());
538581
}
@@ -544,9 +587,24 @@ public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchReque
544587
* @param searchRequest the request
545588
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
546589
* @param listener the listener to be notified upon request completion
590+
* @deprecated use {@link #msearchAsync(MultiSearchRequest, RequestOptions, ActionListener)} instead
547591
*/
592+
@Deprecated
548593
public final void multiSearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
549-
ActionListener<MultiSearchResponse> listener) {
594+
ActionListener<MultiSearchResponse> listener) {
595+
msearchAsync(searchRequest, options, listener);
596+
}
597+
598+
/**
599+
* Asynchronously executes a multi search using the msearch API.
600+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
601+
* elastic.co</a>
602+
* @param searchRequest the request
603+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
604+
* @param listener the listener to be notified upon request completion
605+
*/
606+
public final void msearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
607+
ActionListener<MultiSearchResponse> listener) {
550608
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
551609
listener, emptySet());
552610
}
@@ -559,8 +617,23 @@ public final void multiSearchAsync(MultiSearchRequest searchRequest, RequestOpti
559617
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
560618
* @return the response
561619
* @throws IOException in case there is a problem sending the request or parsing back the response
620+
* @deprecated use {@link #scroll(SearchScrollRequest, RequestOptions)} instead
562621
*/
622+
@Deprecated
563623
public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
624+
return scroll(searchScrollRequest, options);
625+
}
626+
627+
/**
628+
* Executes a search using the Search Scroll API.
629+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
630+
* API on elastic.co</a>
631+
* @param searchScrollRequest the request
632+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
633+
* @return the response
634+
* @throws IOException in case there is a problem sending the request or parsing back the response
635+
*/
636+
public final SearchResponse scroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
564637
return performRequestAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
565638
emptySet());
566639
}
@@ -572,9 +645,24 @@ public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest
572645
* @param searchScrollRequest the request
573646
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
574647
* @param listener the listener to be notified upon request completion
648+
* @deprecated use {@link #scrollAsync(SearchScrollRequest, RequestOptions, ActionListener)} instead
575649
*/
650+
@Deprecated
576651
public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
577-
ActionListener<SearchResponse> listener) {
652+
ActionListener<SearchResponse> listener) {
653+
scrollAsync(searchScrollRequest, options, listener);
654+
}
655+
656+
/**
657+
* Asynchronously executes a search using the Search Scroll API.
658+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
659+
* API on elastic.co</a>
660+
* @param searchScrollRequest the request
661+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
662+
* @param listener the listener to be notified upon request completion
663+
*/
664+
public final void scrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
665+
ActionListener<SearchResponse> listener) {
578666
performRequestAsyncAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
579667
listener, emptySet());
580668
}
@@ -691,8 +779,8 @@ public final RankEvalResponse rankEval(RankEvalRequest rankEvalRequest, RequestO
691779
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-search-template.html">Multi Search Template API
692780
* on elastic.co</a>.
693781
*/
694-
public final MultiSearchTemplateResponse multiSearchTemplate(MultiSearchTemplateRequest multiSearchTemplateRequest,
695-
RequestOptions options) throws IOException {
782+
public final MultiSearchTemplateResponse msearchTemplate(MultiSearchTemplateRequest multiSearchTemplateRequest,
783+
RequestOptions options) throws IOException {
696784
return performRequestAndParseEntity(multiSearchTemplateRequest, RequestConverters::multiSearchTemplate,
697785
options, MultiSearchTemplateResponse::fromXContext, emptySet());
698786
}
@@ -703,9 +791,9 @@ public final MultiSearchTemplateResponse multiSearchTemplate(MultiSearchTemplate
703791
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-search-template.html">Multi Search Template API
704792
* on elastic.co</a>.
705793
*/
706-
public final void multiSearchTemplateAsync(MultiSearchTemplateRequest multiSearchTemplateRequest,
707-
RequestOptions options,
708-
ActionListener<MultiSearchTemplateResponse> listener) {
794+
public final void msearchTemplateAsync(MultiSearchTemplateRequest multiSearchTemplateRequest,
795+
RequestOptions options,
796+
ActionListener<MultiSearchTemplateResponse> listener) {
709797
performRequestAsyncAndParseEntity(multiSearchTemplateRequest, RequestConverters::multiSearchTemplate,
710798
options, MultiSearchTemplateResponse::fromXContext, listener, emptySet());
711799
}

0 commit comments

Comments
 (0)