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 new file mode 100644 index 0000000000000..c5087622404ab --- /dev/null +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -0,0 +1,30 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.deprecation; + +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; + +import java.util.Locale; + +public class NodeDeprecationChecks { + + static DeprecationIssue checkRemovedSetting(final Settings settings, final Setting removedSetting, final String url) { + if (removedSetting.exists(settings) == false) { + return null; + } + final String removedSettingKey = removedSetting.getKey(); + final String value = removedSetting.get(settings).toString(); + final String message = + String.format(Locale.ROOT, "setting [%s] is deprecated and will be removed in the next major version", removedSettingKey); + final String details = + String.format(Locale.ROOT, "the setting [%s] is currently set to [%s], remove this setting", removedSettingKey, 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 new file mode 100644 index 0000000000000..00c49aedbe223 --- /dev/null +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.xpack.deprecation; + +import org.elasticsearch.common.settings.Setting; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.deprecation.DeprecationIssue; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +public class NodeDeprecationChecksTests extends ESTestCase { + + public void testRemovedSettingNotSet() { + final Settings settings = Settings.EMPTY; + final Setting removedSetting = Setting.simpleString("node.removed_setting"); + final DeprecationIssue issue = + NodeDeprecationChecks.checkRemovedSetting(settings, removedSetting, "http://removed-setting.example.com"); + assertThat(issue, nullValue()); + } + + public void testRemovedSetting() { + final Settings settings = Settings.builder().put("node.removed_setting", "value").build(); + final Setting removedSetting = Setting.simpleString("node.removed_setting"); + final DeprecationIssue issue = + NodeDeprecationChecks.checkRemovedSetting(settings, removedSetting, "https://removed-setting.example.com"); + assertThat(issue, not(nullValue())); + assertThat(issue.getLevel(), equalTo(DeprecationIssue.Level.CRITICAL)); + assertThat( + issue.getMessage(), + equalTo("setting [node.removed_setting] is deprecated and will be removed in the next major version")); + assertThat( + issue.getDetails(), + equalTo("the setting [node.removed_setting] is currently set to [value], remove this setting")); + assertThat(issue.getUrl(), equalTo("https://removed-setting.example.com")); + } + +}