Browse Source

Make deprecation plugin project-aware (#130364)

Updates the majority of the plugin to be aware of multiple projects.

The deprecation plugin is excluded in serverless, so in
`DeprecationIndexingComponent` we hard-code the default project ID to
avoid an unworthy investment of namespacing effort.
Niels Bauman 3 tháng trước cách đây
mục cha
commit
2404dac592
14 tập tin đã thay đổi với 238 bổ sung362 xóa
  1. 3 12
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecker.java
  2. 16 18
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecker.java
  3. 7 7
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationChecker.java
  4. 17 17
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java
  5. 3 3
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ResourceDeprecationChecker.java
  6. 8 8
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java
  7. 37 38
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java
  8. 16 2
      x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingComponent.java
  9. 12 18
      x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationCheckerTests.java
  10. 25 47
      x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationCheckerTests.java
  11. 45 106
      x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java
  12. 32 45
      x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java
  13. 17 40
      x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java
  14. 0 1
      x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle

+ 3 - 12
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecker.java

@@ -9,8 +9,6 @@ package org.elasticsearch.xpack.deprecation;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
-import org.elasticsearch.cluster.ClusterState;
-import org.elasticsearch.common.TriConsumer;
 import org.elasticsearch.xcontent.NamedXContentRegistry;
 import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
 import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
@@ -25,26 +23,19 @@ import java.util.List;
 public class ClusterDeprecationChecker {
 
     private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecker.class);
-    private final List<TriConsumer<ClusterState, List<TransformConfig>, List<DeprecationIssue>>> CHECKS = List.of(
-        this::checkTransformSettings
-    );
     private final NamedXContentRegistry xContentRegistry;
 
     ClusterDeprecationChecker(NamedXContentRegistry xContentRegistry) {
         this.xContentRegistry = xContentRegistry;
     }
 
-    public List<DeprecationIssue> check(ClusterState clusterState, List<TransformConfig> transformConfigs) {
+    public List<DeprecationIssue> check(List<TransformConfig> transformConfigs) {
         List<DeprecationIssue> allIssues = new ArrayList<>();
-        CHECKS.forEach(check -> check.apply(clusterState, transformConfigs, allIssues));
+        checkTransformSettings(transformConfigs, allIssues);
         return allIssues;
     }
 
-    private void checkTransformSettings(
-        ClusterState clusterState,
-        List<TransformConfig> transformConfigs,
-        List<DeprecationIssue> allIssues
-    ) {
+    private void checkTransformSettings(List<TransformConfig> transformConfigs, List<DeprecationIssue> allIssues) {
         for (var config : transformConfigs) {
             try {
                 allIssues.addAll(config.checkForDeprecations(xContentRegistry));

+ 16 - 18
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecker.java

@@ -9,9 +9,9 @@ package org.elasticsearch.xpack.deprecation;
 
 import org.elasticsearch.Version;
 import org.elasticsearch.action.support.IndicesOptions;
-import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.metadata.DataStream;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.index.Index;
 import org.elasticsearch.xpack.core.deprecation.DeprecatedIndexPredicate;
 import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
@@ -33,7 +33,7 @@ import static java.util.Map.ofEntries;
 public class DataStreamDeprecationChecker implements ResourceDeprecationChecker {
 
     public static final String NAME = "data_streams";
-    private static final List<BiFunction<DataStream, ClusterState, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
+    private static final List<BiFunction<DataStream, ProjectMetadata, DeprecationIssue>> DATA_STREAM_CHECKS = List.of(
         DataStreamDeprecationChecker::oldIndicesCheck,
         DataStreamDeprecationChecker::ignoredOldIndicesCheck
     );
@@ -44,27 +44,27 @@ public class DataStreamDeprecationChecker implements ResourceDeprecationChecker
     }
 
     /**
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @param request not used yet in these checks
      * @param precomputedData not used yet in these checks
      * @return the name of the data streams that have violated the checks with their respective warnings.
      */
     @Override
     public Map<String, List<DeprecationIssue>> check(
-        ClusterState clusterState,
+        ProjectMetadata project,
         DeprecationInfoAction.Request request,
         TransportDeprecationInfoAction.PrecomputedData precomputedData
     ) {
-        return check(clusterState);
+        return check(project);
     }
 
     /**
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @return the name of the data streams that have violated the checks with their respective warnings.
      */
-    public Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
+    public Map<String, List<DeprecationIssue>> check(ProjectMetadata project) {
         List<String> dataStreamNames = indexNameExpressionResolver.dataStreamNames(
-            clusterState,
+            project,
             IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN
         );
         if (dataStreamNames.isEmpty()) {
@@ -72,10 +72,10 @@ public class DataStreamDeprecationChecker implements ResourceDeprecationChecker
         }
         Map<String, List<DeprecationIssue>> dataStreamIssues = new HashMap<>();
         for (String dataStreamName : dataStreamNames) {
-            DataStream dataStream = clusterState.metadata().getProject().dataStreams().get(dataStreamName);
+            DataStream dataStream = project.dataStreams().get(dataStreamName);
             if (dataStream.isSystem() == false) {
                 List<DeprecationIssue> issuesForSingleDataStream = DATA_STREAM_CHECKS.stream()
-                    .map(c -> c.apply(dataStream, clusterState))
+                    .map(c -> c.apply(dataStream, project))
                     .filter(Objects::nonNull)
                     .toList();
                 if (issuesForSingleDataStream.isEmpty() == false) {
@@ -86,10 +86,10 @@ public class DataStreamDeprecationChecker implements ResourceDeprecationChecker
         return dataStreamIssues.isEmpty() ? Map.of() : dataStreamIssues;
     }
 
-    static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
+    static DeprecationIssue oldIndicesCheck(DataStream dataStream, ProjectMetadata project) {
         List<Index> backingIndices = dataStream.getIndices();
 
-        Set<String> indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, clusterState, false);
+        Set<String> indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, project, false);
 
         if (indicesNeedingUpgrade.isEmpty() == false) {
             return new DeprecationIssue(
@@ -110,9 +110,9 @@ public class DataStreamDeprecationChecker implements ResourceDeprecationChecker
         return null;
     }
 
-    static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterState clusterState) {
+    static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ProjectMetadata project) {
         List<Index> backingIndices = dataStream.getIndices();
-        Set<String> ignoredIndices = getReindexRequiredIndices(backingIndices, clusterState, true);
+        Set<String> ignoredIndices = getReindexRequiredIndices(backingIndices, project, true);
         if (ignoredIndices.isEmpty() == false) {
             return new DeprecationIssue(
                 DeprecationIssue.Level.WARNING,
@@ -135,13 +135,11 @@ public class DataStreamDeprecationChecker implements ResourceDeprecationChecker
 
     private static Set<String> getReindexRequiredIndices(
         List<Index> backingIndices,
-        ClusterState clusterState,
+        ProjectMetadata project,
         boolean filterToBlockedStatus
     ) {
         return backingIndices.stream()
-            .filter(
-                DeprecatedIndexPredicate.getReindexRequiredPredicate(clusterState.metadata().getProject(), filterToBlockedStatus, false)
-            )
+            .filter(DeprecatedIndexPredicate.getReindexRequiredPredicate(project, filterToBlockedStatus, false))
             .map(Index::getName)
             .collect(Collectors.toUnmodifiableSet());
     }

+ 7 - 7
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationChecker.java

@@ -7,7 +7,7 @@
 
 package org.elasticsearch.xpack.deprecation;
 
-import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
 import org.elasticsearch.xpack.core.ilm.AllocateAction;
 import org.elasticsearch.xpack.core.ilm.FreezeAction;
@@ -36,26 +36,26 @@ public class IlmPolicyDeprecationChecker implements ResourceDeprecationChecker {
     private final List<Function<LifecyclePolicy, DeprecationIssue>> checks = List.of(this::checkLegacyTiers, this::checkFrozenAction);
 
     /**
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @param request not used yet in these checks
      * @param precomputedData not used yet in these checks
      * @return the name of the data streams that have violated the checks with their respective warnings.
      */
     @Override
     public Map<String, List<DeprecationIssue>> check(
-        ClusterState clusterState,
+        ProjectMetadata project,
         DeprecationInfoAction.Request request,
         TransportDeprecationInfoAction.PrecomputedData precomputedData
     ) {
-        return check(clusterState);
+        return check(project);
     }
 
     /**
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @return the name of the data streams that have violated the checks with their respective warnings.
      */
-    Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
-        IndexLifecycleMetadata lifecycleMetadata = clusterState.metadata().getProject().custom(IndexLifecycleMetadata.TYPE);
+    Map<String, List<DeprecationIssue>> check(ProjectMetadata project) {
+        IndexLifecycleMetadata lifecycleMetadata = project.custom(IndexLifecycleMetadata.TYPE);
         if (lifecycleMetadata == null || lifecycleMetadata.getPolicyMetadatas().isEmpty()) {
             return Map.of();
         }

+ 17 - 17
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java

@@ -7,10 +7,10 @@
 package org.elasticsearch.xpack.deprecation;
 
 import org.elasticsearch.Version;
-import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
 import org.elasticsearch.cluster.metadata.MappingMetadata;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.common.TriFunction;
 import org.elasticsearch.common.time.DateFormatter;
 import org.elasticsearch.common.time.LegacyFormatNames;
@@ -44,7 +44,7 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
     public static final String NAME = "index_settings";
 
     private final IndexNameExpressionResolver indexNameExpressionResolver;
-    private final List<TriFunction<IndexMetadata, ClusterState, Map<String, List<String>>, DeprecationIssue>> checks = List.of(
+    private final List<TriFunction<IndexMetadata, ProjectMetadata, Map<String, List<String>>, DeprecationIssue>> checks = List.of(
         this::oldIndicesCheck,
         this::ignoredOldIndicesCheck,
         this::translogRetentionSettingCheck,
@@ -60,17 +60,17 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
 
     @Override
     public Map<String, List<DeprecationIssue>> check(
-        ClusterState clusterState,
+        ProjectMetadata project,
         DeprecationInfoAction.Request request,
         TransportDeprecationInfoAction.PrecomputedData precomputedData
     ) {
         Map<String, List<DeprecationIssue>> indexSettingsIssues = new HashMap<>();
-        String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
+        String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(project, request);
         Map<String, List<String>> indexToTransformIds = indexToTransformIds(precomputedData.transformConfigs());
         for (String concreteIndex : concreteIndexNames) {
-            IndexMetadata indexMetadata = clusterState.getMetadata().getProject().index(concreteIndex);
+            IndexMetadata indexMetadata = project.index(concreteIndex);
             List<DeprecationIssue> singleIndexIssues = checks.stream()
-                .map(c -> c.apply(indexMetadata, clusterState, indexToTransformIds))
+                .map(c -> c.apply(indexMetadata, project, indexToTransformIds))
                 .filter(Objects::nonNull)
                 .toList();
             if (singleIndexIssues.isEmpty() == false) {
@@ -90,13 +90,13 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
 
     private DeprecationIssue oldIndicesCheck(
         IndexMetadata indexMetadata,
-        ClusterState clusterState,
+        ProjectMetadata project,
         Map<String, List<String>> indexToTransformIds
     ) {
         // TODO: this check needs to be revised. It's trivially true right now.
         IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
         // We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
-        if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false, false) && isNotDataStreamIndex(indexMetadata, clusterState)) {
+        if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, false, false) && isNotDataStreamIndex(indexMetadata, project)) {
             var transforms = transformIdsForIndex(indexMetadata, indexToTransformIds);
             if (transforms.isEmpty() == false) {
                 return new DeprecationIssue(
@@ -134,12 +134,12 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
 
     private DeprecationIssue ignoredOldIndicesCheck(
         IndexMetadata indexMetadata,
-        ClusterState clusterState,
+        ProjectMetadata project,
         Map<String, List<String>> indexToTransformIds
     ) {
         IndexVersion currentCompatibilityVersion = indexMetadata.getCompatibilityVersion();
         // We intentionally exclude indices that are in data streams because they will be picked up by DataStreamDeprecationChecks
-        if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true, false) && isNotDataStreamIndex(indexMetadata, clusterState)) {
+        if (DeprecatedIndexPredicate.reindexRequired(indexMetadata, true, false) && isNotDataStreamIndex(indexMetadata, project)) {
             var transforms = transformIdsForIndex(indexMetadata, indexToTransformIds);
             if (transforms.isEmpty() == false) {
                 return new DeprecationIssue(
@@ -175,13 +175,13 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
         return null;
     }
 
-    private boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
-        return clusterState.metadata().getProject().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
+    private boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ProjectMetadata project) {
+        return project.findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
     }
 
     private DeprecationIssue translogRetentionSettingCheck(
         IndexMetadata indexMetadata,
-        ClusterState clusterState,
+        ProjectMetadata project,
         Map<String, List<String>> ignored
     ) {
         final boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexMetadata.getSettings());
@@ -210,7 +210,7 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
         return null;
     }
 
-    private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterState clusterState, Map<String, List<String>> ignored) {
+    private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ProjectMetadata project, Map<String, List<String>> ignored) {
         if (IndexMetadata.INDEX_DATA_PATH_SETTING.exists(indexMetadata.getSettings())) {
             final String message = String.format(
                 Locale.ROOT,
@@ -226,7 +226,7 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
 
     private DeprecationIssue storeTypeSettingCheck(
         IndexMetadata indexMetadata,
-        ClusterState clusterState,
+        ProjectMetadata project,
         Map<String, List<String>> ignored
     ) {
         final String storeType = IndexModule.INDEX_STORE_TYPE_SETTING.get(indexMetadata.getSettings());
@@ -247,7 +247,7 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
 
     private DeprecationIssue legacyRoutingSettingCheck(
         IndexMetadata indexMetadata,
-        ClusterState clusterState,
+        ProjectMetadata project,
         Map<String, List<String>> ignored
     ) {
         List<String> deprecatedSettings = LegacyTiersDetection.getDeprecatedFilteredAllocationSettings(indexMetadata.getSettings());
@@ -339,7 +339,7 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
 
     private DeprecationIssue deprecatedCamelCasePattern(
         IndexMetadata indexMetadata,
-        ClusterState clusterState,
+        ProjectMetadata project,
         Map<String, List<String>> ignored
     ) {
         List<String> fields = new ArrayList<>();

+ 3 - 3
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ResourceDeprecationChecker.java

@@ -7,7 +7,7 @@
 
 package org.elasticsearch.xpack.deprecation;
 
-import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
 
 import java.util.List;
@@ -23,12 +23,12 @@ public interface ResourceDeprecationChecker {
     /**
      * This runs the checks for the current deprecation checker.
      *
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @param request The deprecation request that triggered this check
      * @param precomputedData Data that have been remotely retrieved and might be useful in the checks
      */
     Map<String, List<DeprecationIssue>> check(
-        ClusterState clusterState,
+        ProjectMetadata project,
         DeprecationInfoAction.Request request,
         TransportDeprecationInfoAction.PrecomputedData precomputedData
     );

+ 8 - 8
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java

@@ -7,9 +7,9 @@
 
 package org.elasticsearch.xpack.deprecation;
 
-import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.metadata.ComponentTemplate;
 import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.cluster.metadata.Template;
 import org.elasticsearch.common.xcontent.XContentHelper;
 import org.elasticsearch.index.mapper.SourceFieldMapper;
@@ -41,27 +41,27 @@ public class TemplateDeprecationChecker implements ResourceDeprecationChecker {
     );
 
     /**
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @param request not used yet in these checks
      * @param precomputedData not used yet in these checks
      * @return the name of the data streams that have violated the checks with their respective warnings.
      */
     @Override
     public Map<String, List<DeprecationIssue>> check(
-        ClusterState clusterState,
+        ProjectMetadata project,
         DeprecationInfoAction.Request request,
         TransportDeprecationInfoAction.PrecomputedData precomputedData
     ) {
-        return check(clusterState);
+        return check(project);
     }
 
     /**
-     * @param clusterState The cluster state provided for the checker
+     * @param project The project metadata provided for the checker
      * @return the name of the data streams that have violated the checks with their respective warnings.
      */
-    Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
-        var indexTemplates = clusterState.metadata().getProject().templatesV2().entrySet();
-        var componentTemplates = clusterState.metadata().getProject().componentTemplates().entrySet();
+    Map<String, List<DeprecationIssue>> check(ProjectMetadata project) {
+        var indexTemplates = project.templatesV2().entrySet();
+        var componentTemplates = project.componentTemplates().entrySet();
         if (indexTemplates.isEmpty() && componentTemplates.isEmpty()) {
             return Map.of();
         }

+ 37 - 38
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java

@@ -23,7 +23,9 @@ import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
 import org.elasticsearch.cluster.metadata.Metadata;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.cluster.metadata.Template;
+import org.elasticsearch.cluster.project.ProjectResolver;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.regex.Regex;
 import org.elasticsearch.common.settings.Setting;
@@ -66,6 +68,7 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
     private final NodeDeprecationChecker nodeDeprecationChecker;
     private final ClusterDeprecationChecker clusterDeprecationChecker;
     private final List<ResourceDeprecationChecker> resourceDeprecationCheckers;
+    private final ProjectResolver projectResolver;
 
     @Inject
     public TransportDeprecationInfoAction(
@@ -76,7 +79,8 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
         ActionFilters actionFilters,
         IndexNameExpressionResolver indexNameExpressionResolver,
         NodeClient client,
-        NamedXContentRegistry xContentRegistry
+        NamedXContentRegistry xContentRegistry,
+        ProjectResolver projectResolver
     ) {
         super(
             DeprecationInfoAction.NAME,
@@ -101,6 +105,7 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
             new TemplateDeprecationChecker(),
             new IlmPolicyDeprecationChecker()
         );
+        this.projectResolver = projectResolver;
         // Safe to register this here because it happens synchronously before the cluster service is started:
         clusterService.getClusterSettings().addSettingsUpdateConsumer(SKIP_DEPRECATIONS_SETTING, this::setSkipDeprecations);
     }
@@ -123,7 +128,8 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
         final ActionListener<DeprecationInfoAction.Response> listener
     ) {
         PrecomputedData precomputedData = new PrecomputedData();
-        try (var refs = new RefCountingListener(checkAndCreateResponse(state, request, precomputedData, listener))) {
+        final var project = projectResolver.getProjectMetadata(state);
+        try (var refs = new RefCountingListener(checkAndCreateResponse(project, request, precomputedData, listener))) {
             nodeDeprecationChecker.check(client, refs.acquire(precomputedData::setOnceNodeSettingsIssues));
             transformConfigs(refs.acquire(precomputedData::setOnceTransformConfigs));
             DeprecationChecker.Components components = new DeprecationChecker.Components(
@@ -142,7 +148,7 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
      * cluster. Because of that, it's important that it does not run in the transport thread that's why it's combined with
      * {@link #executeInGenericThreadpool(ActionListener)}.
      *
-     * @param state                       The cluster state
+     * @param project                     The project metadata
      * @param request                     The originating request containing the index expressions to evaluate
      * @param precomputedData             Data from remote requests necessary to construct the response
      * @param responseListener            The listener expecting the {@link DeprecationInfoAction.Response}
@@ -150,7 +156,7 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
      * is initialised.
      */
     public ActionListener<Void> checkAndCreateResponse(
-        ClusterState state,
+        ProjectMetadata project,
         DeprecationInfoAction.Request request,
         PrecomputedData precomputedData,
         ActionListener<DeprecationInfoAction.Response> responseListener
@@ -159,7 +165,7 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
             ActionListener.running(
                 () -> responseListener.onResponse(
                     checkAndCreateResponse(
-                        state,
+                        project,
                         indexNameExpressionResolver,
                         request,
                         skipTheseDeprecations,
@@ -173,26 +179,26 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
     }
 
     /**
-     * This is the function that does the bulk of the logic of combining the necessary dependencies together, including the cluster state,
+     * This is the function that does the bulk of the logic of combining the necessary dependencies together, including the cluster project,
      * the precalculated information in {@code context} with the remaining checkers such as the cluster setting checker and the resource
      * checkers.This function will run a significant part of the checks and build out the final list of issues that exist in the
      * cluster. It's important that it does not run in the transport thread that's why it's combined with
-     * {@link #checkAndCreateResponse(ClusterState, DeprecationInfoAction.Request, PrecomputedData, ActionListener)}. We keep this separated
-     * for testing purposes.
+     * {@link #checkAndCreateResponse(ProjectMetadata, DeprecationInfoAction.Request, PrecomputedData, ActionListener)}.
+     * We keep this separated for testing purposes.
      *
-     * @param state                       The cluster state
+     * @param project                       The cluster project
      * @param indexNameExpressionResolver Used to resolve indices into their concrete names
      * @param request                     The originating request containing the index expressions to evaluate
      * @param skipTheseDeprecatedSettings the settings that will be removed from cluster metadata and the index metadata of all the
      *                                    indexes specified by indexNames
      * @param clusterDeprecationChecker   The checker that provides the cluster settings deprecations warnings
-     * @param resourceDeprecationCheckers these are checkers that take as input the cluster state and return a map from resource type
+     * @param resourceDeprecationCheckers these are checkers that take as input the cluster project and return a map from resource type
      *                                    to issues grouped by the resource name.
      * @param precomputedData             data from remote requests necessary to construct the response
      * @return The list of deprecation issues found in the cluster
      */
     static DeprecationInfoAction.Response checkAndCreateResponse(
-        ClusterState state,
+        ProjectMetadata project,
         IndexNameExpressionResolver indexNameExpressionResolver,
         DeprecationInfoAction.Request request,
         List<String> skipTheseDeprecatedSettings,
@@ -202,17 +208,14 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
     ) {
         assert Transports.assertNotTransportThread("walking mappings in indexSettingsChecks is expensive");
         // Allow system index access here to prevent deprecation warnings when we call this API
-        String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(state, request);
-        ClusterState stateWithSkippedSettingsRemoved = removeSkippedSettings(state, concreteIndexNames, skipTheseDeprecatedSettings);
-        List<DeprecationIssue> clusterSettingsIssues = clusterDeprecationChecker.check(
-            stateWithSkippedSettingsRemoved,
-            precomputedData.transformConfigs()
-        );
+        String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(project, request);
+        ProjectMetadata projectWithSkippedSettingsRemoved = removeSkippedSettings(project, concreteIndexNames, skipTheseDeprecatedSettings);
+        List<DeprecationIssue> clusterSettingsIssues = clusterDeprecationChecker.check(precomputedData.transformConfigs());
 
         Map<String, Map<String, List<DeprecationIssue>>> resourceDeprecationIssues = new HashMap<>();
         for (ResourceDeprecationChecker resourceDeprecationChecker : resourceDeprecationCheckers) {
             Map<String, List<DeprecationIssue>> issues = resourceDeprecationChecker.check(
-                stateWithSkippedSettingsRemoved,
+                projectWithSkippedSettingsRemoved,
                 request,
                 precomputedData
             );
@@ -266,35 +269,32 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
 
     /**
      * Removes the skipped settings from the selected indices and the component and index templates.
-     * @param state The cluster state to modify
+     * @param project The project to modify
      * @param indexNames The names of the indexes whose settings need to be filtered
      * @param skipTheseDeprecatedSettings The settings that will be removed from cluster metadata and the index metadata of all the
      *                                    indexes specified by indexNames
-     * @return A modified cluster state with the given settings removed
+     * @return A modified project with the given settings removed
      */
-    private static ClusterState removeSkippedSettings(ClusterState state, String[] indexNames, List<String> skipTheseDeprecatedSettings) {
-        // Short-circuit, no need to reconstruct the cluster state if there are no settings to remove
+    private static ProjectMetadata removeSkippedSettings(
+        ProjectMetadata project,
+        String[] indexNames,
+        List<String> skipTheseDeprecatedSettings
+    ) {
+        // Short-circuit, no need to reconstruct the cluster project if there are no settings to remove
         if (skipTheseDeprecatedSettings == null || skipTheseDeprecatedSettings.isEmpty()) {
-            return state;
+            return project;
         }
-        ClusterState.Builder clusterStateBuilder = new ClusterState.Builder(state);
-        Metadata.Builder metadataBuilder = Metadata.builder(state.metadata());
-        metadataBuilder.transientSettings(
-            metadataBuilder.transientSettings().filter(setting -> Regex.simpleMatch(skipTheseDeprecatedSettings, setting) == false)
-        );
-        metadataBuilder.persistentSettings(
-            metadataBuilder.persistentSettings().filter(setting -> Regex.simpleMatch(skipTheseDeprecatedSettings, setting) == false)
-        );
-        Map<String, IndexMetadata> indicesBuilder = new HashMap<>(state.getMetadata().getProject().indices());
+        ProjectMetadata.Builder projectBuilder = ProjectMetadata.builder(project);
+        Map<String, IndexMetadata> indicesBuilder = new HashMap<>(project.indices());
         for (String indexName : indexNames) {
-            IndexMetadata indexMetadata = state.getMetadata().getProject().index(indexName);
+            IndexMetadata indexMetadata = project.index(indexName);
             IndexMetadata.Builder filteredIndexMetadataBuilder = new IndexMetadata.Builder(indexMetadata);
             Settings filteredSettings = indexMetadata.getSettings()
                 .filter(setting -> Regex.simpleMatch(skipTheseDeprecatedSettings, setting) == false);
             filteredIndexMetadataBuilder.settings(filteredSettings);
             indicesBuilder.put(indexName, filteredIndexMetadataBuilder.build());
         }
-        metadataBuilder.componentTemplates(state.metadata().getProject().componentTemplates().entrySet().stream().map(entry -> {
+        projectBuilder.componentTemplates(project.componentTemplates().entrySet().stream().map(entry -> {
             String templateName = entry.getKey();
             ComponentTemplate componentTemplate = entry.getValue();
             Template template = componentTemplate.template();
@@ -313,7 +313,7 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
                 )
             );
         }).collect(Collectors.toMap(Tuple::v1, Tuple::v2)));
-        metadataBuilder.indexTemplates(state.metadata().getProject().templatesV2().entrySet().stream().map(entry -> {
+        projectBuilder.indexTemplates(project.templatesV2().entrySet().stream().map(entry -> {
             String templateName = entry.getKey();
             ComposableIndexTemplate indexTemplate = entry.getValue();
             Template template = indexTemplate.template();
@@ -335,9 +335,8 @@ public class TransportDeprecationInfoAction extends TransportMasterNodeReadActio
             );
         }).collect(Collectors.toMap(Tuple::v1, Tuple::v2)));
 
-        metadataBuilder.indices(indicesBuilder);
-        clusterStateBuilder.metadata(metadataBuilder);
-        return clusterStateBuilder.build();
+        projectBuilder.indices(indicesBuilder);
+        return projectBuilder.build();
     }
 
     static void pluginSettingIssues(

+ 16 - 2
x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingComponent.java

@@ -21,7 +21,10 @@ import org.elasticsearch.action.index.IndexRequest;
 import org.elasticsearch.client.internal.Client;
 import org.elasticsearch.client.internal.OriginSettingClient;
 import org.elasticsearch.cluster.ClusterChangedEvent;
+import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.ClusterStateListener;
+import org.elasticsearch.cluster.metadata.ProjectId;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.component.AbstractLifecycleComponent;
 import org.elasticsearch.common.logging.ECSJsonLayout;
@@ -29,6 +32,7 @@ import org.elasticsearch.common.logging.Loggers;
 import org.elasticsearch.common.logging.RateLimitingFilter;
 import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.core.NotMultiProjectCapable;
 import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.xpack.core.ClientHelper;
 import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata;
@@ -135,9 +139,10 @@ public class DeprecationIndexingComponent extends AbstractLifecycleComponent imp
         if (event.metadataChanged() == false) {
             return;
         }
-        final IndexLifecycleMetadata indexLifecycleMetadata = event.state().metadata().getProject().custom(IndexLifecycleMetadata.TYPE);
+        final var project = getDefaultDeprecationProject(event.state());
+        final IndexLifecycleMetadata indexLifecycleMetadata = project.custom(IndexLifecycleMetadata.TYPE);
 
-        if (event.state().getMetadata().getProject().templatesV2().containsKey(".deprecation-indexing-template-9")
+        if (project.templatesV2().containsKey(".deprecation-indexing-template-9")
             && indexLifecycleMetadata != null
             && indexLifecycleMetadata.getPolicies().containsKey(".deprecation-indexing-ilm-policy")) {
             flushEnabled.set(true);
@@ -147,6 +152,15 @@ public class DeprecationIndexingComponent extends AbstractLifecycleComponent imp
         }
     }
 
+    /**
+     * This method solely exists because we are not making the deprecation plugin properly project-aware and it's not worth the investment
+     * of altering this feature to be project-aware.
+     */
+    @NotMultiProjectCapable
+    private static ProjectMetadata getDefaultDeprecationProject(ClusterState state) {
+        return state.metadata().getProject(ProjectId.DEFAULT);
+    }
+
     /**
      * This method removes everything that is currently in the pendingRequestsBuffer and sends it to the client. This method is
      * threadsafe. Anything added to the pendingRequestsBuffer while this method is executing might be removed and sent to the client,

+ 12 - 18
x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationCheckerTests.java

@@ -8,13 +8,11 @@
 package org.elasticsearch.xpack.deprecation;
 
 import org.elasticsearch.Version;
-import org.elasticsearch.cluster.ClusterName;
-import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.metadata.DataStream;
 import org.elasticsearch.cluster.metadata.DataStreamOptions;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
-import org.elasticsearch.cluster.metadata.Metadata;
 import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.index.Index;
 import org.elasticsearch.index.IndexMode;
@@ -49,11 +47,10 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
 
         DataStream dataStream = createTestDataStream(oldIndexCount, 0, newIndexCount, 0, nameToIndexMetadata, expectedIndices);
 
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .indices(nameToIndexMetadata)
             .dataStreams(Map.of(dataStream.getName(), dataStream), Map.of())
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
 
         DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.CRITICAL,
@@ -70,7 +67,7 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
         );
 
         // We know that the data stream checks ignore the request.
-        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(project);
         assertThat(issuesByDataStream.size(), equalTo(1));
         assertThat(issuesByDataStream.containsKey(dataStream.getName()), equalTo(true));
         assertThat(issuesByDataStream.get(dataStream.getName()), equalTo(List.of(expected)));
@@ -86,13 +83,12 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
 
         DataStream dataStream = createTestDataStream(0, 0, newOpenIndexCount, newClosedIndexCount, nameToIndexMetadata, expectedIndices);
 
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .indices(nameToIndexMetadata)
             .dataStreams(Map.of(dataStream.getName(), dataStream), Map.of())
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
 
-        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(project);
         assertThat(issuesByDataStream.size(), equalTo(0));
     }
 
@@ -118,11 +114,10 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
             expectedIndices
         );
 
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .indices(nameToIndexMetadata)
             .dataStreams(Map.of(dataStream.getName(), dataStream), Map.of())
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
 
         DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.CRITICAL,
@@ -138,7 +133,7 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
             )
         );
 
-        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(project);
         assertThat(issuesByDataStream.containsKey(dataStream.getName()), equalTo(true));
         assertThat(issuesByDataStream.get(dataStream.getName()), equalTo(List.of(expected)));
     }
@@ -277,11 +272,10 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
             null
         );
 
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .indices(nameToIndexMetadata)
             .dataStreams(Map.of(dataStream.getName(), dataStream), Map.of())
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
 
         DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
@@ -299,7 +293,7 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
             )
         );
 
-        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByDataStream = checker.check(project);
         assertThat(issuesByDataStream.containsKey(dataStream.getName()), equalTo(true));
         assertThat(issuesByDataStream.get(dataStream.getName()), equalTo(List.of(expected)));
     }
@@ -344,12 +338,12 @@ public class DataStreamDeprecationCheckerTests extends ESTestCase {
             randomBoolean(),
             null
         );
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .indices(nameToIndexMetadata)
             .dataStreams(Map.of(dataStream.getName(), dataStream), Map.of())
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
-        assertThat(checker.check(clusterState), equalTo(Map.of()));
+
+        assertThat(checker.check(project), equalTo(Map.of()));
     }
 
 }

+ 25 - 47
x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationCheckerTests.java

@@ -7,8 +7,7 @@
 
 package org.elasticsearch.xpack.deprecation;
 
-import org.elasticsearch.cluster.ClusterState;
-import org.elasticsearch.cluster.metadata.Metadata;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.core.TimeValue;
 import org.elasticsearch.test.ESTestCase;
 import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
@@ -62,35 +61,22 @@ public class IlmPolicyDeprecationCheckerTests extends ESTestCase {
             randomOptionalBoolean()
         );
 
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .putCustom(
-                        IndexLifecycleMetadata.TYPE,
-                        new IndexLifecycleMetadata(
-                            Map.of(
-                                "deprecated-tiers",
-                                new LifecyclePolicyMetadata(
-                                    deprecatedTiersPolicy,
-                                    Map.of(),
-                                    randomNonNegativeLong(),
-                                    randomNonNegativeLong()
-                                ),
-                                "other-attribute",
-                                new LifecyclePolicyMetadata(
-                                    otherAttributePolicy,
-                                    Map.of(),
-                                    randomNonNegativeLong(),
-                                    randomNonNegativeLong()
-                                )
-                            ),
-                            OperationMode.RUNNING
-                        )
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .putCustom(
+                IndexLifecycleMetadata.TYPE,
+                new IndexLifecycleMetadata(
+                    Map.of(
+                        "deprecated-tiers",
+                        new LifecyclePolicyMetadata(deprecatedTiersPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong()),
+                        "other-attribute",
+                        new LifecyclePolicyMetadata(otherAttributePolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
+                    ),
+                    OperationMode.RUNNING
+                )
             )
             .build();
 
-        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(project);
         final DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "Configuring tiers via filtered allocation is not recommended.",
@@ -115,28 +101,20 @@ public class IlmPolicyDeprecationCheckerTests extends ESTestCase {
             randomOptionalBoolean()
         );
 
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .putCustom(
-                        IndexLifecycleMetadata.TYPE,
-                        new IndexLifecycleMetadata(
-                            Map.of(
-                                "deprecated-action",
-                                new LifecyclePolicyMetadata(
-                                    deprecatedTiersPolicy,
-                                    Map.of(),
-                                    randomNonNegativeLong(),
-                                    randomNonNegativeLong()
-                                )
-                            ),
-                            OperationMode.RUNNING
-                        )
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .putCustom(
+                IndexLifecycleMetadata.TYPE,
+                new IndexLifecycleMetadata(
+                    Map.of(
+                        "deprecated-action",
+                        new LifecyclePolicyMetadata(deprecatedTiersPolicy, Map.of(), randomNonNegativeLong(), randomNonNegativeLong())
+                    ),
+                    OperationMode.RUNNING
+                )
             )
             .build();
 
-        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(project);
         final DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "ILM policy [deprecated-action] contains the action 'freeze' that is deprecated and will be removed in a future version.",

+ 45 - 106
x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java

@@ -11,15 +11,13 @@ import com.carrotsearch.randomizedtesting.annotations.Name;
 import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
 
 import org.elasticsearch.Version;
-import org.elasticsearch.cluster.ClusterState;
-import org.elasticsearch.cluster.block.ClusterBlocks;
 import org.elasticsearch.cluster.metadata.DataStream;
 import org.elasticsearch.cluster.metadata.DataStreamMetadata;
 import org.elasticsearch.cluster.metadata.DataStreamOptions;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
-import org.elasticsearch.cluster.metadata.Metadata;
 import org.elasticsearch.cluster.metadata.MetadataIndexStateService;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.common.collect.ImmutableOpenMap;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.core.TimeValue;
@@ -73,10 +71,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.CRITICAL,
             "Old index with a compatibility version < " + Version.CURRENT.major + ".0",
@@ -86,7 +81,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             singletonMap("reindex_required", true)
         );
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -97,10 +92,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
     public void testOldTransformIndicesCheck() {
         var checker = new IndexDeprecationChecker(indexNameExpressionResolver);
         var indexMetadata = indexMetadata("test", OLD_VERSION);
-        var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         var expected = new DeprecationIssue(
             DeprecationIssue.Level.CRITICAL,
             "One or more Transforms write to this index with a compatibility version < " + Version.CURRENT.major + ".0",
@@ -116,7 +108,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             Map.of("reindex_required", true, "transform_ids", List.of("test-transform"))
         );
         var issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             createContextWithTransformConfigs(Map.of("test", List.of("test-transform")))
         );
@@ -125,10 +117,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
 
     public void testOldIndicesCheckWithMultipleTransforms() {
         var indexMetadata = indexMetadata("test", OLD_VERSION);
-        var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         var expected = new DeprecationIssue(
             DeprecationIssue.Level.CRITICAL,
             "One or more Transforms write to this index with a compatibility version < " + Version.CURRENT.major + ".0",
@@ -144,7 +133,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             Map.of("reindex_required", true, "transform_ids", List.of("test-transform1", "test-transform2"))
         );
         var issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             createContextWithTransformConfigs(Map.of("test", List.of("test-transform1", "test-transform2")))
         );
@@ -154,9 +143,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
     public void testMultipleOldIndicesCheckWithTransforms() {
         var indexMetadata1 = indexMetadata("test1", OLD_VERSION);
         var indexMetadata2 = indexMetadata("test2", OLD_VERSION);
-        var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata1, true).put(indexMetadata2, true))
-            .blocks(clusterBlocksForIndices(indexMetadata1, indexMetadata2))
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .put(indexMetadata1, true)
+            .put(indexMetadata2, true)
             .build();
         var expected = Map.of(
             "test1",
@@ -195,7 +184,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             )
         );
         var issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             createContextWithTransformConfigs(Map.of("test1", List.of("test-transform1"), "test2", List.of("test-transform2")))
         );
@@ -234,24 +223,17 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             randomBoolean(),
             null
         );
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .put(indexMetadata, true)
-                    .projectCustoms(
-                        Map.of(
-                            DataStreamMetadata.TYPE,
-                            new DataStreamMetadata(
-                                ImmutableOpenMap.builder(Map.of("my-data-stream", dataStream)).build(),
-                                ImmutableOpenMap.of()
-                            )
-                        )
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .put(indexMetadata, true)
+            .customs(
+                Map.of(
+                    DataStreamMetadata.TYPE,
+                    new DataStreamMetadata(ImmutableOpenMap.builder(Map.of("my-data-stream", dataStream)).build(), ImmutableOpenMap.of())
+                )
             )
-            .blocks(clusterBlocksForIndices(indexMetadata))
             .build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -267,13 +249,10 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
 
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -282,10 +261,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
 
     public void testOldIndicesIgnoredWarningCheck() {
         IndexMetadata indexMetadata = readonlyIndexMetadata("test", OLD_VERSION);
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "Old index with a compatibility version < 9.0 has been ignored",
@@ -295,7 +271,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             singletonMap("reindex_required", true)
         );
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -313,12 +289,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -333,10 +306,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
     public void testOldTransformIndicesIgnoredCheck() {
         var checker = new IndexDeprecationChecker(indexNameExpressionResolver);
         var indexMetadata = readonlyIndexMetadata("test", OLD_VERSION);
-        var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         var expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "One or more Transforms write to this old index with a compatibility version < " + Version.CURRENT.major + ".0",
@@ -352,7 +322,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             Map.of("reindex_required", true, "transform_ids", List.of("test-transform"))
         );
         var issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             createContextWithTransformConfigs(Map.of("test", List.of("test-transform")))
         );
@@ -361,10 +331,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
 
     public void testOldIndicesIgnoredCheckWithMultipleTransforms() {
         var indexMetadata = readonlyIndexMetadata("test", OLD_VERSION);
-        var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         var expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "One or more Transforms write to this old index with a compatibility version < " + Version.CURRENT.major + ".0",
@@ -380,7 +347,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             Map.of("reindex_required", true, "transform_ids", List.of("test-transform1", "test-transform2"))
         );
         var issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             createContextWithTransformConfigs(Map.of("test", List.of("test-transform1", "test-transform2")))
         );
@@ -390,9 +357,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
     public void testMultipleOldIndicesIgnoredCheckWithTransforms() {
         var indexMetadata1 = readonlyIndexMetadata("test1", OLD_VERSION);
         var indexMetadata2 = readonlyIndexMetadata("test2", OLD_VERSION);
-        var clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata1, true).put(indexMetadata2, true))
-            .blocks(clusterBlocksForIndices(indexMetadata1, indexMetadata2))
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .put(indexMetadata1, true)
+            .put(indexMetadata2, true)
             .build();
         var expected = Map.of(
             "test1",
@@ -431,7 +398,7 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             )
         );
         var issuesByIndex = checker.check(
-            clusterState,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             createContextWithTransformConfigs(Map.of("test1", List.of("test-transform1"), "test2", List.of("test-transform2")))
         );
@@ -448,12 +415,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            state,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -492,12 +456,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            state,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -513,12 +474,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            state,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -547,12 +505,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            state,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -591,12 +546,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .putMapping(simpleMapping)
             .state(indexMetdataState)
             .build();
-        ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(simpleIndex, true))
-            .blocks(clusterBlocksForIndices(simpleIndex))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(simpleIndex, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            state,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -623,12 +575,9 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
             .numberOfReplicas(0)
             .state(indexMetdataState)
             .build();
-        ClusterState state = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(Metadata.builder().put(indexMetadata, true))
-            .blocks(clusterBlocksForIndices(indexMetadata))
-            .build();
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault()).put(indexMetadata, true).build();
         Map<String, List<DeprecationIssue>> issuesByIndex = checker.check(
-            state,
+            project,
             new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS),
             emptyPrecomputedData
         );
@@ -649,16 +598,6 @@ public class IndexDeprecationCheckerTests extends ESTestCase {
         );
     }
 
-    private ClusterBlocks clusterBlocksForIndices(IndexMetadata... indicesMetadatas) {
-        ClusterBlocks.Builder builder = ClusterBlocks.builder();
-        for (IndexMetadata indexMetadata : indicesMetadatas) {
-            if (indexMetadata.getState() == IndexMetadata.State.CLOSE) {
-                builder.addIndexBlock(indexMetadata.getIndex().getName(), MetadataIndexStateService.INDEX_CLOSED_BLOCK);
-            }
-        }
-        return builder.build();
-    }
-
     private TransportDeprecationInfoAction.PrecomputedData createContextWithTransformConfigs(Map<String, List<String>> indexToTransform) {
         List<TransformConfig> transforms = new ArrayList<>();
         for (Map.Entry<String, List<String>> entry : indexToTransform.entrySet()) {

+ 32 - 45
x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java

@@ -7,10 +7,9 @@
 
 package org.elasticsearch.xpack.deprecation;
 
-import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.metadata.ComponentTemplate;
 import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
-import org.elasticsearch.cluster.metadata.Metadata;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.cluster.metadata.Template;
 import org.elasticsearch.common.compress.CompressedXContent;
 import org.elasticsearch.common.settings.Settings;
@@ -39,16 +38,13 @@ public class TemplateDeprecationCheckerTests extends ESTestCase {
             { "_doc": { "_source": { "enabled": false} } }""")).build();
         ComponentTemplate componentTemplate2 = new ComponentTemplate(template2, 1L, new HashMap<>());
 
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .componentTemplates(
-                        Map.of("my-template-1", componentTemplate, "my-template-2", componentTemplate, "my-template-3", componentTemplate2)
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .componentTemplates(
+                Map.of("my-template-1", componentTemplate, "my-template-2", componentTemplate, "my-template-3", componentTemplate2)
             )
             .build();
 
-        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(project);
         final DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.CRITICAL,
             SourceFieldMapper.DEPRECATION_WARNING_TITLE,
@@ -72,16 +68,13 @@ public class TemplateDeprecationCheckerTests extends ESTestCase {
             .build();
         ComponentTemplate componentTemplate2 = new ComponentTemplate(template2, 1L, new HashMap<>());
 
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .componentTemplates(
-                        Map.of("my-template-1", componentTemplate, "my-template-2", componentTemplate, "my-template-3", componentTemplate2)
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .componentTemplates(
+                Map.of("my-template-1", componentTemplate, "my-template-2", componentTemplate, "my-template-3", componentTemplate2)
             )
             .build();
 
-        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(project);
         final DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "Configuring tiers via filtered allocation is not recommended.",
@@ -105,23 +98,20 @@ public class TemplateDeprecationCheckerTests extends ESTestCase {
             .settings(Settings.builder().put("index.routing.allocation.require.data", randomAlphaOfLength(10)).build())
             .build();
 
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .indexTemplates(
-                        Map.of(
-                            "my-template-1",
-                            ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
-                            "my-template-2",
-                            ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
-                            "my-template-3",
-                            ComposableIndexTemplate.builder().template(template2).indexPatterns(List.of(randomAlphaOfLength(10))).build()
-                        )
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .indexTemplates(
+                Map.of(
+                    "my-template-1",
+                    ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
+                    "my-template-2",
+                    ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
+                    "my-template-3",
+                    ComposableIndexTemplate.builder().template(template2).indexPatterns(List.of(randomAlphaOfLength(10))).build()
+                )
             )
             .build();
 
-        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(project);
         final DeprecationIssue expected = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "Configuring tiers via filtered allocation is not recommended.",
@@ -147,24 +137,21 @@ public class TemplateDeprecationCheckerTests extends ESTestCase {
 
         ComponentTemplate componentTemplate = new ComponentTemplate(template, 1L, new HashMap<>());
 
-        ClusterState clusterState = ClusterState.builder(ClusterState.EMPTY_STATE)
-            .metadata(
-                Metadata.builder()
-                    .componentTemplates(Map.of("my-template-1", componentTemplate))
-                    .indexTemplates(
-                        Map.of(
-                            "my-template-1",
-                            ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
-                            "my-template-2",
-                            ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
-                            "my-template-3",
-                            ComposableIndexTemplate.builder().template(template2).indexPatterns(List.of(randomAlphaOfLength(10))).build()
-                        )
-                    )
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
+            .componentTemplates(Map.of("my-template-1", componentTemplate))
+            .indexTemplates(
+                Map.of(
+                    "my-template-1",
+                    ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
+                    "my-template-2",
+                    ComposableIndexTemplate.builder().template(template).indexPatterns(List.of(randomAlphaOfLength(10))).build(),
+                    "my-template-3",
+                    ComposableIndexTemplate.builder().template(template2).indexPatterns(List.of(randomAlphaOfLength(10))).build()
+                )
             )
             .build();
 
-        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(clusterState);
+        Map<String, List<DeprecationIssue>> issuesByComponentTemplate = checker.check(project);
         final DeprecationIssue expectedIndexTemplateIssue = new DeprecationIssue(
             DeprecationIssue.Level.WARNING,
             "Configuring tiers via filtered allocation is not recommended.",

+ 17 - 40
x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java

@@ -9,20 +9,15 @@ package org.elasticsearch.xpack.deprecation;
 import org.elasticsearch.ElasticsearchStatusException;
 import org.elasticsearch.action.ActionListener;
 import org.elasticsearch.action.support.PlainActionFuture;
-import org.elasticsearch.cluster.ClusterName;
-import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.metadata.ComponentTemplate;
 import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
 import org.elasticsearch.cluster.metadata.DataStream;
 import org.elasticsearch.cluster.metadata.IndexMetadata;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
-import org.elasticsearch.cluster.metadata.Metadata;
+import org.elasticsearch.cluster.metadata.ProjectMetadata;
 import org.elasticsearch.cluster.metadata.Template;
-import org.elasticsearch.cluster.node.DiscoveryNode;
-import org.elasticsearch.cluster.node.DiscoveryNodeUtils;
 import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.index.IndexVersion;
 import org.elasticsearch.indices.TestIndexNameExpressionResolver;
 import org.elasticsearch.test.ESTestCase;
@@ -62,7 +57,7 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
         mapping.field("enabled", false);
         mapping.endObject().endObject();
 
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .put(
                 IndexMetadata.builder("test")
                     .putMapping(Strings.toString(mapping))
@@ -72,8 +67,6 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
             )
             .build();
 
-        DiscoveryNode discoveryNode = DiscoveryNodeUtils.create("test", new TransportAddress(TransportAddress.META_ADDRESS, 9300));
-        ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
         IndexNameExpressionResolver resolver = TestIndexNameExpressionResolver.newInstance();
         boolean clusterIssueFound = randomBoolean();
         boolean nodeIssueFound = randomBoolean();
@@ -84,7 +77,7 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
         boolean ilmPolicyIssueFound = randomBoolean();
         DeprecationIssue foundIssue = createTestDeprecationIssue();
         ClusterDeprecationChecker clusterDeprecationChecker = mock(ClusterDeprecationChecker.class);
-        when(clusterDeprecationChecker.check(any(), any())).thenReturn(clusterIssueFound ? List.of(foundIssue) : List.of());
+        when(clusterDeprecationChecker.check(any())).thenReturn(clusterIssueFound ? List.of(foundIssue) : List.of());
         List<ResourceDeprecationChecker> resourceCheckers = List.of(createResourceChecker("index_settings", (cs, req) -> {
             if (indexIssueFound) {
                 return Map.of("test", List.of(foundIssue));
@@ -119,7 +112,7 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
         precomputedData.setOncePluginIssues(Map.of());
         precomputedData.setOnceNodeSettingsIssues(nodeDeprecationIssues);
         DeprecationInfoAction.Response response = TransportDeprecationInfoAction.checkAndCreateResponse(
-            state,
+            project,
             resolver,
             request,
             List.of(),
@@ -184,7 +177,7 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
         ComposableIndexTemplate indexTemplate = ComposableIndexTemplate.builder()
             .template(Template.builder().settings(inputSettings))
             .build();
-        Metadata metadata = Metadata.builder()
+        ProjectMetadata project = ProjectMetadata.builder(randomProjectIdOrDefault())
             .put(IndexMetadata.builder("test").settings(inputSettings).numberOfShards(1).numberOfReplicas(0))
             .put(dataStreamIndexMetadata, true)
             .put(DataStream.builder("ds-test", List.of(dataStreamIndexMetadata.getIndex())).build())
@@ -197,37 +190,25 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
                 )
             )
             .componentTemplates(Map.of("my-component-template", componentTemplate))
-            .persistentSettings(inputSettings)
             .build();
 
-        ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build();
         IndexNameExpressionResolver resolver = TestIndexNameExpressionResolver.newInstance();
-        AtomicReference<Settings> visibleClusterSettings = new AtomicReference<>();
         ClusterDeprecationChecker clusterDeprecationChecker = mock(ClusterDeprecationChecker.class);
-        when(clusterDeprecationChecker.check(any(), any())).thenAnswer(invocationOnMock -> {
-            ClusterState observedState = invocationOnMock.getArgument(0);
-            visibleClusterSettings.set(observedState.getMetadata().settings());
-            return List.of();
-        });
         AtomicReference<Settings> visibleIndexSettings = new AtomicReference<>();
         AtomicReference<Settings> visibleComponentTemplateSettings = new AtomicReference<>();
         AtomicReference<Settings> visibleIndexTemplateSettings = new AtomicReference<>();
         AtomicInteger backingIndicesCount = new AtomicInteger(0);
-        List<ResourceDeprecationChecker> resourceCheckers = List.of(createResourceChecker("index_settings", (cs, req) -> {
-            for (String indexName : resolver.concreteIndexNames(cs, req)) {
-                visibleIndexSettings.set(cs.metadata().getProject().index(indexName).getSettings());
+        List<ResourceDeprecationChecker> resourceCheckers = List.of(createResourceChecker("index_settings", (pr, req) -> {
+            for (String indexName : resolver.concreteIndexNames(pr, req)) {
+                visibleIndexSettings.set(pr.index(indexName).getSettings());
             }
             return Map.of();
-        }), createResourceChecker("data_streams", (cs, req) -> {
-            cs.metadata().getProject().dataStreams().values().forEach(ds -> backingIndicesCount.set(ds.getIndices().size()));
+        }), createResourceChecker("data_streams", (pr, req) -> {
+            pr.dataStreams().values().forEach(ds -> backingIndicesCount.set(ds.getIndices().size()));
             return Map.of();
-        }), createResourceChecker("templates", (cs, req) -> {
-            cs.metadata()
-                .getProject()
-                .componentTemplates()
-                .values()
-                .forEach(template -> visibleComponentTemplateSettings.set(template.template().settings()));
-            cs.metadata().getProject().templatesV2().values().forEach(template -> {
+        }), createResourceChecker("templates", (pr, req) -> {
+            pr.componentTemplates().values().forEach(template -> visibleComponentTemplateSettings.set(template.template().settings()));
+            pr.templatesV2().values().forEach(template -> {
                 if (template.template() != null && template.template().settings() != null) {
                     visibleIndexTemplateSettings.set(template.template().settings());
                 }
@@ -240,7 +221,7 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
         precomputedData.setOnceNodeSettingsIssues(List.of());
         DeprecationInfoAction.Request request = new DeprecationInfoAction.Request(randomTimeValue(), Strings.EMPTY_ARRAY);
         TransportDeprecationInfoAction.checkAndCreateResponse(
-            state,
+            project,
             resolver,
             request,
             List.of("some.deprecated.property", "some.other.*.deprecated.property"),
@@ -254,10 +235,6 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
         settingsBuilder.putList("some.undeprecated.list.property", List.of("someValue4", "someValue5"));
 
         Settings expectedSettings = settingsBuilder.build();
-        Settings resultClusterSettings = visibleClusterSettings.get();
-        Assert.assertNotNull(resultClusterSettings);
-        Assert.assertEquals(expectedSettings, visibleClusterSettings.get());
-
         Settings resultIndexSettings = visibleIndexSettings.get();
         Assert.assertNotNull(resultIndexSettings);
         Assert.assertEquals("someValue3", resultIndexSettings.get("some.undeprecated.property"));
@@ -341,17 +318,17 @@ public class TransportDeprecationInfoActionTests extends ESTestCase {
 
     private static ResourceDeprecationChecker createResourceChecker(
         String name,
-        BiFunction<ClusterState, DeprecationInfoAction.Request, Map<String, List<DeprecationIssue>>> check
+        BiFunction<ProjectMetadata, DeprecationInfoAction.Request, Map<String, List<DeprecationIssue>>> check
     ) {
         return new ResourceDeprecationChecker() {
 
             @Override
             public Map<String, List<DeprecationIssue>> check(
-                ClusterState clusterState,
+                ProjectMetadata project,
                 DeprecationInfoAction.Request request,
                 TransportDeprecationInfoAction.PrecomputedData precomputedData
             ) {
-                return check.apply(clusterState, request);
+                return check.apply(project, request);
             }
 
             @Override

+ 0 - 1
x-pack/qa/multi-project/xpack-rest-tests-with-multiple-projects/build.gradle

@@ -31,7 +31,6 @@ tasks.named("yamlRestTest").configure {
     '^analytics/moving_percentiles/*',
     '^analytics/top_metrics/*',
     '^data_streams/10_data_stream_resolvability/*',
-    '^deprecation/10_basic/*',
     '^health/10_usage/*', // The usage API is project-aware, this test just fails on the project-awareness of the SLM health indicator
     '^migration/10_get_feature_upgrade_status/*',
     '^migration/20_post_feature_upgrade/*',