From f7f06e05d79da4e1a79193e56fc4e1de1444feed Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 1 May 2018 20:39:31 +0000 Subject: [PATCH 1/2] [Rollup] Specialize validation exception for easier management 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` --- .../rollup/action/PutRollupJobAction.java | 4 +-- ...ollupActionRequestValidationException.java | 11 ++++++++ .../rest-api-spec/test/rollup/put_job.yml | 28 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupActionRequestValidationException.java diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java index bb64d97f1c87d..d4b7e33123054 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java @@ -88,8 +88,8 @@ public ActionRequestValidationException validate() { return null; } - public ActionRequestValidationException validateMappings(Map> fieldCapsResponse) { - ActionRequestValidationException validationException = new ActionRequestValidationException(); + public RollupActionRequestValidationException validateMappings(Map> fieldCapsResponse) { + RollupActionRequestValidationException validationException = new RollupActionRequestValidationException(); if (fieldCapsResponse.size() == 0) { validationException.addValidationError("Could not find any fields in the index/index-pattern that were configured in job"); return validationException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupActionRequestValidationException.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupActionRequestValidationException.java new file mode 100644 index 0000000000000..d81e59a55ead3 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupActionRequestValidationException.java @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.core.rollup.action; + +import org.elasticsearch.action.ActionRequestValidationException; + +public class RollupActionRequestValidationException extends ActionRequestValidationException { +} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml index 080fed7a80ec9..568a6261cda9b 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml @@ -159,5 +159,33 @@ setup: ] } +--- +"Validation failures": + + - do: + catch: /Could not find a \[numeric\] field with name \[field_doesnt_exist\] in any of the indices matching the index pattern/ + headers: + Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser + xpack.rollup.put_job: + id: foo + body: > + { + "index_pattern": "foo", + "rollup_index": "foo_rollup", + "cron": "*/30 * * * * ?", + "page_size" :10, + "groups" : { + "date_histogram": { + "field": "the_field", + "interval": "1h" + } + }, + "metrics": [ + { + "field": "field_doesnt_exist", + "metrics": ["min", "max", "sum"] + } + ] + } From f6bc5c661cc5c820191db24b67bcbd0c355762d8 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 4 May 2018 14:04:52 +0000 Subject: [PATCH 2/2] [DOCS] Update Changelog --- docs/CHANGELOG.asciidoc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.asciidoc b/docs/CHANGELOG.asciidoc index 9e33c10a56b12..ef699ca02246e 100644 --- a/docs/CHANGELOG.asciidoc +++ b/docs/CHANGELOG.asciidoc @@ -98,8 +98,12 @@ ones that the user is authorized to access in case field level security is enabl //[float] //=== New Features -//[float] -//=== Enhancements +=== Enhancements + +Rollup:: +* Exceptions thrown when validating rollup job configs on job creation have been +specialized to `rollup_action_request_validation_exception`, to make it easier for +clients to handle/parse ({pull}30339[#30339]) [float] === Bug Fixes @@ -156,6 +160,11 @@ synchronous and predictable. Also the trigger engine thread is only started on data nodes. And the Execute Watch API can be triggered regardless is watcher is started or stopped. ({pull}30118[#30118]) +Rollup:: +* Exceptions thrown when validating rollup job configs on job creation have been +specialized to `rollup_action_request_validation_exception`, to make it easier for +clients to handle/parse ({pull}30339[#30339]) + [float] === Bug Fixes