Skip to content

Commit 0ffc1c7

Browse files
committed
Polishing
1 parent 7bdaebb commit 0ffc1c7

File tree

9 files changed

+87
-67
lines changed

9 files changed

+87
-67
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +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
5052
public Map<String, List<DeprecationIssue>> check(
5153
ClusterState clusterState,
5254
DeprecationInfoAction.Request request,
53-
TransportDeprecationInfoAction.PrecomputedData ignored
55+
TransportDeprecationInfoAction.PrecomputedData precomputedData
5456
) {
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) {
5565
List<String> dataStreamNames = indexNameExpressionResolver.dataStreamNames(
5666
clusterState,
5767
IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED_HIDDEN

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,24 @@ public class IlmPolicyDeprecationChecker implements ResourceDeprecationChecker {
4040

4141
/**
4242
* @param clusterState The cluster state provided for the checker
43+
* @param request not used yet in these checks
44+
* @param precomputedData not used yet in these checks
4345
* @return the name of the data streams that have violated the checks with their respective warnings.
4446
*/
4547
@Override
4648
public Map<String, List<DeprecationIssue>> check(
4749
ClusterState clusterState,
4850
DeprecationInfoAction.Request request,
49-
TransportDeprecationInfoAction.PrecomputedData ignored
51+
TransportDeprecationInfoAction.PrecomputedData precomputedData
5052
) {
53+
return check(clusterState);
54+
}
55+
56+
/**
57+
* @param clusterState The cluster state provided for the checker
58+
* @return the name of the data streams that have violated the checks with their respective warnings.
59+
*/
60+
Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
5161
IndexLifecycleMetadata lifecycleMetadata = clusterState.metadata().custom(IndexLifecycleMetadata.TYPE);
5262
if (lifecycleMetadata == null || lifecycleMetadata.getPolicyMetadatas().isEmpty()) {
5363
return Map.of();

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

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ public class IndexDeprecationChecker implements ResourceDeprecationChecker {
4242
public static final String NAME = "index_settings";
4343

4444
private final IndexNameExpressionResolver indexNameExpressionResolver;
45+
private final List<TriFunction<IndexMetadata, ClusterState, Map<String, List<String>>, DeprecationIssue>> checks = List.of(
46+
this::oldIndicesCheck,
47+
this::ignoredOldIndicesCheck,
48+
this::translogRetentionSettingCheck,
49+
this::checkIndexDataPath,
50+
this::storeTypeSettingCheck,
51+
this::deprecatedCamelCasePattern,
52+
this::legacyRoutingSettingCheck
53+
);
4554

4655
public IndexDeprecationChecker(IndexNameExpressionResolver indexNameExpressionResolver) {
4756
this.indexNameExpressionResolver = indexNameExpressionResolver;
@@ -58,10 +67,7 @@ public Map<String, List<DeprecationIssue>> check(
5867
Map<String, List<String>> indexToTransformIds = indexToTransformIds(precomputedData.transformConfigs());
5968
for (String concreteIndex : concreteIndexNames) {
6069
IndexMetadata indexMetadata = clusterState.getMetadata().index(concreteIndex);
61-
List<DeprecationIssue> singleIndexIssues = filterChecks(
62-
indexSettingsChecks(),
63-
c -> c.apply(indexMetadata, clusterState, indexToTransformIds)
64-
);
70+
List<DeprecationIssue> singleIndexIssues = filterChecks(checks, c -> c.apply(indexMetadata, clusterState, indexToTransformIds));
6571
if (singleIndexIssues.isEmpty() == false) {
6672
indexSettingsIssues.put(concreteIndex, singleIndexIssues);
6773
}
@@ -72,24 +78,12 @@ public Map<String, List<DeprecationIssue>> check(
7278
return indexSettingsIssues;
7379
}
7480

75-
private List<TriFunction<IndexMetadata, ClusterState, Map<String, List<String>>, DeprecationIssue>> indexSettingsChecks() {
76-
return List.of(
77-
IndexDeprecationChecker::oldIndicesCheck,
78-
IndexDeprecationChecker::ignoredOldIndicesCheck,
79-
IndexDeprecationChecker::translogRetentionSettingCheck,
80-
IndexDeprecationChecker::checkIndexDataPath,
81-
IndexDeprecationChecker::storeTypeSettingCheck,
82-
IndexDeprecationChecker::deprecatedCamelCasePattern,
83-
IndexDeprecationChecker::legacyRoutingSettingCheck
84-
);
85-
}
86-
8781
@Override
8882
public String getName() {
8983
return NAME;
9084
}
9185

92-
private static DeprecationIssue oldIndicesCheck(
86+
private DeprecationIssue oldIndicesCheck(
9387
IndexMetadata indexMetadata,
9488
ClusterState clusterState,
9589
Map<String, List<String>> indexToTransformIds
@@ -110,7 +104,7 @@ private static DeprecationIssue oldIndicesCheck(
110104
return null;
111105
}
112106

113-
private static Map<String, Object> meta(IndexMetadata indexMetadata, Map<String, List<String>> indexToTransformIds) {
107+
private Map<String, Object> meta(IndexMetadata indexMetadata, Map<String, List<String>> indexToTransformIds) {
114108
var transforms = indexToTransformIds.getOrDefault(indexMetadata.getIndex().getName(), List.of());
115109
if (transforms.isEmpty()) {
116110
return Map.of("reindex_required", true);
@@ -119,7 +113,7 @@ private static Map<String, Object> meta(IndexMetadata indexMetadata, Map<String,
119113
}
120114
}
121115

122-
private static DeprecationIssue ignoredOldIndicesCheck(
116+
private DeprecationIssue ignoredOldIndicesCheck(
123117
IndexMetadata indexMetadata,
124118
ClusterState clusterState,
125119
Map<String, List<String>> indexToTransformIds
@@ -141,11 +135,11 @@ private static DeprecationIssue ignoredOldIndicesCheck(
141135
return null;
142136
}
143137

144-
private static boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
138+
private boolean isNotDataStreamIndex(IndexMetadata indexMetadata, ClusterState clusterState) {
145139
return clusterState.metadata().findDataStreams(indexMetadata.getIndex().getName()).isEmpty();
146140
}
147141

148-
private static DeprecationIssue translogRetentionSettingCheck(
142+
private DeprecationIssue translogRetentionSettingCheck(
149143
IndexMetadata indexMetadata,
150144
ClusterState clusterState,
151145
Map<String, List<String>> ignored
@@ -176,11 +170,7 @@ private static DeprecationIssue translogRetentionSettingCheck(
176170
return null;
177171
}
178172

179-
private static DeprecationIssue checkIndexDataPath(
180-
IndexMetadata indexMetadata,
181-
ClusterState clusterState,
182-
Map<String, List<String>> ignored
183-
) {
173+
private DeprecationIssue checkIndexDataPath(IndexMetadata indexMetadata, ClusterState clusterState, Map<String, List<String>> ignored) {
184174
if (IndexMetadata.INDEX_DATA_PATH_SETTING.exists(indexMetadata.getSettings())) {
185175
final String message = String.format(
186176
Locale.ROOT,
@@ -195,7 +185,7 @@ private static DeprecationIssue checkIndexDataPath(
195185
return null;
196186
}
197187

198-
private static DeprecationIssue storeTypeSettingCheck(
188+
private DeprecationIssue storeTypeSettingCheck(
199189
IndexMetadata indexMetadata,
200190
ClusterState clusterState,
201191
Map<String, List<String>> ignored
@@ -216,7 +206,7 @@ private static DeprecationIssue storeTypeSettingCheck(
216206
return null;
217207
}
218208

219-
private static DeprecationIssue legacyRoutingSettingCheck(
209+
private DeprecationIssue legacyRoutingSettingCheck(
220210
IndexMetadata indexMetadata,
221211
ClusterState clusterState,
222212
Map<String, List<String>> ignored
@@ -236,7 +226,7 @@ private static DeprecationIssue legacyRoutingSettingCheck(
236226
);
237227
}
238228

239-
private static void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsumer<MappingMetadata, Map<String, Object>> checker) {
229+
private void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsumer<MappingMetadata, Map<String, Object>> checker) {
240230
if (indexMetadata.mapping() != null) {
241231
Map<String, Object> sourceAsMap = indexMetadata.mapping().sourceAsMap();
242232
checker.accept(indexMetadata.mapping(), sourceAsMap);
@@ -254,7 +244,7 @@ private static void fieldLevelMappingIssue(IndexMetadata indexMetadata, BiConsum
254244
* @return a list of issues found in fields
255245
*/
256246
@SuppressWarnings("unchecked")
257-
private static List<String> findInPropertiesRecursively(
247+
private List<String> findInPropertiesRecursively(
258248
String type,
259249
Map<String, Object> parentMap,
260250
Function<Map<?, ?>, Boolean> predicate,
@@ -308,7 +298,7 @@ private static List<String> findInPropertiesRecursively(
308298
return issues;
309299
}
310300

311-
private static DeprecationIssue deprecatedCamelCasePattern(
301+
private DeprecationIssue deprecatedCamelCasePattern(
312302
IndexMetadata indexMetadata,
313303
ClusterState clusterState,
314304
Map<String, List<String>> ignored
@@ -320,8 +310,8 @@ private static DeprecationIssue deprecatedCamelCasePattern(
320310
findInPropertiesRecursively(
321311
mappingMetadata.type(),
322312
sourceAsMap,
323-
IndexDeprecationChecker::isDateFieldWithCamelCasePattern,
324-
IndexDeprecationChecker::changeFormatToSnakeCase,
313+
this::isDateFieldWithCamelCasePattern,
314+
this::changeFormatToSnakeCase,
325315
"",
326316
""
327317
)
@@ -342,7 +332,7 @@ private static DeprecationIssue deprecatedCamelCasePattern(
342332
return null;
343333
}
344334

345-
private static boolean isDateFieldWithCamelCasePattern(Map<?, ?> property) {
335+
private boolean isDateFieldWithCamelCasePattern(Map<?, ?> property) {
346336
if ("date".equals(property.get("type")) && property.containsKey("format")) {
347337
String[] patterns = DateFormatter.splitCombinedPatterns((String) property.get("format"));
348338
for (String pattern : patterns) {
@@ -353,7 +343,7 @@ private static boolean isDateFieldWithCamelCasePattern(Map<?, ?> property) {
353343
return false;
354344
}
355345

356-
private static String changeFormatToSnakeCase(String type, Map.Entry<?, ?> entry) {
346+
private String changeFormatToSnakeCase(String type, Map.Entry<?, ?> entry) {
357347
Map<?, ?> value = (Map<?, ?>) entry.getValue();
358348
final String formatFieldValue = (String) value.get("format");
359349
String[] patterns = DateFormatter.splitCombinedPatterns(formatFieldValue);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public void check(Client client, ActionListener<List<DeprecationIssue>> listener
6161
}
6262

6363
/**
64-
* This method rolls up DeprecationIssues that are identical but on different nodes. It also roles up DeprecationIssues that are
64+
* This method rolls up DeprecationIssues that are identical but on different nodes. It also rolls up DeprecationIssues that are
6565
* identical (and on different nodes) except that they differ in the removable settings listed in their meta object. We roll these up
6666
* by taking the intersection of all removable settings in otherwise identical DeprecationIssues. That way we don't claim that a
6767
* setting can be automatically removed if any node has it in its elasticsearch.yml.
68-
* @param response
69-
* @return
68+
* @param response the response that contains the deprecation issues of single nodes
69+
* @return a list of deprecation issues grouped accordingly.
7070
*/
7171
static List<DeprecationIssue> reduceToDeprecationIssues(NodesDeprecationCheckResponse response) {
7272
// A collection whose values are lists of DeprecationIssues that differ only by meta values (if that):

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

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,34 @@
3232
public class TemplateDeprecationChecker implements ResourceDeprecationChecker {
3333

3434
public static final String NAME = "templates";
35-
private static final List<Function<ComposableIndexTemplate, DeprecationIssue>> INDEX_TEMPLATE_CHECKS = List.of(
36-
TemplateDeprecationChecker::checkLegacyTiersInIndexTemplate
35+
private final List<Function<ComposableIndexTemplate, DeprecationIssue>> indexTemplateChecks = List.of(
36+
this::checkLegacyTiersInIndexTemplate
3737
);
38-
private static final List<Function<ComponentTemplate, DeprecationIssue>> COMPONENT_TEMPLATE_CHECKS = List.of(
39-
TemplateDeprecationChecker::checkSourceModeInComponentTemplates,
40-
TemplateDeprecationChecker::checkLegacyTiersInComponentTemplates
38+
private final List<Function<ComponentTemplate, DeprecationIssue>> componentTemplateChecks = List.of(
39+
this::checkSourceModeInComponentTemplates,
40+
this::checkLegacyTiersInComponentTemplates
4141
);
4242

4343
/**
4444
* @param clusterState The cluster state provided for the checker
45+
* @param request not used yet in these checks
46+
* @param precomputedData not used yet in these checks
4547
* @return the name of the data streams that have violated the checks with their respective warnings.
4648
*/
4749
@Override
4850
public Map<String, List<DeprecationIssue>> check(
4951
ClusterState clusterState,
5052
DeprecationInfoAction.Request request,
51-
TransportDeprecationInfoAction.PrecomputedData ignored
53+
TransportDeprecationInfoAction.PrecomputedData precomputedData
5254
) {
55+
return check(clusterState);
56+
}
57+
58+
/**
59+
* @param clusterState The cluster state provided for the checker
60+
* @return the name of the data streams that have violated the checks with their respective warnings.
61+
*/
62+
Map<String, List<DeprecationIssue>> check(ClusterState clusterState) {
5363
var indexTemplates = clusterState.metadata().templatesV2().entrySet();
5464
var componentTemplates = clusterState.metadata().componentTemplates().entrySet();
5565
if (indexTemplates.isEmpty() && componentTemplates.isEmpty()) {
@@ -60,24 +70,24 @@ public Map<String, List<DeprecationIssue>> check(
6070
String name = entry.getKey();
6171
ComposableIndexTemplate template = entry.getValue();
6272

63-
List<DeprecationIssue> issuesForSingleIndexTemplate = filterChecks(INDEX_TEMPLATE_CHECKS, c -> c.apply(template));
73+
List<DeprecationIssue> issuesForSingleIndexTemplate = filterChecks(indexTemplateChecks, c -> c.apply(template));
6474
if (issuesForSingleIndexTemplate.isEmpty() == false) {
65-
issues.computeIfAbsent(name, ignore -> new ArrayList<>()).addAll(issuesForSingleIndexTemplate);
75+
issues.computeIfAbsent(name, ignored -> new ArrayList<>()).addAll(issuesForSingleIndexTemplate);
6676
}
6777
}
6878
for (Map.Entry<String, ComponentTemplate> entry : componentTemplates) {
6979
String name = entry.getKey();
7080
ComponentTemplate template = entry.getValue();
7181

72-
List<DeprecationIssue> issuesForSingleIndexTemplate = filterChecks(COMPONENT_TEMPLATE_CHECKS, c -> c.apply(template));
82+
List<DeprecationIssue> issuesForSingleIndexTemplate = filterChecks(componentTemplateChecks, c -> c.apply(template));
7383
if (issuesForSingleIndexTemplate.isEmpty() == false) {
74-
issues.computeIfAbsent(name, ignore -> new ArrayList<>()).addAll(issuesForSingleIndexTemplate);
84+
issues.computeIfAbsent(name, ignored -> new ArrayList<>()).addAll(issuesForSingleIndexTemplate);
7585
}
7686
}
7787
return issues.isEmpty() ? Map.of() : issues;
7888
}
7989

80-
static DeprecationIssue checkLegacyTiersInIndexTemplate(ComposableIndexTemplate composableIndexTemplate) {
90+
private DeprecationIssue checkLegacyTiersInIndexTemplate(ComposableIndexTemplate composableIndexTemplate) {
8191
Template template = composableIndexTemplate.template();
8292
if (template != null) {
8393
List<String> deprecatedSettings = LegacyTiersDetection.getDeprecatedFilteredAllocationSettings(template.settings());
@@ -97,7 +107,7 @@ static DeprecationIssue checkLegacyTiersInIndexTemplate(ComposableIndexTemplate
97107
return null;
98108
}
99109

100-
static DeprecationIssue checkSourceModeInComponentTemplates(ComponentTemplate template) {
110+
private DeprecationIssue checkSourceModeInComponentTemplates(ComponentTemplate template) {
101111
if (template.template().mappings() != null) {
102112
var sourceAsMap = (Map<?, ?>) XContentHelper.convertToMap(template.template().mappings().uncompressed(), true).v2().get("_doc");
103113
if (sourceAsMap != null) {
@@ -119,7 +129,7 @@ static DeprecationIssue checkSourceModeInComponentTemplates(ComponentTemplate te
119129
return null;
120130
}
121131

122-
static DeprecationIssue checkLegacyTiersInComponentTemplates(ComponentTemplate componentTemplate) {
132+
private DeprecationIssue checkLegacyTiersInComponentTemplates(ComponentTemplate componentTemplate) {
123133
Template template = componentTemplate.template();
124134
List<String> deprecatedSettings = LegacyTiersDetection.getDeprecatedFilteredAllocationSettings(template.settings());
125135
if (deprecatedSettings.isEmpty()) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public TransportDeprecationInfoAction(
100100
.addSettingsUpdateConsumer(DeprecationChecks.SKIP_DEPRECATIONS_SETTING, this::setSkipDeprecations);
101101
}
102102

103+
private <T> void setSkipDeprecations(List<String> skipDeprecations) {
104+
this.skipTheseDeprecations = Collections.unmodifiableList(skipDeprecations);
105+
}
106+
103107
@Override
104108
protected ClusterBlockException checkBlock(DeprecationInfoAction.Request request, ClusterState state) {
105109
// Cluster is not affected but we look up repositories in metadata
@@ -220,10 +224,6 @@ static DeprecationInfoAction.Response checkAndCreateResponse(
220224
);
221225
}
222226

223-
private <T> void setSkipDeprecations(List<String> skipDeprecations) {
224-
this.skipTheseDeprecations = Collections.unmodifiableList(skipDeprecations);
225-
}
226-
227227
/**
228228
* This class holds the results of remote requests. These can be either checks that require remote requests such as
229229
* {@code nodeSettingsIssues} and {@code pluginIssues} or metadata needed for more than one types of checks such as

0 commit comments

Comments
 (0)