From 5a59c5394fce188ceff630d553f765d5088b8d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 6 Apr 2018 13:41:00 +0200 Subject: [PATCH] Add migration check for deprecated `delimited_payload_filter` (elastic/x-pack-elasticsearch#4310) Add a check to the migration assistant to warn about the renaming of `delimited_payload_filter` to `delimited_payload`. This should still word for old indices from 7.0 on but will throw an error for newly created indices and the user should be warned about it when running the migration checks. Original commit: elastic/x-pack-elasticsearch@5d55e4e49977354dec12ea8cae113dc0e7b78178 --- .../xpack/deprecation/DeprecationChecks.java | 4 +-- .../deprecation/IndexDeprecationChecks.java | 26 ++++++++++++++++--- .../IndexDeprecationChecksTests.java | 21 ++++++++++++++- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index 371ace3e3e0..83b72d47838 100644 --- a/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -37,7 +37,6 @@ public class DeprecationChecks { // STUB )); - @SuppressWarnings("unchecked") static List> INDEX_SETTINGS_CHECKS = Collections.unmodifiableList(Arrays.asList( IndexDeprecationChecks::baseSimilarityDefinedCheck, @@ -45,6 +44,7 @@ public class DeprecationChecks { IndexDeprecationChecks::dynamicTemplateWithMatchMappingTypeCheck, IndexDeprecationChecks::indexSharedFileSystemCheck, IndexDeprecationChecks::indexStoreTypeCheck, - IndexDeprecationChecks::storeThrottleSettingsCheck)); + IndexDeprecationChecks::storeThrottleSettingsCheck, + IndexDeprecationChecks::delimitedPayloadFilterCheck)); } diff --git a/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index 5b996fbb9ef..177574d89b6 100644 --- a/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -7,10 +7,12 @@ package org.elasticsearch.xpack.deprecation; import com.carrotsearch.hppc.cursors.ObjectCursor; + import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.analysis.AnalysisRegistry; import org.elasticsearch.index.mapper.DynamicTemplate; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; @@ -127,7 +129,6 @@ public class IndexDeprecationChecks { return null; } - @SuppressWarnings("unchecked") static DeprecationIssue baseSimilarityDefinedCheck(IndexMetaData indexMetaData) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { Settings settings = indexMetaData.getSettings().getAsSettings("index.similarity.base"); @@ -143,7 +144,26 @@ public class IndexDeprecationChecks { return null; } - @SuppressWarnings("unchecked") + static DeprecationIssue delimitedPayloadFilterCheck(IndexMetaData indexMetaData) { + if (indexMetaData.getCreationVersion().before(Version.V_7_0_0_alpha1)) { + List issues = new ArrayList<>(); + Map filters = indexMetaData.getSettings().getGroups(AnalysisRegistry.INDEX_ANALYSIS_FILTER); + for (Map.Entry entry : filters.entrySet()) { + if ("delimited_payload_filter".equals(entry.getValue().get("type"))) { + issues.add("The filter [" + entry.getKey() + "] is of deprecated 'delimited_payload_filter' type. " + + "The filter type should be changed to 'delimited_payload'."); + } + } + if (issues.size() > 0) { + return new DeprecationIssue(DeprecationIssue.Level.WARNING, + "Use of 'delimited_payload_filter'.", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_analysis_changes.html", + issues.toString()); + } + } + return null; + } + static DeprecationIssue indexStoreTypeCheck(IndexMetaData indexMetaData) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1) && indexMetaData.getSettings().get("index.store.type") != null) { @@ -158,7 +178,6 @@ public class IndexDeprecationChecks { return null; } - @SuppressWarnings("unchecked") static DeprecationIssue storeThrottleSettingsCheck(IndexMetaData indexMetaData) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1)) { Settings settings = indexMetaData.getSettings(); @@ -181,7 +200,6 @@ public class IndexDeprecationChecks { return null; } - @SuppressWarnings("unchecked") static DeprecationIssue indexSharedFileSystemCheck(IndexMetaData indexMetaData) { if (indexMetaData.getCreationVersion().before(Version.V_6_0_0_alpha1) && indexMetaData.getSettings().get("index.shared_filesystem") != null) { diff --git a/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 6ef50cb310e..0f54784a33f 100644 --- a/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -8,9 +8,11 @@ package org.elasticsearch.xpack.deprecation; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.VersionUtils; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; @@ -22,7 +24,7 @@ import static org.elasticsearch.xpack.deprecation.DeprecationChecks.INDEX_SETTIN public class IndexDeprecationChecksTests extends ESTestCase { - private void assertSettingsAndIssue(String key, String value, DeprecationIssue expected) { + private static void assertSettingsAndIssue(String key, String value, DeprecationIssue expected) { IndexMetaData indexMetaData = IndexMetaData.builder("test") .settings(settings(Version.V_5_6_0) .put(key, value)) @@ -164,4 +166,21 @@ public class IndexDeprecationChecksTests extends ESTestCase { "https://www.elastic.co/guide/en/elasticsearch/reference/6.0/" + "breaking_60_indices_changes.html#_shadow_replicas_have_been_removed", null)); } + + public void testDelimitedPayloadFilterCheck() throws IOException { + Settings settings = settings( + VersionUtils.randomVersionBetween(random(), Version.V_5_0_0, VersionUtils.getPreviousVersion(Version.V_7_0_0_alpha1))) + .put("index.analysis.filter.my_delimited_payload_filter.type", "delimited_payload_filter") + .put("index.analysis.filter.my_delimited_payload_filter.delimiter", "^") + .put("index.analysis.filter.my_delimited_payload_filter.encoding", "identity").build(); + + IndexMetaData indexMetaData = IndexMetaData.builder("test").settings(settings).numberOfShards(1).numberOfReplicas(0).build(); + + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, "Use of 'delimited_payload_filter'.", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_analysis_changes.html", + "[The filter [my_delimited_payload_filter] is of deprecated 'delimited_payload_filter' type. " + + "The filter type should be changed to 'delimited_payload'.]"); + List issues = DeprecationInfoAction.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData)); + assertEquals(singletonList(expected), issues); + } } \ No newline at end of file