From 3b37bdc8bced196e9c127e3945761fb0a5b81f15 Mon Sep 17 00:00:00 2001 From: Nikita Nikolenko Date: Wed, 26 Mar 2025 15:09:42 +0000 Subject: [PATCH 1/3] Add some missed options to UpdateContainerCmd --- .../api/command/UpdateContainerCmd.java | 119 ++++++- .../core/command/UpdateContainerCmdImpl.java | 325 +++++++++++++++++- .../dockerjava/cmd/UpdateContainerCmdIT.java | 4 +- 3 files changed, 434 insertions(+), 14 deletions(-) diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java b/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java index 82fbca5f8..3457633fd 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java @@ -1,9 +1,16 @@ package com.github.dockerjava.api.command; +import com.github.dockerjava.api.model.BlkioRateDevice; +import com.github.dockerjava.api.model.BlkioWeightDevice; +import com.github.dockerjava.api.model.Device; +import com.github.dockerjava.api.model.DeviceRequest; +import com.github.dockerjava.api.model.RestartPolicy; +import com.github.dockerjava.api.model.Ulimit; import com.github.dockerjava.api.model.UpdateContainerResponse; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import java.util.List; /** * @author Kanstantsin Shautsou @@ -13,23 +20,78 @@ public interface UpdateContainerCmd extends SyncDockerCmd getBlkioWeightDevice(); + + UpdateContainerCmd withBlkioWeightDevice(List blkioWeightDevice); + + @CheckForNull + List getBlkioDeviceReadBps(); + + UpdateContainerCmd withBlkioDeviceReadBps(List blkioDeviceReadBps); + + @CheckForNull + List getBlkioDeviceWriteBps(); + + UpdateContainerCmd withBlkioDeviceWriteBps(List blkioDeviceWriteBps); + + @CheckForNull + List getBlkioDeviceReadIOps(); + + UpdateContainerCmd withBlkioDeviceReadIOps(List blkioDeviceReadIOps); @CheckForNull + List getBlkioDeviceWriteIOps(); + + UpdateContainerCmd withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps); + + /** + * + * @deprecated see {@link #getCpuPeriodLong()} + */ + @CheckForNull + @Deprecated Integer getCpuPeriod(); + /** + * + * @deprecated see {@link #withCpuPeriod(Long)} + */ + @Deprecated UpdateContainerCmd withCpuPeriod(Integer cpuPeriod); @CheckForNull + Long getCpuPeriodLong(); + + UpdateContainerCmd withCpuPeriod(Long cpuPeriod); + + /** + * + * @deprecated see {@link #getCpuQuotaLong()} + */ + @CheckForNull + @Deprecated Integer getCpuQuota(); + /** + * + * @deprecated see {@link #withCpuQuota(Long)} + */ + @Deprecated UpdateContainerCmd withCpuQuota(Integer cpuQuota); + @CheckForNull + Long getCpuQuotaLong(); + + UpdateContainerCmd withCpuQuota(Long cpuQuota); + @CheckForNull String getCpusetCpus(); @@ -45,6 +107,31 @@ public interface UpdateContainerCmd extends SyncDockerCmd getDevices(); + + UpdateContainerCmd withDevices(List devices); + + @CheckForNull + List getDeviceCgroupRules(); + + UpdateContainerCmd withDeviceCgroupRules(List deviceCgroupRules); + + @CheckForNull + List getDeviceRequests(); + + UpdateContainerCmd withDeviceRequests(List deviceRequests); + @CheckForNull Long getKernelMemory(); @@ -65,6 +152,36 @@ public interface UpdateContainerCmd extends SyncDockerCmd getUlimits(); + + UpdateContainerCmd withUlimits(List ulimits); + + @CheckForNull + RestartPolicy getRestartPolicy(); + + UpdateContainerCmd withRestartPolicy(RestartPolicy restartPolicy); + interface Exec extends DockerCmdSyncExec { } } diff --git a/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java b/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java index 14357ba08..c239e2531 100644 --- a/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java +++ b/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java @@ -4,6 +4,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.github.dockerjava.api.command.UpdateContainerCmd; import com.github.dockerjava.api.exception.NotFoundException; +import com.github.dockerjava.api.model.BlkioRateDevice; +import com.github.dockerjava.api.model.BlkioWeightDevice; +import com.github.dockerjava.api.model.Device; +import com.github.dockerjava.api.model.DeviceRequest; +import com.github.dockerjava.api.model.RestartPolicy; +import com.github.dockerjava.api.model.Ulimit; import com.github.dockerjava.api.model.UpdateContainerResponse; import com.github.dockerjava.core.RemoteApiVersion; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -12,6 +18,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import java.util.List; /** * @author Kanstantsin Shautsou @@ -28,14 +35,38 @@ public class UpdateContainerCmdImpl extends AbstrDockerCmd blkioWeightDevice; + + @JsonProperty("BlkioDeviceReadBps") + private List blkioDeviceReadBps; + + @JsonProperty("BlkioDeviceWriteBps") + private List blkioDeviceWriteBps; + + @JsonProperty("BlkioDeviceReadIOps") + private List blkioDeviceReadIOps; + + @JsonProperty("BlkioDeviceWriteIOps") + private List blkioDeviceWriteIOps; + @JsonProperty("CpuShares") private Integer cpuShares; @JsonProperty("CpuPeriod") - private Integer cpuPeriod; + private Long cpuPeriod; @JsonProperty("CpuQuota") - private Integer cpuQuota; + private Long cpuQuota; + + @JsonProperty("CpuRealtimePeriod") + private Long cpuRealtimePeriod; + + @JsonProperty("CpuRealtimeRuntime") + private Long cpuRealtimeRuntime; + + @JsonProperty("NanoCpus") + private Long nanoCPUs; @JsonProperty("CpusetCpus") private String cpusetCpus; @@ -43,6 +74,18 @@ public class UpdateContainerCmdImpl extends AbstrDockerCmd devices; + + @JsonProperty("DeviceCgroupRules") + private List deviceCgroupRules; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_40} + */ + @JsonProperty("DeviceRequests") + private List deviceRequests; + @JsonProperty("Memory") private Long memory; @@ -55,11 +98,43 @@ public class UpdateContainerCmdImpl extends AbstrDockerCmd ulimits; + + @JsonProperty("RestartPolicy") + private RestartPolicy restartPolicy; + public UpdateContainerCmdImpl(UpdateContainerCmd.Exec exec, String containerId) { super(exec); withContainerId(containerId); } + /** + * @see #containerId + */ + @CheckForNull + @JsonIgnore + public String getContainerId() { + return containerId; + } + + /** + * @see #containerId + */ + public UpdateContainerCmd withContainerId(@Nonnull String containerId) { + this.containerId = containerId; + return this; + } + /** * @see #blkioWeight */ @@ -77,19 +152,68 @@ public UpdateContainerCmd withBlkioWeight(Integer blkioWeight) { } /** - * @see #containerId + * @see #blkioWeightDevice */ @CheckForNull - @JsonIgnore - public String getContainerId() { - return containerId; + public List getBlkioWeightDevice() { + return blkioWeightDevice; + } + + public UpdateContainerCmd withBlkioWeightDevice(List blkioWeightDevice) { + this.blkioWeightDevice = blkioWeightDevice; + return this; } /** - * @see #containerId + * @see #blkioDeviceReadBps */ - public UpdateContainerCmd withContainerId(@Nonnull String containerId) { - this.containerId = containerId; + @CheckForNull + public List getBlkioDeviceReadBps() { + return blkioDeviceReadBps; + } + + public UpdateContainerCmd withBlkioDeviceReadBps(List blkioDeviceReadBps) { + this.blkioDeviceReadBps = blkioDeviceReadBps; + return this; + } + + /** + * @see #blkioDeviceWriteBps + */ + @CheckForNull + public List getBlkioDeviceWriteBps() { + return blkioDeviceWriteBps; + } + + public UpdateContainerCmd withBlkioDeviceWriteBps(List blkioDeviceWriteBps) { + this.blkioDeviceWriteBps = blkioDeviceWriteBps; + return this; + } + + /** + * @see #blkioDeviceReadIOps + */ + @CheckForNull + public List getBlkioDeviceReadIOps() { + return blkioDeviceReadIOps; + } + + public UpdateContainerCmd withBlkioDeviceReadIOps(List blkioDeviceReadIOps) { + this.blkioDeviceReadIOps = blkioDeviceReadIOps; + return this; + } + + /** + * @see #blkioDeviceWriteIOps + */ + @CheckForNull + public List getBlkioDeviceWriteIOps() { + return blkioDeviceWriteIOps; + } + + @Override + public UpdateContainerCmd withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { + this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; return this; } @@ -97,14 +221,32 @@ public UpdateContainerCmd withContainerId(@Nonnull String containerId) { * @see #cpuPeriod */ @CheckForNull + @Deprecated public Integer getCpuPeriod() { - return cpuPeriod; + return cpuPeriod == null ? null : cpuPeriod.intValue(); } /** * @see #cpuPeriod */ + @Deprecated public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { + this.cpuPeriod = cpuPeriod == null ? null : cpuPeriod.longValue(); + return this; + } + + /** + * @see #cpuPeriod + */ + @CheckForNull + public Long getCpuPeriodLong() { + return cpuPeriod; + } + + /** + * @see #cpuPeriod + */ + public UpdateContainerCmd withCpuPeriod(Long cpuPeriod) { this.cpuPeriod = cpuPeriod; return this; } @@ -113,14 +255,32 @@ public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { * @see #cpuQuota */ @CheckForNull + @Deprecated public Integer getCpuQuota() { - return cpuQuota; + return cpuQuota == null ? null : cpuQuota.intValue(); } /** * @see #cpuQuota */ + @Deprecated public UpdateContainerCmd withCpuQuota(Integer cpuQuota) { + this.cpuQuota = cpuQuota == null ? null : cpuQuota.longValue(); + return this; + } + + /** + * @see #cpuQuota + */ + @CheckForNull + public Long getCpuQuotaLong() { + return cpuQuota; + } + + /** + * @see #cpuQuota + */ + public UpdateContainerCmd withCpuQuota(Long cpuQuota) { this.cpuQuota = cpuQuota; return this; } @@ -173,6 +333,71 @@ public UpdateContainerCmd withCpuShares(Integer cpuShares) { return this; } + /** + * @see #cpuRealtimePeriod + */ + @CheckForNull + public Long getCpuRealtimePeriod() { + return cpuRealtimePeriod; + } + + public UpdateContainerCmd withCpuRealtimePeriod(Long cpuRealtimePeriod) { + this.cpuRealtimePeriod = cpuRealtimePeriod; + return this; + } + + /** + * @see #cpuRealtimeRuntime + */ + @CheckForNull + public Long getCpuRealtimeRuntime() { + return cpuRealtimeRuntime; + } + + public UpdateContainerCmd withCpuRealtimeRuntime(Long cpuRealtimeRuntime) { + this.cpuRealtimeRuntime = cpuRealtimeRuntime; + return this; + } + + /** + * @see #devices + */ + @CheckForNull + public List getDevices() { + return devices; + } + + public UpdateContainerCmd withDevices(List devices) { + this.devices = devices; + return this; + } + + /** + * @see #deviceCgroupRules + */ + @CheckForNull + public List getDeviceCgroupRules() { + return deviceCgroupRules; + } + + public UpdateContainerCmd withDeviceCgroupRules(List deviceCgroupRules) { + this.deviceCgroupRules = deviceCgroupRules; + return this; + } + + /** + * @see #deviceRequests + */ + @CheckForNull + public List getDeviceRequests() { + return deviceRequests; + } + + public UpdateContainerCmd withDeviceRequests(List deviceRequests) { + this.deviceRequests = deviceRequests; + return this; + } + /** * @see #kernelMemory */ @@ -237,6 +462,84 @@ public UpdateContainerCmd withMemorySwap(Long memorySwap) { return this; } + /** + * @see #nanoCPUs + */ + @CheckForNull + public Long getNanoCPUs() { + return nanoCPUs; + } + + public UpdateContainerCmd withNanoCPUs(Long nanoCPUs) { + this.nanoCPUs = nanoCPUs; + return this; + } + + /** + * @see #oomKillDisable + */ + @CheckForNull + public Boolean getOomKillDisable() { + return oomKillDisable; + } + + public UpdateContainerCmd withOomKillDisable(Boolean oomKillDisable) { + this.oomKillDisable = oomKillDisable; + return this; + } + + /** + * @see #init + */ + @CheckForNull + public Boolean getInit() { + return init; + } + + public UpdateContainerCmd withInit(Boolean init) { + this.init = init; + return this; + } + + /** + * @see #pidsLimit + */ + @CheckForNull + public Long getPidsLimit() { + return pidsLimit; + } + + public UpdateContainerCmd withPidsLimit(Long pidsLimit) { + this.pidsLimit = pidsLimit; + return this; + } + + /** + * @see #ulimits + */ + @CheckForNull + public List getUlimits() { + return ulimits; + } + + public UpdateContainerCmd withUlimits(List ulimits) { + this.ulimits = ulimits; + return this; + } + + /** + * @see #restartPolicy + */ + @CheckForNull + public RestartPolicy getRestartPolicy() { + return restartPolicy; + } + + public UpdateContainerCmd withRestartPolicy(RestartPolicy restartPolicy) { + this.restartPolicy = restartPolicy; + return this; + } + /** * @throws NotFoundException No such container */ diff --git a/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java b/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java index e5bb55499..e1e637809 100644 --- a/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java +++ b/docker-java/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java @@ -48,8 +48,8 @@ public void updateContainer() throws DockerException { dockerRule.getClient().updateContainerCmd(containerId) .withBlkioWeight(300) .withCpuShares(512) - .withCpuPeriod(100000) - .withCpuQuota(50000) + .withCpuPeriod(100000L) + .withCpuQuota(50000L) // .withCpusetCpus("0") // depends on env .withCpusetMems("0") // .withMemory(209715200L + 2L) From a6ca6affaa409c5564a006072801fabae2949db4 Mon Sep 17 00:00:00 2001 From: Nikita Nikolenko Date: Wed, 26 Mar 2025 16:46:24 +0000 Subject: [PATCH 2/3] Delete old cpuPeriod and cpuQuota functions --- docker-java-api/pom.xml | 11 +++++ .../api/command/UpdateContainerCmd.java | 34 +--------------- .../core/command/UpdateContainerCmdImpl.java | 40 +------------------ 3 files changed, 15 insertions(+), 70 deletions(-) diff --git a/docker-java-api/pom.xml b/docker-java-api/pom.xml index 82d176e38..74813570f 100644 --- a/docker-java-api/pom.xml +++ b/docker-java-api/pom.xml @@ -84,6 +84,17 @@ com.github.siom79.japicmp japicmp-maven-plugin + + + + + com.github.dockerjava.api.command.UpdateContainerCmd#getCpuPeriod() + com.github.dockerjava.api.command.UpdateContainerCmd#withCpuPeriod(java.lang.Integer) + com.github.dockerjava.api.command.UpdateContainerCmd#getCpuQuota() + com.github.dockerjava.api.command.UpdateContainerCmd#withCpuQuota(java.lang.Integer) + + + diff --git a/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java b/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java index 3457633fd..d53bcdcdf 100644 --- a/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java +++ b/docker-java-api/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java @@ -52,43 +52,13 @@ public interface UpdateContainerCmd extends SyncDockerCmd blkioDeviceWriteIOps); - /** - * - * @deprecated see {@link #getCpuPeriodLong()} - */ @CheckForNull - @Deprecated - Integer getCpuPeriod(); - - /** - * - * @deprecated see {@link #withCpuPeriod(Long)} - */ - @Deprecated - UpdateContainerCmd withCpuPeriod(Integer cpuPeriod); - - @CheckForNull - Long getCpuPeriodLong(); + Long getCpuPeriod(); UpdateContainerCmd withCpuPeriod(Long cpuPeriod); - /** - * - * @deprecated see {@link #getCpuQuotaLong()} - */ - @CheckForNull - @Deprecated - Integer getCpuQuota(); - - /** - * - * @deprecated see {@link #withCpuQuota(Long)} - */ - @Deprecated - UpdateContainerCmd withCpuQuota(Integer cpuQuota); - @CheckForNull - Long getCpuQuotaLong(); + Long getCpuQuota(); UpdateContainerCmd withCpuQuota(Long cpuQuota); diff --git a/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java b/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java index c239e2531..47ab710eb 100644 --- a/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java +++ b/docker-java-core/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java @@ -221,25 +221,7 @@ public UpdateContainerCmd withBlkioDeviceWriteIOps(List blkioDe * @see #cpuPeriod */ @CheckForNull - @Deprecated - public Integer getCpuPeriod() { - return cpuPeriod == null ? null : cpuPeriod.intValue(); - } - - /** - * @see #cpuPeriod - */ - @Deprecated - public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { - this.cpuPeriod = cpuPeriod == null ? null : cpuPeriod.longValue(); - return this; - } - - /** - * @see #cpuPeriod - */ - @CheckForNull - public Long getCpuPeriodLong() { + public Long getCpuPeriod() { return cpuPeriod; } @@ -255,25 +237,7 @@ public UpdateContainerCmd withCpuPeriod(Long cpuPeriod) { * @see #cpuQuota */ @CheckForNull - @Deprecated - public Integer getCpuQuota() { - return cpuQuota == null ? null : cpuQuota.intValue(); - } - - /** - * @see #cpuQuota - */ - @Deprecated - public UpdateContainerCmd withCpuQuota(Integer cpuQuota) { - this.cpuQuota = cpuQuota == null ? null : cpuQuota.longValue(); - return this; - } - - /** - * @see #cpuQuota - */ - @CheckForNull - public Long getCpuQuotaLong() { + public Long getCpuQuota() { return cpuQuota; } From b8f30510537ebf9ae825507f5c12c060df8c72ff Mon Sep 17 00:00:00 2001 From: Nikita Nikolenko Date: Thu, 27 Mar 2025 10:29:46 +0000 Subject: [PATCH 3/3] Add update container response tests --- .../api/command/CommandJSONSamples.java | 4 ++- .../command/UpdateContainerResponseTest.java | 33 +++++++++++++++++++ .../updateContainerResponse_empty.json | 1 + .../updateContainerResponse_warnings.json | 5 +++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java create mode 100644 docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json create mode 100644 docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json diff --git a/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java b/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java index 0cf5141d4..23ef4b7f2 100644 --- a/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java +++ b/docker-java/src/test/java/com/github/dockerjava/api/command/CommandJSONSamples.java @@ -28,7 +28,9 @@ public enum CommandJSONSamples implements JSONResourceRef { inspectContainerResponse_full_1_21, inspectContainerResponse_full_1_26a, inspectContainerResponse_full_1_26b, - inspectContainerResponse_empty; + inspectContainerResponse_empty, + updateContainerResponse_empty, + updateContainerResponse_warnings; @Override public String getFileName() { diff --git a/docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java b/docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java new file mode 100644 index 000000000..300a5c324 --- /dev/null +++ b/docker-java/src/test/java/com/github/dockerjava/api/command/UpdateContainerResponseTest.java @@ -0,0 +1,33 @@ +package com.github.dockerjava.api.command; + +import com.github.dockerjava.api.model.UpdateContainerResponse; +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +public class UpdateContainerResponseTest { + @Test + public void roundTrip_empty() throws IOException { + UpdateContainerResponse response = testRoundTrip(CommandJSONSamples.updateContainerResponse_empty, UpdateContainerResponse.class); + assertNull(response.getWarnings()); + } + + @Test + public void roundTrip_warnings() throws IOException { + UpdateContainerResponse response = testRoundTrip(CommandJSONSamples.updateContainerResponse_warnings, + UpdateContainerResponse.class); + + List warnings = response.getWarnings(); + assertNotNull(warnings); + assertEquals(1, warnings.size()); + + final String warning = warnings.get(0); + assertEquals("Published ports are discarded when using host network mode", warning); + } +} diff --git a/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_empty.json @@ -0,0 +1 @@ +{} diff --git a/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json new file mode 100644 index 000000000..edeaedc7a --- /dev/null +++ b/docker-java/src/test/resources/com/github/dockerjava/api/command/updateContainerResponse_warnings.json @@ -0,0 +1,5 @@ +{ + "Warnings": [ + "Published ports are discarded when using host network mode" + ] +}