diff --git a/server/src/main/java/org/elasticsearch/Build.java b/server/src/main/java/org/elasticsearch/Build.java index 50f03a8e1dda8..be76564e52f6b 100644 --- a/server/src/main/java/org/elasticsearch/Build.java +++ b/server/src/main/java/org/elasticsearch/Build.java @@ -130,21 +130,6 @@ public static String minimumCompatString(IndexVersion minimumCompatible) { } } - /** - * Check whether a node version is compatible with the current minimum transport version. - * @param version A version identifier as a string - * @throws IllegalArgumentException if version is not a valid transport version identifier - * @return true if the version is compatible, false otherwise - */ - public static boolean isNodeVersionWireCompatible(String version) { - try { - Version esVersion = Version.fromString(version); - return esVersion.onOrAfter(Version.CURRENT.minimumCompatibilityVersion()); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("Cannot parse [" + version + "] as a transport version identifier", e); - } - } - public static Build current() { return CurrentHolder.CURRENT; } diff --git a/server/src/main/java/org/elasticsearch/env/NodeMetadata.java b/server/src/main/java/org/elasticsearch/env/NodeMetadata.java index ce046aa3445fd..37dd01733e664 100644 --- a/server/src/main/java/org/elasticsearch/env/NodeMetadata.java +++ b/server/src/main/java/org/elasticsearch/env/NodeMetadata.java @@ -113,7 +113,7 @@ public void verifyUpgradeToCurrentVersion() { assert (nodeVersion.equals(Version.V_EMPTY) == false) || (Version.CURRENT.major <= Version.V_7_0_0.major + 1) : "version is required in the node metadata from v9 onwards"; - if (Build.isNodeVersionWireCompatible(nodeVersion.toString()) == false) { + if (NodeMetadata.isNodeVersionWireCompatible(nodeVersion.toString()) == false) { throw new IllegalStateException( "cannot upgrade a node from version [" + nodeVersion @@ -220,4 +220,21 @@ public NodeMetadata fromXContent(XContentParser parser) throws IOException { } public static final MetadataStateFormat FORMAT = new NodeMetadataStateFormat(false); + + /** + * Check whether a node version is compatible with the current minimum transport version. + * @param version A version identifier as a string + * @throws IllegalArgumentException if version is not a valid transport version identifier + * @return true if the version is compatible, false otherwise + */ + // visible for testing + static boolean isNodeVersionWireCompatible(String version) { + try { + Version esVersion = Version.fromString(version); + return esVersion.onOrAfter(Version.CURRENT.minimumCompatibilityVersion()); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("Cannot parse [" + version + "] as a transport version identifier", e); + } + } + } diff --git a/server/src/test/java/org/elasticsearch/BuildTests.java b/server/src/test/java/org/elasticsearch/BuildTests.java index fa266e6e7fb11..dfb6eb492507d 100644 --- a/server/src/test/java/org/elasticsearch/BuildTests.java +++ b/server/src/test/java/org/elasticsearch/BuildTests.java @@ -14,8 +14,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; -import org.elasticsearch.test.TransportVersionUtils; -import org.elasticsearch.test.VersionUtils; import java.io.IOException; import java.io.InputStream; @@ -121,20 +119,4 @@ public void testStrictTypeParsing() { assertThat(e, hasToString(containsString("unexpected distribution type [" + displayName + "]; your distribution is broken"))); } - public void testIsNodeVersionWireCompatible() { - String nodeVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT).toString(); - assertTrue(Build.isNodeVersionWireCompatible(nodeVersion)); - nodeVersion = VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()).toString(); - assertFalse(Build.isNodeVersionWireCompatible(nodeVersion)); - - String transportVersion = TransportVersionUtils.randomCompatibleVersion(random()).toString(); - IllegalArgumentException e1 = expectThrows( - IllegalArgumentException.class, - () -> Build.isNodeVersionWireCompatible(transportVersion) - ); - assertThat(e1.getMessage(), equalTo("Cannot parse [" + transportVersion + "] as a transport version identifier")); - - IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> Build.isNodeVersionWireCompatible("x.y.z")); - assertThat(e2.getMessage(), equalTo("Cannot parse [x.y.z] as a transport version identifier")); - } } diff --git a/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java b/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java index 44ef31cfbd9d7..6a309767878c4 100644 --- a/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java +++ b/server/src/test/java/org/elasticsearch/env/NodeMetadataTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.index.IndexVersion; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; +import org.elasticsearch.test.TransportVersionUtils; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.index.IndexVersionUtils; @@ -158,6 +159,23 @@ public void testUpgradeMarksPreviousVersion() { assertThat(nodeMetadata.previousNodeVersion(), equalTo(version)); } + public void testIsNodeVersionWireCompatible() { + String nodeVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT).toString(); + assertTrue(NodeMetadata.isNodeVersionWireCompatible(nodeVersion)); + nodeVersion = VersionUtils.getPreviousVersion(Version.CURRENT.minimumCompatibilityVersion()).toString(); + assertFalse(NodeMetadata.isNodeVersionWireCompatible(nodeVersion)); + + String transportVersion = TransportVersionUtils.randomCompatibleVersion(random()).toString(); + IllegalArgumentException e1 = expectThrows( + IllegalArgumentException.class, + () -> NodeMetadata.isNodeVersionWireCompatible(transportVersion) + ); + assertThat(e1.getMessage(), equalTo("Cannot parse [" + transportVersion + "] as a transport version identifier")); + + IllegalArgumentException e2 = expectThrows(IllegalArgumentException.class, () -> NodeMetadata.isNodeVersionWireCompatible("x.y.z")); + assertThat(e2.getMessage(), equalTo("Cannot parse [x.y.z] as a transport version identifier")); + } + public static Version tooNewVersion() { return Version.fromId(between(Version.CURRENT.id + 1, 99999999)); }