diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java index 7f11c2c2944a7..f9269c9862c84 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecks.java @@ -18,7 +18,7 @@ static DeprecationIssue checkShardLimit(ClusterState state) { int maxShardsInCluster = shardsPerNode * nodeCount; int currentOpenShards = state.getMetaData().getTotalOpenIndexShards(); - if (currentOpenShards >= maxShardsInCluster) { + if (nodeCount > 0 && currentOpenShards >= maxShardsInCluster) { return new DeprecationIssue(DeprecationIssue.Level.WARNING, "Number of open shards exceeds cluster soft limit", "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_70_cluster_changes.html", @@ -27,4 +27,16 @@ static DeprecationIssue checkShardLimit(ClusterState state) { } return null; } + + static DeprecationIssue checkClusterName(ClusterState state) { + String clusterName = state.getClusterName().value(); + if (clusterName.contains(":")) { + return new DeprecationIssue(DeprecationIssue.Level.CRITICAL, + "Cluster name cannot contain ':'", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + + "#_literal_literal_is_no_longer_allowed_in_cluster_name", + "This cluster is named [" + clusterName + "], which contains the illegal character ':'."); + } + return null; + } } 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 f8d85129be760..6dbbee49589a4 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 @@ -32,7 +32,8 @@ private DeprecationChecks() { static List> CLUSTER_SETTINGS_CHECKS = Collections.unmodifiableList(Arrays.asList( - ClusterDeprecationChecks::checkShardLimit + ClusterDeprecationChecks::checkShardLimit, + ClusterDeprecationChecks::checkClusterName )); static List, List, DeprecationIssue>> NODE_SETTINGS_CHECKS = @@ -44,7 +45,9 @@ private DeprecationChecks() { static List> INDEX_SETTINGS_CHECKS = Collections.unmodifiableList(Arrays.asList( IndexDeprecationChecks::oldIndicesCheck, - IndexDeprecationChecks::delimitedPayloadFilterCheck)); + IndexDeprecationChecks::delimitedPayloadFilterCheck, + IndexDeprecationChecks::indexNameCheck + )); /** * helper utility function to reduce repeat of running a specific {@link Set} of checks. diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java index a022a9c42a329..5134d86f51891 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecks.java @@ -104,4 +104,16 @@ static DeprecationIssue oldIndicesCheck(IndexMetaData indexMetaData) { } return null; } + + static DeprecationIssue indexNameCheck(IndexMetaData indexMetaData) { + String clusterName = indexMetaData.getIndex().getName(); + if (clusterName.contains(":")) { + return new DeprecationIssue(DeprecationIssue.Level.WARNING, + "Index name cannot contain ':'", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + + "#_literal_literal_is_no_longer_allowed_in_index_name", + "This index is named [" + clusterName + "], which contains the illegal character ':'."); + } + return null; + } } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java index dc9611c5e717a..95315e9418cb1 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/ClusterDeprecationChecksTests.java @@ -24,6 +24,23 @@ public class ClusterDeprecationChecksTests extends ESTestCase { + public void testCheckClusterName() { + final String badClusterName = randomAlphaOfLengthBetween(0, 10) + ":" + randomAlphaOfLengthBetween(0, 10); + final ClusterState badClusterState = ClusterState.builder(new ClusterName(badClusterName)).build(); + + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.CRITICAL, "Cluster name cannot contain ':'", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + + "#_literal_literal_is_no_longer_allowed_in_cluster_name", + "This cluster is named [" + badClusterName + "], which contains the illegal character ':'."); + List issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(badClusterState)); + assertEquals(singletonList(expected), issues); + + final String goodClusterName = randomAlphaOfLengthBetween(1,30); + final ClusterState goodClusterState = ClusterState.builder(new ClusterName(goodClusterName)).build(); + List noIssues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(goodClusterState)); + assertTrue(noIssues.isEmpty()); + } + public void testCheckShardLimit() { int shardsPerNode = randomIntBetween(2, 10000); int nodeCount = randomIntBetween(1, 10); diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java index 3020dc82e78f7..8255461c1bcdd 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/IndexDeprecationChecksTests.java @@ -51,4 +51,29 @@ public void testDelimitedPayloadFilterCheck() { List issues = DeprecationInfoAction.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(indexMetaData)); assertEquals(singletonList(expected), issues); } + + public void testIndexNameCheck(){ + final String badIndexName = randomAlphaOfLengthBetween(0, 10) + ":" + randomAlphaOfLengthBetween(0, 10); + final IndexMetaData badIndex = IndexMetaData.builder(badIndexName) + .settings(settings(Version.CURRENT)) + .numberOfShards(randomIntBetween(1,100)) + .numberOfReplicas(randomIntBetween(1,15)) + .build(); + + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, "Index name cannot contain ':'", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + + "#_literal_literal_is_no_longer_allowed_in_index_name", + "This index is named [" + badIndexName + "], which contains the illegal character ':'."); + List issues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(badIndex)); + assertEquals(singletonList(expected), issues); + + final String goodIndexName = randomAlphaOfLengthBetween(1,30); + final IndexMetaData goodIndex = IndexMetaData.builder(goodIndexName) + .settings(settings(Version.CURRENT)) + .numberOfShards(randomIntBetween(1,100)) + .numberOfReplicas(randomIntBetween(1,15)) + .build(); + List noIssues = DeprecationChecks.filterChecks(INDEX_SETTINGS_CHECKS, c -> c.apply(goodIndex)); + assertTrue(noIssues.isEmpty()); + } }