Skip to content

Commit f28cddf

Browse files
authored
LLREST: Drop deprecated methods (#33223)
In #29623 we added `Request` object flavored requests to the low level REST client and in #30315 we deprecated the old `performRequest`s. In a long series of PRs I've changed all of the old style requests. This drops the deprecated methods and will be released with 7.0.
1 parent ce635f5 commit f28cddf

File tree

6 files changed

+32
-520
lines changed

6 files changed

+32
-520
lines changed

client/rest/src/main/java/org/elasticsearch/client/RestClient.java

+1-278
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
* The hosts that are part of the cluster need to be provided at creation time, but can also be replaced later
8686
* by calling {@link #setNodes(Collection)}.
8787
* <p>
88-
* The method {@link #performRequest(String, String, Map, HttpEntity, Header...)} allows to send a request to the cluster. When
88+
* The method {@link #performRequest(Request)} allows to send a request to the cluster. When
8989
* sending a request, a host gets selected out of the provided ones in a round-robin fashion. Failing hosts are marked dead and
9090
* retried after a certain amount of time (minimum 1 minute, maximum 30 minutes), depending on how many times they previously
9191
* failed (the more failures, the later they will be retried). In case of failures all of the alive nodes (or dead nodes that
@@ -145,17 +145,6 @@ public static RestClientBuilder builder(HttpHost... hosts) {
145145
return new RestClientBuilder(hostsToNodes(hosts));
146146
}
147147

148-
/**
149-
* Replaces the hosts with which the client communicates.
150-
*
151-
* @deprecated prefer {@link #setNodes(Collection)} because it allows you
152-
* to set metadata for use with {@link NodeSelector}s
153-
*/
154-
@Deprecated
155-
public void setHosts(HttpHost... hosts) {
156-
setNodes(hostsToNodes(hosts));
157-
}
158-
159148
/**
160149
* Replaces the nodes with which the client communicates.
161150
*/
@@ -251,234 +240,6 @@ public void performRequestAsync(Request request, ResponseListener responseListen
251240
}
252241
}
253242

254-
/**
255-
* Sends a request to the Elasticsearch cluster that the client points to and waits for the corresponding response
256-
* to be returned. Shortcut to {@link #performRequest(String, String, Map, HttpEntity, Header...)} but without parameters
257-
* and request body.
258-
*
259-
* @param method the http method
260-
* @param endpoint the path of the request (without host and port)
261-
* @param headers the optional request headers
262-
* @return the response returned by Elasticsearch
263-
* @throws IOException in case of a problem or the connection was aborted
264-
* @throws ClientProtocolException in case of an http protocol error
265-
* @throws ResponseException in case Elasticsearch responded with a status code that indicated an error
266-
* @deprecated prefer {@link #performRequest(Request)}
267-
*/
268-
@Deprecated
269-
public Response performRequest(String method, String endpoint, Header... headers) throws IOException {
270-
Request request = new Request(method, endpoint);
271-
addHeaders(request, headers);
272-
return performRequest(request);
273-
}
274-
275-
/**
276-
* Sends a request to the Elasticsearch cluster that the client points to and waits for the corresponding response
277-
* to be returned. Shortcut to {@link #performRequest(String, String, Map, HttpEntity, Header...)} but without request body.
278-
*
279-
* @param method the http method
280-
* @param endpoint the path of the request (without host and port)
281-
* @param params the query_string parameters
282-
* @param headers the optional request headers
283-
* @return the response returned by Elasticsearch
284-
* @throws IOException in case of a problem or the connection was aborted
285-
* @throws ClientProtocolException in case of an http protocol error
286-
* @throws ResponseException in case Elasticsearch responded with a status code that indicated an error
287-
* @deprecated prefer {@link #performRequest(Request)}
288-
*/
289-
@Deprecated
290-
public Response performRequest(String method, String endpoint, Map<String, String> params, Header... headers) throws IOException {
291-
Request request = new Request(method, endpoint);
292-
addParameters(request, params);
293-
addHeaders(request, headers);
294-
return performRequest(request);
295-
}
296-
297-
/**
298-
* Sends a request to the Elasticsearch cluster that the client points to and waits for the corresponding response
299-
* to be returned. Shortcut to {@link #performRequest(String, String, Map, HttpEntity, HttpAsyncResponseConsumerFactory, Header...)}
300-
* which doesn't require specifying an {@link HttpAsyncResponseConsumerFactory} instance,
301-
* {@link HttpAsyncResponseConsumerFactory} will be used to create the needed instances of {@link HttpAsyncResponseConsumer}.
302-
*
303-
* @param method the http method
304-
* @param endpoint the path of the request (without host and port)
305-
* @param params the query_string parameters
306-
* @param entity the body of the request, null if not applicable
307-
* @param headers the optional request headers
308-
* @return the response returned by Elasticsearch
309-
* @throws IOException in case of a problem or the connection was aborted
310-
* @throws ClientProtocolException in case of an http protocol error
311-
* @throws ResponseException in case Elasticsearch responded with a status code that indicated an error
312-
* @deprecated prefer {@link #performRequest(Request)}
313-
*/
314-
@Deprecated
315-
public Response performRequest(String method, String endpoint, Map<String, String> params,
316-
HttpEntity entity, Header... headers) throws IOException {
317-
Request request = new Request(method, endpoint);
318-
addParameters(request, params);
319-
request.setEntity(entity);
320-
addHeaders(request, headers);
321-
return performRequest(request);
322-
}
323-
324-
/**
325-
* Sends a request to the Elasticsearch cluster that the client points to. Blocks until the request is completed and returns
326-
* its response or fails by throwing an exception. Selects a host out of the provided ones in a round-robin fashion. Failing hosts
327-
* are marked dead and retried after a certain amount of time (minimum 1 minute, maximum 30 minutes), depending on how many times
328-
* they previously failed (the more failures, the later they will be retried). In case of failures all of the alive nodes (or dead
329-
* nodes that deserve a retry) are retried until one responds or none of them does, in which case an {@link IOException} will be thrown.
330-
*
331-
* This method works by performing an asynchronous call and waiting
332-
* for the result. If the asynchronous call throws an exception we wrap
333-
* it and rethrow it so that the stack trace attached to the exception
334-
* contains the call site. While we attempt to preserve the original
335-
* exception this isn't always possible and likely haven't covered all of
336-
* the cases. You can get the original exception from
337-
* {@link Exception#getCause()}.
338-
*
339-
* @param method the http method
340-
* @param endpoint the path of the request (without host and port)
341-
* @param params the query_string parameters
342-
* @param entity the body of the request, null if not applicable
343-
* @param httpAsyncResponseConsumerFactory the {@link HttpAsyncResponseConsumerFactory} used to create one
344-
* {@link HttpAsyncResponseConsumer} callback per retry. Controls how the response body gets streamed from a non-blocking HTTP
345-
* connection on the client side.
346-
* @param headers the optional request headers
347-
* @return the response returned by Elasticsearch
348-
* @throws IOException in case of a problem or the connection was aborted
349-
* @throws ClientProtocolException in case of an http protocol error
350-
* @throws ResponseException in case Elasticsearch responded with a status code that indicated an error
351-
* @deprecated prefer {@link #performRequest(Request)}
352-
*/
353-
@Deprecated
354-
public Response performRequest(String method, String endpoint, Map<String, String> params,
355-
HttpEntity entity, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory,
356-
Header... headers) throws IOException {
357-
Request request = new Request(method, endpoint);
358-
addParameters(request, params);
359-
request.setEntity(entity);
360-
setOptions(request, httpAsyncResponseConsumerFactory, headers);
361-
return performRequest(request);
362-
}
363-
364-
/**
365-
* Sends a request to the Elasticsearch cluster that the client points to. Doesn't wait for the response, instead
366-
* the provided {@link ResponseListener} will be notified upon completion or failure. Shortcut to
367-
* {@link #performRequestAsync(String, String, Map, HttpEntity, ResponseListener, Header...)} but without parameters and request body.
368-
*
369-
* @param method the http method
370-
* @param endpoint the path of the request (without host and port)
371-
* @param responseListener the {@link ResponseListener} to notify when the request is completed or fails
372-
* @param headers the optional request headers
373-
* @deprecated prefer {@link #performRequestAsync(Request, ResponseListener)}
374-
*/
375-
@Deprecated
376-
public void performRequestAsync(String method, String endpoint, ResponseListener responseListener, Header... headers) {
377-
Request request;
378-
try {
379-
request = new Request(method, endpoint);
380-
addHeaders(request, headers);
381-
} catch (Exception e) {
382-
responseListener.onFailure(e);
383-
return;
384-
}
385-
performRequestAsync(request, responseListener);
386-
}
387-
388-
/**
389-
* Sends a request to the Elasticsearch cluster that the client points to. Doesn't wait for the response, instead
390-
* the provided {@link ResponseListener} will be notified upon completion or failure. Shortcut to
391-
* {@link #performRequestAsync(String, String, Map, HttpEntity, ResponseListener, Header...)} but without request body.
392-
*
393-
* @param method the http method
394-
* @param endpoint the path of the request (without host and port)
395-
* @param params the query_string parameters
396-
* @param responseListener the {@link ResponseListener} to notify when the request is completed or fails
397-
* @param headers the optional request headers
398-
* @deprecated prefer {@link #performRequestAsync(Request, ResponseListener)}
399-
*/
400-
@Deprecated
401-
public void performRequestAsync(String method, String endpoint, Map<String, String> params,
402-
ResponseListener responseListener, Header... headers) {
403-
Request request;
404-
try {
405-
request = new Request(method, endpoint);
406-
addParameters(request, params);
407-
addHeaders(request, headers);
408-
} catch (Exception e) {
409-
responseListener.onFailure(e);
410-
return;
411-
}
412-
performRequestAsync(request, responseListener);
413-
}
414-
415-
/**
416-
* Sends a request to the Elasticsearch cluster that the client points to. Doesn't wait for the response, instead
417-
* the provided {@link ResponseListener} will be notified upon completion or failure.
418-
* Shortcut to {@link #performRequestAsync(String, String, Map, HttpEntity, HttpAsyncResponseConsumerFactory, ResponseListener,
419-
* Header...)} which doesn't require specifying an {@link HttpAsyncResponseConsumerFactory} instance,
420-
* {@link HttpAsyncResponseConsumerFactory} will be used to create the needed instances of {@link HttpAsyncResponseConsumer}.
421-
*
422-
* @param method the http method
423-
* @param endpoint the path of the request (without host and port)
424-
* @param params the query_string parameters
425-
* @param entity the body of the request, null if not applicable
426-
* @param responseListener the {@link ResponseListener} to notify when the request is completed or fails
427-
* @param headers the optional request headers
428-
* @deprecated prefer {@link #performRequestAsync(Request, ResponseListener)}
429-
*/
430-
@Deprecated
431-
public void performRequestAsync(String method, String endpoint, Map<String, String> params,
432-
HttpEntity entity, ResponseListener responseListener, Header... headers) {
433-
Request request;
434-
try {
435-
request = new Request(method, endpoint);
436-
addParameters(request, params);
437-
request.setEntity(entity);
438-
addHeaders(request, headers);
439-
} catch (Exception e) {
440-
responseListener.onFailure(e);
441-
return;
442-
}
443-
performRequestAsync(request, responseListener);
444-
}
445-
446-
/**
447-
* Sends a request to the Elasticsearch cluster that the client points to. The request is executed asynchronously
448-
* and the provided {@link ResponseListener} gets notified upon request completion or failure.
449-
* Selects a host out of the provided ones in a round-robin fashion. Failing hosts are marked dead and retried after a certain
450-
* amount of time (minimum 1 minute, maximum 30 minutes), depending on how many times they previously failed (the more failures,
451-
* the later they will be retried). In case of failures all of the alive nodes (or dead nodes that deserve a retry) are retried
452-
* until one responds or none of them does, in which case an {@link IOException} will be thrown.
453-
*
454-
* @param method the http method
455-
* @param endpoint the path of the request (without host and port)
456-
* @param params the query_string parameters
457-
* @param entity the body of the request, null if not applicable
458-
* @param httpAsyncResponseConsumerFactory the {@link HttpAsyncResponseConsumerFactory} used to create one
459-
* {@link HttpAsyncResponseConsumer} callback per retry. Controls how the response body gets streamed from a non-blocking HTTP
460-
* connection on the client side.
461-
* @param responseListener the {@link ResponseListener} to notify when the request is completed or fails
462-
* @param headers the optional request headers
463-
* @deprecated prefer {@link #performRequestAsync(Request, ResponseListener)}
464-
*/
465-
@Deprecated
466-
public void performRequestAsync(String method, String endpoint, Map<String, String> params,
467-
HttpEntity entity, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory,
468-
ResponseListener responseListener, Header... headers) {
469-
Request request;
470-
try {
471-
request = new Request(method, endpoint);
472-
addParameters(request, params);
473-
request.setEntity(entity);
474-
setOptions(request, httpAsyncResponseConsumerFactory, headers);
475-
} catch (Exception e) {
476-
responseListener.onFailure(e);
477-
return;
478-
}
479-
performRequestAsync(request, responseListener);
480-
}
481-
482243
void performRequestAsyncNoCatch(Request request, ResponseListener listener) throws IOException {
483244
Map<String, String> requestParams = new HashMap<>(request.getParameters());
484245
//ignore is a special parameter supported by the clients, shouldn't be sent to es
@@ -1035,42 +796,4 @@ public void remove() {
1035796
itr.remove();
1036797
}
1037798
}
1038-
1039-
/**
1040-
* Add all headers from the provided varargs argument to a {@link Request}. This only exists
1041-
* to support methods that exist for backwards compatibility.
1042-
*/
1043-
@Deprecated
1044-
private static void addHeaders(Request request, Header... headers) {
1045-
setOptions(request, RequestOptions.DEFAULT.getHttpAsyncResponseConsumerFactory(), headers);
1046-
}
1047-
1048-
/**
1049-
* Add all headers from the provided varargs argument to a {@link Request}. This only exists
1050-
* to support methods that exist for backwards compatibility.
1051-
*/
1052-
@Deprecated
1053-
private static void setOptions(Request request, HttpAsyncResponseConsumerFactory httpAsyncResponseConsumerFactory,
1054-
Header... headers) {
1055-
Objects.requireNonNull(headers, "headers cannot be null");
1056-
RequestOptions.Builder options = request.getOptions().toBuilder();
1057-
for (Header header : headers) {
1058-
Objects.requireNonNull(header, "header cannot be null");
1059-
options.addHeader(header.getName(), header.getValue());
1060-
}
1061-
options.setHttpAsyncResponseConsumerFactory(httpAsyncResponseConsumerFactory);
1062-
request.setOptions(options);
1063-
}
1064-
1065-
/**
1066-
* Add all parameters from a map to a {@link Request}. This only exists
1067-
* to support methods that exist for backwards compatibility.
1068-
*/
1069-
@Deprecated
1070-
private static void addParameters(Request request, Map<String, String> parameters) {
1071-
Objects.requireNonNull(parameters, "parameters cannot be null");
1072-
for (Map.Entry<String, String> entry : parameters.entrySet()) {
1073-
request.addParameter(entry.getKey(), entry.getValue());
1074-
}
1075-
}
1076799
}

client/rest/src/test/java/org/elasticsearch/client/RestClientSingleHostIntegTests.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.net.InetAddress;
4646
import java.net.InetSocketAddress;
4747
import java.util.Arrays;
48-
import java.util.Collections;
4948
import java.util.HashSet;
5049
import java.util.List;
5150
import java.util.Map;
@@ -215,9 +214,15 @@ public void testHeaders() throws IOException {
215214
}
216215
final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header");
217216
final int statusCode = randomStatusCode(getRandom());
217+
Request request = new Request(method, "/" + statusCode);
218+
RequestOptions.Builder options = request.getOptions().toBuilder();
219+
for (Header header : requestHeaders) {
220+
options.addHeader(header.getName(), header.getValue());
221+
}
222+
request.setOptions(options);
218223
Response esResponse;
219224
try {
220-
esResponse = restClient.performRequest(method, "/" + statusCode, Collections.<String, String>emptyMap(), requestHeaders);
225+
esResponse = restClient.performRequest(request);
221226
} catch (ResponseException e) {
222227
esResponse = e.getResponse();
223228
}

0 commit comments

Comments
 (0)