diff --git a/server/src/main/java/org/elasticsearch/TransportVersions.java b/server/src/main/java/org/elasticsearch/TransportVersions.java index 24ca2f6ee589f..364c624813da6 100644 --- a/server/src/main/java/org/elasticsearch/TransportVersions.java +++ b/server/src/main/java/org/elasticsearch/TransportVersions.java @@ -174,12 +174,14 @@ static TransportVersion def(int id) { public static final TransportVersion TIMEOUT_GET_PARAM_FOR_RESOLVE_CLUSTER = def(8_838_0_00); public static final TransportVersion INFERENCE_REQUEST_ADAPTIVE_RATE_LIMITING = def(8_839_0_00); public static final TransportVersion ML_INFERENCE_IBM_WATSONX_RERANK_ADDED = def(8_840_0_00); + public static final TransportVersion REMOVE_ALL_APPLICABLE_SELECTOR_BACKPORT_8_18 = def(8_840_0_01); public static final TransportVersion INITIAL_ELASTICSEARCH_8_19 = def(8_841_0_00); public static final TransportVersion INITIAL_ELASTICSEARCH_9_0 = def(9_000_0_00); public static final TransportVersion REMOVE_SNAPSHOT_FAILURES_90 = def(9_000_0_01); public static final TransportVersion TRANSPORT_STATS_HANDLING_TIME_REQUIRED_90 = def(9_000_0_02); public static final TransportVersion REMOVE_DESIRED_NODE_VERSION_90 = def(9_000_0_03); public static final TransportVersion ESQL_DRIVER_TASK_DESCRIPTION_90 = def(9_000_0_04); + public static final TransportVersion REMOVE_ALL_APPLICABLE_SELECTOR_9_0 = def(9_000_0_05); /* * STOP! READ THIS FIRST! No, really, diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java index 0f1b77af0242e..d61901b246d05 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java @@ -646,10 +646,6 @@ private static void enrichIndexAbstraction( : switch (resolvedExpression.selector()) { case DATA -> dataStream.getDataComponent().getIndices().stream(); case FAILURES -> dataStream.getFailureIndices().stream(); - case ALL_APPLICABLE -> Stream.concat( - dataStream.getIndices().stream(), - dataStream.getFailureIndices().stream() - ); }; String[] backingIndices = dataStreamIndices.map(Index::getName).toArray(String[]::new); dataStreams.add(new ResolvedDataStream(dataStream.getName(), backingIndices, DataStream.TIMESTAMP_FIELD_NAME)); @@ -670,13 +666,6 @@ private static Stream getAliasIndexStream(ResolvedExpression resolvedExpr assert ia.isDataStreamRelated() : "Illegal selector [failures] used on non data stream alias"; yield ia.getFailureIndices(metadata).stream(); } - case ALL_APPLICABLE -> { - if (ia.isDataStreamRelated()) { - yield Stream.concat(ia.getIndices().stream(), ia.getFailureIndices(metadata).stream()); - } else { - yield ia.getIndices().stream(); - } - } }; } return aliasIndices; diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java index 608d32d50a856..cb46d039c5b3b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequest.java @@ -13,14 +13,13 @@ import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.support.ActiveShardCount; -import org.elasticsearch.action.support.IndexComponentSelector; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.ResolvedExpression; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SelectorResolver; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.tasks.CancellableTask; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskId; @@ -126,14 +125,12 @@ public ActionRequestValidationException validate() { ); } + // Ensure we have a valid selector in the request if (rolloverTarget != null) { - ResolvedExpression resolvedExpression = SelectorResolver.parseExpression(rolloverTarget, indicesOptions); - IndexComponentSelector selector = resolvedExpression.selector(); - if (IndexComponentSelector.ALL_APPLICABLE.equals(selector)) { - validationException = addValidationError( - "rollover cannot be applied to both regular and failure indices at the same time", - validationException - ); + try { + SelectorResolver.parseExpression(rolloverTarget, indicesOptions); + } catch (InvalidIndexNameException exception) { + validationException = addValidationError(exception.getMessage(), validationException); } } diff --git a/server/src/main/java/org/elasticsearch/action/support/IndexComponentSelector.java b/server/src/main/java/org/elasticsearch/action/support/IndexComponentSelector.java index 910be151d1bf5..d281b5def324a 100644 --- a/server/src/main/java/org/elasticsearch/action/support/IndexComponentSelector.java +++ b/server/src/main/java/org/elasticsearch/action/support/IndexComponentSelector.java @@ -9,6 +9,7 @@ package org.elasticsearch.action.support; +import org.elasticsearch.TransportVersions; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -23,14 +24,11 @@ * We define as index components the two different sets of indices a data stream could consist of: * - DATA: represents the backing indices * - FAILURES: represent the failing indices - * - ALL: represents all available in this expression components, meaning if it's a data stream both backing and failure indices and if it's - * an index only the index itself. * Note: An index is its own DATA component, but it cannot have a FAILURE component. */ public enum IndexComponentSelector implements Writeable { DATA("data", (byte) 0), - FAILURES("failures", (byte) 1), - ALL_APPLICABLE("*", (byte) 2); + FAILURES("failures", (byte) 1); private final String key; private final byte id; @@ -75,7 +73,14 @@ public static IndexComponentSelector getByKey(String key) { } public static IndexComponentSelector read(StreamInput in) throws IOException { - return getById(in.readByte()); + byte id = in.readByte(); + if (in.getTransportVersion().onOrAfter(TransportVersions.REMOVE_ALL_APPLICABLE_SELECTOR_9_0) + || in.getTransportVersion().isPatchFrom(TransportVersions.REMOVE_ALL_APPLICABLE_SELECTOR_BACKPORT_8_18)) { + return getById(id); + } else { + // Legacy value ::*, converted to ::data + return id == 2 ? DATA : getById(id); + } } // Visible for testing @@ -95,10 +100,10 @@ public void writeTo(StreamOutput out) throws IOException { } public boolean shouldIncludeData() { - return this == ALL_APPLICABLE || this == DATA; + return this == DATA; } public boolean shouldIncludeFailures() { - return this == ALL_APPLICABLE || this == FAILURES; + return this == FAILURES; } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java index d83bde9542d9e..fe7199f8332d2 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolver.java @@ -81,8 +81,7 @@ && isIndexVisible( indexNameExpressionResolver, includeDataStreams )) { - // Resolve any ::* suffixes on the expression. We need to resolve them all to their final valid selectors - resolveSelectorsAndCombine(authorizedIndex, selectorString, indicesOptions, resolvedIndices, metadata); + resolveSelectorsAndCollect(authorizedIndex, selectorString, indicesOptions, resolvedIndices, metadata); } } if (resolvedIndices.isEmpty()) { @@ -98,9 +97,8 @@ && isIndexVisible( } } } else { - // Resolve any ::* suffixes on the expression. We need to resolve them all to their final valid selectors Set resolvedIndices = new HashSet<>(); - resolveSelectorsAndCombine(indexAbstraction, selectorString, indicesOptions, resolvedIndices, metadata); + resolveSelectorsAndCollect(indexAbstraction, selectorString, indicesOptions, resolvedIndices, metadata); if (minus) { finalIndices.removeAll(resolvedIndices); } else if (indicesOptions.ignoreUnavailable() == false || isAuthorized.test(indexAbstraction)) { @@ -114,7 +112,7 @@ && isIndexVisible( return finalIndices; } - private static void resolveSelectorsAndCombine( + private static void resolveSelectorsAndCollect( String indexAbstraction, String selectorString, IndicesOptions indicesOptions, @@ -132,19 +130,8 @@ private static void resolveSelectorsAndCombine( selectorString = IndexComponentSelector.DATA.getKey(); } - if (Regex.isMatchAllPattern(selectorString)) { - // Always accept data - collect.add(IndexNameExpressionResolver.combineSelectorExpression(indexAbstraction, IndexComponentSelector.DATA.getKey())); - // Only put failures on the expression if the abstraction supports it. - if (acceptsAllSelectors) { - collect.add( - IndexNameExpressionResolver.combineSelectorExpression(indexAbstraction, IndexComponentSelector.FAILURES.getKey()) - ); - } - } else { - // A non-wildcard selector is always passed along as-is, it's validity for this kind of abstraction is tested later - collect.add(IndexNameExpressionResolver.combineSelectorExpression(indexAbstraction, selectorString)); - } + // A selector is always passed along as-is, it's validity for this kind of abstraction is tested later + collect.add(IndexNameExpressionResolver.combineSelectorExpression(indexAbstraction, selectorString)); } else { assert selectorString == null : "A selector string [" + selectorString + "] is present but selectors are disabled in this context"; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java index cb074b1437040..d28049f2a6316 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -364,21 +364,9 @@ protected static Collection resolveExpressionsToResources(Co } } else { if (isExclusion) { - if (IndexComponentSelector.ALL_APPLICABLE.equals(selector)) { - resources.remove(new ResolvedExpression(baseExpression, IndexComponentSelector.DATA)); - resources.remove(new ResolvedExpression(baseExpression, IndexComponentSelector.FAILURES)); - } else { - resources.remove(new ResolvedExpression(baseExpression, selector)); - } + resources.remove(new ResolvedExpression(baseExpression, selector)); } else if (ensureAliasOrIndexExists(context, baseExpression, selector)) { - if (IndexComponentSelector.ALL_APPLICABLE.equals(selector)) { - resources.add(new ResolvedExpression(baseExpression, IndexComponentSelector.DATA)); - if (context.getState().getMetadata().getIndicesLookup().get(baseExpression).isDataStreamRelated()) { - resources.add(new ResolvedExpression(baseExpression, IndexComponentSelector.FAILURES)); - } - } else { - resources.add(new ResolvedExpression(baseExpression, selector)); - } + resources.add(new ResolvedExpression(baseExpression, selector)); } } } @@ -1046,8 +1034,7 @@ public String[] indexAliases( private static boolean resolvedExpressionsContainsAbstraction(Set resolvedExpressions, String abstractionName) { return resolvedExpressions.contains(new ResolvedExpression(abstractionName)) - || resolvedExpressions.contains(new ResolvedExpression(abstractionName, IndexComponentSelector.DATA)) - || resolvedExpressions.contains(new ResolvedExpression(abstractionName, IndexComponentSelector.ALL_APPLICABLE)); + || resolvedExpressions.contains(new ResolvedExpression(abstractionName, IndexComponentSelector.DATA)); } /** @@ -1342,8 +1329,7 @@ private static boolean ensureAliasOrIndexExists(Context context, String name, In if (context.options.allowSelectors()) { // Ensure that the selectors are present and that they are compatible with the abstractions they are used with assert selector != null : "Earlier logic should have parsed selectors or added the default selectors already"; - // Check if ::failures has been explicitly requested, since requesting ::* for non-data-stream abstractions would just - // return their data components. + // Check if ::failures has been explicitly requested if (IndexComponentSelector.FAILURES.equals(selector) && indexAbstraction.isDataStreamRelated() == false) { // If requested abstraction is not data stream related, then you cannot use ::failures if (ignoreUnavailable) { @@ -1700,9 +1686,9 @@ private static Set expandToOpenClosed( final IndexMetadata.State excludeState = excludeState(context.getOptions()); Set resources = new HashSet<>(); if (context.isPreserveAliases() && indexAbstraction.getType() == Type.ALIAS) { - expandToApplicableSelectors(indexAbstraction, selector, resources); + resources.add(new ResolvedExpression(indexAbstraction.getName(), selector)); } else if (context.isPreserveDataStreams() && indexAbstraction.getType() == Type.DATA_STREAM) { - expandToApplicableSelectors(indexAbstraction, selector, resources); + resources.add(new ResolvedExpression(indexAbstraction.getName(), selector)); } else { if (shouldIncludeRegularIndices(context.getOptions(), selector)) { for (int i = 0, n = indexAbstraction.getIndices().size(); i < n; i++) { @@ -1729,31 +1715,6 @@ private static Set expandToOpenClosed( return resources; } - /** - * Adds the abstraction and selector to the results when preserving data streams and aliases at wildcard resolution. If a selector - * is provided, the result is only added if the selector is applicable to the abstraction provided. If - * {@link IndexComponentSelector#ALL_APPLICABLE} is given, the selectors are expanded only to those which are applicable to the - * provided abstraction. - * @param indexAbstraction abstraction to add - * @param selector The selector to add - * @param resources Result collector which is updated with all applicable resolved expressions for a given abstraction and selector - * pair. - */ - private static void expandToApplicableSelectors( - IndexAbstraction indexAbstraction, - IndexComponentSelector selector, - Set resources - ) { - if (IndexComponentSelector.ALL_APPLICABLE.equals(selector)) { - resources.add(new ResolvedExpression(indexAbstraction.getName(), IndexComponentSelector.DATA)); - if (indexAbstraction.isDataStreamRelated()) { - resources.add(new ResolvedExpression(indexAbstraction.getName(), IndexComponentSelector.FAILURES)); - } - } else if (selector == null || indexAbstraction.isDataStreamRelated() || selector.shouldIncludeFailures() == false) { - resources.add(new ResolvedExpression(indexAbstraction.getName(), selector)); - } - } - private static List resolveEmptyOrTrivialWildcard(Context context, IndexComponentSelector selector) { final String[] allIndices = resolveEmptyOrTrivialWildcardToAllIndices( context.getOptions(), @@ -2150,20 +2111,10 @@ private static V splitSelectorExpression(String expression, BiFunction> groupClusterIndices(Set remoteCluste if (indexName.equals("*") == false) { throw new IllegalArgumentException( Strings.format( - "To exclude a cluster you must specify the '*' wildcard for " + "the index expression, but found: [%s]", + "To exclude a cluster you must specify the '*' wildcard for the index expression, but found: [%s]", indexName ) ); } - if (selectorString != null && selectorString.equals("*") == false) { + if (selectorString != null) { throw new IllegalArgumentException( Strings.format( - "To exclude a cluster you must specify the '::*' selector or leave it off, but found: [%s]", + "To exclude a cluster you must not specify the a selector, but found selector: [%s]", selectorString ) ); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java index ee95f7ffb5b9a..515d571243a7c 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/RolloverRequestTests.java @@ -253,7 +253,7 @@ public void testValidation() { assertNotNull(validationException); assertEquals(1, validationException.validationErrors().size()); assertEquals( - "rollover cannot be applied to both regular and failure indices at the same time", + "Invalid index name [alias-index::*], invalid usage of :: separator, [*] is not a recognized selector", validationException.validationErrors().get(0) ); } diff --git a/server/src/test/java/org/elasticsearch/action/support/IndexComponentSelectorTests.java b/server/src/test/java/org/elasticsearch/action/support/IndexComponentSelectorTests.java index 73d4ab59ce479..585d660917e4b 100644 --- a/server/src/test/java/org/elasticsearch/action/support/IndexComponentSelectorTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/IndexComponentSelectorTests.java @@ -20,7 +20,7 @@ public class IndexComponentSelectorTests extends ESTestCase { public void testIndexComponentSelectorFromKey() { assertThat(IndexComponentSelector.getByKey("data"), equalTo(IndexComponentSelector.DATA)); assertThat(IndexComponentSelector.getByKey("failures"), equalTo(IndexComponentSelector.FAILURES)); - assertThat(IndexComponentSelector.getByKey("*"), equalTo(IndexComponentSelector.ALL_APPLICABLE)); + assertThat(IndexComponentSelector.getByKey("*"), nullValue()); assertThat(IndexComponentSelector.getByKey("d*ta"), nullValue()); assertThat(IndexComponentSelector.getByKey("_all"), nullValue()); assertThat(IndexComponentSelector.getByKey("**"), nullValue()); @@ -30,11 +30,10 @@ public void testIndexComponentSelectorFromKey() { public void testIndexComponentSelectorFromId() { assertThat(IndexComponentSelector.getById((byte) 0), equalTo(IndexComponentSelector.DATA)); assertThat(IndexComponentSelector.getById((byte) 1), equalTo(IndexComponentSelector.FAILURES)); - assertThat(IndexComponentSelector.getById((byte) 2), equalTo(IndexComponentSelector.ALL_APPLICABLE)); - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexComponentSelector.getById((byte) 3)); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexComponentSelector.getById((byte) 2)); assertThat( exception.getMessage(), - containsString("Unknown id of index component selector [3], available options are: {0=DATA, 1=FAILURES, 2=ALL_APPLICABLE}") + containsString("Unknown id of index component selector [2], available options are: {0=DATA, 1=FAILURES}") ); } diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolverTests.java index 286e1d3afaeef..a3ac361f5b055 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexAbstractionResolverTests.java @@ -81,11 +81,8 @@ public void testResolveIndexAbstractions() { expectThrows(IllegalArgumentException.class, () -> resolveAbstractionsSelectorNotAllowed(List.of("index1::data"))); // Selectors allowed, valid selector given, data selector stripped off in result since it is the default assertThat(resolveAbstractionsSelectorAllowed(List.of("index1::data")), contains("index1")); - // Selectors allowed, wildcard selector provided, data selector stripped off in result since it is the default - // ** only returns ::data since expression is an index - assertThat(resolveAbstractionsSelectorAllowed(List.of("index1::*")), contains("index1")); // Selectors allowed, invalid selector given - expectThrows(InvalidIndexNameException.class, () -> resolveAbstractionsSelectorAllowed(List.of("index1::custom"))); + expectThrows(InvalidIndexNameException.class, () -> resolveAbstractionsSelectorAllowed(List.of("index1::*"))); // == Single Date Math Expressions == @@ -125,7 +122,7 @@ public void testResolveIndexAbstractions() { assertThat(resolveAbstractionsSelectorAllowed(List.of("index*::data")), containsInAnyOrder("index1", "index2")); // Selectors allowed, wildcard selector provided, data selector stripped off in result since it is the default // ** only returns ::data since expression is an index - assertThat(resolveAbstractionsSelectorAllowed(List.of("index*::*")), containsInAnyOrder("index1", "index2")); + assertThat(resolveAbstractionsSelectorAllowed(List.of("index*")), containsInAnyOrder("index1", "index2")); // Selectors allowed, invalid selector given expectThrows(InvalidIndexNameException.class, () -> resolveAbstractionsSelectorAllowed(List.of("index*::custom"))); @@ -137,11 +134,9 @@ public void testResolveIndexAbstractions() { expectThrows(IllegalArgumentException.class, () -> resolveAbstractionsSelectorNotAllowed(List.of("data-stream1::data"))); // Selectors allowed, valid selector given assertThat(resolveAbstractionsSelectorAllowed(List.of("data-stream1::failures")), contains("data-stream1::failures")); - // Selectors allowed, wildcard selector provided - // ** returns both ::data and ::failures since expression is a data stream - // ** data selector stripped off in result since it is the default + // Selectors allowed, data selector is not added in result since it is the default assertThat( - resolveAbstractionsSelectorAllowed(List.of("data-stream1::*")), + resolveAbstractionsSelectorAllowed(List.of("data-stream1", "data-stream1::failures")), containsInAnyOrder("data-stream1", "data-stream1::failures") ); // Selectors allowed, invalid selector given @@ -155,10 +150,9 @@ public void testResolveIndexAbstractions() { expectThrows(IllegalArgumentException.class, () -> resolveAbstractionsSelectorNotAllowed(List.of("data-stream*::data"))); // Selectors allowed, valid selector given assertThat(resolveAbstractionsSelectorAllowed(List.of("data-stream*::failures")), contains("data-stream1::failures")); - // Selectors allowed, wildcard selector provided - // ** returns both ::data and ::failures since expression is a data stream + // Selectors allowed, both ::data and ::failures are returned assertThat( - resolveAbstractionsSelectorAllowed(List.of("data-stream*::*")), + resolveAbstractionsSelectorAllowed(List.of("data-stream*", "data-stream*::failures")), containsInAnyOrder("data-stream1", "data-stream1::failures") ); // Selectors allowed, invalid selector given @@ -179,7 +173,7 @@ public void testResolveIndexAbstractions() { // Selectors allowed, wildcard selector provided // ** returns both ::data and ::failures for applicable abstractions assertThat( - resolveAbstractionsSelectorAllowed(List.of("*::*")), + resolveAbstractionsSelectorAllowed(List.of("*", "*::failures")), containsInAnyOrder("index1", "index2", "data-stream1", "data-stream1::failures") ); // Selectors allowed, invalid selector given @@ -194,11 +188,11 @@ public void testResolveIndexAbstractions() { // Selectors allowed, wildcard selector provided // ** returns both ::data and ::failures for applicable abstractions // ** limits the returned values based on selectors - assertThat(resolveAbstractionsSelectorAllowed(List.of("*::*", "-*::data")), contains("data-stream1::failures")); + assertThat(resolveAbstractionsSelectorAllowed(List.of("*", "*::failures", "-*::data")), contains("data-stream1::failures")); // Selectors allowed, wildcard selector provided // ** limits the returned values based on selectors assertThat( - resolveAbstractionsSelectorAllowed(List.of("*::*", "-*::failures")), + resolveAbstractionsSelectorAllowed(List.of("*", "*::failures", "-*::failures")), containsInAnyOrder("index1", "index2", "data-stream1") ); // Selectors allowed, none given, default to both selectors diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java index f5e4c3d8f2d09..293bdb2c53899 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -2765,10 +2765,27 @@ public void testDataStreamsWithFailureStore() { assertThat(result[1].getName(), equalTo(DataStream.getDefaultBackingIndexName(dataStreamName, 2, epochMillis))); } + // Test default with an exact data stream name and include failures true + { + IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN_CLOSED_HIDDEN_FAILURE_NO_SELECTORS; + Index[] result = indexNameExpressionResolver.concreteIndices(state, indicesOptions, true, "my-data-stream"); + assertThat(result.length, equalTo(4)); + assertThat(result[0].getName(), equalTo(DataStream.getDefaultBackingIndexName(dataStreamName, 1, epochMillis))); + assertThat(result[1].getName(), equalTo(DataStream.getDefaultBackingIndexName(dataStreamName, 2, epochMillis))); + assertThat(result[2].getName(), equalTo(DataStream.getDefaultFailureStoreName(dataStreamName, 1, epochMillis))); + assertThat(result[3].getName(), equalTo(DataStream.getDefaultFailureStoreName(dataStreamName, 2, epochMillis))); + } + // Test explicit include failure store with an exact data stream name { IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN; - Index[] result = indexNameExpressionResolver.concreteIndices(state, indicesOptions, true, "my-data-stream::*"); + Index[] result = indexNameExpressionResolver.concreteIndices( + state, + indicesOptions, + true, + "my-data-stream::data", + "my-data-stream::failures" + ); assertThat(result.length, equalTo(4)); assertThat(result[0].getName(), equalTo(DataStream.getDefaultBackingIndexName(dataStreamName, 1, epochMillis))); assertThat(result[1].getName(), equalTo(DataStream.getDefaultBackingIndexName(dataStreamName, 2, epochMillis))); @@ -2784,7 +2801,7 @@ public void testDataStreamsWithFailureStore() { .build(); expectThrows( IllegalArgumentException.class, - () -> indexNameExpressionResolver.concreteIndices(state, indicesOptions, true, "my-data-stream::*") + () -> indexNameExpressionResolver.concreteIndices(state, indicesOptions, true, "my-data-stream::failures") ); } @@ -2813,6 +2830,26 @@ public void testDataStreamsWithFailureStore() { ); } + // Test default without any expressions and include failures + { + IndicesOptions indicesOptions = IndicesOptions.builder() + .gatekeeperOptions(IndicesOptions.GatekeeperOptions.builder().allowSelectors(false).includeFailureIndices(true).build()) + .build(); + Index[] result = indexNameExpressionResolver.concreteIndices(state, indicesOptions, true); + assertThat(result.length, equalTo(5)); + List indexNames = Arrays.stream(result).map(Index::getName).toList(); + assertThat( + indexNames, + containsInAnyOrder( + DataStream.getDefaultBackingIndexName(dataStreamName, 2, epochMillis), + DataStream.getDefaultBackingIndexName(dataStreamName, 1, epochMillis), + DataStream.getDefaultFailureStoreName(dataStreamName, 1, epochMillis), + DataStream.getDefaultFailureStoreName(dataStreamName, 2, epochMillis), + otherIndex.getIndex().getName() + ) + ); + } + // Test default with wildcard expression { IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN; @@ -2832,7 +2869,7 @@ public void testDataStreamsWithFailureStore() { // Test explicit include failure store with wildcard expression { IndicesOptions indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN; - Index[] result = indexNameExpressionResolver.concreteIndices(state, indicesOptions, true, "my-*::*"); + Index[] result = indexNameExpressionResolver.concreteIndices(state, indicesOptions, true, "my-*::data", "my-*::failures"); assertThat(result.length, equalTo(5)); List indexNames = Arrays.stream(result).map(Index::getName).toList(); assertThat( @@ -3225,8 +3262,8 @@ public void testDataStreamsNames() { assertThat(streams, containsInAnyOrder(new ResolvedExpression(dataStream1, DATA), new ResolvedExpression(dataStream2, DATA))); assertThat(names, containsInAnyOrder(dataStream1, dataStream2)); - streams = indexNameExpressionResolver.dataStreams(state, IndicesOptions.lenientExpand(), "*foobar::*"); - names = indexNameExpressionResolver.dataStreamNames(state, IndicesOptions.lenientExpand(), "*foobar::*"); + streams = indexNameExpressionResolver.dataStreams(state, IndicesOptions.lenientExpand(), "*foobar::data", "*foobar::failures"); + names = indexNameExpressionResolver.dataStreamNames(state, IndicesOptions.lenientExpand(), "*foobar::data", "*foobar::failures"); assertThat( streams, containsInAnyOrder( diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/SelectorResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/SelectorResolverTests.java index 2bf34dcfd2a34..dd3876afd3c74 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/SelectorResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/SelectorResolverTests.java @@ -18,7 +18,6 @@ import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; -import static org.elasticsearch.action.support.IndexComponentSelector.ALL_APPLICABLE; import static org.elasticsearch.action.support.IndexComponentSelector.DATA; import static org.elasticsearch.action.support.IndexComponentSelector.FAILURES; import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.Context; @@ -38,7 +37,6 @@ public void testResolveExpression() { assertThat(resolve(selectorsAllowed, "testXXX"), equalTo(new ResolvedExpression("testXXX", DATA))); assertThat(resolve(selectorsAllowed, "testXXX::data"), equalTo(new ResolvedExpression("testXXX", DATA))); assertThat(resolve(selectorsAllowed, "testXXX::failures"), equalTo(new ResolvedExpression("testXXX", FAILURES))); - assertThat(resolve(selectorsAllowed, "testXXX::*"), equalTo(new ResolvedExpression("testXXX", ALL_APPLICABLE))); // Disallow selectors (example: creating, modifying, or deleting indices/data streams/aliases). // Accepts standard expressions but throws when selectors are specified. @@ -47,7 +45,6 @@ public void testResolveExpression() { assertThat(resolve(noSelectors, "testXXX"), equalTo(new ResolvedExpression("testXXX"))); expectThrows(IllegalArgumentException.class, () -> resolve(noSelectors, "testXXX::data")); expectThrows(IllegalArgumentException.class, () -> resolve(noSelectors, "testXXX::failures")); - expectThrows(IllegalArgumentException.class, () -> resolve(noSelectors, "testXXX::*")); // === Errors // Only recognized components can be selected @@ -116,9 +113,7 @@ public void testCombineExpressionWithSelector() { assertThat(IndexNameExpressionResolver.combineSelectorExpression("a", null), is(equalTo("a"))); assertThat(IndexNameExpressionResolver.combineSelectorExpression("a", ""), is(equalTo("a::"))); assertThat(IndexNameExpressionResolver.combineSelectorExpression("a", "b"), is(equalTo("a::b"))); - assertThat(IndexNameExpressionResolver.combineSelectorExpression("a", "*"), is(equalTo("a::*"))); assertThat(IndexNameExpressionResolver.combineSelectorExpression("*", "b"), is(equalTo("*::b"))); - assertThat(IndexNameExpressionResolver.combineSelectorExpression("*", "*"), is(equalTo("*::*"))); } public void testHasSelectorSuffix() { @@ -151,14 +146,14 @@ public void testSplitSelectorExpression() { assertThat(IndexNameExpressionResolver.splitSelectorExpression("a::data"), is(equalTo(new Tuple<>("a", "data")))); assertThat(IndexNameExpressionResolver.splitSelectorExpression("a::failures"), is(equalTo(new Tuple<>("a", "failures")))); - assertThat(IndexNameExpressionResolver.splitSelectorExpression("a::*"), is(equalTo(new Tuple<>("a", "*")))); + expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("a::*")); expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("a::random")); expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("a::d*ta")); expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("a::*ailures")); expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("a::")); expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("a::**")); expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("index::data::*")); - assertThat(IndexNameExpressionResolver.splitSelectorExpression("::*"), is(equalTo(new Tuple<>("", "*")))); + expectThrows(InvalidIndexNameException.class, () -> IndexNameExpressionResolver.splitSelectorExpression("::*")); } private static IndicesOptions getOptionsForSelectors() { diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java index 9d9a5ebd37218..1eeaef473521d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java @@ -25,7 +25,6 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import static org.elasticsearch.action.support.IndexComponentSelector.ALL_APPLICABLE; import static org.elasticsearch.action.support.IndexComponentSelector.DATA; import static org.elasticsearch.action.support.IndexComponentSelector.FAILURES; import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.createBackingIndex; @@ -54,19 +53,19 @@ public void testConvertWildcardsJustIndicesTests() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "ku*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "ku*", DATA)), equalTo(resolvedExpressionsSet("kuku")) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*", DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXYY", "testYYY")) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXYY")) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "*", DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXYY", "testYYY", "kuku")) ); } @@ -87,7 +86,7 @@ public void testConvertWildcardsOpenClosedIndicesTests() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXXY", "testXYY")) ); context = new IndexNameExpressionResolver.Context( @@ -96,7 +95,7 @@ public void testConvertWildcardsOpenClosedIndicesTests() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", DATA)), equalTo(resolvedExpressionsSet("testXYY")) ); context = new IndexNameExpressionResolver.Context( @@ -105,7 +104,7 @@ public void testConvertWildcardsOpenClosedIndicesTests() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "testX*", DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXXY")) ); } @@ -128,31 +127,27 @@ public void testMultipleWildcards() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*X*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*X*", DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXXY", "testXYY")) ); assertThat( - newHashSet( - IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*X*Y", ALL_APPLICABLE) - ), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*X*Y", DATA)), equalTo(resolvedExpressionsSet("testXXY", "testXYY")) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "kuku*Y*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "kuku*Y*", DATA)), equalTo(resolvedExpressionsSet("kukuYYY")) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "*Y*", ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "*Y*", DATA)), equalTo(resolvedExpressionsSet("testXXY", "testXYY", "testYYY", "kukuYYY")) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*Y*X", ALL_APPLICABLE)) - .size(), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "test*Y*X", DATA)).size(), equalTo(0) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "*Y*X", ALL_APPLICABLE)) - .size(), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(context, "*Y*X", DATA)).size(), equalTo(0) ); } @@ -171,7 +166,7 @@ public void testAll() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, DATA)), equalTo(resolvedExpressionsSet("testXXX", "testXYY", "testYYY")) ); } @@ -189,7 +184,7 @@ public void testAll() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, null)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, DATA)), equalTo(resolvedExpressionsNoSelectorSet("testXXX", "testXYY", "testYYY")) ); } @@ -212,10 +207,7 @@ public void testAllAliases() { IndicesOptions.lenientExpandOpen(), // don't include hidden SystemIndexAccessLevel.NONE ); - assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, ALL_APPLICABLE)), - equalTo(newHashSet()) - ); + assertThat(newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, DATA)), equalTo(newHashSet())); } { @@ -235,7 +227,7 @@ public void testAllAliases() { SystemIndexAccessLevel.NONE ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, ALL_APPLICABLE)), + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, DATA)), equalTo(resolvedExpressionsSet("index-visible-alias")) ); } @@ -290,13 +282,8 @@ public void testAllDataStreams() { equalTo(resolvedExpressionsSet(DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis))) ); assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, ALL_APPLICABLE)), - equalTo( - resolvedExpressionsSet( - DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis), - DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis) - ) - ) + newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, FAILURES)), + equalTo(resolvedExpressionsSet(DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis))) ); } @@ -328,10 +315,7 @@ public void testAllDataStreams() { ); assertThat(newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, DATA)), equalTo(Set.of())); - assertThat( - newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, ALL_APPLICABLE)), - equalTo(Set.of()) - ); + assertThat(newHashSet(IndexNameExpressionResolver.WildcardExpressionResolver.resolveAll(context, FAILURES)), equalTo(Set.of())); } } @@ -455,7 +439,7 @@ public void testResolveAliases() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAndAliasesContext, "foo_a*", - ALL_APPLICABLE + DATA ); assertThat(indices, containsInAnyOrder(new ResolvedExpression("foo_index", DATA), new ResolvedExpression("bar_index", DATA))); } @@ -463,7 +447,7 @@ public void testResolveAliases() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( skipAliasesLenientContext, "foo_a*", - ALL_APPLICABLE + DATA ); assertEquals(0, indices.size()); } @@ -471,7 +455,7 @@ public void testResolveAliases() { Set indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( skipAliasesStrictContext, "foo_a*", - ALL_APPLICABLE + DATA ); assertThat(indices, empty()); } @@ -479,7 +463,7 @@ public void testResolveAliases() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAndAliasesContext, "foo*", - ALL_APPLICABLE + DATA ); assertThat( indices, @@ -494,7 +478,7 @@ public void testResolveAliases() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( skipAliasesLenientContext, "foo*", - ALL_APPLICABLE + DATA ); assertThat(indices, containsInAnyOrder(new ResolvedExpression("foo_foo", DATA), new ResolvedExpression("foo_index", DATA))); } @@ -502,7 +486,7 @@ public void testResolveAliases() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( skipAliasesStrictContext, "foo*", - ALL_APPLICABLE + DATA ); assertThat(indices, containsInAnyOrder(new ResolvedExpression("foo_foo", DATA), new ResolvedExpression("foo_index", DATA))); } @@ -556,7 +540,7 @@ public void testResolveDataStreams() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAndAliasesContext, "foo_*", - ALL_APPLICABLE + DATA ); assertThat( indices, @@ -571,7 +555,7 @@ public void testResolveDataStreams() { indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAndAliasesContext, "bar_*", - ALL_APPLICABLE + DATA ); assertThat(indices, containsInAnyOrder(new ResolvedExpression("bar_bar", DATA), new ResolvedExpression("bar_index", DATA))); } @@ -602,7 +586,7 @@ public void testResolveDataStreams() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAliasesAndDataStreamsContext, "foo_*", - ALL_APPLICABLE + DATA ); assertThat( indices, @@ -611,9 +595,7 @@ public void testResolveDataStreams() { new ResolvedExpression("bar_index", DATA), new ResolvedExpression("foo_foo", DATA), new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultFailureStoreName("foo_logs", 2, epochMillis), DATA) + new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), DATA) ) ); @@ -632,26 +614,6 @@ public void testResolveDataStreams() { ) ) ); - - // include all wildcard adds the data stream's backing indices - indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( - indicesAliasesAndDataStreamsContext, - "*", - ALL_APPLICABLE - ); - assertThat( - indices, - containsInAnyOrder( - new ResolvedExpression("foo_index", DATA), - new ResolvedExpression("bar_index", DATA), - new ResolvedExpression("foo_foo", DATA), - new ResolvedExpression("bar_bar", DATA), - new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultFailureStoreName("foo_logs", 2, epochMillis), DATA) - ) - ); } { @@ -681,7 +643,7 @@ public void testResolveDataStreams() { Collection indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAliasesDataStreamsAndHiddenIndices, "foo_*", - ALL_APPLICABLE + DATA ); assertThat( indices, @@ -690,9 +652,7 @@ public void testResolveDataStreams() { new ResolvedExpression("bar_index", DATA), new ResolvedExpression("foo_foo", DATA), new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis), DATA), - new ResolvedExpression(DataStream.getDefaultFailureStoreName("foo_logs", 2, epochMillis), DATA) + new ResolvedExpression(DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), DATA) ) ); @@ -712,32 +672,11 @@ public void testResolveDataStreams() { ) ); - // Resolve both backing and failure indices - indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( - indicesAliasesDataStreamsAndHiddenIndices, - "foo_*", - ALL_APPLICABLE - ); - assertThat( - newHashSet(indices), - equalTo( - resolvedExpressionsSet( - "foo_index", - "bar_index", - "foo_foo", - DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis), - DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), - DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis), - DataStream.getDefaultFailureStoreName("foo_logs", 2, epochMillis) - ) - ) - ); - // include all wildcard adds the data stream's backing indices indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAliasesDataStreamsAndHiddenIndices, "*", - ALL_APPLICABLE + DATA ); assertThat( newHashSet(indices), @@ -770,28 +709,6 @@ public void testResolveDataStreams() { ) ) ); - - // include all wildcard adds the data stream's backing and failure indices - indices = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( - indicesAliasesDataStreamsAndHiddenIndices, - "*", - ALL_APPLICABLE - ); - assertThat( - newHashSet(indices), - equalTo( - resolvedExpressionsSet( - "foo_index", - "bar_index", - "foo_foo", - "bar_bar", - DataStream.getDefaultBackingIndexName("foo_logs", 1, epochMillis), - DataStream.getDefaultBackingIndexName("foo_logs", 2, epochMillis), - DataStream.getDefaultFailureStoreName("foo_logs", 1, epochMillis), - DataStream.getDefaultFailureStoreName("foo_logs", 2, epochMillis) - ) - ) - ); } } @@ -824,7 +741,7 @@ public void testMatchesConcreteIndicesWildcardAndAliases() { Collection matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( indicesAndAliasesContext, "*", - ALL_APPLICABLE + DATA ); assertThat( matches, @@ -835,7 +752,7 @@ public void testMatchesConcreteIndicesWildcardAndAliases() { new ResolvedExpression("bar_index", DATA) ) ); - matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(onlyIndicesContext, "*", ALL_APPLICABLE); + matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(onlyIndicesContext, "*", DATA); assertThat( matches, containsInAnyOrder( @@ -845,11 +762,7 @@ public void testMatchesConcreteIndicesWildcardAndAliases() { new ResolvedExpression("bar_index", DATA) ) ); - matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( - indicesAndAliasesContext, - "foo*", - ALL_APPLICABLE - ); + matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(indicesAndAliasesContext, "foo*", DATA); assertThat( matches, containsInAnyOrder( @@ -858,11 +771,7 @@ public void testMatchesConcreteIndicesWildcardAndAliases() { new ResolvedExpression("bar_index", DATA) ) ); - matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources( - onlyIndicesContext, - "foo*", - ALL_APPLICABLE - ); + matches = IndexNameExpressionResolver.WildcardExpressionResolver.matchWildcardToResources(onlyIndicesContext, "foo*", DATA); assertThat(matches, containsInAnyOrder(new ResolvedExpression("foo_foo", DATA), new ResolvedExpression("foo_index", DATA))); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java index f7dc725c3f07d..6099b7351cf76 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolverTests.java @@ -465,22 +465,6 @@ public void testSelectorsDoNotImpactWildcardDetection() { ); } - public void testWildcardSelectorsAreNotAllowedInShardLevelRequests() { - ShardSearchRequest request = mock(ShardSearchRequest.class); - when(request.indices()).thenReturn(new String[] { "index10::*" }); - IllegalArgumentException exception = expectThrows( - IllegalArgumentException.class, - () -> defaultIndicesResolver.resolveIndicesAndAliasesWithoutWildcards(TransportSearchAction.TYPE.name() + "[s]", request) - ); - assertThat( - exception, - throwableWithMessage( - "the action indices:data/read/search[s] does not support wildcard selectors;" - + " the provided index expression(s) [index10::*] are not allowed" - ) - ); - } - public void testAllIsNotAllowedInShardLevelRequests() { ShardSearchRequest request = mock(ShardSearchRequest.class); final boolean literalAll = randomBoolean();