Search in sources :

Example 1 with MLModelDeleteRequest

use of org.opensearch.ml.common.transport.model.MLModelDeleteRequest in project ml-commons by opensearch-project.

the class DeleteModelTransportAction method doExecute.

@Override
protected void doExecute(Task task, ActionRequest request, ActionListener<DeleteResponse> actionListener) {
    MLModelDeleteRequest mlModelDeleteRequest = MLModelDeleteRequest.fromActionRequest(request);
    String modelId = mlModelDeleteRequest.getModelId();
    DeleteRequest deleteRequest = new DeleteRequest(ML_MODEL_INDEX, modelId);
    try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
        client.delete(deleteRequest, new ActionListener<DeleteResponse>() {

            @Override
            public void onResponse(DeleteResponse deleteResponse) {
                log.info("Completed Delete Model Request, model id:{} deleted", modelId);
                actionListener.onResponse(deleteResponse);
            }

            @Override
            public void onFailure(Exception e) {
                log.error("Failed to delete ML model " + modelId, e);
                actionListener.onFailure(e);
            }
        });
    } catch (Exception e) {
        log.error("Failed to delete ML model " + modelId, e);
        actionListener.onFailure(e);
    }
}
Also used : DeleteResponse(org.opensearch.action.delete.DeleteResponse) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest)

Example 2 with MLModelDeleteRequest

use of org.opensearch.ml.common.transport.model.MLModelDeleteRequest in project ml-commons by opensearch-project.

the class MachineLearningNodeClient method deleteModel.

@Override
public void deleteModel(String modelId, ActionListener<DeleteResponse> listener) {
    MLModelDeleteRequest mlModelDeleteRequest = MLModelDeleteRequest.builder().modelId(modelId).build();
    client.execute(MLModelDeleteAction.INSTANCE, mlModelDeleteRequest, ActionListener.wrap(deleteResponse -> {
        listener.onResponse(deleteResponse);
    }, listener::onFailure));
}
Also used : MLOutput(org.opensearch.ml.common.parameter.MLOutput) FieldDefaults(lombok.experimental.FieldDefaults) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest) RequiredArgsConstructor(lombok.RequiredArgsConstructor) MLInput(org.opensearch.ml.common.parameter.MLInput) MLTrainAndPredictionTaskAction(org.opensearch.ml.common.transport.trainpredict.MLTrainAndPredictionTaskAction) Input(org.opensearch.ml.common.parameter.Input) Function(java.util.function.Function) MLPredictionTaskRequest(org.opensearch.ml.common.transport.prediction.MLPredictionTaskRequest) Output(org.opensearch.ml.common.parameter.Output) AccessLevel(lombok.AccessLevel) MLPredictionTaskAction(org.opensearch.ml.common.transport.prediction.MLPredictionTaskAction) DeleteResponse(org.opensearch.action.delete.DeleteResponse) SearchRequest(org.opensearch.action.search.SearchRequest) ActionListener(org.opensearch.action.ActionListener) ActionResponse(org.opensearch.action.ActionResponse) SearchResponse(org.opensearch.action.search.SearchResponse) MLModel(org.opensearch.ml.common.parameter.MLModel) MLModelGetResponse(org.opensearch.ml.common.transport.model.MLModelGetResponse) MLTaskResponse(org.opensearch.ml.common.transport.MLTaskResponse) MLExecuteTaskAction(org.opensearch.ml.common.transport.execute.MLExecuteTaskAction) MLModelDeleteAction(org.opensearch.ml.common.transport.model.MLModelDeleteAction) NodeClient(org.opensearch.client.node.NodeClient) MLModelGetRequest(org.opensearch.ml.common.transport.model.MLModelGetRequest) MLModelSearchAction(org.opensearch.ml.common.transport.model.MLModelSearchAction) MLExecuteTaskRequest(org.opensearch.ml.common.transport.execute.MLExecuteTaskRequest) MLTrainingTaskAction(org.opensearch.ml.common.transport.training.MLTrainingTaskAction) MLModelGetAction(org.opensearch.ml.common.transport.model.MLModelGetAction) MLExecuteTaskResponse(org.opensearch.ml.common.transport.execute.MLExecuteTaskResponse) MLTrainingTaskRequest(org.opensearch.ml.common.transport.training.MLTrainingTaskRequest) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest)

Example 3 with MLModelDeleteRequest

use of org.opensearch.ml.common.transport.model.MLModelDeleteRequest in project ml-commons by opensearch-project.

the class RestMLDeleteModelAction method prepareRequest.

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String modelId = request.param(PARAMETER_MODEL_ID);
    MLModelDeleteRequest mlModelDeleteRequest = new MLModelDeleteRequest(modelId);
    return channel -> client.execute(MLModelDeleteAction.INSTANCE, mlModelDeleteRequest, new RestToXContentListener<>(channel));
}
Also used : PARAMETER_MODEL_ID(org.opensearch.ml.utils.RestActionUtils.PARAMETER_MODEL_ID) List(java.util.List) MLModelDeleteAction(org.opensearch.ml.common.transport.model.MLModelDeleteAction) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) ML_BASE_URI(org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest)

Aggregations

MLModelDeleteRequest (org.opensearch.ml.common.transport.model.MLModelDeleteRequest)3 DeleteResponse (org.opensearch.action.delete.DeleteResponse)2 NodeClient (org.opensearch.client.node.NodeClient)2 MLModelDeleteAction (org.opensearch.ml.common.transport.model.MLModelDeleteAction)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 List (java.util.List)1 Locale (java.util.Locale)1 Function (java.util.function.Function)1 AccessLevel (lombok.AccessLevel)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 FieldDefaults (lombok.experimental.FieldDefaults)1 ActionListener (org.opensearch.action.ActionListener)1 ActionResponse (org.opensearch.action.ActionResponse)1 DeleteRequest (org.opensearch.action.delete.DeleteRequest)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 SearchResponse (org.opensearch.action.search.SearchResponse)1 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)1 Input (org.opensearch.ml.common.parameter.Input)1 MLInput (org.opensearch.ml.common.parameter.MLInput)1