Fix GET bucket params validation (elastic/elasticsearch#661)
Original commit: elastic/x-pack-elasticsearch@66f522588b
This commit is contained in:
parent
45ef535b38
commit
fd4d412433
|
@ -51,26 +51,21 @@ public class RestGetBucketsAction extends BaseRestHandler {
|
||||||
request = GetBucketsAction.Request.parseRequest(jobId, parser, () -> parseFieldMatcher);
|
request = GetBucketsAction.Request.parseRequest(jobId, parser, () -> parseFieldMatcher);
|
||||||
} else {
|
} else {
|
||||||
request = new GetBucketsAction.Request(jobId);
|
request = new GetBucketsAction.Request(jobId);
|
||||||
String timestamp = restRequest.param(GetBucketsAction.Request.TIMESTAMP.getPreferredName());
|
|
||||||
|
|
||||||
// Single bucket
|
// Check if the REST param is set first so mutually exclusive
|
||||||
|
// options will only cause an error if set
|
||||||
|
if (restRequest.hasParam(GetBucketsAction.Request.TIMESTAMP.getPreferredName())) {
|
||||||
|
String timestamp = restRequest.param(GetBucketsAction.Request.TIMESTAMP.getPreferredName());
|
||||||
if (timestamp != null && !timestamp.isEmpty()) {
|
if (timestamp != null && !timestamp.isEmpty()) {
|
||||||
request.setTimestamp(timestamp);
|
request.setTimestamp(timestamp);
|
||||||
}
|
}
|
||||||
if (restRequest.hasParam(PageParams.FROM.getPreferredName())
|
}
|
||||||
|| restRequest.hasParam(PageParams.SIZE.getPreferredName())
|
// multiple bucket options
|
||||||
|| restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())
|
if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
|
||||||
|| restRequest.hasParam(GetBucketsAction.Request.END.getPreferredName())
|
|
||||||
|| restRequest.hasParam(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName())
|
|
||||||
|| restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())
|
|
||||||
|| timestamp == null) {
|
|
||||||
|
|
||||||
request.setPageParams(
|
request.setPageParams(
|
||||||
new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM),
|
new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM),
|
||||||
restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE)));
|
restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE)));
|
||||||
|
}
|
||||||
// Multiple buckets, check if the param is set first so mutually exclusive
|
|
||||||
// options will only cause an error if set
|
|
||||||
if (restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())) {
|
if (restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())) {
|
||||||
request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName()));
|
request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName()));
|
||||||
}
|
}
|
||||||
|
@ -89,9 +84,8 @@ public class RestGetBucketsAction extends BaseRestHandler {
|
||||||
if (restRequest.hasParam(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName())) {
|
if (restRequest.hasParam(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName())) {
|
||||||
request.setPartitionValue(restRequest.param(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName()));
|
request.setPartitionValue(restRequest.param(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Common options
|
// single and multiple bucket options
|
||||||
request.setExpand(restRequest.paramAsBoolean(GetBucketsAction.Request.EXPAND.getPreferredName(), false));
|
request.setExpand(restRequest.paramAsBoolean(GetBucketsAction.Request.EXPAND.getPreferredName(), false));
|
||||||
request.setIncludeInterim(restRequest.paramAsBoolean(GetBucketsAction.Request.INCLUDE_INTERIM.getPreferredName(), false));
|
request.setIncludeInterim(restRequest.paramAsBoolean(GetBucketsAction.Request.INCLUDE_INTERIM.getPreferredName(), false));
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,13 @@ setup:
|
||||||
timestamp: "2016-06-01T00:00:00Z"
|
timestamp: "2016-06-01T00:00:00Z"
|
||||||
end: "2016-05-01T00:00:00Z"
|
end: "2016-05-01T00:00:00Z"
|
||||||
|
|
||||||
|
- do:
|
||||||
|
catch: request
|
||||||
|
xpack.ml.get_buckets:
|
||||||
|
job_id: "farequote"
|
||||||
|
timestamp: "2016-06-01T00:00:00Z"
|
||||||
|
anomaly_score: "80.0"
|
||||||
|
|
||||||
---
|
---
|
||||||
"Test mutually-exclusive params (via body)":
|
"Test mutually-exclusive params (via body)":
|
||||||
- do:
|
- do:
|
||||||
|
@ -132,3 +139,11 @@ setup:
|
||||||
body:
|
body:
|
||||||
timestamp: "2016-06-01T00:00:00Z"
|
timestamp: "2016-06-01T00:00:00Z"
|
||||||
end: "2016-05-01T00:00:00Z"
|
end: "2016-05-01T00:00:00Z"
|
||||||
|
|
||||||
|
- do:
|
||||||
|
catch: request
|
||||||
|
xpack.ml.get_buckets:
|
||||||
|
job_id: "farequote"
|
||||||
|
body:
|
||||||
|
timestamp: "2016-06-01T00:00:00Z"
|
||||||
|
anomaly_score: "80.0"
|
||||||
|
|
Loading…
Reference in New Issue