Skip to content

Commit bf610d2

Browse files
committed
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 9f55f03 commit bf610d2

21 files changed

+374
-83
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

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ dependencies {
5252
testCompile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
5353
testCompile "junit:junit:${versions.junit}"
5454
testCompile "org.hamcrest:hamcrest-all:${versions.hamcrest}"
55+
//this is needed to make RestHighLevelClientTests#testApiNamingConventions work from IDEs
56+
testCompile "org.elasticsearch:rest-api-spec:${version}"
5557
}
5658

5759
dependencyLicenses {

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void putMappingAsync(PutMappingRequest putMappingRequest, ActionListener<
254254
* @return the response
255255
* @throws IOException in case there is a problem sending the request or parsing back the response
256256
*/
257-
public GetMappingsResponse getMappings(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
257+
public GetMappingsResponse getMapping(GetMappingsRequest getMappingsRequest, RequestOptions options) throws IOException {
258258
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest, RequestConverters::getMappings, options,
259259
GetMappingsResponse::fromXContent, emptySet());
260260
}
@@ -267,8 +267,8 @@ public GetMappingsResponse getMappings(GetMappingsRequest getMappingsRequest, Re
267267
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
268268
* @param listener the listener to be notified upon request completion
269269
*/
270-
public void getMappingsAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
271-
ActionListener<GetMappingsResponse> listener) {
270+
public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOptions options,
271+
ActionListener<GetMappingsResponse> listener) {
272272
restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest, RequestConverters::getMappings, options,
273273
GetMappingsResponse::fromXContent, listener, emptySet());
274274
}
@@ -709,8 +709,23 @@ public void getAsync(GetIndexRequest getIndexRequest, RequestOptions options,
709709
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
710710
* @return the response
711711
* @throws IOException in case there is a problem sending the request or parsing back the response
712+
* @deprecated use {@link #forcemerge(ForceMergeRequest, RequestOptions)} instead
712713
*/
714+
@Deprecated
713715
public ForceMergeResponse forceMerge(ForceMergeRequest forceMergeRequest, RequestOptions options) throws IOException {
716+
return forcemerge(forceMergeRequest, options);
717+
}
718+
719+
/**
720+
* Force merge one or more indices using the Force Merge API.
721+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
722+
* Force Merge API on elastic.co</a>
723+
* @param forceMergeRequest the request
724+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
725+
* @return the response
726+
* @throws IOException in case there is a problem sending the request or parsing back the response
727+
*/
728+
public ForceMergeResponse forcemerge(ForceMergeRequest forceMergeRequest, RequestOptions options) throws IOException {
714729
return restHighLevelClient.performRequestAndParseEntity(forceMergeRequest, RequestConverters::forceMerge, options,
715730
ForceMergeResponse::fromXContent, emptySet());
716731
}
@@ -735,8 +750,22 @@ public ForceMergeResponse forceMerge(ForceMergeRequest forceMergeRequest, Header
735750
* @param forceMergeRequest the request
736751
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
737752
* @param listener the listener to be notified upon request completion
753+
* @deprecated use {@link #forcemergeAsync(ForceMergeRequest, RequestOptions, ActionListener)} instead
738754
*/
755+
@Deprecated
739756
public void forceMergeAsync(ForceMergeRequest forceMergeRequest, RequestOptions options, ActionListener<ForceMergeResponse> listener) {
757+
forcemergeAsync(forceMergeRequest, options, listener);
758+
}
759+
760+
/**
761+
* Asynchronously force merge one or more indices using the Force Merge API.
762+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
763+
* Force Merge API on elastic.co</a>
764+
* @param forceMergeRequest the request
765+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
766+
* @param listener the listener to be notified upon request completion
767+
*/
768+
public void forcemergeAsync(ForceMergeRequest forceMergeRequest, RequestOptions options, ActionListener<ForceMergeResponse> listener) {
740769
restHighLevelClient.performRequestAsyncAndParseEntity(forceMergeRequest, RequestConverters::forceMerge, options,
741770
ForceMergeResponse::fromXContent, listener, emptySet());
742771
}

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
@@ -447,8 +447,23 @@ public final void getAsync(GetRequest getRequest, ActionListener<GetResponse> li
447447
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
448448
* @return the response
449449
* @throws IOException in case there is a problem sending the request or parsing back the response
450+
* @deprecated use {@link #mget(MultiGetRequest, RequestOptions)} instead
450451
*/
452+
@Deprecated
451453
public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
454+
return mget(multiGetRequest, options);
455+
}
456+
457+
458+
/**
459+
* Retrieves multiple documents by id using the Multi Get API.
460+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
461+
* @param multiGetRequest the request
462+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
463+
* @return the response
464+
* @throws IOException in case there is a problem sending the request or parsing back the response
465+
*/
466+
public final MultiGetResponse mget(MultiGetRequest multiGetRequest, RequestOptions options) throws IOException {
452467
return performRequestAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent,
453468
singleton(404));
454469
}
@@ -471,8 +486,21 @@ public final MultiGetResponse multiGet(MultiGetRequest multiGetRequest, Header..
471486
* @param multiGetRequest the request
472487
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
473488
* @param listener the listener to be notified upon request completion
489+
* @deprecated use {@link #mgetAsync(MultiGetRequest, RequestOptions, ActionListener)} instead
474490
*/
491+
@Deprecated
475492
public final void multiGetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
493+
mgetAsync(multiGetRequest, options, listener);
494+
}
495+
496+
/**
497+
* Asynchronously retrieves multiple documents by id using the Multi Get API.
498+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html">Multi Get API on elastic.co</a>
499+
* @param multiGetRequest the request
500+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
501+
* @param listener the listener to be notified upon request completion
502+
*/
503+
public final void mgetAsync(MultiGetRequest multiGetRequest, RequestOptions options, ActionListener<MultiGetResponse> listener) {
476504
performRequestAsyncAndParseEntity(multiGetRequest, RequestConverters::multiGet, options, MultiGetResponse::fromXContent, listener,
477505
singleton(404));
478506
}
@@ -734,8 +762,23 @@ public final void searchAsync(SearchRequest searchRequest, ActionListener<Search
734762
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
735763
* @return the response
736764
* @throws IOException in case there is a problem sending the request or parsing back the response
765+
* @deprecated use {@link #msearch(MultiSearchRequest, RequestOptions)} instead
737766
*/
767+
@Deprecated
738768
public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
769+
return msearch(multiSearchRequest, options);
770+
}
771+
772+
/**
773+
* Executes a multi search using the msearch API.
774+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
775+
* elastic.co</a>
776+
* @param multiSearchRequest the request
777+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
778+
* @return the response
779+
* @throws IOException in case there is a problem sending the request or parsing back the response
780+
*/
781+
public final MultiSearchResponse msearch(MultiSearchRequest multiSearchRequest, RequestOptions options) throws IOException {
739782
return performRequestAndParseEntity(multiSearchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
740783
emptySet());
741784
}
@@ -760,9 +803,24 @@ public final MultiSearchResponse multiSearch(MultiSearchRequest multiSearchReque
760803
* @param searchRequest the request
761804
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
762805
* @param listener the listener to be notified upon request completion
806+
* @deprecated use {@link #msearchAsync(MultiSearchRequest, RequestOptions, ActionListener)} instead
763807
*/
808+
@Deprecated
764809
public final void multiSearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
765-
ActionListener<MultiSearchResponse> listener) {
810+
ActionListener<MultiSearchResponse> listener) {
811+
msearchAsync(searchRequest, options, listener);
812+
}
813+
814+
/**
815+
* Asynchronously executes a multi search using the msearch API.
816+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html">Multi search API on
817+
* elastic.co</a>
818+
* @param searchRequest the request
819+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
820+
* @param listener the listener to be notified upon request completion
821+
*/
822+
public final void msearchAsync(MultiSearchRequest searchRequest, RequestOptions options,
823+
ActionListener<MultiSearchResponse> listener) {
766824
performRequestAsyncAndParseEntity(searchRequest, RequestConverters::multiSearch, options, MultiSearchResponse::fromXContext,
767825
listener, emptySet());
768826
}
@@ -788,8 +846,23 @@ public final void multiSearchAsync(MultiSearchRequest searchRequest, ActionListe
788846
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
789847
* @return the response
790848
* @throws IOException in case there is a problem sending the request or parsing back the response
849+
* @deprecated use {@link #scroll(SearchScrollRequest, RequestOptions)} instead
791850
*/
851+
@Deprecated
792852
public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
853+
return scroll(searchScrollRequest, options);
854+
}
855+
856+
/**
857+
* Executes a search using the Search Scroll API.
858+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
859+
* API on elastic.co</a>
860+
* @param searchScrollRequest the request
861+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
862+
* @return the response
863+
* @throws IOException in case there is a problem sending the request or parsing back the response
864+
*/
865+
public final SearchResponse scroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
793866
return performRequestAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
794867
emptySet());
795868
}
@@ -814,9 +887,24 @@ public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest
814887
* @param searchScrollRequest the request
815888
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
816889
* @param listener the listener to be notified upon request completion
890+
* @deprecated use {@link #scrollAsync(SearchScrollRequest, RequestOptions, ActionListener)} instead
817891
*/
892+
@Deprecated
818893
public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
819-
ActionListener<SearchResponse> listener) {
894+
ActionListener<SearchResponse> listener) {
895+
scrollAsync(searchScrollRequest, options, listener);
896+
}
897+
898+
/**
899+
* Asynchronously executes a search using the Search Scroll API.
900+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html">Search Scroll
901+
* API on elastic.co</a>
902+
* @param searchScrollRequest the request
903+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
904+
* @param listener the listener to be notified upon request completion
905+
*/
906+
public final void scrollAsync(SearchScrollRequest searchScrollRequest, RequestOptions options,
907+
ActionListener<SearchResponse> listener) {
820908
performRequestAsyncAndParseEntity(searchScrollRequest, RequestConverters::searchScroll, options, SearchResponse::fromXContent,
821909
listener, emptySet());
822910
}
@@ -999,8 +1087,8 @@ public final void rankEvalAsync(RankEvalRequest rankEvalRequest, RequestOptions
9991087
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-search-template.html">Multi Search Template API
10001088
* on elastic.co</a>.
10011089
*/
1002-
public final MultiSearchTemplateResponse multiSearchTemplate(MultiSearchTemplateRequest multiSearchTemplateRequest,
1003-
RequestOptions options) throws IOException {
1090+
public final MultiSearchTemplateResponse msearchTemplate(MultiSearchTemplateRequest multiSearchTemplateRequest,
1091+
RequestOptions options) throws IOException {
10041092
return performRequestAndParseEntity(multiSearchTemplateRequest, RequestConverters::multiSearchTemplate,
10051093
options, MultiSearchTemplateResponse::fromXContext, emptySet());
10061094
}
@@ -1011,9 +1099,9 @@ public final MultiSearchTemplateResponse multiSearchTemplate(MultiSearchTemplate
10111099
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-search-template.html">Multi Search Template API
10121100
* on elastic.co</a>.
10131101
*/
1014-
public final void multiSearchTemplateAsync(MultiSearchTemplateRequest multiSearchTemplateRequest,
1015-
RequestOptions options,
1016-
ActionListener<MultiSearchTemplateResponse> listener) {
1102+
public final void msearchTemplateAsync(MultiSearchTemplateRequest multiSearchTemplateRequest,
1103+
RequestOptions options,
1104+
ActionListener<MultiSearchTemplateResponse> listener) {
10171105
performRequestAsyncAndParseEntity(multiSearchTemplateRequest, RequestConverters::multiSearchTemplate,
10181106
options, MultiSearchTemplateResponse::fromXContext, listener, emptySet());
10191107
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public final class SnapshotClient {
6161
* @return the response
6262
* @throws IOException in case there is a problem sending the request or parsing back the response
6363
*/
64-
public GetRepositoriesResponse getRepositories(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options)
64+
public GetRepositoriesResponse getRepository(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options)
6565
throws IOException {
6666
return restHighLevelClient.performRequestAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories, options,
6767
GetRepositoriesResponse::fromXContent, emptySet());
@@ -76,8 +76,8 @@ public GetRepositoriesResponse getRepositories(GetRepositoriesRequest getReposit
7676
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
7777
* @param listener the listener to be notified upon request completion
7878
*/
79-
public void getRepositoriesAsync(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options,
80-
ActionListener<GetRepositoriesResponse> listener) {
79+
public void getRepositoryAsync(GetRepositoriesRequest getRepositoriesRequest, RequestOptions options,
80+
ActionListener<GetRepositoriesResponse> listener) {
8181
restHighLevelClient.performRequestAsyncAndParseEntity(getRepositoriesRequest, RequestConverters::getRepositories, options,
8282
GetRepositoriesResponse::fromXContent, listener, emptySet());
8383
}

0 commit comments

Comments
 (0)