Skip to content

Commit bc5d050

Browse files
authored
[grid] Improve Docker client for Dynamic Grid (#16596)
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
1 parent 1df75c1 commit bc5d050

23 files changed

+799
-75
lines changed

java/src/org/openqa/selenium/docker/Docker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Docker(HttpHandler client) {
3737
* Creates a Docker client with an optional API version override.
3838
*
3939
* @param client HTTP client for Docker communication
40-
* @param apiVersion Optional API version to use (e.g., "1.41" or "1.44"). If null, the version
40+
* @param apiVersion Optional API version to use (e.g., "1.40" or "1.44"). If null, the version
4141
* will be auto-detected.
4242
*/
4343
public Docker(HttpHandler client, String apiVersion) {

java/src/org/openqa/selenium/docker/VersionCommand.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ class VersionCommand {
3939
private static final Json JSON = new Json();
4040
// Insertion order matters, and is preserved by ImmutableMap.
4141
// Map Docker API versions to their implementations
42-
// 1.44 is the default for Docker Engine 29.0.0+
43-
// 1.41 is maintained for backward compatibility with legacy engines
44-
// Both use the same generic implementation with different API version strings
42+
// 1.48 is for Docker Engine v28+ with multi-platform and gateway priority support
43+
// 1.44 is for Docker Engine v25+ with multi-network and modern features
44+
// 1.40 is maintained for backward compatibility with legacy engines (Docker v19.03+)
45+
// All use the same generic implementation with version-specific adapters
4546
private static final Map<Version, Function<HttpHandler, DockerProtocol>> SUPPORTED_VERSIONS =
4647
ImmutableMap.of(
48+
new Version("1.48"), client -> new DockerClient(client, "1.48"),
4749
new Version("1.44"), client -> new DockerClient(client, "1.44"),
48-
new Version("1.41"), client -> new DockerClient(client, "1.41"),
4950
new Version("1.40"), client -> new DockerClient(client, "1.40"));
5051

5152
private final HttpHandler handler;
@@ -56,10 +57,10 @@ public VersionCommand(HttpHandler handler) {
5657

5758
/**
5859
* Gets the Docker protocol implementation for a user-specified API version. This allows users to
59-
* override the automatic version detection and force a specific API version (e.g., 1.41 for
60+
* override the automatic version detection and force a specific API version (e.g., 1.40 for
6061
* legacy Docker engines).
6162
*
62-
* @param requestedVersion The API version to use (e.g., "1.41" or "1.44")
63+
* @param requestedVersion The API version to use (e.g., "1.40" or "1.44")
6364
* @return Optional containing the DockerProtocol implementation if the version is supported
6465
*/
6566
public Optional<DockerProtocol> getDockerProtocol(String requestedVersion) {

java/src/org/openqa/selenium/docker/client/AdapterFactory.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
*
2727
* <ul>
2828
* <li>API v1.40-1.43: Uses {@link V140Adapter}
29-
* <li>API v1.44+: Uses {@link V144Adapter}
29+
* <li>API v1.44-1.47: Uses {@link V144Adapter}
30+
* <li>API v1.48+: Uses {@link V148Adapter}
3031
* </ul>
3132
*
3233
* <p>The factory uses version comparison to determine which adapter to use, ensuring that future
33-
* API versions (e.g., 1.45, 1.46) automatically use the most appropriate adapter.
34+
* API versions automatically use the most appropriate adapter.
3435
*/
3536
class AdapterFactory {
3637

@@ -39,7 +40,7 @@ class AdapterFactory {
3940
/**
4041
* Creates an appropriate adapter for the given API version.
4142
*
42-
* @param apiVersion The Docker API version (e.g., "1.40", "1.44")
43+
* @param apiVersion The Docker API version (e.g., "1.40", "1.44", "1.48")
4344
* @return An adapter suitable for the specified API version
4445
* @throws IllegalArgumentException if apiVersion is null or empty
4546
*/
@@ -48,7 +49,13 @@ public static ApiVersionAdapter createAdapter(String apiVersion) {
4849
throw new IllegalArgumentException("API version cannot be null or empty");
4950
}
5051

51-
// API v1.44+ uses the new adapter
52+
// API v1.48+ uses the latest adapter with multi-platform and gateway priority support
53+
if (compareVersions(apiVersion, "1.48") >= 0) {
54+
LOG.fine("Using V148Adapter for API version " + apiVersion);
55+
return new V148Adapter(apiVersion);
56+
}
57+
58+
// API v1.44-1.47 uses the v1.44 adapter
5259
if (compareVersions(apiVersion, "1.44") >= 0) {
5360
LOG.fine("Using V144Adapter for API version " + apiVersion);
5461
return new V144Adapter(apiVersion);

java/src/org/openqa/selenium/docker/client/CreateContainer.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium.docker.client;
1919

20-
import static org.openqa.selenium.docker.client.DockerClient.DOCKER_API_VERSION;
2120
import static org.openqa.selenium.json.Json.JSON_UTF_8;
2221
import static org.openqa.selenium.json.Json.MAP_TYPE;
2322
import static org.openqa.selenium.remote.http.Contents.asJson;
@@ -48,14 +47,6 @@ class CreateContainer {
4847
private final String apiVersion;
4948
private final ApiVersionAdapter adapter;
5049

51-
public CreateContainer(DockerProtocol protocol, HttpHandler client) {
52-
this(protocol, client, DOCKER_API_VERSION, AdapterFactory.createAdapter(DOCKER_API_VERSION));
53-
}
54-
55-
public CreateContainer(DockerProtocol protocol, HttpHandler client, String apiVersion) {
56-
this(protocol, client, apiVersion, AdapterFactory.createAdapter(apiVersion));
57-
}
58-
5950
public CreateContainer(
6051
DockerProtocol protocol, HttpHandler client, String apiVersion, ApiVersionAdapter adapter) {
6152
this.protocol = Require.nonNull("Protocol", protocol);

java/src/org/openqa/selenium/docker/client/DockerClient.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
public class DockerClient implements DockerProtocol {
3636

37-
static final String DOCKER_API_VERSION = "1.41";
3837
private static final Logger LOG = Logger.getLogger(DockerClient.class.getName());
3938
private final String apiVersion;
4039
private final ApiVersionAdapter adapter;
@@ -47,10 +46,6 @@ public class DockerClient implements DockerProtocol {
4746
private final InspectContainer inspectContainer;
4847
private final GetContainerLogs containerLogs;
4948

50-
public DockerClient(HttpHandler client) {
51-
this(client, DOCKER_API_VERSION);
52-
}
53-
5449
public DockerClient(HttpHandler client, String apiVersion) {
5550
Require.nonNull("HTTP client", client);
5651
this.apiVersion = Require.nonNull("API version", apiVersion);

java/src/org/openqa/selenium/docker/client/GetContainerLogs.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openqa.selenium.docker.client;
1919

2020
import static java.net.HttpURLConnection.HTTP_OK;
21-
import static org.openqa.selenium.docker.client.DockerClient.DOCKER_API_VERSION;
2221
import static org.openqa.selenium.remote.http.HttpMethod.GET;
2322

2423
import java.util.Arrays;
@@ -38,10 +37,6 @@ class GetContainerLogs {
3837
private final HttpHandler client;
3938
private final String apiVersion;
4039

41-
public GetContainerLogs(HttpHandler client) {
42-
this(client, DOCKER_API_VERSION);
43-
}
44-
4540
public GetContainerLogs(HttpHandler client, String apiVersion) {
4641
this.client = Require.nonNull("HTTP client", client);
4742
this.apiVersion = Require.nonNull("API version", apiVersion);

java/src/org/openqa/selenium/docker/client/InspectContainer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openqa.selenium.docker.client;
1919

2020
import static java.net.HttpURLConnection.HTTP_OK;
21-
import static org.openqa.selenium.docker.client.DockerClient.DOCKER_API_VERSION;
2221
import static org.openqa.selenium.json.Json.MAP_TYPE;
2322
import static org.openqa.selenium.remote.http.HttpMethod.GET;
2423

@@ -44,10 +43,6 @@ class InspectContainer {
4443
private final String apiVersion;
4544
private final ApiVersionAdapter adapter;
4645

47-
public InspectContainer(HttpHandler client) {
48-
this(client, DOCKER_API_VERSION, AdapterFactory.createAdapter(DOCKER_API_VERSION));
49-
}
50-
5146
public InspectContainer(HttpHandler client, String apiVersion) {
5247
this(client, apiVersion, AdapterFactory.createAdapter(apiVersion));
5348
}

java/src/org/openqa/selenium/docker/client/IsContainerPresent.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium.docker.client;
1919

20-
import static org.openqa.selenium.docker.client.DockerClient.DOCKER_API_VERSION;
2120
import static org.openqa.selenium.remote.http.HttpMethod.GET;
2221

2322
import org.openqa.selenium.docker.ContainerId;
@@ -30,10 +29,6 @@ class IsContainerPresent {
3029
private final HttpHandler client;
3130
private final String apiVersion;
3231

33-
public IsContainerPresent(HttpHandler client) {
34-
this(client, DOCKER_API_VERSION);
35-
}
36-
3732
public IsContainerPresent(HttpHandler client, String apiVersion) {
3833
this.client = Require.nonNull("Http client", client);
3934
this.apiVersion = Require.nonNull("API version", apiVersion);

java/src/org/openqa/selenium/docker/client/ListImages.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openqa.selenium.docker.client;
1919

2020
import static com.google.common.collect.ImmutableSet.toImmutableSet;
21-
import static org.openqa.selenium.docker.client.DockerClient.DOCKER_API_VERSION;
2221
import static org.openqa.selenium.json.Json.JSON_UTF_8;
2322
import static org.openqa.selenium.remote.http.Contents.string;
2423
import static org.openqa.selenium.remote.http.HttpMethod.GET;
@@ -47,10 +46,6 @@ class ListImages {
4746
private final String apiVersion;
4847
private final ApiVersionAdapter adapter;
4948

50-
public ListImages(HttpHandler client) {
51-
this(client, DOCKER_API_VERSION, AdapterFactory.createAdapter(DOCKER_API_VERSION));
52-
}
53-
5449
public ListImages(HttpHandler client, String apiVersion) {
5550
this(client, apiVersion, AdapterFactory.createAdapter(apiVersion));
5651
}
@@ -67,7 +62,7 @@ public Set<Image> apply(Reference reference) {
6762
String familiarName = reference.getFamiliarName();
6863
Map<String, Object> filters = ImmutableMap.of("reference", ImmutableMap.of(familiarName, true));
6964

70-
// https://docs.docker.com/engine/api/v1.41/#operation/ImageList
65+
// https://docs.docker.com/engine/api/v1.40/#operation/ImageList
7166
HttpRequest req =
7267
new HttpRequest(GET, String.format("/v%s/images/json", apiVersion))
7368
.addHeader("Content-Type", JSON_UTF_8)

java/src/org/openqa/selenium/docker/client/PullImage.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.openqa.selenium.docker.client;
1919

20-
import static org.openqa.selenium.docker.client.DockerClient.DOCKER_API_VERSION;
2120
import static org.openqa.selenium.json.Json.JSON_UTF_8;
2221
import static org.openqa.selenium.json.Json.MAP_TYPE;
2322
import static org.openqa.selenium.remote.http.HttpMethod.POST;
@@ -39,10 +38,6 @@ class PullImage {
3938
private final HttpHandler client;
4039
private final String apiVersion;
4140

42-
public PullImage(HttpHandler client) {
43-
this(client, DOCKER_API_VERSION);
44-
}
45-
4641
public PullImage(HttpHandler client, String apiVersion) {
4742
this.client = Require.nonNull("HTTP client", client);
4843
this.apiVersion = Require.nonNull("API version", apiVersion);

0 commit comments

Comments
 (0)