diff --git a/docs/devel.adoc b/docs/devel.adoc new file mode 100644 index 000000000..50c6a7279 --- /dev/null +++ b/docs/devel.adoc @@ -0,0 +1,25 @@ +### Code Design + * Model is based on Objects and not primitives that allows nullify requests and have null values for data + that wasn't provided by docker daemon. + * For null safeness findbugs annotations are used. + ** Every method that may return `null` (and we are unsure in any fields as docker daemon may change something) + should be annotated with `@CheckForNull` return qualifier from `javax.annotation` package. + ** Methods that can't return `null` must be annotated with `@Nonnull`. + ** The same for Arguments. + ** `@Nullable` must be used only for changing inherited (other typed) qualifier. + * Setters in builder style must be prefixed with `withXX`. + * All classes should provide `toString()` `equals()` and `hashCode()` defined methods. + * Javadocs + ** Provide full information on field: + *** For models define API version with `@since {@link RemoteApiVersion#VERSION_1_X}`. + ** getters/setters should refernce to field `@see #$field`. + +### Coding style + * TBD, some initial styling already enforced with checkstyle. + IDEA/checkstyle file analogues will be provided soon. + +### Testing + * Unit tests for serder (serialization-deserialization). + * Integration tests for commands. + * If model object has builders, then fill it with data and compare by `equals()` with expected response + from docker daemon. If failed, then some fields mappings are wrong. diff --git a/pom.xml b/pom.xml index d4a5b6947..ae08bf720 100644 --- a/pom.xml +++ b/pom.xml @@ -72,8 +72,8 @@ 2.2 2.3.1 2.3.1 - 2.17 - 2.17 + 2.19.1 + 2.19.1 1.7 @@ -124,6 +124,11 @@ commons-io ${commons-io.version} + + + + + org.slf4j slf4j-api diff --git a/src/main/java/com/github/dockerjava/api/DockerClient.java b/src/main/java/com/github/dockerjava/api/DockerClient.java index aaa3c5fcf..4ae45ec89 100644 --- a/src/main/java/com/github/dockerjava/api/DockerClient.java +++ b/src/main/java/com/github/dockerjava/api/DockerClient.java @@ -53,6 +53,7 @@ import com.github.dockerjava.api.command.TagImageCmd; import com.github.dockerjava.api.command.TopContainerCmd; import com.github.dockerjava.api.command.UnpauseContainerCmd; +import com.github.dockerjava.api.command.UpdateContainerCmd; import com.github.dockerjava.api.command.VersionCmd; import com.github.dockerjava.api.command.WaitContainerCmd; import com.github.dockerjava.api.exception.DockerException; @@ -175,6 +176,15 @@ public interface DockerClient extends Closeable { public KillContainerCmd killContainerCmd(@Nonnull String containerId); + /** + * Update container settings + * + * @param containerId id of the container + * @return command + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + public UpdateContainerCmd updateContainerCmd(@Nonnull String containerId); + public RestartContainerCmd restartContainerCmd(@Nonnull String containerId); public CommitCmd commitCmd(@Nonnull String containerId); 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 6b004c826..972739898 100644 --- a/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java +++ b/src/main/java/com/github/dockerjava/api/command/CreateContainerCmd.java @@ -80,6 +80,9 @@ public interface CreateContainerCmd extends SyncDockerCmd exposedPorts); /** diff --git a/src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java b/src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java index fc793558f..fcaad81fc 100644 --- a/src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java +++ b/src/main/java/com/github/dockerjava/api/command/DockerCmdExecFactory.java @@ -69,6 +69,8 @@ public interface DockerCmdExecFactory extends Closeable { public KillContainerCmd.Exec createKillContainerCmdExec(); + UpdateContainerCmd.Exec createUpdateContainerCmdExec(); + public RestartContainerCmd.Exec createRestartContainerCmdExec(); public CommitCmd.Exec createCommitCmdExec(); diff --git a/src/main/java/com/github/dockerjava/api/command/InspectExecResponse.java b/src/main/java/com/github/dockerjava/api/command/InspectExecResponse.java index 63f111dce..2833a5ade 100644 --- a/src/main/java/com/github/dockerjava/api/command/InspectExecResponse.java +++ b/src/main/java/com/github/dockerjava/api/command/InspectExecResponse.java @@ -9,6 +9,8 @@ import com.github.dockerjava.api.model.NetworkSettings; import com.github.dockerjava.core.RemoteApiVersion; +import javax.annotation.CheckForNull; + @JsonIgnoreProperties(ignoreUnknown = true) public class InspectExecResponse { @JsonProperty("ID") @@ -26,15 +28,37 @@ public class InspectExecResponse { @JsonProperty("Running") private Boolean running; + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("CanRemove") + private Boolean canRemove; + @JsonProperty("ExitCode") private Integer exitCode; @JsonProperty("ProcessConfig") private ProcessConfig processConfig; + /** + * @deprecated @since {@link RemoteApiVersion#VERSION_1_22} + */ + @Deprecated @JsonProperty("Container") private Container container; + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("ContainerID") + private String containerID; + + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("DetachKeys") + private String detachKeys; + public String getId() { return id; } @@ -63,10 +87,38 @@ public ProcessConfig getProcessConfig() { return processConfig; } + /** + * @see #container + */ + @Deprecated public Container getContainer() { return container; } + /** + * @see #canRemove + */ + @CheckForNull + public Boolean getCanRemove() { + return canRemove; + } + + /** + * @see #containerID + */ + @CheckForNull + public String getContainerID() { + return containerID; + } + + /** + * @see #detachKeys + */ + @CheckForNull + public String getDetachKeys() { + return detachKeys; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); diff --git a/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java b/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java new file mode 100644 index 000000000..3dc7a0773 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java @@ -0,0 +1,68 @@ +package com.github.dockerjava.api.command; + +import com.github.dockerjava.api.model.UpdateContainerResponse; + +import javax.annotation.CheckForNull; + +/** + * @author Kanstantsin Shautsou + */ +public interface UpdateContainerCmd extends SyncDockerCmd { + @CheckForNull + String getContainerId(); + + @CheckForNull + public Integer getBlkioWeight(); + + public UpdateContainerCmd withBlkioWeight(Integer blkioWeight); + + public UpdateContainerCmd withContainerId(String containerId); + + @CheckForNull + public Integer getCpuPeriod(); + + public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod); + + @CheckForNull + public Integer getCpuQuota(); + + public UpdateContainerCmd withCpuQuota(Integer cpuQuota); + + @CheckForNull + public String getCpusetCpus(); + + public UpdateContainerCmd withCpusetCpus(String cpusetCpus); + + @CheckForNull + public String getCpusetMems(); + + public UpdateContainerCmd withCpusetMems(String cpusetMems); + + @CheckForNull + public Integer getCpuShares(); + + public UpdateContainerCmd withCpuShares(Integer cpuShares); + + @CheckForNull + public Long getKernelMemory(); + + public UpdateContainerCmd withKernelMemory(Long kernelMemory); + + @CheckForNull + public Long getMemory(); + + public UpdateContainerCmd withMemory(Long memory); + + @CheckForNull + public Long getMemoryReservation(); + + public UpdateContainerCmd withMemoryReservation(Long memoryReservation); + + @CheckForNull + Long getMemorySwap(); + + UpdateContainerCmd withMemorySwap(Long memorySwap); + + interface Exec extends DockerCmdSyncExec { + } +} 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 ae7ebdda2..849f26a21 100644 --- a/src/main/java/com/github/dockerjava/api/model/AuthConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/AuthConfig.java @@ -7,6 +7,8 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import javax.annotation.CheckForNull; + @JsonInclude(Include.NON_NULL) public class AuthConfig { @@ -32,6 +34,12 @@ public class AuthConfig { @JsonProperty("auth") private String auth; + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("registrytoken") + private String registrytoken; + public String getUsername() { return username; } @@ -77,6 +85,22 @@ public AuthConfig withAuth(String auth) { return this; } + /** + * @see #registrytoken + */ + @CheckForNull + public String getRegistrytoken() { + return registrytoken; + } + + /** + * @see #registrytoken + */ + public AuthConfig withRegistrytoken(String registrytoken) { + this.registrytoken = registrytoken; + return this; + } + @Override public String toString() { return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE); diff --git a/src/main/java/com/github/dockerjava/api/model/Container.java b/src/main/java/com/github/dockerjava/api/model/Container.java index dcdf1699d..47492920d 100644 --- a/src/main/java/com/github/dockerjava/api/model/Container.java +++ b/src/main/java/com/github/dockerjava/api/model/Container.java @@ -1,18 +1,22 @@ package com.github.dockerjava.api.model; -import java.util.Map; - -import org.apache.commons.lang.builder.ToStringBuilder; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.api.command.ListContainersCmd; +import com.github.dockerjava.core.RemoteApiVersion; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import javax.annotation.CheckForNull; +import java.util.Map; /** + * Used for Listing containers. * * @author Konstantin Pelykh (kpelykh@gmail.com) - * */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(Include.NON_NULL) @@ -30,11 +34,17 @@ public class Container { @JsonProperty("Image") private String image; + /** + * @since since {@link RemoteApiVersion#VERSION_1_21} + */ + @JsonProperty("ImageID") + private String imageId; + @JsonProperty("Names") private String[] names; @JsonProperty("Ports") - public Port[] ports; + public ContainerPort[] ports; @JsonProperty("Labels") public Map labels; @@ -42,6 +52,35 @@ public class Container { @JsonProperty("Status") private String status; + /** + * @since ~{@link RemoteApiVersion#VERSION_1_19} + */ + @JsonProperty("SizeRw") + private Long sizeRw; + + /** + * Returns only when {@link ListContainersCmd#withShowSize(java.lang.Boolean)} set + * + * @since ~{@link RemoteApiVersion#VERSION_1_19} + */ + @JsonProperty("SizeRootFs") + private Long sizeRootFs; + + /** + * @since ~{@link RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("HostConfig") + private ContainerHostConfig hostConfig; + + /** + * Docker API docs says "list of networks", but json names `networkSettings`. + * So, reusing existed NetworkSettings model object. + * + * @since ~{@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("NetworkSettings") + private ContainerNetworkSettings networkSettings; + public String getId() { return id; } @@ -54,6 +93,11 @@ public String getImage() { return image; } + @CheckForNull + public String getImageId() { + return imageId; + } + public Long getCreated() { return created; } @@ -62,7 +106,7 @@ public String getStatus() { return status; } - public Port[] getPorts() { + public ContainerPort[] getPorts() { return ports; } @@ -74,45 +118,50 @@ public String[] getNames() { return names; } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); + /** + * @see #sizeRw + */ + @CheckForNull + public Long getSizeRw() { + return sizeRw; } - @JsonIgnoreProperties(ignoreUnknown = true) - public static class Port { - - @JsonProperty("IP") - private String ip; - - @JsonProperty("PrivatePort") - private Integer privatePort; - - @JsonProperty("PublicPort") - private Integer publicPort; - - @JsonProperty("Type") - private String type; + /** + * @see #sizeRootFs + */ + @CheckForNull + public Long getSizeRootFs() { + return sizeRootFs; + } - public String getIp() { - return ip; - } + /** + * @see #networkSettings + */ + @CheckForNull + public ContainerNetworkSettings getNetworkSettings() { + return networkSettings; + } - public Integer getPrivatePort() { - return privatePort; - } + /** + * @see #hostConfig + */ + @CheckForNull + public ContainerHostConfig getHostConfig() { + return hostConfig; + } - public Integer getPublicPort() { - return publicPort; - } + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } - public String getType() { - return type; - } + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); } } diff --git a/src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java b/src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java new file mode 100644 index 000000000..43a5a94b1 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java @@ -0,0 +1,46 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +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; + +/** + * Used in {@link Container} + * + * @see Container + * @author Kanstantsin Shautsou + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContainerHostConfig { + @JsonProperty("NetworkMode") + private String networkMode; + + public String getNetworkMode() { + return networkMode; + } + + /** + * @see #networkMode + */ + public ContainerHostConfig withNetworkMode(String networkMode) { + this.networkMode = networkMode; + 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/ContainerNetwork.java b/src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java new file mode 100644 index 000000000..4bfde8bfd --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java @@ -0,0 +1,273 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.core.RemoteApiVersion; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import javax.annotation.CheckForNull; +import java.util.List; + +/** + * @see ContainerNetworkSettings + * @author Kanstantsin Shautsou + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContainerNetwork { + /** + * FIXME verify + */ + @JsonProperty("IPAMConfig") + private Network.Ipam.Config ipamConfig; + + /** + * FIXME verify + */ + @JsonProperty("Links") + private List links; + + /** + * FIXME no docs, unknown field. + * Type picked from `docker/vendor/src/github.com/docker/engine-api/types/network/network.go` + * + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("Aliases") + private List aliases; + + @JsonProperty("NetworkID") + private String networkID; + + @JsonProperty("EndpointID") + private String endpointId; + + @JsonProperty("Gateway") + private String gateway; + + @JsonProperty("IPAddress") + private String ipAddress; + + @JsonProperty("IPPrefixLen") + private Integer ipPrefixLen; + + @JsonProperty("IPv6Gateway") + private String ipV6Gateway; + + @JsonProperty("GlobalIPv6Address") + private String globalIPv6Address; + + @JsonProperty("GlobalIPv6PrefixLen") + private Integer globalIPv6PrefixLen; + + @JsonProperty("MacAddress") + private String macAddress; + + /** + * @see #aliases + */ + @CheckForNull + public List getAliases() { + return aliases; + } + + /** + * @see #aliases + */ + public ContainerNetwork withAliases(List aliases) { + this.aliases = aliases; + return this; + } + + /** + * @see #endpointId + */ + @CheckForNull + public String getEndpointId() { + return endpointId; + } + + /** + * @see #endpointId + */ + public ContainerNetwork withEndpointId(String endpointId) { + this.endpointId = endpointId; + return this; + } + + /** + * @see #gateway + */ + @CheckForNull + public String getGateway() { + return gateway; + } + + /** + * @see #gateway + */ + public ContainerNetwork withGateway(String gateway) { + this.gateway = gateway; + return this; + } + + /** + * @see #globalIPv6Address + */ + @CheckForNull + public String getGlobalIPv6Address() { + return globalIPv6Address; + } + + /** + * @see #globalIPv6Address + */ + public ContainerNetwork withGlobalIPv6Address(String globalIPv6Address) { + this.globalIPv6Address = globalIPv6Address; + return this; + } + + /** + * @see #globalIPv6PrefixLen + */ + @CheckForNull + public Integer getGlobalIPv6PrefixLen() { + return globalIPv6PrefixLen; + } + + /** + * @see #globalIPv6PrefixLen + */ + public ContainerNetwork withGlobalIPv6PrefixLen(Integer globalIPv6PrefixLen) { + this.globalIPv6PrefixLen = globalIPv6PrefixLen; + return this; + } + + /** + * @see #ipAddress + */ + @CheckForNull + public String getIpAddress() { + return ipAddress; + } + + /** + * @see #ipAddress + */ + public ContainerNetwork withIpAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + /** + * @see #ipamConfig + */ + @CheckForNull + public Network.Ipam.Config getIpamConfig() { + return ipamConfig; + } + + /** + * @see #ipamConfig + */ + public ContainerNetwork withIpamConfig(Network.Ipam.Config ipamConfig) { + this.ipamConfig = ipamConfig; + return this; + } + + /** + * @see #ipPrefixLen + */ + @CheckForNull + public Integer getIpPrefixLen() { + return ipPrefixLen; + } + + /** + * @see #ipPrefixLen + */ + public ContainerNetwork withIpPrefixLen(Integer ipPrefixLen) { + this.ipPrefixLen = ipPrefixLen; + return this; + } + + /** + * @see #ipV6Gateway + */ + @CheckForNull + public String getIpV6Gateway() { + return ipV6Gateway; + } + + /** + * @see #ipV6Gateway + */ + public ContainerNetwork withIpV6Gateway(String ipV6Gateway) { + this.ipV6Gateway = ipV6Gateway; + return this; + } + + /** + * @see #links + */ + @CheckForNull + public List getLinks() { + return links; + } + + /** + * @see #links + */ + public ContainerNetwork withLinks(List links) { + this.links = links; + return this; + } + + /** + * @see #macAddress + */ + @CheckForNull + public String getMacAddress() { + return macAddress; + } + + /** + * @see #macAddress + */ + public ContainerNetwork withMacAddress(String macAddress) { + this.macAddress = macAddress; + return this; + } + + /** + * @see #networkID + */ + @CheckForNull + public String getNetworkID() { + return networkID; + } + + /** + * @see #networkID + */ + public ContainerNetwork withNetworkID(String networkID) { + this.networkID = networkID; + 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/ContainerNetworkSettings.java b/src/main/java/com/github/dockerjava/api/model/ContainerNetworkSettings.java new file mode 100644 index 000000000..7f4b17be5 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerNetworkSettings.java @@ -0,0 +1,55 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.core.RemoteApiVersion; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.Map; + +/** + * Sub-object in {@link Container} + * + * @see Container + * @since {@link RemoteApiVersion#VERSION_1_22} + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContainerNetworkSettings { + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("Networks") + private Map networks; + + /** + * @see #networks + */ + public Map getNetworks() { + return networks; + } + + /** + * @see #networks + */ + public ContainerNetworkSettings withNetworks(Map networks) { + this.networks = networks; + 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/ContainerPort.java b/src/main/java/com/github/dockerjava/api/model/ContainerPort.java new file mode 100644 index 000000000..09f718ef6 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerPort.java @@ -0,0 +1,108 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +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 javax.annotation.CheckForNull; + +/** + * @author Kanstantsin Shautsou + * @see Container + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContainerPort { + + @JsonProperty("IP") + private String ip; + + @JsonProperty("PrivatePort") + private Integer privatePort; + + @JsonProperty("PublicPort") + private Integer publicPort; + + @JsonProperty("Type") + private String type; + + /** + * @see #ip + */ + @CheckForNull + public String getIp() { + return ip; + } + + /** + * @see #ip + */ + public ContainerPort withIp(String ip) { + this.ip = ip; + return this; + } + + /** + * @see #privatePort + */ + @CheckForNull + public Integer getPrivatePort() { + return privatePort; + } + + /** + * @see #privatePort + */ + public ContainerPort withPrivatePort(Integer privatePort) { + this.privatePort = privatePort; + return this; + } + + /** + * @see #publicPort + */ + @CheckForNull + public Integer getPublicPort() { + return publicPort; + } + + /** + * @see #publicPort + */ + public ContainerPort withPublicPort(Integer publicPort) { + this.publicPort = publicPort; + return this; + } + + /** + * @see #type + */ + @CheckForNull + public String getType() { + return type; + } + + /** + * @see #type + */ + public ContainerPort withType(String type) { + this.type = type; + 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 edad5cfcb..e5d974c2d 100644 --- a/src/main/java/com/github/dockerjava/api/model/HostConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/HostConfig.java @@ -1,15 +1,21 @@ package com.github.dockerjava.api.model; -import javax.annotation.CheckForNull; - -import org.apache.commons.lang.builder.ToStringBuilder; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.core.RemoteApiVersion; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import javax.annotation.CheckForNull; +import java.util.List; +/** + * Used in `/containers/create`. + */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(Include.NON_NULL) public class HostConfig { @@ -20,6 +26,42 @@ public class HostConfig { @JsonProperty("BlkioWeight") private Integer blkioWeight; + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("BlkioWeightDevice") + private List blkioWeightDevice; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("BlkioDeviceReadBps") + private List blkioDeviceReadBps; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("BlkioDeviceReadIOps") + private List blkioDeviceReadIOps; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("BlkioDeviceWriteBps") + private List blkioDeviceWriteBps; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("BlkioDeviceWriteIOps") + private List blkioDeviceWriteIOps; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("MemorySwappiness") + private Integer memorySwappiness; + @JsonProperty("CapAdd") private Capability[] capAdd; @@ -35,6 +77,12 @@ public class HostConfig { @JsonProperty("CpuShares") private Integer cpuShares; + /** + * @since ~{@link RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("CpuQuota") + private Integer cpuQuota; + @JsonProperty("CpusetCpus") private String cpusetCpus; @@ -68,12 +116,30 @@ public class HostConfig { @JsonProperty("MemorySwap") private Long memorySwap; + /** + * @since {@link RemoteApiVersion#VERSION_1_21} + */ + @JsonProperty("MemoryReservation") + private Long memoryReservation; + + /** + * @since {@link RemoteApiVersion#VERSION_1_21} + */ + @JsonProperty("KernelMemory") + private Long kernelMemory; + @JsonProperty("NetworkMode") private String networkMode; @JsonProperty("OomKillDisable") private Boolean oomKillDisable; + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("OomScoreAdj") + private Boolean oomScoreAdj; + @JsonProperty("PortBindings") private Ports portBindings; @@ -98,6 +164,31 @@ public class HostConfig { @JsonProperty("PidMode") private String pidMode; + /** + * @since {@link RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("SecurityOpt") + private List securityOpts; + + /** + * @since {@link RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("CgroupParent") + private String cgroupParent; + + /** + * @since {@link RemoteApiVersion#VERSION_1_21} + */ + @JsonProperty("VolumeDriver") + private String volumeDriver; + + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("ShmSize") + private String shmSize; + + @JsonIgnore public Bind[] getBinds() { return (binds == null) ? new Bind[0] : binds.getBinds(); @@ -214,124 +305,486 @@ public String getPidMode() { return pidMode; } + /** + * @see #blkioDeviceReadBps + */ + @CheckForNull + public List getBlkioDeviceReadBps() { + return blkioDeviceReadBps; + } + + /** + * @see #blkioDeviceReadIOps + */ + @CheckForNull + public List getBlkioDeviceReadIOps() { + return blkioDeviceReadIOps; + } + + /** + * @see #blkioDeviceWriteBps + */ + @CheckForNull + public List getBlkioDeviceWriteBps() { + return blkioDeviceWriteBps; + } + + /** + * @see #blkioDeviceWriteIOps + */ + @CheckForNull + public List getBlkioDeviceWriteIOps() { + return blkioDeviceWriteIOps; + } + + /** + * @see #blkioWeightDevice + */ + @CheckForNull + public List getBlkioWeightDevice() { + return blkioWeightDevice; + } + + /** + * @see #oomScoreAdj + */ + @CheckForNull + public Boolean getOomScoreAdj() { + return oomScoreAdj; + } + + /** + * @see #cpuQuota + */ + @CheckForNull + public Integer getCpuQuota() { + return cpuQuota; + } + + /** + * @see #kernelMemory + */ + @CheckForNull + public Long getKernelMemory() { + return kernelMemory; + } + + /** + * @see #memoryReservation + */ + @CheckForNull + public Long getMemoryReservation() { + return memoryReservation; + } + + /** + * @see #memorySwappiness + */ + @CheckForNull + public Integer getMemorySwappiness() { + return memorySwappiness; + } + + /** + * @see #oomKillDisable + */ + @CheckForNull + public Boolean getOomKillDisable() { + return oomKillDisable; + } + + /** + * @see #securityOpts + */ + @CheckForNull + public List getSecurityOpts() { + return securityOpts; + } + + /** + * @see #cgroupParent + */ + @CheckForNull + public String getCgroupParent() { + return cgroupParent; + } + + /** + * @see #shmSize + */ + @CheckForNull + public String getShmSize() { + return shmSize; + } + + /** + * @see #volumeDriver + */ + @CheckForNull + public String getVolumeDriver() { + return volumeDriver; + } + @JsonIgnore public void setBinds(Bind... binds) { this.binds = new Binds(binds); } - public void setBlkioWeight(Integer blkioWeight) { - this.blkioWeight = blkioWeight; + @JsonIgnore + public void setLinks(Link... links) { + this.links = new Links(links); } - public void setCpuPeriod(Integer cpuPeriod) { - this.cpuPeriod = cpuPeriod; + // auto-generated builder setters + /** + * @see #binds + */ + public HostConfig withBinds(Binds binds) { + this.binds = binds; + return this; } - public void setCpuShares(Integer cpuShares) { - this.cpuShares = cpuShares; + /** + * @see #blkioDeviceReadBps + */ + public HostConfig withBlkioDeviceReadBps(List blkioDeviceReadBps) { + this.blkioDeviceReadBps = blkioDeviceReadBps; + return this; } - public void setCpusetCpus(String cpusetCpus) { - this.cpusetCpus = cpusetCpus; + /** + * @see #blkioDeviceReadIOps + */ + public HostConfig withBlkioDeviceReadIOps(List blkioDeviceReadIOps) { + this.blkioDeviceReadIOps = blkioDeviceReadIOps; + return this; } - public void setCpusetMems(String cpusetMems) { - this.cpusetMems = cpusetMems; + /** + * @see #blkioDeviceWriteBps + */ + public HostConfig withBlkioDeviceWriteBps(List blkioDeviceWriteBps) { + this.blkioDeviceWriteBps = blkioDeviceWriteBps; + return this; + } + + /** + * @see #blkioDeviceWriteIOps + */ + public HostConfig withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { + this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; + return this; + } + + /** + * @see #blkioWeight + */ + public HostConfig withBlkioWeight(Integer blkioWeight) { + this.blkioWeight = blkioWeight; + return this; } - public void setCapAdd(Capability[] capAdd) { + /** + * @see #blkioWeightDevice + */ + public HostConfig withBlkioWeightDevice(List blkioWeightDevice) { + this.blkioWeightDevice = blkioWeightDevice; + return this; + } + + /** + * @see #capAdd + */ + public HostConfig withCapAdd(Capability[] capAdd) { this.capAdd = capAdd; + return this; } - public void setCapDrop(Capability[] capDrop) { + /** + * @see #capDrop + */ + public HostConfig withCapDrop(Capability[] capDrop) { this.capDrop = capDrop; + return this; + } + + /** + * @see #cgroupParent + */ + public HostConfig withCgroupParent(String cgroupParent) { + this.cgroupParent = cgroupParent; + return this; } - public void setContainerIDFile(String containerIDFile) { + /** + * @see #containerIDFile + */ + public HostConfig withContainerIDFile(String containerIDFile) { this.containerIDFile = containerIDFile; + return this; + } + + /** + * @see #cpuPeriod + */ + public HostConfig withCpuPeriod(Integer cpuPeriod) { + this.cpuPeriod = cpuPeriod; + return this; + } + + /** + * @see #cpuQuota + */ + public HostConfig withCpuQuota(Integer cpuQuota) { + this.cpuQuota = cpuQuota; + return this; + } + + /** + * @see #cpusetCpus + */ + public HostConfig withCpusetCpus(String cpusetCpus) { + this.cpusetCpus = cpusetCpus; + return this; + } + + /** + * @see #cpusetMems + */ + public HostConfig withCpusetMems(String cpusetMems) { + this.cpusetMems = cpusetMems; + return this; } - public void setDevices(Device[] devices) { + /** + * @see #cpuShares + */ + public HostConfig withCpuShares(Integer cpuShares) { + this.cpuShares = cpuShares; + return this; + } + + /** + * @see #devices + */ + public HostConfig withDevices(Device[] devices) { this.devices = devices; + return this; } - public void setDns(String[] dns) { + /** + * @see #dns + */ + public HostConfig withDns(String[] dns) { this.dns = dns; + return this; } - public void setDnsSearch(String[] dnsSearch) { + /** + * @see #dnsSearch + */ + public HostConfig withDnsSearch(String[] dnsSearch) { this.dnsSearch = dnsSearch; + return this; } - public void setExtraHosts(String[] extraHosts) { + /** + * @see #extraHosts + */ + public HostConfig withExtraHosts(String[] extraHosts) { this.extraHosts = extraHosts; + return this; } - @JsonIgnore - public void setLinks(Link... links) { - this.links = new Links(links); + /** + * @see #kernelMemory + */ + public HostConfig withKernelMemory(Long kernelMemory) { + this.kernelMemory = kernelMemory; + return this; } - @JsonIgnore - public void setLogConfig(LogConfig logConfig) { + /** + * @see #links + */ + public HostConfig withLinks(Links links) { + this.links = links; + return this; + } + + /** + * @see #logConfig + */ + public HostConfig withLogConfig(LogConfig logConfig) { this.logConfig = logConfig; + return this; } - public void setLxcConf(LxcConf[] lxcConf) { + /** + * @see #lxcConf + */ + public HostConfig withLxcConf(LxcConf[] lxcConf) { this.lxcConf = lxcConf; + return this; } - public void setMemory(Long memory) { + /** + * @see #memory + */ + public HostConfig withMemory(Long memory) { this.memory = memory; + return this; + } + + /** + * @see #memoryReservation + */ + public HostConfig withMemoryReservation(Long memoryReservation) { + this.memoryReservation = memoryReservation; + return this; } - public void setMemorySwap(Long memorySwap) { + /** + * @see #memorySwap + */ + public HostConfig withMemorySwap(Long memorySwap) { this.memorySwap = memorySwap; + return this; } - public void setNetworkMode(String networkMode) { + /** + * @see #memorySwappiness + */ + public HostConfig withMemorySwappiness(Integer memorySwappiness) { + this.memorySwappiness = memorySwappiness; + return this; + } + + /** + * @see #networkMode + */ + public HostConfig withNetworkMode(String networkMode) { this.networkMode = networkMode; + return this; } - public void setOomKillDisable(Boolean oomKillDisable) { + /** + * @see #oomKillDisable + */ + public HostConfig withOomKillDisable(Boolean oomKillDisable) { this.oomKillDisable = oomKillDisable; + return this; + } + + /** + * @see #oomScoreAdj + */ + public HostConfig withOomScoreAdj(Boolean oomScoreAdj) { + this.oomScoreAdj = oomScoreAdj; + return this; } - public void setPortBindings(Ports portBindings) { + /** + * @see #pidMode + */ + public HostConfig withPidMode(String pidMode) { + this.pidMode = pidMode; + return this; + } + + /** + * @see #portBindings + */ + public HostConfig withPortBindings(Ports portBindings) { this.portBindings = portBindings; + return this; } - public void setPrivileged(Boolean privileged) { + /** + * @see #privileged + */ + public HostConfig withPrivileged(Boolean privileged) { this.privileged = privileged; + return this; } - public void setPublishAllPorts(Boolean publishAllPorts) { + /** + * @see #publishAllPorts + */ + public HostConfig withPublishAllPorts(Boolean publishAllPorts) { this.publishAllPorts = publishAllPorts; + return this; } - public void setReadonlyRootfs(Boolean readonlyRootfs) { + /** + * @see #readonlyRootfs + */ + public HostConfig withReadonlyRootfs(Boolean readonlyRootfs) { this.readonlyRootfs = readonlyRootfs; + return this; } - public void setRestartPolicy(RestartPolicy restartPolicy) { + /** + * @see #restartPolicy + */ + public HostConfig withRestartPolicy(RestartPolicy restartPolicy) { this.restartPolicy = restartPolicy; + return this; + } + + /** + * @see #securityOpts + */ + public HostConfig withSecurityOpts(List securityOpts) { + this.securityOpts = securityOpts; + return this; + } + + /** + * @see #shmSize + */ + public HostConfig withShmSize(String shmSize) { + this.shmSize = shmSize; + return this; } - public void setUlimits(Ulimit[] ulimits) { + /** + * @see #ulimits + */ + public HostConfig withUlimits(Ulimit[] ulimits) { this.ulimits = ulimits; + return this; } - public void setVolumesFrom(VolumesFrom[] volumesFrom) { - this.volumesFrom = volumesFrom; + /** + * @see #volumeDriver + */ + public HostConfig withVolumeDriver(String volumeDriver) { + this.volumeDriver = volumeDriver; + return this; } - public void setPidMode(String pidMode) { - this.pidMode = pidMode; + /** + * @see #volumesFrom + */ + public HostConfig withVolumesFrom(VolumesFrom[] volumesFrom) { + this.volumesFrom = volumesFrom; + return this; } + // end of auto-generated @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/Info.java b/src/main/java/com/github/dockerjava/api/model/Info.java index 0e4816cce..7270eceb8 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -1,29 +1,80 @@ package com.github.dockerjava.api.model; -import java.util.List; - -import org.apache.commons.lang.builder.ToStringBuilder; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; 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 javax.annotation.CheckForNull; +import java.util.List; +import java.util.Map; /** + * Used for `/info` * * @author Konstantin Pelykh (kpelykh@gmail.com) - * */ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Info { + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("Architecture") + private String architecture; + @JsonProperty("Containers") private Integer containers; + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("ContainersStopped") + private Integer containersStopped; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("ContainersPaused") + private Integer containersPaused; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("ContainersRunning") + private Integer containersRunning; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("CpuCfsPeriod") + private Boolean cpuCfsPeriod; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("CpuCfsQuota") + private Boolean cpuCfsQuota; + + @JsonProperty("CPUShares") + private Boolean cpuShares; + + @JsonProperty("CPUSet") + private Boolean cpuSet; + @JsonProperty("Debug") private Boolean debug; + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_21} + */ + @JsonProperty("DiscoveryBackend") + private String discoveryBackend; + @JsonProperty("DockerRootDir") private String dockerRootDir; @@ -31,17 +82,53 @@ public class Info { private String driver; @JsonProperty("DriverStatus") - private List driverStatuses; + private List> driverStatuses; + + @JsonProperty("SystemStatus") + private List systemStatus; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("Plugins") + private Map> plugins; @JsonProperty("ExecutionDriver") private String executionDriver; + @JsonProperty("LoggingDriver") + private String loggingDriver; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("ExperimentalBuild") + private Boolean experimentalBuild; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("HttpProxy") + private String httpProxy; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("HttpsProxy") + private String httpsProxy; + @JsonProperty("ID") private String id; @JsonProperty("IPv4Forwarding") private Boolean ipv4Forwarding; + @JsonProperty("BridgeNfIptables") + private Boolean bridgeNfIptables; + + @JsonProperty("BridgeNfIp6tables") + private Boolean bridgeNfIp6tables; + @JsonProperty("Images") private Integer images; @@ -73,7 +160,7 @@ public class Info { private Integer ncpu; @JsonProperty("NEventsListener") - private Long nEventListener; + private Integer nEventsListener; @JsonProperty("NFd") private Integer nfd; @@ -81,113 +168,872 @@ public class Info { @JsonProperty("NGoroutines") private Integer nGoroutines; + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("NoProxy") + private String noProxy; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("OomKillDisable") + private Boolean oomKillDisable; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("OSType") + private String osType; + + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("OomScoreAdj") + private Integer oomScoreAdj; + @JsonProperty("OperatingSystem") private String operatingSystem; + @JsonProperty("RegistryConfig") + private InfoRegistryConfig registryConfig; + @JsonProperty("Sockets") private String[] sockets; @JsonProperty("SwapLimit") private Boolean swapLimit; - public Boolean isDebug() { - return debug; + /** + * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("SystemTime") + private String systemTime; + + /** + * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_21} + */ + @JsonProperty("ServerVersion") + private String serverVersion; + + @JsonProperty("ClusterStore") + private String clusterStore; + + @JsonProperty("ClusterAdvertise") + private String clusterAdvertise; + + /** + * @see #architecture + */ + @CheckForNull + public String getArchitecture() { + return architecture; + } + + /** + * @see #architecture + */ + public Info withArchitecture(String architecture) { + this.architecture = architecture; + return this; } + /** + * @see #containers + */ + @CheckForNull public Integer getContainers() { return containers; } + /** + * @see #containers + */ + public Info withContainers(Integer containers) { + this.containers = containers; + return this; + } + + /** + * @see #containersPaused + */ + @CheckForNull + public Integer getContainersPaused() { + return containersPaused; + } + + /** + * @see #containersPaused + */ + public Info withContainersPaused(Integer containersPaused) { + this.containersPaused = containersPaused; + return this; + } + + /** + * @see #containersRunning + */ + @CheckForNull + public Integer getContainersRunning() { + return containersRunning; + } + + /** + * @see #containersRunning + */ + public Info withContainersRunning(Integer containersRunning) { + this.containersRunning = containersRunning; + return this; + } + + /** + * @see #containersStopped + */ + @CheckForNull + public Integer getContainersStopped() { + return containersStopped; + } + + /** + * @see #containersStopped + */ + public Info withContainersStopped(Integer containersStopped) { + this.containersStopped = containersStopped; + return this; + } + + /** + * @see #cpuCfsPeriod + */ + @CheckForNull + public Boolean getCpuCfsPeriod() { + return cpuCfsPeriod; + } + + /** + * @see #cpuCfsPeriod + */ + public Info withCpuCfsPeriod(Boolean cpuCfsPeriod) { + this.cpuCfsPeriod = cpuCfsPeriod; + return this; + } + + /** + * @see #cpuCfsQuota + */ + @CheckForNull + public Boolean getCpuCfsQuota() { + return cpuCfsQuota; + } + + /** + * @see #cpuCfsQuota + */ + public Info withCpuCfsQuota(Boolean cpuCfsQuota) { + this.cpuCfsQuota = cpuCfsQuota; + return this; + } + + /** + * @see #cpuShares + */ + @CheckForNull + public Boolean getCpuShares() { + return cpuShares; + } + + /** + * @see #cpuShares + */ + public Info withCpuShares(Boolean cpuShares) { + this.cpuShares = cpuShares; + return this; + } + + /** + * @see #cpuSet + */ + @CheckForNull + public Boolean getCpuSet() { + return cpuSet; + } + + /** + * @see #cpuSet + */ + public Info withCpuSet(Boolean cpuSet) { + this.cpuSet = cpuSet; + return this; + } + + /** + * @see #debug + */ + @CheckForNull + public Boolean getDebug() { + return debug; + } + + /** + * @see #debug + */ + public Info withDebug(Boolean debug) { + this.debug = debug; + return this; + } + + /** + * @see #discoveryBackend + */ + @CheckForNull + public String getDiscoveryBackend() { + return discoveryBackend; + } + + /** + * @see #discoveryBackend + */ + public Info withDiscoveryBackend(String discoveryBackend) { + this.discoveryBackend = discoveryBackend; + return this; + } + + /** + * @see #dockerRootDir + */ + @CheckForNull public String getDockerRootDir() { return dockerRootDir; } + /** + * @see #dockerRootDir + */ + public Info withDockerRootDir(String dockerRootDir) { + this.dockerRootDir = dockerRootDir; + return this; + } + + /** + * @see #driver + */ + @CheckForNull public String getDriver() { return driver; } - public List getDriverStatuses() { + /** + * @see #driver + */ + public Info withDriver(String driver) { + this.driver = driver; + return this; + } + + /** + * @see #driverStatuses + */ + @CheckForNull + public List> getDriverStatuses() { return driverStatuses; } - public Integer getImages() { - return images; + /** + * @see #driverStatuses + */ + public Info withDriverStatuses(List> driverStatuses) { + this.driverStatuses = driverStatuses; + return this; + } + + /** + * @see #executionDriver + */ + @CheckForNull + public String getExecutionDriver() { + return executionDriver; + } + + /** + * @see #executionDriver + */ + public Info withExecutionDriver(String executionDriver) { + this.executionDriver = executionDriver; + return this; + } + + /** + * @see #loggingDriver + */ + @CheckForNull + public String getLoggingDriver() { + return loggingDriver; + } + + /** + * @see #loggingDriver + */ + public Info withLoggingDriver(String loggingDriver) { + this.loggingDriver = loggingDriver; + return this; } - public String getID() { + /** + * @see #experimentalBuild + */ + @CheckForNull + public Boolean getExperimentalBuild() { + return experimentalBuild; + } + + /** + * @see #experimentalBuild + */ + public Info withExperimentalBuild(Boolean experimentalBuild) { + this.experimentalBuild = experimentalBuild; + return this; + } + + /** + * @see #httpProxy + */ + @CheckForNull + public String getHttpProxy() { + return httpProxy; + } + + /** + * @see #httpProxy + */ + public Info withHttpProxy(String httpProxy) { + this.httpProxy = httpProxy; + return this; + } + + /** + * @see #httpsProxy + */ + @CheckForNull + public String getHttpsProxy() { + return httpsProxy; + } + + /** + * @see #httpsProxy + */ + public Info withHttpsProxy(String httpsProxy) { + this.httpsProxy = httpsProxy; + return this; + } + + /** + * @see #id + */ + @CheckForNull + public String getId() { return id; } - public Boolean getIPv4Forwarding() { - return ipv4Forwarding; + /** + * @see #id + */ + public Info withId(String id) { + this.id = id; + return this; + } + + /** + * @see #images + */ + @CheckForNull + public Integer getImages() { + return images; + } + + /** + * @see #images + */ + public Info withImages(Integer images) { + this.images = images; + return this; } + /** + * @see #indexServerAddress + */ + @CheckForNull public String getIndexServerAddress() { return indexServerAddress; } + /** + * @see #indexServerAddress + */ + public Info withIndexServerAddress(String indexServerAddress) { + this.indexServerAddress = indexServerAddress; + return this; + } + + /** + * @see #initPath + */ + @CheckForNull public String getInitPath() { return initPath; } + /** + * @see #initPath + */ + public Info withInitPath(String initPath) { + this.initPath = initPath; + return this; + } + + /** + * @see #initSha1 + */ + @CheckForNull public String getInitSha1() { return initSha1; } + /** + * @see #initSha1 + */ + public Info withInitSha1(String initSha1) { + this.initSha1 = initSha1; + return this; + } + + /** + * @see #ipv4Forwarding + */ + @CheckForNull + public Boolean getIPv4Forwarding() { + return ipv4Forwarding; + } + + /** + * @see #ipv4Forwarding + */ + public Info withIPv4Forwarding(Boolean ipv4Forwarding) { + this.ipv4Forwarding = ipv4Forwarding; + return this; + } + + /** + * @see #bridgeNfIptables + */ + @CheckForNull + public Boolean getBridgeNfIptables() { + return bridgeNfIptables; + } + + /** + * @see #bridgeNfIptables + */ + public Info withBridgeNfIptables(Boolean bridgeNfIptables) { + this.bridgeNfIptables = bridgeNfIptables; + return this; + } + + /** + * @see #bridgeNfIp6tables + */ + @CheckForNull + public Boolean getBridgeNfIp6tables() { + return bridgeNfIp6tables; + } + + /** + * @see #bridgeNfIp6tables + */ + public Info withBridgeNfIp6tables(Boolean bridgeNfIp6tables) { + this.bridgeNfIp6tables = bridgeNfIp6tables; + return this; + } + + /** + * @see #kernelVersion + */ + @CheckForNull public String getKernelVersion() { return kernelVersion; } + /** + * @see #kernelVersion + */ + public Info withKernelVersion(String kernelVersion) { + this.kernelVersion = kernelVersion; + return this; + } + + /** + * @see #labels + */ + @CheckForNull public String[] getLabels() { return labels; } - public String[] getSockets() { - return sockets; + /** + * @see #labels + */ + public Info withLabels(String[] labels) { + this.labels = labels; + return this; } - public Boolean isMemoryLimit() { + /** + * @see #memoryLimit + */ + @CheckForNull + public Boolean getMemoryLimit() { return memoryLimit; } - public Long getnEventListener() { - return nEventListener; + /** + * @see #memoryLimit + */ + public Info withMemoryLimit(Boolean memoryLimit) { + this.memoryLimit = memoryLimit; + return this; } + /** + * @see #memTotal + */ + @CheckForNull public Long getMemTotal() { return memTotal; } + /** + * @see #memTotal + */ + public Info withMemTotal(Long memTotal) { + this.memTotal = memTotal; + return this; + } + + /** + * @see #name + */ + @CheckForNull public String getName() { return name; } + /** + * @see #name + */ + public Info withName(String name) { + this.name = name; + return this; + } + + /** + * @see #ncpu + */ + @CheckForNull public Integer getNCPU() { return ncpu; } + /** + * @see #ncpu + */ + public Info withNCPU(Integer ncpu) { + this.ncpu = ncpu; + return this; + } + + /** + * @see #nEventsListener + */ + @CheckForNull + public Integer getNEventsListener() { + return nEventsListener; + } + + /** + * @see #nEventsListener + */ + public Info withNEventsListener(Integer nEventListener) { + this.nEventsListener = nEventListener; + return this; + } + + /** + * @see #nfd + */ + @CheckForNull public Integer getNFd() { return nfd; } + /** + * @see #nfd + */ + public Info withNFd(Integer nfd) { + this.nfd = nfd; + return this; + } + + /** + * @see #nGoroutines + */ + @CheckForNull public Integer getNGoroutines() { return nGoroutines; } + /** + * @see #nGoroutines + */ + public Info withNGoroutines(Integer nGoroutines) { + this.nGoroutines = nGoroutines; + return this; + } + + /** + * @see #noProxy + */ + @CheckForNull + public String getNoProxy() { + return noProxy; + } + + /** + * @see #noProxy + */ + public Info withNoProxy(String noProxy) { + this.noProxy = noProxy; + return this; + } + + /** + * @see #oomKillDisable + */ + @CheckForNull + public Boolean getOomKillDisable() { + return oomKillDisable; + } + + /** + * @see #oomKillDisable + */ + public Info withOomKillDisable(Boolean oomKillDisable) { + this.oomKillDisable = oomKillDisable; + return this; + } + + /** + * @see #oomScoreAdj + */ + @CheckForNull + public Integer getOomScoreAdj() { + return oomScoreAdj; + } + + /** + * @see #oomScoreAdj + */ + public Info withOomScoreAdj(Integer oomScoreAdj) { + this.oomScoreAdj = oomScoreAdj; + return this; + } + + /** + * @see #operatingSystem + */ + @CheckForNull public String getOperatingSystem() { return operatingSystem; } + /** + * @see #operatingSystem + */ + public Info withOperatingSystem(String operatingSystem) { + this.operatingSystem = operatingSystem; + return this; + } + + /** + * @see #osType + */ + @CheckForNull + public String getOsType() { + return osType; + } + + /** + * @see #osType + */ + public Info withOsType(String osType) { + this.osType = osType; + return this; + } + + /** + * @see #plugins + */ + @CheckForNull + public Map> getPlugins() { + return plugins; + } + + /** + * @see #plugins + */ + public Info withPlugins(Map> plugins) { + this.plugins = plugins; + return this; + } + + /** + * @see #registryConfig + */ + @CheckForNull + public InfoRegistryConfig getRegistryConfig() { + return registryConfig; + } + + /** + * @see #registryConfig + */ + public Info withRegistryConfig(InfoRegistryConfig registryConfig) { + this.registryConfig = registryConfig; + return this; + } + + /** + * @see #serverVersion + */ + @CheckForNull + public String getServerVersion() { + return serverVersion; + } + + /** + * @see #serverVersion + */ + public Info withServerVersion(String serverVersion) { + this.serverVersion = serverVersion; + return this; + } + + /** + * @see #clusterStore + */ + @CheckForNull + public String getClusterStore() { + return clusterStore; + } + + /** + * @see #clusterStore + */ + public Info withClusterStore(String clusterStore) { + this.clusterStore = clusterStore; + return this; + } + + /** + * @see #clusterAdvertise + */ + @CheckForNull + public String getClusterAdvertise() { + return clusterAdvertise; + } + + /** + * @see #clusterAdvertise + */ + public Info withClusterAdvertise(String clusterAdvertise) { + this.clusterAdvertise = clusterAdvertise; + return this; + } + + /** + * @see #sockets + */ + @CheckForNull + public String[] getSockets() { + return sockets; + } + + /** + * @see #sockets + */ + public Info withSockets(String[] sockets) { + this.sockets = sockets; + return this; + } + + /** + * @see #swapLimit + */ + @CheckForNull public Boolean getSwapLimit() { return swapLimit; } - public String getExecutionDriver() { - return executionDriver; + /** + * @see #swapLimit + */ + public Info withSwapLimit(Boolean swapLimit) { + this.swapLimit = swapLimit; + return this; + } + + /** + * @see #systemStatus + */ + @CheckForNull + public List getSystemStatus() { + return systemStatus; + } + + /** + * @see #systemStatus + */ + public Info withSystemStatus(List systemStatus) { + this.systemStatus = systemStatus; + return this; + } + + /** + * @see #systemTime + */ + @CheckForNull + public String getSystemTime() { + return systemTime; + } + + /** + * @see #systemTime + */ + public Info withSystemTime(String systemTime) { + this.systemTime = systemTime; + 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/InfoRegistryConfig.java b/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java new file mode 100644 index 000000000..cc67994a5 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java @@ -0,0 +1,189 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +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 javax.annotation.CheckForNull; +import java.util.List; +import java.util.Map; + +/** + * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public final class InfoRegistryConfig { + @JsonProperty("IndexConfigs") + private Map indexConfigs; + + @JsonProperty("InsecureRegistryCIDRs") + private List insecureRegistryCIDRs; + + /** + * //FIXME unknown field + */ + @JsonProperty("Mirrors") + private Object mirrors; + + /** + * @see #indexConfigs + */ + @CheckForNull + public Map getIndexConfigs() { + return indexConfigs; + } + + /** + * @see #indexConfigs + */ + public InfoRegistryConfig withIndexConfigs(Map indexConfigs) { + this.indexConfigs = indexConfigs; + return this; + } + + /** + * @see #insecureRegistryCIDRs + */ + @CheckForNull + public List getInsecureRegistryCIDRs() { + return insecureRegistryCIDRs; + } + + /** + * @see #insecureRegistryCIDRs + */ + public InfoRegistryConfig withInsecureRegistryCIDRs(List insecureRegistryCIDRs) { + this.insecureRegistryCIDRs = insecureRegistryCIDRs; + return this; + } + + /** + * @see #mirrors + */ + @CheckForNull + public Object getMirrors() { + return mirrors; + } + + /** + * @see #mirrors + */ + public InfoRegistryConfig withMirrors(Object mirrors) { + this.mirrors = mirrors; + 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); + } + + /** + * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class IndexConfig { + @JsonProperty("Mirrors") + private String mirrors; + + @JsonProperty("Name") + private String name; + + @JsonProperty("Official") + private Boolean official; + + @JsonProperty("Secure") + private Boolean secure; + + /** + * @see #mirrors + */ + @CheckForNull + public String getMirrors() { + return mirrors; + } + + /** + * @see #mirrors + */ + public IndexConfig withMirrors(String mirrors) { + this.mirrors = mirrors; + return this; + } + + /** + * @see #name + */ + @CheckForNull + public String getName() { + return name; + } + + /** + * @see #name + */ + public IndexConfig withName(String name) { + this.name = name; + return this; + } + + /** + * @see #official + */ + @CheckForNull + public Boolean getOfficial() { + return official; + } + + /** + * @see #official + */ + public IndexConfig withOfficial(Boolean official) { + this.official = official; + return this; + } + + /** + * @see #secure + */ + @CheckForNull + public Boolean getSecure() { + return secure; + } + + /** + * @see #secure + */ + public IndexConfig withSecure(Boolean secure) { + this.secure = secure; + 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/NetworkSettings.java b/src/main/java/com/github/dockerjava/api/model/NetworkSettings.java index 64c954ec9..680048c18 100644 --- a/src/main/java/com/github/dockerjava/api/model/NetworkSettings.java +++ b/src/main/java/com/github/dockerjava/api/model/NetworkSettings.java @@ -11,6 +11,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.github.dockerjava.core.RemoteApiVersion; +import javax.annotation.CheckForNull; + /** * * @author Marcus Linke @@ -208,6 +210,15 @@ public String toString() { @JsonIgnoreProperties(ignoreUnknown = true) public static class Network { + @JsonProperty("IPAMConfig") + private String ipamConfig; + + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("NetworkID") + private String networkID; + @JsonProperty("EndpointID") private String endpointId; @@ -232,6 +243,11 @@ public static class Network { @JsonProperty("MacAddress") private String macAddress; + @CheckForNull + public String getNetworkID() { + return networkID; + } + public String getEndpointId() { return endpointId; } diff --git a/src/main/java/com/github/dockerjava/api/model/UpdateContainerResponse.java b/src/main/java/com/github/dockerjava/api/model/UpdateContainerResponse.java new file mode 100644 index 000000000..b1b1188d0 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/UpdateContainerResponse.java @@ -0,0 +1,28 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.core.RemoteApiVersion; + +import javax.annotation.CheckForNull; +import java.util.List; + +/** + * @author Kanstantsin Shautsou + * @see com.github.dockerjava.api.command.UpdateContainerCmd + * @see + * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/ + * @since {@link RemoteApiVersion#VERSION_1_22} + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class UpdateContainerResponse extends ResponseItem { + private static final long serialVersionUID = 1L; + + @JsonProperty("Warnings") + private List warnings; + + @CheckForNull + public List getWarnings() { + return warnings; + } +} diff --git a/src/main/java/com/github/dockerjava/api/model/Version.java b/src/main/java/com/github/dockerjava/api/model/Version.java index aca548987..004c85f22 100644 --- a/src/main/java/com/github/dockerjava/api/model/Version.java +++ b/src/main/java/com/github/dockerjava/api/model/Version.java @@ -1,14 +1,19 @@ package com.github.dockerjava.api.model; -import org.apache.commons.lang.builder.ToStringBuilder; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.github.dockerjava.api.command.VersionCmd; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import javax.annotation.CheckForNull; /** + * Used for `/version` * * @author Konstantin Pelykh (kpelykh@gmail.com) - * + * @see VersionCmd */ @JsonIgnoreProperties(ignoreUnknown = true) public class Version { @@ -34,6 +39,18 @@ public class Version { @JsonProperty("Version") private String version; + /** + * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("BuildTime") + private String buildTime; + + /** + * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonProperty("Experimental") + private Boolean experimental; + public String getVersion() { return version; } @@ -62,8 +79,34 @@ public String getApiVersion() { return apiVersion; } + /** + * @see #buildTime + */ + @CheckForNull + public String getBuildTime() { + return buildTime; + } + + /** + * @see #experimental + */ + @CheckForNull + public Boolean getExperimental() { + return experimental; + } + @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/core/DockerClientImpl.java b/src/main/java/com/github/dockerjava/core/DockerClientImpl.java index 59e18bc85..9d342e249 100644 --- a/src/main/java/com/github/dockerjava/core/DockerClientImpl.java +++ b/src/main/java/com/github/dockerjava/core/DockerClientImpl.java @@ -55,6 +55,7 @@ import com.github.dockerjava.api.command.TagImageCmd; import com.github.dockerjava.api.command.TopContainerCmd; import com.github.dockerjava.api.command.UnpauseContainerCmd; +import com.github.dockerjava.api.command.UpdateContainerCmd; import com.github.dockerjava.api.command.VersionCmd; import com.github.dockerjava.api.command.WaitContainerCmd; import com.github.dockerjava.api.model.AuthConfig; @@ -105,9 +106,12 @@ import com.github.dockerjava.core.command.TagImageCmdImpl; import com.github.dockerjava.core.command.TopContainerCmdImpl; import com.github.dockerjava.core.command.UnpauseContainerCmdImpl; +import com.github.dockerjava.core.command.UpdateContainerCmdImpl; import com.github.dockerjava.core.command.VersionCmdImpl; import com.github.dockerjava.core.command.WaitContainerCmdImpl; +import javax.annotation.Nonnull; + /** * @author Konstantin Pelykh (kpelykh@gmail.com) * @see "https://github.com/docker/docker/blob/master/api/client/commands.go" @@ -355,6 +359,11 @@ public KillContainerCmd killContainerCmd(String containerId) { return new KillContainerCmdImpl(getDockerCmdExecFactory().createKillContainerCmdExec(), containerId); } + @Override + public UpdateContainerCmd updateContainerCmd(@Nonnull String containerId) { + return new UpdateContainerCmdImpl(getDockerCmdExecFactory().createUpdateContainerCmdExec(), containerId); + } + @Override public RestartContainerCmd restartContainerCmd(String containerId) { return new RestartContainerCmdImpl(getDockerCmdExecFactory().createRestartContainerCmdExec(), containerId); diff --git a/src/main/java/com/github/dockerjava/core/RemoteApiVersion.java b/src/main/java/com/github/dockerjava/core/RemoteApiVersion.java index 1dd93f466..e15cccc88 100644 --- a/src/main/java/com/github/dockerjava/core/RemoteApiVersion.java +++ b/src/main/java/com/github/dockerjava/core/RemoteApiVersion.java @@ -12,7 +12,7 @@ /** * Bean to encapsulate the version of the Docker Remote (REST) * API - *

+ *

* Contains the minor and major version of the API as well as operations to compare API versions. * * @author Marcus Thiesen diff --git a/src/main/java/com/github/dockerjava/core/async/JsonStreamProcessor.java b/src/main/java/com/github/dockerjava/core/async/JsonStreamProcessor.java index 8d9a64303..9da43b62b 100644 --- a/src/main/java/com/github/dockerjava/core/async/JsonStreamProcessor.java +++ b/src/main/java/com/github/dockerjava/core/async/JsonStreamProcessor.java @@ -34,7 +34,7 @@ public JsonStreamProcessor(Class clazz) { public void processResponseStream(InputStream response, ResultCallback resultCallback) { resultCallback.onStart(response); - OBJECT_MAPPER.configure(com.fasterxml.jackson.core.JsonParser.Feature.AUTO_CLOSE_SOURCE, true); + OBJECT_MAPPER.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, true); try { JsonParser jp = JSON_FACTORY.createParser(response); 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 6b5cea08a..e03acbf7f 100644 --- a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java +++ b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java @@ -33,9 +33,8 @@ import com.github.dockerjava.api.model.VolumesFrom; /** - * * Creates a new container. - * + * `/containers/create` */ @JsonInclude(Include.NON_NULL) public class CreateContainerCmdImpl extends AbstrDockerCmd implements @@ -100,6 +99,12 @@ public class CreateContainerCmdImpl extends AbstrDockerCmd binds) { @Override public CreateContainerCmd withBlkioWeight(Integer blkioWeight) { checkNotNull(blkioWeight, "blkioWeight was not specified"); - hostConfig.setBlkioWeight(blkioWeight); + hostConfig.withBlkioWeight(blkioWeight); return this; } @Override public CreateContainerCmd withCapAdd(Capability... capAdd) { checkNotNull(capAdd, "capAdd was not specified"); - hostConfig.setCapAdd(capAdd); + hostConfig.withCapAdd(capAdd); return this; } @@ -456,7 +470,7 @@ public CreateContainerCmd withCapAdd(List capAdd) { @Override public CreateContainerCmd withCapDrop(Capability... capDrop) { checkNotNull(capDrop, "capDrop was not specified"); - hostConfig.setCapDrop(capDrop); + hostConfig.withCapDrop(capDrop); return this; } @@ -482,42 +496,42 @@ public CreateContainerCmd withCmd(List cmd) { @Override public CreateContainerCmd withContainerIDFile(String containerIDFile) { checkNotNull(containerIDFile, "no containerIDFile was specified"); - hostConfig.setContainerIDFile(containerIDFile); + hostConfig.withContainerIDFile(containerIDFile); return this; } @Override public CreateContainerCmd withCpuPeriod(Integer cpuPeriod) { checkNotNull(cpuPeriod, "cpuPeriod was not specified"); - hostConfig.setCpuPeriod(cpuPeriod); + hostConfig.withCpuPeriod(cpuPeriod); return this; } @Override public CreateContainerCmd withCpusetCpus(String cpusetCpus) { checkNotNull(cpusetCpus, "cpusetCpus was not specified"); - hostConfig.setCpusetCpus(cpusetCpus); + hostConfig.withCpusetCpus(cpusetCpus); return this; } @Override public CreateContainerCmd withCpusetMems(String cpusetMems) { checkNotNull(cpusetMems, "cpusetMems was not specified"); - hostConfig.setCpusetMems(cpusetMems); + hostConfig.withCpusetMems(cpusetMems); return this; } @Override public CreateContainerCmd withCpuShares(Integer cpuShares) { checkNotNull(cpuShares, "cpuShares was not specified"); - hostConfig.setCpuShares(cpuShares); + hostConfig.withCpuShares(cpuShares); return this; } @Override public CreateContainerCmd withDevices(Device... devices) { checkNotNull(devices, "devices was not specified"); - this.hostConfig.setDevices(devices); + this.hostConfig.withDevices(devices); return this; } @@ -530,7 +544,7 @@ public CreateContainerCmd withDevices(List devices) { @Override public CreateContainerCmd withDns(String... dns) { checkNotNull(dns, "dns was not specified"); - this.hostConfig.setDns(dns); + this.hostConfig.withDns(dns); return this; } @@ -543,7 +557,7 @@ public CreateContainerCmd withDns(List dns) { @Override public CreateContainerCmd withDnsSearch(String... dnsSearch) { checkNotNull(dnsSearch, "dnsSearch was not specified"); - this.hostConfig.setDnsSearch(dnsSearch); + this.hostConfig.withDnsSearch(dnsSearch); return this; } @@ -593,6 +607,13 @@ public CreateContainerCmd withExposedPorts(ExposedPort... exposedPorts) { return this; } + @Override + public CreateContainerCmd withStopSignal(String stopSignal) { + checkNotNull(stopSignal, "stopSignal wasn't specified."); + this.stopSignal = stopSignal; + return this; + } + @Override public CreateContainerCmd withExposedPorts(List exposedPorts) { checkNotNull(exposedPorts, "exposedPorts was not specified"); @@ -602,7 +623,7 @@ public CreateContainerCmd withExposedPorts(List exposedPorts) { @Override public CreateContainerCmd withExtraHosts(String... extraHosts) { checkNotNull(extraHosts, "extraHosts was not specified"); - this.hostConfig.setExtraHosts(extraHosts); + this.hostConfig.withExtraHosts(extraHosts); return this; } @@ -649,7 +670,7 @@ public CreateContainerCmd withLinks(List links) { @Override public CreateContainerCmd withLxcConf(LxcConf... lxcConf) { checkNotNull(lxcConf, "lxcConf was not specified"); - this.hostConfig.setLxcConf(lxcConf); + this.hostConfig.withLxcConf(lxcConf); return this; } @@ -662,7 +683,7 @@ public CreateContainerCmd withLxcConf(List lxcConf) { @Override public CreateContainerCmd withLogConfig(LogConfig logConfig) { checkNotNull(logConfig, "logConfig was not specified"); - this.hostConfig.setLogConfig(logConfig); + this.hostConfig.withLogConfig(logConfig); return this; } @@ -676,14 +697,14 @@ public CreateContainerCmd withMacAddress(String macAddress) { @Override public CreateContainerCmd withMemory(Long memory) { checkNotNull(memory, "memory was not specified"); - hostConfig.setMemory(memory); + hostConfig.withMemory(memory); return this; } @Override public CreateContainerCmd withMemorySwap(Long memorySwap) { checkNotNull(memorySwap, "memorySwap was not specified"); - hostConfig.setMemorySwap(memorySwap); + hostConfig.withMemorySwap(memorySwap); return this; } @@ -704,21 +725,21 @@ public CreateContainerCmd withNetworkDisabled(Boolean disableNetwork) { @Override public CreateContainerCmd withNetworkMode(String networkMode) { checkNotNull(networkMode, "networkMode was not specified"); - this.hostConfig.setNetworkMode(networkMode); + this.hostConfig.withNetworkMode(networkMode); return this; } @Override public CreateContainerCmd withOomKillDisable(Boolean oomKillDisable) { checkNotNull(oomKillDisable, "oomKillDisable was not specified"); - hostConfig.setOomKillDisable(oomKillDisable); + hostConfig.withOomKillDisable(oomKillDisable); return this; } @Override public CreateContainerCmd withPortBindings(PortBinding... portBindings) { checkNotNull(portBindings, "portBindings was not specified"); - this.hostConfig.setPortBindings(new Ports(portBindings)); + this.hostConfig.withPortBindings(new Ports(portBindings)); return this; } @@ -731,7 +752,7 @@ public CreateContainerCmd withPortBindings(List portBindings) { @Override public CreateContainerCmd withPortBindings(Ports portBindings) { checkNotNull(portBindings, "portBindings was not specified"); - this.hostConfig.setPortBindings(portBindings); + this.hostConfig.withPortBindings(portBindings); return this; } @@ -751,28 +772,28 @@ public CreateContainerCmd withPortSpecs(List portSpecs) { @Override public CreateContainerCmd withPrivileged(Boolean privileged) { checkNotNull(privileged, "no privileged was specified"); - this.hostConfig.setPrivileged(privileged); + this.hostConfig.withPrivileged(privileged); return this; } @Override public CreateContainerCmd withPublishAllPorts(Boolean publishAllPorts) { checkNotNull(publishAllPorts, "no publishAllPorts was specified"); - this.hostConfig.setPublishAllPorts(publishAllPorts); + this.hostConfig.withPublishAllPorts(publishAllPorts); return this; } @Override public CreateContainerCmd withReadonlyRootfs(Boolean readonlyRootfs) { checkNotNull(readonlyRootfs, "no readonlyRootfs was specified"); - hostConfig.setReadonlyRootfs(readonlyRootfs); + hostConfig.withReadonlyRootfs(readonlyRootfs); return this; } @Override public CreateContainerCmd withRestartPolicy(RestartPolicy restartPolicy) { checkNotNull(restartPolicy, "restartPolicy was not specified"); - this.hostConfig.setRestartPolicy(restartPolicy); + this.hostConfig.withRestartPolicy(restartPolicy); return this; } @@ -800,7 +821,7 @@ public CreateContainerCmd withTty(Boolean tty) { @Override public CreateContainerCmd withUlimits(Ulimit... ulimits) { checkNotNull(ulimits, "no ulimits was specified"); - hostConfig.setUlimits(ulimits); + hostConfig.withUlimits(ulimits); return this; } @@ -833,7 +854,7 @@ public CreateContainerCmd withVolumes(List volumes) { @Override public CreateContainerCmd withVolumesFrom(VolumesFrom... volumesFrom) { checkNotNull(volumesFrom, "volumesFrom was not specified"); - this.hostConfig.setVolumesFrom(volumesFrom); + this.hostConfig.withVolumesFrom(volumesFrom); return this; } @@ -853,7 +874,7 @@ public CreateContainerCmd withWorkingDir(String workingDir) { @Override public CreateContainerCmd withPidMode(String pidMode) { checkNotNull(pidMode, "pidMode was not specified"); - this.hostConfig.setPidMode(pidMode); + this.hostConfig.withPidMode(pidMode); return this; } diff --git a/src/main/java/com/github/dockerjava/core/command/FrameReader.java b/src/main/java/com/github/dockerjava/core/command/FrameReader.java index 1e8ac0930..9c9c31e74 100644 --- a/src/main/java/com/github/dockerjava/core/command/FrameReader.java +++ b/src/main/java/com/github/dockerjava/core/command/FrameReader.java @@ -7,6 +7,8 @@ import com.github.dockerjava.api.model.Frame; import com.github.dockerjava.api.model.StreamType; +import javax.annotation.CheckForNull; + /** * Breaks the input into frame. Similar to how a buffered reader would readLies. *

@@ -42,14 +44,16 @@ private static StreamType streamType(byte streamType) { /** * @return A frame, or null if no more frames. */ + @CheckForNull public Frame readFrame() throws IOException { if (rawStreamDetected) { - int read = inputStream.read(rawBuffer); + if (read == -1) { + return null; + } return new Frame(StreamType.RAW, Arrays.copyOf(rawBuffer, read)); - } else { byte[] header = new byte[HEADER_SIZE]; diff --git a/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java b/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java new file mode 100644 index 000000000..ee95842b2 --- /dev/null +++ b/src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java @@ -0,0 +1,264 @@ +package com.github.dockerjava.core.command; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +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.UpdateContainerResponse; +import com.github.dockerjava.core.RemoteApiVersion; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +import javax.annotation.CheckForNull; + +/** + * @author Kanstantsin Shautsou + * @see + * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/ + * @since {@link RemoteApiVersion#VERSION_1_22} + */ +public class UpdateContainerCmdImpl extends AbstrDockerCmd + implements UpdateContainerCmd { + + @JsonIgnoreProperties + private String containerId; + + @JsonProperty("BlkioWeight") + private Integer blkioWeight; + + @JsonProperty("CpuShares") + private Integer cpuShares; + + @JsonProperty("CpuPeriod") + private Integer cpuPeriod; + + @JsonProperty("CpuQuota") + private Integer cpuQuota; + + @JsonProperty("CpusetCpus") + private String cpusetCpus; + + @JsonProperty("CpusetMems") + private String cpusetMems; + + @JsonProperty("Memory") + private Long memory; + + @JsonProperty("MemorySwap") + private Long memorySwap; + + @JsonProperty("MemoryReservation") + private Long memoryReservation; + + @JsonProperty("KernelMemory") + private Long kernelMemory; + + public UpdateContainerCmdImpl() { + super(null); + } + + public UpdateContainerCmdImpl(UpdateContainerCmd.Exec exec, String containerId) { + super(exec); + withContainerId(containerId); + } + + /** + * @see #blkioWeight + */ + @CheckForNull + public Integer getBlkioWeight() { + return blkioWeight; + } + + /** + * @see #blkioWeight + */ + public UpdateContainerCmd withBlkioWeight(Integer blkioWeight) { + this.blkioWeight = blkioWeight; + return this; + } + + /** + * @see #containerId + */ + @CheckForNull + public String getContainerId() { + return containerId; + } + + /** + * @see #containerId + */ + public UpdateContainerCmd withContainerId(String containerId) { + this.containerId = containerId; + return this; + } + + /** + * @see #cpuPeriod + */ + @CheckForNull + public Integer getCpuPeriod() { + return cpuPeriod; + } + + /** + * @see #cpuPeriod + */ + public UpdateContainerCmd withCpuPeriod(Integer cpuPeriod) { + this.cpuPeriod = cpuPeriod; + return this; + } + + /** + * @see #cpuQuota + */ + @CheckForNull + public Integer getCpuQuota() { + return cpuQuota; + } + + /** + * @see #cpuQuota + */ + public UpdateContainerCmd withCpuQuota(Integer cpuQuota) { + this.cpuQuota = cpuQuota; + return this; + } + + /** + * @see #cpusetCpus + */ + @CheckForNull + public String getCpusetCpus() { + return cpusetCpus; + } + + /** + * @see #cpusetCpus + */ + public UpdateContainerCmd withCpusetCpus(String cpusetCpus) { + this.cpusetCpus = cpusetCpus; + return this; + } + + /** + * @see #cpusetMems + */ + @CheckForNull + public String getCpusetMems() { + return cpusetMems; + } + + /** + * @see #cpusetMems + */ + public UpdateContainerCmd withCpusetMems(String cpusetMems) { + this.cpusetMems = cpusetMems; + return this; + } + + /** + * @see #cpuShares + */ + @CheckForNull + public Integer getCpuShares() { + return cpuShares; + } + + /** + * @see #cpuShares + */ + public UpdateContainerCmd withCpuShares(Integer cpuShares) { + this.cpuShares = cpuShares; + return this; + } + + /** + * @see #kernelMemory + */ + @CheckForNull + public Long getKernelMemory() { + return kernelMemory; + } + + /** + * @see #kernelMemory + */ + public UpdateContainerCmd withKernelMemory(Long kernelMemory) { + this.kernelMemory = kernelMemory; + return this; + } + + /** + * @see #memory + */ + @CheckForNull + public Long getMemory() { + return memory; + } + + /** + * @see #memory + */ + public UpdateContainerCmd withMemory(Long memory) { + this.memory = memory; + return this; + } + + /** + * @see #memoryReservation + */ + @CheckForNull + public Long getMemoryReservation() { + return memoryReservation; + } + + /** + * @see #memoryReservation + */ + public UpdateContainerCmd withMemoryReservation(Long memoryReservation) { + this.memoryReservation = memoryReservation; + return this; + } + + /** + * @see #memorySwap + */ + @CheckForNull + public Long getMemorySwap() { + return memorySwap; + } + + /** + * @see #memorySwap + */ + public UpdateContainerCmd withMemorySwap(Long memorySwap) { + this.memorySwap = memorySwap; + return this; + } + + /** + * @throws NotFoundException No such container + */ + @Override + public UpdateContainerResponse exec() throws NotFoundException { + return super.exec(); + } + + @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/jaxrs/DockerCmdExecFactoryImpl.java b/src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java index 2c5b2b077..4716877af 100644 --- a/src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java +++ b/src/main/java/com/github/dockerjava/jaxrs/DockerCmdExecFactoryImpl.java @@ -17,6 +17,7 @@ import javax.ws.rs.client.ClientResponseFilter; import javax.ws.rs.client.WebTarget; +import com.github.dockerjava.api.command.UpdateContainerCmd; import org.apache.http.config.RegistryBuilder; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.socket.PlainConnectionSocketFactory; @@ -410,6 +411,12 @@ public KillContainerCmd.Exec createKillContainerCmdExec() { return new KillContainerCmdExec(getBaseResource(), getDockerClientConfig()); } + + @Override + public UpdateContainerCmd.Exec createUpdateContainerCmdExec() { + return new UpdateContainerCmdExec(getBaseResource(), getDockerClientConfig()); + } + @Override public RestartContainerCmd.Exec createRestartContainerCmdExec() { return new RestartContainerCmdExec(getBaseResource(), getDockerClientConfig()); diff --git a/src/main/java/com/github/dockerjava/jaxrs/UpdateContainerCmdExec.java b/src/main/java/com/github/dockerjava/jaxrs/UpdateContainerCmdExec.java new file mode 100644 index 000000000..474d7338e --- /dev/null +++ b/src/main/java/com/github/dockerjava/jaxrs/UpdateContainerCmdExec.java @@ -0,0 +1,36 @@ +package com.github.dockerjava.jaxrs; + +import com.github.dockerjava.api.command.UpdateContainerCmd; +import com.github.dockerjava.api.model.UpdateContainerResponse; +import com.github.dockerjava.core.DockerClientConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import static javax.ws.rs.client.Entity.entity; + +/** + * Update container settings. + * + * @author Kanstantsin Shautsou + */ +public class UpdateContainerCmdExec extends AbstrSyncDockerCmdExec + implements UpdateContainerCmd.Exec { + private static final Logger LOGGER = LoggerFactory.getLogger(UpdateContainerCmdExec.class); + + public UpdateContainerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { + super(baseResource, dockerClientConfig); + } + + @Override + protected UpdateContainerResponse execute(UpdateContainerCmd command) { + WebTarget webResource = getBaseResource().path("/containers/{id}/update") + .resolveTemplate("id", command.getContainerId()); + + LOGGER.trace("POST: {}", webResource); + return webResource.request().accept(MediaType.APPLICATION_JSON) + .post(entity(command, MediaType.APPLICATION_JSON), UpdateContainerResponse.class); + } +} diff --git a/src/main/java/com/github/dockerjava/netty/DockerCmdExecFactoryImpl.java b/src/main/java/com/github/dockerjava/netty/DockerCmdExecFactoryImpl.java index c714f5cc6..3dae972fe 100644 --- a/src/main/java/com/github/dockerjava/netty/DockerCmdExecFactoryImpl.java +++ b/src/main/java/com/github/dockerjava/netty/DockerCmdExecFactoryImpl.java @@ -47,6 +47,7 @@ import com.github.dockerjava.api.command.TagImageCmd; import com.github.dockerjava.api.command.TopContainerCmd; import com.github.dockerjava.api.command.UnpauseContainerCmd; +import com.github.dockerjava.api.command.UpdateContainerCmd; import com.github.dockerjava.api.command.VersionCmd; import com.github.dockerjava.api.command.WaitContainerCmd; import com.github.dockerjava.core.DockerClientConfig; @@ -98,6 +99,7 @@ import com.github.dockerjava.netty.exec.TagImageCmdExec; import com.github.dockerjava.netty.exec.TopContainerCmdExec; import com.github.dockerjava.netty.exec.UnpauseContainerCmdExec; +import com.github.dockerjava.netty.exec.UpdateContainerCmdExec; import com.github.dockerjava.netty.exec.VersionCmdExec; import com.github.dockerjava.netty.exec.WaitContainerCmdExec; @@ -458,6 +460,11 @@ public KillContainerCmd.Exec createKillContainerCmdExec() { return new KillContainerCmdExec(getBaseResource(), getDockerClientConfig()); } + @Override + public UpdateContainerCmd.Exec createUpdateContainerCmdExec() { + return new UpdateContainerCmdExec(getBaseResource(), getDockerClientConfig()); + } + @Override public RestartContainerCmd.Exec createRestartContainerCmdExec() { return new RestartContainerCmdExec(getBaseResource(), getDockerClientConfig()); diff --git a/src/main/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExec.java b/src/main/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExec.java new file mode 100644 index 000000000..3c88dead8 --- /dev/null +++ b/src/main/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExec.java @@ -0,0 +1,34 @@ +package com.github.dockerjava.netty.exec; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.github.dockerjava.api.command.UpdateContainerCmd; +import com.github.dockerjava.api.model.UpdateContainerResponse; +import com.github.dockerjava.core.DockerClientConfig; +import com.github.dockerjava.netty.MediaType; +import com.github.dockerjava.netty.WebTarget; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * @author Kanstantsin Shautsou + */ +public class UpdateContainerCmdExec extends AbstrSyncDockerCmdExec + implements UpdateContainerCmd.Exec { + private static final Logger LOGGER = LoggerFactory.getLogger(UpdateContainerCmdExec.class); + + public UpdateContainerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) { + super(baseResource, dockerClientConfig); + } + + @Override + protected UpdateContainerResponse execute(UpdateContainerCmd command) { + WebTarget webResource = getBaseResource().path("/containers/{id}/update") + .resolveTemplate("id", command.getContainerId()); + + LOGGER.trace("POST: {}", webResource); + return webResource.request().accept(MediaType.APPLICATION_JSON) + .post(command, new TypeReference() { + }); + } +} diff --git a/src/test/java/com/github/dockerjava/api/command/InspectExecResponseTest.java b/src/test/java/com/github/dockerjava/api/command/InspectExecResponseTest.java new file mode 100644 index 000000000..cb9264d9f --- /dev/null +++ b/src/test/java/com/github/dockerjava/api/command/InspectExecResponseTest.java @@ -0,0 +1,56 @@ +package com.github.dockerjava.api.command; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.core.RemoteApiVersion; +import org.testng.annotations.Test; + +import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isEmptyString; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.core.IsNull.nullValue; + +/** + * @author Kanstantsin Shautsou + */ +public class InspectExecResponseTest { + + @Test + public void test_1_22_SerDer1() throws Exception { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().uncheckedSimpleType(InspectExecResponse.class); + + final InspectExecResponse execResponse = testRoundTrip(RemoteApiVersion.VERSION_1_22, + "/exec/ID/1.json", + type + ); + + assertThat(execResponse, notNullValue()); + + assertThat(execResponse.getId(), + is("1ca2ca598fab202f86dd9281196c405456069013958a475396b707e85c56473b")); + assertThat(execResponse.isRunning(), is(false)); + assertThat(execResponse.getExitCode(), is(nullValue())); + + final InspectExecResponse.ProcessConfig processConfig = execResponse.getProcessConfig(); + assertThat(processConfig, notNullValue()); + assertThat(processConfig.isTty(), is(false)); + assertThat(processConfig.getEntryPoint(), is("/bin/bash")); + assertThat(processConfig.getArguments(), hasSize(0)); + assertThat(processConfig.isPrivileged(), is(false)); + assertThat(processConfig.getUser(), isEmptyString()); + + + assertThat(execResponse.isOpenStdin(), is(false)); + assertThat(execResponse.isOpenStderr(), is(true)); + assertThat(execResponse.isOpenStdout(), is(true)); + assertThat(execResponse.getCanRemove(), is(false)); + assertThat(execResponse.getContainerID(), + is("ffa39805f089af3099e36452a985481f96170a9dff40be69d34d1722c7660d38")); + + assertThat(execResponse.getDetachKeys(), isEmptyString()); + } +} diff --git a/src/test/java/com/github/dockerjava/api/model/AuthConfigTest.java b/src/test/java/com/github/dockerjava/api/model/AuthConfigTest.java index 8f5bd64f3..db1553e33 100644 --- a/src/test/java/com/github/dockerjava/api/model/AuthConfigTest.java +++ b/src/test/java/com/github/dockerjava/api/model/AuthConfigTest.java @@ -1,25 +1,64 @@ package com.github.dockerjava.api.model; -import static org.testng.Assert.assertEquals; - -import org.testng.annotations.BeforeMethod; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.core.RemoteApiVersion; import org.testng.annotations.Test; -public class AuthConfigTest { +import java.io.IOException; - private AuthConfig authConfig; +import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; +import static org.testng.Assert.assertEquals; - @BeforeMethod - public void setUp() throws Exception { - authConfig = new AuthConfig() - .withEmail("foo") - .withPassword("bar") - .withRegistryAddress("baz") - .withUsername("qux"); - } +public class AuthConfigTest { @Test public void defaultServerAddress() throws Exception { assertEquals(new AuthConfig().getRegistryAddress(), "https://index.docker.io/v1/"); } + + @Test + public void serderDocs1() throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().uncheckedSimpleType(AuthConfig.class); + + final AuthConfig authConfig = testRoundTrip(RemoteApiVersion.VERSION_1_22, + "/other/AuthConfig/docs1.json", + type + ); + + assertThat(authConfig, notNullValue()); + assertThat(authConfig.getUsername(), is("jdoe")); + assertThat(authConfig.getPassword(), is("secret")); + assertThat(authConfig.getEmail(), is("jdoe@acme.com")); + + final AuthConfig authConfig1 = new AuthConfig().withUsername("jdoe") + .withPassword("secret") + .withEmail("jdoe@acme.com"); + + assertThat(authConfig1, equalTo(authConfig)); + } + + @Test + public void serderDocs2() throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().uncheckedSimpleType(AuthConfig.class); + + final AuthConfig authConfig = testRoundTrip(RemoteApiVersion.VERSION_1_22, + "/other/AuthConfig/docs2.json", + type + ); + + assertThat(authConfig, notNullValue()); + assertThat(authConfig.getRegistrytoken(), is("9cbaf023786cd7...")); + + + final AuthConfig authConfig1 = new AuthConfig().withRegistrytoken("9cbaf023786cd7..."); + + assertThat(authConfig1, equalTo(authConfig)); + } } diff --git a/src/test/java/com/github/dockerjava/api/model/ContainerTest.java b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java new file mode 100644 index 000000000..a143e6c57 --- /dev/null +++ b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java @@ -0,0 +1,44 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.CollectionType; +import com.github.dockerjava.core.RemoteApiVersion; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.List; + +import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.core.IsEqual.equalTo; + +/** + * @author Kanstantsin Shautsou + */ +public class ContainerTest { + + @Test + public void serderJson1() throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final CollectionType type = mapper.getTypeFactory().constructCollectionType(List.class, Container.class); + + final List containers = testRoundTrip(RemoteApiVersion.VERSION_1_22, + "containers/json/filter1.json", + type + ); + + assertThat(containers.size(), equalTo(1)); + + final Container container = containers.get(0); + + assertThat(container.getImageId(), + equalTo("sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efe7ec9")); + assertThat(container.getSizeRootFs(), equalTo(1113554L)); + + final ContainerHostConfig hostConfig = container.getHostConfig(); + assertThat(hostConfig, notNullValue()); + assertThat(hostConfig.getNetworkMode(), equalTo("default")); + } + +} diff --git a/src/test/java/com/github/dockerjava/api/model/IdentifierTest.java b/src/test/java/com/github/dockerjava/api/model/IdentifierTest.java index e8d4703db..eb458ab4c 100644 --- a/src/test/java/com/github/dockerjava/api/model/IdentifierTest.java +++ b/src/test/java/com/github/dockerjava/api/model/IdentifierTest.java @@ -1,9 +1,14 @@ package com.github.dockerjava.api.model; -import junit.framework.TestCase; -public class IdentifierTest extends TestCase { +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.AssertJUnit.assertTrue; + +public class IdentifierTest { + + @Test public void testFromCompoundString() throws Exception { Identifier i1 = Identifier.fromCompoundString("10.0.0.1/jim"); diff --git a/src/test/java/com/github/dockerjava/api/model/InfoTest.java b/src/test/java/com/github/dockerjava/api/model/InfoTest.java new file mode 100644 index 000000000..6d4c76471 --- /dev/null +++ b/src/test/java/com/github/dockerjava/api/model/InfoTest.java @@ -0,0 +1,172 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.api.model.InfoRegistryConfig.IndexConfig; +import org.hamcrest.CoreMatchers; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22; +import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.isEmptyString; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +/** + * @author Kanstantsin Shautsou + */ +public class InfoTest { + + @Test + public void serder1Json() throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().constructType(Info.class); + + final Info info = testRoundTrip(VERSION_1_22, + "info/1.json", + type + ); + + final List> driverStatus = asList( + asList("Root Dir", "/mnt/sda1/var/lib/docker/aufs"), + asList("Backing Filesystem", "extfs"), + asList("Dirs", "31"), + asList("Dirperm1 Supported", "true") + ); + + final Map> plugins = new LinkedHashMap<>(); + plugins.put("Volume", singletonList("local")); + plugins.put("Network", asList("bridge", "null", "host")); + plugins.put("Authorization", null); + + assertThat(info, notNullValue()); + assertThat(info.getArchitecture(), equalTo("x86_64")); + assertThat(info.getContainersStopped(), is(3)); + assertThat(info.getContainersPaused(), is(10)); + assertThat(info.getContainersRunning(), is(2)); + assertThat(info.getCpuCfsPeriod(), is(true)); + + // not available in this dump + assertThat(info.getCpuCfsQuota(), is(true)); + assertThat(info.getDiscoveryBackend(), nullValue()); + assertThat(info.getOomScoreAdj(), nullValue()); + + assertThat(info.getDriverStatuses(), notNullValue()); + assertThat(info.getDriverStatuses(), hasSize(4)); + assertThat(info.getDriverStatuses(), equalTo(driverStatus)); + + assertThat(info.getNGoroutines(), is(40)); + + assertThat(info.getSystemStatus(), CoreMatchers.nullValue()); + + assertThat(info.getPlugins(), equalTo(plugins)); + assertThat(info.getPlugins(), hasEntry("Volume", singletonList("local"))); + assertThat(info.getPlugins(), hasEntry("Authorization", null)); + + assertThat(info.getExperimentalBuild(), is(false)); + + assertThat(info.getHttpProxy(), isEmptyString()); + assertThat(info.getHttpsProxy(), isEmptyString()); + assertThat(info.getNoProxy(), isEmptyString()); + assertThat(info.getOomKillDisable(), is(true)); + assertThat(info.getOsType(), equalTo("linux")); + + final InfoRegistryConfig registryConfig = info.getRegistryConfig(); + assertThat(registryConfig, notNullValue()); + final List cidRs = registryConfig.getInsecureRegistryCIDRs(); + assertThat(cidRs, notNullValue()); + assertThat(cidRs, contains("127.0.0.0/8")); + + final Map indexConfigs = registryConfig.getIndexConfigs(); + assertThat(indexConfigs, notNullValue()); + final IndexConfig indexConfig = new IndexConfig().withMirrors(null).withName("docker.io") + .withSecure(true).withOfficial(true); + assertThat(indexConfigs, hasEntry("docker.io", indexConfig)); + assertThat(registryConfig.getMirrors(), nullValue()); + + assertThat(info.getSystemTime(), is("2016-02-17T14:56:35.212841831Z")); + assertThat(info.getServerVersion(), is("1.10.1")); + + assertThat(info.getCpuSet(), is(true)); + assertThat(info.getCpuShares(), is(true)); + assertThat(info.getIPv4Forwarding(), is(true)); + assertThat(info.getBridgeNfIptables(), is(true)); + assertThat(info.getBridgeNfIp6tables(), is(true)); + assertThat(info.getDebug(), is(true)); + assertThat(info.getNFd(), is(24)); + assertThat(info.getOomKillDisable(), is(true)); + assertThat(info.getLoggingDriver(), is("json-file")); + assertThat(info.getOperatingSystem(), + is("Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016")); + assertThat(info.getClusterStore(), is("")); + + + final Info withInfo = new Info().withArchitecture("x86_64") + .withContainers(2) + .withContainersRunning(2) + .withContainersPaused(10) + .withContainersStopped(3) + .withImages(13) + .withId("HLN2:5SBU:SRQR:CQI6:AB52:LZZ2:DED5:REDM:BU73:JFHE:R37A:5HMX") + .withDriver("aufs") + .withDriverStatuses(driverStatus) + .withSystemStatus(null) + .withPlugins(plugins) + .withMemoryLimit(true) + .withSwapLimit(true) + .withCpuCfsPeriod(true) + .withCpuCfsQuota(true) + .withCpuShares(true) + .withCpuSet(true) + .withIPv4Forwarding(true) + .withBridgeNfIptables(true) + .withBridgeNfIp6tables(true) + .withDebug(true) + .withNFd(24) + .withOomKillDisable(true) + .withNGoroutines(40) + .withSystemTime("2016-02-17T14:56:35.212841831Z") + .withExecutionDriver("native-0.2") + .withLoggingDriver("json-file") + .withNEventsListener(0) + .withKernelVersion("4.1.17-boot2docker") + .withOperatingSystem("Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016") + .withOsType("linux") + .withIndexServerAddress("https://index.docker.io/v1/") + .withRegistryConfig(registryConfig) + .withInitSha1("") + .withInitPath("/usr/local/bin/docker") + .withNCPU(1) + .withMemTotal(1044574208L) + .withDockerRootDir("/mnt/sda1/var/lib/docker") + .withHttpProxy("") + .withHttpsProxy("") + .withNoProxy("") + .withName("docker-java") + .withLabels(new String[]{"provider=virtualbox"}) + .withExperimentalBuild(false) + .withServerVersion("1.10.1") + .withClusterStore("") + .withClusterAdvertise("") + //shredinger-fields + .withDiscoveryBackend(null) + .withOomScoreAdj(null) + .withSockets(null) + ; + + assertThat(info, is(withInfo)); + } +} diff --git a/src/test/java/com/github/dockerjava/api/model/VersionTest.java b/src/test/java/com/github/dockerjava/api/model/VersionTest.java new file mode 100644 index 000000000..c32d93069 --- /dev/null +++ b/src/test/java/com/github/dockerjava/api/model/VersionTest.java @@ -0,0 +1,40 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.core.RemoteApiVersion; +import org.testng.annotations.Test; + +import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.notNullValue; + +/** + * @author Kanstantsin Shautsou + */ +public class VersionTest { + + @Test + public void testSerDer1() throws Exception { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().uncheckedSimpleType(Version.class); + + final Version version = testRoundTrip(RemoteApiVersion.VERSION_1_22, + "/version/1.json", + type + ); + + assertThat(version, notNullValue()); + + assertThat(version.getVersion(), is("1.10.1")); + assertThat(version.getApiVersion(), is("1.22")); + assertThat(version.getGitCommit(), is("9e83765")); + assertThat(version.getGoVersion(), is("go1.5.3")); + assertThat(version.getOperatingSystem(), is("linux")); + assertThat(version.getArch(), is("amd64")); + assertThat(version.getKernelVersion(), is("4.1.17-boot2docker")); + assertThat(version.getBuildTime(), is("2016-02-11T20:39:58.688092588+00:00")); + } + +} diff --git a/src/test/java/com/github/dockerjava/client/AbstractDockerClientTest.java b/src/test/java/com/github/dockerjava/client/AbstractDockerClientTest.java index 8ddc481b3..1375cc9b6 100644 --- a/src/test/java/com/github/dockerjava/client/AbstractDockerClientTest.java +++ b/src/test/java/com/github/dockerjava/client/AbstractDockerClientTest.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.List; +import com.github.dockerjava.core.RemoteApiVersion; import org.apache.commons.io.IOUtils; import org.apache.commons.io.LineIterator; import org.apache.commons.lang.StringUtils; @@ -39,7 +40,7 @@ public abstract class AbstractDockerClientTest extends Assert { public static final Logger LOG = LoggerFactory.getLogger(AbstractDockerClientTest.class); - private String apiVersion = "1.21"; + private RemoteApiVersion apiVersion = RemoteApiVersion.VERSION_1_22; protected DockerClient dockerClient; @@ -54,7 +55,9 @@ public void beforeTest() throws Exception { LOG.info("======================= BEFORETEST ======================="); LOG.info("Connecting to Docker server"); - dockerClient = DockerClientBuilder.getInstance(config()).withDockerCmdExecFactory(dockerCmdExecFactory).build(); + dockerClient = DockerClientBuilder.getInstance(config()) + .withDockerCmdExecFactory(dockerCmdExecFactory) + .build(); try { dockerClient.inspectImageCmd("busybox").exec(); diff --git a/src/test/java/com/github/dockerjava/core/TestDockerCmdExecFactory.java b/src/test/java/com/github/dockerjava/core/TestDockerCmdExecFactory.java index cf49a669e..b2b86601c 100644 --- a/src/test/java/com/github/dockerjava/core/TestDockerCmdExecFactory.java +++ b/src/test/java/com/github/dockerjava/core/TestDockerCmdExecFactory.java @@ -235,6 +235,11 @@ public KillContainerCmd.Exec createKillContainerCmdExec() { return delegate.createKillContainerCmdExec(); } + @Override + public UpdateContainerCmd.Exec createUpdateContainerCmdExec() { + return delegate.createUpdateContainerCmdExec(); + } + @Override public RestartContainerCmd.Exec createRestartContainerCmdExec() { return delegate.createRestartContainerCmdExec(); diff --git a/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java index dba1a1a34..7800a8c12 100644 --- a/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java @@ -1,33 +1,5 @@ package com.github.dockerjava.core.command; -import static com.github.dockerjava.api.model.Capability.MKNOD; -import static com.github.dockerjava.api.model.Capability.NET_ADMIN; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItemInArray; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.isEmptyString; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.startsWith; - -import java.lang.reflect.Method; -import java.security.SecureRandom; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.testng.ITestResult; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - import com.github.dockerjava.api.command.CreateContainerResponse; import com.github.dockerjava.api.command.InspectContainerResponse; import com.github.dockerjava.api.exception.ConflictException; @@ -35,6 +7,7 @@ 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.Frame; import com.github.dockerjava.api.model.Link; import com.github.dockerjava.api.model.LogConfig; import com.github.dockerjava.api.model.Ports; @@ -43,9 +16,38 @@ import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.api.model.VolumesFrom; import com.github.dockerjava.client.AbstractDockerClientTest; +import org.testng.ITestResult; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.lang.reflect.Method; +import java.security.SecureRandom; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static com.github.dockerjava.api.model.Capability.MKNOD; +import static com.github.dockerjava.api.model.Capability.NET_ADMIN; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItemInArray; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isEmptyString; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.startsWith; @Test(groups = "integration") public class CreateContainerCmdImplTest extends AbstractDockerClientTest { + public static final String BUSYBOX_IMAGE = "busybox"; @BeforeTest public void beforeTest() throws Exception { @@ -72,7 +74,7 @@ public void createContainerWithExistingName() throws DockerException { String containerName = "generated_" + new SecureRandom().nextInt(); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("env") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("env") .withName(containerName).exec(); LOG.info("Created container {}", container.toString()); @@ -80,7 +82,7 @@ public void createContainerWithExistingName() throws DockerException { assertThat(container.getId(), not(isEmptyString())); try { - dockerClient.createContainerCmd("busybox").withCmd("env").withName(containerName).exec(); + dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("env").withName(containerName).exec(); fail("expected ConflictException"); } catch (ConflictException e) { } @@ -91,7 +93,7 @@ public void createContainerWithVolume() throws DockerException { Volume volume = new Volume("/var/log"); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withVolumes(volume) + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withVolumes(volume) .withCmd("true").exec(); LOG.info("Created container {}", container.toString()); @@ -114,7 +116,7 @@ public void createContainerWithReadOnlyVolume() throws DockerException { Volume volume = new Volume("/srv/test"); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withVolumes(volume) + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withVolumes(volume) .withCmd("true").exec(); LOG.info("Created container {}", container.toString()); @@ -144,7 +146,7 @@ public void createContainerWithVolumesFrom() throws DockerException { Bind bind2 = new Bind("/src/webapp2", volume2); // create a running container with bind mounts - CreateContainerResponse container1 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container1 = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withName(container1Name) .withBinds(bind1, bind2).exec(); LOG.info("Created container1 {}", container1.toString()); @@ -157,7 +159,7 @@ public void createContainerWithVolumesFrom() throws DockerException { assertThat(inspectContainerResponse1, mountedVolumes(containsInAnyOrder(volume1, volume2))); // create a second container with volumes from first container - CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container2 = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withVolumesFrom(new VolumesFrom(container1Name)).exec(); LOG.info("Created container2 {}", container2.toString()); @@ -187,7 +189,7 @@ public void createContainerWithVolumesFrom() throws DockerException { @Test public void createContainerWithEnv() throws Exception { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withEnv("VARIABLE=success") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withEnv("VARIABLE=success") .withCmd("env").exec(); LOG.info("Created container {}", container.toString()); @@ -206,7 +208,7 @@ public void createContainerWithEnv() throws Exception { @Test public void createContainerWithHostname() throws Exception { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withHostName("docker-java") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withHostName("docker-java") .withCmd("env").exec(); LOG.info("Created container {}", container.toString()); @@ -225,7 +227,7 @@ public void createContainerWithHostname() throws Exception { @Test public void createContainerWithName() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withName("container") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withName("container") .withCmd("env").exec(); LOG.info("Created container {}", container.toString()); @@ -237,7 +239,7 @@ public void createContainerWithName() throws DockerException { assertThat(inspectContainerResponse.getName(), equalTo("/container")); try { - dockerClient.createContainerCmd("busybox").withName("container").withCmd("env").exec(); + dockerClient.createContainerCmd(BUSYBOX_IMAGE).withName("container").withCmd("env").exec(); fail("Expected ConflictException"); } catch (ConflictException e) { } @@ -247,7 +249,7 @@ public void createContainerWithName() throws DockerException { @Test public void createContainerWithLink() throws DockerException { - CreateContainerResponse container1 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container1 = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withName("container1").exec(); LOG.info("Created container1 {}", container1.toString()); assertThat(container1.getId(), not(isEmptyString())); @@ -259,21 +261,21 @@ public void createContainerWithLink() throws DockerException { LOG.info("Container1 Inspect: {}", inspectContainerResponse1.toString()); assertThat(inspectContainerResponse1.getState().getRunning(), is(true)); - CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withName("container2") + CreateContainerResponse container2 = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withName("container2") .withCmd("env").withLinks(new Link("container1", "container1Link")).exec(); LOG.info("Created container {}", container2.toString()); assertThat(container2.getId(), not(isEmptyString())); InspectContainerResponse inspectContainerResponse2 = dockerClient.inspectContainerCmd(container2.getId()) .exec(); - assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[] {new Link("container1", + assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[]{new Link("container1", "container1Link")})); } @Test public void createContainerWithCapAddAndCapDrop() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCapAdd(NET_ADMIN) + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCapAdd(NET_ADMIN) .withCapDrop(MKNOD).exec(); LOG.info("Created container {}", container.toString()); @@ -293,7 +295,7 @@ public void createContainerWithDns() throws DockerException { String aDnsServer = "8.8.8.8"; String anotherDnsServer = "8.8.4.4"; - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("true") .withDns(aDnsServer, anotherDnsServer).exec(); LOG.info("Created container {}", container.toString()); @@ -309,7 +311,7 @@ public void createContainerWithDns() throws DockerException { @Test public void createContainerWithEntrypoint() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withName("container") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withName("container") .withEntrypoint("sleep", "9999").exec(); LOG.info("Created container {}", container.toString()); @@ -327,7 +329,7 @@ public void createContainerWithExtraHosts() throws DockerException { String[] extraHosts = {"dockerhost:127.0.0.1", "otherhost:10.0.0.1"}; - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withName("container") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withName("container") .withExtraHosts(extraHosts).exec(); LOG.info("Created container {}", container.toString()); @@ -343,7 +345,7 @@ public void createContainerWithExtraHosts() throws DockerException { @Test public void createContainerWithDevices() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withDevices(new Device("rwm", "/dev/nulo", "/dev/zero")).exec(); LOG.info("Created container {}", container.toString()); @@ -367,7 +369,7 @@ public void createContainerWithPortBindings() throws DockerException { portBindings.bind(tcp23, Ports.binding(11023)); portBindings.bind(tcp23, Ports.binding(11024)); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("true") .withExposedPorts(tcp22, tcp23).withPortBindings(portBindings).exec(); LOG.info("Created container {}", container.toString()); @@ -392,7 +394,7 @@ public void createContainerWithPortBindings() throws DockerException { @Test public void createContainerWithLinking() throws DockerException { - CreateContainerResponse container1 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container1 = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withName("container1").exec(); LOG.info("Created container1 {}", container1.toString()); @@ -416,7 +418,7 @@ public void createContainerWithLinking() throws DockerException { assertThat(inspectContainerResponse1.getState().getExitCode(), is(equalTo(0))); } - CreateContainerResponse container2 = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container2 = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withName("container2").withLinks(new Link("container1", "container1Link")).exec(); LOG.info("Created container2 {}", container2.toString()); @@ -430,7 +432,7 @@ public void createContainerWithLinking() throws DockerException { assertThat(inspectContainerResponse2.getId(), not(isEmptyString())); assertThat(inspectContainerResponse2.getHostConfig(), is(notNullValue())); assertThat(inspectContainerResponse2.getHostConfig().getLinks(), is(notNullValue())); - assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[] {new Link("container1", + assertThat(inspectContainerResponse2.getHostConfig().getLinks(), equalTo(new Link[]{new Link("container1", "container1Link")})); assertThat(inspectContainerResponse2.getId(), startsWith(container2.getId())); assertThat(inspectContainerResponse2.getName(), equalTo("/container2")); @@ -443,7 +445,7 @@ public void createContainerWithRestartPolicy() throws DockerException { RestartPolicy restartPolicy = RestartPolicy.onFailureRestart(5); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withRestartPolicy(restartPolicy).exec(); LOG.info("Created container {}", container.toString()); @@ -458,7 +460,7 @@ public void createContainerWithRestartPolicy() throws DockerException { @Test public void createContainerWithPidMode() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("true") .withPidMode("host").exec(); LOG.info("Created container {}", container.toString()); @@ -479,7 +481,7 @@ public void createContainerWithPidMode() throws DockerException { @Test public void createContainerWithNetworkMode() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("true") .withNetworkMode("host").exec(); LOG.info("Created container {}", container.toString()); @@ -494,7 +496,7 @@ public void createContainerWithNetworkMode() throws DockerException { @Test public void createContainerWithMacAddress() throws DockerException { - CreateContainerResponse container = dockerClient.createContainerCmd("busybox") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE) .withMacAddress("00:80:41:ae:fd:7e").withCmd("true").exec(); LOG.info("Created container {}", container.toString()); @@ -511,7 +513,7 @@ public void createContainerWithULimits() throws DockerException { Ulimit[] ulimits = {new Ulimit("nproc", 709, 1026), new Ulimit("nofile", 1024, 4096)}; - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withName("container") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withName("container") .withUlimits(ulimits).exec(); LOG.info("Created container {}", container.toString()); @@ -532,7 +534,7 @@ public void createContainerWithLabels() throws DockerException { labels.put("com.github.dockerjava.null", null); labels.put("com.github.dockerjava.Boolean", "true"); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withCmd("sleep", "9999") .withLabels(labels).exec(); LOG.info("Created container {}", container.toString()); @@ -550,7 +552,7 @@ public void createContainerWithLabels() throws DockerException { public void createContainerWithLogConfig() throws DockerException { LogConfig logConfig = new LogConfig(LogConfig.LoggingType.NONE, null); - CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withLogConfig(logConfig).exec(); + CreateContainerResponse container = dockerClient.createContainerCmd(BUSYBOX_IMAGE).withLogConfig(logConfig).exec(); LOG.info("Created container {}", container.toString()); @@ -561,4 +563,58 @@ public void createContainerWithLogConfig() throws DockerException { // null becomes empty string assertEquals(inspectContainerResponse.getHostConfig().getLogConfig().type, logConfig.type); } + + /** + * https://github.com/calavera/docker/blob/3781cde61ff10b1d9114ae5b4c5c1d1b2c20a1ee/integration-cli/docker_cli_run_unix_test.go#L319-L333 + */ + @Test + public void testWithStopSignal() throws Exception { + Integer signal = 10; // SIGUSR1 in busybox + + CreateContainerResponse resp = dockerClient.createContainerCmd(BUSYBOX_IMAGE) + .withCmd("/bin/sh", "-c", "trap 'echo \"exit trapped 10\"; exit 10' USR1; while true; do sleep 1; done") + .withAttachStdin(true) + .withTty(true) + .withStopSignal(signal.toString()) + .exec(); + final String containerId = resp.getId(); + assertThat(containerId, not(isEmptyString())); + dockerClient.startContainerCmd(containerId).exec(); + + InspectContainerResponse inspect = dockerClient.inspectContainerCmd(containerId).exec(); + assertThat(inspect.getState().getRunning(), is(true)); + + dockerClient.stopContainerCmd(containerId).exec(); + Thread.sleep(TimeUnit.SECONDS.toMillis(3)); + + inspect = dockerClient.inspectContainerCmd(containerId).exec(); + assertThat(inspect.getState().getRunning(), is(false)); + assertThat(inspect.getState().getExitCode(), is(signal)); + + StringBuilder stringBuilder = new StringBuilder(); + final StringBuilderLogReader callback = new StringBuilderLogReader(stringBuilder); + dockerClient.logContainerCmd(containerId) + .withStdErr(true) + .withStdOut(true) + .withTailAll() + .exec(callback) + .awaitCompletion(); + + String log = callback.builder.toString(); + assertThat(log, is("exit trapped 10")); + } + + private static class StringBuilderLogReader extends LogContainerResultCallback { + public StringBuilder builder; + + public StringBuilderLogReader(StringBuilder builder) { + this.builder = builder; + } + + @Override + public void onNext(Frame item) { + builder.append(new String(item.getPayload()).trim()); + super.onNext(item); + } + } } diff --git a/src/test/java/com/github/dockerjava/core/command/FrameReaderITest.java b/src/test/java/com/github/dockerjava/core/command/FrameReaderITest.java index df616ddba..06d07667c 100644 --- a/src/test/java/com/github/dockerjava/core/command/FrameReaderITest.java +++ b/src/test/java/com/github/dockerjava/core/command/FrameReaderITest.java @@ -1,10 +1,18 @@ package com.github.dockerjava.core.command; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import org.testng.annotations.AfterTest; @@ -39,18 +47,17 @@ public void deleteDockerContainerImage() throws Exception { @Test public void canCloseFrameReaderAndReadExpectedLines() throws Exception { - // wait for the container to be successfully executed int exitCode = dockerClient.waitContainerCmd(dockerfileFixture.getContainerId()) .exec(new WaitContainerResultCallback()).awaitStatusCode(); assertEquals(0, exitCode); - Iterator response = getLoggingFrames().iterator(); - - assertEquals(response.next(), new Frame(StreamType.STDOUT, "to stdout\n".getBytes())); - assertEquals(response.next(), new Frame(StreamType.STDERR, "to stderr\n".getBytes())); - assertFalse(response.hasNext()); - + final List loggingFrames = getLoggingFrames(); + final Frame outFrame = new Frame(StreamType.STDOUT, "to stdout\n".getBytes()); + final Frame errFrame = new Frame(StreamType.STDERR, "to stderr\n".getBytes()); + + assertThat(loggingFrames, containsInAnyOrder(outFrame, errFrame)); + assertThat(loggingFrames, hasSize(2)); } private List getLoggingFrames() throws Exception { diff --git a/src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java index f40ee7e69..a21a312aa 100644 --- a/src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java @@ -1,14 +1,19 @@ package com.github.dockerjava.core.command; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22; +import static com.github.dockerjava.utils.TestUtils.getVersion; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyString; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import java.io.IOException; import java.lang.reflect.Method; import java.security.SecureRandom; +import com.github.dockerjava.core.RemoteApiVersion; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; @@ -97,6 +102,8 @@ public void inspectExec() throws Exception { @Test(groups = "ignoreInCircleCi") public void inspectExecNetworkSettings() throws IOException { + final RemoteApiVersion apiVersion = getVersion(dockerClient); + String containerName = "generated_" + new SecureRandom().nextInt(); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") @@ -112,8 +119,19 @@ public void inspectExecNetworkSettings() throws IOException { assertThat(exec.getId(), not(isEmptyString())); InspectExecResponse inspectExecResponse = dockerClient.inspectExecCmd(exec.getId()).exec(); - assertThat(inspectExecResponse.getExitCode(), is(0)); - - assertNotNull(inspectExecResponse.getContainer().getNetworkSettings().getNetworks().get("bridge")); + assertThat(inspectExecResponse.getExitCode(), is(nullValue())); + assertThat(inspectExecResponse.isOpenStdin(), is(false)); + assertThat(inspectExecResponse.isOpenStdout(), is(true)); + assertThat(inspectExecResponse.isRunning(), is(false)); + assertThat(inspectExecResponse.getCanRemove(), is(false)); + assertThat(inspectExecResponse.getContainerID(), is(container.getId())); + + final InspectExecResponse.Container inspectContainer = inspectExecResponse.getContainer(); + if (apiVersion.isGreaterOrEqual(VERSION_1_22)) { + assertThat(inspectContainer, nullValue()); + } else { + assertThat(inspectContainer, notNullValue()); + assertNotNull(inspectContainer.getNetworkSettings().getNetworks().get("bridge")); + } } } diff --git a/src/test/java/com/github/dockerjava/core/command/StopContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/StopContainerCmdImplTest.java index 0718c7700..913ed9474 100644 --- a/src/test/java/com/github/dockerjava/core/command/StopContainerCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/StopContainerCmdImplTest.java @@ -1,5 +1,7 @@ package com.github.dockerjava.core.command; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22; +import static com.github.dockerjava.utils.TestUtils.getVersion; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -8,6 +10,7 @@ import java.lang.reflect.Method; +import com.github.dockerjava.core.RemoteApiVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.ITestResult; @@ -50,6 +53,7 @@ public void afterMethod(ITestResult result) { @Test(groups = "ignoreInCircleCi") public void testStopContainer() throws DockerException { + final RemoteApiVersion apiVersion = getVersion(dockerClient); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); LOG.info("Created container: {}", container.toString()); @@ -63,7 +67,13 @@ public void testStopContainer() throws DockerException { LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false))); - assertThat(inspectContainerResponse.getState().getExitCode(), not(equalTo(0))); + + final Integer exitCode = inspectContainerResponse.getState().getExitCode(); + if (apiVersion.equals(VERSION_1_22)) { + assertThat(exitCode, is(0)); + } else { + assertThat(exitCode, not(0)); + } } @Test diff --git a/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java new file mode 100644 index 000000000..76708f889 --- /dev/null +++ b/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java @@ -0,0 +1,114 @@ +package com.github.dockerjava.core.command; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.api.command.CreateContainerResponse; +import com.github.dockerjava.api.command.InspectContainerResponse; +import com.github.dockerjava.api.exception.DockerException; +import com.github.dockerjava.api.model.HostConfig; +import com.github.dockerjava.api.model.UpdateContainerResponse; +import com.github.dockerjava.client.AbstractDockerClientTest; +import com.github.dockerjava.core.RemoteApiVersion; +import org.testng.ITestResult; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.lang.reflect.Method; + +import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.hamcrest.core.IsNull.notNullValue; + +/** + * @author Kanstantsin Shautsou + */ +@Test(groups = "integration") +public class UpdateContainerCmdImplTest extends AbstractDockerClientTest { + + public static final String BUSYBOX_IMAGE = "busybox"; + + @BeforeTest + public void beforeTest() throws Exception { + super.beforeTest(); + } + + @AfterTest + public void afterTest() { + super.afterTest(); + } + + @BeforeMethod + public void beforeMethod(Method method) { + super.beforeMethod(method); + } + + @AfterMethod + public void afterMethod(ITestResult result) { + super.afterMethod(result); + } + + @Test(groups = "ignoreInCircleCi") + public void updateContainer() throws DockerException, IOException { + CreateContainerResponse response = dockerClient.createContainerCmd(BUSYBOX_IMAGE) + .withCmd("sleep", "9999") + .exec(); + String containerId = response.getId(); + dockerClient.startContainerCmd(containerId).exec(); + + InspectContainerResponse inspectBefore = dockerClient.inspectContainerCmd(containerId).exec(); + final HostConfig beforeHostConfig = inspectBefore.getHostConfig(); + + final UpdateContainerResponse updateResponse = dockerClient.updateContainerCmd(containerId) + .withBlkioWeight(300) + .withCpuShares(512) + .withCpuPeriod(100000) + .withCpuQuota(50000) +// .withCpusetCpus("0") // depends on env + .withCpusetMems("0") + .withMemory(314572800L) + .withMemorySwap(514288000L) + .withMemoryReservation(209715200L) +// .withKernelMemory(52428800) Can not update kernel memory to a running container, please stop it first. + .exec(); + + // docker toolbox 1.10.1 + assertThat(updateResponse.getWarnings(), hasSize(1)); + assertThat(updateResponse.getWarnings().get(0), + is("Your kernel does not support Block I/O weight. Weight discarded.")); + + InspectContainerResponse inspectAfter = dockerClient.inspectContainerCmd(containerId).exec(); + final HostConfig afterHostConfig = inspectAfter.getHostConfig(); + + assertThat(afterHostConfig.getMemory(), + is(314572800L)); + +// assertThat(afterHostConfig.getBlkioWeight(), is(300)); + assertThat(afterHostConfig.getCpuShares(), is(512)); + assertThat(afterHostConfig.getCpuPeriod(), is(100000)); + assertThat(afterHostConfig.getCpuQuota(), is(50000)); + assertThat(afterHostConfig.getCpusetMems(), is("0")); + + assertThat(afterHostConfig.getMemoryReservation(), is(209715200L)); + assertThat(afterHostConfig.getMemorySwap(), is(514288000L)); + + } + + @Test(enabled = false, description = "impossible to serder because model bundled in cmd") + public void serDerDocs1() throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().uncheckedSimpleType(UpdateContainerCmdImpl.class); + + final UpdateContainerCmdImpl upd = testRoundTrip(RemoteApiVersion.VERSION_1_22, + "/containers/container/update/docs.json", + type + ); + + assertThat(upd, notNullValue()); + } +} diff --git a/src/test/java/com/github/dockerjava/core/dockerfile/DockerfileStatementAddTest.java b/src/test/java/com/github/dockerjava/core/dockerfile/DockerfileStatementAddTest.java index 47d570d8c..102b113e3 100644 --- a/src/test/java/com/github/dockerjava/core/dockerfile/DockerfileStatementAddTest.java +++ b/src/test/java/com/github/dockerjava/core/dockerfile/DockerfileStatementAddTest.java @@ -2,7 +2,6 @@ import com.github.dockerjava.api.exception.DockerClientException; import com.google.common.base.Optional; -import junit.framework.TestCase; import org.hamcrest.Matcher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,9 +13,9 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; -public class DockerfileStatementAddTest extends TestCase { +public class DockerfileStatementAddTest { - private static final Logger log = LoggerFactory.getLogger(DockerfileStatementAddTest.class); + private static final Logger LOG = LoggerFactory.getLogger(DockerfileStatementAddTest.class); @DataProvider(name = "valid scenarios") public Object[][] validScenarios() { diff --git a/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java index ecf5ed568..3d2b55e24 100644 --- a/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java +++ b/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java @@ -1,14 +1,19 @@ package com.github.dockerjava.netty.exec; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22; +import static com.github.dockerjava.utils.TestUtils.getVersion; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyString; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import java.io.IOException; import java.lang.reflect.Method; import java.security.SecureRandom; +import com.github.dockerjava.core.RemoteApiVersion; import org.testng.ITestResult; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; @@ -99,6 +104,7 @@ public void inspectExec() throws Exception { @Test(groups = "ignoreInCircleCi") public void inspectExecNetworkSettings() throws IOException { + final RemoteApiVersion apiVersion = getVersion(dockerClient); String containerName = "generated_" + new SecureRandom().nextInt(); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999") @@ -114,8 +120,19 @@ public void inspectExecNetworkSettings() throws IOException { assertThat(exec.getId(), not(isEmptyString())); InspectExecResponse inspectExecResponse = dockerClient.inspectExecCmd(exec.getId()).exec(); - assertThat(inspectExecResponse.getExitCode(), is(0)); - - assertNotNull(inspectExecResponse.getContainer().getNetworkSettings().getNetworks().get("bridge")); + assertThat(inspectExecResponse.getExitCode(), is(nullValue())); + assertThat(inspectExecResponse.isOpenStdin(), is(false)); + assertThat(inspectExecResponse.isOpenStdout(), is(true)); + assertThat(inspectExecResponse.isRunning(), is(false)); + assertThat(inspectExecResponse.getCanRemove(), is(false)); + assertThat(inspectExecResponse.getContainerID(), is(container.getId())); + + final InspectExecResponse.Container inspectContainer = inspectExecResponse.getContainer(); + if (apiVersion.isGreaterOrEqual(VERSION_1_22)) { + assertThat(inspectContainer, nullValue()); + } else { + assertThat(inspectContainer, notNullValue()); + assertNotNull(inspectContainer.getNetworkSettings().getNetworks().get("bridge")); + } } } diff --git a/src/test/java/com/github/dockerjava/netty/exec/StopContainerCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/StopContainerCmdExecTest.java index 01bf74458..b3f545a42 100644 --- a/src/test/java/com/github/dockerjava/netty/exec/StopContainerCmdExecTest.java +++ b/src/test/java/com/github/dockerjava/netty/exec/StopContainerCmdExecTest.java @@ -1,5 +1,7 @@ package com.github.dockerjava.netty.exec; +import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22; +import static com.github.dockerjava.utils.TestUtils.getVersion; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -8,6 +10,7 @@ import java.lang.reflect.Method; +import com.github.dockerjava.core.RemoteApiVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.ITestResult; @@ -50,6 +53,7 @@ public void afterMethod(ITestResult result) { @Test(groups = "ignoreInCircleCi") public void testStopContainer() throws DockerException { + final RemoteApiVersion apiVersion = getVersion(dockerClient); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); LOG.info("Created container: {}", container.toString()); @@ -63,7 +67,13 @@ public void testStopContainer() throws DockerException { LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false))); - assertThat(inspectContainerResponse.getState().getExitCode(), not(equalTo(0))); + + final Integer exitCode = inspectContainerResponse.getState().getExitCode(); + if (apiVersion.equals(VERSION_1_22)) { + assertThat(exitCode, is(0)); + } else { + assertThat(exitCode, not(0)); + } } @Test diff --git a/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java new file mode 100644 index 000000000..94c8242e5 --- /dev/null +++ b/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java @@ -0,0 +1,98 @@ +package com.github.dockerjava.netty.exec; + +import com.github.dockerjava.api.command.CreateContainerResponse; +import com.github.dockerjava.api.command.InspectContainerResponse; +import com.github.dockerjava.api.exception.DockerException; +import com.github.dockerjava.api.model.HostConfig; +import com.github.dockerjava.api.model.UpdateContainerResponse; +import com.github.dockerjava.netty.AbstractNettyDockerClientTest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.ITestResult; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.lang.reflect.Method; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsCollectionWithSize.hasSize; + +/** + * @author Kanstantsin Shautsou + */ +@Test(groups = "integration") +public class UpdateContainerCmdExecTest extends AbstractNettyDockerClientTest { + public static final Logger LOG = LoggerFactory.getLogger(UpdateContainerCmdExecTest.class); + private static final String BUSYBOX_IMAGE = "busybox"; + + @BeforeTest + public void beforeTest() throws Exception { + super.beforeTest(); + } + + @AfterTest + public void afterTest() { + super.afterTest(); + } + + @BeforeMethod + public void beforeMethod(Method method) { + super.beforeMethod(method); + } + + @AfterMethod + public void afterMethod(ITestResult result) { + super.afterMethod(result); + } + + @Test + public void updateContainer() throws DockerException, IOException { + CreateContainerResponse response = dockerClient.createContainerCmd(BUSYBOX_IMAGE) + .withCmd("sleep", "9999") + .exec(); + String containerId = response.getId(); + dockerClient.startContainerCmd(containerId).exec(); + + InspectContainerResponse inspectBefore = dockerClient.inspectContainerCmd(containerId).exec(); + final HostConfig beforeHostConfig = inspectBefore.getHostConfig(); + + final UpdateContainerResponse updateResponse = dockerClient.updateContainerCmd(containerId) + .withBlkioWeight(300) + .withCpuShares(512) + .withCpuPeriod(100000) + .withCpuQuota(50000) +// .withCpusetCpus("0") // depends on env + .withCpusetMems("0") + .withMemory(314572800L) + .withMemorySwap(514288000L) + .withMemoryReservation(209715200L) +// .withKernelMemory(52428800) Can not update kernel memory to a running container, please stop it first. + .exec(); + + // docker toolbox 1.10.1 + assertThat(updateResponse.getWarnings(), hasSize(1)); + assertThat(updateResponse.getWarnings().get(0), + is("Your kernel does not support Block I/O weight. Weight discarded.")); + + InspectContainerResponse inspectAfter = dockerClient.inspectContainerCmd(containerId).exec(); + final HostConfig afterHostConfig = inspectAfter.getHostConfig(); + + assertThat(afterHostConfig.getMemory(), + is(314572800L)); + +// assertThat(afterHostConfig.getBlkioWeight(), is(300)); + assertThat(afterHostConfig.getCpuShares(), is(512)); + assertThat(afterHostConfig.getCpuPeriod(), is(100000)); + assertThat(afterHostConfig.getCpuQuota(), is(50000)); + assertThat(afterHostConfig.getCpusetMems(), is("0")); + + assertThat(afterHostConfig.getMemoryReservation(), is(209715200L)); + assertThat(afterHostConfig.getMemorySwap(), is(514288000L)); + } + +} diff --git a/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java b/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java new file mode 100644 index 000000000..1b5337aa6 --- /dev/null +++ b/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java @@ -0,0 +1,66 @@ +package com.github.dockerjava.test.serdes; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.core.RemoteApiVersion; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotSame; + +/** + * Samples helper + * + * @author Kanstantsin Shautsou + */ +public class JSONSamples { + + /** + * Access to samples storage. + * + * @param version docker version of json sample + * @param context path to file for interested dump + * @return Content of JSON sample + * @throws IOException + */ + public static String getSampleContent(RemoteApiVersion version, String context) throws IOException { + File resource = new File("src/test/resources/samples/" + version.getVersion() + "/" + context); + return FileUtils.readFileToString(resource, "UTF-8"); + } + + public static TClass testRoundTrip(RemoteApiVersion version, String context, + JavaType type) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + final TClass tObject = mapper.readValue(getSampleContent(version, context), type); + return testRoundTrip(tObject, type); + } + + /** + * Same as {@link JSONTestHelper#testRoundTrip(java.lang.Object, java.lang.Class)} + * but via {@link TypeReference} + */ + public static TClass testRoundTrip(TClass item, JavaType type) + throws IOException, AssertionError { + ObjectMapper mapper = new ObjectMapper(); + + String serialized1 = mapper.writeValueAsString(item); + JsonNode json1 = mapper.readTree(serialized1); + + TClass deserialized1 = mapper.readValue(serialized1, type); + String serialized2 = mapper.writeValueAsString(deserialized1); + + JsonNode json2 = mapper.readTree(serialized2); + TClass deserialized2 = mapper.readValue(serialized2, type); + + assertEquals(json2, json1, "JSONs must be equal after the second roundtrip"); + assertEquals(deserialized2, deserialized2, "Objects must be equal after the second roundtrip"); + assertNotSame(deserialized2, deserialized1, "Objects must be not the same"); + + return deserialized2; + } +} diff --git a/src/test/java/com/github/dockerjava/test/serdes/JSONTestHelper.java b/src/test/java/com/github/dockerjava/test/serdes/JSONTestHelper.java index 8cacb6c5e..99a90f0af 100644 --- a/src/test/java/com/github/dockerjava/test/serdes/JSONTestHelper.java +++ b/src/test/java/com/github/dockerjava/test/serdes/JSONTestHelper.java @@ -29,10 +29,6 @@ /** * Provides helper methods for serialization-deserialization tests. * - *

- * TODO: Create helper that loads json files from simple folder structure using a type, version number, and name. - *

- * * @author Oleg Nenashev */ public class JSONTestHelper { diff --git a/src/test/java/com/github/dockerjava/utils/TestUtils.java b/src/test/java/com/github/dockerjava/utils/TestUtils.java new file mode 100644 index 000000000..b40273ecb --- /dev/null +++ b/src/test/java/com/github/dockerjava/utils/TestUtils.java @@ -0,0 +1,17 @@ +package com.github.dockerjava.utils; + +import com.github.dockerjava.api.DockerClient; +import com.github.dockerjava.core.RemoteApiVersion; + +/** + * @author Kanstantsin Shautsou + */ +public class TestUtils { + private TestUtils() { + } + + public static RemoteApiVersion getVersion(DockerClient client) { + final String serverVersion = client.versionCmd().exec().getApiVersion(); + return RemoteApiVersion.parseConfig(serverVersion); + } +} diff --git a/src/test/resources/samples/1.22/containers/container/json/1.json b/src/test/resources/samples/1.22/containers/container/json/1.json new file mode 100644 index 000000000..6cb71cc82 --- /dev/null +++ b/src/test/resources/samples/1.22/containers/container/json/1.json @@ -0,0 +1,151 @@ +{ + "Id": "095351afe7b4995dfb3e965f9cfd3a07b1fe69198c50085a2cb7c2b5a5c9b62f", + "Created": "2016-02-16T22:40:51.465045919Z", + "Path": "echo", + "Args": [], + "State": { + "Status": "created", + "Running": false, + "Paused": false, + "Restarting": false, + "OOMKilled": false, + "Dead": false, + "Pid": 0, + "ExitCode": 0, + "Error": "", + "StartedAt": "0001-01-01T00:00:00Z", + "FinishedAt": "0001-01-01T00:00:00Z" + }, + "Image": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efe7ec9", + "ResolvConfPath": "", + "HostnamePath": "", + "HostsPath": "", + "LogPath": "", + "Name": "/drunk_golick", + "RestartCount": 0, + "Driver": "aufs", + "MountLabel": "", + "ProcessLabel": "", + "AppArmorProfile": "", + "ExecIDs": null, + "HostConfig": { + "Binds": null, + "ContainerIDFile": "", + "LogConfig": { + "Type": "json-file", + "Config": {} + }, + "NetworkMode": "default", + "PortBindings": null, + "RestartPolicy": { + "Name": "", + "MaximumRetryCount": 0 + }, + "VolumeDriver": "", + "VolumesFrom": null, + "CapAdd": null, + "CapDrop": null, + "Dns": null, + "DnsOptions": null, + "DnsSearch": null, + "ExtraHosts": null, + "GroupAdd": null, + "IpcMode": "", + "Links": null, + "OomScoreAdj": 0, + "PidMode": "", + "Privileged": false, + "PublishAllPorts": false, + "ReadonlyRootfs": false, + "SecurityOpt": null, + "UTSMode": "", + "ShmSize": 67108864, + "ConsoleSize": [ + 0, + 0 + ], + "Isolation": "", + "CpuShares": 0, + "CgroupParent": "", + "BlkioWeight": 0, + "BlkioWeightDevice": null, + "BlkioDeviceReadBps": null, + "BlkioDeviceWriteBps": null, + "BlkioDeviceReadIOps": null, + "BlkioDeviceWriteIOps": null, + "CpuPeriod": 0, + "CpuQuota": 0, + "CpusetCpus": "", + "CpusetMems": "", + "Devices": null, + "KernelMemory": 0, + "Memory": 0, + "MemoryReservation": 0, + "MemorySwap": 0, + "MemorySwappiness": -1, + "OomKillDisable": false, + "PidsLimit": 0, + "Ulimits": null + }, + "GraphDriver": { + "Name": "aufs", + "Data": null + }, + "Mounts": [], + "Config": { + "Hostname": "095351afe7b4", + "Domainname": "", + "User": "", + "AttachStdin": false, + "AttachStdout": false, + "AttachStderr": false, + "Tty": false, + "OpenStdin": false, + "StdinOnce": false, + "Env": null, + "Cmd": [ + "echo" + ], + "Image": "busybox", + "Volumes": null, + "WorkingDir": "", + "Entrypoint": null, + "OnBuild": null, + "Labels": {} + }, + "NetworkSettings": { + "Bridge": "", + "SandboxID": "", + "HairpinMode": false, + "LinkLocalIPv6Address": "", + "LinkLocalIPv6PrefixLen": 0, + "Ports": null, + "SandboxKey": "", + "SecondaryIPAddresses": null, + "SecondaryIPv6Addresses": null, + "EndpointID": "", + "Gateway": "", + "GlobalIPv6Address": "", + "GlobalIPv6PrefixLen": 0, + "IPAddress": "", + "IPPrefixLen": 0, + "IPv6Gateway": "", + "MacAddress": "", + "Networks": { + "bridge": { + "IPAMConfig": null, + "Links": null, + "Aliases": null, + "NetworkID": "", + "EndpointID": "", + "Gateway": "", + "IPAddress": "", + "IPPrefixLen": 0, + "IPv6Gateway": "", + "GlobalIPv6Address": "", + "GlobalIPv6PrefixLen": 0, + "MacAddress": "" + } + } + } +} diff --git a/src/test/resources/samples/1.22/containers/container/update/docs.json b/src/test/resources/samples/1.22/containers/container/update/docs.json new file mode 100644 index 000000000..9d26fcb2f --- /dev/null +++ b/src/test/resources/samples/1.22/containers/container/update/docs.json @@ -0,0 +1,12 @@ +{ + "BlkioWeight": 300, + "CpuShares": 512, + "CpuPeriod": 100000, + "CpuQuota": 50000, + "CpusetCpus": "0,1", + "CpusetMems": "0", + "Memory": 314572800, + "MemorySwap": 514288000, + "MemoryReservation": 209715200, + "KernelMemory": 52428800 +} diff --git a/src/test/resources/samples/1.22/containers/create/docs.json b/src/test/resources/samples/1.22/containers/create/docs.json new file mode 100644 index 000000000..4bafc3cb5 --- /dev/null +++ b/src/test/resources/samples/1.22/containers/create/docs.json @@ -0,0 +1,131 @@ +{ + "Hostname": "", + "Domainname": "", + "User": "", + "AttachStdin": false, + "AttachStdout": true, + "AttachStderr": true, + "Tty": false, + "OpenStdin": false, + "StdinOnce": false, + "Env": [ + "FOO=bar", + "BAZ=quux" + ], + "Cmd": [ + "date" + ], + "Entrypoint": "", + "Image": "ubuntu", + "Labels": { + "com.example.vendor": "Acme", + "com.example.license": "GPL", + "com.example.version": "1.0" + }, + "Mounts": [ + { + "Name": "fac362...80535", + "Source": "/data", + "Destination": "/data", + "Driver": "local", + "Mode": "ro,Z", + "RW": false, + "Propagation": "" + } + ], + "WorkingDir": "", + "NetworkDisabled": false, + "MacAddress": "12:34:56:78:9a:bc", + "ExposedPorts": { + "22/tcp": {} + }, + "StopSignal": "SIGTERM", + "HostConfig": { + "Binds": [ + "/tmp:/tmp" + ], + "Links": [ + "redis3:redis" + ], + "Memory": 0, + "MemorySwap": 0, + "MemoryReservation": 0, + "KernelMemory": 0, + "CpuShares": 512, + "CpuPeriod": 100000, + "CpuQuota": 50000, + "CpusetCpus": "0,1", + "CpusetMems": "0,1", + "BlkioWeight": 300, + "BlkioWeightDevice": [ + {} + ], + "BlkioDeviceReadBps": [ + {} + ], + "BlkioDeviceReadIOps": [ + {} + ], + "BlkioDeviceWriteBps": [ + {} + ], + "BlkioDeviceWriteIOps": [ + {} + ], + "MemorySwappiness": 60, + "OomKillDisable": false, + "OomScoreAdj": 500, + "PortBindings": { + "22/tcp": [ + { + "HostPort": "11022" + } + ] + }, + "PublishAllPorts": false, + "Privileged": false, + "ReadonlyRootfs": false, + "Dns": [ + "8.8.8.8" + ], + "DnsOptions": [ + "" + ], + "DnsSearch": [ + "" + ], + "ExtraHosts": null, + "VolumesFrom": [ + "parent", + "other:ro" + ], + "CapAdd": [ + "NET_ADMIN" + ], + "CapDrop": [ + "MKNOD" + ], + "GroupAdd": [ + "newgroup" + ], + "RestartPolicy": { + "Name": "", + "MaximumRetryCount": 0 + }, + "NetworkMode": "bridge", + "Devices": [], + "Ulimits": [ + {} + ], + "LogConfig": { + "Type": "json-file", + "Config": {} + }, + "SecurityOpt": [ + "" + ], + "CgroupParent": "", + "VolumeDriver": "", + "ShmSize": 67108864 + } +} diff --git a/src/test/resources/samples/1.22/containers/json/filter1.json b/src/test/resources/samples/1.22/containers/json/filter1.json new file mode 100644 index 000000000..159e62da6 --- /dev/null +++ b/src/test/resources/samples/1.22/containers/json/filter1.json @@ -0,0 +1,37 @@ +[ + { + "Id": "095351afe7b4995dfb3e965f9cfd3a07b1fe69198c50085a2cb7c2b5a5c9b62f", + "Names": [ + "/drunk_golick" + ], + "Image": "busybox", + "ImageID": "sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efe7ec9", + "Command": "echo", + "Created": 1455662451, + "Ports": [], + "SizeRootFs": 1113554, + "Labels": {}, + "Status": "Up Less than a second", + "HostConfig": { + "NetworkMode": "default" + }, + "NetworkSettings": { + "Networks": { + "bridge": { + "IPAMConfig": null, + "Links": null, + "Aliases": null, + "NetworkID": "", + "EndpointID": "f69f5cff77b527c829bc45d71ba8c5eabca005ef3a8da8c7ee88c13ffc1ab602", + "Gateway": "172.17.0.1", + "IPAddress": "172.17.0.2", + "IPPrefixLen": 16, + "IPv6Gateway": "", + "GlobalIPv6Address": "", + "GlobalIPv6PrefixLen": 0, + "MacAddress": "02:42:ac:11:00:02" + } + } + } + } +] diff --git a/src/test/resources/samples/1.22/exec/ID/1.json b/src/test/resources/samples/1.22/exec/ID/1.json new file mode 100644 index 000000000..f06c807af --- /dev/null +++ b/src/test/resources/samples/1.22/exec/ID/1.json @@ -0,0 +1,18 @@ +{ + "ID": "1ca2ca598fab202f86dd9281196c405456069013958a475396b707e85c56473b", + "Running": false, + "ExitCode": null, + "ProcessConfig": { + "tty": false, + "entrypoint": "/bin/bash", + "arguments": [], + "privileged": false, + "user": "" + }, + "OpenStdin": false, + "OpenStderr": true, + "OpenStdout": true, + "CanRemove": false, + "ContainerID": "ffa39805f089af3099e36452a985481f96170a9dff40be69d34d1722c7660d38", + "DetachKeys": "" +} diff --git a/src/test/resources/samples/1.22/info/1.json b/src/test/resources/samples/1.22/info/1.json new file mode 100644 index 000000000..42ceb1b6e --- /dev/null +++ b/src/test/resources/samples/1.22/info/1.json @@ -0,0 +1,91 @@ +{ + "ID": "HLN2:5SBU:SRQR:CQI6:AB52:LZZ2:DED5:REDM:BU73:JFHE:R37A:5HMX", + "Containers": 2, + "ContainersRunning": 2, + "ContainersPaused": 10, + "ContainersStopped": 3, + "Images": 13, + "Driver": "aufs", + "DriverStatus": [ + [ + "Root Dir", + "/mnt/sda1/var/lib/docker/aufs" + ], + [ + "Backing Filesystem", + "extfs" + ], + [ + "Dirs", + "31" + ], + [ + "Dirperm1 Supported", + "true" + ] + ], + "SystemStatus": null, + "Plugins": { + "Volume": [ + "local" + ], + "Network": [ + "bridge", + "null", + "host" + ], + "Authorization": null + }, + "MemoryLimit": true, + "SwapLimit": true, + "CpuCfsPeriod": true, + "CpuCfsQuota": true, + "CPUShares": true, + "CPUSet": true, + "IPv4Forwarding": true, + "BridgeNfIptables": true, + "BridgeNfIp6tables": true, + "Debug": true, + "NFd": 24, + "OomKillDisable": true, + "NGoroutines": 40, + "SystemTime": "2016-02-17T14:56:35.212841831Z", + "ExecutionDriver": "native-0.2", + "LoggingDriver": "json-file", + "NEventsListener": 0, + "KernelVersion": "4.1.17-boot2docker", + "OperatingSystem": "Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016", + "OSType": "linux", + "Architecture": "x86_64", + "IndexServerAddress": "https://index.docker.io/v1/", + "RegistryConfig": { + "InsecureRegistryCIDRs": [ + "127.0.0.0/8" + ], + "IndexConfigs": { + "docker.io": { + "Name": "docker.io", + "Mirrors": null, + "Secure": true, + "Official": true + } + }, + "Mirrors": null + }, + "InitSha1": "", + "InitPath": "/usr/local/bin/docker", + "NCPU": 1, + "MemTotal": 1044574208, + "DockerRootDir": "/mnt/sda1/var/lib/docker", + "HttpProxy": "", + "HttpsProxy": "", + "NoProxy": "", + "Name": "docker-java", + "Labels": [ + "provider=virtualbox" + ], + "ExperimentalBuild": false, + "ServerVersion": "1.10.1", + "ClusterStore": "", + "ClusterAdvertise": "" +} diff --git a/src/test/resources/samples/1.22/info/docs.json b/src/test/resources/samples/1.22/info/docs.json new file mode 100644 index 000000000..537a0a1d2 --- /dev/null +++ b/src/test/resources/samples/1.22/info/docs.json @@ -0,0 +1,76 @@ +{ + "Architecture": "x86_64", + "Containers": 11, + "ContainersRunning": 7, + "ContainersStopped": 3, + "ContainersPaused": 1, + "CpuCfsPeriod": true, + "CpuCfsQuota": true, + "Debug": false, + "DiscoveryBackend": "etcd://localhost:2379", + "DockerRootDir": "/var/lib/docker", + "Driver": "btrfs", + "DriverStatus": [ + [ + "" + ] + ], + "SystemStatus": [ + [ + "State", + "Healthy" + ] + ], + "Plugins": { + "Volume": [ + "local" + ], + "Network": [ + "null", + "host", + "bridge" + ] + }, + "ExecutionDriver": "native-0.1", + "ExperimentalBuild": false, + "HttpProxy": "http://test:test@localhost:8080", + "HttpsProxy": "https://test:test@localhost:8080", + "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", + "IPv4Forwarding": true, + "Images": 16, + "IndexServerAddress": "https://index.docker.io/v1/", + "InitPath": "/usr/bin/docker", + "InitSha1": "", + "KernelVersion": "3.12.0-1-amd64", + "Labels": [ + "storage=ssd" + ], + "MemTotal": 2099236864, + "MemoryLimit": true, + "NCPU": 1, + "NEventsListener": 0, + "NFd": 11, + "NGoroutines": 21, + "Name": "prod-server-42", + "NoProxy": "9.81.1.160", + "OomKillDisable": true, + "OSType": "linux", + "OomScoreAdj": 500, + "OperatingSystem": "Boot2Docker", + "RegistryConfig": { + "IndexConfigs": { + "docker.io": { + "Mirrors": null, + "Name": "docker.io", + "Official": true, + "Secure": true + } + }, + "InsecureRegistryCIDRs": [ + "127.0.0.0/8" + ] + }, + "SwapLimit": false, + "SystemTime": "2015-03-10T11:11:23.730591467-07:00", + "ServerVersion": "1.9.0" +} diff --git a/src/test/resources/samples/1.22/other/AuthConfig/docs1.json b/src/test/resources/samples/1.22/other/AuthConfig/docs1.json new file mode 100644 index 000000000..5f712fb62 --- /dev/null +++ b/src/test/resources/samples/1.22/other/AuthConfig/docs1.json @@ -0,0 +1,5 @@ +{ + "username": "jdoe", + "password": "secret", + "email": "jdoe@acme.com" +} diff --git a/src/test/resources/samples/1.22/other/AuthConfig/docs2.json b/src/test/resources/samples/1.22/other/AuthConfig/docs2.json new file mode 100644 index 000000000..8ac70c20a --- /dev/null +++ b/src/test/resources/samples/1.22/other/AuthConfig/docs2.json @@ -0,0 +1,3 @@ +{ + "registrytoken": "9cbaf023786cd7..." +} diff --git a/src/test/resources/samples/1.22/version/1.json b/src/test/resources/samples/1.22/version/1.json new file mode 100644 index 000000000..454c767ba --- /dev/null +++ b/src/test/resources/samples/1.22/version/1.json @@ -0,0 +1,10 @@ +{ + "Version": "1.10.1", + "ApiVersion": "1.22", + "GitCommit": "9e83765", + "GoVersion": "go1.5.3", + "Os": "linux", + "Arch": "amd64", + "KernelVersion": "4.1.17-boot2docker", + "BuildTime": "2016-02-11T20:39:58.688092588+00:00" +}