From 1a13a0b10ff7c8f33beff5f3df822ebf8ac8da7c Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Mon, 23 Nov 2020 09:17:49 -0700 Subject: [PATCH] Watcher understands hidden expand wildcard value (#65372) Watcher has a search template that stores indices options to be used as part of a search during watch execution, but this was not updated to be aware of hidden indices and the `hidden` expand_wildcards option. This change makes use of the `IndicesOptions#toXContent` method in Watcher, which already handles the new value. Additionally, the XContent parsing is moved to the IndicesOptions class so that we will be less likely to miss updating this in the future. Closes #65148 Backport of #65332 --- .../action/support/IndicesOptions.java | 130 ++++++++++++++---- .../action/support/IndicesOptionsTests.java | 93 ++++++++++++- .../search/WatcherSearchTemplateRequest.java | 63 +-------- 3 files changed, 193 insertions(+), 93 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java index 2352fadab79..676112c2eb8 100644 --- a/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java +++ b/server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java @@ -19,15 +19,18 @@ package org.elasticsearch.action.support; import org.elasticsearch.Version; +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.rest.RestRequest; import java.io.IOException; -import java.util.Collection; import java.util.EnumSet; import java.util.Locale; import java.util.Map; @@ -59,25 +62,7 @@ public class IndicesOptions implements ToXContentFragment { // TODO why do we let patterns like "none,all" or "open,none,closed" get used. The location of 'none' in the array changes the // meaning of the resulting value for (String wildcard : wildcards) { - switch (wildcard) { - case "open": - states.add(OPEN); - break; - case "closed": - states.add(CLOSED); - break; - case "hidden": - states.add(HIDDEN); - break; - case "none": - states.clear(); - break; - case "all": - states = EnumSet.allOf(WildcardStates.class); - break; - default: - throw new IllegalArgumentException("No valid expand wildcard value [" + wildcard + "]"); - } + updateSetForValue(states, wildcard); } return states; @@ -94,6 +79,28 @@ public class IndicesOptions implements ToXContentFragment { } return builder; } + + private static void updateSetForValue(EnumSet states, String wildcard) { + switch (wildcard) { + case "open": + states.add(OPEN); + break; + case "closed": + states.add(CLOSED); + break; + case "hidden": + states.add(HIDDEN); + break; + case "none": + states.clear(); + break; + case "all": + states.addAll(EnumSet.allOf(WildcardStates.class)); + break; + default: + throw new IllegalArgumentException("No valid expand wildcard value [" + wildcard + "]"); + } + } } public enum Option { @@ -148,11 +155,6 @@ public class IndicesOptions implements ToXContentFragment { this.expandWildcards = expandWildcards; } - private IndicesOptions(Collection