Skip to content

Commit fb4d714

Browse files
committed
[grid] Moving to Docker API 1.41
1 parent 8755948 commit fb4d714

14 files changed

+63
-51
lines changed

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

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

1818
package org.openqa.selenium.docker;
1919

20-
import static org.openqa.selenium.json.Json.MAP_TYPE;
21-
import static org.openqa.selenium.remote.http.HttpMethod.GET;
22-
2320
import com.google.common.collect.ImmutableMap;
2421

25-
import org.openqa.selenium.docker.v1_40.V140Docker;
22+
import org.openqa.selenium.docker.v1_41.V141Docker;
2623
import org.openqa.selenium.internal.Require;
2724
import org.openqa.selenium.json.Json;
2825
import org.openqa.selenium.json.JsonException;
@@ -36,12 +33,15 @@
3633
import java.util.Optional;
3734
import java.util.function.Function;
3835

36+
import static org.openqa.selenium.json.Json.MAP_TYPE;
37+
import static org.openqa.selenium.remote.http.HttpMethod.GET;
38+
3939
class VersionCommand {
4040

4141
private static final Json JSON = new Json();
4242
// Insertion order matters, and is preserved by ImmutableMap.
43-
private static final Map<Version, Function<HttpHandler, DockerProtocol>> SUPPORTED_VERSIONS = ImmutableMap.of(
44-
new Version("1.40"), V140Docker::new);
43+
private static final Map<Version, Function<HttpHandler, DockerProtocol>>
44+
SUPPORTED_VERSIONS = ImmutableMap.of(new Version("1.40"), V141Docker::new);
4545

4646
private final HttpHandler handler;
4747

java/server/src/org/openqa/selenium/docker/v1_40/CreateContainer.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/CreateContainer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.Container;
2121
import org.openqa.selenium.docker.ContainerConfig;
@@ -35,6 +35,7 @@
3535
import java.util.logging.Logger;
3636
import java.util.stream.Collectors;
3737

38+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
3839
import static org.openqa.selenium.json.Json.JSON_UTF_8;
3940
import static org.openqa.selenium.json.Json.MAP_TYPE;
4041
import static org.openqa.selenium.remote.http.Contents.asJson;
@@ -54,7 +55,7 @@ public CreateContainer(DockerProtocol protocol, HttpHandler client) {
5455
public Container apply(ContainerConfig info) {
5556
HttpResponse res = DockerMessages.throwIfNecessary(
5657
client.execute(
57-
new HttpRequest(POST, "/v1.40/containers/create")
58+
new HttpRequest(POST, String.format("/v%s/containers/create", DOCKER_API_VERSION))
5859
.addHeader("Content-Type", JSON_UTF_8)
5960
.setContent(asJson(info))),
6061
"Unable to create container: ",

java/server/src/org/openqa/selenium/docker/v1_40/DockerMessages.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/DockerMessages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.DockerException;
2121
import org.openqa.selenium.internal.Require;

java/server/src/org/openqa/selenium/docker/v1_40/GetContainerLogs.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/GetContainerLogs.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
19-
20-
import static java.net.HttpURLConnection.HTTP_OK;
21-
import static org.openqa.selenium.remote.http.HttpMethod.GET;
18+
package org.openqa.selenium.docker.v1_41;
2219

2320
import org.openqa.selenium.docker.ContainerId;
2421
import org.openqa.selenium.docker.ContainerLogs;
@@ -32,7 +29,12 @@
3229
import java.util.List;
3330
import java.util.logging.Logger;
3431

32+
import static java.net.HttpURLConnection.HTTP_OK;
33+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
34+
import static org.openqa.selenium.remote.http.HttpMethod.GET;
35+
3536
class GetContainerLogs {
37+
3638
private static final Logger LOG = Logger.getLogger(GetContainerLogs.class.getName());
3739
private final HttpHandler client;
3840

@@ -44,7 +46,7 @@ public ContainerLogs apply(ContainerId id) {
4446
Require.nonNull("Container id", id);
4547

4648
String requestUrl =
47-
String.format("/v1.40/containers/%s/logs?stdout=true&stderr=true", id);
49+
String.format("/v%s/containers/%s/logs?stdout=true&stderr=true", DOCKER_API_VERSION, id);
4850

4951
HttpResponse res = client.execute(
5052
new HttpRequest(GET, requestUrl)

java/server/src/org/openqa/selenium/docker/v1_40/InspectContainer.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/InspectContainer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.ContainerId;
2121
import org.openqa.selenium.docker.ContainerInfo;
@@ -33,6 +33,7 @@
3333
import java.util.stream.Collectors;
3434

3535
import static java.net.HttpURLConnection.HTTP_OK;
36+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
3637
import static org.openqa.selenium.json.Json.MAP_TYPE;
3738
import static org.openqa.selenium.remote.http.HttpMethod.GET;
3839

@@ -50,7 +51,7 @@ public ContainerInfo apply(ContainerId id) {
5051
Require.nonNull("Container id", id);
5152

5253
HttpResponse res = client.execute(
53-
new HttpRequest(GET, String.format("/v1.40/containers/%s/json", id))
54+
new HttpRequest(GET, String.format("/v%s/containers/%s/json", DOCKER_API_VERSION, id))
5455
.addHeader("Content-Length", "0")
5556
.addHeader("Content-Type", "text/plain"));
5657
if (res.getStatus() != HTTP_OK) {

java/server/src/org/openqa/selenium/docker/v1_40/IsContainerPresent.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/IsContainerPresent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.ContainerId;
2121
import org.openqa.selenium.internal.Require;
2222
import org.openqa.selenium.remote.http.HttpHandler;
2323
import org.openqa.selenium.remote.http.HttpRequest;
2424
import org.openqa.selenium.remote.http.HttpResponse;
2525

26+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
2627
import static org.openqa.selenium.remote.http.HttpMethod.GET;
2728

2829
class IsContainerPresent {
@@ -36,7 +37,7 @@ public boolean apply(ContainerId id) {
3637
Require.nonNull("Container id", id);
3738

3839
HttpResponse res = client.execute(
39-
new HttpRequest(GET, String.format("/v1.40/containers/%s/json", id))
40+
new HttpRequest(GET, String.format("/v%s/containers/%s/json", DOCKER_API_VERSION, id))
4041
.addHeader("Content-Length", "0")
4142
.addHeader("Content-Type", "text/plain"));
4243

java/server/src/org/openqa/selenium/docker/v1_40/ListImages.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/ListImages.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import com.google.common.collect.ImmutableMap;
21+
2122
import org.openqa.selenium.docker.Image;
2223
import org.openqa.selenium.docker.internal.ImageSummary;
2324
import org.openqa.selenium.docker.internal.Reference;
@@ -33,6 +34,7 @@
3334
import java.util.Set;
3435

3536
import static com.google.common.collect.ImmutableSet.toImmutableSet;
37+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
3638
import static org.openqa.selenium.json.Json.JSON_UTF_8;
3739
import static org.openqa.selenium.remote.http.Contents.string;
3840
import static org.openqa.selenium.remote.http.HttpMethod.GET;
@@ -54,15 +56,15 @@ public Set<Image> apply(Reference reference) {
5456
String familiarName = reference.getFamiliarName();
5557
Map<String, Object> filters = ImmutableMap.of("reference", ImmutableMap.of(familiarName, true));
5658

57-
// https://docs.docker.com/engine/api/v1.40/#operation/ImageList
58-
HttpRequest req = new HttpRequest(GET, "/v1.40/images/json")
59+
// https://docs.docker.com/engine/api/v1.41/#operation/ImageList
60+
HttpRequest req = new HttpRequest(GET, String.format("/v%s/images/json", DOCKER_API_VERSION))
5961
.addHeader("Content-Length", "0")
6062
.addHeader("Content-Type", JSON_UTF_8)
6163
.addQueryParameter("filters", JSON.toJson(filters));
6264

6365
HttpResponse response = DockerMessages.throwIfNecessary(
6466
client.execute(req),
65-
"Unable to list images for %s", reference);
67+
"Unable to list images for %s", reference);
6668

6769
Set<ImageSummary> images =
6870
JSON.toType(string(response), SET_OF_IMAGE_SUMMARIES);

java/server/src/org/openqa/selenium/docker/v1_40/PullImage.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/PullImage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.DockerException;
2121
import org.openqa.selenium.docker.internal.Reference;
@@ -29,6 +29,7 @@
2929
import java.util.Map;
3030
import java.util.logging.Logger;
3131

32+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
3233
import static org.openqa.selenium.json.Json.JSON_UTF_8;
3334
import static org.openqa.selenium.json.Json.MAP_TYPE;
3435
import static org.openqa.selenium.remote.http.HttpMethod.POST;
@@ -48,7 +49,7 @@ public void apply(Reference ref) {
4849
LOG.info("Pulling " + ref);
4950

5051
String image = String.format("%s/%s", ref.getDomain(), ref.getName());
51-
HttpRequest req = new HttpRequest(POST, "/v1.40/images/create")
52+
HttpRequest req = new HttpRequest(POST, String.format("/v%s/images/create", DOCKER_API_VERSION))
5253
.addHeader("Content-Type", JSON_UTF_8)
5354
.addHeader("Content-Length", "0")
5455
.addQueryParameter("fromImage", image);

java/server/src/org/openqa/selenium/docker/v1_40/StartContainer.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/StartContainer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.ContainerId;
2121
import org.openqa.selenium.internal.Require;
2222
import org.openqa.selenium.remote.http.HttpHandler;
2323
import org.openqa.selenium.remote.http.HttpRequest;
2424

25-
import static org.openqa.selenium.docker.v1_40.DockerMessages.throwIfNecessary;
25+
import static org.openqa.selenium.docker.v1_41.DockerMessages.throwIfNecessary;
26+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
2627
import static org.openqa.selenium.remote.http.HttpMethod.POST;
2728

2829
class StartContainer {
@@ -37,7 +38,7 @@ public void apply(ContainerId id) {
3738

3839
throwIfNecessary(
3940
client.execute(
40-
new HttpRequest(POST, String.format("/v1.40/containers/%s/start", id))
41+
new HttpRequest(POST, String.format("/v%s/containers/%s/start", DOCKER_API_VERSION, id))
4142
.addHeader("Content-Length", "0")
4243
.addHeader("Content-Type", "text/plain")),
4344
"Unable to start container: %s",

java/server/src/org/openqa/selenium/docker/v1_40/StopContainer.java renamed to java/server/src/org/openqa/selenium/docker/v1_41/StopContainer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
package org.openqa.selenium.docker.v1_40;
18+
package org.openqa.selenium.docker.v1_41;
1919

2020
import org.openqa.selenium.docker.ContainerId;
2121
import org.openqa.selenium.internal.Require;
@@ -24,7 +24,8 @@
2424

2525
import java.time.Duration;
2626

27-
import static org.openqa.selenium.docker.v1_40.DockerMessages.throwIfNecessary;
27+
import static org.openqa.selenium.docker.v1_41.DockerMessages.throwIfNecessary;
28+
import static org.openqa.selenium.docker.v1_41.V141Docker.DOCKER_API_VERSION;
2829
import static org.openqa.selenium.remote.http.HttpMethod.POST;
2930

3031
class StopContainer {
@@ -40,7 +41,8 @@ public void apply(ContainerId id, Duration timeout) {
4041

4142
String seconds = String.valueOf(timeout.toMillis() / 1000);
4243

43-
HttpRequest request = new HttpRequest(POST, String.format("/v1.40/containers/%s/stop", id))
44+
String requestUrl = String.format("/v%s/containers/%s/stop", DOCKER_API_VERSION, id);
45+
HttpRequest request = new HttpRequest(POST, requestUrl)
4446
.addHeader("Content-Length", "0")
4547
.addHeader("Content-Type", "text/plain")
4648
.addQueryParameter("t", seconds);

0 commit comments

Comments
 (0)