Skip to content

Commit 7b18fd6

Browse files
committed
Apply review comment: Emit deprecation warnings for request params
1 parent 53dee5d commit 7b18fd6

9 files changed

+79
-32
lines changed

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.cluster.node.DiscoveryNode;
1010
import org.elasticsearch.common.Strings;
1111
import org.elasticsearch.common.Table;
12+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1213
import org.elasticsearch.xpack.core.common.table.TableColumnAttributeBuilder;
1314
import org.elasticsearch.common.unit.TimeValue;
1415
import org.elasticsearch.rest.RestRequest;
@@ -17,6 +18,8 @@
1718
import org.elasticsearch.rest.action.cat.AbstractCatAction;
1819
import org.elasticsearch.rest.action.cat.RestTable;
1920
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction;
21+
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction.Request;
22+
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction.Response;
2023
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
2124
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedTimingStats;
2225

@@ -44,14 +47,17 @@ protected RestChannelConsumer doCatRequest(RestRequest restRequest, NodeClient c
4447
if (Strings.isNullOrEmpty(datafeedId)) {
4548
datafeedId = GetDatafeedsStatsAction.ALL;
4649
}
47-
GetDatafeedsStatsAction.Request request = new GetDatafeedsStatsAction.Request(datafeedId);
50+
Request request = new Request(datafeedId);
51+
if (restRequest.hasParam(Request.ALLOW_NO_DATAFEEDS)) {
52+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(null, () -> null, Request.ALLOW_NO_DATAFEEDS, Request.ALLOW_NO_MATCH);
53+
}
4854
request.setAllowNoMatch(
4955
restRequest.paramAsBoolean(
50-
GetDatafeedsStatsAction.Request.ALLOW_NO_MATCH,
51-
restRequest.paramAsBoolean(GetDatafeedsStatsAction.Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
56+
Request.ALLOW_NO_MATCH,
57+
restRequest.paramAsBoolean(Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
5258
return channel -> client.execute(GetDatafeedsStatsAction.INSTANCE, request, new RestResponseListener<>(channel) {
5359
@Override
54-
public RestResponse buildResponse(GetDatafeedsStatsAction.Response getDatafeedsStatsRespons) throws Exception {
60+
public RestResponse buildResponse(Response getDatafeedsStatsRespons) throws Exception {
5561
return RestTable.buildResponse(buildTable(restRequest, getDatafeedsStatsRespons), channel);
5662
}
5763
});
@@ -124,7 +130,7 @@ protected Table getTableWithHeader(RestRequest request) {
124130
return table;
125131
}
126132

127-
private Table buildTable(RestRequest request, GetDatafeedsStatsAction.Response dfStats) {
133+
private Table buildTable(RestRequest request, Response dfStats) {
128134
Table table = getTableWithHeader(request);
129135
dfStats.getResponse().results().forEach(df -> {
130136
table.startRow();

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +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;
1314
import org.elasticsearch.xpack.core.common.table.TableColumnAttributeBuilder;
1415
import org.elasticsearch.common.unit.ByteSizeValue;
1516
import org.elasticsearch.common.unit.TimeValue;
@@ -19,6 +20,8 @@
1920
import org.elasticsearch.rest.action.cat.AbstractCatAction;
2021
import org.elasticsearch.rest.action.cat.RestTable;
2122
import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction;
23+
import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction.Request;
24+
import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction.Response;
2225
import org.elasticsearch.xpack.core.ml.job.config.Job;
2326
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts;
2427
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats;
@@ -49,14 +52,17 @@ protected RestChannelConsumer doCatRequest(RestRequest restRequest, NodeClient c
4952
if (Strings.isNullOrEmpty(jobId)) {
5053
jobId = Metadata.ALL;
5154
}
52-
GetJobsStatsAction.Request request = new GetJobsStatsAction.Request(jobId);
55+
Request request = new Request(jobId);
56+
if (restRequest.hasParam(Request.ALLOW_NO_JOBS)) {
57+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(null, () -> null, Request.ALLOW_NO_JOBS, Request.ALLOW_NO_MATCH);
58+
}
5359
request.setAllowNoMatch(
5460
restRequest.paramAsBoolean(
55-
GetJobsStatsAction.Request.ALLOW_NO_MATCH,
56-
restRequest.paramAsBoolean(GetJobsStatsAction.Request.ALLOW_NO_JOBS, request.allowNoMatch())));
61+
Request.ALLOW_NO_MATCH,
62+
restRequest.paramAsBoolean(Request.ALLOW_NO_JOBS, request.allowNoMatch())));
5763
return channel -> client.execute(GetJobsStatsAction.INSTANCE, request, new RestResponseListener<>(channel) {
5864
@Override
59-
public RestResponse buildResponse(GetJobsStatsAction.Response getJobStatsResponse) throws Exception {
65+
public RestResponse buildResponse(Response getJobStatsResponse) throws Exception {
6066
return RestTable.buildResponse(buildTable(restRequest, getJobStatsResponse), channel);
6167
}
6268
});
@@ -324,7 +330,7 @@ protected Table getTableWithHeader(RestRequest request) {
324330
return table;
325331
}
326332

327-
private Table buildTable(RestRequest request, GetJobsStatsAction.Response jobStats) {
333+
private Table buildTable(RestRequest request, Response jobStats) {
328334
Table table = getTableWithHeader(request);
329335
jobStats.getResponse().results().forEach(job -> {
330336
table.startRow();

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
import org.elasticsearch.client.node.NodeClient;
99
import org.elasticsearch.common.Strings;
10+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1011
import org.elasticsearch.rest.BaseRestHandler;
1112
import org.elasticsearch.rest.RestRequest;
1213
import org.elasticsearch.rest.action.RestToXContentListener;
1314
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction;
15+
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction.Request;
1416
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
1517
import org.elasticsearch.xpack.ml.MachineLearning;
1618

@@ -40,11 +42,14 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
4042
if (Strings.isNullOrEmpty(datafeedId)) {
4143
datafeedId = GetDatafeedsStatsAction.ALL;
4244
}
43-
GetDatafeedsStatsAction.Request request = new GetDatafeedsStatsAction.Request(datafeedId);
45+
Request request = new Request(datafeedId);
46+
if (restRequest.hasParam(Request.ALLOW_NO_DATAFEEDS)) {
47+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(null, () -> null, Request.ALLOW_NO_DATAFEEDS, Request.ALLOW_NO_MATCH);
48+
}
4449
request.setAllowNoMatch(
4550
restRequest.paramAsBoolean(
46-
GetDatafeedsStatsAction.Request.ALLOW_NO_MATCH,
47-
restRequest.paramAsBoolean(GetDatafeedsStatsAction.Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
51+
Request.ALLOW_NO_MATCH,
52+
restRequest.paramAsBoolean(Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
4853
return channel -> client.execute(GetDatafeedsStatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
4954
}
5055
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
package org.elasticsearch.xpack.ml.rest.datafeeds;
77

88
import org.elasticsearch.client.node.NodeClient;
9+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
910
import org.elasticsearch.rest.BaseRestHandler;
1011
import org.elasticsearch.rest.RestRequest;
1112
import org.elasticsearch.rest.action.RestToXContentListener;
1213
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction;
14+
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction.Request;
1315
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
1416
import org.elasticsearch.xpack.ml.MachineLearning;
1517

@@ -39,11 +41,14 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
3941
if (datafeedId == null) {
4042
datafeedId = GetDatafeedsAction.ALL;
4143
}
42-
GetDatafeedsAction.Request request = new GetDatafeedsAction.Request(datafeedId);
44+
Request request = new Request(datafeedId);
45+
if (restRequest.hasParam(Request.ALLOW_NO_DATAFEEDS)) {
46+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(null, () -> null, Request.ALLOW_NO_DATAFEEDS, Request.ALLOW_NO_MATCH);
47+
}
4348
request.setAllowNoMatch(
4449
restRequest.paramAsBoolean(
45-
GetDatafeedsAction.Request.ALLOW_NO_MATCH,
46-
restRequest.paramAsBoolean(GetDatafeedsAction.Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
50+
Request.ALLOW_NO_MATCH,
51+
restRequest.paramAsBoolean(Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
4752
return channel -> client.execute(GetDatafeedsAction.INSTANCE, request, new RestToXContentListener<>(channel));
4853
}
4954
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.client.node.NodeClient;
99
import org.elasticsearch.common.unit.TimeValue;
10+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1011
import org.elasticsearch.common.xcontent.XContentBuilder;
1112
import org.elasticsearch.common.xcontent.XContentParser;
1213
import org.elasticsearch.rest.BaseRestHandler;
@@ -16,6 +17,7 @@
1617
import org.elasticsearch.rest.RestStatus;
1718
import org.elasticsearch.rest.action.RestBuilderListener;
1819
import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction;
20+
import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction.Request;
1921
import org.elasticsearch.xpack.core.ml.action.StopDatafeedAction.Response;
2022
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig;
2123
import org.elasticsearch.xpack.ml.MachineLearning;
@@ -43,24 +45,27 @@ public String getName() {
4345
@Override
4446
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
4547
String datafeedId = restRequest.param(DatafeedConfig.ID.getPreferredName());
46-
StopDatafeedAction.Request request;
48+
Request request;
4749
if (restRequest.hasContentOrSourceParam()) {
4850
XContentParser parser = restRequest.contentOrSourceParamParser();
49-
request = StopDatafeedAction.Request.parseRequest(datafeedId, parser);
51+
request = Request.parseRequest(datafeedId, parser);
5052
} else {
51-
request = new StopDatafeedAction.Request(datafeedId);
52-
if (restRequest.hasParam(StopDatafeedAction.Request.TIMEOUT.getPreferredName())) {
53-
TimeValue stopTimeout = restRequest.paramAsTime(
54-
StopDatafeedAction.Request.TIMEOUT.getPreferredName(), StopDatafeedAction.DEFAULT_TIMEOUT);
53+
request = new Request(datafeedId);
54+
if (restRequest.hasParam(Request.TIMEOUT.getPreferredName())) {
55+
TimeValue stopTimeout = restRequest.paramAsTime(Request.TIMEOUT.getPreferredName(), StopDatafeedAction.DEFAULT_TIMEOUT);
5556
request.setStopTimeout(stopTimeout);
5657
}
57-
if (restRequest.hasParam(StopDatafeedAction.Request.FORCE.getPreferredName())) {
58-
request.setForce(restRequest.paramAsBoolean(StopDatafeedAction.Request.FORCE.getPreferredName(), request.isForce()));
58+
if (restRequest.hasParam(Request.FORCE.getPreferredName())) {
59+
request.setForce(restRequest.paramAsBoolean(Request.FORCE.getPreferredName(), request.isForce()));
60+
}
61+
if (restRequest.hasParam(Request.ALLOW_NO_DATAFEEDS)) {
62+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(
63+
null, () -> null, Request.ALLOW_NO_DATAFEEDS, Request.ALLOW_NO_MATCH.getPreferredName());
5964
}
6065
request.setAllowNoMatch(
6166
restRequest.paramAsBoolean(
62-
StopDatafeedAction.Request.ALLOW_NO_MATCH.getPreferredName(),
63-
restRequest.paramAsBoolean(StopDatafeedAction.Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
67+
Request.ALLOW_NO_MATCH.getPreferredName(),
68+
restRequest.paramAsBoolean(Request.ALLOW_NO_DATAFEEDS, request.allowNoMatch())));
6469
}
6570
return channel -> client.execute(StopDatafeedAction.INSTANCE, request, new RestBuilderListener<Response>(channel) {
6671

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.elasticsearch.client.node.NodeClient;
99
import org.elasticsearch.common.unit.TimeValue;
10+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1011
import org.elasticsearch.rest.BaseRestHandler;
1112
import org.elasticsearch.rest.RestRequest;
1213
import org.elasticsearch.rest.action.RestToXContentListener;
@@ -49,6 +50,10 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
4950
if (restRequest.hasParam(Request.FORCE.getPreferredName())) {
5051
request.setForce(restRequest.paramAsBoolean(Request.FORCE.getPreferredName(), request.isForce()));
5152
}
53+
if (restRequest.hasParam(Request.ALLOW_NO_JOBS)) {
54+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(
55+
null, () -> null, Request.ALLOW_NO_JOBS, Request.ALLOW_NO_MATCH.getPreferredName());
56+
}
5257
request.setAllowNoMatch(
5358
restRequest.paramAsBoolean(
5459
Request.ALLOW_NO_MATCH.getPreferredName(),

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import org.elasticsearch.client.node.NodeClient;
99
import org.elasticsearch.cluster.metadata.Metadata;
1010
import org.elasticsearch.common.Strings;
11+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1112
import org.elasticsearch.rest.BaseRestHandler;
1213
import org.elasticsearch.rest.RestRequest;
1314
import org.elasticsearch.rest.action.RestToXContentListener;
1415
import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction;
16+
import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction.Request;
1517
import org.elasticsearch.xpack.core.ml.job.config.Job;
1618
import org.elasticsearch.xpack.ml.MachineLearning;
1719

@@ -41,11 +43,14 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
4143
if (Strings.isNullOrEmpty(jobId)) {
4244
jobId = Metadata.ALL;
4345
}
44-
GetJobsStatsAction.Request request = new GetJobsStatsAction.Request(jobId);
46+
Request request = new Request(jobId);
47+
if (restRequest.hasParam(Request.ALLOW_NO_JOBS)) {
48+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(null, () -> null, Request.ALLOW_NO_JOBS, Request.ALLOW_NO_MATCH);
49+
}
4550
request.setAllowNoMatch(
4651
restRequest.paramAsBoolean(
47-
GetJobsStatsAction.Request.ALLOW_NO_MATCH,
48-
restRequest.paramAsBoolean(GetJobsStatsAction.Request.ALLOW_NO_JOBS, request.allowNoMatch())));
52+
Request.ALLOW_NO_MATCH,
53+
restRequest.paramAsBoolean(Request.ALLOW_NO_JOBS, request.allowNoMatch())));
4954
return channel -> client.execute(GetJobsStatsAction.INSTANCE, request, new RestToXContentListener<>(channel));
5055
}
5156
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import org.elasticsearch.client.node.NodeClient;
99
import org.elasticsearch.cluster.metadata.Metadata;
1010
import org.elasticsearch.common.Strings;
11+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1112
import org.elasticsearch.rest.BaseRestHandler;
1213
import org.elasticsearch.rest.RestRequest;
1314
import org.elasticsearch.rest.action.RestToXContentListener;
1415
import org.elasticsearch.xpack.core.ml.action.GetJobsAction;
16+
import org.elasticsearch.xpack.core.ml.action.GetJobsAction.Request;
1517
import org.elasticsearch.xpack.core.ml.job.config.Job;
1618
import org.elasticsearch.xpack.ml.MachineLearning;
1719

@@ -41,11 +43,14 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
4143
if (Strings.isNullOrEmpty(jobId)) {
4244
jobId = Metadata.ALL;
4345
}
44-
GetJobsAction.Request request = new GetJobsAction.Request(jobId);
46+
Request request = new Request(jobId);
47+
if (restRequest.hasParam(Request.ALLOW_NO_JOBS)) {
48+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(null, () -> null, Request.ALLOW_NO_JOBS, Request.ALLOW_NO_MATCH);
49+
}
4550
request.setAllowNoMatch(
4651
restRequest.paramAsBoolean(
47-
GetJobsAction.Request.ALLOW_NO_MATCH,
48-
restRequest.paramAsBoolean(GetJobsAction.Request.ALLOW_NO_JOBS, request.allowNoMatch())));
52+
Request.ALLOW_NO_MATCH,
53+
restRequest.paramAsBoolean(Request.ALLOW_NO_JOBS, request.allowNoMatch())));
4954
return channel -> client.execute(GetJobsAction.INSTANCE, request, new RestToXContentListener<>(channel));
5055
}
5156
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.elasticsearch.xpack.ml.rest.results;
77

88
import org.elasticsearch.client.node.NodeClient;
9+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
910
import org.elasticsearch.common.xcontent.XContentParser;
1011
import org.elasticsearch.rest.BaseRestHandler;
1112
import org.elasticsearch.rest.RestRequest;
@@ -59,6 +60,10 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
5960
if (restRequest.hasParam(Request.END.getPreferredName())) {
6061
request.setEnd(restRequest.param(Request.END.getPreferredName()));
6162
}
63+
if (restRequest.hasParam(Request.ALLOW_NO_JOBS)) {
64+
LoggingDeprecationHandler.INSTANCE.usedDeprecatedName(
65+
null, () -> null, Request.ALLOW_NO_JOBS, Request.ALLOW_NO_MATCH.getPreferredName());
66+
}
6267
request.setAllowNoMatch(
6368
restRequest.paramAsBoolean(
6469
Request.ALLOW_NO_MATCH.getPreferredName(),

0 commit comments

Comments
 (0)