use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class RecoveryIT method getNodeId.
private String getNodeId(Predicate<Version> versionPredicate) throws IOException {
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()) {
Version version = Version.fromString(objectPath.evaluate("nodes." + id + ".version"));
if (versionPredicate.test(version)) {
return id;
}
}
return null;
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class RecoveryIT method testRecoveryWithConcurrentIndexing.
public void testRecoveryWithConcurrentIndexing() throws Exception {
final String index = "recovery_with_concurrent_indexing";
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());
switch(CLUSTER_TYPE) {
case OLD:
Settings.Builder settings = Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 2).put(INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), "100ms").put(SETTING_ALLOCATION_MAX_RETRY.getKey(), // fail faster
"0");
createIndex(index, settings.build());
indexDocs(index, 0, 10);
ensureGreen(index);
// make sure that we can index while the replicas are recovering
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "primaries"));
break;
case MIXED:
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String) null));
asyncIndexDocs(index, 10, 50).get();
ensureGreen(index);
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);
// make sure that we can index while the replicas are recovering
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "primaries"));
break;
case UPGRADED:
updateIndexSettings(index, Settings.builder().put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String) null));
asyncIndexDocs(index, 60, 45).get();
ensureGreen(index);
client().performRequest(new Request("POST", index + "/_refresh"));
assertCount(index, "_only_nodes:" + nodes.get(0), 105);
assertCount(index, "_only_nodes:" + nodes.get(1), 105);
assertCount(index, "_only_nodes:" + nodes.get(2), 105);
break;
default:
throw new IllegalStateException("unknown type " + CLUSTER_TYPE);
}
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class CorsNotSetIT method testCorsSettingDefaultBehaviourDoesNotReturnAnything.
public void testCorsSettingDefaultBehaviourDoesNotReturnAnything() throws IOException {
String corsValue = "http://localhost:9200";
Request request = new Request("GET", "/");
RequestOptions.Builder options = request.getOptions().toBuilder();
options.addHeader("User-Agent", "Mozilla Bar");
options.addHeader("Origin", corsValue);
request.setOptions(options);
Response response = getRestClient().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
assertThat(response.getHeader("Access-Control-Allow-Origin"), nullValue());
assertThat(response.getHeader("Access-Control-Allow-Credentials"), nullValue());
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class JodaCompatibilityIT method performOnAllNodes.
private void performOnAllNodes(Request search, Consumer<Response> consumer) throws IOException {
List<Node> nodes = client().getNodes();
for (Node node : nodes) {
client().setNodes(Collections.singletonList(node));
Response response = client().performRequest(search);
consumer.accept(response);
assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
}
client().setNodes(nodes);
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class SearchRestCancellationIT method verifyCancellationDuringFetchPhase.
void verifyCancellationDuringFetchPhase(String searchAction, Request searchRequest) throws Exception {
Map<String, String> nodeIdToName = readNodesInfo();
List<ScriptedBlockPlugin> plugins = initBlockFactory();
indexTestData();
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Exception> error = new AtomicReference<>();
Cancellable cancellable = getRestClient().performRequestAsync(searchRequest, new ResponseListener() {
@Override
public void onSuccess(Response response) {
latch.countDown();
}
@Override
public void onFailure(Exception exception) {
error.set(exception);
latch.countDown();
}
});
awaitForBlock(plugins);
cancellable.cancel();
ensureSearchTaskIsCancelled(searchAction, nodeIdToName::get);
disableBlocks(plugins);
latch.await();
assertThat(error.get(), instanceOf(CancellationException.class));
}
Aggregations