Skip to content

Commit

Permalink
Use OptionalInt for return value
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts195 committed Oct 25, 2023
1 parent b8d0343 commit 6ef7291
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ public static Tuple<MlConfigVersion, MlConfigVersion> 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.
Expand Down

0 comments on commit 6ef7291

Please sign in to comment.