Search in sources :

Example 66 with Response

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);
}
Also used : Response(org.opensearch.client.Response)

Example 67 with 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);
}
Also used : Response(org.opensearch.client.Response)

Example 68 with 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);
    }
}
Also used : Response(org.opensearch.client.Response) MLInput(org.opensearch.ml.common.parameter.MLInput) HttpEntity(org.apache.http.HttpEntity) MLInputDataset(org.opensearch.ml.common.dataset.MLInputDataset) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 69 with Response

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);
}
Also used : Response(org.opensearch.client.Response)

Example 70 with 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));
}
Also used : Response(org.opensearch.client.Response) HttpEntity(org.apache.http.HttpEntity) Map(java.util.Map)

Aggregations

Response (org.opensearch.client.Response)134 Request (org.opensearch.client.Request)113 ResponseException (org.opensearch.client.ResponseException)24 Map (java.util.Map)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 ArrayList (java.util.ArrayList)17 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)16 RestClient (org.opensearch.client.RestClient)15 HashMap (java.util.HashMap)14 RequestOptions (org.opensearch.client.RequestOptions)12 ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 IndexRequest (org.opensearch.action.index.IndexRequest)11 IOException (java.io.IOException)10 List (java.util.List)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 Version (org.opensearch.Version)8 WriteRequest (org.opensearch.action.support.WriteRequest)8 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)7 IndexResponse (org.opensearch.action.index.IndexResponse)7 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)7