From 5ad0731e7f1e5979384a18daaa1053752baefbc6 Mon Sep 17 00:00:00 2001 From: David Kyle Date: Tue, 4 Mar 2025 16:12:13 +0000 Subject: [PATCH 1/5] Remove deprecated routes for ml trained models APIs --- .../api/ml.get_trained_models.json | 7 -- .../api/ml.infer_trained_model.json | 4 - .../rest-api-spec/api/ml.stop_datafeed.json | 6 - .../xpack/ml/MachineLearning.java | 2 - .../TransportTrainedModelCacheInfoAction.java | 8 -- .../RestDeleteTrainedModelAction.java | 16 +-- .../inference/RestGetTrainedModelsAction.java | 44 +------ .../RestGetTrainedModelsStatsAction.java | 18 +-- ...RestInferTrainedModelDeploymentAction.java | 116 ------------------ .../inference/RestPutTrainedModelAction.java | 16 +-- 10 files changed, 7 insertions(+), 230 deletions(-) delete mode 100644 x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestInferTrainedModelDeploymentAction.java diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.get_trained_models.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.get_trained_models.json index 1581fe314246f..e5b635b02075c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.get_trained_models.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.get_trained_models.json @@ -43,13 +43,6 @@ "required":false, "description":"A comma-separate list of fields to optionally include. Valid options are 'definition' and 'total_feature_importance'. Default is none." }, - "include_model_definition":{ - "type":"boolean", - "required":false, - "description":"Should the full model definition be included in the results. These definitions can be large. So be cautious when including them. Defaults to false.", - "default":false, - "deprecated": true - }, "decompress_definition":{ "type":"boolean", "required":false, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json index 6041155b1ea6e..a330e8582ce4d 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json @@ -36,10 +36,6 @@ "description":"The unique identifier of the trained model.", "required":true } - }, - "deprecated": { - "version":"8.3.0", - "description": "/_ml/trained_models/{model_id}/deployment/_infer is deprecated. Use /_ml/trained_models/{model_id}/_infer instead" } } ] diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.stop_datafeed.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.stop_datafeed.json index f689a33d72c7d..6eb64661f6f41 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.stop_datafeed.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.stop_datafeed.json @@ -32,12 +32,6 @@ "required":false, "description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)" }, - "allow_no_datafeeds":{ - "type":"boolean", - "required":false, - "description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)", - "deprecated":true - }, "force":{ "type":"boolean", "required":false, diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index dcbe18a1f34d2..b4042d674a30f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -422,7 +422,6 @@ import org.elasticsearch.xpack.ml.rest.inference.RestGetTrainedModelsAction; import org.elasticsearch.xpack.ml.rest.inference.RestGetTrainedModelsStatsAction; import org.elasticsearch.xpack.ml.rest.inference.RestInferTrainedModelAction; -import org.elasticsearch.xpack.ml.rest.inference.RestInferTrainedModelDeploymentAction; import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelAction; import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelAliasAction; import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelDefinitionPartAction; @@ -1503,7 +1502,6 @@ public List getRestHandlers( if (machineLearningExtension.get().isNlpEnabled()) { restHandlers.add(new RestStartTrainedModelDeploymentAction(machineLearningExtension.get().disableInferenceProcessCache())); restHandlers.add(new RestStopTrainedModelDeploymentAction()); - restHandlers.add(new RestInferTrainedModelDeploymentAction()); restHandlers.add(new RestUpdateTrainedModelDeploymentAction()); restHandlers.add(new RestPutTrainedModelVocabularyAction()); restHandlers.add(new RestClearDeploymentCacheAction()); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportTrainedModelCacheInfoAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportTrainedModelCacheInfoAction.java index 7b52cf09f2204..c5e4584a80b34 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportTrainedModelCacheInfoAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportTrainedModelCacheInfoAction.java @@ -13,8 +13,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.core.UpdateForV9; import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.tasks.CancellableTask; import org.elasticsearch.tasks.Task; @@ -87,7 +85,6 @@ protected CacheInfo nodeOperation(NodeModelCacheInfoRequest nodeModelCacheInfoRe ); } - @UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // this can be replaced with TransportRequest.Empty in v9 public static class NodeModelCacheInfoRequest extends TransportRequest { NodeModelCacheInfoRequest() {} @@ -100,10 +97,5 @@ public NodeModelCacheInfoRequest(StreamInput in) throws IOException { public Task createTask(long id, String type, String action, TaskId parentTaskId, Map headers) { return new CancellableTask(id, type, action, "", parentTaskId, headers); } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - } } } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java index b04b5f2f45006..d1ca1ae230ec5 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.core.TimeValue; -import org.elasticsearch.core.UpdateForV9; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.Scope; @@ -28,22 +27,9 @@ @ServerlessScope(Scope.PUBLIC) public class RestDeleteTrainedModelAction extends BaseRestHandler { - @UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) - // one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access - // that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will - // continue to emit deprecations warnings but will not require any special headers to access the API in v9. - // Please review and update the code and tests as needed. The original code remains commented out below for reference. @Override public List routes() { - return List.of( - // Route.builder(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}") - // .replaces(DELETE, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8) - // .build() - new Route(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"), - Route.builder(DELETE, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}") - .deprecateAndKeep("Use the trained_models API instead.") - .build() - ); + return List.of(new Route(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java index 14f6858f51fba..d4822dc2e36db 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java @@ -9,9 +9,6 @@ import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.logging.DeprecationCategory; -import org.elasticsearch.common.logging.DeprecationLogger; -import org.elasticsearch.core.UpdateForV9; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestRequest; @@ -38,7 +35,6 @@ import static java.util.Arrays.asList; import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Includes.DEFINITION; import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; import static org.elasticsearch.xpack.core.ml.utils.ToXContentParams.EXCLUDE_GENERATED; import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH; @@ -46,28 +42,9 @@ @ServerlessScope(Scope.PUBLIC) public class RestGetTrainedModelsAction extends BaseRestHandler { - private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetTrainedModelsAction.class); - private static final String INCLUDE_MODEL_DEFINITION = "include_model_definition"; - - @UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) - // one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access - // that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will - // continue to emit deprecations warnings but will not require any special headers to access the API in v9. - // Please review and update the code and tests as needed. The original code remains commented out below for reference. @Override public List routes() { - return List.of( - // Route.builder(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}") - // .replaces(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8) - // .build(), - // Route.builder(GET, BASE_PATH + "trained_models").replaces(GET, BASE_PATH + "inference", RestApiVersion.V_8).build() - new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"), - Route.builder(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}") - .deprecateAndKeep("Use the trained_models API instead.") - .build(), - new Route(GET, BASE_PATH + "trained_models"), - Route.builder(GET, BASE_PATH + "inference").deprecateAndKeep("Use the trained_models API instead.").build() - ); + return List.of(new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")); } private static final Map DEFAULT_TO_XCONTENT_VALUES = Collections.singletonMap( @@ -90,22 +67,9 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient Set includes = new HashSet<>( asList(restRequest.paramAsStringArray(GetTrainedModelsAction.Request.INCLUDE.getPreferredName(), Strings.EMPTY_ARRAY)) ); - final GetTrainedModelsAction.Request request; - if (restRequest.hasParam(INCLUDE_MODEL_DEFINITION)) { - deprecationLogger.warn( - DeprecationCategory.API, - INCLUDE_MODEL_DEFINITION, - "[{}] parameter is deprecated! Use [include=definition] instead.", - INCLUDE_MODEL_DEFINITION - ); - request = new GetTrainedModelsAction.Request( - modelId, - tags, - restRequest.paramAsBoolean(INCLUDE_MODEL_DEFINITION, false) ? Set.of(DEFINITION) : Set.of() - ); - } else { - request = new GetTrainedModelsAction.Request(modelId, tags, includes); - } + + final GetTrainedModelsAction.Request request = new GetTrainedModelsAction.Request(modelId, tags, includes); + if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) { request.setPageParams( new PageParams( diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java index 92a89c1365960..f4cc3726c6fdc 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Strings; -import org.elasticsearch.core.UpdateForV9; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.Scope; @@ -30,26 +29,11 @@ @ServerlessScope(Scope.PUBLIC) public class RestGetTrainedModelsStatsAction extends BaseRestHandler { - @UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) - // one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access - // that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will - // continue to emit deprecations warnings but will not require any special headers to access the API in v9. - // Please review and update the code and tests as needed. The original code remains commented out below for reference. @Override public List routes() { return List.of( - // Route.builder(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}/_stats") - // .replaces(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}/_stats", RestApiVersion.V_8) - // .build(), - // Route.builder(GET, BASE_PATH + "trained_models/_stats") - // .replaces(GET, BASE_PATH + "inference/_stats", RestApiVersion.V_8) - // .build() new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}/_stats"), - Route.builder(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}/_stats") - .deprecateAndKeep("Use the trained_models API instead.") - .build(), - new Route(GET, BASE_PATH + "trained_models/_stats"), - Route.builder(GET, BASE_PATH + "inference/_stats").deprecateAndKeep("Use the trained_models API instead.").build() + new Route(GET, BASE_PATH + "trained_models/_stats") ); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestInferTrainedModelDeploymentAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestInferTrainedModelDeploymentAction.java deleted file mode 100644 index e377d185e16df..0000000000000 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestInferTrainedModelDeploymentAction.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -package org.elasticsearch.xpack.ml.rest.inference; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.client.internal.node.NodeClient; -import org.elasticsearch.common.ValidationException; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.core.UpdateForV9; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.rest.action.RestCancellableNodeClient; -import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.core.ml.action.InferModelAction; -import org.elasticsearch.xpack.core.ml.action.InferTrainedModelDeploymentAction; -import org.elasticsearch.xpack.core.ml.inference.TrainedModelConfig; -import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; - -import static org.elasticsearch.rest.RestRequest.Method.POST; -import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH; - -public class RestInferTrainedModelDeploymentAction extends BaseRestHandler { - - static final String PATH = BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}/deployment/_infer"; - - @Override - public String getName() { - return "xpack_ml_infer_trained_models_deployment_action"; - } - - @UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) - // these routes were ".deprecated" in RestApiVersion.V_8 which will require use of REST API compatibility headers to access - // this API in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will - // continue to emit deprecations warnings but will not require any special headers to access the API in v9. - // Please review and update the code and tests as needed. The original code remains commented out below for reference. - @Override - public List routes() { - return Collections.singletonList( - // Route.builder(POST, PATH) - // .deprecated( - // "[" - // + POST.name() - // + " " - // + PATH - // + "] is deprecated! Use [" - // + POST.name() - // + " " - // + RestInferTrainedModelAction.PATH - // + "] instead.", - // RestApiVersion.V_8 - // ) - // .build() - Route.builder(POST, PATH) - .deprecateAndKeep( - "[" - + POST.name() - + " " - + PATH - + "] is deprecated! Use [" - + POST.name() - + " " - + RestInferTrainedModelAction.PATH - + "] instead." - ) - .build() - ); - } - - @Override - protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { - String modelId = restRequest.param(TrainedModelConfig.MODEL_ID.getPreferredName()); - if (restRequest.hasContent() == false) { - throw ExceptionsHelper.badRequestException("requires body"); - } - InferModelAction.Request.Builder requestBuilder = InferModelAction.Request.parseRequest(modelId, restRequest.contentParser()); - - if (restRequest.hasParam(InferModelAction.Request.TIMEOUT.getPreferredName())) { - TimeValue inferTimeout = restRequest.paramAsTime( - InferModelAction.Request.TIMEOUT.getPreferredName(), - InferModelAction.Request.DEFAULT_TIMEOUT_FOR_API - ); - requestBuilder.setInferenceTimeout(inferTimeout); - } - - // Unlike the _infer API, deployment/_infer only accepts a single document - var request = requestBuilder.build(); - if (request.getObjectsToInfer() != null && request.getObjectsToInfer().size() > 1) { - ValidationException ex = new ValidationException(); - ex.addValidationError("multiple documents are not supported"); - throw ex; - } - - return channel -> new RestCancellableNodeClient(client, restRequest.getHttpChannel()).execute( - InferModelAction.EXTERNAL_INSTANCE, - request, - // This API is deprecated but refactoring makes it simpler to call - // the new replacement API and swap in the old response. - ActionListener.wrap(response -> { - InferTrainedModelDeploymentAction.Response oldResponse = new InferTrainedModelDeploymentAction.Response( - response.getInferenceResults() - ); - new RestToXContentListener<>(channel).onResponse(oldResponse); - }, e -> new RestToXContentListener<>(channel).onFailure(e)) - - ); - } -} diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java index 437861c5f9a00..523066f359b05 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.ml.rest.inference; import org.elasticsearch.client.internal.node.NodeClient; -import org.elasticsearch.core.UpdateForV9; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.Scope; @@ -27,22 +26,9 @@ @ServerlessScope(Scope.PUBLIC) public class RestPutTrainedModelAction extends BaseRestHandler { - @UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) - // one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access - // that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will - // continue to emit deprecations warnings but will not require any special headers to access the API in v9. - // Please review and update the code and tests as needed. The original code remains commented out below for reference. @Override public List routes() { - return List.of( - // Route.builder(PUT, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}") - // .replaces(PUT, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8) - // .build() - new Route(PUT, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"), - Route.builder(PUT, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}") - .deprecateAndKeep("Use the trained_models API instead.") - .build() - ); + return List.of(new Route(PUT, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")); } @Override From ab5bdb55ee47f35b1e9fd510f5d7282c8437582d Mon Sep 17 00:00:00 2001 From: David Kyle Date: Tue, 4 Mar 2025 16:32:59 +0000 Subject: [PATCH 2/5] and the path --- .../rest-api-spec/api/ml.infer_trained_model.json | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json index a330e8582ce4d..95d389266302c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json @@ -24,19 +24,6 @@ "required":true } } - }, - { - "path":"/_ml/trained_models/{model_id}/deployment/_infer", - "methods":[ - "POST" - ], - "parts":{ - "model_id":{ - "type":"string", - "description":"The unique identifier of the trained model.", - "required":true - } - } } ] }, From 131b2f505401355abd53e829f3bebff49d2e4878 Mon Sep 17 00:00:00 2001 From: David Kyle Date: Tue, 4 Mar 2025 18:42:32 +0000 Subject: [PATCH 3/5] fix tests --- .../xpack/ml/integration/PyTorchModelIT.java | 9 --------- .../test/ml/3rd_party_deployment.yml | 20 ------------------- ...MLModelDeploymentFullClusterRestartIT.java | 2 +- .../upgrades/MLModelDeploymentsUpgradeIT.java | 2 +- .../MlAssignmentPlannerUpgradeIT.java | 11 ---------- 5 files changed, 2 insertions(+), 42 deletions(-) diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java index 04f349d67d7fe..3ca24edf25ada 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java @@ -560,15 +560,6 @@ public void testInferWithMultipleDocs() throws IOException { assertArrayEquals(expectedEmbeddings.get(i).toArray(), embedding.toArray()); } } - { - // the deprecated deployment/_infer endpoint does not support multiple docs - Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/deployment/_infer"); - request.setJsonEntity(String.format(Locale.ROOT, """ - { "docs": [%s] } - """, docsBuilder)); - Exception ex = expectThrows(Exception.class, () -> client().performRequest(request)); - assertThat(ex.getMessage(), containsString("multiple documents are not supported")); - } } public void testGetPytorchModelWithDefinition() throws IOException { diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/3rd_party_deployment.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/3rd_party_deployment.yml index 18332e14a4e34..6fbc5e346b0eb 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/3rd_party_deployment.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/3rd_party_deployment.yml @@ -271,8 +271,6 @@ setup: - match: { assignment.task_parameters.cache_size: 10kb } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -283,8 +281,6 @@ setup: } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -295,8 +291,6 @@ setup: } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -426,8 +420,6 @@ setup: - match: { assignment.task_parameters.cache_size: 10kb } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -438,8 +430,6 @@ setup: } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -450,8 +440,6 @@ setup: } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -475,8 +463,6 @@ setup: - match: { cleared: true } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model" body: > @@ -538,8 +524,6 @@ setup: model_id: "test_model" - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "pytorch" body: > @@ -610,8 +594,6 @@ setup: - match: { assignment.task_parameters.model_id: test_model } - match: { assignment.task_parameters.deployment_id: test_model_for_search } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model_for_search" body: > @@ -631,8 +613,6 @@ setup: - match: { assignment.task_parameters.model_id: test_model } - match: { assignment.task_parameters.deployment_id: test_model_for_ingest } - do: - allowed_warnings: - - '[POST /_ml/trained_models/{model_id}/deployment/_infer] is deprecated! Use [POST /_ml/trained_models/{model_id}/_infer] instead.' ml.infer_trained_model: model_id: "test_model_for_ingest" body: > diff --git a/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java index dc9afb1bec237..b4ada2f3ae2cd 100644 --- a/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java @@ -236,7 +236,7 @@ private Response getTrainedModelStats(String modelId) throws IOException { } private Response infer(String input, String modelId) throws IOException { - Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/deployment/_infer"); + Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/_infer"); request.setJsonEntity(Strings.format(""" { "docs": [{"input":"%s"}] } """, input)); diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java index 8c051d03d5f04..cf1eab937c744 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java @@ -296,7 +296,7 @@ private Response getTrainedModelStats(String modelId) throws IOException { } private Response infer(String input, String modelId) throws IOException { - Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/deployment/_infer"); + Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/_infer"); request.setJsonEntity(Strings.format(""" { "docs": [{"input":"%s"}] } """, input)); diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlAssignmentPlannerUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlAssignmentPlannerUpgradeIT.java index aa166311f6465..1f3db455c9ce7 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlAssignmentPlannerUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MlAssignmentPlannerUpgradeIT.java @@ -161,17 +161,6 @@ private Response getTrainedModelStats(String modelId) throws IOException { return response; } - private Response infer(String input, String modelId) throws IOException { - Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/deployment/_infer"); - request.setJsonEntity(Strings.format(""" - { "docs": [{"input":"%s"}] } - """, input)); - request.setOptions(request.getOptions().toBuilder().setWarningsHandler(PERMISSIVE).build()); - var response = client().performRequest(request); - assertOK(response); - return response; - } - private void putModelDefinition(String modelId) throws IOException { Request request = new Request("PUT", "_ml/trained_models/" + modelId + "/definition/0"); request.setJsonEntity(Strings.format(""" From 9645af02d9aed976f063f2a899656326a4a3149b Mon Sep 17 00:00:00 2001 From: David Kyle Date: Tue, 4 Mar 2025 21:34:36 +0000 Subject: [PATCH 4/5] upgrade tests --- .../rest-api-spec/test/ml/inference_crud.yml | 12 +----------- .../MLModelDeploymentFullClusterRestartIT.java | 18 ------------------ .../upgrades/MLModelDeploymentsUpgradeIT.java | 17 ----------------- 3 files changed, 1 insertion(+), 46 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/inference_crud.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/inference_crud.yml index a53e5be54e35b..18e3c73f98110 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/inference_crud.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/ml/inference_crud.yml @@ -931,17 +931,7 @@ setup: - is_false: trained_model_configs.0.estimated_heap_memory_usage - is_false: trained_model_configs.0.estimated_operations - is_false: trained_model_configs.0.license_level ---- -"Test deprecation of include model definition param": - - skip: - features: "warnings" - - do: - warnings: - - "[include_model_definition] parameter is deprecated! Use [include=definition] instead." - ml.get_trained_models: - model_id: "a-regression-model-1" - include_model_definition: true - decompress_definition: false + --- "Test put model model aliases": diff --git a/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java b/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java index b4ada2f3ae2cd..7ef15a13a16c5 100644 --- a/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java +++ b/x-pack/qa/full-cluster-restart/src/javaRestTest/java/org/elasticsearch/xpack/restart/MLModelDeploymentFullClusterRestartIT.java @@ -109,7 +109,6 @@ public void testDeploymentSurvivesRestart() throws Exception { assertBusy(() -> { try { assertInfer(modelId); - assertNewInfer(modelId); } catch (ResponseException e) { // assertBusy only loops on AssertionErrors, so we have // to convert failure status exceptions to these @@ -139,11 +138,6 @@ private void waitForDeploymentStarted(String modelId) throws Exception { private void assertInfer(String modelId) throws IOException { Response inference = infer("my words", modelId); - assertThat(EntityUtils.toString(inference.getEntity()), equalTo("{\"predicted_value\":[[1.0,1.0]]}")); - } - - private void assertNewInfer(String modelId) throws IOException { - Response inference = newInfer("my words", modelId); assertThat(EntityUtils.toString(inference.getEntity()), equalTo("{\"inference_results\":[{\"predicted_value\":[[1.0,1.0]]}]}")); } @@ -236,18 +230,6 @@ private Response getTrainedModelStats(String modelId) throws IOException { } private Response infer(String input, String modelId) throws IOException { - Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/_infer"); - request.setJsonEntity(Strings.format(""" - { "docs": [{"input":"%s"}] } - """, input)); - - request.setOptions(request.getOptions().toBuilder().setWarningsHandler(PERMISSIVE).build()); - var response = client().performRequest(request); - assertOK(response); - return response; - } - - private Response newInfer(String input, String modelId) throws IOException { Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/_infer"); request.setJsonEntity(Strings.format(""" { "docs": [{"input":"%s"}] } diff --git a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java index cf1eab937c744..adeaeae31be45 100644 --- a/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java +++ b/x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/MLModelDeploymentsUpgradeIT.java @@ -125,7 +125,6 @@ public void testTrainedModelDeployment() throws Exception { waitForDeploymentStarted(modelId); assertInfer(modelId); - assertNewInfer(modelId); stopDeployment(modelId); } default -> throw new UnsupportedOperationException("Unknown cluster type [" + CLUSTER_TYPE + "]"); @@ -179,11 +178,6 @@ private void waitForDeploymentStarted(String modelId) throws Exception { private void assertInfer(String modelId) throws IOException { Response inference = infer("my words", modelId); - assertThat(EntityUtils.toString(inference.getEntity()), equalTo("{\"predicted_value\":[[1.0,1.0]]}")); - } - - private void assertNewInfer(String modelId) throws IOException { - Response inference = newInfer("my words", modelId); assertThat(EntityUtils.toString(inference.getEntity()), equalTo("{\"inference_results\":[{\"predicted_value\":[[1.0,1.0]]}]}")); } @@ -296,17 +290,6 @@ private Response getTrainedModelStats(String modelId) throws IOException { } private Response infer(String input, String modelId) throws IOException { - Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/_infer"); - request.setJsonEntity(Strings.format(""" - { "docs": [{"input":"%s"}] } - """, input)); - request.setOptions(request.getOptions().toBuilder().setWarningsHandler(PERMISSIVE).build()); - var response = client().performRequest(request); - assertOK(response); - return response; - } - - private Response newInfer(String input, String modelId) throws IOException { Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/_infer"); request.setJsonEntity(Strings.format(""" { "docs": [{"input":"%s"}] } From cb87cca670ac59de15ef9ae29f61367ccdcc2e34 Mon Sep 17 00:00:00 2001 From: David Kyle Date: Wed, 5 Mar 2025 07:36:16 +0000 Subject: [PATCH 5/5] missing route --- .../xpack/ml/rest/inference/RestGetTrainedModelsAction.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java index d4822dc2e36db..509060c17274d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java @@ -44,7 +44,10 @@ public class RestGetTrainedModelsAction extends BaseRestHandler { @Override public List routes() { - return List.of(new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")); + return List.of( + new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"), + new Route(GET, BASE_PATH + "trained_models") + ); } private static final Map DEFAULT_TO_XCONTENT_VALUES = Collections.singletonMap(