From 104e5d0140d5651aa67d41641151aab03d28dadd Mon Sep 17 00:00:00 2001 From: Keith Massey Date: Mon, 30 Aug 2021 15:57:16 -0500 Subject: [PATCH] Adding deprecation info API checks for delay cluster state recovery settings --- .../xpack/deprecation/DeprecationChecks.java | 1 + .../deprecation/NodeDeprecationChecks.java | 31 +++++++++++++++++++ .../NodeDeprecationChecksTests.java | 27 ++++++++++++++++ 3 files changed, 59 insertions(+) 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 dddccceb358ac..124bfc1351801 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 @@ -95,6 +95,7 @@ private DeprecationChecks() { NodeDeprecationChecks::checkSingleDataNodeWatermarkSetting, NodeDeprecationChecks::checkImplicitlyDisabledSecurityOnBasicAndTrial, NodeDeprecationChecks::checkMonitoringExporterPassword, + NodeDeprecationChecks::checkDelayClusterStateRecoverySettings, NodeDeprecationChecks::checkClusterRoutingAllocationIncludeRelocationsSetting ) ).collect(Collectors.toList()); 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 4968eea4ed60f..aa49b12cbd606 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 @@ -22,6 +22,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.env.Environment; +import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.jdk.JavaVersion; import org.elasticsearch.license.License; import org.elasticsearch.license.XPackLicenseState; @@ -595,4 +596,34 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f DeprecationIssue.Level.CRITICAL ); } + + static DeprecationIssue checkDelayClusterStateRecoverySettings(final Settings settings, + final PluginsAndModules pluginsAndModules, + final ClusterState clusterState, + final XPackLicenseState licenseState) { + List> deprecatedSettings = new ArrayList<>(); + deprecatedSettings.add(GatewayService.EXPECTED_NODES_SETTING); + deprecatedSettings.add(GatewayService.EXPECTED_MASTER_NODES_SETTING); + deprecatedSettings.add(GatewayService.RECOVER_AFTER_NODES_SETTING); + deprecatedSettings.add(GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING); + List> existingSettings = + deprecatedSettings.stream().filter(deprecatedSetting -> deprecatedSetting.exists(settings)).collect(Collectors.toList()); + if (existingSettings.isEmpty()) { + return null; + } + final String settingNames = existingSettings.stream().map(Setting::getKey).collect(Collectors.joining(",")); + final String message = String.format( + Locale.ROOT, + "cannot use properties related to delaying cluster state recovery after a majority of master nodes have joined because " + + "they have been deprecated and will be removed in the next major version", + settingNames + ); + final String details = String.format( + Locale.ROOT, + "cannot use properties [%s] because they have been deprecated and will be removed in the next major version", + settingNames + ); + final String url = "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_settings_changes"; + return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, message, url, details, false, null); + } } 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 0886f0dfe28fd..61363cf469d69 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 @@ -21,6 +21,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.core.Set; import org.elasticsearch.env.Environment; +import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.license.License; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.jdk.JavaVersion; @@ -863,4 +864,30 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() { final List issues = getDeprecationIssues(settings, pluginsAndModules, licenseState); assertThat(issues, empty()); } + + public void testCheckDelayClusterStateRecoverySettings() { + Settings settings = Settings.builder() + .put(GatewayService.EXPECTED_NODES_SETTING.getKey(), randomIntBetween(2, 10)) + .put(GatewayService.EXPECTED_MASTER_NODES_SETTING.getKey(), randomIntBetween(2, 10)) + .put(GatewayService.RECOVER_AFTER_NODES_SETTING.getKey(), randomIntBetween(2, 10)) + .put(GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING.getKey(), randomIntBetween(2, 10)) + .build(); + final ClusterState clusterState = ClusterState.EMPTY_STATE; + final DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, + "cannot use properties related to delaying cluster state recovery after a majority of master nodes have joined because they " + + "have been deprecated and will be removed in the next major version", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/migrating-8.0.html#breaking_80_settings_changes", + "cannot use properties [gateway.expected_nodes,gateway.expected_master_nodes,gateway.recover_after_nodes,gateway" + + ".recover_after_master_nodes] because they have been deprecated and will be removed in the next major version", + false, null + ); + final XPackLicenseState licenseState = mock(XPackLicenseState.class); + when(licenseState.getOperationMode()) + .thenReturn(randomValueOtherThanMany((m -> m.equals(License.OperationMode.BASIC) || m.equals(License.OperationMode.TRIAL)), + () -> randomFrom(License.OperationMode.values()))); + assertThat( + NodeDeprecationChecks.checkDelayClusterStateRecoverySettings(settings, null, clusterState, licenseState), + equalTo(expectedIssue) + ); + } }