Remove use of deprecated methods to perform request (#31117)
The old perform request methods on the REST client have been deprecated in favor using request-flavored methods. This commit addresses the use of these deprecated methods in the CCR test suite.
This commit is contained in:
parent
6e109e90c3
commit
d230548401
|
@ -5,10 +5,8 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.ccr;
|
package org.elasticsearch.xpack.ccr;
|
||||||
|
|
||||||
import org.apache.http.client.methods.HttpPut;
|
|
||||||
import org.apache.http.entity.ContentType;
|
|
||||||
import org.apache.http.entity.StringEntity;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.elasticsearch.client.Request;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.client.RestClient;
|
import org.elasticsearch.client.RestClient;
|
||||||
import org.elasticsearch.common.Booleans;
|
import org.elasticsearch.common.Booleans;
|
||||||
|
@ -23,12 +21,9 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
@ -81,10 +76,10 @@ public class FollowIndexSecurityIT extends ESRestTestCase {
|
||||||
createAndFollowIndex("leader_cluster:" + allowedIndex, allowedIndex);
|
createAndFollowIndex("leader_cluster:" + allowedIndex, allowedIndex);
|
||||||
assertBusy(() -> verifyDocuments(client(), allowedIndex, numDocs));
|
assertBusy(() -> verifyDocuments(client(), allowedIndex, numDocs));
|
||||||
assertThat(countCcrNodeTasks(), equalTo(1));
|
assertThat(countCcrNodeTasks(), equalTo(1));
|
||||||
assertOK(client().performRequest("POST", "/" + allowedIndex + "/_xpack/ccr/_unfollow"));
|
assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_xpack/ccr/_unfollow")));
|
||||||
// Make sure that there are no other ccr relates operations running:
|
// Make sure that there are no other ccr relates operations running:
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
Map<String, Object> clusterState = toMap(adminClient().performRequest("GET", "/_cluster/state"));
|
Map<String, Object> clusterState = toMap(adminClient().performRequest(new Request("GET", "/_cluster/state")));
|
||||||
List<?> tasks = (List<?>) XContentMapValues.extractValue("metadata.persistent_tasks.tasks", clusterState);
|
List<?> tasks = (List<?>) XContentMapValues.extractValue("metadata.persistent_tasks.tasks", clusterState);
|
||||||
assertThat(tasks.size(), equalTo(0));
|
assertThat(tasks.size(), equalTo(0));
|
||||||
assertThat(countCcrNodeTasks(), equalTo(0));
|
assertThat(countCcrNodeTasks(), equalTo(0));
|
||||||
|
@ -92,10 +87,10 @@ public class FollowIndexSecurityIT extends ESRestTestCase {
|
||||||
|
|
||||||
followIndex("leader_cluster:" + allowedIndex, allowedIndex);
|
followIndex("leader_cluster:" + allowedIndex, allowedIndex);
|
||||||
assertThat(countCcrNodeTasks(), equalTo(1));
|
assertThat(countCcrNodeTasks(), equalTo(1));
|
||||||
assertOK(client().performRequest("POST", "/" + allowedIndex + "/_xpack/ccr/_unfollow"));
|
assertOK(client().performRequest(new Request("POST", "/" + allowedIndex + "/_xpack/ccr/_unfollow")));
|
||||||
// Make sure that there are no other ccr relates operations running:
|
// Make sure that there are no other ccr relates operations running:
|
||||||
assertBusy(() -> {
|
assertBusy(() -> {
|
||||||
Map<String, Object> clusterState = toMap(adminClient().performRequest("GET", "/_cluster/state"));
|
Map<String, Object> clusterState = toMap(adminClient().performRequest(new Request("GET", "/_cluster/state")));
|
||||||
List<?> tasks = (List<?>) XContentMapValues.extractValue("metadata.persistent_tasks.tasks", clusterState);
|
List<?> tasks = (List<?>) XContentMapValues.extractValue("metadata.persistent_tasks.tasks", clusterState);
|
||||||
assertThat(tasks.size(), equalTo(0));
|
assertThat(tasks.size(), equalTo(0));
|
||||||
assertThat(countCcrNodeTasks(), equalTo(0));
|
assertThat(countCcrNodeTasks(), equalTo(0));
|
||||||
|
@ -115,8 +110,9 @@ public class FollowIndexSecurityIT extends ESRestTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int countCcrNodeTasks() throws IOException {
|
private int countCcrNodeTasks() throws IOException {
|
||||||
Map<String, Object> rsp1 = toMap(adminClient().performRequest("GET", "/_tasks",
|
final Request request = new Request("GET", "/_tasks");
|
||||||
Collections.singletonMap("detailed", "true")));
|
request.addParameter("detailed", "true");
|
||||||
|
Map<String, Object> rsp1 = toMap(adminClient().performRequest(request));
|
||||||
Map<?, ?> nodes = (Map<?, ?>) rsp1.get("nodes");
|
Map<?, ?> nodes = (Map<?, ?>) rsp1.get("nodes");
|
||||||
assertThat(nodes.size(), equalTo(1));
|
assertThat(nodes.size(), equalTo(1));
|
||||||
Map<?, ?> node = (Map<?, ?>) nodes.values().iterator().next();
|
Map<?, ?> node = (Map<?, ?>) nodes.values().iterator().next();
|
||||||
|
@ -138,30 +134,33 @@ public class FollowIndexSecurityIT extends ESRestTestCase {
|
||||||
document.field((String) fields[i], fields[i + 1]);
|
document.field((String) fields[i], fields[i + 1]);
|
||||||
}
|
}
|
||||||
document.endObject();
|
document.endObject();
|
||||||
assertOK(adminClient().performRequest("POST", "/" + index + "/doc/" + id, emptyMap(),
|
final Request request = new Request("POST", "/" + index + "/_doc/" + id);
|
||||||
new StringEntity(Strings.toString(document), ContentType.APPLICATION_JSON)));
|
request.setJsonEntity(Strings.toString(document));
|
||||||
|
assertOK(adminClient().performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void refresh(String index) throws IOException {
|
private static void refresh(String index) throws IOException {
|
||||||
assertOK(adminClient().performRequest("POST", "/" + index + "/_refresh"));
|
assertOK(adminClient().performRequest(new Request("POST", "/" + index + "/_refresh")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void followIndex(String leaderIndex, String followIndex) throws IOException {
|
private static void followIndex(String leaderIndex, String followIndex) throws IOException {
|
||||||
Map<String, String> params = Collections.singletonMap("leader_index", leaderIndex);
|
final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_follow");
|
||||||
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_follow", params));
|
request.addParameter("leader_index", leaderIndex);
|
||||||
|
assertOK(client().performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException {
|
private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException {
|
||||||
Map<String, String> params = Collections.singletonMap("leader_index", leaderIndex);
|
final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow");
|
||||||
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow", params));
|
request.addParameter("leader_index", leaderIndex);
|
||||||
|
assertOK(client().performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
void verifyDocuments(RestClient client, String index, int expectedNumDocs) throws IOException {
|
void verifyDocuments(RestClient client, String index, int expectedNumDocs) throws IOException {
|
||||||
Map<String, String> params = new HashMap<>();
|
final Request request = new Request("GET", "/" + index + "/_search");
|
||||||
params.put("size", Integer.toString(expectedNumDocs));
|
request.addParameter("pretty", "true");
|
||||||
params.put("sort", "field:asc");
|
request.addParameter("size", Integer.toString(expectedNumDocs));
|
||||||
params.put("pretty", "true");
|
request.addParameter("sort", "field:asc");
|
||||||
Map<String, ?> response = toMap(client.performRequest("GET", "/" + index + "/_search", params));
|
Map<String, ?> response = toMap(client.performRequest(request));
|
||||||
|
|
||||||
int numDocs = (int) XContentMapValues.extractValue("hits.total", response);
|
int numDocs = (int) XContentMapValues.extractValue("hits.total", response);
|
||||||
assertThat(numDocs, equalTo(expectedNumDocs));
|
assertThat(numDocs, equalTo(expectedNumDocs));
|
||||||
|
@ -187,9 +186,9 @@ public class FollowIndexSecurityIT extends ESRestTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void createIndex(String name, Settings settings, String mapping) throws IOException {
|
protected static void createIndex(String name, Settings settings, String mapping) throws IOException {
|
||||||
assertOK(adminClient().performRequest(HttpPut.METHOD_NAME, name, Collections.emptyMap(),
|
final Request request = new Request("PUT", "/" + name);
|
||||||
new StringEntity("{ \"settings\": " + Strings.toString(settings)
|
request.setJsonEntity("{ \"settings\": " + Strings.toString(settings) + ", \"mappings\" : {" + mapping + "} }");
|
||||||
+ ", \"mappings\" : {" + mapping + "} }", ContentType.APPLICATION_JSON)));
|
assertOK(adminClient().performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
package org.elasticsearch.xpack.ccr;
|
package org.elasticsearch.xpack.ccr;
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.entity.ContentType;
|
|
||||||
import org.apache.http.entity.StringEntity;
|
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.elasticsearch.client.Request;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.client.RestClient;
|
import org.elasticsearch.client.RestClient;
|
||||||
import org.elasticsearch.common.Booleans;
|
import org.elasticsearch.common.Booleans;
|
||||||
|
@ -21,12 +20,9 @@ import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
|
@ -78,33 +74,36 @@ public class FollowIndexIT extends ESRestTestCase {
|
||||||
document.field((String) fields[i], fields[i + 1]);
|
document.field((String) fields[i], fields[i + 1]);
|
||||||
}
|
}
|
||||||
document.endObject();
|
document.endObject();
|
||||||
assertOK(client.performRequest("POST", "/" + index + "/doc/" + id, emptyMap(),
|
final Request request = new Request("POST", "/" + index + "/_doc/" + id);
|
||||||
new StringEntity(Strings.toString(document), ContentType.APPLICATION_JSON)));
|
request.setJsonEntity(Strings.toString(document));
|
||||||
|
assertOK(client.performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void refresh(String index) throws IOException {
|
private static void refresh(String index) throws IOException {
|
||||||
assertOK(client().performRequest("POST", "/" + index + "/_refresh"));
|
assertOK(client().performRequest(new Request("POST", "/" + index + "/_refresh")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void followIndex(String leaderIndex, String followIndex) throws IOException {
|
private static void followIndex(String leaderIndex, String followIndex) throws IOException {
|
||||||
Map<String, String> params = Collections.singletonMap("leader_index", leaderIndex);
|
final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_follow");
|
||||||
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_follow", params));
|
request.addParameter("leader_index", leaderIndex);
|
||||||
|
assertOK(client().performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException {
|
private static void createAndFollowIndex(String leaderIndex, String followIndex) throws IOException {
|
||||||
Map<String, String> params = Collections.singletonMap("leader_index", leaderIndex);
|
final Request request = new Request("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow");
|
||||||
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_create_and_follow", params));
|
request.addParameter("leader_index", leaderIndex);
|
||||||
|
assertOK(client().performRequest(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void unfollowIndex(String followIndex) throws IOException {
|
private static void unfollowIndex(String followIndex) throws IOException {
|
||||||
assertOK(client().performRequest("POST", "/" + followIndex + "/_xpack/ccr/_unfollow"));
|
assertOK(client().performRequest(new Request("POST", "/" + followIndex + "/_xpack/ccr/_unfollow")));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyDocuments(String index, int expectedNumDocs) throws IOException {
|
private static void verifyDocuments(String index, int expectedNumDocs) throws IOException {
|
||||||
Map<String, String> params = new HashMap<>();
|
final Request request = new Request("GET", "/" + index + "/_search");
|
||||||
params.put("size", Integer.toString(expectedNumDocs));
|
request.addParameter("size", Integer.toString(expectedNumDocs));
|
||||||
params.put("sort", "field:asc");
|
request.addParameter("sort", "field:asc");
|
||||||
Map<String, ?> response = toMap(client().performRequest("GET", "/" + index + "/_search", params));
|
Map<String, ?> response = toMap(client().performRequest(request));
|
||||||
|
|
||||||
int numDocs = (int) XContentMapValues.extractValue("hits.total", response);
|
int numDocs = (int) XContentMapValues.extractValue("hits.total", response);
|
||||||
assertThat(numDocs, equalTo(expectedNumDocs));
|
assertThat(numDocs, equalTo(expectedNumDocs));
|
||||||
|
@ -125,15 +124,6 @@ public class FollowIndexIT extends ESRestTestCase {
|
||||||
return XContentHelper.convertToMap(JsonXContent.jsonXContent, response, false);
|
return XContentHelper.convertToMap(JsonXContent.jsonXContent, response, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureYellow(String index) throws IOException {
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
params.put("wait_for_status", "yellow");
|
|
||||||
params.put("wait_for_no_relocating_shards", "true");
|
|
||||||
params.put("timeout", "30s");
|
|
||||||
params.put("level", "shards");
|
|
||||||
assertOK(client().performRequest("GET", "_cluster/health/" + index, params));
|
|
||||||
}
|
|
||||||
|
|
||||||
private RestClient buildLeaderClient() throws IOException {
|
private RestClient buildLeaderClient() throws IOException {
|
||||||
assert runningAgainstLeaderCluster == false;
|
assert runningAgainstLeaderCluster == false;
|
||||||
String leaderUrl = System.getProperty("tests.leader_host");
|
String leaderUrl = System.getProperty("tests.leader_host");
|
||||||
|
|
Loading…
Reference in New Issue