diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index 72c98a7d30132..43f117acbd9fe 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.OptionalInt; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -488,14 +489,14 @@ public Version getVersion() { return this.versionInfo.nodeVersion(); } - public int getLegacyVersionIdOrThrow() { + public OptionalInt getPre811VersionId() { // Even if Version is removed from this class completely it will need to read the version ID // off the wire for old node versions, so the value of this variable can be obtained from that int versionId = versionInfo.nodeVersion().id; - if (versionId > Version.V_8_10_0.id) { - throw new IllegalStateException("getting legacy version id [" + versionId + "] not supported"); + if (versionId >= Version.V_8_11_0.id) { + return OptionalInt.empty(); } - return versionId; + return OptionalInt.of(versionId); } public IndexVersion getMinIndexVersion() { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java index c51e418e069d4..7ab8e41cd2453 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MlConfigVersion.java @@ -297,10 +297,10 @@ public static Tuple getMinMaxMlConfigVersion(D public static MlConfigVersion getMlConfigVersionForNode(DiscoveryNode node) { String mlConfigVerStr = node.getAttributes().get(ML_CONFIG_VERSION_NODE_ATTR); - if (mlConfigVerStr == null) { - return fromId(node.getLegacyVersionIdOrThrow()); + if (mlConfigVerStr != null) { + return fromString(mlConfigVerStr); } - return fromString(mlConfigVerStr); + return fromId(node.getPre811VersionId().orElseThrow(() -> new IllegalStateException("getting legacy version id not possible"))); } // Parse an MlConfigVersion from a string.