diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java index 0abcf793042a4..e8c25b2bfd0fc 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java @@ -10,7 +10,7 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.injection.guice.Inject; @@ -32,6 +32,7 @@ public class CCRUsageTransportAction extends XPackUsageFeatureTransportAction { private final Settings settings; private final XPackLicenseState licenseState; + private final ProjectResolver projectResolver; @Inject public CCRUsageTransportAction( @@ -40,11 +41,13 @@ public CCRUsageTransportAction( ThreadPool threadPool, ActionFilters actionFilters, Settings settings, - XPackLicenseState licenseState + XPackLicenseState licenseState, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.CCR.name(), transportService, clusterService, threadPool, actionFilters); this.settings = settings; this.licenseState = licenseState; + this.projectResolver = projectResolver; } @Override @@ -54,11 +57,11 @@ protected void localClusterStateOperation( ClusterState state, ActionListener listener ) { - Metadata metadata = state.metadata(); + final var project = projectResolver.getProjectMetadata(state); int numberOfFollowerIndices = 0; long lastFollowerIndexCreationDate = 0L; - for (IndexMetadata imd : metadata.getProject()) { + for (IndexMetadata imd : project) { if (imd.getCustomData("ccr") != null) { numberOfFollowerIndices++; if (lastFollowerIndexCreationDate < imd.getCreationDate()) { @@ -66,7 +69,7 @@ protected void localClusterStateOperation( } } } - AutoFollowMetadata autoFollowMetadata = metadata.getProject().custom(AutoFollowMetadata.TYPE); + AutoFollowMetadata autoFollowMetadata = project.custom(AutoFollowMetadata.TYPE); int numberOfAutoFollowPatterns = autoFollowMetadata != null ? autoFollowMetadata.getPatterns().size() : 0; Long lastFollowTimeInMillis; diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java index 5ca3b4ca01995..7a4dc1185227d 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java @@ -11,7 +11,8 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; +import org.elasticsearch.cluster.project.TestProjectResolvers; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.Maps; @@ -92,7 +93,8 @@ public void testName() { } public void testUsageStats() throws Exception { - Metadata.Builder metadata = Metadata.builder(); + final var projectId = randomProjectIdOrDefault(); + ProjectMetadata.Builder project = ProjectMetadata.builder(projectId); int numFollowerIndices = randomIntBetween(0, 32); for (int i = 0; i < numFollowerIndices; i++) { @@ -102,7 +104,7 @@ public void testUsageStats() throws Exception { .numberOfReplicas(0) .creationDate(i) .putCustom(Ccr.CCR_CUSTOM_METADATA_KEY, new HashMap<>()); - metadata.put(followerIndex); + project.put(followerIndex); } // Add a regular index, to check that we do not take that one into account: @@ -111,7 +113,7 @@ public void testUsageStats() throws Exception { .numberOfShards(1) .numberOfReplicas(0) .creationDate(numFollowerIndices); - metadata.put(regularIndex); + project.put(regularIndex); int numAutoFollowPatterns = randomIntBetween(0, 32); Map patterns = Maps.newMapWithExpectedSize(numAutoFollowPatterns); @@ -136,9 +138,9 @@ public void testUsageStats() throws Exception { ); patterns.put("pattern" + i, pattern); } - metadata.putCustom(AutoFollowMetadata.TYPE, new AutoFollowMetadata(patterns, Collections.emptyMap(), Collections.emptyMap())); + project.putCustom(AutoFollowMetadata.TYPE, new AutoFollowMetadata(patterns, Collections.emptyMap(), Collections.emptyMap())); - ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).metadata(metadata).build(); + ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).putProjectMetadata(project).build(); Mockito.when(clusterService.state()).thenReturn(clusterState); ThreadPool threadPool = mock(ThreadPool.class); @@ -149,7 +151,8 @@ public void testUsageStats() throws Exception { threadPool, mock(ActionFilters.class), Settings.EMPTY, - licenseState + licenseState, + TestProjectResolvers.singleProject(projectId) ); PlainActionFuture future = new PlainActionFuture<>(); usageAction.localClusterStateOperation(null, null, clusterState, future); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamLifecycleUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamLifecycleUsageTransportAction.java index 18f1028940d38..795b57501bdd6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamLifecycleUsageTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamLifecycleUsageTransportAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention; import org.elasticsearch.cluster.metadata.DataStreamGlobalRetentionSettings; import org.elasticsearch.cluster.metadata.DataStreamLifecycle; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.core.TimeValue; import org.elasticsearch.core.Tuple; @@ -32,6 +33,7 @@ public class DataStreamLifecycleUsageTransportAction extends XPackUsageFeatureTransportAction { private final DataStreamGlobalRetentionSettings globalRetentionSettings; + private final ProjectResolver projectResolver; @Inject public DataStreamLifecycleUsageTransportAction( @@ -39,10 +41,12 @@ public DataStreamLifecycleUsageTransportAction( ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, - DataStreamGlobalRetentionSettings globalRetentionSettings + DataStreamGlobalRetentionSettings globalRetentionSettings, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.DATA_STREAM_LIFECYCLE.name(), transportService, clusterService, threadPool, actionFilters); this.globalRetentionSettings = globalRetentionSettings; + this.projectResolver = projectResolver; } @Override @@ -52,7 +56,7 @@ protected void localClusterStateOperation( ClusterState state, ActionListener listener ) { - final Collection dataStreams = state.metadata().getProject().dataStreams().values(); + final Collection dataStreams = projectResolver.getProjectMetadata(state).dataStreams().values(); DataStreamLifecycleFeatureSetUsage.LifecycleStats lifecycleStats = calculateStats( dataStreams, clusterService.getClusterSettings().get(DataStreamLifecycle.CLUSTER_LIFECYCLE_DEFAULT_ROLLOVER_SETTING), diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamUsageTransportAction.java index edd3b071a97d9..8c1f5825e633c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamUsageTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/DataStreamUsageTransportAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.cluster.metadata.DataStreamGlobalRetention; import org.elasticsearch.cluster.metadata.DataStreamGlobalRetentionSettings; import org.elasticsearch.cluster.metadata.DataStreamLifecycle; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.core.TimeValue; import org.elasticsearch.core.Tuple; @@ -33,6 +34,7 @@ public class DataStreamUsageTransportAction extends XPackUsageFeatureTransportAc private final DataStreamFailureStoreSettings dataStreamFailureStoreSettings; private final DataStreamGlobalRetentionSettings globalRetentionSettings; + private final ProjectResolver projectResolver; @Inject public DataStreamUsageTransportAction( @@ -41,11 +43,13 @@ public DataStreamUsageTransportAction( ThreadPool threadPool, ActionFilters actionFilters, DataStreamFailureStoreSettings dataStreamFailureStoreSettings, - DataStreamGlobalRetentionSettings globalRetentionSettings + DataStreamGlobalRetentionSettings globalRetentionSettings, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.DATA_STREAMS.name(), transportService, clusterService, threadPool, actionFilters); this.dataStreamFailureStoreSettings = dataStreamFailureStoreSettings; this.globalRetentionSettings = globalRetentionSettings; + this.projectResolver = projectResolver; } @Override @@ -55,7 +59,7 @@ protected void localClusterStateOperation( ClusterState state, ActionListener listener ) { - final Map dataStreams = state.metadata().getProject().dataStreams(); + final Map dataStreams = projectResolver.getProjectMetadata(state).dataStreams(); long backingIndicesCounter = 0; long failureStoreExplicitlyEnabledCounter = 0; long failureStoreEffectivelyEnabledCounter = 0; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportAction.java index 11a468e5f3eaf..4b0fab8aeeac6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportAction.java @@ -13,9 +13,11 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.client.internal.ParentTaskAssigningClient; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ProjectState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.DataTier; @@ -43,6 +45,7 @@ public class DataTiersUsageTransportAction extends XPackUsageFeatureTransportAction { private final Client client; + private final ProjectResolver projectResolver; @Inject public DataTiersUsageTransportAction( @@ -50,10 +53,12 @@ public DataTiersUsageTransportAction( ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, - Client client + Client client, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.DATA_TIERS.name(), transportService, clusterService, threadPool, actionFilters); this.client = client; + this.projectResolver = projectResolver; } @Override @@ -69,11 +74,12 @@ protected void localClusterStateOperation( NodesDataTiersUsageTransportAction.TYPE, new NodesDataTiersUsageTransportAction.NodesRequest(), listener.delegateFailureAndWrap((delegate, response) -> { + final var projectState = projectResolver.getProjectState(state); // Generate tier specific stats for the nodes and indices delegate.onResponse( new XPackUsageFeatureResponse( new DataTiersFeatureSetUsage( - aggregateStats(response.getNodes(), getIndicesGroupedByTier(state, response.getNodes())) + aggregateStats(response.getNodes(), getIndicesGroupedByTier(projectState, response.getNodes())) ) ) ); @@ -82,16 +88,16 @@ protected void localClusterStateOperation( } // Visible for testing - static Map> getIndicesGroupedByTier(ClusterState state, List nodes) { + static Map> getIndicesGroupedByTier(ProjectState state, List nodes) { Set indices = nodes.stream() - .map(nodeResponse -> state.getRoutingNodes().node(nodeResponse.getNode().getId())) + .map(nodeResponse -> state.cluster().getRoutingNodes().node(nodeResponse.getNode().getId())) .filter(Objects::nonNull) .flatMap(node -> StreamSupport.stream(node.spliterator(), false)) .map(ShardRouting::getIndexName) .collect(Collectors.toSet()); Map> indicesByTierPreference = new HashMap<>(); for (String indexName : indices) { - IndexMetadata indexMetadata = state.metadata().getProject().index(indexName); + IndexMetadata indexMetadata = state.metadata().index(indexName); // If the index was deleted in the meantime, skip if (indexMetadata == null) { continue; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportActionTests.java index d324233f867cc..a9cf2ae1d97ca 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/datatiers/DataTiersUsageTransportActionTests.java @@ -10,7 +10,7 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -57,15 +57,14 @@ public void testTierIndices() { IndexMetadata nonTiered = indexMetadata("non-tier", 1, 0); // No tier IndexMetadata hotIndex3 = indexMetadata("hot-3", 1, 0, DataTier.DATA_HOT); - Metadata.Builder metadataBuilder = Metadata.builder() + ProjectMetadata.Builder projectBuilder = ProjectMetadata.builder(randomProjectIdOrDefault()) .put(hotIndex1, false) .put(hotIndex2, false) .put(warmIndex1, false) .put(coldIndex1, false) .put(coldIndex2, false) .put(nonTiered, false) - .put(hotIndex3, false) - .generateClusterUuidIfNeeded(); + .put(hotIndex3, false); RoutingTable.Builder routingTableBuilder = RoutingTable.builder(); routingTableBuilder.add(getIndexRoutingTable(hotIndex1, dataNode)); routingTableBuilder.add(getIndexRoutingTable(hotIndex2, dataNode)); @@ -76,11 +75,11 @@ public void testTierIndices() { routingTableBuilder.add(getIndexRoutingTable(nonTiered, dataNode)); ClusterState clusterState = ClusterState.builder(new ClusterName("test")) .nodes(discoBuilder) - .metadata(metadataBuilder) - .routingTable(routingTableBuilder.build()) + .putProjectMetadata(projectBuilder) + .putRoutingTable(projectBuilder.getId(), routingTableBuilder.build()) .build(); Map> result = DataTiersUsageTransportAction.getIndicesGroupedByTier( - clusterState, + clusterState.projectState(projectBuilder.getId()), List.of(new NodeDataTiersUsage(dataNode, Map.of(DataTier.DATA_WARM, createStats(5, 5, 0, 10)))) ); assertThat(result.keySet(), equalTo(Set.of(DataTier.DATA_HOT, DataTier.DATA_WARM, DataTier.DATA_COLD))); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java index 2caff49b603c6..773582d227bbd 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java @@ -10,7 +10,7 @@ import org.elasticsearch.action.admin.indices.rollover.RolloverConditions; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.core.Tuple; import org.elasticsearch.injection.guice.Inject; @@ -42,14 +42,18 @@ public class IndexLifecycleUsageTransportAction extends XPackUsageFeatureTransportAction { + private final ProjectResolver projectResolver; + @Inject public IndexLifecycleUsageTransportAction( TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters + ActionFilters actionFilters, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.INDEX_LIFECYCLE.name(), transportService, clusterService, threadPool, actionFilters); + this.projectResolver = projectResolver; } @Override @@ -59,12 +63,12 @@ protected void localClusterStateOperation( ClusterState state, ActionListener listener ) { - Metadata metadata = state.metadata(); - IndexLifecycleMetadata lifecycleMetadata = metadata.getProject().custom(IndexLifecycleMetadata.TYPE); + final var project = projectResolver.getProjectMetadata(state); + IndexLifecycleMetadata lifecycleMetadata = project.custom(IndexLifecycleMetadata.TYPE); final IndexLifecycleFeatureSetUsage usage; if (lifecycleMetadata != null) { Map policyUsage = new HashMap<>(); - metadata.getProject().indices().values().forEach(value -> { + project.indices().values().forEach(value -> { String policyName = value.getLifecyclePolicyName(); Integer indicesManaged = policyUsage.get(policyName); if (indicesManaged == null) { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java index f4f5b794a98cb..22a3862d33b88 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java @@ -12,7 +12,9 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.Metadata; +import org.elasticsearch.cluster.metadata.ProjectId; +import org.elasticsearch.cluster.metadata.ProjectMetadata; +import org.elasticsearch.cluster.project.TestProjectResolvers; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexVersion; @@ -87,12 +89,19 @@ public void testUsageStats() throws Exception { policies.add(policy3); PolicyStats policy3Stats = new PolicyStats(Map.of(), 1); - ClusterState clusterState = buildClusterState(policies, indexPolicies); + final var projectId = randomProjectIdOrDefault(); + ClusterState clusterState = buildClusterState(projectId, policies, indexPolicies); Mockito.when(clusterService.state()).thenReturn(clusterState); ThreadPool threadPool = mock(ThreadPool.class); TransportService transportService = MockUtils.setupTransportServiceWithThreadpoolExecutor(threadPool); - var usageAction = new IndexLifecycleUsageTransportAction(transportService, null, threadPool, mock(ActionFilters.class)); + var usageAction = new IndexLifecycleUsageTransportAction( + transportService, + null, + threadPool, + mock(ActionFilters.class), + TestProjectResolvers.singleProject(projectId) + ); PlainActionFuture future = new PlainActionFuture<>(); usageAction.localClusterStateOperation(null, null, clusterState, future); IndexLifecycleFeatureSetUsage ilmUsage = (IndexLifecycleFeatureSetUsage) future.get().getUsage(); @@ -107,19 +116,23 @@ public void testUsageStats() throws Exception { } - private ClusterState buildClusterState(List lifecyclePolicies, Map indexPolicies) { + private ClusterState buildClusterState( + ProjectId projectId, + List lifecyclePolicies, + Map indexPolicies + ) { Map lifecyclePolicyMetadatasMap = lifecyclePolicies.stream() .map(p -> new LifecyclePolicyMetadata(p, Map.of(), 1, 0L)) .collect(Collectors.toMap(LifecyclePolicyMetadata::getName, Function.identity())); IndexLifecycleMetadata indexLifecycleMetadata = new IndexLifecycleMetadata(lifecyclePolicyMetadatasMap, OperationMode.RUNNING); - Metadata.Builder metadata = Metadata.builder().putCustom(IndexLifecycleMetadata.TYPE, indexLifecycleMetadata); + ProjectMetadata.Builder project = ProjectMetadata.builder(projectId).putCustom(IndexLifecycleMetadata.TYPE, indexLifecycleMetadata); indexPolicies.forEach((indexName, policyName) -> { Settings indexSettings = indexSettings(IndexVersion.current(), 1, 0).put(LifecycleSettings.LIFECYCLE_NAME, policyName).build(); IndexMetadata.Builder indexMetadata = IndexMetadata.builder(indexName).settings(indexSettings); - metadata.put(indexMetadata); + project.put(indexMetadata); }); - return ClusterState.builder(new ClusterName("my_cluster")).metadata(metadata).build(); + return ClusterState.builder(new ClusterName("my_cluster")).putProjectMetadata(project).build(); } } diff --git a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java index abcaf5c39cbbd..b5f59a0b48b29 100644 --- a/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java +++ b/x-pack/plugin/logsdb/src/main/java/org/elasticsearch/xpack/logsdb/LogsDBUsageTransportAction.java @@ -12,6 +12,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexSettings; @@ -30,6 +31,7 @@ public class LogsDBUsageTransportAction extends XPackUsageFeatureTransportAction { private final ClusterService clusterService; private final Client client; + private final ProjectResolver projectResolver; @Inject public LogsDBUsageTransportAction( @@ -37,11 +39,13 @@ public LogsDBUsageTransportAction( ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, - Client client + Client client, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.LOGSDB.name(), transportService, clusterService, threadPool, actionFilters); this.clusterService = clusterService; this.client = client; + this.projectResolver = projectResolver; } @Override @@ -53,7 +57,7 @@ protected void localClusterStateOperation( ) { int numIndices = 0; int numIndicesWithSyntheticSources = 0; - for (IndexMetadata indexMetadata : state.metadata().getProject()) { + for (IndexMetadata indexMetadata : projectResolver.getProjectMetadata(state)) { if (indexMetadata.getIndexMode() == IndexMode.LOGSDB) { numIndices++; if (IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexMetadata.getSettings()) == SourceFieldMapper.Mode.SYNTHETIC) { diff --git a/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveUsageTransportAction.java b/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveUsageTransportAction.java index 09b4666f31ae3..478465e897bfb 100644 --- a/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveUsageTransportAction.java +++ b/x-pack/plugin/old-lucene-versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveUsageTransportAction.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.license.XPackLicenseState; @@ -28,6 +29,7 @@ public class ArchiveUsageTransportAction extends XPackUsageFeatureTransportAction { private final XPackLicenseState licenseState; + private final ProjectResolver projectResolver; @Inject public ArchiveUsageTransportAction( @@ -35,10 +37,12 @@ public ArchiveUsageTransportAction( ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, - XPackLicenseState licenseState + XPackLicenseState licenseState, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.ARCHIVE.name(), transportService, clusterService, threadPool, actionFilters); this.licenseState = licenseState; + this.projectResolver = projectResolver; } @Override @@ -49,7 +53,7 @@ protected void localClusterStateOperation( ActionListener listener ) { int numArchiveIndices = 0; - for (IndexMetadata indexMetadata : state.metadata().getProject()) { + for (IndexMetadata indexMetadata : projectResolver.getProjectMetadata(state)) { if (indexMetadata.getCreationVersion().isLegacyIndexVersion()) { numArchiveIndices++; } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupUsageTransportAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupUsageTransportAction.java index 9009af3eea9ab..dc7e7e4354c33 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupUsageTransportAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupUsageTransportAction.java @@ -9,6 +9,8 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.ProjectMetadata; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.core.Predicates; import org.elasticsearch.injection.guice.Inject; @@ -25,14 +27,18 @@ public class RollupUsageTransportAction extends XPackUsageFeatureTransportAction { + private final ProjectResolver projectResolver; + @Inject public RollupUsageTransportAction( TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters + ActionFilters actionFilters, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.ROLLUP.name(), transportService, clusterService, threadPool, actionFilters); + this.projectResolver = projectResolver; } @Override @@ -42,14 +48,14 @@ protected void localClusterStateOperation( ClusterState state, ActionListener listener ) { - int numberOfRollupJobs = findNumberOfRollupJobs(state); + int numberOfRollupJobs = findNumberOfRollupJobs(projectResolver.getProjectMetadata(state)); RollupFeatureSetUsage usage = new RollupFeatureSetUsage(numberOfRollupJobs); listener.onResponse(new XPackUsageFeatureResponse(usage)); } - static int findNumberOfRollupJobs(ClusterState state) { + static int findNumberOfRollupJobs(ProjectMetadata project) { int numberOfRollupJobs = 0; - PersistentTasksCustomMetadata persistentTasks = state.metadata().getProject().custom(PersistentTasksCustomMetadata.TYPE); + PersistentTasksCustomMetadata persistentTasks = project.custom(PersistentTasksCustomMetadata.TYPE); if (persistentTasks != null) { numberOfRollupJobs = persistentTasks.findTasks(RollupJob.NAME, Predicates.always()).size(); } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index 33df5bf8d60be..4880454bf81cb 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -113,7 +113,7 @@ protected void masterOperation( XPackPlugin.checkReadyForXPackCustomMetadata(clusterState); checkForDeprecatedTZ(request); - int numberOfCurrentRollupJobs = RollupUsageTransportAction.findNumberOfRollupJobs(clusterState); + int numberOfCurrentRollupJobs = RollupUsageTransportAction.findNumberOfRollupJobs(clusterState.metadata().getProject()); if (numberOfCurrentRollupJobs == 0) { try { boolean hasRollupIndices = hasRollupIndices(clusterState.getMetadata()); diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupInfoTransportActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupInfoTransportActionTests.java index a5e30cd3a8cb9..369b45c5d626d 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupInfoTransportActionTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupInfoTransportActionTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.project.TestProjectResolvers; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.MockUtils; @@ -41,7 +42,13 @@ public void testEnabledDefault() { public void testUsage() throws ExecutionException, InterruptedException, IOException { ThreadPool threadPool = mock(ThreadPool.class); TransportService transportService = MockUtils.setupTransportServiceWithThreadpoolExecutor(threadPool); - var usageAction = new RollupUsageTransportAction(transportService, null, threadPool, mock(ActionFilters.class)); + var usageAction = new RollupUsageTransportAction( + transportService, + null, + threadPool, + mock(ActionFilters.class), + TestProjectResolvers.DEFAULT_PROJECT_ONLY + ); PlainActionFuture future = new PlainActionFuture<>(); usageAction.localClusterStateOperation(null, null, ClusterState.EMPTY_STATE, future); RollupFeatureSetUsage rollupUsage = (RollupFeatureSetUsage) future.get().getUsage(); diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/SearchableSnapshotsUsageTransportAction.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/SearchableSnapshotsUsageTransportAction.java index f6aff0d549aae..e7f74ae2aa927 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/SearchableSnapshotsUsageTransportAction.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/xpack/searchablesnapshots/action/SearchableSnapshotsUsageTransportAction.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.license.XPackLicenseState; @@ -28,6 +29,7 @@ public class SearchableSnapshotsUsageTransportAction extends XPackUsageFeatureTransportAction { private final XPackLicenseState licenseState; + private final ProjectResolver projectResolver; @Inject public SearchableSnapshotsUsageTransportAction( @@ -35,10 +37,12 @@ public SearchableSnapshotsUsageTransportAction( ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, - XPackLicenseState licenseState + XPackLicenseState licenseState, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.SEARCHABLE_SNAPSHOTS.name(), transportService, clusterService, threadPool, actionFilters); this.licenseState = licenseState; + this.projectResolver = projectResolver; } @Override @@ -50,7 +54,7 @@ protected void localClusterStateOperation( ) { int numFullCopySnapIndices = 0; int numSharedCacheSnapIndices = 0; - for (IndexMetadata indexMetadata : state.metadata().getProject()) { + for (IndexMetadata indexMetadata : projectResolver.getProjectMetadata(state)) { if (indexMetadata.isSearchableSnapshot()) { if (indexMetadata.isPartialSearchableSnapshot()) { numSharedCacheSnapIndices++; diff --git a/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java b/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java index f0077776a03ea..7e1c6c7f174c8 100644 --- a/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java +++ b/x-pack/plugin/slm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.project.ProjectResolver; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.injection.guice.Inject; import org.elasticsearch.protocol.xpack.XPackUsageRequest; @@ -24,14 +25,18 @@ public class SLMUsageTransportAction extends XPackUsageFeatureTransportAction { + private final ProjectResolver projectResolver; + @Inject public SLMUsageTransportAction( TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters + ActionFilters actionFilters, + ProjectResolver projectResolver ) { super(XPackUsageFeatureAction.SNAPSHOT_LIFECYCLE.name(), transportService, clusterService, threadPool, actionFilters); + this.projectResolver = projectResolver; } @Override @@ -41,7 +46,7 @@ protected void localClusterStateOperation( ClusterState state, ActionListener listener ) { - final SnapshotLifecycleMetadata slmMeta = state.metadata().getProject().custom(SnapshotLifecycleMetadata.TYPE); + final SnapshotLifecycleMetadata slmMeta = projectResolver.getProjectMetadata(state).custom(SnapshotLifecycleMetadata.TYPE); final SLMFeatureSetUsage usage = new SLMFeatureSetUsage(slmMeta == null ? null : slmMeta.getStats()); listener.onResponse(new XPackUsageFeatureResponse(usage)); } diff --git a/x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle b/x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle index c41d8c3a196e2..9fb4d5ed6929d 100644 --- a/x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle +++ b/x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle @@ -30,14 +30,10 @@ tasks.named("yamlRestTest").configure { '^analytics/histogram/*', '^analytics/moving_percentiles/*', '^analytics/top_metrics/*', - '^analytics/usage/*', '^data_streams/10_data_stream_resolvability/*', '^deprecation/10_basic/*', - '^dlm/10_usage/*', - '^esql/60_usage/*', - '^health/10_usage/*', + '^health/10_usage/*', // The usage API is project-aware, this test just fails on the project-awareness of the SLM health indicator '^ilm/80_health/*', - '^logsdb/10_usage/*', '^migration/10_get_feature_upgrade_status/*', '^migration/20_post_feature_upgrade/*', '^ml/3rd_party_deployment/*', @@ -110,7 +106,7 @@ tasks.named("yamlRestTest").configure { '^rollup/rollup_search/*', '^rollup/start_job/*', '^rollup/stop_job/*', - '^searchable_snapshots/10_usage/*', + '^searchable_snapshots/10_usage/*', // The usage API is project-aware, so this test can be unmuted once snapshot repositories are project-aware '^searchable_snapshots/20_synthetic_source/*', '^security/authz/14_cat_indices/*', '^security/authz/14_cat_indices/Test explicit request while multiple opened/*', @@ -118,7 +114,6 @@ tasks.named("yamlRestTest").configure { '^security/settings/10_update_security_settings/*', '^snapshot/10_basic/*', '^snapshot/20_operator_privileges_disabled/*', - '^spatial/50_feature_usage/*', '^spatial/100_geo_grid_ingest/*', '^transform/preview_transforms/*', '^transform/transforms_cat_apis/*',