diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index 4bdccc267fb..0ddbcac6109 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -41,6 +41,7 @@ public class DeprecationChecks { static List> NODE_SETTINGS_CHECKS = Collections.unmodifiableList(Arrays.asList( + NodeDeprecationChecks::checkPidfile, NodeDeprecationChecks::checkProcessors )); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 835026183f0..fdc8ae69f3d 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -7,32 +7,59 @@ package org.elasticsearch.xpack.deprecation; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; +import org.elasticsearch.env.Environment; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; import java.util.Locale; class NodeDeprecationChecks { + static DeprecationIssue checkPidfile(final Settings settings, final PluginsAndModules pluginsAndModules) { + return checkDeprecatedSetting( + settings, + pluginsAndModules, + Environment.PIDFILE_SETTING, + Environment.NODE_PIDFILE_SETTING, + "https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-pidfile"); + } + static DeprecationIssue checkProcessors(final Settings settings , final PluginsAndModules pluginsAndModules) { - if (EsExecutors.PROCESSORS_SETTING.exists(settings) == false) { + return checkDeprecatedSetting( + settings, + pluginsAndModules, + EsExecutors.PROCESSORS_SETTING, + EsExecutors.NODE_PROCESSORS_SETTING, + "https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors"); + } + + private static DeprecationIssue checkDeprecatedSetting( + final Settings settings, + final PluginsAndModules pluginsAndModules, + final Setting deprecatedSetting, + final Setting replacementSetting, + final String url) { + assert deprecatedSetting.isDeprecated() : deprecatedSetting; + if (deprecatedSetting.exists(settings) == false) { return null; } + final String deprecatedSettingKey = deprecatedSetting.getKey(); + final String replacementSettingKey = replacementSetting.getKey(); + final String value = deprecatedSetting.get(settings).toString(); final String message = String.format( Locale.ROOT, "setting [%s] is deprecated in favor of setting [%s]", - EsExecutors.PROCESSORS_SETTING.getKey(), - EsExecutors.NODE_PROCESSORS_SETTING.getKey()); - final String url = - "https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-processors"; + deprecatedSettingKey, + replacementSettingKey); final String details = String.format( Locale.ROOT, - "the setting [%s] is currently set to [%d], instead set [%s] to [%d]", - EsExecutors.PROCESSORS_SETTING.getKey(), - EsExecutors.PROCESSORS_SETTING.get(settings), - EsExecutors.NODE_PROCESSORS_SETTING.getKey(), - EsExecutors.PROCESSORS_SETTING.get(settings)); + "the setting [%s] is currently set to [%s], instead set [%s] to [%s]", + deprecatedSettingKey, + value, + replacementSettingKey, + value); return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details); } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 9c5b67ee1d0..21a8bc16bc2 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; +import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; @@ -21,6 +22,29 @@ import static org.hamcrest.Matchers.empty; public class NodeDeprecationChecksTests extends ESTestCase { + public void testCheckDefaults() { + final Settings settings = Settings.EMPTY; + final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList()); + final List issues = + DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules)); + assertThat(issues, empty()); + } + + public void testCheckPidfile() { + final String pidfile = randomAlphaOfLength(16); + final Settings settings = Settings.builder().put(Environment.PIDFILE_SETTING.getKey(), pidfile).build(); + final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList()); + final List issues = + DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules)); + final DeprecationIssue expected = new DeprecationIssue( + DeprecationIssue.Level.CRITICAL, + "setting [pidfile] is deprecated in favor of setting [node.pidfile]", + "https://www.elastic.co/guide/en/elasticsearch/reference/7.4/breaking-changes-7.4.html#deprecate-pidfile", + "the setting [pidfile] is currently set to [" + pidfile + "], instead set [node.pidfile] to [" + pidfile + "]"); + assertThat(issues, contains(expected)); + assertSettingDeprecationsAndWarnings(new Setting[]{Environment.PIDFILE_SETTING}); + } + public void testCheckProcessors() { final int processors = randomIntBetween(1, 4); final Settings settings = Settings.builder().put(EsExecutors.PROCESSORS_SETTING.getKey(), processors).build(); @@ -36,12 +60,4 @@ public class NodeDeprecationChecksTests extends ESTestCase { assertSettingDeprecationsAndWarnings(new Setting[]{EsExecutors.PROCESSORS_SETTING}); } - public void testCheckProcessorsNotSet() { - final Settings settings = Settings.EMPTY; - final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList()); - final List issues = - DeprecationChecks.filterChecks(DeprecationChecks.NODE_SETTINGS_CHECKS, c -> c.apply(settings, pluginsAndModules)); - assertThat(issues, empty()); - } - }