Skip to content

Commit

Permalink
transport version as local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Oct 10, 2023
1 parent 9562fec commit e8731fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
3 changes: 0 additions & 3 deletions server/src/main/java/org/elasticsearch/TransportVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ static TransportVersion def(int id) {
public static final TransportVersion NESTED_KNN_VECTOR_QUERY_V = def(8_511_00_0);
public static final TransportVersion ML_PACKAGE_LOADER_PLATFORM_ADDED = def(8_512_00_0);
public static final TransportVersion ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH = def(8_512_00_1);
public static final TransportVersion PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME = def(8_513_00_0);
public static final TransportVersion UNIVERSAL_PROFILING_LICENSE_ADDED = def(8_514_00_0);
public static final TransportVersion ELSER_SERVICE_MODEL_VERSION_ADDED = def(8_515_00_0);
/*
* STOP! READ THIS FIRST! No, really,
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ public ElserMlNodeServiceSettings(StreamInput in) throws IOException {
}

static boolean transportVersionIsCompatibleWithElserModelVersion(TransportVersion transportVersion) {
var nextNonPatchVersion = TransportVersions.PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME;
var elserServiceModelVersionAdded = new TransportVersion(8_515_00_0);

if (transportVersion.onOrAfter(TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED)) {
if (transportVersion.onOrAfter(elserServiceModelVersionAdded)) {
return true;
} else {
var nextNonPatchVersion = new TransportVersion(8_513_00_0);
return transportVersion.onOrAfter(TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH)
&& transportVersion.before(nextNonPatchVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

package org.elasticsearch.xpack.inference.services.elser;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.ValidationException;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -70,6 +72,27 @@ public void testFromMapInvalidVersion() {
assertThat(e.getMessage(), containsString("unknown ELSER model version [.elser_model_27]"));
}

public void testBwcWrite() throws IOException {
{
var elserServiceModelVersionAdded = new TransportVersion(8_515_00_0);
var settings = new ElserMlNodeServiceSettings(1, 1, ".elser_model_1");
var copy = copyInstance(settings, elserServiceModelVersionAdded);
assertEquals(settings, copy);
}
{
var firstIncompatibleNotPatchVersion = new TransportVersion(8_513_00_0);
var settings = new ElserMlNodeServiceSettings(1, 1, ".elser_model_1");
var copy = copyInstance(settings, firstIncompatibleNotPatchVersion);
assertNotEquals(settings, copy);
assertEquals(".elser_model_2", copy.getModelVariant());
}
{
var settings = new ElserMlNodeServiceSettings(1, 1, ".elser_model_1");
var copy = copyInstance(settings, TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH);
assertEquals(settings, copy);
}
}

public void testFromMapMissingOptions() {
var e = expectThrows(
ValidationException.class,
Expand All @@ -87,11 +110,8 @@ public void testFromMapMissingOptions() {
}

public void testTransportVersionIsCompatibleWithElserModelVersion() {
assertTrue(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED
)
);
var elserServiceModelVersionAdded = new TransportVersion(8_515_00_0);
assertTrue(ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(elserServiceModelVersionAdded));
assertTrue(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.ELSER_SERVICE_MODEL_VERSION_ADDED_PATCH
Expand All @@ -101,16 +121,8 @@ public void testTransportVersionIsCompatibleWithElserModelVersion() {
assertFalse(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(TransportVersions.ML_PACKAGE_LOADER_PLATFORM_ADDED)
);
assertFalse(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME
)
);
assertFalse(
ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(
TransportVersions.UNIVERSAL_PROFILING_LICENSE_ADDED
)
);
var firstIncompatibleNotPatchVersion = new TransportVersion(8_513_00_0);
assertFalse(ElserMlNodeServiceSettings.transportVersionIsCompatibleWithElserModelVersion(firstIncompatibleNotPatchVersion));
}

public void testFromMapInvalidSettings() {
Expand Down

0 comments on commit e8731fa

Please sign in to comment.