diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecker.java index cc21f0b2cd711..c5a42ad5f63dc 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecker.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecker.java @@ -9,8 +9,6 @@ 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 @@ public class ClusterDeprecationChecker { private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecker.class); - private final List, List>> CHECKS = List.of( - this::checkTransformSettings - ); private final NamedXContentRegistry xContentRegistry; ClusterDeprecationChecker(NamedXContentRegistry xContentRegistry) { this.xContentRegistry = xContentRegistry; } - public List check(ClusterState clusterState, List transformConfigs) { + public List check(List transformConfigs) { List allIssues = new ArrayList<>(); - CHECKS.forEach(check -> check.apply(clusterState, transformConfigs, allIssues)); + checkTransformSettings(transformConfigs, allIssues); return allIssues; } - private void checkTransformSettings( - ClusterState clusterState, - List transformConfigs, - List allIssues - ) { + private void checkTransformSettings(List transformConfigs, List allIssues) { for (var config : transformConfigs) { try { allIssues.addAll(config.checkForDeprecations(xContentRegistry)); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecker.java index c2204f893a081..b05bdb25df792 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecker.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationChecker.java @@ -9,9 +9,9 @@ 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 @@ public class DataStreamDeprecationChecker implements ResourceDeprecationChecker { public static final String NAME = "data_streams"; - private static final List> DATA_STREAM_CHECKS = List.of( + private static final List> DATA_STREAM_CHECKS = List.of( DataStreamDeprecationChecker::oldIndicesCheck, DataStreamDeprecationChecker::ignoredOldIndicesCheck ); @@ -44,27 +44,27 @@ public DataStreamDeprecationChecker(IndexNameExpressionResolver indexNameExpress } /** - * @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> 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> check(ClusterState clusterState) { + public Map> check(ProjectMetadata project) { List dataStreamNames = indexNameExpressionResolver.dataStreamNames( - clusterState, + project, IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN ); if (dataStreamNames.isEmpty()) { @@ -72,10 +72,10 @@ public Map> check(ClusterState clusterState) { } Map> 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 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 Map> check(ClusterState clusterState) { return dataStreamIssues.isEmpty() ? Map.of() : dataStreamIssues; } - static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clusterState) { + static DeprecationIssue oldIndicesCheck(DataStream dataStream, ProjectMetadata project) { List backingIndices = dataStream.getIndices(); - Set indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, clusterState, false); + Set indicesNeedingUpgrade = getReindexRequiredIndices(backingIndices, project, false); if (indicesNeedingUpgrade.isEmpty() == false) { return new DeprecationIssue( @@ -110,9 +110,9 @@ static DeprecationIssue oldIndicesCheck(DataStream dataStream, ClusterState clus return null; } - static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterState clusterState) { + static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ProjectMetadata project) { List backingIndices = dataStream.getIndices(); - Set ignoredIndices = getReindexRequiredIndices(backingIndices, clusterState, true); + Set ignoredIndices = getReindexRequiredIndices(backingIndices, project, true); if (ignoredIndices.isEmpty() == false) { return new DeprecationIssue( DeprecationIssue.Level.WARNING, @@ -135,13 +135,11 @@ static DeprecationIssue ignoredOldIndicesCheck(DataStream dataStream, ClusterSta private static Set getReindexRequiredIndices( List 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()); } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationChecker.java index 885d9b13e5e42..2ed7339706d2c 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationChecker.java +++ b/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> 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> 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> check(ClusterState clusterState) { - IndexLifecycleMetadata lifecycleMetadata = clusterState.metadata().getProject().custom(IndexLifecycleMetadata.TYPE); + Map> check(ProjectMetadata project) { + IndexLifecycleMetadata lifecycleMetadata = project.custom(IndexLifecycleMetadata.TYPE); if (lifecycleMetadata == null || lifecycleMetadata.getPolicyMetadatas().isEmpty()) { return Map.of(); } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java index b5be7c121d05c..5f1a3310027c3 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecker.java +++ b/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>, DeprecationIssue>> checks = List.of( + private final List>, DeprecationIssue>> checks = List.of( this::oldIndicesCheck, this::ignoredOldIndicesCheck, this::translogRetentionSettingCheck, @@ -60,17 +60,17 @@ public IndexDeprecationChecker(IndexNameExpressionResolver indexNameExpressionRe @Override public Map> check( - ClusterState clusterState, + ProjectMetadata project, DeprecationInfoAction.Request request, TransportDeprecationInfoAction.PrecomputedData precomputedData ) { Map> indexSettingsIssues = new HashMap<>(); - String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(clusterState, request); + String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(project, request); Map> indexToTransformIds = indexToTransformIds(precomputedData.transformConfigs()); for (String concreteIndex : concreteIndexNames) { - IndexMetadata indexMetadata = clusterState.getMetadata().getProject().index(concreteIndex); + IndexMetadata indexMetadata = project.index(concreteIndex); List 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 String getName() { private DeprecationIssue oldIndicesCheck( IndexMetadata indexMetadata, - ClusterState clusterState, + ProjectMetadata project, Map> 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 @@ private List transformIdsForIndex(IndexMetadata indexMetadata, Map> 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 @@ private DeprecationIssue ignoredOldIndicesCheck( 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> ignored ) { final boolean softDeletesEnabled = IndexSettings.INDEX_SOFT_DELETES_SETTING.get(indexMetadata.getSettings()); @@ -210,7 +210,7 @@ private DeprecationIssue translogRetentionSettingCheck( return null; } - private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterState clusterState, Map> ignored) { + private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ProjectMetadata project, Map> ignored) { if (IndexMetadata.INDEX_DATA_PATH_SETTING.exists(indexMetadata.getSettings())) { final String message = String.format( Locale.ROOT, @@ -226,7 +226,7 @@ private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, Cluster private DeprecationIssue storeTypeSettingCheck( IndexMetadata indexMetadata, - ClusterState clusterState, + ProjectMetadata project, Map> ignored ) { final String storeType = IndexModule.INDEX_STORE_TYPE_SETTING.get(indexMetadata.getSettings()); @@ -247,7 +247,7 @@ private DeprecationIssue storeTypeSettingCheck( private DeprecationIssue legacyRoutingSettingCheck( IndexMetadata indexMetadata, - ClusterState clusterState, + ProjectMetadata project, Map> ignored ) { List deprecatedSettings = LegacyTiersDetection.getDeprecatedFilteredAllocationSettings(indexMetadata.getSettings()); @@ -339,7 +339,7 @@ private List findInPropertiesRecursively( private DeprecationIssue deprecatedCamelCasePattern( IndexMetadata indexMetadata, - ClusterState clusterState, + ProjectMetadata project, Map> ignored ) { List fields = new ArrayList<>(); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ResourceDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ResourceDeprecationChecker.java index daa3514e3b989..2377e03028155 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ResourceDeprecationChecker.java +++ b/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> check( - ClusterState clusterState, + ProjectMetadata project, DeprecationInfoAction.Request request, TransportDeprecationInfoAction.PrecomputedData precomputedData ); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java index ce29c0dd6cd7e..baa247cf9bab9 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationChecker.java +++ b/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> 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> check(ClusterState clusterState) { - var indexTemplates = clusterState.metadata().getProject().templatesV2().entrySet(); - var componentTemplates = clusterState.metadata().getProject().componentTemplates().entrySet(); + Map> check(ProjectMetadata project) { + var indexTemplates = project.templatesV2().entrySet(); + var componentTemplates = project.componentTemplates().entrySet(); if (indexTemplates.isEmpty() && componentTemplates.isEmpty()) { return Map.of(); } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java index 4d3978b4c32ce..316a1ea75b7a3 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java @@ -23,7 +23,9 @@ 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 resourceDeprecationCheckers; + private final ProjectResolver projectResolver; @Inject public TransportDeprecationInfoAction( @@ -76,7 +79,8 @@ public TransportDeprecationInfoAction( ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, NodeClient client, - NamedXContentRegistry xContentRegistry + NamedXContentRegistry xContentRegistry, + ProjectResolver projectResolver ) { super( DeprecationInfoAction.NAME, @@ -101,6 +105,7 @@ public TransportDeprecationInfoAction( 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 @@ protected final void masterOperation( final ActionListener 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 @@ protected final void masterOperation( * 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 @@ protected final void masterOperation( * is initialised. */ public ActionListener checkAndCreateResponse( - ClusterState state, + ProjectMetadata project, DeprecationInfoAction.Request request, PrecomputedData precomputedData, ActionListener responseListener @@ -159,7 +165,7 @@ public ActionListener checkAndCreateResponse( ActionListener.running( () -> responseListener.onResponse( checkAndCreateResponse( - state, + project, indexNameExpressionResolver, request, skipTheseDeprecations, @@ -173,26 +179,26 @@ public ActionListener checkAndCreateResponse( } /** - * 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 skipTheseDeprecatedSettings, @@ -202,17 +208,14 @@ static DeprecationInfoAction.Response checkAndCreateResponse( ) { 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 clusterSettingsIssues = clusterDeprecationChecker.check( - stateWithSkippedSettingsRemoved, - precomputedData.transformConfigs() - ); + String[] concreteIndexNames = indexNameExpressionResolver.concreteIndexNames(project, request); + ProjectMetadata projectWithSkippedSettingsRemoved = removeSkippedSettings(project, concreteIndexNames, skipTheseDeprecatedSettings); + List clusterSettingsIssues = clusterDeprecationChecker.check(precomputedData.transformConfigs()); Map>> resourceDeprecationIssues = new HashMap<>(); for (ResourceDeprecationChecker resourceDeprecationChecker : resourceDeprecationCheckers) { Map> issues = resourceDeprecationChecker.check( - stateWithSkippedSettingsRemoved, + projectWithSkippedSettingsRemoved, request, precomputedData ); @@ -266,35 +269,32 @@ public List transformConfigs() { /** * 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 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 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 indicesBuilder = new HashMap<>(state.getMetadata().getProject().indices()); + ProjectMetadata.Builder projectBuilder = ProjectMetadata.builder(project); + Map 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 @@ private static ClusterState removeSkippedSettings(ClusterState state, String[] i ) ); }).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 @@ private static ClusterState removeSkippedSettings(ClusterState state, String[] i ); }).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( diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingComponent.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingComponent.java index ad6518eccca4c..d512b8a2fa9e8 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingComponent.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingComponent.java @@ -21,7 +21,10 @@ 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.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 void clusterChanged(ClusterChangedEvent event) { 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 void clusterChanged(ClusterChangedEvent event) { } } + /** + * 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, diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationCheckerTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationCheckerTests.java index 6f1853eaeed68..6bf5151cee627 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DataStreamDeprecationCheckerTests.java +++ b/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 void testOldIndicesCheck() { 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 void testOldIndicesCheck() { ); // We know that the data stream checks ignore the request. - Map> issuesByDataStream = checker.check(clusterState); + Map> 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 void testOldIndicesCheckWithOnlyNewIndices() { 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> issuesByDataStream = checker.check(clusterState); + Map> issuesByDataStream = checker.check(project); assertThat(issuesByDataStream.size(), equalTo(0)); } @@ -118,11 +114,10 @@ public void testOldIndicesCheckWithClosedAndOpenIndices() { 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 void testOldIndicesCheckWithClosedAndOpenIndices() { ) ); - Map> issuesByDataStream = checker.check(clusterState); + Map> 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 void testOldIndicesIgnoredWarningCheck() { 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 void testOldIndicesIgnoredWarningCheck() { ) ); - Map> issuesByDataStream = checker.check(clusterState); + Map> 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 void testOldSystemDataStreamIgnored() { 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())); } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationCheckerTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationCheckerTests.java index 1b3d8b83fa500..8d4ec461980ef 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IlmPolicyDeprecationCheckerTests.java +++ b/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 void testLegacyTierSettings() { 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> issuesByComponentTemplate = checker.check(clusterState); + Map> 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 void testFrozenAction() { 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> issuesByComponentTemplate = checker.check(clusterState); + Map> 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.", diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java index 17bc1c6fefbda..5ea8a9eea6b8e 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationCheckerTests.java @@ -11,15 +11,13 @@ 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 void testOldIndicesCheck() { .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 void testOldIndicesCheck() { singletonMap("reindex_required", true) ); Map> issuesByIndex = checker.check( - clusterState, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -97,10 +92,7 @@ public void testOldIndicesCheck() { 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 void testOldTransformIndicesCheck() { 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 void testOldTransformIndicesCheck() { 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 void testOldIndicesCheckWithMultipleTransforms() { 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 void testOldIndicesCheckWithMultipleTransforms() { 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 void testMultipleOldIndicesCheckWithTransforms() { ) ); 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 void testOldIndicesCheckDataStreamIndex() { 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> issuesByIndex = checker.check( - clusterState, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -267,13 +249,10 @@ public void testOldIndicesCheckSnapshotIgnored() { .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> issuesByIndex = checker.check( - clusterState, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -282,10 +261,7 @@ public void testOldIndicesCheckSnapshotIgnored() { 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 void testOldIndicesIgnoredWarningCheck() { singletonMap("reindex_required", true) ); Map> issuesByIndex = checker.check( - clusterState, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -313,12 +289,9 @@ public void testOldSystemIndicesIgnored() { .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> issuesByIndex = checker.check( - clusterState, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -333,10 +306,7 @@ private IndexMetadata readonlyIndexMetadata(String indexName, IndexVersion index 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 void testOldTransformIndicesIgnoredCheck() { 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 void testOldTransformIndicesIgnoredCheck() { 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 void testOldIndicesIgnoredCheckWithMultipleTransforms() { 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 void testOldIndicesIgnoredCheckWithMultipleTransforms() { 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 void testMultipleOldIndicesIgnoredCheckWithTransforms() { ) ); 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 void testTranslogRetentionSettings() { .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> issuesByIndex = checker.check( - state, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -492,12 +456,9 @@ public void testDefaultTranslogRetentionSettings() { .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> issuesByIndex = checker.check( - state, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -513,12 +474,9 @@ public void testIndexDataPathSetting() { .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> issuesByIndex = checker.check( - state, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -547,12 +505,9 @@ public void testSimpleFSSetting() { .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> issuesByIndex = checker.check( - state, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -591,12 +546,9 @@ public void testCamelCaseDeprecation() { .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> issuesByIndex = checker.check( - state, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -623,12 +575,9 @@ public void testLegacyTierIndex() { .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> issuesByIndex = checker.check( - state, + project, new DeprecationInfoAction.Request(TimeValue.THIRTY_SECONDS), emptyPrecomputedData ); @@ -649,16 +598,6 @@ public void testLegacyTierIndex() { ); } - 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> indexToTransform) { List transforms = new ArrayList<>(); for (Map.Entry> entry : indexToTransform.entrySet()) { diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java index 4e1b28b341282..48ebdf25b7e2a 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TemplateDeprecationCheckerTests.java +++ b/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 void testCheckSourceModeInComponentTemplates() throws IOException { { "_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> issuesByComponentTemplate = checker.check(clusterState); + Map> issuesByComponentTemplate = checker.check(project); final DeprecationIssue expected = new DeprecationIssue( DeprecationIssue.Level.CRITICAL, SourceFieldMapper.DEPRECATION_WARNING_TITLE, @@ -72,16 +68,13 @@ public void testCheckLegacyTiersInComponentTemplates() { .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> issuesByComponentTemplate = checker.check(clusterState); + Map> 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 void testCheckLegacyTierSettings() { .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> issuesByComponentTemplate = checker.check(clusterState); + Map> 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 void testComponentAndComposableTemplateWithSameName() { 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> issuesByComponentTemplate = checker.check(clusterState); + Map> issuesByComponentTemplate = checker.check(project); final DeprecationIssue expectedIndexTemplateIssue = new DeprecationIssue( DeprecationIssue.Level.WARNING, "Configuring tiers via filtered allocation is not recommended.", diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java index 10465c00ab7de..9adf13f45a363 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoActionTests.java @@ -9,20 +9,15 @@ 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 void testCheckAndCreateResponse() throws IOException { 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 void testCheckAndCreateResponse() throws IOException { ) .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 void testCheckAndCreateResponse() throws IOException { 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 resourceCheckers = List.of(createResourceChecker("index_settings", (cs, req) -> { if (indexIssueFound) { return Map.of("test", List.of(foundIssue)); @@ -119,7 +112,7 @@ public void testCheckAndCreateResponse() throws IOException { precomputedData.setOncePluginIssues(Map.of()); precomputedData.setOnceNodeSettingsIssues(nodeDeprecationIssues); DeprecationInfoAction.Response response = TransportDeprecationInfoAction.checkAndCreateResponse( - state, + project, resolver, request, List.of(), @@ -184,7 +177,7 @@ public void testRemoveSkippedSettings() { 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 void testRemoveSkippedSettings() { ) ) .componentTemplates(Map.of("my-component-template", componentTemplate)) - .persistentSettings(inputSettings) .build(); - ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build(); IndexNameExpressionResolver resolver = TestIndexNameExpressionResolver.newInstance(); - AtomicReference 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 visibleIndexSettings = new AtomicReference<>(); AtomicReference visibleComponentTemplateSettings = new AtomicReference<>(); AtomicReference visibleIndexTemplateSettings = new AtomicReference<>(); AtomicInteger backingIndicesCount = new AtomicInteger(0); - List resourceCheckers = List.of(createResourceChecker("index_settings", (cs, req) -> { - for (String indexName : resolver.concreteIndexNames(cs, req)) { - visibleIndexSettings.set(cs.metadata().getProject().index(indexName).getSettings()); + List 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 void testRemoveSkippedSettings() { 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 void testRemoveSkippedSettings() { 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 void testPluginSettingIssuesWithFailures() { private static ResourceDeprecationChecker createResourceChecker( String name, - BiFunction>> check + BiFunction>> check ) { return new ResourceDeprecationChecker() { @Override public Map> check( - ClusterState clusterState, + ProjectMetadata project, DeprecationInfoAction.Request request, TransportDeprecationInfoAction.PrecomputedData precomputedData ) { - return check.apply(clusterState, request); + return check.apply(project, request); } @Override 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 eca07a541e407..d85ffcf47b9b9 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 @@ -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/*',