Skip to content

Commit 4663e90

Browse files
authored
DeprecationInfoAction refactoring (#121181) (#121643) (#121649)
1 parent 10cf628 commit 4663e90

26 files changed

+1191
-1141
lines changed

x-pack/plugin/deprecation/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
requires org.apache.logging.log4j;
1414
requires org.apache.logging.log4j.core;
1515
requires log4j2.ecs.layout;
16+
requires org.apache.lucene.core;
1617

1718
exports org.elasticsearch.xpack.deprecation to org.elasticsearch.server;
1819
exports org.elasticsearch.xpack.deprecation.logging to org.elasticsearch.server;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.deprecation;
9+
10+
import org.apache.logging.log4j.LogManager;
11+
import org.apache.logging.log4j.Logger;
12+
import org.elasticsearch.cluster.ClusterState;
13+
import org.elasticsearch.common.TriConsumer;
14+
import org.elasticsearch.xcontent.NamedXContentRegistry;
15+
import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
16+
import org.elasticsearch.xpack.core.transform.transforms.TransformConfig;
17+
18+
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
/**
23+
* Cluster-specific deprecation checks, this is used to populate the {@code cluster_settings} field
24+
*/
25+
public class ClusterDeprecationChecker {
26+
27+
private static final Logger logger = LogManager.getLogger(ClusterDeprecationChecker.class);
28+
private final List<TriConsumer<ClusterState, List<TransformConfig>, List<DeprecationIssue>>> CHECKS = List.of(
29+
this::checkTransformSettings
30+
);
31+
private final NamedXContentRegistry xContentRegistry;
32+
33+
ClusterDeprecationChecker(NamedXContentRegistry xContentRegistry) {
34+
this.xContentRegistry = xContentRegistry;
35+
}
36+
37+
public List<DeprecationIssue> check(ClusterState clusterState, List<TransformConfig> transformConfigs) {
38+
List<DeprecationIssue> allIssues = new ArrayList<>();
39+
CHECKS.forEach(check -> check.apply(clusterState, transformConfigs, allIssues));
40+
return allIssues;
41+
}
42+
43+
private void checkTransformSettings(
44+
ClusterState clusterState,
45+
List<TransformConfig> transformConfigs,
46+
List<DeprecationIssue> allIssues
47+
) {
48+
for (var config : transformConfigs) {
49+
try {
50+
allIssues.addAll(config.checkForDeprecations(xContentRegistry));
51+
} catch (IOException e) {
52+
logger.warn("failed to check transformation settings for '" + config.getId() + "'", e);
53+
}
54+
}
55+
}
56+
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import java.util.HashMap;
1919
import java.util.List;
2020
import java.util.Map;
21+
import java.util.Objects;
2122
import java.util.Set;
2223
import java.util.function.BiFunction;
2324
import java.util.stream.Collectors;
2425

2526
import static java.util.Map.entry;
2627
import static java.util.Map.ofEntries;
27-
import static org.elasticsearch.xpack.deprecation.DeprecationInfoAction.filterChecks;
2828

2929
/**
3030
* Checks the data streams for deprecation warnings.
@@ -44,10 +44,24 @@ public DataStreamDeprecationChecker(IndexNameExpressionResolver indexNameExpress
4444

4545
/**
4646
* @param clusterState The cluster state provided for the checker
47+
* @param request not used yet in these checks
48+
* @param precomputedData not used yet in these checks
4749
* @return the name of the data streams that have violated the checks with their respective warnings.
4850
*/
4951
@Override
50-
public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, DeprecationInfoAction.Request request) {
52+
public Map<String, List<DeprecationIssue>> check(
53+
ClusterState clusterState,
54+
DeprecationInfoAction.Request request,
55+
TransportDeprecationInfoAction.PrecomputedData precomputedData
56+
) {
57+
return check(clusterState);
58+
}
59+
60+
/**
61+
* @param clusterState The cluster state provided for the checker
62+
* @return the name of the data streams that have violated the checks with their respective warnings.
63+
*/
64+
public Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
5165
List<String> dataStreamNames = indexNameExpressionResolver.dataStreamNames(
5266
clusterState,
5367
IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN
@@ -58,7 +72,10 @@ public Map<String, List<DeprecationIssue>> check(ClusterState clusterState, Depr
5872
Map<String, List<DeprecationIssue>> dataStreamIssues = new HashMap<>();
5973
for (String dataStreamName : dataStreamNames) {
6074
DataStream dataStream = clusterState.metadata().dataStreams().get(dataStreamName);
61-
List<DeprecationIssue> issuesForSingleDataStream = filterChecks(DATA_STREAM_CHECKS, c -> c.apply(dataStream, clusterState));
75+
List<DeprecationIssue> issuesForSingleDataStream = DATA_STREAM_CHECKS.stream()
76+
.map(c -> c.apply(dataStream, clusterState))
77+
.filter(Objects::nonNull)
78+
.toList();
6279
if (issuesForSingleDataStream.isEmpty() == false) {
6380
dataStreamIssues.put(dataStreamName, issuesForSingleDataStream);
6481
}

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.function.Predicate;
3434
import java.util.function.Supplier;
3535

36-
import static org.elasticsearch.xpack.deprecation.DeprecationChecks.SKIP_DEPRECATIONS_SETTING;
36+
import static org.elasticsearch.xpack.deprecation.TransportDeprecationInfoAction.SKIP_DEPRECATIONS_SETTING;
3737
import static org.elasticsearch.xpack.deprecation.logging.DeprecationIndexingComponent.DEPRECATION_INDEXING_FLUSH_INTERVAL;
3838

3939
/**

x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)