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,47 +51,41 @@ 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
|
||||||
if (timestamp != null && !timestamp.isEmpty()) {
|
// options will only cause an error if set
|
||||||
request.setTimestamp(timestamp);
|
if (restRequest.hasParam(GetBucketsAction.Request.TIMESTAMP.getPreferredName())) {
|
||||||
|
String timestamp = restRequest.param(GetBucketsAction.Request.TIMESTAMP.getPreferredName());
|
||||||
|
if (timestamp != null && !timestamp.isEmpty()) {
|
||||||
|
request.setTimestamp(timestamp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (restRequest.hasParam(PageParams.FROM.getPreferredName())
|
// multiple bucket options
|
||||||
|| restRequest.hasParam(PageParams.SIZE.getPreferredName())
|
if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
|
||||||
|| restRequest.hasParam(GetBucketsAction.Request.START.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
|
if (restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())) {
|
||||||
// options will only cause an error if set
|
request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName()));
|
||||||
if (restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())) {
|
}
|
||||||
request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName()));
|
if (restRequest.hasParam(GetBucketsAction.Request.END.getPreferredName())) {
|
||||||
}
|
request.setEnd(restRequest.param(GetBucketsAction.Request.END.getPreferredName()));
|
||||||
if (restRequest.hasParam(GetBucketsAction.Request.END.getPreferredName())) {
|
}
|
||||||
request.setEnd(restRequest.param(GetBucketsAction.Request.END.getPreferredName()));
|
if (restRequest.hasParam(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName())) {
|
||||||
}
|
request.setAnomalyScore(
|
||||||
if (restRequest.hasParam(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName())) {
|
Double.parseDouble(restRequest.param(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName(), "0.0")));
|
||||||
request.setAnomalyScore(
|
}
|
||||||
Double.parseDouble(restRequest.param(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName(), "0.0")));
|
if (restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())) {
|
||||||
}
|
request.setMaxNormalizedProbability(
|
||||||
if (restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())) {
|
Double.parseDouble(restRequest.param(
|
||||||
request.setMaxNormalizedProbability(
|
GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName(), "0.0")));
|
||||||
Double.parseDouble(restRequest.param(
|
}
|
||||||
GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName(), "0.0")));
|
if (restRequest.hasParam(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName())) {
|
||||||
}
|
request.setPartitionValue(restRequest.param(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName()));
|
||||||
if (restRequest.hasParam(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