From abcb110382ea40eae591f76038139c977eecb272 Mon Sep 17 00:00:00 2001 From: jaymode Date: Thu, 11 Feb 2021 09:06:21 -0700 Subject: [PATCH] Introduce system index types including external This commit introduces system index types that will be used to differentiate behavior. Previously system indices were all treated the same regardless of whether they belonged to Elasticsearch, a stack component, or one of our solutions. Upon further discussion and analysis this decision was not in the best interest of the various teams and instead a new type of system index was needed. These system indices will be referred to as external system indices. Within external system indices, an option exists for these indices to be managed by Elasticsearch or to be managed by the external product. In order to represent this within Elasticsearch, each system index will have a type and this type will be used to control behavior. Closes #67383 --- .../elasticsearch/kibana/KibanaPlugin.java | 143 ++++-------------- .../kibana/KibanaPluginTests.java | 18 +-- .../ReindexSourceTargetValidationTests.java | 5 +- .../action/IndicesRequestIT.java | 5 +- .../indices/TestSystemIndexDescriptor.java | 4 +- .../DedicatedClusterSnapshotRestoreIT.java | 5 +- .../alias/get/TransportGetAliasesAction.java | 49 ++++-- .../elasticsearch/cluster/ClusterModule.java | 6 +- .../metadata/IndexNameExpressionResolver.java | 103 ++++++++----- .../indices/SystemIndexDescriptor.java | 107 ++++++++++++- .../elasticsearch/indices/SystemIndices.java | 52 +++++++ .../java/org/elasticsearch/node/Node.java | 18 +-- .../elasticsearch/rest/RestController.java | 17 ++- .../action/ActionModuleTests.java | 18 ++- ...tAddVotingConfigExclusionsActionTests.java | 6 +- ...learVotingConfigExclusionsActionTests.java | 5 +- .../get/TransportGetAliasesActionTests.java | 31 ++-- .../indices/get/GetIndexActionTests.java | 4 +- .../mapping/put/PutMappingRequestTests.java | 12 +- .../indices/resolve/ResolveIndexTests.java | 5 +- .../MetadataRolloverServiceTests.java | 3 +- .../settings/get/GetSettingsActionTests.java | 4 +- ...ActionIndicesThatCannotBeCreatedTests.java | 11 +- .../bulk/TransportBulkActionIngestTests.java | 3 +- .../bulk/TransportBulkActionTookTests.java | 2 +- .../get/TransportMultiGetActionTests.java | 3 +- .../search/MultiSearchActionTookTests.java | 14 -- .../action/support/AutoCreateIndexTests.java | 9 +- .../TransportBroadcastByNodeActionTests.java | 3 +- .../TransportMasterNodeActionTests.java | 7 +- .../BroadcastReplicationTests.java | 6 +- ...ortInstanceSingleOperationActionTests.java | 5 +- .../TransportMultiTermVectorsActionTests.java | 3 +- .../cluster/ClusterModuleTests.java | 16 +- .../health/ClusterStateHealthTests.java | 8 +- .../DateMathExpressionResolverTests.java | 6 +- ...ExpressionResolverAliasIterationTests.java | 9 +- ...sionResolverExpressionsIterationTests.java | 9 +- .../IndexNameExpressionResolverTests.java | 121 +++++++-------- .../WildcardExpressionResolverTests.java | 31 ++-- .../elasticsearch/index/IndexModuleTests.java | 43 +++--- .../query/SearchIndexNameMatcherTests.java | 7 +- .../indices/cluster/ClusterStateChanges.java | 3 +- .../snapshots/SnapshotResiliencyTests.java | 2 +- .../core/ilm/GenerateSnapshotNameStep.java | 3 +- .../validation/SourceDestValidatorTests.java | 20 +-- .../DeprecationInfoActionResponseTests.java | 4 +- .../core/ml/utils/MlIndexAndAliasTests.java | 3 +- .../DeleteDataStreamTransportActionTests.java | 7 +- .../GetDataStreamsTransportActionTests.java | 59 +++----- .../xpack/enrich/AbstractEnrichTestCase.java | 7 +- .../enrich/EnrichPolicyExecutorTests.java | 19 +-- .../EnrichPolicyMaintenanceServiceTests.java | 7 +- .../integration/ModelSnapshotRetentionIT.java | 4 +- .../AutodetectResultProcessorIT.java | 6 +- .../ml/integration/EstablishedMemUsageIT.java | 7 +- .../ml/integration/JobResultsProviderIT.java | 6 +- .../integration/JobStorageDeletionTaskIT.java | 5 +- .../ml/integration/MlAutoUpdateServiceIT.java | 5 +- .../ml/integration/MlConfigMigratorIT.java | 5 +- .../ml/integration/UnusedStatsRemoverIT.java | 4 +- ...ortStartDataFrameAnalyticsActionTests.java | 3 +- .../DatafeedConfigAutoUpdaterTests.java | 5 +- .../datafeed/DatafeedNodeSelectorTests.java | 4 +- .../TrainedModelStatsServiceTests.java | 8 +- .../persistence/JobResultsProviderTests.java | 4 +- .../AutodetectProcessManagerTests.java | 4 +- .../OpenJobPersistentTasksExecutorTests.java | 4 +- ...stractJobPersistentTasksExecutorTests.java | 8 +- .../cluster/ClusterStatsCollectorTests.java | 8 +- .../DateMathExpressionIntegTests.java | 5 +- .../xpack/security/SecurityTests.java | 3 +- .../authz/AuthorizationServiceTests.java | 10 +- .../authz/IndicesAndAliasesResolverTests.java | 5 +- ...TransformPersistentTasksExecutorTests.java | 7 +- .../xpack/watcher/WatcherPluginTests.java | 5 +- 76 files changed, 706 insertions(+), 489 deletions(-) diff --git a/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java b/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java index 2afb2b058ec53..07311747d18bf 100644 --- a/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java +++ b/modules/kibana/src/main/java/org/elasticsearch/kibana/KibanaPlugin.java @@ -8,130 +8,53 @@ package org.elasticsearch.kibana; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.settings.ClusterSettings; -import org.elasticsearch.common.settings.IndexScopedSettings; -import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsFilter; -import org.elasticsearch.index.reindex.RestDeleteByQueryAction; import org.elasticsearch.indices.SystemIndexDescriptor; +import org.elasticsearch.indices.SystemIndexDescriptor.Type; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.SystemIndexPlugin; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestHandler; -import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction; -import org.elasticsearch.rest.action.admin.indices.RestGetAliasesAction; -import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction; -import org.elasticsearch.rest.action.admin.indices.RestIndexPutAliasAction; -import org.elasticsearch.rest.action.admin.indices.RestRefreshAction; -import org.elasticsearch.rest.action.admin.indices.RestUpdateSettingsAction; -import org.elasticsearch.rest.action.document.RestBulkAction; -import org.elasticsearch.rest.action.document.RestDeleteAction; -import org.elasticsearch.rest.action.document.RestGetAction; -import org.elasticsearch.rest.action.document.RestIndexAction; -import org.elasticsearch.rest.action.document.RestIndexAction.AutoIdHandler; -import org.elasticsearch.rest.action.document.RestIndexAction.CreateHandler; -import org.elasticsearch.rest.action.document.RestMultiGetAction; -import org.elasticsearch.rest.action.document.RestUpdateAction; -import org.elasticsearch.rest.action.search.RestClearScrollAction; -import org.elasticsearch.rest.action.search.RestSearchAction; -import org.elasticsearch.rest.action.search.RestSearchScrollAction; import java.util.Collection; import java.util.List; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; public class KibanaPlugin extends Plugin implements SystemIndexPlugin { - public static final Setting> KIBANA_INDEX_NAMES_SETTING = Setting.listSetting( - "kibana.system_indices", - List.of(".kibana", ".kibana_*", ".reporting-*", ".apm-agent-configuration", ".apm-custom-link"), - Function.identity(), - Property.NodeScope - ); + public static final SystemIndexDescriptor KIBANA_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder() + .setIndexPattern(".kibana_*") + .setDescription("Kibana saved objects system index") + .setAliasName(".kibana") + .setType(Type.EXTERNAL_UNMANAGED) + .setAllowedStackComponents(List.of("kibana")) + .build(); + + public static final SystemIndexDescriptor REPORTING_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder() + .setIndexPattern(".reporting-*") + .setDescription("system index for reporting") + .setType(Type.EXTERNAL_UNMANAGED) + .setAllowedStackComponents(List.of("kibana")) + .build(); + + public static final SystemIndexDescriptor APM_AGENT_CONFIG_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder() + .setIndexPattern(".apm-agent-configuration") + .setDescription("system index for APM agent configuration") + .setType(Type.EXTERNAL_UNMANAGED) + .setAllowedStackComponents(List.of("kibana")) + .build(); + + public static final SystemIndexDescriptor APM_CUSTOM_LINK_INDEX_DESCRIPTOR = SystemIndexDescriptor.builder() + .setIndexPattern(".apm-custom-link") + .setDescription("system index for APM custom links") + .setType(Type.EXTERNAL_UNMANAGED) + .setAllowedStackComponents(List.of("kibana")) + .build(); @Override public Collection getSystemIndexDescriptors(Settings settings) { - return KIBANA_INDEX_NAMES_SETTING.get(settings) - .stream() - .map(pattern -> new SystemIndexDescriptor(pattern, "System index used by kibana")) - .collect(Collectors.toUnmodifiableList()); - } - - @Override - public List getRestHandlers( - Settings settings, - RestController restController, - ClusterSettings clusterSettings, - IndexScopedSettings indexScopedSettings, - SettingsFilter settingsFilter, - IndexNameExpressionResolver indexNameExpressionResolver, - Supplier nodesInCluster - ) { - // TODO need to figure out what subset of system indices Kibana should have access to via these APIs return List.of( - // Based on https://github.com/elastic/kibana/issues/49764 - // apis needed to perform migrations... ideally these will go away - new KibanaWrappedRestHandler(new RestCreateIndexAction()), - new KibanaWrappedRestHandler(new RestGetAliasesAction()), - new KibanaWrappedRestHandler(new RestIndexPutAliasAction()), - new KibanaWrappedRestHandler(new RestRefreshAction()), - - // apis needed to access saved objects - new KibanaWrappedRestHandler(new RestGetAction()), - new KibanaWrappedRestHandler(new RestMultiGetAction(settings)), - new KibanaWrappedRestHandler(new RestSearchAction()), - new KibanaWrappedRestHandler(new RestBulkAction(settings)), - new KibanaWrappedRestHandler(new RestDeleteAction()), - new KibanaWrappedRestHandler(new RestDeleteByQueryAction()), - - // api used for testing - new KibanaWrappedRestHandler(new RestUpdateSettingsAction()), - - // apis used specifically by reporting - new KibanaWrappedRestHandler(new RestGetIndicesAction()), - new KibanaWrappedRestHandler(new RestIndexAction()), - new KibanaWrappedRestHandler(new CreateHandler()), - new KibanaWrappedRestHandler(new AutoIdHandler(nodesInCluster)), - new KibanaWrappedRestHandler(new RestUpdateAction()), - new KibanaWrappedRestHandler(new RestSearchScrollAction()), - new KibanaWrappedRestHandler(new RestClearScrollAction()) + KIBANA_INDEX_DESCRIPTOR, + REPORTING_INDEX_DESCRIPTOR, + APM_AGENT_CONFIG_INDEX_DESCRIPTOR, + APM_CUSTOM_LINK_INDEX_DESCRIPTOR ); - - } - - @Override - public List> getSettings() { - return List.of(KIBANA_INDEX_NAMES_SETTING); - } - - static class KibanaWrappedRestHandler extends BaseRestHandler.Wrapper { - - KibanaWrappedRestHandler(BaseRestHandler delegate) { - super(delegate); - } - - @Override - public String getName() { - return "kibana_" + super.getName(); - } - - @Override - public boolean allowSystemIndexAccessByDefault() { - return true; - } - - @Override - public List routes() { - return super.routes().stream() - .map(route -> new Route(route.getMethod(), "/_kibana" + route.getPath())) - .collect(Collectors.toUnmodifiableList()); - } } } diff --git a/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java b/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java index c34bf9fe6c4f7..0f8b9ba7071cc 100644 --- a/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java +++ b/modules/kibana/src/test/java/org/elasticsearch/kibana/KibanaPluginTests.java @@ -12,35 +12,19 @@ import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.test.ESTestCase; -import java.util.List; import java.util.stream.Collectors; import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.is; public class KibanaPluginTests extends ESTestCase { public void testKibanaIndexNames() { - assertThat(new KibanaPlugin().getSettings(), contains(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING)); assertThat( new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY) .stream() .map(SystemIndexDescriptor::getIndexPattern) .collect(Collectors.toUnmodifiableList()), - contains(".kibana", ".kibana_*", ".reporting-*", ".apm-agent-configuration", ".apm-custom-link") - ); - - final List names = List.of("." + randomAlphaOfLength(4), "." + randomAlphaOfLength(5)); - final List namesFromDescriptors = new KibanaPlugin().getSystemIndexDescriptors( - Settings.builder().putList(KibanaPlugin.KIBANA_INDEX_NAMES_SETTING.getKey(), names).build() - ).stream().map(SystemIndexDescriptor::getIndexPattern).collect(Collectors.toUnmodifiableList()); - assertThat(namesFromDescriptors, is(names)); - - assertThat( - new KibanaPlugin().getSystemIndexDescriptors(Settings.EMPTY) - .stream() - .anyMatch(systemIndexDescriptor -> systemIndexDescriptor.matchesIndexPattern(".kibana-event-log-7-1")), - is(false) + contains(".kibana_*", ".reporting-*", ".apm-agent-configuration", ".apm-custom-link") ); } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexSourceTargetValidationTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexSourceTargetValidationTests.java index 57f4aa2502ecf..90a051177f7f8 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexSourceTargetValidationTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexSourceTargetValidationTests.java @@ -24,11 +24,12 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import java.util.HashMap; +import java.util.Map; import static java.util.Collections.emptyMap; import static org.hamcrest.Matchers.containsString; @@ -52,7 +53,7 @@ public class ReindexSourceTargetValidationTests extends ESTestCase { .put(index("source", "source_multi"), true) .put(index("source2", "source_multi"), true)).build(); private static final IndexNameExpressionResolver INDEX_NAME_EXPRESSION_RESOLVER = - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); private static final AutoCreateIndex AUTO_CREATE_INDEX = new AutoCreateIndex(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), INDEX_NAME_EXPRESSION_RESOLVER, new SystemIndices(new HashMap<>())); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/IndicesRequestIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/IndicesRequestIT.java index bb80a88357d80..a789a33a75467 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/IndicesRequestIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/IndicesRequestIT.java @@ -72,6 +72,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.PluginsService; @@ -381,7 +382,7 @@ public void testFlush() { internalCluster().coordOnlyNodeClient().admin().indices().flush(flushRequest).actionGet(); clearInterceptedActions(); - String[] indices = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) + String[] indices = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())) .concreteIndexNames(client().admin().cluster().prepareState().get().getState(), flushRequest); assertIndicesSubset(Arrays.asList(indices), indexShardActions); } @@ -406,7 +407,7 @@ public void testRefresh() { internalCluster().coordOnlyNodeClient().admin().indices().refresh(refreshRequest).actionGet(); clearInterceptedActions(); - String[] indices = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) + String[] indices = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())) .concreteIndexNames(client().admin().cluster().prepareState().get().getState(), refreshRequest); assertIndicesSubset(Arrays.asList(indices), indexShardActions); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java index 313dadb816ea1..e3180f7e44560 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/TestSystemIndexDescriptor.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.UncheckedIOException; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; @@ -38,7 +39,8 @@ public class TestSystemIndexDescriptor extends SystemIndexDescriptor { .build(); TestSystemIndexDescriptor() { - super(INDEX_NAME + "*", PRIMARY_INDEX_NAME, "Test system index", null, SETTINGS, INDEX_NAME, 0, "version", "stack", null); + super(INDEX_NAME + "*", PRIMARY_INDEX_NAME, "Test system index", null, SETTINGS, INDEX_NAME, 0, "version", "stack", null, + Type.INTERNAL, List.of()); } @Override diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index 0f2186eea9f1f..52dbce9d14e17 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -37,6 +37,7 @@ import org.elasticsearch.index.seqno.RetentionLeaseActions; import org.elasticsearch.index.seqno.RetentionLeases; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.indices.recovery.PeerRecoveryTargetService; import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.node.Node; @@ -71,6 +72,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -585,7 +587,8 @@ public void testRestoreShrinkIndex() throws Exception { public void testSnapshotWithDateMath() { final String repo = "repo"; - final IndexNameExpressionResolver nameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + final IndexNameExpressionResolver nameExpressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); final String snapshotName = ""; logger.info("--> creating repository"); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java index f27c316e3cf92..dc4203392160a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesAction.java @@ -16,6 +16,7 @@ import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; @@ -32,6 +33,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.function.Predicate; import java.util.stream.Collectors; public class TransportGetAliasesAction extends TransportMasterNodeReadAction { @@ -63,10 +65,12 @@ protected void masterOperation(Task task, GetAliasesRequest request, ClusterStat try (ThreadContext.StoredContext ignore = threadPool.getThreadContext().newStoredContext(false)) { concreteIndices = indexNameExpressionResolver.concreteIndexNames(state, request); } - final boolean systemIndexAccessAllowed = indexNameExpressionResolver.isSystemIndexAccessAllowed(); + final SystemIndexAccessLevel systemIndexAccessLevel = indexNameExpressionResolver.getSystemIndexAccessLevel(); + final String elasticProduct = + threadPool.getThreadContext().getHeader(IndexNameExpressionResolver.EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY); ImmutableOpenMap> aliases = state.metadata().findAliases(request, concreteIndices); listener.onResponse(new GetAliasesResponse(postProcess(request, concreteIndices, aliases, state, - systemIndexAccessAllowed, systemIndices))); + systemIndexAccessLevel, elasticProduct, systemIndices))); } /** @@ -74,8 +78,8 @@ protected void masterOperation(Task task, GetAliasesRequest request, ClusterStat */ static ImmutableOpenMap> postProcess(GetAliasesRequest request, String[] concreteIndices, ImmutableOpenMap> aliases, - ClusterState state, boolean systemIndexAccessAllowed, - SystemIndices systemIndices) { + ClusterState state, SystemIndexAccessLevel systemIndexAccessLevel, + String elasticProduct, SystemIndices systemIndices) { boolean noAliasesSpecified = request.getOriginalAliases() == null || request.getOriginalAliases().length == 0; ImmutableOpenMap.Builder> mapBuilder = ImmutableOpenMap.builder(aliases); for (String index : concreteIndices) { @@ -85,20 +89,32 @@ static ImmutableOpenMap> postProcess(GetAliasesReque } } final ImmutableOpenMap> finalResponse = mapBuilder.build(); - if (systemIndexAccessAllowed == false) { - checkSystemIndexAccess(request, systemIndices, state, finalResponse); + if (systemIndexAccessLevel != SystemIndexAccessLevel.ALL) { + checkSystemIndexAccess(request, systemIndices, state, finalResponse, systemIndexAccessLevel, elasticProduct); } return finalResponse; } private static void checkSystemIndexAccess(GetAliasesRequest request, SystemIndices systemIndices, ClusterState state, - ImmutableOpenMap> aliasesMap) { + ImmutableOpenMap> aliasesMap, + SystemIndexAccessLevel systemIndexAccessLevel, String elasticProduct) { + final Predicate systemIndexAccessAllowPredicate; + if (systemIndexAccessLevel == SystemIndexAccessLevel.NONE) { + systemIndexAccessAllowPredicate = indexMetadata -> false; + } else if (systemIndexAccessLevel == SystemIndexAccessLevel.RESTRICTED) { + systemIndexAccessAllowPredicate = systemIndices.getProductSystemIndexMetadataPredicate(elasticProduct); + } else { + throw new IllegalArgumentException("Unexpected system index access level: " + systemIndexAccessLevel); + } + List systemIndicesNames = new ArrayList<>(); for (Iterator it = aliasesMap.keysIt(); it.hasNext(); ) { String indexName = it.next(); IndexMetadata index = state.metadata().index(indexName); if (index != null && index.isSystem()) { - systemIndicesNames.add(indexName); + if (systemIndexAccessAllowPredicate.test(index) == false) { + systemIndicesNames.add(indexName); + } } } if (systemIndicesNames.isEmpty() == false) { @@ -106,13 +122,24 @@ private static void checkSystemIndexAccess(GetAliasesRequest request, SystemIndi "this request accesses system indices: {}, but in a future major version, direct access to system " + "indices will be prevented by default", systemIndicesNames); } else { - checkSystemAliasAccess(request, systemIndices); + checkSystemAliasAccess(request, systemIndices, systemIndexAccessLevel, elasticProduct); } } - private static void checkSystemAliasAccess(GetAliasesRequest request, SystemIndices systemIndices) { + private static void checkSystemAliasAccess(GetAliasesRequest request, SystemIndices systemIndices, + SystemIndexAccessLevel systemIndexAccessLevel, String elasticProduct) { + final Predicate systemIndexAccessAllowPredicate; + if (systemIndexAccessLevel == SystemIndexAccessLevel.NONE) { + systemIndexAccessAllowPredicate = name -> true; + } else if (systemIndexAccessLevel == SystemIndexAccessLevel.RESTRICTED) { + systemIndexAccessAllowPredicate = systemIndices.getProductSystemIndexNamePredicate(elasticProduct).negate(); + } else { + throw new IllegalArgumentException("Unexpected system index access level: " + systemIndexAccessLevel); + } + final List systemAliases = Arrays.stream(request.aliases()) - .filter(alias -> systemIndices.isSystemIndex(alias)) + .filter(systemIndices::isSystemIndex) + .filter(systemIndexAccessAllowPredicate) .collect(Collectors.toList()); if (systemAliases.isEmpty() == false) { deprecationLogger.deprecate(DeprecationCategory.API, "open_system_alias_access", diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java index 090b6797fe500..5e59633c2b19c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterModule.java @@ -61,6 +61,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.gateway.GatewayAllocator; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.ingest.IngestMetadata; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.persistent.PersistentTasksNodeService; @@ -100,13 +101,14 @@ public class ClusterModule extends AbstractModule { final ShardsAllocator shardsAllocator; public ClusterModule(Settings settings, ClusterService clusterService, List clusterPlugins, - ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService, ThreadContext threadContext) { + ClusterInfoService clusterInfoService, SnapshotsInfoService snapshotsInfoService, ThreadContext threadContext, + SystemIndices systemIndices) { this.clusterPlugins = clusterPlugins; this.deciderList = createAllocationDeciders(settings, clusterService.getClusterSettings(), clusterPlugins); this.allocationDeciders = new AllocationDeciders(deciderList); this.shardsAllocator = createShardsAllocator(settings, clusterService.getClusterSettings(), clusterPlugins); this.clusterService = clusterService; - this.indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext); + this.indexNameExpressionResolver = new IndexNameExpressionResolver(threadContext, systemIndices); this.allocationService = new AllocationService(allocationDeciders, shardsAllocator, clusterInfoService, snapshotsInfoService); } 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 6bc2cf1d5d438..adabec42f8a98 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java @@ -30,6 +30,7 @@ import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.indices.InvalidIndexNameException; +import org.elasticsearch.indices.SystemIndices; import java.time.Instant; import java.time.ZoneId; @@ -57,6 +58,7 @@ public class IndexNameExpressionResolver { public static final String EXCLUDED_DATA_STREAMS_KEY = "es.excluded_ds"; public static final String SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY = "_system_index_access_allowed"; + public static final String EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY = "_system_index_access_allowed"; public static final Version SYSTEM_INDEX_ENFORCEMENT_VERSION = Version.V_8_0_0; private final DateMathExpressionResolver dateMathExpressionResolver = new DateMathExpressionResolver(); @@ -64,18 +66,19 @@ public class IndexNameExpressionResolver { private final List expressionResolvers = List.of(dateMathExpressionResolver, wildcardExpressionResolver); private final ThreadContext threadContext; + private final SystemIndices systemIndices; - public IndexNameExpressionResolver(ThreadContext threadContext) { + public IndexNameExpressionResolver(ThreadContext threadContext, SystemIndices systemIndices) { this.threadContext = Objects.requireNonNull(threadContext, "Thread Context must not be null"); + this.systemIndices = Objects.requireNonNull(systemIndices, "System Indices must not be null"); } - /** * Same as {@link #concreteIndexNames(ClusterState, IndicesOptions, String...)}, but the index expressions and options * are encapsulated in the specified request. */ public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), - isSystemIndexAccessAllowed()); + getSystemIndexAccessLevel()); return concreteIndexNames(context, request.indices()); } @@ -83,7 +86,8 @@ public String[] concreteIndexNames(ClusterState state, IndicesRequest request) { * Same as {@link #concreteIndexNames(ClusterState, IndicesRequest)}, but access to system indices is always allowed. */ public String[] concreteIndexNamesWithSystemIndexAccess(ClusterState state, IndicesRequest request) { - Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), true); + Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), + SystemIndexAccessLevel.ALL); return concreteIndexNames(context, request.indices()); } @@ -93,7 +97,7 @@ public String[] concreteIndexNamesWithSystemIndexAccess(ClusterState state, Indi */ public Index[] concreteIndices(ClusterState state, IndicesRequest request) { Context context = new Context(state, request.indicesOptions(), false, false, request.includeDataStreams(), - isSystemIndexAccessAllowed()); + getSystemIndexAccessLevel()); return concreteIndices(context, request.indices()); } @@ -111,23 +115,23 @@ public Index[] concreteIndices(ClusterState state, IndicesRequest request) { * indices options in the context don't allow such a case. */ public String[] concreteIndexNames(ClusterState state, IndicesOptions options, String... indexExpressions) { - Context context = new Context(state, options, isSystemIndexAccessAllowed()); + Context context = new Context(state, options, getSystemIndexAccessLevel()); return concreteIndexNames(context, indexExpressions); } public String[] concreteIndexNames(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) { - Context context = new Context(state, options, false, false, includeDataStreams, isSystemIndexAccessAllowed()); + Context context = new Context(state, options, false, false, includeDataStreams, getSystemIndexAccessLevel()); return concreteIndexNames(context, indexExpressions); } public String[] concreteIndexNames(ClusterState state, IndicesOptions options, IndicesRequest request) { - Context context = new Context(state, options, false, false, request.includeDataStreams(), isSystemIndexAccessAllowed()); + Context context = new Context(state, options, false, false, request.includeDataStreams(), getSystemIndexAccessLevel()); return concreteIndexNames(context, request.indices()); } public List dataStreamNames(ClusterState state, IndicesOptions options, String... indexExpressions) { // Allow system index access - they'll be filtered out below as there's no such thing (yet) as system data streams - Context context = new Context(state, options, false, false, true, true, true); + Context context = new Context(state, options, false, false, true, true, SystemIndexAccessLevel.ALL); if (indexExpressions == null || indexExpressions.length == 0) { indexExpressions = new String[]{"*"}; } @@ -160,7 +164,7 @@ public Index[] concreteIndices(ClusterState state, IndicesOptions options, Strin public Index[] concreteIndices(ClusterState state, IndicesOptions options, boolean includeDataStreams, String... indexExpressions) { Context context = new Context(state, options, false, false, includeDataStreams, - isSystemIndexAccessAllowed()); + getSystemIndexAccessLevel()); return concreteIndices(context, indexExpressions); } @@ -178,7 +182,7 @@ public Index[] concreteIndices(ClusterState state, IndicesOptions options, boole */ public Index[] concreteIndices(ClusterState state, IndicesRequest request, long startTime) { Context context = new Context(state, request.indicesOptions(), startTime, false, false, request.includeDataStreams(), false, - isSystemIndexAccessAllowed()); + getSystemIndexAccessLevel()); return concreteIndices(context, request.indices()); } @@ -301,14 +305,21 @@ Index[] concreteIndices(Context context, String... indexExpressions) { throw infe; } checkSystemIndexAccess(context, metadata, concreteIndices, indexExpressions); - return concreteIndices.toArray(new Index[concreteIndices.size()]); + return concreteIndices.toArray(Index.EMPTY_ARRAY); } private void checkSystemIndexAccess(Context context, Metadata metadata, Set concreteIndices, String[] originalPatterns) { - if (context.isSystemIndexAccessAllowed() == false) { + final SystemIndexAccessLevel systemIndexAccessLevel = context.getSystemIndexAccessLevel(); + if (systemIndexAccessLevel != SystemIndexAccessLevel.ALL) { + final Predicate systemIndexAccessLevelPredicate = systemIndexAccessLevel == SystemIndexAccessLevel.NONE ? + indexMetadata -> true : + systemIndices + .getProductSystemIndexMetadataPredicate(threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY)) + .negate(); final List resolvedSystemIndices = concreteIndices.stream() .map(metadata::index) .filter(IndexMetadata::isSystem) + .filter(systemIndexAccessLevelPredicate) .map(i -> i.getIndex().getName()) .sorted() // reliable order for testing .collect(Collectors.toList()); @@ -404,7 +415,7 @@ public Index concreteWriteIndex(ClusterState state, IndicesOptions options, Stri options.allowAliasesToMultipleIndices(), options.forbidClosedIndices(), options.ignoreAliases(), options.ignoreThrottled()); - Context context = new Context(state, combinedOptions, false, true, includeDataStreams, isSystemIndexAccessAllowed()); + Context context = new Context(state, combinedOptions, false, true, includeDataStreams, getSystemIndexAccessLevel()); Index[] indices = concreteIndices(context, index); if (allowNoIndices && indices.length == 0) { return null; @@ -421,7 +432,7 @@ public Index concreteWriteIndex(ClusterState state, IndicesOptions options, Stri * If the data stream, index or alias contains date math then that is resolved too. */ public boolean hasIndexAbstraction(String indexAbstraction, ClusterState state) { - Context context = new Context(state, IndicesOptions.lenientExpandOpen(), false, false, true, isSystemIndexAccessAllowed()); + Context context = new Context(state, IndicesOptions.lenientExpandOpen(), false, false, true, getSystemIndexAccessLevel()); String resolvedAliasOrIndex = dateMathExpressionResolver.resolveExpression(indexAbstraction, context); return state.metadata().getIndicesLookup().containsKey(resolvedAliasOrIndex); } @@ -432,14 +443,14 @@ public boolean hasIndexAbstraction(String indexAbstraction, ClusterState state) public String resolveDateMathExpression(String dateExpression) { // The data math expression resolver doesn't rely on cluster state or indices options, because // it just resolves the date math to an actual date. - return dateMathExpressionResolver.resolveExpression(dateExpression, new Context(null, null, isSystemIndexAccessAllowed())); + return dateMathExpressionResolver.resolveExpression(dateExpression, new Context(null, null, getSystemIndexAccessLevel())); } /** * Resolve an array of expressions to the set of indices and aliases that these expressions match. */ public Set resolveExpressions(ClusterState state, String... expressions) { - Context context = new Context(state, IndicesOptions.lenientExpandOpen(), true, false, true, isSystemIndexAccessAllowed()); + Context context = new Context(state, IndicesOptions.lenientExpandOpen(), true, false, true, getSystemIndexAccessLevel()); List resolvedExpressions = Arrays.asList(expressions); for (ExpressionResolver expressionResolver : expressionResolvers) { resolvedExpressions = expressionResolver.resolve(context, resolvedExpressions); @@ -533,7 +544,7 @@ public String[] indexAliases(ClusterState state, String index, Predicate> resolveSearchRouting(ClusterState state, @Nullable String routing, String... expressions) { List resolvedExpressions = expressions != null ? Arrays.asList(expressions) : Collections.emptyList(); - Context context = new Context(state, IndicesOptions.lenientExpandOpen(), false, false, true, isSystemIndexAccessAllowed()); + Context context = new Context(state, IndicesOptions.lenientExpandOpen(), false, false, true, getSystemIndexAccessLevel()); for (ExpressionResolver expressionResolver : expressionResolvers) { resolvedExpressions = expressionResolver.resolve(context, resolvedExpressions); } @@ -685,12 +696,32 @@ boolean isPatternMatchingAllIndices(Metadata metadata, String[] indicesOrAliases } /** - * Determines whether or not system index access should be allowed in the current context. + * Determines what level of system index access should be allowed in the current context. * - * @return True if system index access should be allowed, false otherwise. + * @return {@link SystemIndexAccessLevel#ALL} if unrestricted system index access should be allowed, + * {@link SystemIndexAccessLevel#RESTRICTED} if a subset of system index access should be allowed, or + * {@link SystemIndexAccessLevel#NONE} if no system index access should be allowed. */ - public boolean isSystemIndexAccessAllowed() { - return Booleans.parseBoolean(threadContext.getHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY), true); + public SystemIndexAccessLevel getSystemIndexAccessLevel() { + final String headerValue = threadContext.getHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY); + final String productHeaderValue = threadContext.getHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY); + + final boolean allowed = Booleans.parseBoolean(headerValue, true); + if (allowed) { + if (productHeaderValue != null) { + return SystemIndexAccessLevel.RESTRICTED; + } else { + return SystemIndexAccessLevel.ALL; + } + } else { + return SystemIndexAccessLevel.NONE; + } + } + + public enum SystemIndexAccessLevel { + ALL, + NONE, + RESTRICTED } public static class Context { @@ -702,30 +733,30 @@ public static class Context { private final boolean resolveToWriteIndex; private final boolean includeDataStreams; private final boolean preserveDataStreams; - private final boolean isSystemIndexAccessAllowed; + private final SystemIndexAccessLevel systemIndexAccessLevel; - Context(ClusterState state, IndicesOptions options, boolean isSystemIndexAccessAllowed) { - this(state, options, System.currentTimeMillis(), isSystemIndexAccessAllowed); + Context(ClusterState state, IndicesOptions options, SystemIndexAccessLevel systemIndexAccessLevel) { + this(state, options, System.currentTimeMillis(), systemIndexAccessLevel); } Context(ClusterState state, IndicesOptions options, boolean preserveAliases, boolean resolveToWriteIndex, - boolean includeDataStreams, boolean isSystemIndexAccessAllowed) { + boolean includeDataStreams, SystemIndexAccessLevel systemIndexAccessLevel) { this(state, options, System.currentTimeMillis(), preserveAliases, resolveToWriteIndex, includeDataStreams, false, - isSystemIndexAccessAllowed); + systemIndexAccessLevel); } Context(ClusterState state, IndicesOptions options, boolean preserveAliases, boolean resolveToWriteIndex, - boolean includeDataStreams, boolean preserveDataStreams, boolean isSystemIndexAccessAllowed) { + boolean includeDataStreams, boolean preserveDataStreams, SystemIndexAccessLevel systemIndexAccessLevel) { this(state, options, System.currentTimeMillis(), preserveAliases, resolveToWriteIndex, includeDataStreams, preserveDataStreams, - isSystemIndexAccessAllowed); + systemIndexAccessLevel); } - Context(ClusterState state, IndicesOptions options, long startTime, boolean isSystemIndexAccessAllowed) { - this(state, options, startTime, false, false, false, false, isSystemIndexAccessAllowed); + Context(ClusterState state, IndicesOptions options, long startTime, SystemIndexAccessLevel systemIndexAccessLevel) { + this(state, options, startTime, false, false, false, false, systemIndexAccessLevel); } protected Context(ClusterState state, IndicesOptions options, long startTime, boolean preserveAliases, boolean resolveToWriteIndex, - boolean includeDataStreams, boolean preserveDataStreams, boolean isSystemIndexAccessAllowed) { + boolean includeDataStreams, boolean preserveDataStreams, SystemIndexAccessLevel systemIndexAccessLevel) { this.state = state; this.options = options; this.startTime = startTime; @@ -733,7 +764,7 @@ protected Context(ClusterState state, IndicesOptions options, long startTime, bo this.resolveToWriteIndex = resolveToWriteIndex; this.includeDataStreams = includeDataStreams; this.preserveDataStreams = preserveDataStreams; - this.isSystemIndexAccessAllowed = isSystemIndexAccessAllowed; + this.systemIndexAccessLevel = systemIndexAccessLevel; } public ClusterState getState() { @@ -774,10 +805,10 @@ public boolean isPreserveDataStreams() { } /** - * Used to determine if it is allowed to access system indices in this context (e.g. for this request). + * Used to determine system index access is allowed in this context (e.g. for this request). */ - public boolean isSystemIndexAccessAllowed() { - return isSystemIndexAccessAllowed; + public SystemIndexAccessLevel getSystemIndexAccessLevel() { + return systemIndexAccessLevel; } } diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java index 728d110a59899..fbac2afeb68a0 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndexDescriptor.java @@ -18,6 +18,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import java.util.List; import java.util.Locale; import java.util.Objects; @@ -67,6 +68,12 @@ public class SystemIndexDescriptor { /** The minimum cluster node version required for this descriptor, or null if there is no restriction */ private final Version minimumNodeVersion; + /** The {@link Type} of system index this descriptor represents */ + private final Type type; + + /** A list of allowed product origins that may access an external system index */ + private final List allowedElasticProductOrigins; + /** * Creates a descriptor for system indices matching the supplied pattern. These indices will not be managed * by Elasticsearch internally. @@ -74,7 +81,20 @@ public class SystemIndexDescriptor { * @param description The name of the plugin responsible for this system index. */ public SystemIndexDescriptor(String indexPattern, String description) { - this(indexPattern, null, description, null, null, null, 0, null, null, null); + this(indexPattern, null, description, null, null, null, 0, null, null, null, Type.EXTERNAL_UNMANAGED, List.of()); + } + + /** + * Creates a descriptor for system indices matching the supplied pattern. These indices will not be managed + * by Elasticsearch internally. + * @param indexPattern The pattern of index names that this descriptor will be used for. Must start with a '.' character. + * @param description The name of the plugin responsible for this system index. + * @param type The {@link Type} of system index + * @param allowedElasticProductOrigins A list of allowed origin values that should be allowed access in the case of external system + * indices + */ + public SystemIndexDescriptor(String indexPattern, String description, Type type, List allowedElasticProductOrigins) { + this(indexPattern, null, description, null, null, null, 0, null, null, null, type, allowedElasticProductOrigins); } /** @@ -91,6 +111,9 @@ public SystemIndexDescriptor(String indexPattern, String description) { * Elasticsearch version when the index was created. * @param origin the client origin to use when creating this index. * @param minimumNodeVersion the minimum cluster node version required for this descriptor, or null if there is no restriction + * @param type The {@link Type} of system index + * @param allowedElasticProductOrigins A list of allowed origin values that should be allowed access in the case of external system + * indices */ SystemIndexDescriptor( String indexPattern, @@ -102,7 +125,9 @@ public SystemIndexDescriptor(String indexPattern, String description) { int indexFormat, String versionMetaKey, String origin, - Version minimumNodeVersion + Version minimumNodeVersion, + Type type, + List allowedElasticProductOrigins ) { Objects.requireNonNull(indexPattern, "system index pattern must not be null"); if (indexPattern.length() < 2) { @@ -147,6 +172,11 @@ public SystemIndexDescriptor(String indexPattern, String description) { Strings.requireNonEmpty(versionMetaKey, "Must supply versionMetaKey if mappings or settings are defined"); Strings.requireNonEmpty(origin, "Must supply origin if mappings or settings are defined"); } + Objects.requireNonNull(type, "type must not be null"); + Objects.requireNonNull(allowedElasticProductOrigins, "allowedProductOrigins must not be null"); + if (type.isInternal() && allowedElasticProductOrigins.isEmpty() == false) { + throw new IllegalArgumentException("Allowed origins are not valid for internal system indices"); + } this.indexPattern = indexPattern; this.primaryIndex = primaryIndex; @@ -162,6 +192,8 @@ public SystemIndexDescriptor(String indexPattern, String description) { this.versionMetaKey = versionMetaKey; this.origin = origin; this.minimumNodeVersion = minimumNodeVersion; + this.type = type; + this.allowedElasticProductOrigins = allowedElasticProductOrigins; } /** @@ -221,13 +253,26 @@ public String getVersionMetaKey() { } public boolean isAutomaticallyManaged() { - return this.mappings != null || this.settings != null; + // TODO remove mappings/settings check after all internal indices have been migrated + return type.isManaged() && (this.mappings != null || this.settings != null); } public String getOrigin() { return this.origin; } + public boolean isExternal() { + return type.isExternal(); + } + + public boolean isInternal() { + return type.isInternal(); + } + + public List getAllowedElasticProductOrigins() { + return allowedElasticProductOrigins; + } + /** * Checks that this descriptor can be used within this cluster, by comparing the supplied minimum * node version to this descriptor's minimum version. @@ -251,13 +296,47 @@ public String checkMinimumNodeVersion(String cause, Version actualMinimumNodeVer return null; } - // TODO: getThreadpool() - // TODO: Upgrade handling (reindex script?) - public static Builder builder() { return new Builder(); } + /** + * The specific type of system index that this descriptor represents. System indices have three defined types, which is used to + * control behavior. Elasticsearch itself has system indices that are necessary for features of Elasticsearch; these system indices + * are referred to as internal system indices. Internal system indices are always managed indices that Elasticsearch itself manages. + * + * System indices can also belong to features outside of Elasticsearch that may be part of other Elastic stack components. These are + * external system indices as the intent is for these to be accessed via normal APIs with a special value. Within external system + * indices, there are two sub-types. The first are those that are managed by Elasticsearch and will have mappings/settings changed as + * the cluster itself is upgraded. The second are those managed by the external application and for those Elasticsearch will not + * perform any updates. + */ + public enum Type { + INTERNAL(false, true), + EXTERNAL_MANAGED(true, true), + EXTERNAL_UNMANAGED(true, false); + + private final boolean external; + private final boolean managed; + + Type(boolean external, boolean managed) { + this.external = external; + this.managed = managed; + } + + public boolean isExternal() { + return external; + } + + public boolean isManaged() { + return managed; + } + + public boolean isInternal() { + return external == false; + } + } + /** * Provides a fluent API for building a {@link SystemIndexDescriptor}. Validation still happens in that class. */ @@ -272,6 +351,8 @@ public static class Builder { private String versionMetaKey = null; private String origin = null; private Version minimumNodeVersion = null; + private Type type = Type.INTERNAL; + private List allowedStackComponents = List.of(); private Builder() {} @@ -330,6 +411,16 @@ public Builder setMinimumNodeVersion(Version version) { return this; } + public Builder setType(Type type) { + this.type = type; + return this; + } + + public Builder setAllowedStackComponents(List allowedStackComponents) { + this.allowedStackComponents = allowedStackComponents; + return this; + } + /** * Builds a {@link SystemIndexDescriptor} using the fields supplied to this builder. * @return a populated descriptor. @@ -346,7 +437,9 @@ public SystemIndexDescriptor build() { indexFormat, versionMetaKey, origin, - minimumNodeVersion + minimumNodeVersion, + type, + allowedStackComponents ); } } diff --git a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java index cd97756b16429..3c68a0a217e2e 100644 --- a/server/src/main/java/org/elasticsearch/indices/SystemIndices.java +++ b/server/src/main/java/org/elasticsearch/indices/SystemIndices.java @@ -13,6 +13,7 @@ import org.apache.lucene.util.automaton.CharacterRunAutomaton; import org.apache.lucene.util.automaton.MinimizationOperations; import org.apache.lucene.util.automaton.Operations; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.index.Index; @@ -23,7 +24,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Collectors; import static java.util.stream.Collectors.toUnmodifiableList; @@ -41,6 +44,7 @@ public class SystemIndices { private final CharacterRunAutomaton runAutomaton; private final Collection systemIndexDescriptors; + private final Map productToSystemIndicesMatcher; public SystemIndices(Map> pluginAndModulesDescriptors) { final Map> descriptorsMap = buildSystemIndexDescriptorMap(pluginAndModulesDescriptors); @@ -48,6 +52,7 @@ public SystemIndices(Map> pluginAndMod this.systemIndexDescriptors = descriptorsMap.values().stream().flatMap(Collection::stream).collect(Collectors.toUnmodifiableList()); checkForDuplicateAliases(this.systemIndexDescriptors); this.runAutomaton = buildCharacterRunAutomaton(systemIndexDescriptors); + this.productToSystemIndicesMatcher = getProductToSystemIndicesMap((systemIndexDescriptors)); } private void checkForDuplicateAliases(Collection descriptors) { @@ -72,6 +77,27 @@ private void checkForDuplicateAliases(Collection descript } } + private static Map getProductToSystemIndicesMap(Collection descriptors) { + Map map = new HashMap<>(); + descriptors.stream().filter(SystemIndexDescriptor::isExternal) + .forEach(descriptor -> + descriptor.getAllowedElasticProductOrigins().forEach(product -> + map.compute(product, (key, automaton) -> { + Automaton built = SystemIndexDescriptor.buildAutomaton(descriptor.getIndexPattern(), descriptor.getAliasName()); + if (automaton != null) { + return Operations.union(automaton, built); + } else { + return built; + } + }) + ) + ); + + return map.entrySet().stream() + .collect(Collectors.toUnmodifiableMap(Entry::getKey, entry -> + new CharacterRunAutomaton(MinimizationOperations.minimize(entry.getValue(), Integer.MAX_VALUE)))); + } + /** * Determines whether a given index is a system index by comparing its name to the collection of loaded {@link SystemIndexDescriptor}s * @param index the {@link Index} object to check against loaded {@link SystemIndexDescriptor}s @@ -120,6 +146,32 @@ public boolean isSystemIndex(String indexName) { } } + /** + * Builds a predicate that tests if a system index should be accessible based on the provided product name + * @param product the name of the product that is attempting to access an external system index + * @return Predicate to check external system index metadata with + */ + public Predicate getProductSystemIndexMetadataPredicate(String product) { + final CharacterRunAutomaton automaton = productToSystemIndicesMatcher.get(product); + if (automaton == null) { + return indexMetadata -> false; + } + return indexMetadata -> automaton.run(indexMetadata.getIndex().getName()); + } + + /** + * Builds a predicate that tests if a system index name should be accessible based on the provided product name + * @param product the name of the product that is attempting to access an external system index + * @return Predicate to check external system index names with + */ + public Predicate getProductSystemIndexNamePredicate(String product) { + final CharacterRunAutomaton automaton = productToSystemIndicesMatcher.get(product); + if (automaton == null) { + return name -> false; + } + return automaton::run; + } + private static CharacterRunAutomaton buildCharacterRunAutomaton(Collection descriptors) { Optional automaton = descriptors.stream() .map(descriptor -> SystemIndexDescriptor.buildAutomaton(descriptor.getIndexPattern(), descriptor.getAliasName())) diff --git a/server/src/main/java/org/elasticsearch/node/Node.java b/server/src/main/java/org/elasticsearch/node/Node.java index f0ecdf761a8d6..94baf91042fa5 100644 --- a/server/src/main/java/org/elasticsearch/node/Node.java +++ b/server/src/main/java/org/elasticsearch/node/Node.java @@ -404,6 +404,14 @@ protected Node(final Environment initialEnvironment, final ClusterInfoService clusterInfoService = newClusterInfoService(settings, clusterService, threadPool, client); final UsageService usageService = new UsageService(); + final Map> systemIndexDescriptorMap = pluginsService + .filterPlugins(SystemIndexPlugin.class) + .stream() + .collect(Collectors.toUnmodifiableMap( + plugin -> plugin.getClass().getSimpleName(), + plugin -> plugin.getSystemIndexDescriptors(settings))); + final SystemIndices systemIndices = new SystemIndices(systemIndexDescriptorMap); + ModulesBuilder modules = new ModulesBuilder(); final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool); final FsHealthService fsHealthService = new FsHealthService(settings, clusterService.getClusterSettings(), threadPool, @@ -412,7 +420,7 @@ protected Node(final Environment initialEnvironment, final InternalSnapshotsInfoService snapshotsInfoService = new InternalSnapshotsInfoService(settings, clusterService, repositoriesServiceReference::get, rerouteServiceReference::get); final ClusterModule clusterModule = new ClusterModule(settings, clusterService, clusterPlugins, clusterInfoService, - snapshotsInfoService, threadPool.getThreadContext()); + snapshotsInfoService, threadPool.getThreadContext(), systemIndices); modules.add(clusterModule); IndicesModule indicesModule = new IndicesModule(pluginsService.filterPlugins(MapperPlugin.class)); modules.add(indicesModule); @@ -496,14 +504,6 @@ protected Node(final Environment initialEnvironment, .flatMap(m -> m.entrySet().stream()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - final Map> systemIndexDescriptorMap = pluginsService - .filterPlugins(SystemIndexPlugin.class) - .stream() - .collect(Collectors.toUnmodifiableMap( - plugin -> plugin.getClass().getSimpleName(), - plugin -> plugin.getSystemIndexDescriptors(settings))); - final SystemIndices systemIndices = new SystemIndices(systemIndexDescriptorMap); - final SystemIndexManager systemIndexManager = new SystemIndexManager(systemIndices, client); clusterService.addListener(systemIndexManager); diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java index fa2d533d99f06..23db9204f0acd 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestController.java +++ b/server/src/main/java/org/elasticsearch/rest/RestController.java @@ -43,6 +43,7 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; +import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY; import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY; import static org.elasticsearch.rest.BytesRestResponse.TEXT_CONTENT_TYPE; import static org.elasticsearch.rest.RestStatus.BAD_REQUEST; @@ -245,11 +246,19 @@ private void dispatchRequest(RestRequest request, RestChannel channel, RestHandl if (handler.allowsUnsafeBuffers() == false) { request.ensureSafeBuffers(); } - if (handler.allowSystemIndexAccessByDefault() == false && request.header(ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER) == null) { - // The ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER indicates that the request is coming from an Elastic product with a plan - // to move away from direct access to system indices, and thus deprecation warnings should not be emitted. + if (handler.allowSystemIndexAccessByDefault() == false) { + // The ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER indicates that the request is coming from an Elastic product and + // therefore we should allow a subset of external system index access. // This header is intended for internal use only. - client.threadPool().getThreadContext().putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, Boolean.FALSE.toString()); + final String prodOriginValue = request.header(ELASTIC_PRODUCT_ORIGIN_HTTP_HEADER); + if (prodOriginValue != null) { + client.threadPool().getThreadContext().putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, Boolean.TRUE.toString()); + client.threadPool().getThreadContext().putHeader(EXTERNAL_SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, prodOriginValue); + } else { + client.threadPool().getThreadContext().putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, Boolean.FALSE.toString()); + } + } else { + client.threadPool().getThreadContext().putHeader(SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY, Boolean.TRUE.toString()); } handler.handleRequest(request, responseChannel, client); diff --git a/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java b/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java index 6fb5fa50b1488..f21d1bb8fa9ed 100644 --- a/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java +++ b/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java @@ -21,6 +21,7 @@ import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.ActionPlugin.ActionHandler; import org.elasticsearch.rest.RestChannel; @@ -38,6 +39,7 @@ import java.io.IOException; import java.util.List; +import java.util.Map; import java.util.function.Supplier; import static java.util.Collections.emptyList; @@ -98,8 +100,8 @@ public void testSetupRestHandlerContainsKnownBuiltin() { SettingsModule settings = new SettingsModule(Settings.EMPTY); UsageService usageService = new UsageService(); ActionModule actionModule = new ActionModule(settings.getSettings(), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), settings.getIndexScopedSettings(), - settings.getClusterSettings(), settings.getSettingsFilter(), null, emptyList(), null, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), + settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), null, emptyList(), null, null, usageService, null); actionModule.initRestHandlers(null); // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail @@ -138,9 +140,9 @@ public String getName() { try { UsageService usageService = new UsageService(); ActionModule actionModule = new ActionModule(settings.getSettings(), - new IndexNameExpressionResolver(threadPool.getThreadContext()), settings.getIndexScopedSettings(), - settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(dupsMainAction), - null, null, usageService, null); + new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of())), + settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, + singletonList(dupsMainAction), null, null, usageService, null); Exception e = expectThrows(IllegalArgumentException.class, () -> actionModule.initRestHandlers(null)); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET")); } finally { @@ -173,9 +175,9 @@ public List getRestHandlers(Settings settings, RestController restC try { UsageService usageService = new UsageService(); ActionModule actionModule = new ActionModule(settings.getSettings(), - new IndexNameExpressionResolver(threadPool.getThreadContext()), settings.getIndexScopedSettings(), - settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, singletonList(registersFakeHandler), - null, null, usageService, null); + new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of())), + settings.getIndexScopedSettings(), settings.getClusterSettings(), settings.getSettingsFilter(), threadPool, + singletonList(registersFakeHandler), null, null, usageService, null); actionModule.initRestHandlers(null); // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail Exception e = expectThrows(IllegalArgumentException.class, () -> diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java index b7ffe7bbe3006..c63c7ea98708a 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java @@ -31,7 +31,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.transport.MockTransport; import org.elasticsearch.threadpool.TestThreadPool; @@ -44,6 +44,7 @@ import org.junit.BeforeClass; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -120,7 +121,8 @@ public void setupForTest() { clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); new TransportAddVotingConfigExclusionsAction(nodeSettings, clusterSettings, transportService, clusterService, threadPool, - new ActionFilters(emptySet()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); // registers action + new ActionFilters(emptySet()), + new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of()))); // registers action transportService.start(); transportService.acceptIncomingRequests(); diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java index 59dd43a4107ff..fb9d0ad67b711 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java @@ -25,7 +25,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.transport.MockTransport; import org.elasticsearch.threadpool.TestThreadPool; @@ -37,6 +37,7 @@ import org.junit.Before; import org.junit.BeforeClass; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @@ -84,7 +85,7 @@ public void setupForTest() { TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet()); new TransportClearVotingConfigExclusionsAction(transportService, clusterService, threadPool, new ActionFilters(emptySet()), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); // registers action + new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of()))); // registers action transportService.start(); transportService.acceptIncomingRequests(); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java index a9a316f29061f..d37e874ed2f61 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/alias/get/TransportGetAliasesActionTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.indices.SystemIndexDescriptor; @@ -31,8 +32,8 @@ public void testPostProcess() { .fPut("b", Collections.singletonList(new AliasMetadata.Builder("y").build())) .build(); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, new String[]{"a", "b", "c"}, aliases, ClusterState.EMPTY_STATE, false, - EMPTY_SYSTEM_INDICES); + TransportGetAliasesAction.postProcess(request, new String[]{"a", "b", "c"}, aliases, ClusterState.EMPTY_STATE, + SystemIndexAccessLevel.NONE, null, EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(3)); assertThat(result.get("a").size(), equalTo(0)); assertThat(result.get("b").size(), equalTo(1)); @@ -43,8 +44,8 @@ public void testPostProcess() { aliases = ImmutableOpenMap.>builder() .fPut("b", Collections.singletonList(new AliasMetadata.Builder("y").build())) .build(); - result = TransportGetAliasesAction.postProcess(request, new String[]{"a", "b", "c"}, aliases, ClusterState.EMPTY_STATE, false, - EMPTY_SYSTEM_INDICES); + result = TransportGetAliasesAction.postProcess(request, new String[]{"a", "b", "c"}, aliases, ClusterState.EMPTY_STATE, + SystemIndexAccessLevel.NONE, null, EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(3)); assertThat(result.get("a").size(), equalTo(0)); assertThat(result.get("b").size(), equalTo(1)); @@ -54,8 +55,8 @@ public void testPostProcess() { aliases = ImmutableOpenMap.>builder() .fPut("b", Collections.singletonList(new AliasMetadata.Builder("y").build())) .build(); - result = TransportGetAliasesAction.postProcess(request, new String[]{"a", "b", "c"}, aliases, ClusterState.EMPTY_STATE, false, - EMPTY_SYSTEM_INDICES); + result = TransportGetAliasesAction.postProcess(request, new String[]{"a", "b", "c"}, aliases, ClusterState.EMPTY_STATE, + SystemIndexAccessLevel.NONE, null, EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(1)); assertThat(result.get("b").size(), equalTo(1)); } @@ -71,7 +72,8 @@ public void testDeprecationWarningEmittedForTotalWildcard() { final String[] concreteIndices = {"a", ".b", "c"}; assertEquals(state.metadata().findAliases(request, concreteIndices), aliases); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, false, EMPTY_SYSTEM_INDICES); + TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, + SystemIndexAccessLevel.NONE, null, EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(3)); assertThat(result.get("a").size(), equalTo(0)); assertThat(result.get(".b").size(), equalTo(1)); @@ -91,7 +93,8 @@ public void testDeprecationWarningEmittedWhenSystemIndexIsRequested() { final String[] concreteIndices = {".b"}; assertEquals(state.metadata().findAliases(request, concreteIndices), aliases); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, false, EMPTY_SYSTEM_INDICES); + TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, + SystemIndexAccessLevel.NONE, null, EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(1)); assertThat(result.get(".b").size(), equalTo(1)); assertWarnings("this request accesses system indices: [.b], but in a future major version, direct access to system " + @@ -108,7 +111,8 @@ public void testDeprecationWarningEmittedWhenSystemIndexIsRequestedByAlias() { final String[] concreteIndices = {"a", ".b", "c"}; assertEquals(state.metadata().findAliases(request, concreteIndices), aliases); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, false, EMPTY_SYSTEM_INDICES); + TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, + SystemIndexAccessLevel.NONE, null, EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(1)); assertThat(result.get(".b").size(), equalTo(1)); assertWarnings("this request accesses system indices: [.b], but in a future major version, direct access to system " + @@ -125,7 +129,8 @@ public void testDeprecationWarningNotEmittedWhenSystemAccessAllowed() { final String[] concreteIndices = {"a", ".b", "c"}; assertEquals(state.metadata().findAliases(request, concreteIndices), aliases); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, true, EMPTY_SYSTEM_INDICES); + TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, + SystemIndexAccessLevel.ALL, "", EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(1)); assertThat(result.get(".b").size(), equalTo(1)); } @@ -144,7 +149,8 @@ public void testDeprecationWarningNotEmittedWhenOnlyNonsystemIndexRequested() { final String[] concreteIndices = {"c"}; assertEquals(state.metadata().findAliases(request, concreteIndices), aliases); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, false, EMPTY_SYSTEM_INDICES); + TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, + SystemIndexAccessLevel.NONE, "", EMPTY_SYSTEM_INDICES); assertThat(result.size(), equalTo(1)); assertThat(result.get("c").size(), equalTo(1)); } @@ -160,7 +166,8 @@ public void testDeprecationWarningEmittedWhenRequestingNonExistingAliasInSystemP final String[] concreteIndices = {}; assertEquals(state.metadata().findAliases(request, concreteIndices), aliases); ImmutableOpenMap> result = - TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, false, systemIndices); + TransportGetAliasesAction.postProcess(request, concreteIndices, aliases, state, + SystemIndexAccessLevel.NONE, null, systemIndices); assertThat(result.size(), equalTo(0)); assertWarnings("this request accesses aliases with names reserved for system indices: [.y], but in a future major version, direct" + "access to system indices and their aliases will not be allowed"); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java index 4376e2a0e1ffe..387711e73ecfc 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexActionTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.test.transport.CapturingTransport; import org.elasticsearch.threadpool.TestThreadPool; @@ -31,6 +32,7 @@ import org.junit.After; import org.junit.Before; +import java.util.Map; import java.util.concurrent.TimeUnit; import static java.util.Collections.emptyList; @@ -113,7 +115,7 @@ protected void doMasterOperation(GetIndexRequest request, String[] concreteIndic static class Resolver extends IndexNameExpressionResolver { Resolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java index 4ab89ad739234..8fbca6f2558c9 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/put/PutMappingRequestTests.java @@ -21,10 +21,12 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.Index; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static org.elasticsearch.common.collect.Tuple.tuple; @@ -81,7 +83,7 @@ public void testResolveIndicesWithWriteIndexOnlyAndDataStreamsAndWriteAliases() )); PutMappingRequest request = new PutMappingRequest().indices("foo", "alias1", "alias2").writeIndexOnly(true); Index[] indices = TransportPutMappingAction.resolveIndices(cs, request, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); List indexNames = Arrays.stream(indices).map(Index::getName).collect(Collectors.toList()); IndexAbstraction expectedDs = cs.metadata().getIndicesLookup().get("foo"); // should resolve the data stream and each alias to their respective write indices @@ -102,7 +104,7 @@ public void testResolveIndicesWithoutWriteIndexOnlyAndDataStreamsAndWriteAliases )); PutMappingRequest request = new PutMappingRequest().indices("foo", "alias1", "alias2"); Index[] indices = TransportPutMappingAction.resolveIndices(cs, request, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); List indexNames = Arrays.stream(indices).map(Index::getName).collect(Collectors.toList()); IndexAbstraction expectedDs = cs.metadata().getIndicesLookup().get("foo"); List expectedIndices = expectedDs.getIndices().stream().map(im -> im.getIndex().getName()).collect(Collectors.toList()); @@ -125,7 +127,7 @@ public void testResolveIndicesWithWriteIndexOnlyAndDataStreamAndIndex() { )); PutMappingRequest request = new PutMappingRequest().indices("foo", "index3").writeIndexOnly(true); Index[] indices = TransportPutMappingAction.resolveIndices(cs, request, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); List indexNames = Arrays.stream(indices).map(Index::getName).collect(Collectors.toList()); IndexAbstraction expectedDs = cs.metadata().getIndicesLookup().get("foo"); List expectedIndices = expectedDs.getIndices().stream().map(im -> im.getIndex().getName()).collect(Collectors.toList()); @@ -149,7 +151,7 @@ public void testResolveIndicesWithWriteIndexOnlyAndNoSingleWriteIndex() { PutMappingRequest request = new PutMappingRequest().indices("*").writeIndexOnly(true); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> TransportPutMappingAction.resolveIndices(cs2, request, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())))); assertThat(e.getMessage(), containsString("The index expression [*] and options provided did not point to a single write-index")); } @@ -168,7 +170,7 @@ public void testResolveIndicesWithWriteIndexOnlyAndAliasWithoutWriteIndex() { PutMappingRequest request = new PutMappingRequest().indices("alias2").writeIndexOnly(true); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> TransportPutMappingAction.resolveIndices(cs2, request, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())))); assertThat(e.getMessage(), containsString("no write index is defined for alias [alias2]")); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexTests.java index 8ce010ac1c494..802cf63aded78 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.junit.Before; @@ -66,8 +67,8 @@ public class ResolveIndexTests extends ESTestCase { }; private Metadata metadata; - private IndexAbstractionResolver resolver = new IndexAbstractionResolver( - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + private final IndexAbstractionResolver resolver = new IndexAbstractionResolver( + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); private long epochMillis; private String dateString; diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceTests.java index 7fc8ffe37ec63..622e45a68df35 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverServiceTests.java @@ -284,7 +284,8 @@ public void testDataStreamValidation() throws IOException { public void testGenerateRolloverIndexName() { String invalidIndexName = randomAlphaOfLength(10) + "A"; - IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver indexNameExpressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); expectThrows(IllegalArgumentException.class, () -> MetadataRolloverService.generateRolloverIndexName(invalidIndexName, indexNameExpressionResolver)); int num = randomIntBetween(0, 100); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java index 7e5fbf0450eb8..5f5039976773b 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/settings/get/GetSettingsActionTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.tasks.Task; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.transport.CapturingTransport; @@ -32,6 +33,7 @@ import org.junit.Before; import java.util.Collections; +import java.util.Map; import java.util.concurrent.TimeUnit; import static java.util.Collections.emptyList; @@ -123,7 +125,7 @@ public void testIncludeDefaultsWithFiltering() { static class Resolver extends IndexNameExpressionResolver { Resolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java index a322a80bd582f..32b96fadb4abd 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java @@ -108,11 +108,12 @@ private void indicesThatCannotBeCreatedTestCase(Set expected, final ExecutorService direct = EsExecutors.newDirectExecutorService(); when(threadPool.executor(anyString())).thenReturn(direct); - final IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) { - @Override - public boolean hasIndexAbstraction(String indexAbstraction, ClusterState state) { - return shouldAutoCreate.apply(indexAbstraction) == false; - } + final IndexNameExpressionResolver indexNameExpressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())) { + @Override + public boolean hasIndexAbstraction(String indexAbstraction, ClusterState state) { + return shouldAutoCreate.apply(indexAbstraction) == false; + } }; TransportBulkAction action = new TransportBulkAction(threadPool, mock(TransportService.class), clusterService, diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java index 4c91a1a7c85b2..4593da9498987 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionIngestTests.java @@ -131,7 +131,8 @@ class TestTransportBulkAction extends TransportBulkAction { TestTransportBulkAction() { super(threadPool, transportService, clusterService, ingestService, - null, new ActionFilters(Collections.emptySet()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + null, new ActionFilters(Collections.emptySet()), + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), new IndexingPressure(SETTINGS), new SystemIndices(Map.of()) ); } diff --git a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java index ab929c79ff346..016c4e1119251 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/TransportBulkActionTookTests.java @@ -197,7 +197,7 @@ public void onFailure(Exception e) { static class Resolver extends IndexNameExpressionResolver { Resolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/get/TransportMultiGetActionTests.java b/server/src/test/java/org/elasticsearch/action/get/TransportMultiGetActionTests.java index 1d675d694bc04..febecd8606006 100644 --- a/server/src/test/java/org/elasticsearch/action/get/TransportMultiGetActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/get/TransportMultiGetActionTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskManager; @@ -214,7 +215,7 @@ private static Task createTask() { static class Resolver extends IndexNameExpressionResolver { Resolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/search/MultiSearchActionTookTests.java b/server/src/test/java/org/elasticsearch/action/search/MultiSearchActionTookTests.java index 7d1a6f584c6d6..85205686b8db7 100644 --- a/server/src/test/java/org/elasticsearch/action/search/MultiSearchActionTookTests.java +++ b/server/src/test/java/org/elasticsearch/action/search/MultiSearchActionTookTests.java @@ -9,19 +9,16 @@ package org.elasticsearch.action.search; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.AtomicArray; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskManager; @@ -179,15 +176,4 @@ void executeSearch(final Queue requests, final AtomicArray getResults() { class MyResolver extends IndexNameExpressionResolver { MyResolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java b/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java index 014c4158960bc..39ba50468cf3d 100644 --- a/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/master/TransportMasterNodeActionTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.discovery.MasterNotDiscoveredException; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.node.NodeClosedException; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.tasks.Task; @@ -53,6 +54,7 @@ import java.io.IOException; import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -163,8 +165,9 @@ class Action extends TransportMasterNodeAction { Action(String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool) { super(actionName, transportService, clusterService, threadPool, - new ActionFilters(new HashSet<>()), Request::new, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - Response::new, ThreadPool.Names.SAME); + new ActionFilters(new HashSet<>()), Request::new, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), Response::new, + ThreadPool.Names.SAME); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java index 90bfc74247dc2..15494c62a0a4c 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/BroadcastReplicationTests.java @@ -31,9 +31,9 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.rest.RestStatus; @@ -53,6 +53,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -93,7 +94,8 @@ threadPool, new NetworkService(Collections.emptyList()), PageCacheRecycler.NON_R transportService.start(); transportService.acceptIncomingRequests(); broadcastReplicationAction = new TestBroadcastReplicationAction(clusterService, transportService, - new ActionFilters(new HashSet<>()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new ActionFilters(new HashSet<>()), + new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of()))); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java b/server/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java index fd8f62428a71b..cb0c6d7ec486f 100644 --- a/server/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/single/instance/TransportInstanceSingleOperationActionTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.transport.CapturingTransport; @@ -126,9 +127,9 @@ protected ShardIterator shards(ClusterState clusterState, Request request) { } } - class MyResolver extends IndexNameExpressionResolver { + static class MyResolver extends IndexNameExpressionResolver { MyResolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java b/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java index 5121bb2826a71..0cef9aab2ff87 100644 --- a/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/termvectors/TransportMultiTermVectorsActionTests.java @@ -35,6 +35,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskManager; @@ -215,7 +216,7 @@ private static Task createTask() { static class Resolver extends IndexNameExpressionResolver { Resolver() { - super(new ThreadContext(Settings.EMPTY)); + super(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); } @Override diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java index a4b7933d40b19..85f1ee9deb32d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java @@ -40,6 +40,7 @@ import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.gateway.GatewayAllocator; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.plugins.ClusterPlugin; import org.elasticsearch.test.gateway.TestGatewayAllocator; @@ -55,6 +56,7 @@ public class ClusterModuleTests extends ModuleTestCase { private ClusterInfoService clusterInfoService = EmptyClusterInfoService.INSTANCE; private ClusterService clusterService; private ThreadContext threadContext; + private SystemIndices systemIndices; @Override public void setUp() throws Exception { @@ -62,6 +64,7 @@ public void setUp() throws Exception { threadContext = new ThreadContext(Settings.EMPTY); clusterService = new ClusterService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null); + systemIndices = new SystemIndices(Map.of()); } @Override @@ -124,7 +127,7 @@ public void testRegisterAllocationDeciderDuplicate() { public Collection createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) { return Collections.singletonList(new EnableAllocationDecider(settings, clusterSettings)); } - }), clusterInfoService, null, threadContext)); + }), clusterInfoService, null, threadContext, systemIndices)); assertEquals(e.getMessage(), "Cannot specify allocation decider [" + EnableAllocationDecider.class.getName() + "] twice"); } @@ -136,7 +139,7 @@ public void testRegisterAllocationDecider() { public Collection createAllocationDeciders(Settings settings, ClusterSettings clusterSettings) { return Collections.singletonList(new FakeAllocationDecider()); } - }), clusterInfoService, null, threadContext); + }), clusterInfoService, null, threadContext, systemIndices); assertTrue(module.deciderList.stream().anyMatch(d -> d.getClass().equals(FakeAllocationDecider.class))); } @@ -148,7 +151,7 @@ public Map> getShardsAllocators(Settings setti return Collections.singletonMap(name, supplier); } } - ), clusterInfoService, null, threadContext); + ), clusterInfoService, null, threadContext, systemIndices); } public void testRegisterShardsAllocator() { @@ -166,7 +169,7 @@ public void testRegisterShardsAllocatorAlreadyRegistered() { public void testUnknownShardsAllocator() { Settings settings = Settings.builder().put(ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING.getKey(), "dne").build(); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> - new ClusterModule(settings, clusterService, Collections.emptyList(), clusterInfoService, null, threadContext)); + new ClusterModule(settings, clusterService, Collections.emptyList(), clusterInfoService, null, threadContext, systemIndices)); assertEquals("Unknown ShardsAllocator [dne]", e.getMessage()); } @@ -209,14 +212,15 @@ public void testAllocationDeciderOrder() { public void testRejectsReservedExistingShardsAllocatorName() { final ClusterModule clusterModule = new ClusterModule(Settings.EMPTY, clusterService, - List.of(existingShardsAllocatorPlugin(GatewayAllocator.ALLOCATOR_NAME)), clusterInfoService, null, threadContext); + List.of(existingShardsAllocatorPlugin(GatewayAllocator.ALLOCATOR_NAME)), clusterInfoService, null, threadContext, + systemIndices); expectThrows(IllegalArgumentException.class, () -> clusterModule.setExistingShardsAllocators(new TestGatewayAllocator())); } public void testRejectsDuplicateExistingShardsAllocatorName() { final ClusterModule clusterModule = new ClusterModule(Settings.EMPTY, clusterService, List.of(existingShardsAllocatorPlugin("duplicate"), existingShardsAllocatorPlugin("duplicate")), clusterInfoService, null, - threadContext); + threadContext, systemIndices); expectThrows(IllegalArgumentException.class, () -> clusterModule.setExistingShardsAllocators(new TestGatewayAllocator())); } diff --git a/server/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java b/server/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java index b5fb66eadb294..8164839b001d8 100644 --- a/server/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/health/ClusterStateHealthTests.java @@ -37,8 +37,8 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.gateway.TestGatewayAllocator; import org.elasticsearch.test.transport.CapturingTransport; @@ -55,6 +55,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -69,13 +70,11 @@ import static org.hamcrest.Matchers.lessThanOrEqualTo; public class ClusterStateHealthTests extends ESTestCase { - private final IndexNameExpressionResolver indexNameExpressionResolver = - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); - private static ThreadPool threadPool; private ClusterService clusterService; private TransportService transportService; + private IndexNameExpressionResolver indexNameExpressionResolver; @BeforeClass public static void setupThreadPool() { @@ -92,6 +91,7 @@ public void setUp() throws Exception { TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null, Collections.emptySet()); transportService.start(); transportService.acceptIncomingRequests(); + indexNameExpressionResolver = new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of())); } @After diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java index 2deb367e6476c..09045500a877d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DateMathExpressionResolverTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.Context; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.DateMathExpressionResolver; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel; import org.elasticsearch.test.ESTestCase; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -24,6 +25,7 @@ import java.util.Collections; import java.util.List; +import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel.NONE; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.joda.time.DateTimeZone.UTC; @@ -33,7 +35,7 @@ public class DateMathExpressionResolverTests extends ESTestCase { private final DateMathExpressionResolver expressionResolver = new DateMathExpressionResolver(); private final Context context = new Context( ClusterState.builder(new ClusterName("_name")).build(), IndicesOptions.strictExpand(), - false + SystemIndexAccessLevel.NONE ); public void testNormal() throws Exception { @@ -136,7 +138,7 @@ public void testExpression_CustomTimeZoneInIndexName() throws Exception { // rounding to today 00:00 now = DateTime.now(UTC).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); } - Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis(), false); + Context context = new Context(this.context.getState(), this.context.getOptions(), now.getMillis(), NONE); List results = expressionResolver.resolve(context, Arrays.asList("<.marvel-{now/d{yyyy.MM.dd|" + timeZone.getID() + "}}>")); assertThat(results.size(), equalTo(1)); logger.info("timezone: [{}], now [{}], name: [{}]", timeZone, now, results.get(0)); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverAliasIterationTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverAliasIterationTests.java index aee7b2979f07b..b056c0b731f4d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverAliasIterationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverAliasIterationTests.java @@ -8,13 +8,16 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; + +import java.util.Map; public class IndexNameExpressionResolverAliasIterationTests extends IndexNameExpressionResolverTests { - protected IndexNameExpressionResolver createIndexNameExpressionResolver() { - return new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) { + @Override + protected IndexNameExpressionResolver createIndexNameExpressionResolver(ThreadContext threadContext) { + return new IndexNameExpressionResolver(threadContext, new SystemIndices(Map.of())) { @Override boolean iterateIndexAliases(int indexAliasesSize, int resolvedExpressionsSize) { return true; diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverExpressionsIterationTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverExpressionsIterationTests.java index fdfc78e863c98..aa9a1d47c2dcc 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverExpressionsIterationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverExpressionsIterationTests.java @@ -8,13 +8,16 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; + +import java.util.Map; public class IndexNameExpressionResolverExpressionsIterationTests extends IndexNameExpressionResolverTests { - protected IndexNameExpressionResolver createIndexNameExpressionResolver() { - return new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) { + @Override + protected IndexNameExpressionResolver createIndexNameExpressionResolver(ThreadContext threadContext) { + return new IndexNameExpressionResolver(threadContext, new SystemIndices(Map.of())) { @Override boolean iterateIndexAliases(int indexAliasesSize, int resolvedExpressionsSize) { return false; 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 7e1802e79acb3..46ab827dad34e 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.indices.InvalidIndexNameException; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import java.util.Arrays; @@ -37,6 +38,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -45,6 +47,7 @@ import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField; import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_HIDDEN_SETTING; import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ACCESS_CONTROL_HEADER_KEY; +import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel.NONE; import static org.elasticsearch.common.util.set.Sets.newHashSet; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.arrayContainingInAnyOrder; @@ -68,7 +71,7 @@ private ThreadContext createThreadContext() { } protected IndexNameExpressionResolver createIndexNameExpressionResolver(ThreadContext threadContext) { - return new IndexNameExpressionResolver(threadContext); + return new IndexNameExpressionResolver(threadContext, new SystemIndices(Map.of())); } @Override @@ -90,7 +93,7 @@ public void testIndexOptionsStrict() { IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand()}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -140,26 +143,26 @@ public void testIndexOptionsStrict() { } IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(3, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); results = indexNameExpressionResolver.concreteIndexNames(context, (String[])null); assertEquals(4, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpand(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); @@ -175,7 +178,7 @@ public void testIndexOptionsLenient() { IndicesOptions[] indicesOptions = new IndicesOptions[]{IndicesOptions.lenientExpandOpen(), IndicesOptions.lenientExpand()}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -213,20 +216,20 @@ public void testIndexOptionsLenient() { } IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(Arrays.toString(results), 4, results.length); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo")); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpand(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foofoo*"); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foobar", "foofoo", "foofoo-closed")); @@ -245,7 +248,7 @@ public void testIndexOptionsAllowUnavailableDisallowEmpty() { IndicesOptions[] indicesOptions = new IndicesOptions[]{expandOpen, expand}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo"); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -267,11 +270,11 @@ public void testIndexOptionsAllowUnavailableDisallowEmpty() { } } - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, expandOpen, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); - context = new IndexNameExpressionResolver.Context(state, expand, false); + context = new IndexNameExpressionResolver.Context(state, expand, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); } @@ -289,7 +292,7 @@ public void testIndexOptionsWildcardExpansion() { // Only closed IndicesOptions options = IndicesOptions.fromOptions(false, true, false, true, false); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(1, results.length); assertEquals("foo", results[0]); @@ -314,7 +317,7 @@ public void testIndexOptionsWildcardExpansion() { // Only open options = IndicesOptions.fromOptions(false, true, true, false, false); - context = new IndexNameExpressionResolver.Context(state, options, false); + context = new IndexNameExpressionResolver.Context(state, options, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar")); @@ -338,7 +341,7 @@ public void testIndexOptionsWildcardExpansion() { // Open and closed options = IndicesOptions.fromOptions(false, true, true, true, false); - context = new IndexNameExpressionResolver.Context(state, options, false); + context = new IndexNameExpressionResolver.Context(state, options, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo")); @@ -377,7 +380,7 @@ public void testIndexOptionsWildcardExpansion() { // open closed and hidden options = IndicesOptions.fromOptions(false, true, true, true, true); - context = new IndexNameExpressionResolver.Context(state, options, false); + context = new IndexNameExpressionResolver.Context(state, options, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(7, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "foo", "hidden", "hidden-closed", ".hidden", ".hidden-closed")); @@ -419,7 +422,7 @@ public void testIndexOptionsWildcardExpansion() { // open and hidden options = IndicesOptions.fromOptions(false, true, true, false, true); - context = new IndexNameExpressionResolver.Context(state, options, false); + context = new IndexNameExpressionResolver.Context(state, options, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(4, results.length); assertThat(results, arrayContainingInAnyOrder("bar", "foobar", "hidden", ".hidden")); @@ -438,7 +441,7 @@ public void testIndexOptionsWildcardExpansion() { // closed and hidden options = IndicesOptions.fromOptions(false, true, false, true, true); - context = new IndexNameExpressionResolver.Context(state, options, false); + context = new IndexNameExpressionResolver.Context(state, options, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertEquals(3, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "hidden-closed", ".hidden-closed")); @@ -457,7 +460,7 @@ public void testIndexOptionsWildcardExpansion() { // only hidden options = IndicesOptions.fromOptions(false, true, false, false, true); - context = new IndexNameExpressionResolver.Context(state, options, false); + context = new IndexNameExpressionResolver.Context(state, options, NONE); results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); @@ -471,7 +474,7 @@ public void testIndexOptionsWildcardExpansion() { assertThat(results, arrayContainingInAnyOrder("hidden-closed")); options = IndicesOptions.fromOptions(false, false, true, true, true); - IndexNameExpressionResolver.Context context2 = new IndexNameExpressionResolver.Context(state, options, false); + IndexNameExpressionResolver.Context context2 = new IndexNameExpressionResolver.Context(state, options, NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context2, "-*")); assertThat(infe.getResourceId().toString(), equalTo("[-*]")); @@ -488,7 +491,7 @@ public void testIndexOptionsNoExpandWildcards() { //ignore unavailable and allow no indices { IndicesOptions noExpandLenient = IndicesOptions.fromOptions(true, true, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandLenient, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); @@ -510,7 +513,7 @@ public void testIndexOptionsNoExpandWildcards() { //ignore unavailable but don't allow no indices { IndicesOptions noExpandDisallowEmpty = IndicesOptions.fromOptions(true, false, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandDisallowEmpty, NONE); { IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, @@ -535,7 +538,7 @@ public void testIndexOptionsNoExpandWildcards() { //error on unavailable but allow no indices { IndicesOptions noExpandErrorUnavailable = IndicesOptions.fromOptions(false, true, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandErrorUnavailable, NONE); { String[] results = indexNameExpressionResolver.concreteIndexNames(context, "baz*"); assertThat(results, emptyArray()); @@ -561,7 +564,7 @@ public void testIndexOptionsNoExpandWildcards() { //error on both unavailable and no indices { IndicesOptions noExpandStrict = IndicesOptions.fromOptions(false, false, false, false, randomBoolean()); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, noExpandStrict, NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*")); assertThat(infe.getIndex().getName(), equalTo("baz*")); @@ -588,7 +591,7 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { { IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "baz*")); assertThat(infe.getIndex().getName(), equalTo("baz*")); @@ -596,7 +599,7 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { { IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*")); assertThat(infe.getIndex().getName(), equalTo("baz*")); @@ -604,7 +607,7 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { { IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foofoobar")); assertThat(e.getMessage(), containsString("alias [foofoobar] has more than one index associated with it")); @@ -612,7 +615,7 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { { IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foo", "foofoobar")); assertThat(e.getMessage(), containsString("alias [foofoobar] has more than one index associated with it")); @@ -620,7 +623,7 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { { IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); IndexClosedException ince = expectThrows(IndexClosedException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "foofoo-closed", "foofoobar")); assertThat(ince.getMessage(), equalTo("closed")); @@ -628,7 +631,7 @@ public void testIndexOptionsSingleIndexNoExpandWildcards() { } IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed(), NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "barbaz"); assertEquals(2, results.length); assertThat(results, arrayContainingInAnyOrder("foo", "foofoo")); @@ -638,7 +641,7 @@ public void testIndexOptionsEmptyCluster() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(Metadata.builder().build()).build(); IndicesOptions options = IndicesOptions.strictExpandOpen(); - final IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false); + final IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); @@ -659,7 +662,7 @@ public void testIndexOptionsEmptyCluster() { final IndexNameExpressionResolver.Context context2 = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context2, Strings.EMPTY_ARRAY); assertThat(results, emptyArray()); results = indexNameExpressionResolver.concreteIndexNames(context2, "foo"); @@ -670,7 +673,7 @@ public void testIndexOptionsEmptyCluster() { assertThat(results, emptyArray()); final IndexNameExpressionResolver.Context context3 = - new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, false, true, false), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context3, Strings.EMPTY_ARRAY)); assertThat(infe.getResourceId().toString(), equalTo("[_all]")); @@ -696,7 +699,7 @@ public void testConcreteIndicesIgnoreIndicesOneMissingIndex() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testZZZ")); @@ -709,7 +712,7 @@ public void testConcreteIndicesIgnoreIndicesOneMissingIndexOtherFound() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testXXX", "testZZZ")), equalTo(newHashSet("testXXX"))); @@ -721,7 +724,7 @@ public void testConcreteIndicesIgnoreIndicesAllMissing() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "testMo", "testMahdy")); @@ -734,7 +737,7 @@ public void testConcreteIndicesIgnoreIndicesEmptyRequest() { .put(indexBuilder("kuku")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, new String[]{})), equalTo(newHashSet("kuku", "testXXX"))); } @@ -742,7 +745,7 @@ public void testConcreteIndicesNoIndicesErrorMessage() { Metadata.Builder mdBuilder = Metadata.builder(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(false, false, true, true), false); + IndicesOptions.fromOptions(false, false, true, true), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[]{})); assertThat(infe.getMessage(), is("no such index [null] and no indices exist")); @@ -752,7 +755,7 @@ public void testConcreteIndicesNoIndicesErrorMessageNoExpand() { Metadata.Builder mdBuilder = Metadata.builder(); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(false, false, false, false), false); + IndicesOptions.fromOptions(false, false, false, false), NONE); IndexNotFoundException infe = expectThrows(IndexNotFoundException.class, () -> indexNameExpressionResolver.concreteIndices(context, new String[]{})); assertThat(infe.getMessage(), is("no such index [_all] and no indices exist")); @@ -768,16 +771,16 @@ public void testConcreteIndicesWildcardExpansion() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, false), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(new HashSet())); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXYY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, true), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); } @@ -795,7 +798,7 @@ public void testConcreteIndicesWildcardWithNegation() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(true, true, true, true), false); + IndicesOptions.fromOptions(true, true, true, true), NONE); assertThat(newHashSet(indexNameExpressionResolver.concreteIndexNames(context, "testX*")), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); @@ -1083,7 +1086,7 @@ public void testConcreteIndicesAllPatternRandom() { { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(Metadata.builder().build()).build(); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, NONE); // with no indices, asking for all indices should return empty list or exception, depending on indices options if (indicesOptions.allowNoIndices()) { @@ -1102,7 +1105,7 @@ public void testConcreteIndicesAllPatternRandom() { .put(indexBuilder("bbb").state(State.OPEN).putAlias(AliasMetadata.builder("bbb_alias1"))) .put(indexBuilder("ccc").state(State.CLOSE).putAlias(AliasMetadata.builder("ccc_alias1"))); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, NONE); if (indicesOptions.expandWildcardsOpen() || indicesOptions.expandWildcardsClosed() || indicesOptions.allowNoIndices()) { String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(context, allIndices); assertThat(concreteIndices, notNullValue()); @@ -1132,7 +1135,7 @@ public void testConcreteIndicesWildcardNoMatch() { .put(indexBuilder("bbb").state(State.OPEN).putAlias(AliasMetadata.builder("bbb_alias1"))) .put(indexBuilder("ccc").state(State.CLOSE).putAlias(AliasMetadata.builder("ccc_alias1"))); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, indicesOptions, NONE); // asking for non existing wildcard pattern should return empty list or exception if (indicesOptions.allowNoIndices()) { @@ -1261,20 +1264,20 @@ public void testIndexOptionsFailClosedIndicesAndAliases() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context contextICE = - new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), NONE); expectThrows(IndexClosedException.class, () -> indexNameExpressionResolver.concreteIndexNames(contextICE, "foo1-closed")); expectThrows(IndexClosedException.class, () -> indexNameExpressionResolver.concreteIndexNames(contextICE, "foobar1-closed")); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, contextICE.getOptions().allowNoIndices(), contextICE.getOptions().expandWildcardsOpen(), - contextICE.getOptions().expandWildcardsClosed(), contextICE.getOptions()), false); + contextICE.getOptions().expandWildcardsClosed(), contextICE.getOptions()), NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed"); assertThat(results, emptyArray()); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar1-closed"); assertThat(results, emptyArray()); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foo1-closed"); assertThat(results, arrayWithSize(1)); assertThat(results, arrayContaining("foo1-closed")); @@ -1284,7 +1287,7 @@ public void testIndexOptionsFailClosedIndicesAndAliases() { assertThat(results, arrayContaining("foo1-closed")); // testing an alias pointing to three indices: - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpenAndForbidClosed(), NONE); try { indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); fail("foo2-closed should be closed, but it is open"); @@ -1294,12 +1297,12 @@ public void testIndexOptionsFailClosedIndicesAndAliases() { context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, context.getOptions().allowNoIndices(), context.getOptions().expandWildcardsOpen(), - context.getOptions().expandWildcardsClosed(), context.getOptions()), false); + context.getOptions().expandWildcardsClosed(), context.getOptions()), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); assertThat(results, arrayWithSize(1)); assertThat(results, arrayContaining("foo3")); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); results = indexNameExpressionResolver.concreteIndexNames(context, "foobar2-closed"); assertThat(results, arrayWithSize(3)); assertThat(results, arrayContainingInAnyOrder("foo1-closed", "foo2-closed", "foo3")); @@ -1312,7 +1315,7 @@ public void testDedupConcreteIndices() { IndicesOptions[] indicesOptions = new IndicesOptions[]{ IndicesOptions.strictExpandOpen(), IndicesOptions.strictExpand(), IndicesOptions.lenientExpandOpen(), IndicesOptions.strictExpandOpenAndForbidClosed()}; for (IndicesOptions options : indicesOptions) { - IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, false); + IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, options, NONE); String[] results = indexNameExpressionResolver.concreteIndexNames(context, "index1", "index1", "alias1"); assertThat(results, equalTo(new String[]{"index1"})); } @@ -1333,11 +1336,11 @@ public void testFilterClosedIndicesOnAliases() { ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); String[] strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*"); assertArrayEquals(new String[] {"test-0"}, strings); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictExpandOpen(), NONE); strings = indexNameExpressionResolver.concreteIndexNames(context, "alias-*"); assertArrayEquals(new String[] {"test-0"}, strings); @@ -1748,7 +1751,7 @@ public void testInvalidIndex() { Metadata.Builder mdBuilder = Metadata.builder().put(indexBuilder("test")); ClusterState state = ClusterState.builder(new ClusterName("_name")).metadata(mdBuilder).build(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); InvalidIndexNameException iine = expectThrows(InvalidIndexNameException.class, () -> indexNameExpressionResolver.concreteIndexNames(context, "_foo")); 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 5b8f7af50cb9b..f0a322acc4323 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/WildcardExpressionResolverTests.java @@ -23,6 +23,7 @@ import static org.elasticsearch.cluster.DataStreamTestHelper.createBackingIndex; import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField; +import static org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel.NONE; import static org.elasticsearch.common.util.set.Sets.newHashSet; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; @@ -38,7 +39,7 @@ public void testConvertWildcardsJustIndicesTests() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testXXX"))), equalTo(newHashSet("testXXX"))); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "testYYY"))), equalTo(newHashSet("testXXX", "testYYY"))); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testXXX", "ku*"))), equalTo(newHashSet("testXXX", "kuku"))); @@ -67,7 +68,7 @@ public void testConvertWildcardsTests() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); assertThat(newHashSet(resolver.resolve(context, Arrays.asList("testYY*", "alias*"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("-kuku"))), equalTo(newHashSet("-kuku"))); @@ -90,12 +91,12 @@ public void testConvertWildcardsOpenClosedIndicesTests() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, - IndicesOptions.fromOptions(true, true, true, true), false); + IndicesOptions.fromOptions(true, true, true, true), NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testX*"))), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, false, true), NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testX*"))), equalTo(newHashSet("testXYY"))); - context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), false); + context = new IndexNameExpressionResolver.Context(state, IndicesOptions.fromOptions(true, true, true, false), NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("testX*"))), equalTo(newHashSet("testXXX", "testXXY"))); } @@ -113,7 +114,7 @@ public void testMultipleWildcards() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("test*X*"))), equalTo(newHashSet("testXXX", "testXXY", "testXYY"))); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("test*X*Y"))), equalTo(newHashSet("testXXY", "testXYY"))); @@ -133,7 +134,7 @@ public void testAll() { IndexNameExpressionResolver.WildcardExpressionResolver resolver = new IndexNameExpressionResolver.WildcardExpressionResolver(); IndexNameExpressionResolver.Context context = - new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), false); + new IndexNameExpressionResolver.Context(state, IndicesOptions.lenientExpandOpen(), NONE); assertThat(newHashSet(resolver.resolve(context, Collections.singletonList("_all"))), equalTo(newHashSet("testXXX", "testXYY", "testYYY"))); } @@ -151,15 +152,15 @@ public void testResolveAliases() { IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAndAliasesContext = - new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, false); + new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, NONE); // ignoreAliases option is set, WildcardExpressionResolver throws error when IndicesOptions skipAliasesIndicesOptions = IndicesOptions.fromOptions(true, true, true, false, true, false, true, false); IndexNameExpressionResolver.Context skipAliasesLenientContext = - new IndexNameExpressionResolver.Context(state, skipAliasesIndicesOptions, false); + new IndexNameExpressionResolver.Context(state, skipAliasesIndicesOptions, NONE); // ignoreAliases option is set, WildcardExpressionResolver resolves the provided expressions only against the defined indices IndicesOptions errorOnAliasIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false); IndexNameExpressionResolver.Context skipAliasesStrictContext = - new IndexNameExpressionResolver.Context(state, errorOnAliasIndicesOptions, false); + new IndexNameExpressionResolver.Context(state, errorOnAliasIndicesOptions, NONE); { List indices = resolver.resolve(indicesAndAliasesContext, Collections.singletonList("foo_a*")); @@ -226,7 +227,7 @@ public void testResolveDataStreams() { IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAndAliasesContext = - new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, false); + new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, NONE); // data streams are not included but expression matches the data stream List indices = resolver.resolve(indicesAndAliasesContext, Collections.singletonList("foo_*")); @@ -241,7 +242,7 @@ public void testResolveDataStreams() { IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAliasesAndDataStreamsContext = new IndexNameExpressionResolver.Context(state, - indicesAndAliasesOptions, false, false, true, false); + indicesAndAliasesOptions, false, false, true, NONE); // data stream's corresponding backing indices are resolved List indices = resolver.resolve(indicesAliasesAndDataStreamsContext, Collections.singletonList("foo_*")); @@ -260,7 +261,7 @@ public void testResolveDataStreams() { IndicesOptions indicesAliasesAndExpandHiddenOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), true, false, true, true, false, false, false); IndexNameExpressionResolver.Context indicesAliasesDataStreamsAndHiddenIndices = new IndexNameExpressionResolver.Context(state, - indicesAliasesAndExpandHiddenOptions, false, false, true, false); + indicesAliasesAndExpandHiddenOptions, false, false, true, NONE); // data stream's corresponding backing indices are resolved List indices = resolver.resolve(indicesAliasesDataStreamsAndHiddenIndices, Collections.singletonList("foo_*")); @@ -288,12 +289,12 @@ public void testMatchesConcreteIndicesWildcardAndAliases() { // expressions against the defined indices and aliases IndicesOptions indicesAndAliasesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, false, false); IndexNameExpressionResolver.Context indicesAndAliasesContext = - new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, false); + new IndexNameExpressionResolver.Context(state, indicesAndAliasesOptions, NONE); // ignoreAliases option is set, WildcardExpressionResolver resolves the provided expressions // only against the defined indices IndicesOptions onlyIndicesOptions = IndicesOptions.fromOptions(false, false, true, false, true, false, true, false); - IndexNameExpressionResolver.Context onlyIndicesContext = new IndexNameExpressionResolver.Context(state, onlyIndicesOptions, false); + IndexNameExpressionResolver.Context onlyIndicesContext = new IndexNameExpressionResolver.Context(state, onlyIndicesOptions, NONE); { Set matches = IndexNameExpressionResolver.WildcardExpressionResolver.matches(indicesAndAliasesContext, diff --git a/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java index 1d24679b0f94a..952d8f0fad857 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -37,7 +37,6 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; -import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.core.internal.io.IOUtils; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; @@ -65,6 +64,7 @@ import org.elasticsearch.index.store.FsDirectoryFactory; import org.elasticsearch.indices.IndicesModule; import org.elasticsearch.indices.IndicesQueryCache; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.indices.analysis.AnalysisModule; import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; @@ -137,6 +137,7 @@ public void beforeShardFoldersDeleted(ShardId shardId, IndexSettings indexSettin private BigArrays bigArrays; private ScriptService scriptService; private ClusterService clusterService; + private IndexNameExpressionResolver indexNameExpressionResolver; @Override public void setUp() throws Exception { @@ -157,6 +158,7 @@ public void setUp() throws Exception { clusterService = ClusterServiceUtils.createClusterService(threadPool); nodeEnvironment = new NodeEnvironment(settings, environment); mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry(); + indexNameExpressionResolver = new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of())); } @Override @@ -181,7 +183,7 @@ public void testWrapperIsBound() throws IOException { engineFactory, Collections.emptyMap(), () -> true, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, Collections.emptyMap()); module.setReaderWrapper(s -> new Wrapper()); @@ -203,7 +205,7 @@ public void testRegisterIndexStore() throws IOException { final Map indexStoreFactories = singletonMap( "foo_store", new FooFunction()); final IndexModule module = new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), indexStoreFactories, - () -> true, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), Collections.emptyMap()); + () -> true, indexNameExpressionResolver, Collections.emptyMap()); final IndexService indexService = newIndexService(module); assertThat(indexService.getDirectoryFactory(), instanceOf(FooFunction.class)); @@ -220,7 +222,7 @@ public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason rea } }; IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); module.addIndexEventListener(eventListener); IndexService indexService = newIndexService(module); IndexSettings x = indexService.getIndexSettings(); @@ -235,7 +237,7 @@ public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason rea public void testListener() throws IOException { Setting booleanSetting = Setting.boolSetting("index.foo.bar", false, Property.Dynamic, Property.IndexScope); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings, booleanSetting); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); Setting booleanSetting2 = Setting.boolSetting("index.foo.bar.baz", false, Property.Dynamic, Property.IndexScope); AtomicBoolean atomicBoolean = new AtomicBoolean(false); module.addSettingsUpdateConsumer(booleanSetting, atomicBoolean::set); @@ -255,7 +257,7 @@ public void testListener() throws IOException { public void testAddIndexOperationListener() throws IOException { final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); AtomicBoolean executed = new AtomicBoolean(false); IndexingOperationListener listener = new IndexingOperationListener() { @Override @@ -286,7 +288,7 @@ public Engine.Index preIndex(ShardId shardId, Engine.Index operation) { public void testAddSearchOperationListener() throws IOException { final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); AtomicBoolean executed = new AtomicBoolean(false); SearchOperationListener listener = new SearchOperationListener() { @Override @@ -319,7 +321,7 @@ public void testAddSimilarity() throws IOException { .build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); IndexModule module = - createIndexModule(indexSettings, emptyAnalysisRegistry); + createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); module.addSimilarity("test_similarity", (providerSettings, indexCreatedVersion, scriptService) -> new TestSimilarity(providerSettings.get("key"))); @@ -339,7 +341,7 @@ public void testAddSimilarity() throws IOException { public void testFrozen() { final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); module.freeze(); String msg = "Can't modify IndexModule once the index service has been created"; assertEquals(msg, expectThrows(IllegalStateException.class, () -> module.addSearchOperationListener(null)).getMessage()); @@ -358,7 +360,7 @@ public void testSetupUnknownSimilarity() { .build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); IndexModule module = - createIndexModule(indexSettings, emptyAnalysisRegistry); + createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module)); assertEquals("Unknown Similarity type [test_similarity] for [my_similarity]", ex.getMessage()); } @@ -370,7 +372,7 @@ public void testSetupWithoutType() { .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) .build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module)); assertEquals("Similarity [my_similarity] must have an associated type", ex.getMessage()); } @@ -380,7 +382,7 @@ public void testForceCustomQueryCache() throws IOException { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); final Set liveQueryCaches = new HashSet<>(); module.forceQueryCacheProvider((a, b) -> { final CustomQueryCache customQueryCache = new CustomQueryCache(liveQueryCaches); @@ -401,7 +403,7 @@ public void testDefaultQueryCacheImplIsSelected() throws IOException { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); IndexService indexService = newIndexService(module); assertTrue(indexService.cache().query() instanceof IndexQueryCache); indexService.close("simon says", false); @@ -413,7 +415,7 @@ public void testDisableQueryCacheHasPrecedenceOverForceQueryCache() throws IOExc .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); module.forceQueryCacheProvider((a, b) -> new CustomQueryCache(null)); IndexService indexService = newIndexService(module); assertTrue(indexService.cache().query() instanceof DisabledQueryCache); @@ -425,7 +427,7 @@ public void testCustomQueryCacheCleanedUpIfIndexServiceCreationFails() { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("foo", settings); - IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry); + IndexModule module = createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); final Set liveQueryCaches = new HashSet<>(); module.forceQueryCacheProvider((a, b) -> { final CustomQueryCache customQueryCache = new CustomQueryCache(liveQueryCaches); @@ -475,7 +477,7 @@ public void close() { }; final AnalysisRegistry analysisRegistry = new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), singletonMap("test", analysisProvider), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()); - IndexModule module = createIndexModule(indexSettings, analysisRegistry); + IndexModule module = createIndexModule(indexSettings, analysisRegistry, indexNameExpressionResolver); threadPool.shutdown(); // causes index service creation to fail expectThrows(EsRejectedExecutionException.class, () -> newIndexService(module)); assertThat(openAnalyzers, empty()); @@ -492,7 +494,7 @@ public void testMmapNotAllowed() { .build(); final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(new Index("foo", "_na_"), settings, nodeSettings); final IndexModule module = - createIndexModule(indexSettings, emptyAnalysisRegistry); + createIndexModule(indexSettings, emptyAnalysisRegistry, indexNameExpressionResolver); final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> newIndexService(module)); assertThat(e, hasToString(containsString("store type [" + storeType + "] is not allowed"))); } @@ -516,7 +518,7 @@ public void testRegisterCustomRecoveryStateFactory() throws IOException { new InternalEngineFactory(), Collections.emptyMap(), () -> true, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, recoveryStateFactories); final IndexService indexService = newIndexService(module); @@ -535,9 +537,10 @@ private ShardRouting createInitializedShardRouting() { return shard; } - private static IndexModule createIndexModule(IndexSettings indexSettings, AnalysisRegistry emptyAnalysisRegistry) { + private static IndexModule createIndexModule(IndexSettings indexSettings, AnalysisRegistry emptyAnalysisRegistry, + IndexNameExpressionResolver indexNameExpressionResolver) { return new IndexModule(indexSettings, emptyAnalysisRegistry, new InternalEngineFactory(), Collections.emptyMap(), () -> true, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), Collections.emptyMap()); + indexNameExpressionResolver, Collections.emptyMap()); } class CustomQueryCache implements QueryCache { diff --git a/server/src/test/java/org/elasticsearch/index/query/SearchIndexNameMatcherTests.java b/server/src/test/java/org/elasticsearch/index/query/SearchIndexNameMatcherTests.java index 352f71e57b11a..f998c981029fc 100644 --- a/server/src/test/java/org/elasticsearch/index/query/SearchIndexNameMatcherTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/SearchIndexNameMatcherTests.java @@ -18,9 +18,12 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.junit.Before; +import java.util.Map; + import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,9 +43,9 @@ public void setUpMatchers() { when(clusterService.state()).thenReturn(state); matcher = new SearchIndexNameMatcher("index1", "", clusterService, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); remoteMatcher = new SearchIndexNameMatcher("index1", "cluster", clusterService, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); } private static IndexMetadata.Builder indexBuilder(String index) { diff --git a/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java b/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java index cb77e03cb76d1..be704f0de6b7a 100644 --- a/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java +++ b/server/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java @@ -146,7 +146,8 @@ public ClusterStateChanges(NamedXContentRegistry xContentRegistry, ThreadPool th shardStartedClusterStateTaskExecutor = new ShardStateAction.ShardStartedClusterStateTaskExecutor(allocationService, null, logger); ActionFilters actionFilters = new ActionFilters(Collections.emptySet()); - IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver indexNameExpressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); SystemIndices systemIndices = new SystemIndices(Map.of()); DestructiveOperations destructiveOperations = new DestructiveOperations(SETTINGS, clusterSettings); Environment environment = TestEnvironment.newEnvironment(SETTINGS); diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java index 1f5c53e9271c2..01efab8cc7dee 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java @@ -1442,7 +1442,7 @@ protected NamedWriteableRegistry writeableRegistry() { transportService = mockTransport.createTransportService(settings, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, a -> node, null, emptySet()); final IndexNameExpressionResolver indexNameExpressionResolver = - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); repositoriesService = new RepositoriesService( settings, clusterService, transportService, Collections.singletonMap(FsRepository.TYPE, getRepoFactory(environment)), emptyMap(), threadPool diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java index 0a3bd45c49174..f3641af4f3c84 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.SystemIndexAccessLevel; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; @@ -134,7 +135,7 @@ public ResolverContext() { } public ResolverContext(long startTime) { - super(null, null, startTime, false, false, false, false, false); + super(null, null, startTime, false, false, false, false, SystemIndexAccessLevel.NONE); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java index 71aedca51a08a..1af0e76d928f1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java @@ -23,7 +23,7 @@ import org.elasticsearch.common.CheckedConsumer; import org.elasticsearch.common.ValidationException; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.ingest.ConfigurationUtils; import org.elasticsearch.ingest.IngestService; import org.elasticsearch.ingest.Pipeline; @@ -103,9 +103,11 @@ public class SourceDestValidatorTests extends ESTestCase { private final TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool); private final RemoteClusterService remoteClusterService = transportService.getRemoteClusterService(); private final IngestService ingestService = mock(IngestService.class); + private final IndexNameExpressionResolver indexNameExpressionResolver = + new IndexNameExpressionResolver(threadPool.getThreadContext(), new SystemIndices(Map.of())); private final SourceDestValidator simpleNonRemoteValidator = new SourceDestValidator( - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, null, ingestService, @@ -655,7 +657,7 @@ public void testRemoteSourceBasic() throws InterruptedException { Context context = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, remoteClusterLicenseCheckerBasic, ingestService, @@ -681,7 +683,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { final Context context = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, new RemoteClusterLicenseChecker(clientWithBasicLicense, operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)), @@ -713,7 +715,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { final Context context2 = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, new RemoteClusterLicenseChecker(clientWithPlatinumLicense, operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)), @@ -736,7 +738,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { final Context context3 = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, new RemoteClusterLicenseChecker(clientWithPlatinumLicense, operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)), @@ -760,7 +762,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { final Context context4 = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, new RemoteClusterLicenseChecker(clientWithTrialLicense, operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)), @@ -786,7 +788,7 @@ public void testRemoteSourceLicenseInActive() throws InterruptedException { final Context context = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, new RemoteClusterLicenseChecker(clientWithExpiredBasicLicense, operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)), @@ -815,7 +817,7 @@ public void testRemoteSourceDoesNotExist() throws InterruptedException { Context context = spy( new SourceDestValidator.Context( CLUSTER_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + indexNameExpressionResolver, remoteClusterService, new RemoteClusterLicenseChecker(clientWithExpiredBasicLicense, operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM)), diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java index 95e087c92f63d..f9c79cb46e813 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/deprecation/DeprecationInfoActionResponseTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfigTests; @@ -86,7 +87,8 @@ public void testFrom() throws IOException { new TransportAddress(TransportAddress.META_ADDRESS, 9300), "test"); ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build(); List datafeeds = Collections.singletonList(DatafeedConfigTests.createRandomizedDatafeedConfig("foo")); - IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver resolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true); boolean clusterIssueFound = randomBoolean(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java index 25dd966aaa30c..71dbf6523ed42 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.inference.persistence.InferenceIndexConstants; @@ -281,7 +282,7 @@ public void testIndexNameComparator() { private void createIndexAndAliasIfNecessary(ClusterState clusterState) { MlIndexAndAlias.createIndexAndAliasIfNecessary( - client, clusterState, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + client, clusterState, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), TEST_INDEX_PREFIX, TEST_INDEX_ALIAS, listener); } diff --git a/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/DeleteDataStreamTransportActionTests.java b/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/DeleteDataStreamTransportActionTests.java index 4d97513137595..a7cff46b7945d 100644 --- a/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/DeleteDataStreamTransportActionTests.java +++ b/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/DeleteDataStreamTransportActionTests.java @@ -21,6 +21,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.snapshots.Snapshot; import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.snapshots.SnapshotInProgressException; @@ -29,6 +30,7 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import static org.hamcrest.Matchers.containsInAnyOrder; @@ -40,7 +42,10 @@ public class DeleteDataStreamTransportActionTests extends ESTestCase { - private final IndexNameExpressionResolver iner = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + private final IndexNameExpressionResolver iner = new IndexNameExpressionResolver( + new ThreadContext(Settings.EMPTY), + new SystemIndices(Map.of()) + ); public void testDeleteDataStream() { final String dataStreamName = "my-data-stream"; diff --git a/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/GetDataStreamsTransportActionTests.java b/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/GetDataStreamsTransportActionTests.java index 8ab5783bf943d..1e201e52cfd08 100644 --- a/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/GetDataStreamsTransportActionTests.java +++ b/x-pack/plugin/data-streams/src/test/java/org/elasticsearch/xpack/datastreams/action/GetDataStreamsTransportActionTests.java @@ -15,10 +15,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.action.GetDataStreamAction; import java.util.List; +import java.util.Map; import static org.elasticsearch.cluster.DataStreamTestHelper.getClusterStateWithDataStreams; import static org.hamcrest.Matchers.containsString; @@ -26,15 +28,16 @@ public class GetDataStreamsTransportActionTests extends ESTestCase { + private final IndexNameExpressionResolver resolver = new IndexNameExpressionResolver( + new ThreadContext(Settings.EMPTY), + new SystemIndices(Map.of()) + ); + public void testGetDataStream() { final String dataStreamName = "my-data-stream"; ClusterState cs = getClusterStateWithDataStreams(List.of(new Tuple<>(dataStreamName, 1)), List.of()); GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamName }); - List dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + List dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(1)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamName)); } @@ -47,40 +50,24 @@ public void testGetDataStreamsWithWildcards() { ); GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamNames[1].substring(0, 5) + "*" }); - List dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + List dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(1)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); req = new GetDataStreamAction.Request(new String[] { "*" }); - dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(2)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0])); req = new GetDataStreamAction.Request((String[]) null); - dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(2)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0])); req = new GetDataStreamAction.Request(new String[] { "matches-none*" }); - dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(0)); } @@ -92,37 +79,25 @@ public void testGetDataStreamsWithoutWildcards() { ); GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamNames[0], dataStreamNames[1] }); - List dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + List dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(2)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); assertThat(dataStreams.get(1).getName(), equalTo(dataStreamNames[0])); req = new GetDataStreamAction.Request(new String[] { dataStreamNames[1] }); - dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(1)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[1])); req = new GetDataStreamAction.Request(new String[] { dataStreamNames[0] }); - dataStreams = GetDataStreamsTransportAction.getDataStreams( - cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), - req - ); + dataStreams = GetDataStreamsTransportAction.getDataStreams(cs, resolver, req); assertThat(dataStreams.size(), equalTo(1)); assertThat(dataStreams.get(0).getName(), equalTo(dataStreamNames[0])); GetDataStreamAction.Request req2 = new GetDataStreamAction.Request(new String[] { "foo" }); IndexNotFoundException e = expectThrows( IndexNotFoundException.class, - () -> GetDataStreamsTransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req2) + () -> GetDataStreamsTransportAction.getDataStreams(cs, resolver, req2) ); assertThat(e.getMessage(), containsString("no such index [foo]")); } @@ -133,7 +108,7 @@ public void testGetNonexistentDataStream() { GetDataStreamAction.Request req = new GetDataStreamAction.Request(new String[] { dataStreamName }); IndexNotFoundException e = expectThrows( IndexNotFoundException.class, - () -> GetDataStreamsTransportAction.getDataStreams(cs, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), req) + () -> GetDataStreamsTransportAction.getDataStreams(cs, resolver, req) ); assertThat(e.getMessage(), containsString("no such index [" + dataStreamName + "]")); } diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/AbstractEnrichTestCase.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/AbstractEnrichTestCase.java index fc6e9f0eb75c2..0ab2fe06ddc0c 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/AbstractEnrichTestCase.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/AbstractEnrichTestCase.java @@ -14,12 +14,14 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; @@ -35,7 +37,10 @@ protected AtomicReference saveEnrichPolicy(String name, EnrichPolicy if (policy != null) { createSourceIndices(policy); } - IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver resolver = new IndexNameExpressionResolver( + new ThreadContext(Settings.EMPTY), + new SystemIndices(Map.of()) + ); CountDownLatch latch = new CountDownLatch(1); AtomicReference error = new AtomicReference<>(); EnrichStore.putPolicy(name, policy, clusterService, resolver, e -> { diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyExecutorTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyExecutorTests.java index 5150b49bce5a2..2d2fa22f2e376 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyExecutorTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyExecutorTests.java @@ -7,12 +7,6 @@ package org.elasticsearch.xpack.enrich; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.function.LongSupplier; - import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.LatchedActionListener; import org.elasticsearch.client.Client; @@ -20,7 +14,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; -import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; @@ -31,6 +25,13 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.LongSupplier; + import static org.hamcrest.CoreMatchers.containsString; public class EnrichPolicyExecutorTests extends ESTestCase { @@ -143,7 +144,7 @@ public void testNonConcurrentPolicyExecution() throws InterruptedException { null, testTaskManager, testThreadPool, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + new IndexNameExpressionResolver(testThreadPool.getThreadContext(), new SystemIndices(Map.of())), ESTestCase::randomNonNegativeLong ); @@ -200,7 +201,7 @@ public void testMaximumPolicyExecutionLimit() throws InterruptedException { null, testTaskManager, testThreadPool, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + new IndexNameExpressionResolver(testThreadPool.getThreadContext(), new SystemIndices(Map.of())), ESTestCase::randomNonNegativeLong ); diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceServiceTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceServiceTests.java index f3944a91eb09b..30db91978205c 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceServiceTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceServiceTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -30,6 +31,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Phaser; @@ -124,7 +126,10 @@ private EnrichPolicy randomPolicy() { } private void addPolicy(String policyName, EnrichPolicy policy) throws InterruptedException { - IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver resolver = new IndexNameExpressionResolver( + new ThreadContext(Settings.EMPTY), + new SystemIndices(Map.of()) + ); createSourceIndices(client(), policy); doSyncronously( (clusterService, exceptionConsumer) -> EnrichStore.putPolicy(policyName, policy, clusterService, resolver, exceptionConsumer) diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ModelSnapshotRetentionIT.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ModelSnapshotRetentionIT.java index 74281712795aa..726ade1ccea23 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ModelSnapshotRetentionIT.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/ModelSnapshotRetentionIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.xpack.core.ml.action.PutJobAction; @@ -49,6 +50,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Map; import static org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex.createStateIndexAndAliasIfNecessary; import static org.hamcrest.Matchers.greaterThan; @@ -71,7 +73,7 @@ public class ModelSnapshotRetentionIT extends MlNativeAutodetectIntegTestCase { public void addMlState() { PlainActionFuture future = new PlainActionFuture<>(); createStateIndexAndAliasIfNecessary(client(), ClusterState.EMPTY_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), future); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), future); future.actionGet(); } diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java index ff789b8919fb7..bd2299fce839f 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/AutodetectResultProcessorIT.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.reindex.ReindexPlugin; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.ingest.common.IngestCommonPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; @@ -91,6 +92,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -143,7 +145,7 @@ public void createComponents() throws Exception { .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueSeconds(1)); AnomalyDetectionAuditor auditor = new AnomalyDetectionAuditor(client(), getInstanceFromNode(ClusterService.class)); jobResultsProvider = new JobResultsProvider(client(), builder.build(), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); renormalizer = mock(Renormalizer.class); process = mock(AutodetectProcess.class); capturedUpdateModelSnapshotOnJobRequests = new ArrayList<>(); @@ -183,7 +185,7 @@ protected void updateModelSnapshotOnJob(ModelSnapshot modelSnapshot) { // copy this setup to tests that run jobs in the way they are run in production. PlainActionFuture future = new PlainActionFuture<>(); createStateIndexAndAliasIfNecessary(client(), ClusterState.EMPTY_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), future); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), future); future.get(); } diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/EstablishedMemUsageIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/EstablishedMemUsageIT.java index b3951e353bd50..99b49183ca51b 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/EstablishedMemUsageIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/EstablishedMemUsageIT.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ml.action.PutJobAction; @@ -23,8 +24,8 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSizeStats; import org.elasticsearch.xpack.core.ml.job.results.Bucket; import org.elasticsearch.xpack.ml.inference.ingest.InferenceProcessor; -import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; import org.elasticsearch.xpack.ml.job.persistence.JobResultsPersister; +import org.elasticsearch.xpack.ml.job.persistence.JobResultsProvider; import org.elasticsearch.xpack.ml.notifications.AnomalyDetectionAuditor; import org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase; import org.elasticsearch.xpack.ml.utils.persistence.ResultsPersisterService; @@ -33,6 +34,7 @@ import java.util.Arrays; import java.util.Date; import java.util.HashSet; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; @@ -60,7 +62,8 @@ public void createComponents() { OriginSettingClient originSettingClient = new OriginSettingClient(client(), ClientHelper.ML_ORIGIN); ResultsPersisterService resultsPersisterService = new ResultsPersisterService(tp, originSettingClient, clusterService, settings); - jobResultsProvider = new JobResultsProvider(client(), settings, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + jobResultsProvider = new JobResultsProvider(client(), settings, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); jobResultsPersister = new JobResultsPersister( originSettingClient, resultsPersisterService, new AnomalyDetectionAuditor(client(), clusterService)); } diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java index 669ef6e73cfa7..d051c90077e2a 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java @@ -39,6 +39,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -114,7 +115,8 @@ public class JobResultsProviderIT extends MlSingleNodeTestCase { public void createComponents() throws Exception { Settings.Builder builder = Settings.builder() .put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.timeValueSeconds(1)); - jobProvider = new JobResultsProvider(client(), builder.build(), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + jobProvider = new JobResultsProvider(client(), builder.build(), + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); ThreadPool tp = mockThreadPool(); ClusterSettings clusterSettings = new ClusterSettings(builder.build(), new HashSet<>(Arrays.asList(InferenceProcessor.MAX_INFERENCE_PROCESSORS, @@ -951,7 +953,7 @@ private void indexModelSnapshot(ModelSnapshot snapshot) { private void indexQuantiles(Quantiles quantiles) { PlainActionFuture future = new PlainActionFuture<>(); createStateIndexAndAliasIfNecessary(client(), ClusterState.EMPTY_STATE, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), future); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), future); future.actionGet(); JobResultsPersister persister = new JobResultsPersister(new OriginSettingClient(client(), ClientHelper.ML_ORIGIN), resultsPersisterService, auditor); diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java index 061023f04e457..92987bec1021c 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/JobStorageDeletionTaskIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ClientHelper; @@ -43,6 +44,7 @@ import java.util.Arrays; import java.util.Date; import java.util.HashSet; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import static org.hamcrest.Matchers.equalTo; @@ -74,7 +76,8 @@ public void createComponents() { ClusterService clusterService = new ClusterService(settings, clusterSettings, tp); OriginSettingClient originSettingClient = new OriginSettingClient(client(), ClientHelper.ML_ORIGIN); ResultsPersisterService resultsPersisterService = new ResultsPersisterService(tp, originSettingClient, clusterService, settings); - jobResultsProvider = new JobResultsProvider(client(), settings, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + jobResultsProvider = new JobResultsProvider(client(), settings, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); jobResultsPersister = new JobResultsPersister( originSettingClient, resultsPersisterService, new AnomalyDetectionAuditor(client(), clusterService)); } diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlAutoUpdateServiceIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlAutoUpdateServiceIT.java index 172a90a6c7445..695b9e1d27999 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlAutoUpdateServiceIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlAutoUpdateServiceIT.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.search.SearchModule; import org.elasticsearch.xpack.core.ml.MlConfigIndex; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; @@ -31,6 +32,7 @@ import java.net.InetAddress; import java.util.Collections; +import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; @@ -72,7 +74,8 @@ public void createComponents() throws Exception { public void testAutomaticModelUpdate() throws Exception { ensureGreen("_all"); - IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver indexNameExpressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); client().prepareIndex(MlConfigIndex.indexName()) .setId(DatafeedConfig.documentId("farequote-datafeed-with-old-agg")) .setSource(AGG_WITH_OLD_DATE_HISTOGRAM_INTERVAL, XContentType.JSON) diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java index b56480cc4381a..6405411c01fbd 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/MlConfigMigratorIT.java @@ -38,6 +38,7 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.core.ml.MlConfigIndex; import org.elasticsearch.xpack.core.ml.MlMetadata; @@ -58,6 +59,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.SortedMap; @@ -77,7 +79,8 @@ public class MlConfigMigratorIT extends MlSingleNodeTestCase { - private final IndexNameExpressionResolver expressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + private final IndexNameExpressionResolver expressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); private ClusterService clusterService; @Before diff --git a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/UnusedStatsRemoverIT.java b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/UnusedStatsRemoverIT.java index 95034146eba49..fb4d0a867a5d0 100644 --- a/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/UnusedStatsRemoverIT.java +++ b/x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/UnusedStatsRemoverIT.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.tasks.TaskId; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ml.MlStatsIndex; @@ -43,6 +44,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.Collections; +import java.util.Map; public class UnusedStatsRemoverIT extends BaseMlIntegTestCase { @@ -53,7 +55,7 @@ public void createComponents() { client = new OriginSettingClient(client(), ClientHelper.ML_ORIGIN); PlainActionFuture future = new PlainActionFuture<>(); MlStatsIndex.createStatsIndexAndAliasIfNecessary(client(), clusterService().state(), - new IndexNameExpressionResolver(client.threadPool().getThreadContext()), future); + new IndexNameExpressionResolver(client.threadPool().getThreadContext(), new SystemIndices(Map.of())), future); future.actionGet(); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsActionTests.java index ebcbfe946b6c5..48950477beb99 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsActionTests.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.set.Sets; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.persistent.PersistentTasksCustomMetadata.Assignment; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.MlMetadata; @@ -165,7 +166,7 @@ private static TaskExecutor createTaskExecutor() { mock(DataFrameAnalyticsManager.class), mock(DataFrameAnalyticsAuditor.class), mock(MlMemoryTracker.class), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); } private static DiscoveryNode createNode(int i, boolean isMlNode, Version nodeVersion) { diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java index 9500d1e41a4b1..b08d62641b167 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedConfigAutoUpdaterTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.MlConfigIndex; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; @@ -35,6 +36,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.equalTo; @@ -51,7 +53,8 @@ public class DatafeedConfigAutoUpdaterTests extends ESTestCase { private DatafeedConfigProvider provider; private List datafeeds = new ArrayList<>(); - private IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + private IndexNameExpressionResolver indexNameExpressionResolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); @Before public void setup() { diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java index 8622521296b16..d54b190a563ea 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.MlMetadata; @@ -47,6 +48,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Map; import static org.elasticsearch.cluster.DataStreamTestHelper.createTimestampField; import static org.elasticsearch.cluster.metadata.DataStream.getDefaultBackingIndexName; @@ -67,7 +69,7 @@ public class DatafeedNodeSelectorTests extends ESTestCase { @Before public void init() { - resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); nodes = DiscoveryNodes.builder() .add(new DiscoveryNode("node_name", "node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), Collections.emptySet(), Version.CURRENT)) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java index 2aa078571f359..59b1199a455ff 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/TrainedModelStatsServiceTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.MlMetadata; @@ -36,6 +37,7 @@ import org.elasticsearch.xpack.ml.utils.persistence.ResultsPersisterService; import java.time.Instant; +import java.util.Map; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.any; @@ -48,7 +50,8 @@ public class TrainedModelStatsServiceTests extends ESTestCase { public void testVerifyIndicesExistAndPrimaryShardsAreActive() { String aliasName = MlStatsIndex.writeAlias(); String concreteIndex = ".ml-stats-000001"; - IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver resolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); { Metadata.Builder metadata = Metadata.builder(); @@ -137,7 +140,8 @@ public void testVerifyIndicesExistAndPrimaryShardsAreActive() { public void testUpdateStatsUpgradeMode() { String aliasName = MlStatsIndex.writeAlias(); String concreteIndex = ".ml-stats-000001"; - IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + IndexNameExpressionResolver resolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); // create a valid index routing so persistence will occur RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java index 9d4fcbd8a7868..e4a176d8280fb 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.test.ESTestCase; @@ -878,7 +879,8 @@ public void testCreateTermFieldsMapping() throws IOException { } private JobResultsProvider createProvider(Client client) { - return new JobResultsProvider(client, Settings.EMPTY, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + return new JobResultsProvider(client, Settings.EMPTY, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); } private static SearchResponse createSearchResponse(List> source) throws IOException { diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java index 406a5e8f38508..dd1c15edc95a3 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/process/autodetect/AutodetectProcessManagerTests.java @@ -28,6 +28,7 @@ import org.elasticsearch.env.Environment; import org.elasticsearch.env.TestEnvironment; import org.elasticsearch.index.analysis.AnalysisRegistry; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ml.annotations.AnnotationIndex; @@ -74,6 +75,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -723,7 +725,7 @@ private AutodetectProcessManager createManager(Settings settings) { return new AutodetectProcessManager(settings, client, threadPool, new NamedXContentRegistry(Collections.emptyList()), auditor, clusterService, jobManager, jobResultsProvider, jobResultsPersister, jobDataCountsPersister, annotationPersister, autodetectFactory, normalizerFactory, nativeStorageProvider, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); } private AutodetectProcessManager createSpyManagerAndCallProcessData(String jobId) { AutodetectProcessManager manager = createSpyManager(); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java index ea52c72cef8fe..96d0fc6e3c88b 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/task/OpenJobPersistentTasksExecutorTests.java @@ -33,6 +33,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; @@ -67,6 +68,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import static org.elasticsearch.xpack.core.ml.job.config.JobTests.buildJobBuilder; @@ -243,6 +245,6 @@ public static Job jobWithRules(String jobId) { private OpenJobPersistentTasksExecutor createExecutor(Settings settings) { return new OpenJobPersistentTasksExecutor( settings, clusterService, autodetectProcessManager, datafeedConfigProvider, mlMemoryTracker, client, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java index 7e51292376959..0c9c49ca0a0ba 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/task/AbstractJobPersistentTasksExecutorTests.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.MlConfigIndex; import org.elasticsearch.xpack.core.ml.MlMetaIndex; @@ -34,13 +35,15 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import static org.elasticsearch.xpack.ml.task.AbstractJobPersistentTasksExecutor.verifyIndicesPrimaryShardsAreActive; public class AbstractJobPersistentTasksExecutorTests extends ESTestCase { public void testVerifyIndicesPrimaryShardsAreActive() { - final IndexNameExpressionResolver resolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + final IndexNameExpressionResolver resolver = + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); Metadata.Builder metadata = Metadata.builder(); RoutingTable.Builder routingTable = RoutingTable.builder(); addIndices(metadata, routingTable); @@ -57,8 +60,7 @@ public void testVerifyIndicesPrimaryShardsAreActive() { metadata = new Metadata.Builder(cs.metadata()); routingTable = new RoutingTable.Builder(cs.routingTable()); - IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); - String indexToRemove = randomFrom(indexNameExpressionResolver.concreteIndexNames(cs, IndicesOptions.lenientExpandOpen(), + String indexToRemove = randomFrom(resolver.concreteIndexNames(cs, IndicesOptions.lenientExpandOpen(), ".ml-anomalies-shared", AnomalyDetectorsIndex.jobStateIndexPattern(), MlMetaIndex.indexName(), diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollectorTests.java index 243cb593e0334..9a47913ae4475 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsCollectorTests.java @@ -25,12 +25,13 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.license.License; import org.elasticsearch.license.LicenseService; +import org.elasticsearch.protocol.xpack.XPackUsageRequest; import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.action.XPackUsageAction; -import org.elasticsearch.protocol.xpack.XPackUsageRequest; import org.elasticsearch.xpack.core.action.XPackUsageResponse; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.MonitoringFeatureSetUsage; @@ -42,6 +43,7 @@ import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.UUID; import static java.util.Collections.singletonList; @@ -73,7 +75,7 @@ public void setUp() throws Exception { public void testShouldCollectReturnsFalseIfNotMaster() { final ClusterStatsCollector collector = new ClusterStatsCollector(Settings.EMPTY, clusterService, licenseState, client, licenseService, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); assertThat(collector.shouldCollect(false), is(false)); } @@ -81,7 +83,7 @@ public void testShouldCollectReturnsFalseIfNotMaster() { public void testShouldCollectReturnsTrue() { final ClusterStatsCollector collector = new ClusterStatsCollector(Settings.EMPTY, clusterService, licenseState, client, licenseService, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))); assertThat(collector.shouldCollect(true), is(true)); } diff --git a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java index 348f28c19bc3b..2736929dc3b70 100644 --- a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java +++ b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/DateMathExpressionIntegTests.java @@ -22,10 +22,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSourceField; import java.util.Collections; +import java.util.Map; import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE; import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.NONE; @@ -64,7 +66,8 @@ protected String configRoles() { public void testDateMathExpressionsCanBeAuthorized() throws Exception { final String expression = ""; final String expectedIndexName = - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)).resolveDateMathExpression(expression); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())) + .resolveDateMathExpression(expression); final boolean refeshOnOperation = randomBoolean(); Client client = client().filterWithHeader(Collections.singletonMap("Authorization", basicAuthHeaderValue("user1", USERS_PASSWD))); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java index 97343380a79be..6575c2467f1d5 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.env.Environment; import org.elasticsearch.env.TestEnvironment; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.license.License; import org.elasticsearch.license.TestUtils; import org.elasticsearch.license.XPackLicenseState; @@ -133,7 +134,7 @@ protected SSLService getSslService() { when(client.threadPool()).thenReturn(threadPool); when(client.settings()).thenReturn(settings); return security.createComponents(client, threadPool, clusterService, mock(ResourceWatcherService.class), mock(ScriptService.class), - xContentRegistry(), env, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + xContentRegistry(), env, new IndexNameExpressionResolver(threadContext, new SystemIndices(Map.of()))); } private Collection createComponentsWithSecurityNotExplicitlyEnabled(Settings testSettings, SecurityExtension... extensions) diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java index 546625da6e30d..5ca606a502912 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java @@ -97,6 +97,7 @@ import org.elasticsearch.index.bulk.stats.BulkOperationListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.script.ScriptService; @@ -282,7 +283,8 @@ public void setup() { operatorPrivilegesService = mock(OperatorPrivileges.OperatorPrivilegesService.class); authorizationService = new AuthorizationService(settings, rolesStore, clusterService, auditTrailService, new DefaultAuthenticationFailureHandler(Collections.emptyMap()), threadPool, new AnonymousUser(settings), - null, Collections.emptySet(), licenseState, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), + null, Collections.emptySet(), licenseState, + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), operatorPrivilegesService); } @@ -1046,7 +1048,7 @@ public void testDenialForAnonymousUser() throws IOException { authorizationService = new AuthorizationService(settings, rolesStore, clusterService, auditTrailService, new DefaultAuthenticationFailureHandler(Collections.emptyMap()), threadPool, anonymousUser, null, Collections.emptySet(), new XPackLicenseState(settings, () -> 0), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), operatorPrivilegesService); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), operatorPrivilegesService); RoleDescriptor role = new RoleDescriptor("a_all", null, new IndicesPrivileges[]{IndicesPrivileges.builder().indices("a").privileges("all").build()}, null); @@ -1075,7 +1077,7 @@ public void testDenialForAnonymousUserAuthorizationExceptionDisabled() throws IO authorizationService = new AuthorizationService(settings, rolesStore, clusterService, auditTrailService, new DefaultAuthenticationFailureHandler(Collections.emptyMap()), threadPool, new AnonymousUser(settings), null, Collections.emptySet(), new XPackLicenseState(settings, () -> 0), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), operatorPrivilegesService); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), operatorPrivilegesService); RoleDescriptor role = new RoleDescriptor("a_all", null, new IndicesPrivileges[]{IndicesPrivileges.builder().indices("a").privileges("all").build()}, null); @@ -1817,7 +1819,7 @@ public void getUserPrivileges(Authentication authentication, AuthorizationInfo a authorizationService = new AuthorizationService(Settings.EMPTY, rolesStore, clusterService, auditTrailService, new DefaultAuthenticationFailureHandler(Collections.emptyMap()), threadPool, new AnonymousUser(Settings.EMPTY), engine, Collections.emptySet(), licenseState, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), operatorPrivilegesService); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), operatorPrivilegesService); Authentication authentication; try (ThreadContext.StoredContext ignore = threadContext.stashContext()) { authentication = createAuthentication(new User("test user", "a_all")); 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 c1cadc89117a7..f4d471bde3388 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 @@ -50,6 +50,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest; import org.elasticsearch.search.internal.ShardSearchRequest; import org.elasticsearch.test.ESTestCase; @@ -130,7 +131,7 @@ public void setup() { .put("cluster.remote.other_remote.seeds", "127.0.0.1:" + randomIntBetween(9351, 9399)) .build(); - indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)); + indexNameExpressionResolver = new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())); DateFormatter dateFormatter = DateFormatter.forPattern("uuuu.MM.dd"); Instant now = Instant.now(Clock.systemUTC()); @@ -285,7 +286,7 @@ public void setup() { ClusterService clusterService = mock(ClusterService.class); when(clusterService.getClusterSettings()).thenReturn(new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); defaultIndicesResolver = - new IndicesAndAliasesResolver(settings, clusterService, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))); + new IndicesAndAliasesResolver(settings, clusterService, indexNameExpressionResolver); } public void testDashIndicesAreAllowedInShardLevelRequests() { diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java index 915df8e06d11a..a539264a9f2f1 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformPersistentTasksExecutorTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; import org.elasticsearch.persistent.PersistentTasksCustomMetadata.Assignment; import org.elasticsearch.test.ESTestCase; @@ -182,7 +183,7 @@ public void testVerifyIndicesPrimaryShardsAreActive() { ClusterState cs = csBuilder.build(); assertEquals(0, TransformPersistentTasksExecutor.verifyIndicesPrimaryShardsAreActive(cs, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY))).size()); + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of()))).size()); metadata = new Metadata.Builder(cs.metadata()); routingTable = new RoutingTable.Builder(cs.routingTable()); @@ -209,7 +210,7 @@ public void testVerifyIndicesPrimaryShardsAreActive() { csBuilder.metadata(metadata); List result = TransformPersistentTasksExecutor.verifyIndicesPrimaryShardsAreActive( csBuilder.build(), - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())) ); assertEquals(1, result.size()); assertEquals(indexToRemove, result.get(0)); @@ -396,7 +397,7 @@ public TransformPersistentTasksExecutor buildTaskExecutor() { mock(ThreadPool.class), clusterService, Settings.EMPTY, - new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)) + new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())) ); } } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java index c15bd95c9a1e9..23e22e61ac0af 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.engine.InternalEngineFactory; +import org.elasticsearch.indices.SystemIndices; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.IndexSettingsModule; import org.elasticsearch.threadpool.ExecutorBuilder; @@ -22,6 +23,7 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import static java.util.Collections.emptyMap; import static org.hamcrest.Matchers.containsString; @@ -78,7 +80,8 @@ public void testWatcherDisabledTests() throws Exception { AnalysisRegistry registry = new AnalysisRegistry(TestEnvironment.newEnvironment(settings), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()); IndexModule indexModule = new IndexModule(indexSettings, registry, new InternalEngineFactory(), Collections.emptyMap(), - () -> true, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)), Collections.emptyMap()); + () -> true, new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY), new SystemIndices(Map.of())), + Collections.emptyMap()); // this will trip an assertion if the watcher indexing operation listener is null (which it is) but we try to add it watcher.onIndexModule(indexModule);