Switch x-pack/plugin to new style Requests (#32327)

In #29623 we added `Request` object flavored requests to the low level
REST client and in #30315 we deprecated the old `performRequest`s. This
changes all calls in the `x-pack/plugin` project to use the new versions.
This commit is contained in:
Nik Everett 2018-07-26 13:31:16 -04:00 committed by GitHub
parent 7ad16ffd84
commit 643235d46a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.CheckedFunction;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -128,18 +129,22 @@ public class XPackRestIT extends ESClientYamlSuiteTestCase {
() -> "Exception when waiting for [" + template + "] template to be created"); () -> "Exception when waiting for [" + template + "] template to be created");
} }
boolean existsWatcherIndex = adminClient().performRequest("HEAD", ".watches").getStatusLine().getStatusCode() == 200; boolean existsWatcherIndex = adminClient()
.performRequest(new Request("HEAD", ".watches"))
.getStatusLine().getStatusCode() == 200;
if (existsWatcherIndex == false) { if (existsWatcherIndex == false) {
return; return;
} }
Response response = adminClient().performRequest("GET", ".watches/_search", Collections.singletonMap("size", "1000")); Request searchWatchesRequest = new Request("GET", ".watches/_search");
searchWatchesRequest.addParameter("size", "1000");
Response response = adminClient().performRequest(searchWatchesRequest);
ObjectPath objectPathResponse = ObjectPath.createFromResponse(response); ObjectPath objectPathResponse = ObjectPath.createFromResponse(response);
int totalHits = objectPathResponse.evaluate("hits.total"); int totalHits = objectPathResponse.evaluate("hits.total");
if (totalHits > 0) { if (totalHits > 0) {
List<Map<String, Object>> hits = objectPathResponse.evaluate("hits.hits"); List<Map<String, Object>> hits = objectPathResponse.evaluate("hits.hits");
for (Map<String, Object> hit : hits) { for (Map<String, Object> hit : hits) {
String id = (String) hit.get("_id"); String id = (String) hit.get("_id");
assertOK(adminClient().performRequest("DELETE", "_xpack/watcher/watch/" + id)); adminClient().performRequest(new Request("DELETE", "_xpack/watcher/watch/" + id));
} }
} }
} }