Skip to content

Commit 0be3db8

Browse files
authored
[ML] removing allow_no_[datafeeds|jobs] from v8 APIs (#80048) (#80134)
This removes the deprecated params `allow_no_datafeeds` and `allow_no_jobs` from v8 rest APIs. The params still exist and are deprecated in v7 REST APIs. closes #60732
1 parent 5cc1cbc commit 0be3db8

32 files changed

+169
-303
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/cat.ml_datafeeds.json

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
"required":false,
3838
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)"
3939
},
40-
"allow_no_datafeeds":{
41-
"type":"boolean",
42-
"required":false,
43-
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)",
44-
"deprecated":true
45-
},
4640
"format":{
4741
"type":"string",
4842
"description":"a short version of the Accept header, e.g. json, yaml"

rest-api-spec/src/main/resources/rest-api-spec/api/cat.ml_jobs.json

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
"required":false,
3838
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)"
3939
},
40-
"allow_no_jobs":{
41-
"type":"boolean",
42-
"required":false,
43-
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)",
44-
"deprecated":true
45-
},
4640
"bytes":{
4741
"type":"enum",
4842
"description":"The unit in which to display byte values",

rest-api-spec/src/main/resources/rest-api-spec/api/ml.close_job.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 jobs. (This includes `_all` string or when no jobs have been specified)"
3434
},
35-
"allow_no_jobs":{
36-
"type":"boolean",
37-
"required":false,
38-
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)",
39-
"deprecated":true
40-
},
4135
"force":{
4236
"type":"boolean",
4337
"required":false,

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

-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
"type":"boolean",
3737
"required":false,
3838
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)"
39-
},
40-
"allow_no_datafeeds":{
41-
"type":"boolean",
42-
"required":false,
43-
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)",
44-
"deprecated":true
4539
}
4640
}
4741
}

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

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
"required":false,
3838
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)"
3939
},
40-
"allow_no_datafeeds":{
41-
"type":"boolean",
42-
"required":false,
43-
"description":"Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified)",
44-
"deprecated":true
45-
},
4640
"exclude_generated": {
4741
"required": false,
4842
"type": "boolean",

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

-6
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,6 @@
3636
"type":"boolean",
3737
"required":false,
3838
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)"
39-
},
40-
"allow_no_jobs":{
41-
"type":"boolean",
42-
"required":false,
43-
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)",
44-
"deprecated":true
4539
}
4640
}
4741
}

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

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
"required":false,
3838
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)"
3939
},
40-
"allow_no_jobs":{
41-
"type":"boolean",
42-
"required":false,
43-
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)",
44-
"deprecated":true
45-
},
4640
"exclude_generated": {
4741
"required": false,
4842
"type": "boolean",

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

-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@
5555
"allow_no_match":{
5656
"type":"boolean",
5757
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)"
58-
},
59-
"allow_no_jobs":{
60-
"type":"boolean",
61-
"description":"Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified)",
62-
"deprecated":true
6358
}
6459
},
6560
"body":{

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

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import java.util.stream.Collectors;
2222

2323
public final class MachineLearningField {
24+
25+
public static final String DEPRECATED_ALLOW_NO_JOBS_PARAM = "allow_no_jobs";
26+
public static final String DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM = "allow_no_datafeeds";
27+
2428
public static final Setting<Boolean> AUTODETECT_PROCESS = Setting.boolSetting(
2529
"xpack.ml.autodetect_process",
2630
true,

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
1414
import org.elasticsearch.common.io.stream.Writeable;
15+
import org.elasticsearch.core.RestApiVersion;
1516
import org.elasticsearch.core.TimeValue;
1617
import org.elasticsearch.tasks.Task;
1718
import org.elasticsearch.xcontent.ObjectParser;
@@ -25,6 +26,10 @@
2526
import java.io.IOException;
2627
import java.util.Objects;
2728

29+
import static org.elasticsearch.core.RestApiVersion.equalTo;
30+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
31+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_JOBS_PARAM;
32+
2833
public class CloseJobAction extends ActionType<CloseJobAction.Response> {
2934

3035
public static final CloseJobAction INSTANCE = new CloseJobAction();
@@ -38,9 +43,9 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
3843

3944
public static final ParseField TIMEOUT = new ParseField("timeout");
4045
public static final ParseField FORCE = new ParseField("force");
41-
@Deprecated
42-
public static final String ALLOW_NO_JOBS = "allow_no_jobs";
43-
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match", ALLOW_NO_JOBS);
46+
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match").forRestApiVersion(onOrAfter(RestApiVersion.V_8));
47+
public static final ParseField ALLOW_NO_MATCH_V7 = new ParseField("allow_no_match", DEPRECATED_ALLOW_NO_JOBS_PARAM)
48+
.forRestApiVersion(equalTo(RestApiVersion.V_7));
4449
public static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);
4550

4651
static {
@@ -51,6 +56,7 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
5156
);
5257
PARSER.declareBoolean(Request::setForce, FORCE);
5358
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH);
59+
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH_V7);
5460
}
5561

5662
public static Request parseRequest(String jobId, XContentParser parser) {
@@ -173,7 +179,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
173179
builder.field(Job.ID.getPreferredName(), jobId);
174180
builder.field(TIMEOUT.getPreferredName(), timeout.getStringRep());
175181
builder.field(FORCE.getPreferredName(), force);
176-
builder.field(ALLOW_NO_MATCH.getPreferredName(), allowNoMatch);
182+
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
183+
builder.field(DEPRECATED_ALLOW_NO_JOBS_PARAM, allowNoMatch);
184+
} else {
185+
builder.field(ALLOW_NO_MATCH.getPreferredName(), allowNoMatch);
186+
}
177187
builder.endObject();
178188
return builder;
179189
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ private GetDatafeedsAction() {
3333

3434
public static class Request extends MasterNodeReadRequest<Request> {
3535

36-
@Deprecated
37-
public static final String ALLOW_NO_DATAFEEDS = "allow_no_datafeeds";
3836
public static final String ALLOW_NO_MATCH = "allow_no_match";
3937

4038
private String datafeedId;

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

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ private GetDatafeedsStatsAction() {
5454

5555
public static class Request extends MasterNodeReadRequest<Request> {
5656

57-
@Deprecated
58-
public static final String ALLOW_NO_DATAFEEDS = "allow_no_datafeeds";
5957
public static final String ALLOW_NO_MATCH = "allow_no_match";
6058

6159
private String datafeedId;

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

-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ private GetJobsAction() {
3131

3232
public static class Request extends MasterNodeReadRequest<Request> {
3333

34-
@Deprecated
35-
public static final String ALLOW_NO_JOBS = "allow_no_jobs";
3634
public static final String ALLOW_NO_MATCH = "allow_no_match";
3735

3836
private String jobId;

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

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ private GetJobsStatsAction() {
5858

5959
public static class Request extends BaseTasksRequest<Request> {
6060

61-
@Deprecated
62-
public static final String ALLOW_NO_JOBS = "allow_no_jobs";
6361
public static final String ALLOW_NO_MATCH = "allow_no_match";
6462

6563
private String jobId;

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.common.time.DateMathParser;
16+
import org.elasticsearch.core.RestApiVersion;
1617
import org.elasticsearch.core.TimeValue;
1718
import org.elasticsearch.index.mapper.DateFieldMapper;
1819
import org.elasticsearch.xcontent.ObjectParser;
@@ -31,6 +32,10 @@
3132
import java.util.Objects;
3233
import java.util.function.LongSupplier;
3334

35+
import static org.elasticsearch.core.RestApiVersion.equalTo;
36+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
37+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_JOBS_PARAM;
38+
3439
/**
3540
* <p>
3641
* This action returns summarized bucket results over multiple jobs.
@@ -62,9 +67,9 @@ public static class Request extends ActionRequest implements ToXContentObject {
6267
public static final ParseField EXCLUDE_INTERIM = new ParseField("exclude_interim");
6368
public static final ParseField START = new ParseField("start");
6469
public static final ParseField END = new ParseField("end");
65-
@Deprecated
66-
public static final String ALLOW_NO_JOBS = "allow_no_jobs";
67-
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match", ALLOW_NO_JOBS);
70+
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match").forRestApiVersion(onOrAfter(RestApiVersion.V_8));
71+
public static final ParseField ALLOW_NO_MATCH_V7 = new ParseField("allow_no_match", DEPRECATED_ALLOW_NO_JOBS_PARAM)
72+
.forRestApiVersion(equalTo(RestApiVersion.V_7));
6873

6974
private static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);
7075

@@ -80,6 +85,7 @@ public static class Request extends ActionRequest implements ToXContentObject {
8085
);
8186
PARSER.declareString((request, endTime) -> request.setEnd(parseDateOrThrow(endTime, END, System::currentTimeMillis)), END);
8287
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH);
88+
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH_V7);
8389
}
8490

8591
static long parseDateOrThrow(String date, ParseField paramName, LongSupplier now) {
@@ -237,7 +243,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
237243
if (end != null) {
238244
builder.field(END.getPreferredName(), String.valueOf(end));
239245
}
240-
builder.field(ALLOW_NO_MATCH.getPreferredName(), allowNoMatch);
246+
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
247+
builder.field(DEPRECATED_ALLOW_NO_JOBS_PARAM, allowNoMatch);
248+
} else {
249+
builder.field(ALLOW_NO_MATCH.getPreferredName(), allowNoMatch);
250+
}
241251
builder.endObject();
242252
return builder;
243253
}

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.common.io.stream.Writeable;
16+
import org.elasticsearch.core.RestApiVersion;
1617
import org.elasticsearch.core.TimeValue;
1718
import org.elasticsearch.tasks.Task;
1819
import org.elasticsearch.xcontent.ObjectParser;
@@ -27,6 +28,10 @@
2728
import java.io.IOException;
2829
import java.util.Objects;
2930

31+
import static org.elasticsearch.core.RestApiVersion.equalTo;
32+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
33+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM;
34+
3035
public class StopDatafeedAction extends ActionType<StopDatafeedAction.Response> {
3136

3237
public static final StopDatafeedAction INSTANCE = new StopDatafeedAction();
@@ -41,9 +46,9 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
4146

4247
public static final ParseField TIMEOUT = new ParseField("timeout");
4348
public static final ParseField FORCE = new ParseField("force");
44-
@Deprecated
45-
public static final String ALLOW_NO_DATAFEEDS = "allow_no_datafeeds";
46-
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match", ALLOW_NO_DATAFEEDS);
49+
public static final ParseField ALLOW_NO_MATCH = new ParseField("allow_no_match").forRestApiVersion(onOrAfter(RestApiVersion.V_8));
50+
public static final ParseField ALLOW_NO_MATCH_V7 = new ParseField("allow_no_match", DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM)
51+
.forRestApiVersion(equalTo(RestApiVersion.V_7));
4752

4853
public static final ObjectParser<Request, Void> PARSER = new ObjectParser<>(NAME, Request::new);
4954
static {
@@ -54,6 +59,7 @@ public static class Request extends BaseTasksRequest<Request> implements ToXCont
5459
);
5560
PARSER.declareBoolean(Request::setForce, FORCE);
5661
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH);
62+
PARSER.declareBoolean(Request::setAllowNoMatch, ALLOW_NO_MATCH_V7);
5763
}
5864

5965
public static Request fromXContent(XContentParser parser) {
@@ -167,7 +173,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
167173
builder.field(DatafeedConfig.ID.getPreferredName(), datafeedId);
168174
builder.field(TIMEOUT.getPreferredName(), stopTimeout.getStringRep());
169175
builder.field(FORCE.getPreferredName(), force);
170-
builder.field(ALLOW_NO_MATCH.getPreferredName(), allowNoMatch);
176+
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
177+
builder.field(DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM, allowNoMatch);
178+
} else {
179+
builder.field(ALLOW_NO_MATCH.getPreferredName(), allowNoMatch);
180+
}
171181
builder.endObject();
172182
return builder;
173183
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.ml.rest;
9+
10+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
11+
import org.elasticsearch.core.RestApiVersion;
12+
import org.elasticsearch.rest.RestRequest;
13+
14+
import java.util.function.BiFunction;
15+
import java.util.function.Consumer;
16+
17+
public final class RestCompatibilityChecker {
18+
19+
private RestCompatibilityChecker() {}
20+
21+
public static <T> void checkAndSetDeprecatedParam(
22+
String deprecatedParam,
23+
String newParam,
24+
RestApiVersion compatVersion,
25+
RestRequest restRequest,
26+
BiFunction<RestRequest, String, T> extractor,
27+
Consumer<T> setter
28+
) {
29+
final T paramValue;
30+
if (restRequest.getRestApiVersion() == compatVersion && restRequest.hasParam(deprecatedParam)) {
31+
LoggingDeprecationHandler.INSTANCE.logRenamedField(null, () -> null, deprecatedParam, newParam, true);
32+
paramValue = extractor.apply(restRequest, deprecatedParam);
33+
} else {
34+
paramValue = extractor.apply(restRequest, newParam);
35+
}
36+
setter.accept(paramValue);
37+
}
38+
39+
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.elasticsearch.cluster.node.DiscoveryNode;
1111
import org.elasticsearch.common.Strings;
1212
import org.elasticsearch.common.Table;
13-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
13+
import org.elasticsearch.core.RestApiVersion;
1414
import org.elasticsearch.core.TimeValue;
1515
import org.elasticsearch.rest.RestRequest;
1616
import org.elasticsearch.rest.RestResponse;
@@ -27,6 +27,8 @@
2727
import java.util.List;
2828

2929
import static org.elasticsearch.rest.RestRequest.Method.GET;
30+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM;
31+
import static org.elasticsearch.xpack.ml.rest.RestCompatibilityChecker.checkAndSetDeprecatedParam;
3032

3133
public class RestCatDatafeedsAction extends AbstractCatAction {
3234

@@ -47,14 +49,13 @@ protected RestChannelConsumer doCatRequest(RestRequest restRequest, NodeClient c
4749
datafeedId = GetDatafeedsStatsAction.ALL;
4850
}
4951
Request request = new Request(datafeedId);
50-
if (restRequest.hasParam(Request.ALLOW_NO_DATAFEEDS)) {
51-
LoggingDeprecationHandler.INSTANCE.logRenamedField(null, () -> null, Request.ALLOW_NO_DATAFEEDS, Request.ALLOW_NO_MATCH);
52-
}
53-
request.setAllowNoMatch(
54-
restRequest.paramAsBoolean(
55-
Request.ALLOW_NO_MATCH,
56-
restRequest.paramAsBoolean(Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())
57-
)
52+
checkAndSetDeprecatedParam(
53+
DEPRECATED_ALLOW_NO_DATAFEEDS_PARAM,
54+
Request.ALLOW_NO_MATCH,
55+
RestApiVersion.V_7,
56+
restRequest,
57+
(r, s) -> r.paramAsBoolean(s, request.allowNoMatch()),
58+
request::setAllowNoMatch
5859
);
5960
return channel -> client.execute(GetDatafeedsStatsAction.INSTANCE, request, new RestResponseListener<>(channel) {
6061
@Override

0 commit comments

Comments
 (0)