|
@@ -32,9 +32,12 @@ import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
+import static org.elasticsearch.cluster.DataStreamTestHelper.createBackingIndex;
|
|
|
|
|
+import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField;
|
|
|
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
|
import static org.elasticsearch.common.util.set.Sets.newHashSet;
|
|
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
+import static org.hamcrest.Matchers.is;
|
|
|
|
|
|
|
|
public class WildcardExpressionResolverTests extends ESTestCase {
|
|
public class WildcardExpressionResolverTests extends ESTestCase {
|
|
|
public void testConvertWildcardsJustIndicesTests() {
|
|
public void testConvertWildcardsJustIndicesTests() {
|
|
@@ -207,6 +210,77 @@ public class WildcardExpressionResolverTests extends ESTestCase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void testResolveDataStreams() {
|
|
|
|
|
+ String dataStreamName = "foo_logs";
|
|
|
|
|
+ IndexMetadata firstBackingIndexMetadata = createBackingIndex(dataStreamName, 1).build();
|
|
|
|
|
+ IndexMetadata secondBackingIndexMetadata = createBackingIndex(dataStreamName, 2).build();
|
|
|
|
|
+
|
|
|
|
|
+ Metadata.Builder mdBuilder = Metadata.builder()
|
|
|
|
|
+ .put(indexBuilder("foo_foo").state(State.OPEN))
|
|
|
|
|
+ .put(indexBuilder("bar_bar").state(State.OPEN))
|
|
|
|
|
+ .put(indexBuilder("foo_index").state(State.OPEN).putAlias(AliasMetadata.builder("foo_alias")))
|
|
|
|
|
+ .put(indexBuilder("bar_index").state(State.OPEN).putAlias(AliasMetadata.builder("foo_alias")))
|
|
|
|
|
+ .put(firstBackingIndexMetadata, true)
|
|
|
|
|
+ .put(secondBackingIndexMetadata, true)
|
|
|
|
|
+ .put(new DataStream(dataStreamName, createTimestampField("timestamp"),
|
|
|
|
|
+ List.of(firstBackingIndexMetadata.getIndex(), secondBackingIndexMetadata.getIndex())));
|
|
|
|
|
+
|
|
|
|
|
+ ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build();
|
|
|
|
|
+
|
|
|
|
|
+ IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver();
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false,
|
|
|
|
|
+ false, false);
|
|
|
|
|
+ IndexNameExpressionResolver.Context indicesAndAliasesContext =
|
|
|
|
|
+ new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions);
|
|
|
|
|
+
|
|
|
|
|
+ // data streams are not included but expression matches the data stream
|
|
|
|
|
+ IllegalArgumentException illegalArgumentException = expectThrows(IllegalArgumentException.class,
|
|
|
|
|
+ () -> resolver.resolve(indicesAndAliasesContext, Collections.singletonList("foo_*")));
|
|
|
|
|
+ assertThat(illegalArgumentException.getMessage(), is("The provided expression [foo_*] matches a data stream, specify the " +
|
|
|
|
|
+ "corresponding concrete indices instead."));
|
|
|
|
|
+
|
|
|
|
|
+ // data streams are not included and expression doesn't match the data steram
|
|
|
|
|
+ List<String> indices = resolver.resolve(indicesAndAliasesContext, Collections.singletonList("bar_*"));
|
|
|
|
|
+ assertThat(indices, containsInAnyOrder("bar_bar", "bar_index"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false,
|
|
|
|
|
+ false, false);
|
|
|
|
|
+ IndexNameExpressionResolver.Context indicesAliasesAndDataStreamsContext = new IndexNameExpressionResolver.Context(state,
|
|
|
|
|
+ indicesAndAliasesOptions, false, false, true);
|
|
|
|
|
+
|
|
|
|
|
+ // data stream's corresponding backing indices are resolved
|
|
|
|
|
+ List<String> indices = resolver.resolve(indicesAliasesAndDataStreamsContext, Collections.singletonList("foo_*"));
|
|
|
|
|
+ assertThat(indices, containsInAnyOrder("foo_index", "bar_index", "foo_foo", ".ds-foo_logs-000001",
|
|
|
|
|
+ ".ds-foo_logs-000002"));
|
|
|
|
|
+
|
|
|
|
|
+ // include all wildcard adds the data stream's backing indices
|
|
|
|
|
+ indices = resolver.resolve(indicesAliasesAndDataStreamsContext, Collections.singletonList("*"));
|
|
|
|
|
+ assertThat(indices, containsInAnyOrder("foo_index", "bar_index", "foo_foo", "bar_bar", ".ds-foo_logs-000001",
|
|
|
|
|
+ ".ds-foo_logs-000002"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ {
|
|
|
|
|
+ IndicesOptions indicesAliasesAndExpandHiddenOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false,
|
|
|
|
|
+ true, true, false, false, false);
|
|
|
|
|
+ IndexNameExpressionResolver.Context indicesAliasesDataStreamsAndHiddenIndices = new IndexNameExpressionResolver.Context(state,
|
|
|
|
|
+ indicesAliasesAndExpandHiddenOptions, false, false, true);
|
|
|
|
|
+
|
|
|
|
|
+ // data stream's corresponding backing indices are resolved
|
|
|
|
|
+ List<String> indices = resolver.resolve(indicesAliasesDataStreamsAndHiddenIndices, Collections.singletonList("foo_*"));
|
|
|
|
|
+ assertThat(indices, containsInAnyOrder("foo_index", "bar_index", "foo_foo", ".ds-foo_logs-000001",
|
|
|
|
|
+ ".ds-foo_logs-000002"));
|
|
|
|
|
+
|
|
|
|
|
+ // include all wildcard adds the data stream's backing indices
|
|
|
|
|
+ indices = resolver.resolve(indicesAliasesDataStreamsAndHiddenIndices, Collections.singletonList("*"));
|
|
|
|
|
+ assertThat(indices, containsInAnyOrder("foo_index", "bar_index", "foo_foo", "bar_bar", ".ds-foo_logs-000001",
|
|
|
|
|
+ ".ds-foo_logs-000002"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void testMatchesConcreteIndicesWildcardAndAliases() {
|
|
public void testMatchesConcreteIndicesWildcardAndAliases() {
|
|
|
Metadata.Builder mdBuilder = Metadata.builder()
|
|
Metadata.Builder mdBuilder = Metadata.builder()
|
|
|
.put(indexBuilder("foo_foo").state(State.OPEN))
|
|
.put(indexBuilder("foo_foo").state(State.OPEN))
|