diff --git a/docker-java-api/pom.xml b/docker-java-api/pom.xml index 1138a27f7..8bfd9e8d4 100644 --- a/docker-java-api/pom.xml +++ b/docker-java-api/pom.xml @@ -87,7 +87,10 @@ - + 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) com.github.dockerjava.api.command.InspectContainerResponse#getSizeRootFs() com.github.dockerjava.api.command.InspectContainerResponse#getSizeRw() 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..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 @@ -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,22 +20,47 @@ public interface UpdateContainerCmd extends SyncDockerCmd getBlkioWeightDevice(); + + UpdateContainerCmd withBlkioWeightDevice(List blkioWeightDevice); @CheckForNull - Integer getCpuPeriod(); + List getBlkioDeviceReadBps(); - UpdateContainerCmd withCpuPeriod(Integer cpuPeriod); + UpdateContainerCmd withBlkioDeviceReadBps(List blkioDeviceReadBps); @CheckForNull - Integer getCpuQuota(); + List getBlkioDeviceWriteBps(); - UpdateContainerCmd withCpuQuota(Integer cpuQuota); + UpdateContainerCmd withBlkioDeviceWriteBps(List blkioDeviceWriteBps); + + @CheckForNull + List getBlkioDeviceReadIOps(); + + UpdateContainerCmd withBlkioDeviceReadIOps(List blkioDeviceReadIOps); + + @CheckForNull + List getBlkioDeviceWriteIOps(); + + UpdateContainerCmd withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps); + + @CheckForNull + Long getCpuPeriod(); + + UpdateContainerCmd withCpuPeriod(Long cpuPeriod); + + @CheckForNull + Long getCpuQuota(); + + UpdateContainerCmd withCpuQuota(Long cpuQuota); @CheckForNull String getCpusetCpus(); @@ -45,6 +77,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 +122,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..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 @@ -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,14 @@ public UpdateContainerCmd withContainerId(@Nonnull String containerId) { * @see #cpuPeriod */ @CheckForNull - public Integer getCpuPeriod() { + public Long getCpuPeriod() { return cpuPeriod; } /** * @see #cpuPeriod */ - public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { + public UpdateContainerCmd withCpuPeriod(Long cpuPeriod) { this.cpuPeriod = cpuPeriod; return this; } @@ -113,14 +237,14 @@ public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { * @see #cpuQuota */ @CheckForNull - public Integer getCpuQuota() { + public Long getCpuQuota() { return cpuQuota; } /** * @see #cpuQuota */ - public UpdateContainerCmd withCpuQuota(Integer cpuQuota) { + public UpdateContainerCmd withCpuQuota(Long cpuQuota) { this.cpuQuota = cpuQuota; return this; } @@ -173,6 +297,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 +426,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/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/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) 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" + ] +}