Skip to content

Commit b422978

Browse files
authored
[Rollup] Specialize validation exception for easier management (#30339)
Extends ActionRequestValidationException with a rollup-specific version to make it easier to handle mapping validation issues on the client side. The type will now be `rollup_action_request_validation_exception` instead of `action_request_validation_exception`
1 parent 167b9b3 commit b422978

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public ActionRequestValidationException validate() {
8282
return null;
8383
}
8484

85-
public ActionRequestValidationException validateMappings(Map<String, Map<String, FieldCapabilities>> fieldCapsResponse) {
86-
ActionRequestValidationException validationException = new ActionRequestValidationException();
85+
public RollupActionRequestValidationException validateMappings(Map<String, Map<String, FieldCapabilities>> fieldCapsResponse) {
86+
RollupActionRequestValidationException validationException = new RollupActionRequestValidationException();
8787
if (fieldCapsResponse.size() == 0) {
8888
validationException.addValidationError("Could not find any fields in the index/index-pattern that were configured in job");
8989
return validationException;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.core.rollup.action;
7+
8+
import org.elasticsearch.action.ActionRequestValidationException;
9+
10+
public class RollupActionRequestValidationException extends ActionRequestValidationException {
11+
}

x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,33 @@ setup:
159159
]
160160
}
161161
162+
---
163+
"Validation failures":
164+
165+
- do:
166+
catch: /Could not find a \[numeric\] field with name \[field_doesnt_exist\] in any of the indices matching the index pattern/
167+
headers:
168+
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
169+
xpack.rollup.put_job:
170+
id: foo
171+
body: >
172+
{
173+
"index_pattern": "foo",
174+
"rollup_index": "foo_rollup",
175+
"cron": "*/30 * * * * ?",
176+
"page_size" :10,
177+
"groups" : {
178+
"date_histogram": {
179+
"field": "the_field",
180+
"interval": "1h"
181+
}
182+
},
183+
"metrics": [
184+
{
185+
"field": "field_doesnt_exist",
186+
"metrics": ["min", "max", "sum"]
187+
}
188+
]
189+
}
162190
163191

0 commit comments

Comments
 (0)