From 126e3c319f4854e529fd8f6285e4ea98d1e25038 Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 2 Nov 2017 19:07:20 +0100 Subject: [PATCH 1/3] Adjust RestHighLevelClient method modifiers RestHighLevelClient can be subclassed to add support for additional methods, but its public and protected method should be final. Also some methods were protected but they can be just package private for testing purposes, they don't need to be accessed directly by subclasses. --- .../client/RestHighLevelClient.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index bc3538930d3d0..a0ce5a8ef531f 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -227,7 +227,7 @@ public final void close() throws IOException { * * See Indices API on elastic.co */ - public IndicesClient indices() { + public final IndicesClient indices() { return indicesClient; } @@ -236,7 +236,7 @@ public IndicesClient indices() { * * See Bulk API on elastic.co */ - public BulkResponse bulk(BulkRequest bulkRequest, Header... headers) throws IOException { + public final BulkResponse bulk(BulkRequest bulkRequest, Header... headers) throws IOException { return performRequestAndParseEntity(bulkRequest, Request::bulk, BulkResponse::fromXContent, emptySet(), headers); } @@ -245,14 +245,14 @@ public BulkResponse bulk(BulkRequest bulkRequest, Header... headers) throws IOEx * * See Bulk API on elastic.co */ - public void bulkAsync(BulkRequest bulkRequest, ActionListener listener, Header... headers) { + public final void bulkAsync(BulkRequest bulkRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(bulkRequest, Request::bulk, BulkResponse::fromXContent, listener, emptySet(), headers); } /** * Pings the remote Elasticsearch cluster and returns true if the ping succeeded, false otherwise */ - public boolean ping(Header... headers) throws IOException { + public final boolean ping(Header... headers) throws IOException { return performRequest(new MainRequest(), (request) -> Request.ping(), RestHighLevelClient::convertExistsResponse, emptySet(), headers); } @@ -260,7 +260,7 @@ public boolean ping(Header... headers) throws IOException { /** * Get the cluster info otherwise provided when sending an HTTP request to port 9200 */ - public MainResponse info(Header... headers) throws IOException { + public final MainResponse info(Header... headers) throws IOException { return performRequestAndParseEntity(new MainRequest(), (request) -> Request.info(), MainResponse::fromXContent, emptySet(), headers); } @@ -270,7 +270,7 @@ public MainResponse info(Header... headers) throws IOException { * * See Get API on elastic.co */ - public GetResponse get(GetRequest getRequest, Header... headers) throws IOException { + public final GetResponse get(GetRequest getRequest, Header... headers) throws IOException { return performRequestAndParseEntity(getRequest, Request::get, GetResponse::fromXContent, singleton(404), headers); } @@ -288,7 +288,7 @@ public void getAsync(GetRequest getRequest, ActionListener listener * * See Get API on elastic.co */ - public boolean exists(GetRequest getRequest, Header... headers) throws IOException { + public final boolean exists(GetRequest getRequest, Header... headers) throws IOException { return performRequest(getRequest, Request::exists, RestHighLevelClient::convertExistsResponse, emptySet(), headers); } @@ -297,7 +297,7 @@ public boolean exists(GetRequest getRequest, Header... headers) throws IOExcepti * * See Get API on elastic.co */ - public void existsAsync(GetRequest getRequest, ActionListener listener, Header... headers) { + public final void existsAsync(GetRequest getRequest, ActionListener listener, Header... headers) { performRequestAsync(getRequest, Request::exists, RestHighLevelClient::convertExistsResponse, listener, emptySet(), headers); } @@ -306,7 +306,7 @@ public void existsAsync(GetRequest getRequest, ActionListener listener, * * See Index API on elastic.co */ - public IndexResponse index(IndexRequest indexRequest, Header... headers) throws IOException { + public final IndexResponse index(IndexRequest indexRequest, Header... headers) throws IOException { return performRequestAndParseEntity(indexRequest, Request::index, IndexResponse::fromXContent, emptySet(), headers); } @@ -315,7 +315,7 @@ public IndexResponse index(IndexRequest indexRequest, Header... headers) throws * * See Index API on elastic.co */ - public void indexAsync(IndexRequest indexRequest, ActionListener listener, Header... headers) { + public final void indexAsync(IndexRequest indexRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(indexRequest, Request::index, IndexResponse::fromXContent, listener, emptySet(), headers); } @@ -324,7 +324,7 @@ public void indexAsync(IndexRequest indexRequest, ActionListener *

* See Update API on elastic.co */ - public UpdateResponse update(UpdateRequest updateRequest, Header... headers) throws IOException { + public final UpdateResponse update(UpdateRequest updateRequest, Header... headers) throws IOException { return performRequestAndParseEntity(updateRequest, Request::update, UpdateResponse::fromXContent, emptySet(), headers); } @@ -333,7 +333,7 @@ public UpdateResponse update(UpdateRequest updateRequest, Header... headers) thr *

* See Update API on elastic.co */ - public void updateAsync(UpdateRequest updateRequest, ActionListener listener, Header... headers) { + public final void updateAsync(UpdateRequest updateRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(updateRequest, Request::update, UpdateResponse::fromXContent, listener, emptySet(), headers); } @@ -342,7 +342,7 @@ public void updateAsync(UpdateRequest updateRequest, ActionListenerDelete API on elastic.co */ - public DeleteResponse delete(DeleteRequest deleteRequest, Header... headers) throws IOException { + public final DeleteResponse delete(DeleteRequest deleteRequest, Header... headers) throws IOException { return performRequestAndParseEntity(deleteRequest, Request::delete, DeleteResponse::fromXContent, Collections.singleton(404), headers); } @@ -352,7 +352,7 @@ public DeleteResponse delete(DeleteRequest deleteRequest, Header... headers) thr * * See Delete API on elastic.co */ - public void deleteAsync(DeleteRequest deleteRequest, ActionListener listener, Header... headers) { + public final void deleteAsync(DeleteRequest deleteRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(deleteRequest, Request::delete, DeleteResponse::fromXContent, listener, Collections.singleton(404), headers); } @@ -362,7 +362,7 @@ public void deleteAsync(DeleteRequest deleteRequest, ActionListenerSearch API on elastic.co */ - public SearchResponse search(SearchRequest searchRequest, Header... headers) throws IOException { + public final SearchResponse search(SearchRequest searchRequest, Header... headers) throws IOException { return performRequestAndParseEntity(searchRequest, Request::search, SearchResponse::fromXContent, emptySet(), headers); } @@ -371,7 +371,7 @@ public SearchResponse search(SearchRequest searchRequest, Header... headers) thr * * See Search API on elastic.co */ - public void searchAsync(SearchRequest searchRequest, ActionListener listener, Header... headers) { + public final void searchAsync(SearchRequest searchRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(searchRequest, Request::search, SearchResponse::fromXContent, listener, emptySet(), headers); } @@ -381,7 +381,7 @@ public void searchAsync(SearchRequest searchRequest, ActionListenerSearch Scroll * API on elastic.co */ - public SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, Header... headers) throws IOException { + public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, Header... headers) throws IOException { return performRequestAndParseEntity(searchScrollRequest, Request::searchScroll, SearchResponse::fromXContent, emptySet(), headers); } @@ -391,7 +391,7 @@ public SearchResponse searchScroll(SearchScrollRequest searchScrollRequest, Head * See Search Scroll * API on elastic.co */ - public void searchScrollAsync(SearchScrollRequest searchScrollRequest, ActionListener listener, Header... headers) { + public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(searchScrollRequest, Request::searchScroll, SearchResponse::fromXContent, listener, emptySet(), headers); } @@ -402,7 +402,7 @@ public void searchScrollAsync(SearchScrollRequest searchScrollRequest, ActionLis * See * Clear Scroll API on elastic.co */ - public ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, Header... headers) throws IOException { + public final ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, Header... headers) throws IOException { return performRequestAndParseEntity(clearScrollRequest, Request::clearScroll, ClearScrollResponse::fromXContent, emptySet(), headers); } @@ -413,19 +413,19 @@ public ClearScrollResponse clearScroll(ClearScrollRequest clearScrollRequest, He * See * Clear Scroll API on elastic.co */ - public void clearScrollAsync(ClearScrollRequest clearScrollRequest, ActionListener listener, Header... headers) { + public final void clearScrollAsync(ClearScrollRequest clearScrollRequest, ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(clearScrollRequest, Request::clearScroll, ClearScrollResponse::fromXContent, listener, emptySet(), headers); } - protected Resp performRequestAndParseEntity(Req request, + protected final Resp performRequestAndParseEntity(Req request, CheckedFunction requestConverter, CheckedFunction entityParser, Set ignores, Header... headers) throws IOException { return performRequest(request, requestConverter, (response) -> parseEntity(response.getEntity(), entityParser), ignores, headers); } - protected Resp performRequest(Req request, + protected final Resp performRequest(Req request, CheckedFunction requestConverter, CheckedFunction responseConverter, Set ignores, Header... headers) throws IOException { @@ -459,7 +459,7 @@ protected Resp performRequest(Req request, } } - protected void performRequestAsyncAndParseEntity(Req request, + protected final void performRequestAsyncAndParseEntity(Req request, CheckedFunction requestConverter, CheckedFunction entityParser, ActionListener listener, Set ignores, Header... headers) { @@ -467,7 +467,7 @@ protected void performRequestAsyncAndParseEnti listener, ignores, headers); } - protected void performRequestAsync(Req request, + protected final void performRequestAsync(Req request, CheckedFunction requestConverter, CheckedFunction responseConverter, ActionListener listener, Set ignores, Header... headers) { @@ -488,7 +488,7 @@ protected void performRequestAsync(Req request client.performRequestAsync(req.getMethod(), req.getEndpoint(), req.getParameters(), req.getEntity(), responseListener, headers); } - ResponseListener wrapResponseListener(CheckedFunction responseConverter, + final ResponseListener wrapResponseListener(CheckedFunction responseConverter, ActionListener actionListener, Set ignores) { return new ResponseListener() { @Override @@ -533,7 +533,7 @@ public void onFailure(Exception exception) { * that wraps the original {@link ResponseException}. The potential exception obtained while parsing is added to the returned * exception as a suppressed exception. This method is guaranteed to not throw any exception eventually thrown while parsing. */ - protected ElasticsearchStatusException parseResponseException(ResponseException responseException) { + final ElasticsearchStatusException parseResponseException(ResponseException responseException) { Response response = responseException.getResponse(); HttpEntity entity = response.getEntity(); ElasticsearchStatusException elasticsearchException; @@ -553,7 +553,7 @@ protected ElasticsearchStatusException parseResponseException(ResponseException return elasticsearchException; } - protected Resp parseEntity(final HttpEntity entity, + final Resp parseEntity(final HttpEntity entity, final CheckedFunction entityParser) throws IOException { if (entity == null) { throw new IllegalStateException("Response body expected but not returned"); From 99bd065d9fcdd5532a65acc28e3bcad8a3d6c253 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 3 Nov 2017 11:32:00 +0100 Subject: [PATCH 2/3] fix checkstyle issues --- .../java/org/elasticsearch/client/RestHighLevelClient.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index a0ce5a8ef531f..630cc08b22f0b 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -391,7 +391,8 @@ public final SearchResponse searchScroll(SearchScrollRequest searchScrollRequest * See Search Scroll * API on elastic.co */ - public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, ActionListener listener, Header... headers) { + public final void searchScrollAsync(SearchScrollRequest searchScrollRequest, + ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(searchScrollRequest, Request::searchScroll, SearchResponse::fromXContent, listener, emptySet(), headers); } @@ -413,7 +414,8 @@ public final ClearScrollResponse clearScroll(ClearScrollRequest clearScrollReque * See * Clear Scroll API on elastic.co */ - public final void clearScrollAsync(ClearScrollRequest clearScrollRequest, ActionListener listener, Header... headers) { + public final void clearScrollAsync(ClearScrollRequest clearScrollRequest, + ActionListener listener, Header... headers) { performRequestAsyncAndParseEntity(clearScrollRequest, Request::clearScroll, ClearScrollResponse::fromXContent, listener, emptySet(), headers); } From b83c479a16412cc31695d0df82bb92af6a78e023 Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 3 Nov 2017 16:02:32 +0100 Subject: [PATCH 3/3] fix test failure --- .../java/org/elasticsearch/client/RestHighLevelClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 630cc08b22f0b..e4827cf31c00d 100755 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -535,7 +535,7 @@ public void onFailure(Exception exception) { * that wraps the original {@link ResponseException}. The potential exception obtained while parsing is added to the returned * exception as a suppressed exception. This method is guaranteed to not throw any exception eventually thrown while parsing. */ - final ElasticsearchStatusException parseResponseException(ResponseException responseException) { + protected final ElasticsearchStatusException parseResponseException(ResponseException responseException) { Response response = responseException.getResponse(); HttpEntity entity = response.getEntity(); ElasticsearchStatusException elasticsearchException; @@ -555,7 +555,7 @@ final ElasticsearchStatusException parseResponseException(ResponseException resp return elasticsearchException; } - final Resp parseEntity(final HttpEntity entity, + protected final Resp parseEntity(final HttpEntity entity, final CheckedFunction entityParser) throws IOException { if (entity == null) { throw new IllegalStateException("Response body expected but not returned");