Skip to content
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
340136c
add primary patch version to transport version
jdconrad Jul 17, 2025
46cf098
add loading for new transport version model
jdconrad Jul 17, 2025
a4ec0d6
update transport versions holder
jdconrad Jul 17, 2025
dc9cfe9
fix bugs
jdconrad Jul 17, 2025
a20dfd7
Merge branch 'main' into transport0
jdconrad Jul 18, 2025
b772a3a
update name
jdconrad Jul 21, 2025
3182209
Merge branch 'main' into transport0
jdconrad Jul 21, 2025
8aa55ca
fix equals/hashcode/toString
jdconrad Jul 21, 2025
f13e723
spotless
jdconrad Jul 21, 2025
ead340b
Merge branch 'main' into transport0
jdconrad Jul 21, 2025
be9d70b
migrate version with multiple patches
jdconrad Jul 21, 2025
01511ff
spotless
jdconrad Jul 21, 2025
cba38b1
fix names
jdconrad Jul 21, 2025
f9bebe8
Merge branch 'main' into transport0
jdconrad Jul 21, 2025
b02cb1a
name fixes
jdconrad Jul 22, 2025
a19caac
Merge branch 'main' into transport0
jdconrad Jul 22, 2025
c56ec3a
move examples to tests
jdconrad Jul 22, 2025
75fbbe4
fix new instances
jdconrad Jul 22, 2025
c42bfc2
add versions to test files
jdconrad Jul 22, 2025
1b272b6
Merge branch 'main' into transport0
jdconrad Jul 22, 2025
da5491c
update tests
jdconrad Jul 22, 2025
c80f8fb
Merge branch 'main' into transport0
jdconrad Jul 22, 2025
19b1923
add java docs
jdconrad Jul 23, 2025
ac02157
move latest
jdconrad Jul 23, 2025
71d2cc4
Merge branch 'main' into transport0
jdconrad Jul 23, 2025
6f4dd0d
move latest
jdconrad Jul 23, 2025
38d5710
more pr responses
jdconrad Jul 23, 2025
eb0a94f
fix ij refactoring
jdconrad Jul 23, 2025
518ed4b
more fixed files
jdconrad Jul 23, 2025
14e2539
add latest placeholder files for backport versions
jdconrad Jul 23, 2025
ec39480
Merge branch 'main' into transport0
jdconrad Jul 23, 2025
18d2206
switch to loading versions with txt files instead of json
jdconrad Jul 23, 2025
aa7a4bc
revert lazy change
jdconrad Jul 23, 2025
5da94f9
Merge branch 'main' into transport0
jdconrad Jul 23, 2025
e097c7a
Merge branch 'main' into transport0
jdconrad Jul 24, 2025
8c8ecfc
update to use csv files and remove names from files when possible
jdconrad Jul 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testImdsNotAvailable() throws IOException {
final var bindTransportException = asInstanceOf(BindTransportException.class, executionException.getCause());
assertEquals("Failed to resolve publish address", bindTransportException.getMessage());
final var ioException = asInstanceOf(IOException.class, bindTransportException.getCause());
assertThat(ioException.getMessage(), containsString("/latest/meta-data/local-ipv4"));
assertThat(ioException.getMessage(), containsString("/transport/latest/meta-data/local-ipv4"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Settings additionalSettings() {
return getAvailabilityZoneNodeAttributes(settings);
}

private static final String IMDS_AVAILABILITY_ZONE_PATH = "/latest/meta-data/placement/availability-zone";
private static final String IMDS_AVAILABILITY_ZONE_PATH = "/transport/latest/meta-data/placement/availability-zone";

// pkg private for testing
static Settings getAvailabilityZoneNodeAttributes(Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public InetAddress[] resolveDefault() {
return null; // using this, one has to explicitly specify _ec2_ in network setting
}

private static final String IMDS_ADDRESS_PATH_PREFIX = "/latest/meta-data/";
private static final String IMDS_ADDRESS_PATH_PREFIX = "/transport/latest/meta-data/";

@Override
public InetAddress[] resolveIfPossible(String value) throws IOException {
Expand Down
269 changes: 256 additions & 13 deletions server/src/main/java/org/elasticsearch/TransportVersion.java

Large diffs are not rendered by default.

15 changes: 1 addition & 14 deletions server/src/main/java/org/elasticsearch/TransportVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.IntFunction;

/**
* <p>Transport version is used to coordinate compatible wire protocol communication between nodes, at a fine-grained level. This replaces
Expand All @@ -45,7 +44,7 @@ static TransportVersion def(int id) {
if (id < IDS.last()) {
throw new IllegalArgumentException("Version id " + id + " is not defined in the right location. Keep constants sorted");
}
return new TransportVersion(id);
return new TransportVersion(null, id, null);
}

// TODO: ES-10337 we can remove all transport versions earlier than 8.18
Expand Down Expand Up @@ -426,16 +425,6 @@ static TransportVersion def(int id) {
*/
static final List<TransportVersion> DEFINED_VERSIONS = collectAllVersionIdsDefinedInClass(TransportVersions.class);

// the highest transport version constant defined
static final TransportVersion LATEST_DEFINED;
static {
LATEST_DEFINED = DEFINED_VERSIONS.getLast();

// see comment on IDS field
// now we're registered all the transport versions, we can clear the map
IDS = null;
}

public static List<TransportVersion> collectAllVersionIdsDefinedInClass(Class<?> cls) {
Map<Integer, String> versionIdFields = new HashMap<>();
List<TransportVersion> definedTransportVersions = new ArrayList<>();
Expand Down Expand Up @@ -477,8 +466,6 @@ public static List<TransportVersion> collectAllVersionIdsDefinedInClass(Class<?>
return List.copyOf(definedTransportVersions);
}

static final IntFunction<String> VERSION_LOOKUP = ReleaseVersions.generateVersionsLookup(TransportVersions.class, LATEST_DEFINED.id());

// no instance
private TransportVersions() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DesiredNodesMetadata extends AbstractNamedDiffable<Metadata.Cluster

public static final DesiredNodesMetadata EMPTY = new DesiredNodesMetadata((DesiredNodes) null);

private static final ParseField LATEST_FIELD = new ParseField("latest");
private static final ParseField LATEST_FIELD = new ParseField("transport/latest");

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<DesiredNodesMetadata, Void> PARSER = new ConstructingObjectParser<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@
*/
public abstract class StreamInput extends InputStream {

private TransportVersion version = TransportVersion.current();
private TransportVersion version;

/**
* The transport version the data is serialized as.
*/
public TransportVersion getTransportVersion() {
if (version == null) {
version = TransportVersion.current();
}
return this.version;
}

Expand Down
6 changes: 6 additions & 0 deletions server/src/main/resources/transport/latest/9.2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "placeholder",
"ids": [
9130000
]
}
108 changes: 108 additions & 0 deletions server/src/test/java/org/elasticsearch/TransportVersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,112 @@ public void testDuplicateConstants() {
previous = next;
}
}

public void testFromName() {
assertThat(TransportVersion.fromName("test-0"), is(new TransportVersion("test-0", 3001000, null)));
assertThat(TransportVersion.fromName("test-1"), is(new TransportVersion("test-1", 3002000, null)));
assertThat(
TransportVersion.fromName("test-2"),
is(
new TransportVersion(
"test-2",
3003000,
new TransportVersion("test-2", 2001001, new TransportVersion("test-2", 1001001, null))
)
)
);
assertThat(
TransportVersion.fromName("test-3"),
is(new TransportVersion("test-3", 3003001, new TransportVersion("test-3", 2001002, null)))
);
assertThat(
TransportVersion.fromName("test-4"),
is(
new TransportVersion(
"test-4",
3003002,
new TransportVersion("test-4", 2001003, new TransportVersion("test-4", 1001002, null))
)
)
);
}

public void testSupports() {
TransportVersion test0 = TransportVersion.fromName("test-0");
assertThat(new TransportVersion(null, 2003000, null).supports(test0), is(false));
assertThat(new TransportVersion(null, 3001000, null).supports(test0), is(true));
assertThat(new TransportVersion(null, 100001001, null).supports(test0), is(true));

TransportVersion test1 = TransportVersion.fromName("test-1");
assertThat(new TransportVersion(null, 2003000, null).supports(test1), is(false));
assertThat(new TransportVersion(null, 3001000, null).supports(test1), is(false));
assertThat(new TransportVersion(null, 3001001, null).supports(test1), is(false));
assertThat(new TransportVersion(null, 3002000, null).supports(test1), is(true));
assertThat(new TransportVersion(null, 100001000, null).supports(test1), is(true));
assertThat(new TransportVersion(null, 100001001, null).supports(test1), is(true));

TransportVersion test2 = TransportVersion.fromName("test-2");
assertThat(new TransportVersion(null, 1001000, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 1001001, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 1001002, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 1002000, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 1002001, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 2001000, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 2001001, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 2001002, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 2003000, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 2003001, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 3001000, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 3001001, null).supports(test2), is(false));
assertThat(new TransportVersion(null, 3003000, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 3003001, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 3003002, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 3003003, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 100001000, null).supports(test2), is(true));
assertThat(new TransportVersion(null, 100001001, null).supports(test2), is(true));

TransportVersion test3 = TransportVersion.fromName("test-3");
assertThat(new TransportVersion(null, 1001001, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 1001002, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 1001003, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 1002001, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 1002002, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 2001001, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 2001002, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 2001003, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 2003000, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 2003001, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 3001000, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 3001001, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 3003000, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 3003001, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 3003002, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 3003003, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 3004000, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 100001000, null).supports(test3), is(true));
assertThat(new TransportVersion(null, 100001001, null).supports(test3), is(true));

TransportVersion test4 = TransportVersion.fromName("test-4");
assertThat(new TransportVersion(null, 1001001, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 1001002, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 1001003, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 1002001, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 1002002, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 1002003, null).supports(test3), is(false));
assertThat(new TransportVersion(null, 2001002, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 2001003, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 2001004, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 2003000, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 2003001, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 3001000, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 3001001, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 3003000, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 3003001, null).supports(test4), is(false));
assertThat(new TransportVersion(null, 3003002, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 3003003, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 3003004, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 3004000, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 100001000, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 100001001, null).supports(test4), is(true));
}
}
5 changes: 5 additions & 0 deletions server/src/test/resources/transport/constant/manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test-0.json
test-1.json
test-2.json
test-3.json
test-4.json
7 changes: 7 additions & 0 deletions server/src/test/resources/transport/constant/test-0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "test-0",
"ids": [
100001000,
3001000
]
}
6 changes: 6 additions & 0 deletions server/src/test/resources/transport/constant/test-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "test-1",
"ids": [
3002000
]
}
8 changes: 8 additions & 0 deletions server/src/test/resources/transport/constant/test-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-2",
"ids": [
3003000,
2001001,
1001001
]
}
8 changes: 8 additions & 0 deletions server/src/test/resources/transport/constant/test-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-3",
"ids": [
100002000,
3003001,
2001002
]
}
9 changes: 9 additions & 0 deletions server/src/test/resources/transport/constant/test-4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "test-4",
"ids": [
100002000,
3003002,
2001003,
1001002
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@SuppressForbidden(reason = "this test uses a HttpServer to emulate the EC2 IMDS endpoint")
public class Ec2ImdsHttpHandler implements HttpHandler {

private static final String IMDS_SECURITY_CREDENTIALS_PATH = "/latest/meta-data/iam/security-credentials/";
private static final String IMDS_SECURITY_CREDENTIALS_PATH = "/transport/latest/meta-data/iam/security-credentials/";

private final Ec2ImdsVersion ec2ImdsVersion;
private final Set<String> validImdsTokens = ConcurrentCollections.newConcurrentSet();
Expand Down Expand Up @@ -90,7 +90,7 @@ public void handle(final HttpExchange exchange) throws IOException {
final var path = exchange.getRequestURI().getPath();
final var requestMethod = exchange.getRequestMethod();

if ("PUT".equals(requestMethod) && "/latest/api/token".equals(path)) {
if ("PUT".equals(requestMethod) && "/transport/latest/api/token".equals(path)) {
switch (ec2ImdsVersion) {
case V1 -> exchange.sendResponseHeaders(RestStatus.METHOD_NOT_ALLOWED.getStatus(), -1);
case V2 -> {
Expand Down Expand Up @@ -125,11 +125,11 @@ public void handle(final HttpExchange exchange) throws IOException {
validCredentialsEndpoints.add(IMDS_SECURITY_CREDENTIALS_PATH + profileName);
sendStringResponse(exchange, profileName);
return;
} else if (path.equals("/latest/meta-data/placement/availability-zone")) {
} else if (path.equals("/transport/latest/meta-data/placement/availability-zone")) {
final var availabilityZone = availabilityZoneSupplier.get();
sendStringResponse(exchange, availabilityZone);
return;
} else if (instanceIdentityDocument != null && path.equals("/latest/dynamic/instance-identity/document")) {
} else if (instanceIdentityDocument != null && path.equals("/transport/latest/dynamic/instance-identity/document")) {
sendStringResponse(exchange, Strings.toString(instanceIdentityDocument));
return;
} else if (validCredentialsEndpoints.contains(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Ec2ImdsServiceBuilder availabilityZoneSupplier(Supplier<String> availabil
}

public Ec2ImdsServiceBuilder addInstanceAddress(String addressType, String addressValue) {
instanceAddresses.put("/latest/meta-data/" + addressType, addressValue);
instanceAddresses.put("/transport/latest/meta-data/" + addressType, addressValue);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public class Ec2ImdsHttpHandlerTests extends ESTestCase {

private static final String SECURITY_CREDENTIALS_URI = "/latest/meta-data/iam/security-credentials/";
private static final String SECURITY_CREDENTIALS_URI = "/transport/latest/meta-data/iam/security-credentials/";

public void testImdsV1() throws IOException {
final Map<String, String> generatedCredentials = new HashMap<>();
Expand All @@ -64,7 +64,7 @@ public void testImdsV1() throws IOException {
public void testImdsV2Disabled() {
assertEquals(
RestStatus.METHOD_NOT_ALLOWED,
handleRequest(new Ec2ImdsServiceBuilder(Ec2ImdsVersion.V1).buildHandler(), "PUT", "/latest/api/token").status()
handleRequest(new Ec2ImdsServiceBuilder(Ec2ImdsVersion.V1).buildHandler(), "PUT", "/transport/latest/api/token").status()
);
}

Expand All @@ -73,7 +73,7 @@ public void testImdsV2() throws IOException {

final var handler = new Ec2ImdsServiceBuilder(Ec2ImdsVersion.V2).newCredentialsConsumer(generatedCredentials::put).buildHandler();

final var tokenResponse = handleRequest(handler, "PUT", "/latest/api/token");
final var tokenResponse = handleRequest(handler, "PUT", "/transport/latest/api/token");
assertEquals(RestStatus.OK, tokenResponse.status());
assertEquals(List.of("86400" /* seconds in a day */), tokenResponse.responseHeaders().get("x-aws-ec2-metadata-token-ttl-seconds"));
final var token = tokenResponse.body().utf8ToString();
Expand Down Expand Up @@ -101,7 +101,7 @@ public void testAvailabilityZone() {
return newAvailabilityZone;
}).buildHandler();

final var availabilityZoneResponse = handleRequest(handler, "GET", "/latest/meta-data/placement/availability-zone");
final var availabilityZoneResponse = handleRequest(handler, "GET", "/transport/latest/meta-data/placement/availability-zone");
assertEquals(RestStatus.OK, availabilityZoneResponse.status());
final var availabilityZone = availabilityZoneResponse.body().utf8ToString();

Expand Down Expand Up @@ -148,7 +148,7 @@ public void testInstanceIdentityDocument() {
return builder.field("region", newRegion);
}).buildHandler();

final var instanceIdentityResponse = handleRequest(handler, "GET", "/latest/dynamic/instance-identity/document");
final var instanceIdentityResponse = handleRequest(handler, "GET", "/transport/latest/dynamic/instance-identity/document");
assertEquals(RestStatus.OK, instanceIdentityResponse.status());
final var instanceIdentityString = instanceIdentityResponse.body().utf8ToString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FieldStats implements ToXContentObject, Writeable {
static final ParseField MEAN_VALUE = new ParseField("mean_value");
static final ParseField MEDIAN_VALUE = new ParseField("median_value");
static final ParseField EARLIEST = new ParseField("earliest");
static final ParseField LATEST = new ParseField("latest");
static final ParseField LATEST = new ParseField("transport/latest");
static final ParseField TOP_HITS = new ParseField("top_hits");

@SuppressWarnings("unchecked")
Expand Down