Switch rolling restart to new style Requests (#32147)
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 `qa/rolling-upgrade` project to use the new versions.
This commit is contained in:
parent
320f1d263f
commit
c6c9075ca4
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.elasticsearch.upgrades;
|
||||
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.support.PlainActionFuture;
|
||||
import org.elasticsearch.client.Request;
|
||||
|
@ -32,14 +30,12 @@ import org.elasticsearch.test.rest.yaml.ObjectPath;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
|
||||
import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.INDEX_ROUTING_ALLOCATION_ENABLE_SETTING;
|
||||
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
|
||||
|
@ -65,8 +61,9 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
createIndex(index, settings.build());
|
||||
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
|
||||
ensureGreen(index);
|
||||
Response response = client().performRequest("GET", index + "/_stats", Collections.singletonMap("level", "shards"));
|
||||
assertOK(response);
|
||||
Request shardStatsRequest = new Request("GET", index + "/_stats");
|
||||
shardStatsRequest.addParameter("level", "shards");
|
||||
Response response = client().performRequest(shardStatsRequest);
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
List<Object> shardStats = objectPath.evaluate("indices." + index + ".shards.0");
|
||||
assertThat(shardStats, hasSize(2));
|
||||
|
@ -87,8 +84,9 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
final int id = idStart + i;
|
||||
assertOK(client().performRequest("PUT", index + "/test/" + id, emptyMap(),
|
||||
new StringEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}", ContentType.APPLICATION_JSON)));
|
||||
Request indexDoc = new Request("PUT", index + "/test/" + id);
|
||||
indexDoc.setJsonEntity("{\"test\": \"test_" + randomAsciiOfLength(2) + "\"}");
|
||||
client().performRequest(indexDoc);
|
||||
}
|
||||
return numDocs;
|
||||
}
|
||||
|
@ -113,7 +111,7 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
|
||||
public void testRecoveryWithConcurrentIndexing() throws Exception {
|
||||
final String index = "recovery_with_concurrent_indexing";
|
||||
Response response = client().performRequest("GET", "_nodes");
|
||||
Response response = client().performRequest(new Request("GET", "_nodes"));
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
|
||||
List<String> nodes = new ArrayList<>(nodeMap.keySet());
|
||||
|
@ -139,7 +137,7 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null));
|
||||
asyncIndexDocs(index, 10, 50).get();
|
||||
ensureGreen(index);
|
||||
assertOK(client().performRequest("POST", index + "/_refresh"));
|
||||
client().performRequest(new Request("POST", index + "/_refresh"));
|
||||
assertCount(index, "_only_nodes:" + nodes.get(0), 60);
|
||||
assertCount(index, "_only_nodes:" + nodes.get(1), 60);
|
||||
assertCount(index, "_only_nodes:" + nodes.get(2), 60);
|
||||
|
@ -150,7 +148,7 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null));
|
||||
asyncIndexDocs(index, 60, 50).get();
|
||||
ensureGreen(index);
|
||||
assertOK(client().performRequest("POST", index + "/_refresh"));
|
||||
client().performRequest(new Request("POST", index + "/_refresh"));
|
||||
assertCount(index, "_only_nodes:" + nodes.get(0), 110);
|
||||
assertCount(index, "_only_nodes:" + nodes.get(1), 110);
|
||||
assertCount(index, "_only_nodes:" + nodes.get(2), 110);
|
||||
|
@ -161,15 +159,16 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
}
|
||||
|
||||
private void assertCount(final String index, final String preference, final int expectedCount) throws IOException {
|
||||
final Response response = client().performRequest("GET", index + "/_count", Collections.singletonMap("preference", preference));
|
||||
assertOK(response);
|
||||
final Request request = new Request("GET", index + "/_count");
|
||||
request.addParameter("preference", preference);
|
||||
final Response response = client().performRequest(request);
|
||||
final int actualCount = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("count").toString());
|
||||
assertThat(actualCount, equalTo(expectedCount));
|
||||
}
|
||||
|
||||
|
||||
private String getNodeId(Predicate<Version> versionPredicate) throws IOException {
|
||||
Response response = client().performRequest("GET", "_nodes");
|
||||
Response response = client().performRequest(new Request("GET", "_nodes"));
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
|
||||
for (String id : nodesAsMap.keySet()) {
|
||||
|
@ -216,7 +215,7 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
|
||||
asyncIndexDocs(index, 10, 50).get();
|
||||
ensureGreen(index);
|
||||
assertOK(client().performRequest("POST", index + "/_refresh"));
|
||||
client().performRequest(new Request("POST", index + "/_refresh"));
|
||||
assertCount(index, "_only_nodes:" + newNode, 60);
|
||||
break;
|
||||
case UPGRADED:
|
||||
|
@ -226,8 +225,8 @@ public class RecoveryIT extends AbstractRollingTestCase {
|
|||
);
|
||||
asyncIndexDocs(index, 60, 50).get();
|
||||
ensureGreen(index);
|
||||
assertOK(client().performRequest("POST", index + "/_refresh"));
|
||||
Response response = client().performRequest("GET", "_nodes");
|
||||
client().performRequest(new Request("POST", index + "/_refresh"));
|
||||
Response response = client().performRequest(new Request("GET", "_nodes"));
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
final Map<String, Object> nodeMap = objectPath.evaluate("nodes");
|
||||
List<String> nodes = new ArrayList<>(nodeMap.keySet());
|
||||
|
|
Loading…
Reference in New Issue