use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method deleteModel.
public void deleteModel(RestClient client, String modelId, Consumer<Map<String, Object>> function) throws IOException {
Response response = TestHelper.makeRequest(client, "DELETE", "/_plugins/_ml/models/" + modelId, null, "", null);
verifyResponse(function, response);
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method searchModels.
public void searchModels(RestClient client, String query, Consumer<Map<String, Object>> function) throws IOException {
Response response = TestHelper.makeRequest(client, "GET", "/_plugins/_ml/models/_search", null, query, null);
verifyResponse(function, response);
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method trainAndPredict.
public void trainAndPredict(RestClient client, FunctionName functionName, String indexName, MLAlgoParams params, SearchSourceBuilder searchSourceBuilder, Consumer<Map<String, Object>> function) throws IOException {
MLInputDataset inputData = SearchQueryInputDataset.builder().indices(ImmutableList.of(indexName)).searchSourceBuilder(searchSourceBuilder).build();
MLInput kmeansInput = MLInput.builder().algorithm(functionName).parameters(params).inputDataset(inputData).build();
Response response = TestHelper.makeRequest(client, "POST", "/_plugins/_ml/_train_predict/" + functionName.name().toLowerCase(Locale.ROOT), ImmutableMap.of(), TestHelper.toHttpEntity(kmeansInput), null);
HttpEntity entity = response.getEntity();
assertNotNull(response);
String entityString = TestHelper.httpEntityToString(entity);
Map map = gson.fromJson(entityString, Map.class);
Map<String, Object> predictionResult = (Map<String, Object>) map.get("prediction_result");
if (function != null) {
function.accept(predictionResult);
}
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class MLCommonsRestTestCase method deleteTask.
public void deleteTask(RestClient client, String taskId, Consumer<Map<String, Object>> function) throws IOException {
Response response = TestHelper.makeRequest(client, "DELETE", "/_plugins/_ml/tasks/" + taskId, null, "", null);
verifyResponse(function, response);
}
use of org.opensearch.client.Response in project ml-commons by opensearch-project.
the class RestMLGetModelActionIT method testGetModelAPI_Success.
public void testGetModelAPI_Success() throws IOException {
Response trainModelResponse = ingestModelData();
HttpEntity entity = trainModelResponse.getEntity();
assertNotNull(trainModelResponse);
String entityString = TestHelper.httpEntityToString(entity);
Map map = gson.fromJson(entityString, Map.class);
String model_id = (String) map.get("model_id");
Response getModelResponse = TestHelper.makeRequest(client(), "GET", "/_plugins/_ml/models/" + model_id, null, "", null);
assertNotNull(getModelResponse);
assertEquals(RestStatus.OK, TestHelper.restStatus(getModelResponse));
}
Aggregations