From 212218890b508be392b396638150d8e96d7b7970 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 26 Nov 2018 05:10:23 +0300 Subject: [PATCH 1/4] WIP --- .../api/command/CreateContainerCmd.java | 14 +++-- .../dockerjava/api/model/HostConfig.java | 62 +++++++++++++++++-- .../core/command/CreateContainerCmdImpl.java | 13 +++- 3 files changed, 78 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java index 63d53563f..c268036a8 100644 --- a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java +++ b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java @@ -37,6 +37,9 @@ public interface CreateContainerCmd extends SyncDockerCmd aliases); @@ -138,6 +144,8 @@ public interface CreateContainerCmd extends SyncDockerCmd exposedPorts); CreateContainerCmd withHostName(String hostName); @@ -177,10 +185,8 @@ public interface CreateContainerCmd extends SyncDockerCmd exposedPorts) { checkNotNull(exposedPorts, "exposedPorts was not specified"); From 3e3c5e5f3919c022186684a51f4def80cf5bfa0e Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 26 Nov 2018 07:45:52 +0300 Subject: [PATCH 2/4] Update part of apis to 1.37 --- .../api/command/CreateContainerCmd.java | 182 +++---- .../dockerjava/api/model/AuthConfig.java | 6 +- .../dockerjava/api/model/BlkioRateDevice.java | 54 ++ .../api/model/BlkioWeightDevice.java | 54 ++ .../github/dockerjava/api/model/Device.java | 12 +- .../dockerjava/api/model/HealthCheck.java | 42 +- .../dockerjava/api/model/HostConfig.java | 462 ++++++++++++------ .../dockerjava/api/model/Isolation.java | 41 ++ .../dockerjava/api/model/LogConfig.java | 63 +-- .../github/dockerjava/api/model/Ulimit.java | 2 - .../core/command/CreateContainerCmdImpl.java | 453 +++++++++-------- .../command/InspectContainerResponseTest.java | 3 +- .../dockerjava/cmd/CreateContainerCmdIT.java | 41 +- .../cmd/DisconnectFromNetworkCmdIT.java | 2 +- .../dockerjava/cmd/ListContainersCmdIT.java | 12 +- .../dockerjava/cmd/StartContainerCmdIT.java | 46 +- .../dockerjava/cmd/UpdateContainerCmdIT.java | 4 +- .../dockerjava/cmd/swarm/SwarmCmdIT.java | 8 +- 18 files changed, 923 insertions(+), 564 deletions(-) create mode 100644 src/main/java/com/github/dockerjava/api/model/BlkioRateDevice.java create mode 100644 src/main/java/com/github/dockerjava/api/model/BlkioWeightDevice.java create mode 100644 src/main/java/com/github/dockerjava/api/model/Isolation.java diff --git a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java index c268036a8..4fa5dd2e2 100644 --- a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java +++ b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java @@ -4,6 +4,7 @@ import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.api.model.AuthConfig; import com.github.dockerjava.api.model.ExposedPort; +import com.github.dockerjava.api.model.HealthCheck; import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.Volume; @@ -16,171 +17,186 @@ public interface CreateContainerCmd extends SyncDockerCmd getAliases(); + /** + * Add network-scoped alias for the container + * + * @param aliases on ore more aliases + */ + CreateContainerCmd withAliases(List aliases); + + /** + * Add network-scoped alias for the container + * + * @param aliases on ore more aliases + */ + CreateContainerCmd withAliases(String... aliases); + @CheckForNull String[] getCmd(); + CreateContainerCmd withCmd(String... cmd); + + CreateContainerCmd withCmd(List cmd); + + @CheckForNull + HealthCheck getHealthcheck(); + + CreateContainerCmd withHealthcheck(HealthCheck healthCheck); + + @CheckForNull + Boolean getArgsEscaped(); + + CreateContainerCmd withArgsEscaped(Boolean argsEscaped); + @CheckForNull String getDomainName(); + CreateContainerCmd withDomainName(String domainName); + @CheckForNull String[] getEntrypoint(); + CreateContainerCmd withEntrypoint(String... entrypoint); + + CreateContainerCmd withEntrypoint(List entrypoint); + @CheckForNull String[] getEnv(); + CreateContainerCmd withEnv(String... env); + + CreateContainerCmd withEnv(List env); + @CheckForNull ExposedPort[] getExposedPorts(); + CreateContainerCmd withExposedPorts(List exposedPorts); + + CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts); + @CheckForNull String getStopSignal(); + CreateContainerCmd withStopSignal(String stopSignal); + @CheckForNull - public Integer getStopTimeout(); + Integer getStopTimeout(); + + CreateContainerCmd withStopTimeout(Integer stopTimeout); @CheckForNull String getHostName(); + CreateContainerCmd withHostName(String hostName); + @CheckForNull String getImage(); + CreateContainerCmd withImage(String image); + @CheckForNull String getIpv4Address(); + CreateContainerCmd withIpv4Address(String ipv4Address); + @CheckForNull String getIpv6Address(); + CreateContainerCmd withIpv6Address(String ipv6Address); + @CheckForNull Map getLabels(); + CreateContainerCmd withLabels(Map labels); + @CheckForNull String getMacAddress(); + CreateContainerCmd withMacAddress(String macAddress); + @CheckForNull String getName(); + CreateContainerCmd withName(String name); + @CheckForNull String[] getPortSpecs(); + CreateContainerCmd withPortSpecs(String... portSpecs); + + CreateContainerCmd withPortSpecs(List portSpecs); + @CheckForNull String getUser(); + CreateContainerCmd withUser(String user); + @CheckForNull Volume[] getVolumes(); + CreateContainerCmd withVolumes(Volume... volumes); + + CreateContainerCmd withVolumes(List volumes); + @CheckForNull String getWorkingDir(); + CreateContainerCmd withWorkingDir(String workingDir); + @CheckForNull Boolean isAttachStderr(); + CreateContainerCmd withAttachStderr(Boolean attachStderr); + @CheckForNull Boolean isAttachStdin(); + CreateContainerCmd withAttachStdin(Boolean attachStdin); + @CheckForNull Boolean isAttachStdout(); + CreateContainerCmd withAttachStdout(Boolean attachStdout); + @CheckForNull Boolean isNetworkDisabled(); + CreateContainerCmd withNetworkDisabled(Boolean disableNetwork); + @CheckForNull Boolean isStdInOnce(); + CreateContainerCmd withStdInOnce(Boolean stdInOnce); + @CheckForNull Boolean isStdinOpen(); - @CheckForNull - HostConfig getHostConfig(); + CreateContainerCmd withStdinOpen(Boolean stdinOpen); @CheckForNull Boolean isTty(); - /** - * While using swarm classic, you can provide an optional auth config which will be used to pull images from a private registry, - * if the swarm node does not already have the docker image. - * Note: This option does not have any effect in normal docker - * - * @param authConfig The optional auth config - */ - CreateContainerCmd withAuthConfig(AuthConfig authConfig); - - /** - * Add network-scoped alias for the container - * - * @param aliases on ore more aliases - */ - CreateContainerCmd withAliases(String... aliases); - - /** - * Add network-scoped alias for the container - * - * @param aliases on ore more aliases - */ - CreateContainerCmd withAliases(List aliases); - - CreateContainerCmd withAttachStderr(Boolean attachStderr); - - CreateContainerCmd withAttachStdin(Boolean attachStdin); - - CreateContainerCmd withAttachStdout(Boolean attachStdout); - - CreateContainerCmd withCmd(String... cmd); - - CreateContainerCmd withCmd(List cmd); - - CreateContainerCmd withDomainName(String domainName); - - CreateContainerCmd withEntrypoint(String... entrypoint); - - CreateContainerCmd withEntrypoint(List entrypoint); - - CreateContainerCmd withEnv(String... env); - - CreateContainerCmd withEnv(List env); - - CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts); - - CreateContainerCmd withStopSignal(String stopSignal); - - CreateContainerCmd withStopTimeout(Integer stopTimeout); - - CreateContainerCmd withExposedPorts(List exposedPorts); - - CreateContainerCmd withHostName(String hostName); - - CreateContainerCmd withImage(String image); - - CreateContainerCmd withIpv4Address(String ipv4Address); - - CreateContainerCmd withIpv6Address(String ipv6Address); - - CreateContainerCmd withLabels(Map labels); - - CreateContainerCmd withMacAddress(String macAddress); - - CreateContainerCmd withName(String name); - - CreateContainerCmd withNetworkDisabled(Boolean disableNetwork); - - CreateContainerCmd withPortSpecs(String... portSpecs); - - CreateContainerCmd withPortSpecs(List portSpecs); - - CreateContainerCmd withStdInOnce(Boolean stdInOnce); - - CreateContainerCmd withStdinOpen(Boolean stdinOpen); - CreateContainerCmd withTty(Boolean tty); - CreateContainerCmd withUser(String user); - - CreateContainerCmd withVolumes(Volume... volumes); + @CheckForNull + List getOnBuild(); - CreateContainerCmd withVolumes(List volumes); + CreateContainerCmd withOnBuild(List onBuild); - CreateContainerCmd withWorkingDir(String workingDir); + @CheckForNull + HostConfig getHostConfig(); CreateContainerCmd withHostConfig(HostConfig hostConfig); diff --git a/src/main/java/com/github/dockerjava/api/model/AuthConfig.java b/src/main/java/com/github/dockerjava/api/model/AuthConfig.java index 72bf4ef04..d2ecd7d90 100644 --- a/src/main/java/com/github/dockerjava/api/model/AuthConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/AuthConfig.java @@ -21,13 +21,13 @@ public class AuthConfig implements Serializable { */ public static final String DEFAULT_SERVER_ADDRESS = "https://index.docker.io/v1/"; - @JsonProperty + @JsonProperty("username") private String username; - @JsonProperty + @JsonProperty("password") private String password; - @JsonProperty + @JsonProperty("email") private String email; @JsonProperty("serveraddress") diff --git a/src/main/java/com/github/dockerjava/api/model/BlkioRateDevice.java b/src/main/java/com/github/dockerjava/api/model/BlkioRateDevice.java new file mode 100644 index 000000000..4e171417f --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/BlkioRateDevice.java @@ -0,0 +1,54 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.io.Serializable; + +import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE; + +public class BlkioRateDevice implements Serializable { + public static final long serialVersionUID = 1L; + + @JsonProperty("Path") + private String path; + + @JsonProperty("Rate") + private Long rate; + + public String getPath() { + return path; + } + + public BlkioRateDevice withPath(String path) { + this.path = path; + return this; + } + + public Long getRate() { + return rate; + } + + public BlkioRateDevice withRate(Long rate) { + this.rate = rate; + return this; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, SHORT_PREFIX_STYLE); + } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + +} diff --git a/src/main/java/com/github/dockerjava/api/model/BlkioWeightDevice.java b/src/main/java/com/github/dockerjava/api/model/BlkioWeightDevice.java new file mode 100644 index 000000000..1c8e5cd08 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/BlkioWeightDevice.java @@ -0,0 +1,54 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.io.Serializable; + +import static org.apache.commons.lang.builder.ToStringStyle.SHORT_PREFIX_STYLE; + +public class BlkioWeightDevice implements Serializable { + public static final long serialVersionUID = 1L; + + @JsonProperty("Path") + private String path; + + @JsonProperty("Weight") + private Integer weight; + + public String getPath() { + return path; + } + + public BlkioWeightDevice withPath(String path) { + this.path = path; + return this; + } + + public Integer getWeight() { + return weight; + } + + public BlkioWeightDevice withWeight(Integer weight) { + this.weight = weight; + return this; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, SHORT_PREFIX_STYLE); + } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + +} diff --git a/src/main/java/com/github/dockerjava/api/model/Device.java b/src/main/java/com/github/dockerjava/api/model/Device.java index 7d73710fd..32155271c 100644 --- a/src/main/java/com/github/dockerjava/api/model/Device.java +++ b/src/main/java/com/github/dockerjava/api/model/Device.java @@ -127,8 +127,10 @@ private static boolean validDeviceMode(String deviceMode) { public boolean equals(Object obj) { if (obj instanceof Device) { Device other = (Device) obj; - return new EqualsBuilder().append(cGroupPermissions, other.getcGroupPermissions()) - .append(pathInContainer, other.getPathInContainer()).append(pathOnHost, other.getPathOnHost()) + return new EqualsBuilder() + .append(cGroupPermissions, other.getcGroupPermissions()) + .append(pathInContainer, other.getPathInContainer()) + .append(pathOnHost, other.getPathOnHost()) .isEquals(); } else { return super.equals(obj); @@ -137,7 +139,11 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return new HashCodeBuilder().append(cGroupPermissions).append(pathInContainer).append(pathOnHost).toHashCode(); + return new HashCodeBuilder() + .append(cGroupPermissions) + .append(pathInContainer) + .append(pathOnHost) + .toHashCode(); } } diff --git a/src/main/java/com/github/dockerjava/api/model/HealthCheck.java b/src/main/java/com/github/dockerjava/api/model/HealthCheck.java index d9057c11a..aba2fd8cd 100644 --- a/src/main/java/com/github/dockerjava/api/model/HealthCheck.java +++ b/src/main/java/com/github/dockerjava/api/model/HealthCheck.java @@ -18,6 +18,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; import java.io.Serializable; import java.util.List; @@ -32,10 +35,10 @@ public class HealthCheck implements Serializable { private static final long serialVersionUID = 1L; @JsonProperty("Interval") - private Long interval; + private Integer interval; @JsonProperty("Timeout") - private Long timeout; + private Integer timeout; /** * @since 1.26 @@ -47,28 +50,28 @@ public class HealthCheck implements Serializable { * @since 1.26 */ @JsonProperty("Retries") - private Long retries; + private Integer retries; /** * @since 1.26 */ @JsonProperty("StartPeriod") - private Long startPeriod; + private Integer startPeriod; - public Long getInterval() { + public Integer getInterval() { return interval; } - public Long getTimeout() { + public Integer getTimeout() { return timeout; } - public HealthCheck withInterval(Long interval) { + public HealthCheck withInterval(Integer interval) { this.interval = interval; return this; } - public HealthCheck withTimeout(Long timeout) { + public HealthCheck withTimeout(Integer timeout) { this.timeout = timeout; return this; } @@ -82,21 +85,36 @@ public HealthCheck withTest(List test) { return this; } - public Long getRetries() { + public Integer getRetries() { return retries; } - public HealthCheck withRetries(Long retries) { + public HealthCheck withRetries(Integer retries) { this.retries = retries; return this; } - public Long getStartPeriod() { + public Integer getStartPeriod() { return startPeriod; } - public HealthCheck withStartPeriod(Long startPeriod) { + public HealthCheck withStartPeriod(Integer startPeriod) { this.startPeriod = startPeriod; return this; } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/src/main/java/com/github/dockerjava/api/model/HostConfig.java b/src/main/java/com/github/dockerjava/api/model/HostConfig.java index 9fad0a7af..1eb0594b6 100644 --- a/src/main/java/com/github/dockerjava/api/model/HostConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/HostConfig.java @@ -29,12 +29,13 @@ public class HostConfig implements Serializable { private static final List PREDEFINED_NETWORKS = Arrays.asList("bridge", "host", "none"); + public static HostConfig newHostConfig() { + return new HostConfig(); + } + @JsonProperty("Binds") private Binds binds; - /** - * @since 1.19 - */ @JsonProperty("BlkioWeight") private Integer blkioWeight; @@ -42,37 +43,40 @@ public class HostConfig implements Serializable { * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} */ @JsonProperty("BlkioWeightDevice") - private List blkioWeightDevice; + private List blkioWeightDevice; /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} */ @JsonProperty("BlkioDeviceReadBps") - private List blkioDeviceReadBps; + private List blkioDeviceReadBps; /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} */ - @JsonProperty("BlkioDeviceReadIOps") - private List blkioDeviceReadIOps; + @JsonProperty("BlkioDeviceWriteBps") + private List blkioDeviceWriteBps; /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} */ - @JsonProperty("BlkioDeviceWriteBps") - private List blkioDeviceWriteBps; + @JsonProperty("BlkioDeviceReadIOps") + private List blkioDeviceReadIOps; /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} */ @JsonProperty("BlkioDeviceWriteIOps") - private List blkioDeviceWriteIOps; + private List blkioDeviceWriteIOps; /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} */ @JsonProperty("MemorySwappiness") - private Integer memorySwappiness; + private Long memorySwappiness; + + @JsonProperty("NanoCPUs") + private Long nanoCPUs; @JsonProperty("CapAdd") private Capability[] capAdd; @@ -83,9 +87,6 @@ public class HostConfig implements Serializable { @JsonProperty("ContainerIDFile") private String containerIDFile; - /** - * @since 1.19 - */ @JsonProperty("CpuPeriod") private Long cpuPeriod; @@ -107,15 +108,15 @@ public class HostConfig implements Serializable { @JsonProperty("CpusetCpus") private String cpusetCpus; - /** - * @since 1.19 - */ @JsonProperty("CpusetMems") private String cpusetMems; @JsonProperty("Devices") private Device[] devices; + @JsonProperty("DeviceCgroupRules") + private List deviceCgroupRules; + /** * @since {@link RemoteApiVersion#VERSION_1_25} */ @@ -125,12 +126,24 @@ public class HostConfig implements Serializable { @JsonProperty("Dns") private String[] dns; + @JsonProperty("DnsOptions") + private List dnsOptions; + @JsonProperty("DnsSearch") private String[] dnsSearch; @JsonProperty("ExtraHosts") private String[] extraHosts; + @JsonProperty("GroupAdd") + private List groupAdd; + + @JsonProperty("IpcMode") + private String ipcMode; + + @JsonProperty("Cgroup") + private String cgroup; + @JsonProperty("Links") private Links links; @@ -158,18 +171,15 @@ public class HostConfig implements Serializable { @JsonProperty("KernelMemory") private Long kernelMemory; - @JsonProperty("NanoCPUs") - private Long nanoCPUs; - - @JsonProperty("CpuPercent") - private Long cpuPercent; - @JsonProperty("NetworkMode") private String networkMode; @JsonProperty("OomKillDisable") private Boolean oomKillDisable; + @JsonProperty("Init") + private Boolean init; + /** * @since {@link RemoteApiVersion#VERSION_1_25} */ @@ -180,7 +190,7 @@ public class HostConfig implements Serializable { * @since {@link RemoteApiVersion#VERSION_1_22} */ @JsonProperty("OomScoreAdj") - private Boolean oomScoreAdj; + private Integer oomScoreAdj; @JsonProperty("PortBindings") private Ports portBindings; @@ -197,27 +207,42 @@ public class HostConfig implements Serializable { @JsonProperty("RestartPolicy") private RestartPolicy restartPolicy; - /** - * @since {@link RemoteApiVersion#VERSION_1_24} - */ - @JsonProperty("StorageOpt") - private Map storageOpt; - @JsonProperty("Ulimits") private Ulimit[] ulimits; + @JsonProperty("CpuCount") + private Long cpuCount; + + @JsonProperty("CpuPercent") + private Long cpuPercent; + + @JsonProperty("IOMaximumIOps") + private Long ioMaximumIOps; + + @JsonProperty("IOMaximumBandwidth") + private Long ioMaximumBandwidth; + @JsonProperty("VolumesFrom") private VolumesFrom[] volumesFrom; + @JsonProperty("Mounts") + private List mounts; + @JsonProperty("PidMode") private String pidMode; + @JsonProperty("Isolation") + private Isolation isolation; + /** * @since {@link RemoteApiVersion#VERSION_1_20} */ @JsonProperty("SecurityOpt") private List securityOpts; + @JsonProperty("StorageOpt") + private Map storageOpt; + /** * @since {@link RemoteApiVersion#VERSION_1_20} */ @@ -254,15 +279,17 @@ public class HostConfig implements Serializable { @JsonProperty("Tmpfs") private Map tmpFs; - /** - * @since ~{@link RemoteApiVersion#VERSION_1_22} - */ - @JsonProperty("Isolation") - private String isolation; + @JsonProperty("UTSMode") + private String utSMode; - public static HostConfig newHostConfig() { - return new HostConfig(); - } + @JsonProperty("UsernsMode") + private String usernsMode; + + @JsonProperty("Sysctls") + private Map sysctls; + + @JsonProperty("ConsoleSize") + private List consoleSize; @JsonIgnore public Bind[] getBinds() { @@ -289,13 +316,6 @@ public Long getCpuPeriod() { return cpuPeriod; } - public Long getCpuRealtimePeriod() { - return cpuRealtimePeriod; - } - - public Long getCpuRealtimeRuntime() { - return cpuRealtimeRuntime; - } public Integer getCpuShares() { return cpuShares; @@ -376,19 +396,11 @@ public String getPidMode() { return pidMode; } - /** - * @see #isolation - */ - @CheckForNull - public String getIsolation() { - return isolation; - } - /** * @see #blkioDeviceReadBps */ @CheckForNull - public List getBlkioDeviceReadBps() { + public List getBlkioDeviceReadBps() { return blkioDeviceReadBps; } @@ -396,7 +408,7 @@ public List getBlkioDeviceReadBps() { * @see #blkioDeviceReadIOps */ @CheckForNull - public List getBlkioDeviceReadIOps() { + public List getBlkioDeviceReadIOps() { return blkioDeviceReadIOps; } @@ -404,7 +416,7 @@ public List getBlkioDeviceReadIOps() { * @see #blkioDeviceWriteBps */ @CheckForNull - public List getBlkioDeviceWriteBps() { + public List getBlkioDeviceWriteBps() { return blkioDeviceWriteBps; } @@ -412,7 +424,7 @@ public List getBlkioDeviceWriteBps() { * @see #blkioDeviceWriteIOps */ @CheckForNull - public List getBlkioDeviceWriteIOps() { + public List getBlkioDeviceWriteIOps() { return blkioDeviceWriteIOps; } @@ -420,7 +432,7 @@ public List getBlkioDeviceWriteIOps() { * @see #blkioWeightDevice */ @CheckForNull - public List getBlkioWeightDevice() { + public List getBlkioWeightDevice() { return blkioWeightDevice; } @@ -428,7 +440,7 @@ public List getBlkioWeightDevice() { * @see #oomScoreAdj */ @CheckForNull - public Boolean getOomScoreAdj() { + public Integer getOomScoreAdj() { return oomScoreAdj; } @@ -448,16 +460,6 @@ public Long getKernelMemory() { return kernelMemory; } - @CheckForNull - public Long getNanoCPUs() { - return nanoCPUs; - } - - @CheckForNull - public Long getCpuPercent() { - return cpuPercent; - } - /** * @see #memoryReservation */ @@ -470,7 +472,7 @@ public Long getMemoryReservation() { * @see #memorySwappiness */ @CheckForNull - public Integer getMemorySwappiness() { + public Long getMemorySwappiness() { return memorySwappiness; } @@ -577,10 +579,15 @@ public HostConfig withBinds(Bind... binds) { return this; } + public HostConfig withBinds(List binds) { + checkNotNull(binds, "binds was not specified"); + return withBinds(binds.toArray(new Bind[binds.size()])); + } + /** * @see #blkioDeviceReadBps */ - public HostConfig withBlkioDeviceReadBps(List blkioDeviceReadBps) { + public HostConfig withBlkioDeviceReadBps(List blkioDeviceReadBps) { this.blkioDeviceReadBps = blkioDeviceReadBps; return this; } @@ -588,7 +595,7 @@ public HostConfig withBlkioDeviceReadBps(List blkioDeviceReadBps) { /** * @see #blkioDeviceReadIOps */ - public HostConfig withBlkioDeviceReadIOps(List blkioDeviceReadIOps) { + public HostConfig withBlkioDeviceReadIOps(List blkioDeviceReadIOps) { this.blkioDeviceReadIOps = blkioDeviceReadIOps; return this; } @@ -596,7 +603,7 @@ public HostConfig withBlkioDeviceReadIOps(List blkioDeviceReadIOps) { /** * @see #blkioDeviceWriteBps */ - public HostConfig withBlkioDeviceWriteBps(List blkioDeviceWriteBps) { + public HostConfig withBlkioDeviceWriteBps(List blkioDeviceWriteBps) { this.blkioDeviceWriteBps = blkioDeviceWriteBps; return this; } @@ -604,7 +611,7 @@ public HostConfig withBlkioDeviceWriteBps(List blkioDeviceWriteBps) { /** * @see #blkioDeviceWriteIOps */ - public HostConfig withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { + public HostConfig withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; return this; } @@ -620,14 +627,13 @@ public HostConfig withBlkioWeight(Integer blkioWeight) { /** * @see #blkioWeightDevice */ - public HostConfig withBlkioWeightDevice(List blkioWeightDevice) { + public HostConfig withBlkioWeightDevice(List blkioWeightDevice) { this.blkioWeightDevice = blkioWeightDevice; return this; } /** - * Add linux kernel capability to the container. For example: - * adding {@link Capability#MKNOD} allows the container to create special files using the 'mknod' command. + * @see #capAdd */ public HostConfig withCapAdd(Capability... capAdd) { this.capAdd = capAdd; @@ -666,16 +672,6 @@ public HostConfig withCpuPeriod(Long cpuPeriod) { return this; } - public HostConfig withCpuRealtimePeriod(Long cpuRealtimePeriod) { - this.cpuRealtimePeriod = cpuRealtimePeriod; - return this; - } - - public HostConfig withCpuRealtimeRuntime(Long cpuRealtimeRuntime) { - this.cpuRealtimeRuntime = cpuRealtimeRuntime; - return this; - } - /** * @see #cpuQuota */ @@ -708,11 +704,6 @@ public HostConfig withCpuShares(Integer cpuShares) { return this; } - public HostConfig withDevices(List devices) { - checkNotNull(devices, "devices was not specified"); - return withDevices(devices.toArray(new Device[devices.size()])); - } - /** * @see #devices */ @@ -721,6 +712,11 @@ public HostConfig withDevices(Device... devices) { return this; } + public HostConfig withDevices(List devices) { + checkNotNull(devices, "devices was not specified"); + return withDevices(devices.toArray(new Device[0])); + } + /** * @see #diskQuota */ @@ -739,7 +735,7 @@ public HostConfig withDns(String... dns) { public HostConfig withDns(List dns) { checkNotNull(dns, "dns was not specified"); - return withDns(dns.toArray(new String[dns.size()])); + return withDns(dns.toArray(new String[0])); } /** @@ -763,11 +759,6 @@ public HostConfig withExtraHosts(String... extraHosts) { return this; } - public HostConfig withExtraHosts(List extraHosts) { - checkNotNull(extraHosts, "extraHosts was not specified"); - return withExtraHosts(extraHosts.toArray(new String[extraHosts.size()])); - } - /** * @see #kernelMemory */ @@ -776,16 +767,6 @@ public HostConfig withKernelMemory(Long kernelMemory) { return this; } - public HostConfig withNanoCPUs(Long nanoCPUs) { - this.nanoCPUs = nanoCPUs; - return this; - } - - public HostConfig withCpuPercent(Long cpuPercent) { - this.cpuPercent = cpuPercent; - return this; - } - /** * @see #links */ @@ -794,18 +775,18 @@ public HostConfig withLinks(Links links) { return this; } - public HostConfig withLinks(List links) { + public HostConfig withLinks(Link... links) { checkNotNull(links, "links was not specified"); - setLinks(links.toArray(new Link[links.size()])); + setLinks(links); return this; } - public HostConfig withLinks(Link... links) { + public HostConfig withLinks(List links) { checkNotNull(links, "links was not specified"); - setLinks(links); - return this; + return withLinks(links.toArray(new Link[0])); } + /** * @see #logConfig */ @@ -822,11 +803,6 @@ public HostConfig withLxcConf(LxcConf[] lxcConf) { return this; } - public HostConfig withLxcConf(List lxcConf) { - checkNotNull(lxcConf, "lxcConf was not specified"); - return withLxcConf(lxcConf.toArray(new LxcConf[0])); - } - /** * @see #memory */ @@ -854,7 +830,7 @@ public HostConfig withMemorySwap(Long memorySwap) { /** * @see #memorySwappiness */ - public HostConfig withMemorySwappiness(Integer memorySwappiness) { + public HostConfig withMemorySwappiness(Long memorySwappiness) { this.memorySwappiness = memorySwappiness; return this; } @@ -868,8 +844,6 @@ public HostConfig withMemorySwappiness(Integer memorySwappiness) { *
  • 'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system * services such as D-bus and is therefore considered insecure.
  • * - * - * @see #networkMode */ public HostConfig withNetworkMode(String networkMode) { this.networkMode = networkMode; @@ -878,6 +852,7 @@ public HostConfig withNetworkMode(String networkMode) { /** * @see #oomKillDisable + * @since 1.19 */ public HostConfig withOomKillDisable(Boolean oomKillDisable) { this.oomKillDisable = oomKillDisable; @@ -895,12 +870,14 @@ public HostConfig withAutoRemove(Boolean autoRemove) { /** * @see #oomScoreAdj */ - public HostConfig withOomScoreAdj(Boolean oomScoreAdj) { + public HostConfig withOomScoreAdj(Integer oomScoreAdj) { this.oomScoreAdj = oomScoreAdj; return this; } /** + * Set the PID (Process) Namespace mode for the container, 'host': use the host's PID namespace inside the container + * * @see #pidMode */ public HostConfig withPidMode(String pidMode) { @@ -909,11 +886,18 @@ public HostConfig withPidMode(String pidMode) { } /** - * @see #portBindings + * Add one or more {@link PortBinding}s. This corresponds to the --publish (-p) option of the + * docker run CLI command. */ + public HostConfig withPortBindings(Ports portBindings) { + this.portBindings = portBindings; + return this; + } + public HostConfig withPortBindings(PortBinding... portBindings) { checkNotNull(portBindings, "portBindings was not specified"); - return withPortBindings(new Ports(portBindings)); + withPortBindings(new Ports(portBindings)); + return this; } public HostConfig withPortBindings(List portBindings) { @@ -921,14 +905,6 @@ public HostConfig withPortBindings(List portBindings) { return withPortBindings(portBindings.toArray(new PortBinding[0])); } - /** - * @see #portBindings - */ - public HostConfig withPortBindings(Ports portBindings) { - this.portBindings = portBindings; - return this; - } - /** * @see #privileged */ @@ -978,28 +954,13 @@ public HostConfig withReadonlyRootfs(Boolean readonlyRootfs) { } /** - * @see #restartPolicy + * Set custom {@link RestartPolicy} for the container. Defaults to {@link RestartPolicy#noRestart()} */ public HostConfig withRestartPolicy(RestartPolicy restartPolicy) { this.restartPolicy = restartPolicy; return this; } - /** - * @see #storageOpt - */ - public Map getStorageOpt() { - return storageOpt; - } - - /** - * @see #storageOpt - */ - public HostConfig withStorageOpt(Map storageOpt) { - this.storageOpt = storageOpt; - return this; - } - /** * @see #securityOpts */ @@ -1026,7 +987,7 @@ public HostConfig withUlimits(Ulimit[] ulimits) { public HostConfig withUlimits(List ulimits) { checkNotNull(ulimits, "no ulimits was specified"); - return withUlimits(ulimits.toArray(new Ulimit[ulimits.size()])); + return withUlimits(ulimits.toArray(new Ulimit[0])); } /** @@ -1047,10 +1008,9 @@ public HostConfig withVolumesFrom(VolumesFrom... volumesFrom) { public HostConfig withVolumesFrom(List volumesFrom) { checkNotNull(volumesFrom, "volumesFrom was not specified"); - return withVolumesFrom(volumesFrom.toArray(new VolumesFrom[volumesFrom.size()])); + return withVolumesFrom(volumesFrom.toArray(new VolumesFrom[0])); } - /** * @see #pidsLimit */ @@ -1072,14 +1032,206 @@ public HostConfig withTmpFs(Map tmpFs) { return this; } - /** - * @see #isolation - */ - public HostConfig withIsolation(String isolation) { + @CheckForNull + public List getDeviceCgroupRules() { + return deviceCgroupRules; + } + + public HostConfig withDeviceCgroupRules(List deviceCgroupRules) { + this.deviceCgroupRules = deviceCgroupRules; + return this; + } + + @CheckForNull + public Long getNanoCPUs() { + return nanoCPUs; + } + + public HostConfig withNanoCPUs(Long nanoCPUs) { + this.nanoCPUs = nanoCPUs; + return this; + } + + @CheckForNull + public Boolean getInit() { + return init; + } + + public HostConfig withInit(Boolean init) { + this.init = init; + return this; + } + + @CheckForNull + public Long getCpuCount() { + return cpuCount; + } + + public HostConfig withCpuCount(Long cpuCount) { + this.cpuCount = cpuCount; + return this; + } + + @CheckForNull + public Long getCpuPercent() { + return cpuPercent; + } + + public HostConfig withCpuPercent(Long cpuPercent) { + this.cpuPercent = cpuPercent; + return this; + } + + @CheckForNull + public Long getIoMaximumIOps() { + return ioMaximumIOps; + } + + public HostConfig withIoMaximumIOps(Long ioMaximumIOps) { + this.ioMaximumIOps = ioMaximumIOps; + return this; + } + + @CheckForNull + public Long getIoMaximumBandwidth() { + return ioMaximumBandwidth; + } + + public HostConfig withIoMaximumBandwidth(Long ioMaximumBandwidth) { + this.ioMaximumBandwidth = ioMaximumBandwidth; + return this; + } + + @CheckForNull + public List getMounts() { + return mounts; + } + + public HostConfig withMounts(List mounts) { + this.mounts = mounts; + return this; + } + + @CheckForNull + public List getDnsOptions() { + return dnsOptions; + } + + public HostConfig withDnsOptions(List dnsOptions) { + this.dnsOptions = dnsOptions; + return this; + } + + @CheckForNull + public List getGroupAdd() { + return groupAdd; + } + + public HostConfig withGroupAdd(List groupAdd) { + this.groupAdd = groupAdd; + return this; + } + + @CheckForNull + public String getIpcMode() { + return ipcMode; + } + + public HostConfig withIpcMode(String ipcMode) { + this.ipcMode = ipcMode; + return this; + } + + @CheckForNull + public String getCgroup() { + return cgroup; + } + + public HostConfig withCgroup(String cgroup) { + this.cgroup = cgroup; + return this; + } + + @CheckForNull + public Map getStorageOpt() { + return storageOpt; + } + + public HostConfig withStorageOpt(Map storageOpt) { + this.storageOpt = storageOpt; + return this; + } + + @CheckForNull + public String getUtSMode() { + return utSMode; + } + + public HostConfig withUtSMode(String utSMode) { + this.utSMode = utSMode; + return this; + } + + @CheckForNull + public String getUsernsMode() { + return usernsMode; + } + + public HostConfig withUsernsMode(String usernsMode) { + this.usernsMode = usernsMode; + return this; + } + + @CheckForNull + public Map getSysctls() { + return sysctls; + } + + public HostConfig withSysctls(Map sysctls) { + this.sysctls = sysctls; + return this; + } + + @CheckForNull + public List getConsoleSize() { + return consoleSize; + } + + public HostConfig withConsoleSize(List consoleSize) { + this.consoleSize = consoleSize; + return this; + } + + @CheckForNull + public Isolation getIsolation() { + return isolation; + } + + public HostConfig withIsolation(Isolation isolation) { this.isolation = isolation; return this; } + @CheckForNull + public Long getCpuRealtimePeriod() { + return cpuRealtimePeriod; + } + + public HostConfig withCpuRealtimePeriod(Long cpuRealtimePeriod) { + this.cpuRealtimePeriod = cpuRealtimePeriod; + return this; + } + + @CheckForNull + public Long getCpuRealtimeRuntime() { + return cpuRealtimeRuntime; + } + + public HostConfig withCpuRealtimeRuntime(Long cpuRealtimeRuntime) { + this.cpuRealtimeRuntime = cpuRealtimeRuntime; + return this; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); diff --git a/src/main/java/com/github/dockerjava/api/model/Isolation.java b/src/main/java/com/github/dockerjava/api/model/Isolation.java new file mode 100644 index 000000000..c59c8848f --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/Isolation.java @@ -0,0 +1,41 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.io.Serializable; + +public enum Isolation implements Serializable { + DEFAULT("default"), + + PROCESS("process"), + + HYPERV("hyperv"); + + private String value; + + Isolation(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @JsonCreator + public static Isolation fromValue(String text) { + for (Isolation b : Isolation.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + + @Override + public String toString() { + return String.valueOf(value); + } + +} diff --git a/src/main/java/com/github/dockerjava/api/model/LogConfig.java b/src/main/java/com/github/dockerjava/api/model/LogConfig.java index 6da68d434..4ea19041e 100644 --- a/src/main/java/com/github/dockerjava/api/model/LogConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/LogConfig.java @@ -1,28 +1,19 @@ package com.github.dockerjava.api.model; -import java.io.IOException; -import java.io.Serializable; -import java.util.Map; - +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.annotation.JsonValue; + +import javax.annotation.CheckForNull; +import java.io.Serializable; +import java.util.Map; /** * Log driver to use for a created/running container. The available types are: - * + *

    * json-file (default) syslog journald none - * + *

    * If a driver is specified that is NOT supported,docker will default to null. If configs are supplied that are not supported by the type * docker will ignore them. In most cases setting the config option to null will suffice. Consult the docker remote API for a more detailed * and up-to-date explanation of the available types and their options. @@ -68,12 +59,11 @@ public LogConfig setConfig(Map config) { return this; } - @JsonDeserialize(using = LoggingType.Deserializer.class) - @JsonSerialize(using = LoggingType.Serializer.class) public enum LoggingType { + NONE("none"), DEFAULT("json-file"), + ETWLOGS("etwlogs"), JSON_FILE("json-file"), - NONE("none"), SYSLOG("syslog"), JOURNALD("journald"), GELF("gelf"), @@ -89,34 +79,25 @@ public enum LoggingType { this.type = type; } + @JsonValue public String getType() { return type; } - public static final class Serializer extends JsonSerializer { - @Override - public void serialize(LoggingType value, JsonGenerator jgen, SerializerProvider provider) - throws IOException, JsonProcessingException { - jgen.writeString(value.getType()); + @JsonCreator + @CheckForNull + public static LoggingType fromValue(String text) { + for (LoggingType b : LoggingType.values()) { + if (String.valueOf(b.type).equals(text)) { + return b; + } } + return null; } - public static final class Deserializer extends JsonDeserializer { - @Override - public LoggingType deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) - throws IOException, JsonProcessingException { - - ObjectCodec oc = jsonParser.getCodec(); - JsonNode node = oc.readTree(jsonParser); - - for (LoggingType loggingType : values()) { - if (loggingType.getType().equals(node.asText())) { - return loggingType; - } - } - - throw new IllegalArgumentException("No enum constant " + LoggingType.class + "." + node.asText()); - } + @Override + public String toString() { + return String.valueOf(type); } } } diff --git a/src/main/java/com/github/dockerjava/api/model/Ulimit.java b/src/main/java/com/github/dockerjava/api/model/Ulimit.java index abcf298bd..5a37810a4 100644 --- a/src/main/java/com/github/dockerjava/api/model/Ulimit.java +++ b/src/main/java/com/github/dockerjava/api/model/Ulimit.java @@ -25,12 +25,10 @@ public class Ulimit implements Serializable { private Integer hard; public Ulimit() { - } public Ulimit(String name, int soft, int hard) { checkNotNull(name, "Name is null"); - this.name = name; this.soft = soft; this.hard = hard; diff --git a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java index 1ba7ba6a6..1819be0c3 100644 --- a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java +++ b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java @@ -12,6 +12,7 @@ import com.github.dockerjava.api.model.ContainerNetwork; import com.github.dockerjava.api.model.ExposedPort; import com.github.dockerjava.api.model.ExposedPorts; +import com.github.dockerjava.api.model.HealthCheck; import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.api.model.Volumes; @@ -19,6 +20,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; +import javax.annotation.CheckForNull; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -72,6 +74,12 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd onBuild; + @JsonProperty("NetworkDisabled") private Boolean networkDisabled; @@ -108,6 +119,9 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd labels; + @JsonProperty("Shell") + private List shell; + @JsonProperty("NetworkingConfig") private NetworkingConfig networkingConfig; @@ -137,50 +151,6 @@ public CreateContainerCmd withAuthConfig(AuthConfig authConfig) { return this; } - /** - * @throws NotFoundException - * No such container - * @throws ConflictException - * Named container already exists - */ - @Override - public CreateContainerResponse exec() throws NotFoundException, ConflictException { - //code flow taken from https://github.com/docker/docker/blob/master/runconfig/opts/parse.go - ContainerNetwork containerNetwork = null; - - if (ipv4Address != null || ipv6Address != null) { - containerNetwork = new ContainerNetwork() - .withIpamConfig(new ContainerNetwork.Ipam() - .withIpv4Address(ipv4Address) - .withIpv6Address(ipv6Address) - ); - - } - - if (hostConfig.isUserDefinedNetwork() && hostConfig.getLinks().length > 0) { - if (containerNetwork == null) { - containerNetwork = new ContainerNetwork(); - } - - containerNetwork.withLinks(hostConfig.getLinks()); - } - - if (aliases != null) { - if (containerNetwork == null) { - containerNetwork = new ContainerNetwork(); - } - - containerNetwork.withAliases(aliases); - } - - if (containerNetwork != null) { - networkingConfig = new NetworkingConfig() - .withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork)); - } - - return super.exec(); - } - @Override @JsonIgnore public List getAliases() { @@ -188,293 +158,315 @@ public List getAliases() { } @Override - public String[] getCmd() { - return cmd; + public CreateContainerCmd withAliases(String... aliases) { + this.aliases = Arrays.asList(aliases); + return this; } @Override - public String getDomainName() { - return domainName; + public CreateContainerCmd withAliases(List aliases) { + checkNotNull(aliases, "aliases was not specified"); + this.aliases = aliases; + return this; } + @Override - public String[] getEntrypoint() { - return entrypoint; + public String[] getCmd() { + return cmd; } @Override - public String[] getEnv() { - return env; + public CreateContainerCmd withCmd(String... cmd) { + checkNotNull(cmd, "cmd was not specified"); + this.cmd = cmd; + return this; } @Override - @JsonIgnore - public ExposedPort[] getExposedPorts() { - return exposedPorts.getExposedPorts(); + public CreateContainerCmd withCmd(List cmd) { + checkNotNull(cmd, "cmd was not specified"); + return withCmd(cmd.toArray(new String[0])); } - /** - * @see #stopSignal - */ - @Override - public String getStopSignal() { - return stopSignal; + @CheckForNull + public HealthCheck getHealthcheck() { + return healthcheck; } - @Override - public Integer getStopTimeout() { return stopTimeout; } + public CreateContainerCmdImpl withHealthcheck(HealthCheck healthcheck) { + this.healthcheck = healthcheck; + return this; + } - @Override - public String getHostName() { - return hostName; + public Boolean getArgsEscaped() { + return argsEscaped; + } + + public CreateContainerCmdImpl withArgsEscaped(Boolean argsEscaped) { + this.argsEscaped = argsEscaped; + return this; } @Override - public String getImage() { - return image; + public String getDomainName() { + return domainName; } @Override - public String getIpv4Address() { - return ipv4Address; + public CreateContainerCmd withDomainName(String domainName) { + checkNotNull(domainName, "no domainName was specified"); + this.domainName = domainName; + return this; } @Override - public String getIpv6Address() { - return ipv6Address; + public String[] getEntrypoint() { + return entrypoint; } @Override - @JsonIgnore - public Map getLabels() { - return labels; + public CreateContainerCmd withEntrypoint(String... entrypoint) { + checkNotNull(entrypoint, "entrypoint was not specified"); + this.entrypoint = entrypoint; + return this; } @Override - public String getMacAddress() { - return macAddress; + public CreateContainerCmd withEntrypoint(List entrypoint) { + checkNotNull(entrypoint, "entrypoint was not specified"); + return withEntrypoint(entrypoint.toArray(new String[0])); } @Override - public String getName() { - return name; + public String[] getEnv() { + return env; } @Override - public String[] getPortSpecs() { - return portSpecs; + public CreateContainerCmd withEnv(String... env) { + checkNotNull(env, "env was not specified"); + this.env = env; + return this; } @Override - public String getUser() { - return user; + public CreateContainerCmd withEnv(List env) { + checkNotNull(env, "env was not specified"); + return withEnv(env.toArray(new String[0])); } @Override @JsonIgnore - public Volume[] getVolumes() { - return volumes.getVolumes(); + public ExposedPort[] getExposedPorts() { + return exposedPorts.getExposedPorts(); } @Override - public String getWorkingDir() { - return workingDir; + public CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts) { + checkNotNull(exposedPorts, "exposedPorts was not specified"); + this.exposedPorts = new ExposedPorts(exposedPorts); + return this; } @Override - public Boolean isAttachStderr() { - return attachStderr; + public CreateContainerCmd withExposedPorts(List exposedPorts) { + checkNotNull(exposedPorts, "exposedPorts was not specified"); + return withExposedPorts(exposedPorts.toArray(new ExposedPort[0])); } + /** + * @see #stopSignal + */ + @JsonIgnore @Override - public Boolean isAttachStdin() { - return attachStdin; + public String getStopSignal() { + return stopSignal; } @Override - public Boolean isAttachStdout() { - return attachStdout; + public CreateContainerCmd withStopSignal(String stopSignal) { + checkNotNull(stopSignal, "stopSignal wasn't specified."); + this.stopSignal = stopSignal; + return this; } @Override - public Boolean isNetworkDisabled() { - return networkDisabled; + public Integer getStopTimeout() { + return stopTimeout; } @Override - public Boolean isStdInOnce() { - return stdInOnce; + public CreateContainerCmd withStopTimeout(Integer stopTimeout) { + this.stopTimeout = stopTimeout; + return this; } @Override - public Boolean isStdinOpen() { - return stdinOpen; + public String getHostName() { + return hostName; } @Override - public Boolean isTty() { - return tty; + public CreateContainerCmd withHostName(String hostName) { + checkNotNull(hostName, "no hostName was specified"); + this.hostName = hostName; + return this; } @Override - public HostConfig getHostConfig() { - return hostConfig; + public String getImage() { + return image; } @Override - public CreateContainerCmd withAliases(String... aliases) { - this.aliases = Arrays.asList(aliases); + public CreateContainerCmd withImage(String image) { + checkNotNull(image, "no image was specified"); + this.image = image; return this; } @Override - public CreateContainerCmd withAliases(List aliases) { - checkNotNull(aliases, "aliases was not specified"); - this.aliases = aliases; - return this; + @JsonIgnore + public Map getLabels() { + return labels; } @Override - public CreateContainerCmd withAttachStderr(Boolean attachStderr) { - checkNotNull(attachStderr, "attachStderr was not specified"); - this.attachStderr = attachStderr; + public CreateContainerCmd withLabels(Map labels) { + checkNotNull(labels, "labels was not specified"); + this.labels = labels; return this; } @Override - public CreateContainerCmd withAttachStdin(Boolean attachStdin) { - checkNotNull(attachStdin, "attachStdin was not specified"); - this.attachStdin = attachStdin; - return this; + public String getMacAddress() { + return macAddress; } @Override - public CreateContainerCmd withAttachStdout(Boolean attachStdout) { - checkNotNull(attachStdout, "attachStdout was not specified"); - this.attachStdout = attachStdout; + public CreateContainerCmd withMacAddress(String macAddress) { + checkNotNull(macAddress, "macAddress was not specified"); + this.macAddress = macAddress; return this; } + @Override + public String getName() { + return name; + } @Override - public CreateContainerCmd withCmd(String... cmd) { - checkNotNull(cmd, "cmd was not specified"); - this.cmd = cmd; + public CreateContainerCmd withName(String name) { + checkNotNull(name, "name was not specified"); + this.name = name; return this; } @Override - public CreateContainerCmd withCmd(List cmd) { - checkNotNull(cmd, "cmd was not specified"); - return withCmd(cmd.toArray(new String[cmd.size()])); + public String[] getPortSpecs() { + return portSpecs; } @Override - public CreateContainerCmd withDomainName(String domainName) { - checkNotNull(domainName, "no domainName was specified"); - this.domainName = domainName; + public CreateContainerCmd withPortSpecs(String... portSpecs) { + checkNotNull(portSpecs, "portSpecs was not specified"); + this.portSpecs = portSpecs; return this; } @Override - public CreateContainerCmd withEntrypoint(String... entrypoint) { - checkNotNull(entrypoint, "entrypoint was not specified"); - this.entrypoint = entrypoint; - return this; + public CreateContainerCmd withPortSpecs(List portSpecs) { + checkNotNull(portSpecs, "portSpecs was not specified"); + return withPortSpecs(portSpecs.toArray(new String[0])); } @Override - public CreateContainerCmd withEntrypoint(List entrypoint) { - checkNotNull(entrypoint, "entrypoint was not specified"); - return withEntrypoint(entrypoint.toArray(new String[entrypoint.size()])); + public String getUser() { + return user; } @Override - public CreateContainerCmd withEnv(String... env) { - checkNotNull(env, "env was not specified"); - this.env = env; + public CreateContainerCmd withUser(String user) { + checkNotNull(user, "user was not specified"); + this.user = user; return this; } + @Override - public CreateContainerCmd withEnv(List env) { - checkNotNull(env, "env was not specified"); - return withEnv(env.toArray(new String[env.size()])); + public Boolean isAttachStderr() { + return attachStderr; } @Override - public CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts) { - checkNotNull(exposedPorts, "exposedPorts was not specified"); - this.exposedPorts = new ExposedPorts(exposedPorts); + public CreateContainerCmd withAttachStderr(Boolean attachStderr) { + checkNotNull(attachStderr, "attachStderr was not specified"); + this.attachStderr = attachStderr; return this; } + @Override - public CreateContainerCmd withStopSignal(String stopSignal) { - checkNotNull(stopSignal, "stopSignal wasn't specified."); - this.stopSignal = stopSignal; - return this; + public Boolean isAttachStdin() { + return attachStdin; } @Override - public CreateContainerCmd withStopTimeout(Integer stopTimeout) { - this.stopTimeout = stopTimeout; + public CreateContainerCmd withAttachStdin(Boolean attachStdin) { + checkNotNull(attachStdin, "attachStdin was not specified"); + this.attachStdin = attachStdin; return this; } + @Override - public CreateContainerCmd withExposedPorts(List exposedPorts) { - checkNotNull(exposedPorts, "exposedPorts was not specified"); - return withExposedPorts(exposedPorts.toArray(new ExposedPort[exposedPorts.size()])); + public Boolean isAttachStdout() { + return attachStdout; } @Override - public CreateContainerCmd withHostName(String hostName) { - checkNotNull(hostConfig, "no hostName was specified"); - this.hostName = hostName; + public CreateContainerCmd withAttachStdout(Boolean attachStdout) { + checkNotNull(attachStdout, "attachStdout was not specified"); + this.attachStdout = attachStdout; return this; } + @Override - public CreateContainerCmd withImage(String image) { - checkNotNull(image, "no image was specified"); - this.image = image; - return this; + @JsonIgnore + public Volume[] getVolumes() { + return volumes.getVolumes(); } @Override - public CreateContainerCmd withIpv4Address(String ipv4Address) { - checkNotNull(ipv4Address, "no ipv4Address was specified"); - this.ipv4Address = ipv4Address; + public CreateContainerCmd withVolumes(Volume... volumes) { + checkNotNull(volumes, "volumes was not specified"); + this.volumes = new Volumes(volumes); return this; } @Override - public CreateContainerCmd withIpv6Address(String ipv6Address) { - checkNotNull(ipv6Address, "no ipv6Address was specified"); - this.ipv6Address = ipv6Address; - return this; + public CreateContainerCmd withVolumes(List volumes) { + checkNotNull(volumes, "volumes was not specified"); + return withVolumes(volumes.toArray(new Volume[0])); } @Override - public CreateContainerCmd withLabels(Map labels) { - checkNotNull(labels, "labels was not specified"); - this.labels = labels; - return this; + public String getWorkingDir() { + return workingDir; } @Override - public CreateContainerCmd withMacAddress(String macAddress) { - checkNotNull(macAddress, "macAddress was not specified"); - this.macAddress = macAddress; + public CreateContainerCmd withWorkingDir(String workingDir) { + checkNotNull(workingDir, "workingDir was not specified"); + this.workingDir = workingDir; return this; } @Override - public CreateContainerCmd withName(String name) { - checkNotNull(name, "name was not specified"); - this.name = name; - return this; + public Boolean isNetworkDisabled() { + return networkDisabled; } @Override @@ -484,17 +476,10 @@ public CreateContainerCmd withNetworkDisabled(Boolean disableNetwork) { return this; } - @Override - public CreateContainerCmd withPortSpecs(String... portSpecs) { - checkNotNull(portSpecs, "portSpecs was not specified"); - this.portSpecs = portSpecs; - return this; - } @Override - public CreateContainerCmd withPortSpecs(List portSpecs) { - checkNotNull(portSpecs, "portSpecs was not specified"); - return withPortSpecs(portSpecs.toArray(new String[portSpecs.size()])); + public Boolean isStdInOnce() { + return stdInOnce; } @Override @@ -504,6 +489,11 @@ public CreateContainerCmd withStdInOnce(Boolean stdInOnce) { return this; } + @Override + public Boolean isStdinOpen() { + return stdinOpen; + } + @Override public CreateContainerCmd withStdinOpen(Boolean stdinOpen) { checkNotNull(stdinOpen, "no stdinOpen was specified"); @@ -511,6 +501,12 @@ public CreateContainerCmd withStdinOpen(Boolean stdinOpen) { return this; } + + @Override + public Boolean isTty() { + return tty; + } + @Override public CreateContainerCmd withTty(Boolean tty) { checkNotNull(tty, "no tty was specified"); @@ -518,41 +514,94 @@ public CreateContainerCmd withTty(Boolean tty) { return this; } + @Override + public HostConfig getHostConfig() { + return hostConfig; + } @Override - public CreateContainerCmd withUser(String user) { - checkNotNull(user, "user was not specified"); - this.user = user; + public CreateContainerCmd withHostConfig(HostConfig hostConfig) { + this.hostConfig = hostConfig; return this; } @Override - public CreateContainerCmd withVolumes(Volume... volumes) { - checkNotNull(volumes, "volumes was not specified"); - this.volumes = new Volumes(volumes); + public String getIpv4Address() { + return ipv4Address; + } + + @Override + public CreateContainerCmd withIpv4Address(String ipv4Address) { + checkNotNull(ipv4Address, "no ipv4Address was specified"); + this.ipv4Address = ipv4Address; return this; } @Override - public CreateContainerCmd withVolumes(List volumes) { - checkNotNull(volumes, "volumes was not specified"); - return withVolumes(volumes.toArray(new Volume[volumes.size()])); + public String getIpv6Address() { + return ipv6Address; } @Override - public CreateContainerCmd withWorkingDir(String workingDir) { - checkNotNull(workingDir, "workingDir was not specified"); - this.workingDir = workingDir; + public CreateContainerCmd withIpv6Address(String ipv6Address) { + checkNotNull(ipv6Address, "no ipv6Address was specified"); + this.ipv6Address = ipv6Address; return this; } + @CheckForNull + public List getOnBuild() { + return onBuild; + } - @Override - public CreateContainerCmd withHostConfig(HostConfig hostConfig) { - this.hostConfig = hostConfig; + public CreateContainerCmdImpl withOnBuild(List onBuild) { + this.onBuild = onBuild; return this; } + /** + * @throws NotFoundException No such container + * @throws ConflictException Named container already exists + */ + @Override + public CreateContainerResponse exec() throws NotFoundException, ConflictException { + //code flow taken from https://github.com/docker/docker/blob/master/runconfig/opts/parse.go + ContainerNetwork containerNetwork = null; + + if (ipv4Address != null || ipv6Address != null) { + containerNetwork = new ContainerNetwork() + .withIpamConfig(new ContainerNetwork.Ipam() + .withIpv4Address(ipv4Address) + .withIpv6Address(ipv6Address) + ); + + } + + if (hostConfig.isUserDefinedNetwork() && hostConfig.getLinks().length > 0) { + if (containerNetwork == null) { + containerNetwork = new ContainerNetwork(); + } + + containerNetwork.withLinks(hostConfig.getLinks()); + } + + if (aliases != null) { + if (containerNetwork == null) { + containerNetwork = new ContainerNetwork(); + } + + containerNetwork.withAliases(aliases); + } + + if (containerNetwork != null) { + networkingConfig = new NetworkingConfig() + .withEndpointsConfig(singletonMap(hostConfig.getNetworkMode(), containerNetwork)); + } + + return super.exec(); + } + + @Override public String toString() { return ToStringBuilder.reflectionToString(this); diff --git a/src/test/java/com/github/dockerjava/api/command/InspectContainerResponseTest.java b/src/test/java/com/github/dockerjava/api/command/InspectContainerResponseTest.java index ee38b70d0..877418d7e 100644 --- a/src/test/java/com/github/dockerjava/api/command/InspectContainerResponseTest.java +++ b/src/test/java/com/github/dockerjava/api/command/InspectContainerResponseTest.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.dockerjava.api.model.ContainerNetwork; +import com.github.dockerjava.api.model.Isolation; import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.core.RemoteApiVersion; import org.junit.Test; @@ -161,7 +162,7 @@ public void inspect_windows_container() throws IOException { ))); assertThat(response.getHostConfig(), notNullValue()); - assertThat(response.getHostConfig().getIsolation(), is("hyperv")); + assertThat(response.getHostConfig().getIsolation(), is(Isolation.HYPERV)); assertThat(response.getImageId(), is("sha256:1381511ec0122f197b6abff5bc0692bef19943ddafd6680eff41197afa3a6dda")); assertThat(response.getLogPath(), is( diff --git a/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java b/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java index f01e60019..3d5c03e1e 100644 --- a/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java @@ -306,7 +306,7 @@ public void createContainerWithMemorySwappiness() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withCmd("sleep", "9999") .withHostConfig(newHostConfig() - .withMemorySwappiness(42)) + .withMemorySwappiness(42L)) .exec(); assertThat(container.getId(), not(isEmptyString())); LOG.info("Created container {}", container.toString()); @@ -335,9 +335,9 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException { assertNotNull(createNetworkResponse.getId()); CreateContainerResponse container1 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) - .withCmd("sleep", "9999") .withHostConfig(newHostConfig() .withNetworkMode(networkName)) + .withCmd("sleep", "9999") .withName(containerName1) .exec(); @@ -352,9 +352,8 @@ public void createContainerWithLinkInCustomNetwork() throws DockerException { CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withHostConfig(newHostConfig() - .withNetworkMode(networkName) .withLinks(new Link(containerName1, containerName1 + "Link")) - ) + .withNetworkMode(networkName)) .withName(containerName2) .withCmd("env") .exec(); @@ -387,9 +386,9 @@ public void createContainerWithCustomIp() throws DockerException { assertNotNull(createNetworkResponse.getId()); CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) - .withCmd("sleep", "9999") .withHostConfig(newHostConfig() .withNetworkMode(networkName)) + .withCmd("sleep", "9999") .withName(containerName1) .withIpv4Address(subnetPrefix + ".100") .exec(); @@ -421,9 +420,9 @@ public void createContainerWithAlias() throws DockerException { assertNotNull(createNetworkResponse.getId()); CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) - .withCmd("sleep", "9999") .withHostConfig(newHostConfig() .withNetworkMode(networkName)) + .withCmd("sleep", "9999") .withName(containerName1) .withAliases("server" + dockerRule.getKind()) .exec(); @@ -505,8 +504,7 @@ public void createContainerWithExtraHosts() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withName("containerextrahosts" + dockerRule.getKind()) .withHostConfig(newHostConfig() - .withExtraHosts(extraHosts)) - .exec(); + .withExtraHosts(extraHosts)).exec(); LOG.info("Created container {}", container.toString()); @@ -523,7 +521,8 @@ public void createContainerWithDevices() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999") .withHostConfig(newHostConfig() - .withDevices(new Device("rwm", "/dev/nulo", "/dev/zero"))).exec(); + .withDevices(new Device("rwm", "/dev/nulo", "/dev/zero"))) + .exec(); LOG.info("Created container {}", container.toString()); @@ -548,8 +547,10 @@ public void createContainerWithPortBindings() throws DockerException { portBindings.bind(tcp23, Binding.bindPort(baseport + 24)); CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true") - .withExposedPorts(tcp22, tcp23).withHostConfig(newHostConfig() - .withPortBindings(portBindings)).exec(); + .withExposedPorts(tcp22, tcp23) + .withHostConfig(newHostConfig() + .withPortBindings(portBindings)) + .exec(); LOG.info("Created container {}", container.toString()); @@ -603,7 +604,8 @@ public void createContainerWithLinking() throws DockerException { CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999") .withName(containerName2) .withHostConfig(newHostConfig() - .withLinks(new Link(containerName1, containerName1 + "Link"))).exec(); + .withLinks(new Link(containerName1, containerName1 + "Link"))) + .exec(); LOG.info("Created container2 {}", container2.toString()); assertThat(container2.getId(), not(isEmptyString())); @@ -630,8 +632,7 @@ public void createContainerWithRestartPolicy() throws DockerException { RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5); CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("sleep", "9999") - .withHostConfig(newHostConfig() - .withRestartPolicy(restartPolicy)).exec(); + .withHostConfig(newHostConfig().withRestartPolicy(restartPolicy)).exec(); LOG.info("Created container {}", container.toString()); @@ -646,8 +647,7 @@ public void createContainerWithRestartPolicy() throws DockerException { public void createContainerWithPidMode() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true") - .withHostConfig(newHostConfig() - .withPidMode("host")).exec(); + .withHostConfig(newHostConfig().withPidMode("host")).exec(); LOG.info("Created container {}", container.toString()); @@ -669,7 +669,8 @@ public void createContainerWithNetworkMode() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE).withCmd("true") .withHostConfig(newHostConfig() - .withNetworkMode("host")).exec(); + .withNetworkMode("host")) + .exec(); LOG.info("Created container {}", container.toString()); @@ -703,7 +704,8 @@ public void createContainerWithULimits() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withName(containerName) .withHostConfig(newHostConfig() - .withUlimits(ulimits)).exec(); + .withUlimits(ulimits)) + .exec(); LOG.info("Created container {}", container.toString()); @@ -819,7 +821,8 @@ public void onNext(Frame item) { public void createContainerWithCgroupParent() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") .withHostConfig(newHostConfig() - .withCgroupParent("/parent")).exec(); + .withCgroupParent("/parent")) + .exec(); LOG.info("Created container {}", container.toString()); diff --git a/src/test/java/com/github/dockerjava/cmd/DisconnectFromNetworkCmdIT.java b/src/test/java/com/github/dockerjava/cmd/DisconnectFromNetworkCmdIT.java index 220ad89ef..3c9451545 100644 --- a/src/test/java/com/github/dockerjava/cmd/DisconnectFromNetworkCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/DisconnectFromNetworkCmdIT.java @@ -41,9 +41,9 @@ public void forceDisconnectFromNetwork() throws InterruptedException { CreateNetworkResponse network = dockerRule.getClient().createNetworkCmd().withName("testNetwork2" + dockerRule.getKind()).exec(); CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") - .withCmd("sleep", "9999") .withHostConfig(newHostConfig() .withNetworkMode("testNetwork2" + dockerRule.getKind())) + .withCmd("sleep", "9999") .exec(); dockerRule.getClient().startContainerCmd(container.getId()).exec(); diff --git a/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java b/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java index 098c592b8..50ba4ca40 100644 --- a/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/ListContainersCmdIT.java @@ -4,7 +4,6 @@ import com.github.dockerjava.api.command.InspectContainerResponse; import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.Container; -import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.core.command.PullImageResultCallback; import com.github.dockerjava.core.command.WaitContainerResultCallback; @@ -22,6 +21,7 @@ import java.util.UUID; import static ch.lambdaj.Lambda.filter; +import static com.github.dockerjava.api.model.HostConfig.newHostConfig; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static org.hamcrest.MatcherAssert.assertThat; @@ -258,9 +258,8 @@ public void testVolumeFilter() throws Exception { id = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withLabels(testLabel) - .withHostConfig(HostConfig.newHostConfig() - .withBinds(new Bind("TestFilterVolume", new Volume("/test"))) - ) + .withHostConfig(newHostConfig() + .withBinds(new Bind("TestFilterVolume", new Volume("/test")))) .exec() .getId(); @@ -288,9 +287,8 @@ public void testNetworkFilter() throws Exception { id = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withLabels(testLabel) - .withHostConfig(HostConfig.newHostConfig() - .withNetworkMode("TestFilterNetwork") - ) + .withHostConfig(newHostConfig() + .withNetworkMode("TestFilterNetwork")) .exec() .getId(); diff --git a/src/test/java/com/github/dockerjava/cmd/StartContainerCmdIT.java b/src/test/java/com/github/dockerjava/cmd/StartContainerCmdIT.java index bd0a53f50..5fde7bc03 100644 --- a/src/test/java/com/github/dockerjava/cmd/StartContainerCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/StartContainerCmdIT.java @@ -10,7 +10,6 @@ import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.Device; import com.github.dockerjava.api.model.ExposedPort; -import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.Link; import com.github.dockerjava.api.model.Ports; import com.github.dockerjava.api.model.Ports.Binding; @@ -55,12 +54,10 @@ public void startContainerWithVolumes() throws DockerException { Volume volume2 = new Volume("/opt/webapp2"); - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") - .withVolumes(volume1, volume2) + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withVolumes(volume1, volume2) .withCmd("true") .withHostConfig(newHostConfig() - .withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2)) - ) + .withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2))) .exec(); LOG.info("Created container {}", container.toString()); @@ -135,8 +132,7 @@ public void startContainerWithDns() throws DockerException { String aDnsServer = "8.8.8.8"; String anotherDnsServer = "8.8.4.4"; - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") - .withCmd("true") + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true") .withHostConfig(newHostConfig() .withDns(aDnsServer, anotherDnsServer)) .exec(); @@ -158,8 +154,7 @@ public void startContainerWithDnsSearch() throws DockerException { String dnsSearch = "example.com"; - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") - .withCmd("true") + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true") .withHostConfig(newHostConfig() .withDnsSearch(dnsSearch)) .exec(); @@ -189,12 +184,10 @@ public void startContainerWithPortBindings() throws DockerException { portBindings.bind(tcp23, Binding.bindPort(baseport + 23)); portBindings.bind(tcp23, Binding.bindPort(baseport + 24)); - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") - .withCmd("true") + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true") .withExposedPorts(tcp22, tcp23) .withHostConfig(newHostConfig() - .withPortBindings(portBindings)) - .exec(); + .withPortBindings(portBindings)).exec(); LOG.info("Created container {}", container.toString()); @@ -230,8 +223,7 @@ public void startContainerWithRandomPortBindings() throws DockerException { portBindings.bind(tcp23, Binding.empty()); CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999") - .withExposedPorts(tcp22, tcp23) - .withHostConfig(newHostConfig() + .withExposedPorts(tcp22, tcp23).withHostConfig(newHostConfig() .withPortBindings(portBindings) .withPublishAllPorts(true)) .exec(); @@ -265,8 +257,7 @@ public void startContainerWithConflictingPortBindings() throws DockerException { portBindings.bind(tcp23, Binding.bindPort(11022)); CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true") - .withExposedPorts(tcp22, tcp23) - .withHostConfig(newHostConfig() + .withExposedPorts(tcp22, tcp23).withHostConfig(newHostConfig() .withPortBindings(portBindings)) .exec(); @@ -310,10 +301,8 @@ public void startContainerWithLinkingDeprecated() throws DockerException { assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0))); } - CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd("busybox") - .withCmd("sleep", "9999") - .withName(container2Name) - .withHostConfig(newHostConfig() + CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999") + .withName(container2Name).withHostConfig(newHostConfig() .withLinks(new Link(container1Name, container1Name + "Link"))) .exec(); @@ -374,8 +363,7 @@ public void startContainerWithLinking() throws DockerException { } CreateContainerResponse container2 = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999") - .withName(container2Name) - .withHostConfig(newHostConfig() + .withName(container2Name).withHostConfig(newHostConfig() .withLinks(new Link(container1Name, container1Name + "Link"))) .exec(); @@ -446,8 +434,7 @@ public void testStartNonExistingContainer() throws DockerException { @Test public void startContainerWithNetworkMode() throws DockerException { - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") - .withCmd("true") + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("true") .withHostConfig(newHostConfig() .withNetworkMode("host")) .exec(); @@ -493,7 +480,8 @@ public void startContainerWithCapAddAndCapDrop() throws DockerException { @Test public void startContainerWithDevices() throws DockerException { - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") + .withCmd("sleep", "9999") .withHostConfig(newHostConfig() .withDevices(new Device("rwm", "/dev/nulo", "/dev/zero"))) .exec(); @@ -539,9 +527,11 @@ public void startContainerWithRestartPolicy() throws DockerException { RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5); - CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") + .withCmd("sleep", "9999") .withHostConfig(newHostConfig() - .withRestartPolicy(restartPolicy)).exec(); + .withRestartPolicy(restartPolicy)) + .exec(); LOG.info("Created container {}", container.toString()); diff --git a/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java b/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java index d63f6aaa2..8ed3dc6f5 100644 --- a/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/UpdateContainerCmdIT.java @@ -71,8 +71,8 @@ public void updateContainer() throws DockerException, IOException { // assertThat(afterHostConfig.getBlkioWeight(), is(300)); assertThat(afterHostConfig.getCpuShares(), is(512)); - assertThat(afterHostConfig.getCpuPeriod(), is(100000)); - assertThat(afterHostConfig.getCpuQuota(), is(50000)); + assertThat(afterHostConfig.getCpuPeriod(), is(100000L)); + assertThat(afterHostConfig.getCpuQuota(), is(50000L)); assertThat(afterHostConfig.getCpusetMems(), is("0")); // assertThat(afterHostConfig.getMemoryReservation(), is(209715200L)); diff --git a/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java b/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java index 79759cdd2..686c24794 100644 --- a/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/swarm/SwarmCmdIT.java @@ -7,7 +7,6 @@ import com.github.dockerjava.api.exception.NotAcceptableException; import com.github.dockerjava.api.exception.NotFoundException; import com.github.dockerjava.api.model.ExposedPort; -import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.PortBinding; import com.github.dockerjava.api.model.Ports; import com.github.dockerjava.cmd.CmdIT; @@ -20,7 +19,6 @@ import com.github.dockerjava.netty.NettyDockerCmdExecFactory; import org.junit.After; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.experimental.categories.Category; import static com.github.dockerjava.api.model.HostConfig.newHostConfig; @@ -105,14 +103,14 @@ protected DockerClient startDockerInDocker() { CreateContainerResponse response = dockerRule.getClient() .createContainerCmd(DOCKER_IN_DOCKER_IMAGE_REPOSITORY + ":" + DOCKER_IN_DOCKER_IMAGE_TAG) .withHostConfig(newHostConfig() - .withPrivileged(true) .withNetworkMode(NETWORK_NAME) .withPortBindings(new PortBinding( Ports.Binding.bindIpAndPort("127.0.0.1", port), - ExposedPort.tcp(2375) - ))) + ExposedPort.tcp(2375))) + .withPrivileged(true)) .withName(name) .withAliases(name) + .exec(); dockerRule.getClient().startContainerCmd(response.getId()).exec(); From 36c93fbde4a157fe0f72fc8559c50958af8b73cb Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 26 Nov 2018 19:22:28 +0300 Subject: [PATCH 3/4] Fix test --- .../com/github/dockerjava/api/model/HealthCheck.java | 12 ++++++------ .../command/inspectContainerResponse_full_1_26a.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/dockerjava/api/model/HealthCheck.java b/src/main/java/com/github/dockerjava/api/model/HealthCheck.java index aba2fd8cd..a6581f261 100644 --- a/src/main/java/com/github/dockerjava/api/model/HealthCheck.java +++ b/src/main/java/com/github/dockerjava/api/model/HealthCheck.java @@ -35,10 +35,10 @@ public class HealthCheck implements Serializable { private static final long serialVersionUID = 1L; @JsonProperty("Interval") - private Integer interval; + private Long interval; @JsonProperty("Timeout") - private Integer timeout; + private Long timeout; /** * @since 1.26 @@ -58,20 +58,20 @@ public class HealthCheck implements Serializable { @JsonProperty("StartPeriod") private Integer startPeriod; - public Integer getInterval() { + public Long getInterval() { return interval; } - public Integer getTimeout() { + public Long getTimeout() { return timeout; } - public HealthCheck withInterval(Integer interval) { + public HealthCheck withInterval(Long interval) { this.interval = interval; return this; } - public HealthCheck withTimeout(Integer timeout) { + public HealthCheck withTimeout(Long timeout) { this.timeout = timeout; return this; } diff --git a/src/test/resources/com/github/dockerjava/api/command/inspectContainerResponse_full_1_26a.json b/src/test/resources/com/github/dockerjava/api/command/inspectContainerResponse_full_1_26a.json index 9c505c04b..2f3428d7a 100644 --- a/src/test/resources/com/github/dockerjava/api/command/inspectContainerResponse_full_1_26a.json +++ b/src/test/resources/com/github/dockerjava/api/command/inspectContainerResponse_full_1_26a.json @@ -36,7 +36,7 @@ "Memory" : 0, "MemorySwap" : 0, "CpuQuota" : 0, - "OomScoreAdj" : false, + "OomScoreAdj" : 500, "MemoryReservation" : 0 }, "Id" : "58fd1abe8e43a65fb6231b76a9678e7bb4e91686f838945e782a4b74119ce959", From 71245d76dc79542563d3082b5f664c0fd26aae3d Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 26 Nov 2018 20:01:29 +0300 Subject: [PATCH 4/4] Fix test --- .../java/com/github/dockerjava/cmd/CreateContainerCmdIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java b/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java index 3d5c03e1e..570f20f64 100644 --- a/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java +++ b/src/test/java/com/github/dockerjava/cmd/CreateContainerCmdIT.java @@ -318,7 +318,7 @@ public void createContainerWithMemorySwappiness() throws DockerException { .inspectContainerCmd(container.getId()) .exec(); LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); - assertSame(42, inspectContainerResponse.getHostConfig().getMemorySwappiness()); + assertSame(42L, inspectContainerResponse.getHostConfig().getMemorySwappiness()); } @Test