Skip to content

Commit 9d1110e

Browse files
authored
[ML] Remove deprecated routes for ml trained models APIs (#124019) (#124117)
The 7.x routes for ml trained models _ml/inference/ have been deprecated since 8 and replaced with _ml/trained_models. Also removes query parameters that are no longer supported.
1 parent 8b78ee2 commit 9d1110e

File tree

16 files changed

+8
-326
lines changed

16 files changed

+8
-326
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/ml.get_trained_models.json

-7
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@
4343
"required":false,
4444
"description":"A comma-separate list of fields to optionally include. Valid options are 'definition' and 'total_feature_importance'. Default is none."
4545
},
46-
"include_model_definition":{
47-
"type":"boolean",
48-
"required":false,
49-
"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.",
50-
"default":false,
51-
"deprecated": true
52-
},
5346
"decompress_definition":{
5447
"type":"boolean",
5548
"required":false,

rest-api-spec/src/main/resources/rest-api-spec/api/ml.infer_trained_model.json

-17
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,6 @@
2424
"required":true
2525
}
2626
}
27-
},
28-
{
29-
"path":"/_ml/trained_models/{model_id}/deployment/_infer",
30-
"methods":[
31-
"POST"
32-
],
33-
"parts":{
34-
"model_id":{
35-
"type":"string",
36-
"description":"The unique identifier of the trained model.",
37-
"required":true
38-
}
39-
},
40-
"deprecated": {
41-
"version":"8.3.0",
42-
"description": "/_ml/trained_models/{model_id}/deployment/_infer is deprecated. Use /_ml/trained_models/{model_id}/_infer instead"
43-
}
4427
}
4528
]
4629
},

rest-api-spec/src/main/resources/rest-api-spec/api/ml.stop_datafeed.json

-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
"required":false,
3333
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)"
3434
},
35-
"allow_no_datafeeds":{
36-
"type":"boolean",
37-
"required":false,
38-
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)",
39-
"deprecated":true
40-
},
4135
"force":{
4236
"type":"boolean",
4337
"required":false,

x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/PyTorchModelIT.java

-9
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,6 @@ public void testInferWithMultipleDocs() throws IOException {
560560
assertArrayEquals(expectedEmbeddings.get(i).toArray(), embedding.toArray());
561561
}
562562
}
563-
{
564-
// the deprecated deployment/_infer endpoint does not support multiple docs
565-
Request request = new Request("POST", "/_ml/trained_models/" + modelId + "/deployment/_infer");
566-
request.setJsonEntity(String.format(Locale.ROOT, """
567-
{ "docs": [%s] }
568-
""", docsBuilder));
569-
Exception ex = expectThrows(Exception.class, () -> client().performRequest(request));
570-
assertThat(ex.getMessage(), containsString("multiple documents are not supported"));
571-
}
572563
}
573564

574565
public void testGetPytorchModelWithDefinition() throws IOException {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java

-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@
421421
import org.elasticsearch.xpack.ml.rest.inference.RestGetTrainedModelsAction;
422422
import org.elasticsearch.xpack.ml.rest.inference.RestGetTrainedModelsStatsAction;
423423
import org.elasticsearch.xpack.ml.rest.inference.RestInferTrainedModelAction;
424-
import org.elasticsearch.xpack.ml.rest.inference.RestInferTrainedModelDeploymentAction;
425424
import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelAction;
426425
import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelAliasAction;
427426
import org.elasticsearch.xpack.ml.rest.inference.RestPutTrainedModelDefinitionPartAction;
@@ -1502,7 +1501,6 @@ public List<RestHandler> getRestHandlers(
15021501
if (machineLearningExtension.get().isNlpEnabled()) {
15031502
restHandlers.add(new RestStartTrainedModelDeploymentAction(machineLearningExtension.get().disableInferenceProcessCache()));
15041503
restHandlers.add(new RestStopTrainedModelDeploymentAction());
1505-
restHandlers.add(new RestInferTrainedModelDeploymentAction());
15061504
restHandlers.add(new RestUpdateTrainedModelDeploymentAction());
15071505
restHandlers.add(new RestPutTrainedModelVocabularyAction());
15081506
restHandlers.add(new RestClearDeploymentCacheAction());

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportTrainedModelCacheInfoAction.java

-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import org.elasticsearch.cluster.node.DiscoveryNode;
1414
import org.elasticsearch.cluster.service.ClusterService;
1515
import org.elasticsearch.common.io.stream.StreamInput;
16-
import org.elasticsearch.common.io.stream.StreamOutput;
17-
import org.elasticsearch.core.UpdateForV9;
1816
import org.elasticsearch.injection.guice.Inject;
1917
import org.elasticsearch.tasks.CancellableTask;
2018
import org.elasticsearch.tasks.Task;
@@ -87,7 +85,6 @@ protected CacheInfo nodeOperation(NodeModelCacheInfoRequest nodeModelCacheInfoRe
8785
);
8886
}
8987

90-
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING) // this can be replaced with TransportRequest.Empty in v9
9188
public static class NodeModelCacheInfoRequest extends TransportRequest {
9289

9390
NodeModelCacheInfoRequest() {}
@@ -100,10 +97,5 @@ public NodeModelCacheInfoRequest(StreamInput in) throws IOException {
10097
public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String, String> headers) {
10198
return new CancellableTask(id, type, action, "", parentTaskId, headers);
10299
}
103-
104-
@Override
105-
public void writeTo(StreamOutput out) throws IOException {
106-
super.writeTo(out);
107-
}
108100
}
109101
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java

+1-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.elasticsearch.action.support.master.AcknowledgedRequest;
1010
import org.elasticsearch.client.internal.node.NodeClient;
1111
import org.elasticsearch.core.TimeValue;
12-
import org.elasticsearch.core.UpdateForV9;
1312
import org.elasticsearch.rest.BaseRestHandler;
1413
import org.elasticsearch.rest.RestRequest;
1514
import org.elasticsearch.rest.Scope;
@@ -28,22 +27,9 @@
2827
@ServerlessScope(Scope.PUBLIC)
2928
public class RestDeleteTrainedModelAction extends BaseRestHandler {
3029

31-
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
32-
// one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access
33-
// that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will
34-
// continue to emit deprecations warnings but will not require any special headers to access the API in v9.
35-
// Please review and update the code and tests as needed. The original code remains commented out below for reference.
3630
@Override
3731
public List<Route> routes() {
38-
return List.of(
39-
// Route.builder(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")
40-
// .replaces(DELETE, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8)
41-
// .build()
42-
new Route(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"),
43-
Route.builder(DELETE, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}")
44-
.deprecateAndKeep("Use the trained_models API instead.")
45-
.build()
46-
);
32+
return List.of(new Route(DELETE, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"));
4733
}
4834

4935
@Override

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java

+4-37
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import org.elasticsearch.client.internal.node.NodeClient;
1010
import org.elasticsearch.cluster.metadata.Metadata;
1111
import org.elasticsearch.common.Strings;
12-
import org.elasticsearch.common.logging.DeprecationCategory;
13-
import org.elasticsearch.common.logging.DeprecationLogger;
14-
import org.elasticsearch.core.UpdateForV9;
1512
import org.elasticsearch.rest.BaseRestHandler;
1613
import org.elasticsearch.rest.RestChannel;
1714
import org.elasticsearch.rest.RestRequest;
@@ -38,35 +35,18 @@
3835

3936
import static java.util.Arrays.asList;
4037
import static org.elasticsearch.rest.RestRequest.Method.GET;
41-
import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Includes.DEFINITION;
4238
import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH;
4339
import static org.elasticsearch.xpack.core.ml.utils.ToXContentParams.EXCLUDE_GENERATED;
4440
import static org.elasticsearch.xpack.ml.MachineLearning.BASE_PATH;
4541

4642
@ServerlessScope(Scope.PUBLIC)
4743
public class RestGetTrainedModelsAction extends BaseRestHandler {
4844

49-
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetTrainedModelsAction.class);
50-
private static final String INCLUDE_MODEL_DEFINITION = "include_model_definition";
51-
52-
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
53-
// one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access
54-
// that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will
55-
// continue to emit deprecations warnings but will not require any special headers to access the API in v9.
56-
// Please review and update the code and tests as needed. The original code remains commented out below for reference.
5745
@Override
5846
public List<Route> routes() {
5947
return List.of(
60-
// Route.builder(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}")
61-
// .replaces(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}", RestApiVersion.V_8)
62-
// .build(),
63-
// Route.builder(GET, BASE_PATH + "trained_models").replaces(GET, BASE_PATH + "inference", RestApiVersion.V_8).build()
6448
new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}"),
65-
Route.builder(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}")
66-
.deprecateAndKeep("Use the trained_models API instead.")
67-
.build(),
68-
new Route(GET, BASE_PATH + "trained_models"),
69-
Route.builder(GET, BASE_PATH + "inference").deprecateAndKeep("Use the trained_models API instead.").build()
49+
new Route(GET, BASE_PATH + "trained_models")
7050
);
7151
}
7252

@@ -90,22 +70,9 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
9070
Set<String> includes = new HashSet<>(
9171
asList(restRequest.paramAsStringArray(GetTrainedModelsAction.Request.INCLUDE.getPreferredName(), Strings.EMPTY_ARRAY))
9272
);
93-
final GetTrainedModelsAction.Request request;
94-
if (restRequest.hasParam(INCLUDE_MODEL_DEFINITION)) {
95-
deprecationLogger.warn(
96-
DeprecationCategory.API,
97-
INCLUDE_MODEL_DEFINITION,
98-
"[{}] parameter is deprecated! Use [include=definition] instead.",
99-
INCLUDE_MODEL_DEFINITION
100-
);
101-
request = new GetTrainedModelsAction.Request(
102-
modelId,
103-
tags,
104-
restRequest.paramAsBoolean(INCLUDE_MODEL_DEFINITION, false) ? Set.of(DEFINITION) : Set.of()
105-
);
106-
} else {
107-
request = new GetTrainedModelsAction.Request(modelId, tags, includes);
108-
}
73+
74+
final GetTrainedModelsAction.Request request = new GetTrainedModelsAction.Request(modelId, tags, includes);
75+
10976
if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
11077
request.setPageParams(
11178
new PageParams(

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.elasticsearch.client.internal.node.NodeClient;
1010
import org.elasticsearch.cluster.metadata.Metadata;
1111
import org.elasticsearch.common.Strings;
12-
import org.elasticsearch.core.UpdateForV9;
1312
import org.elasticsearch.rest.BaseRestHandler;
1413
import org.elasticsearch.rest.RestRequest;
1514
import org.elasticsearch.rest.Scope;
@@ -30,26 +29,11 @@
3029
@ServerlessScope(Scope.PUBLIC)
3130
public class RestGetTrainedModelsStatsAction extends BaseRestHandler {
3231

33-
@UpdateForV9(owner = UpdateForV9.Owner.MACHINE_LEARNING)
34-
// one or more routes use ".replaces" with RestApiVersion.V_8 which will require use of REST API compatibility headers to access
35-
// that route in v9. It is unclear if this was intentional for v9, and the code has been updated to ".deprecateAndKeep" which will
36-
// continue to emit deprecations warnings but will not require any special headers to access the API in v9.
37-
// Please review and update the code and tests as needed. The original code remains commented out below for reference.
3832
@Override
3933
public List<Route> routes() {
4034
return List.of(
41-
// Route.builder(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}/_stats")
42-
// .replaces(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}/_stats", RestApiVersion.V_8)
43-
// .build(),
44-
// Route.builder(GET, BASE_PATH + "trained_models/_stats")
45-
// .replaces(GET, BASE_PATH + "inference/_stats", RestApiVersion.V_8)
46-
// .build()
4735
new Route(GET, BASE_PATH + "trained_models/{" + TrainedModelConfig.MODEL_ID + "}/_stats"),
48-
Route.builder(GET, BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID + "}/_stats")
49-
.deprecateAndKeep("Use the trained_models API instead.")
50-
.build(),
51-
new Route(GET, BASE_PATH + "trained_models/_stats"),
52-
Route.builder(GET, BASE_PATH + "inference/_stats").deprecateAndKeep("Use the trained_models API instead.").build()
36+
new Route(GET, BASE_PATH + "trained_models/_stats")
5337
);
5438
}
5539

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestInferTrainedModelDeploymentAction.java

-116
This file was deleted.

0 commit comments

Comments
 (0)