use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class IndexingIT method buildNodeAndVersions.
private Nodes buildNodeAndVersions() throws IOException {
Response response = client().performRequest(new Request("GET", "_nodes"));
ObjectPath objectPath = ObjectPath.createFromResponse(response);
Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
Nodes nodes = new Nodes();
for (String id : nodesAsMap.keySet()) {
nodes.add(new Node(id, objectPath.evaluate("nodes." + id + ".name"), Version.fromString(objectPath.evaluate("nodes." + id + ".version")), HttpHost.create(objectPath.evaluate("nodes." + id + ".http.publish_address"))));
}
response = client().performRequest(new Request("GET", "_cluster/state"));
nodes.setMasterNodeId(ObjectPath.createFromResponse(response).evaluate("master_node"));
return nodes;
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class ExceptionIT method testOpensearchException.
public void testOpensearchException() throws Exception {
logClusterNodes();
Request request = new Request("GET", "/no_such_index");
for (Node node : client().getNodes()) {
try {
client().setNodes(Collections.singletonList(node));
logger.info("node: {}", node.getHost());
client().performRequest(request);
fail();
} catch (ResponseException e) {
logger.debug(e.getMessage());
Response response = e.getResponse();
assertEquals(SC_NOT_FOUND, response.getStatusLine().getStatusCode());
assertEquals("no_such_index", ObjectPath.createFromResponse(response).evaluate("error.index"));
}
}
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method ingestModelData.
protected Response ingestModelData() throws IOException {
Response trainModelResponse = TestHelper.makeRequest(client(), "POST", "_plugins/_ml/_train/sample_algo", null, TestHelper.toHttpEntity(trainModelDataJson()), null);
HttpEntity entity = trainModelResponse.getEntity();
assertNotNull(trainModelResponse);
return trainModelResponse;
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method indexExistsWithAdminClient.
// Utility fn for checking if an index exists. Should only be used when not allowed in a regular context
// (e.g., checking existence of system indices)
protected static boolean indexExistsWithAdminClient(String indexName) throws IOException {
Request request = new Request("HEAD", "/" + indexName);
Response response = adminClient().performRequest(request);
return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode();
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method validateStats.
protected void validateStats(FunctionName functionName, ActionName actionName, int expectedMinimumTotalFailureCount, int expectedMinimumTotalAlgoFailureCount, int expectedMinimumTotalRequestCount, int expectedMinimumTotalAlgoRequestCount) throws IOException {
Response statsResponse = TestHelper.makeRequest(client(), "GET", "_plugins/_ml/stats", null, "", null);
HttpEntity entity = statsResponse.getEntity();
assertNotNull(statsResponse);
String entityString = TestHelper.httpEntityToString(entity);
Map<String, Object> map = gson.fromJson(entityString, Map.class);
int totalFailureCount = 0;
int totalAlgoFailureCount = 0;
int totalRequestCount = 0;
int totalAlgoRequestCount = 0;
for (String key : map.keySet()) {
Map<String, Object> nodeStatsMap = (Map<String, Object>) map.get(key);
if (nodeStatsMap.containsKey(ML_TOTAL_FAILURE_COUNT)) {
totalFailureCount += (Double) nodeStatsMap.get(ML_TOTAL_FAILURE_COUNT);
}
String failureCountStat = StatNames.failureCountStat(functionName, actionName);
if (nodeStatsMap.containsKey(failureCountStat)) {
totalAlgoFailureCount += (Double) nodeStatsMap.get(failureCountStat);
}
if (nodeStatsMap.containsKey(ML_TOTAL_REQUEST_COUNT)) {
totalRequestCount += (Double) nodeStatsMap.get(ML_TOTAL_REQUEST_COUNT);
}
String requestCountStat = StatNames.requestCountStat(functionName, actionName);
if (nodeStatsMap.containsKey(requestCountStat)) {
totalAlgoRequestCount += (Double) nodeStatsMap.get(requestCountStat);
}
}
assertTrue(totalFailureCount >= expectedMinimumTotalFailureCount);
assertTrue(totalAlgoFailureCount >= expectedMinimumTotalAlgoFailureCount);
assertTrue(totalRequestCount >= expectedMinimumTotalRequestCount);
assertTrue(totalAlgoRequestCount >= expectedMinimumTotalAlgoRequestCount);
}
Aggregations