From b97fc4daaa57311173ac915b3d379201a44508bf Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Wed, 17 Feb 2016 04:58:37 +0300 Subject: [PATCH 01/34] [WIP] Syncing 1.22 --- pom.xml | 5 + .../dockerjava/api/model/Container.java | 328 +++++++++++++++++- .../dockerjava/api/model/NetworkSettings.java | 16 + .../github/dockerjava/api/model/Update.java | 203 +++++++++++ .../dockerjava/api/model/UpdateResponse.java | 29 ++ .../dockerjava/core/RemoteApiVersion.java | 2 +- .../client/AbstractDockerClientTest.java | 7 +- .../1.22/containers/container/json/1.json | 151 ++++++++ .../samples/1.22/containers/json/filter1.json | 37 ++ 9 files changed, 770 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/github/dockerjava/api/model/Update.java create mode 100644 src/main/java/com/github/dockerjava/api/model/UpdateResponse.java create mode 100644 src/test/resources/samples/1.22/containers/container/json/1.json create mode 100644 src/test/resources/samples/1.22/containers/json/filter1.json diff --git a/pom.xml b/pom.xml index d4a5b6947..14778ebde 100644 --- a/pom.xml +++ b/pom.xml @@ -124,6 +124,11 @@ commons-io ${commons-io.version} + + + + + org.slf4j slf4j-api 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..44f5e80cc 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,24 @@ 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.api.model.Network.Ipam; +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; +import java.util.Map; /** + * Used for Listing containers. * * @author Konstantin Pelykh (kpelykh@gmail.com) - * */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(Include.NON_NULL) @@ -30,6 +36,12 @@ 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; @@ -42,6 +54,32 @@ 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; + + @JsonProperty("HostConfig") + private HostConfig 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 NetworkSettings networkSettings; + public String getId() { return id; } @@ -54,6 +92,11 @@ public String getImage() { return image; } + @CheckForNull + public String getImageId() { + return imageId; + } + public Long getCreated() { return created; } @@ -74,11 +117,260 @@ public String[] getNames() { return names; } + /** + * @see #sizeRw + */ + @CheckForNull + public Long getSizeRw() { + return sizeRw; + } + + /** + * @see #sizeRootFs + */ + @CheckForNull + public Long getSizeRootFs() { + return sizeRootFs; + } + + /** + * @see #networkSettings + */ + @CheckForNull + public NetworkSettings getNetworkSettings() { + return networkSettings; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + Container container = (Container) o; + + return new EqualsBuilder() + .append(command, container.command) + .append(created, container.created) + .append(id, container.id) + .append(image, container.image) + .append(imageId, container.imageId) + .append(names, container.names) + .append(ports, container.ports) + .append(labels, container.labels) + .append(status, container.status) + .append(sizeRw, container.sizeRw) + .append(sizeRootFs, container.sizeRootFs) + .append(hostConfig, container.hostConfig) + .append(networkSettings, container.networkSettings) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(command) + .append(created) + .append(id) + .append(image) + .append(imageId) + .append(names) + .append(ports) + .append(labels) + .append(status) + .append(sizeRw) + .append(sizeRootFs) + .append(hostConfig) + .append(networkSettings) + .toHashCode(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class HostConfig { + @JsonProperty("NetworkMode") + private String networkMode; + + public String getNetworkMode() { + return networkMode; + } + } + + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class NetworkSettings { + @JsonProperty("Networks") + private Map networks; + + public Map getNetworks() { + return networks; + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Network { + /** + * FIXME verify + */ + @JsonProperty("IPAMConfig") + private 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` + */ + @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; + + @CheckForNull + public List getAliases() { + return aliases; + } + + public String getEndpointId() { + return endpointId; + } + + public String getGateway() { + return gateway; + } + + public String getGlobalIPv6Address() { + return globalIPv6Address; + } + + public Integer getGlobalIPv6PrefixLen() { + return globalIPv6PrefixLen; + } + + public String getIpAddress() { + return ipAddress; + } + + public Ipam.Config getIpamConfig() { + return ipamConfig; + } + + public Integer getIpPrefixLen() { + return ipPrefixLen; + } + + public String getIpV6Gateway() { + return ipV6Gateway; + } + + public List getLinks() { + return links; + } + + public String getMacAddress() { + return macAddress; + } + + public String getNetworkID() { + return networkID; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("aliases", aliases) + .append("ipamConfig", ipamConfig) + .append("links", links) + .append("networkID", networkID) + .append("endpointId", endpointId) + .append("gateway", gateway) + .append("ipAddress", ipAddress) + .append("ipPrefixLen", ipPrefixLen) + .append("ipV6Gateway", ipV6Gateway) + .append("globalIPv6Address", globalIPv6Address) + .append("globalIPv6PrefixLen", globalIPv6PrefixLen) + .append("macAddress", macAddress) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + Network network = (Network) o; + + return new EqualsBuilder() + .append(ipamConfig, network.ipamConfig) + .append(links, network.links) + .append(aliases, network.aliases) + .append(networkID, network.networkID) + .append(endpointId, network.endpointId) + .append(gateway, network.gateway) + .append(ipAddress, network.ipAddress) + .append(ipPrefixLen, network.ipPrefixLen) + .append(ipV6Gateway, network.ipV6Gateway) + .append(globalIPv6Address, network.globalIPv6Address) + .append(globalIPv6PrefixLen, network.globalIPv6PrefixLen) + .append(macAddress, network.macAddress) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(ipamConfig) + .append(links) + .append(aliases) + .append(networkID) + .append(endpointId) + .append(gateway) + .append(ipAddress) + .append(ipPrefixLen) + .append(ipV6Gateway) + .append(globalIPv6Address) + .append(globalIPv6PrefixLen) + .append(macAddress) + .toHashCode(); + } + } + } + @JsonIgnoreProperties(ignoreUnknown = true) public static class Port { @@ -114,5 +406,31 @@ public String getType() { public String toString() { return ToStringBuilder.reflectionToString(this); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + Port port = (Port) o; + + return new EqualsBuilder() + .append(ip, port.ip) + .append(privatePort, port.privatePort) + .append(publicPort, port.publicPort) + .append(type, port.type) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(ip) + .append(privatePort) + .append(publicPort) + .append(type) + .toHashCode(); + } } } 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/Update.java b/src/main/java/com/github/dockerjava/api/model/Update.java new file mode 100644 index 000000000..c1b5355c7 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/Update.java @@ -0,0 +1,203 @@ +package com.github.dockerjava.api.model; + +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; + +/** + * FIXME test case + * TODO add command + * @author Kanstantsin Shautsou + * @see + * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/ + * @since {@link RemoteApiVersion#VERSION_1_22} + */ +public class Update { + @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 Integer memory; + + @JsonProperty("MemorySwap") + private Integer memorySwap; + + @JsonProperty("MemoryReservation") + private Integer memoryReservation; + + @JsonProperty("KernelMemory") + private Integer kernelMemory; + + @CheckForNull + public Integer getBlkioWeight() { + return blkioWeight; + } + + public Update setBlkioWeight(Integer blkioWeight) { + this.blkioWeight = blkioWeight; + return this; + } + + @CheckForNull + public Integer getCpuPeriod() { + return cpuPeriod; + } + + public Update setCpuPeriod(Integer cpuPeriod) { + this.cpuPeriod = cpuPeriod; + return this; + } + + @CheckForNull + public Integer getCpuQuota() { + return cpuQuota; + } + + public Update setCpuQuota(Integer cpuQuota) { + this.cpuQuota = cpuQuota; + return this; + } + + @CheckForNull + public String getCpusetCpus() { + return cpusetCpus; + } + + public Update setCpusetCpus(String cpusetCpus) { + this.cpusetCpus = cpusetCpus; + return this; + } + + @CheckForNull + public String getCpusetMems() { + return cpusetMems; + } + + public Update setCpusetMems(String cpusetMems) { + this.cpusetMems = cpusetMems; + return this; + } + + @CheckForNull + public Integer getCpuShares() { + return cpuShares; + } + + public Update setCpuShares(Integer cpuShares) { + this.cpuShares = cpuShares; + return this; + } + + @CheckForNull + public Integer getKernelMemory() { + return kernelMemory; + } + + public Update setKernelMemory(Integer kernelMemory) { + this.kernelMemory = kernelMemory; + return this; + } + + @CheckForNull + public Integer getMemory() { + return memory; + } + + public Update setMemory(Integer memory) { + this.memory = memory; + return this; + } + + @CheckForNull + public Integer getMemoryReservation() { + return memoryReservation; + } + + public Update setMemoryReservation(Integer memoryReservation) { + this.memoryReservation = memoryReservation; + return this; + } + + @CheckForNull + public Integer getMemorySwap() { + return memorySwap; + } + + public Update setMemorySwap(Integer memorySwap) { + this.memorySwap = memorySwap; + return this; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("blkioWeight", blkioWeight) + .append("cpuShares", cpuShares) + .append("cpuPeriod", cpuPeriod) + .append("cpuQuota", cpuQuota) + .append("cpusetCpus", cpusetCpus) + .append("cpusetMems", cpusetMems) + .append("memory", memory) + .append("memorySwap", memorySwap) + .append("memoryReservation", memoryReservation) + .append("kernelMemory", kernelMemory) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + Update update = (Update) o; + + return new EqualsBuilder() + .append(blkioWeight, update.blkioWeight) + .append(cpuShares, update.cpuShares) + .append(cpuPeriod, update.cpuPeriod) + .append(cpuQuota, update.cpuQuota) + .append(cpusetCpus, update.cpusetCpus) + .append(cpusetMems, update.cpusetMems) + .append(memory, update.memory) + .append(memorySwap, update.memorySwap) + .append(memoryReservation, update.memoryReservation) + .append(kernelMemory, update.kernelMemory) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(blkioWeight) + .append(cpuShares) + .append(cpuPeriod) + .append(cpuQuota) + .append(cpusetCpus) + .append(cpusetMems) + .append(memory) + .append(memorySwap) + .append(memoryReservation) + .append(kernelMemory) + .toHashCode(); + } +} diff --git a/src/main/java/com/github/dockerjava/api/model/UpdateResponse.java b/src/main/java/com/github/dockerjava/api/model/UpdateResponse.java new file mode 100644 index 000000000..e6b1305eb --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/UpdateResponse.java @@ -0,0 +1,29 @@ +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; + +/** + * TODO update command + * + * @author Kanstantsin Shautsou + * @see + * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/ + * @since {@link RemoteApiVersion#VERSION_1_22} + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class UpdateResponse 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/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/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/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/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" + } + } + } + } +] From 8c93adf173419409da86f9063e7b289c994e8350 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Wed, 17 Feb 2016 18:09:04 +0300 Subject: [PATCH 02/34] Update Info --- .../com/github/dockerjava/api/model/Info.java | 490 +++++++++++++++++- src/test/resources/samples/1.22/info/1.json | 91 ++++ .../resources/samples/1.22/info/docs.json | 76 +++ 3 files changed, 650 insertions(+), 7 deletions(-) create mode 100644 src/test/resources/samples/1.22/info/1.json create mode 100644 src/test/resources/samples/1.22/info/docs.json 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..9f292e27d 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,74 @@ 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("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,11 +76,38 @@ 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; + /** + * @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; @@ -81,15 +153,50 @@ 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; + @JsonProperty("OperatingSystem") private String operatingSystem; + @JsonProperty("RegistryConfig") + private RegistryConfig registryConfig; + @JsonProperty("Sockets") private String[] sockets; @JsonProperty("SwapLimit") private Boolean swapLimit; + /** + * @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; + + /** + * @see #architecture + */ + @CheckForNull + public String getArchitecture() { + return architecture; + } + public Boolean isDebug() { return debug; } @@ -98,6 +205,22 @@ public Integer getContainers() { return containers; } + /** + * @see #cpuCfsPeriod + */ + @CheckForNull + public Boolean getCpuCfsPeriod() { + return cpuCfsPeriod; + } + + /** + * @see #cpuCfsQuota + */ + @CheckForNull + public Boolean getCpuCfsQuota() { + return cpuCfsQuota; + } + public String getDockerRootDir() { return dockerRootDir; } @@ -106,10 +229,26 @@ public String getDriver() { return driver; } - public List getDriverStatuses() { + public List> getDriverStatuses() { return driverStatuses; } + /** + * @see #systemStatus + */ + @CheckForNull + public List getSystemStatus() { + return systemStatus; + } + + /** + * @see #plugins + */ + @CheckForNull + public Map> getPlugins() { + return plugins; + } + public Integer getImages() { return images; } @@ -186,8 +325,345 @@ public String getExecutionDriver() { return executionDriver; } + /** + * @see #experimentalBuild + */ + @CheckForNull + public Boolean getExperimentalBuild() { + return experimentalBuild; + } + + /** + * @see #httpProxy + */ + @CheckForNull + public String getHttpProxy() { + return httpProxy; + } + + /** + * @see #httpsProxy + */ + @CheckForNull + public String getHttpsProxy() { + return httpsProxy; + } + + /** + * @see #systemTime + */ + @CheckForNull + public String getSystemTime() { + return systemTime; + } + + /** + * @see #serverVersion + */ + @CheckForNull + public String getServerVersion() { + return serverVersion; + } + + // autogenerated getters + // TODO remove `is*()` that doesn't match to primitives + @CheckForNull + public Integer getContainersPaused() { + return containersPaused; + } + + @CheckForNull + public Integer getContainersRunning() { + return containersRunning; + } + + @CheckForNull + public Integer getContainersStopped() { + return containersStopped; + } + + @CheckForNull + public Boolean getDebug() { + return debug; + } + + @CheckForNull + public String getDiscoveryBackend() { + return discoveryBackend; + } + + @CheckForNull + public String getId() { + return id; + } + + @CheckForNull + public Boolean getIpv4Forwarding() { + return ipv4Forwarding; + } + + @CheckForNull + public Boolean getMemoryLimit() { + return memoryLimit; + } + + @CheckForNull + public Integer getNcpu() { + return ncpu; + } + + @CheckForNull + public Integer getNfd() { + return nfd; + } + + @CheckForNull + public Integer getnGoroutines() { + return nGoroutines; + } + + @CheckForNull + public String getNoProxy() { + return noProxy; + } + + @CheckForNull + public Boolean getOomKillDisable() { + return oomKillDisable; + } + + @CheckForNull + public RegistryConfig getRegistryConfig() { + return registryConfig; + } + // end of autogeneration + @Override public String toString() { return ToStringBuilder.reflectionToString(this); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + Info info = (Info) o; + + return new EqualsBuilder() + .append(architecture, info.architecture) + .append(containers, info.containers) + .append(containersStopped, info.containersStopped) + .append(containersPaused, info.containersPaused) + .append(containersRunning, info.containersRunning) + .append(cpuCfsPeriod, info.cpuCfsPeriod) + .append(cpuCfsQuota, info.cpuCfsQuota) + .append(debug, info.debug) + .append(discoveryBackend, info.discoveryBackend) + .append(dockerRootDir, info.dockerRootDir) + .append(driver, info.driver) + .append(driverStatuses, info.driverStatuses) + .append(systemStatus, info.systemStatus) + .append(plugins, info.plugins) + .append(executionDriver, info.executionDriver) + .append(experimentalBuild, info.experimentalBuild) + .append(httpProxy, info.httpProxy) + .append(httpsProxy, info.httpsProxy) + .append(id, info.id) + .append(ipv4Forwarding, info.ipv4Forwarding) + .append(images, info.images) + .append(indexServerAddress, info.indexServerAddress) + .append(initPath, info.initPath) + .append(initSha1, info.initSha1) + .append(kernelVersion, info.kernelVersion) + .append(labels, info.labels) + .append(memoryLimit, info.memoryLimit) + .append(memTotal, info.memTotal) + .append(name, info.name) + .append(ncpu, info.ncpu) + .append(nEventListener, info.nEventListener) + .append(nfd, info.nfd) + .append(nGoroutines, info.nGoroutines) + .append(noProxy, info.noProxy) + .append(oomKillDisable, info.oomKillDisable) + .append(operatingSystem, info.operatingSystem) + .append(registryConfig, info.registryConfig) + .append(sockets, info.sockets) + .append(swapLimit, info.swapLimit) + .append(systemTime, info.systemTime) + .append(serverVersion, info.serverVersion) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(architecture) + .append(containers) + .append(containersStopped) + .append(containersPaused) + .append(containersRunning) + .append(cpuCfsPeriod) + .append(cpuCfsQuota) + .append(debug) + .append(discoveryBackend) + .append(dockerRootDir) + .append(driver) + .append(driverStatuses) + .append(systemStatus) + .append(plugins) + .append(executionDriver) + .append(experimentalBuild) + .append(httpProxy) + .append(httpsProxy) + .append(id) + .append(ipv4Forwarding) + .append(images) + .append(indexServerAddress) + .append(initPath) + .append(initSha1) + .append(kernelVersion) + .append(labels) + .append(memoryLimit) + .append(memTotal) + .append(name) + .append(ncpu) + .append(nEventListener) + .append(nfd) + .append(nGoroutines) + .append(noProxy) + .append(oomKillDisable) + .append(operatingSystem) + .append(registryConfig) + .append(sockets) + .append(swapLimit) + .append(systemTime) + .append(serverVersion) + .toHashCode(); + } + + /** + * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} + */ + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class RegistryConfig { + @JsonProperty("IndexConfigs") + private Map indexConfigs; + + @JsonProperty("InsecureRegistryCIDRs") + private List insecureRegistryCIDRs; + + public Map getIndexConfigs() { + return indexConfigs; + } + + public List getInsecureRegistryCIDRs() { + return insecureRegistryCIDRs; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("indexConfigs", indexConfigs) + .append("insecureRegistryCIDRs", insecureRegistryCIDRs) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + RegistryConfig that = (RegistryConfig) o; + + return new EqualsBuilder() + .append(indexConfigs, that.indexConfigs) + .append(insecureRegistryCIDRs, that.insecureRegistryCIDRs) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(indexConfigs) + .append(insecureRegistryCIDRs) + .toHashCode(); + } + + /** + * @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; + + @CheckForNull + public String getMirrors() { + return mirrors; + } + + @CheckForNull + public String getName() { + return name; + } + + @CheckForNull + public Boolean getOfficial() { + return official; + } + + @CheckForNull + public Boolean getSecure() { + return secure; + } + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("mirrors", mirrors) + .append("name", name) + .append("official", official) + .append("secure", secure) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + IndexConfig that = (IndexConfig) o; + + return new EqualsBuilder() + .append(mirrors, that.mirrors) + .append(name, that.name) + .append(official, that.official) + .append(secure, that.secure) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(mirrors) + .append(name) + .append(official) + .append(secure) + .toHashCode(); + } + } + } } 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..df9b3f4cb --- /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": 0, + "ContainersStopped": 0, + "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" +} From 93b9dc81f12027ea46baf436a1a07598b84882b3 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Wed, 17 Feb 2016 18:18:49 +0300 Subject: [PATCH 03/34] Update info --- .../com/github/dockerjava/api/model/Info.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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 9f292e27d..5233cc387 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -20,7 +20,7 @@ @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class Info { - + /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_22} */ @@ -165,6 +165,18 @@ public class Info { @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; @@ -438,6 +450,22 @@ public RegistryConfig getRegistryConfig() { } // end of autogeneration + /** + * @see #oomScoreAdj + */ + @CheckForNull + public Integer getOomScoreAdj() { + return oomScoreAdj; + } + + /** + * @see #osType + */ + @CheckForNull + public String getOsType() { + return osType; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); @@ -487,6 +515,8 @@ public boolean equals(Object o) { .append(nGoroutines, info.nGoroutines) .append(noProxy, info.noProxy) .append(oomKillDisable, info.oomKillDisable) + .append(osType, info.osType) + .append(oomScoreAdj, info.oomScoreAdj) .append(operatingSystem, info.operatingSystem) .append(registryConfig, info.registryConfig) .append(sockets, info.sockets) @@ -534,6 +564,8 @@ public int hashCode() { .append(nGoroutines) .append(noProxy) .append(oomKillDisable) + .append(osType) + .append(oomScoreAdj) .append(operatingSystem) .append(registryConfig) .append(sockets) From 2ad06b1056fb190cfaacaaf6f8872b9c18189588 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Wed, 17 Feb 2016 18:28:51 +0300 Subject: [PATCH 04/34] Update /version --- .../github/dockerjava/api/model/Version.java | 75 ++++++++++++++++++- 1 file changed, 72 insertions(+), 3 deletions(-) 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..c7cf6f68c 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,60 @@ 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) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + Version version1 = (Version) o; + + return new EqualsBuilder() + .append(apiVersion, version1.apiVersion) + .append(arch, version1.arch) + .append(gitCommit, version1.gitCommit) + .append(goVersion, version1.goVersion) + .append(kernelVersion, version1.kernelVersion) + .append(operatingSystem, version1.operatingSystem) + .append(version, version1.version) + .append(buildTime, version1.buildTime) + .append(experimental, version1.experimental) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(apiVersion) + .append(arch) + .append(gitCommit) + .append(goVersion) + .append(kernelVersion) + .append(operatingSystem) + .append(version) + .append(buildTime) + .append(experimental) + .toHashCode(); + } } From 074883aa29989fdd700219aa3d7565b3ce7e9e90 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Wed, 17 Feb 2016 21:26:38 +0300 Subject: [PATCH 05/34] Update create request --- .../api/command/CreateContainerCmd.java | 5 + .../dockerjava/api/model/AuthConfig.java | 24 ++ .../dockerjava/api/model/HostConfig.java | 287 +++++++++++++++++- .../core/command/CreateContainerCmdImpl.java | 25 +- .../samples/1.22/containers/create/docs.json | 131 ++++++++ 5 files changed, 466 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/samples/1.22/containers/create/docs.json 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/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/HostConfig.java b/src/main/java/com/github/dockerjava/api/model/HostConfig.java index edad5cfcb..b15cf8cd6 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,19 @@ 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.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 +24,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 +75,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 +114,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 +162,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,6 +303,126 @@ 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); @@ -329,6 +538,76 @@ public void setPidMode(String pidMode) { this.pidMode = pidMode; } + public HostConfig setBlkioDeviceReadBps(List blkioDeviceReadBps) { + this.blkioDeviceReadBps = blkioDeviceReadBps; + return this; + } + + public HostConfig setBlkioDeviceReadIOps(List blkioDeviceReadIOps) { + this.blkioDeviceReadIOps = blkioDeviceReadIOps; + return this; + } + + public HostConfig setBlkioDeviceWriteBps(List blkioDeviceWriteBps) { + this.blkioDeviceWriteBps = blkioDeviceWriteBps; + return this; + } + + public HostConfig setBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { + this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; + return this; + } + + public HostConfig setBlkioWeightDevice(List blkioWeightDevice) { + this.blkioWeightDevice = blkioWeightDevice; + return this; + } + + public HostConfig setCpuQuota(Integer cpuQuota) { + this.cpuQuota = cpuQuota; + return this; + } + + public HostConfig setKernelMemory(Long kernelMemory) { + this.kernelMemory = kernelMemory; + return this; + } + + public HostConfig setMemoryReservation(Long memoryReservation) { + this.memoryReservation = memoryReservation; + return this; + } + + public HostConfig setMemorySwappiness(Integer memorySwappiness) { + this.memorySwappiness = memorySwappiness; + return this; + } + + public HostConfig setOomScoreAdj(Boolean oomScoreAdj) { + this.oomScoreAdj = oomScoreAdj; + return this; + } + + public HostConfig setSecurityOpts(List securityOpts) { + this.securityOpts = securityOpts; + return this; + } + + public HostConfig setCgroupParent(String cgroupParent) { + this.cgroupParent = cgroupParent; + return this; + } + + public HostConfig setShmSize(String shmSize) { + this.shmSize = shmSize; + return this; + } + + public HostConfig setVolumeDriver(String volumeDriver) { + this.volumeDriver = volumeDriver; + return this; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); 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..841292b0e 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 exposedPorts) { checkNotNull(exposedPorts, "exposedPorts was not specified"); 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 + } +} From d25eda0d2a0c0b3cc97314f72270e82d484a0dfa Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Fri, 19 Feb 2016 22:38:13 +0300 Subject: [PATCH 06/34] InfoTest, ContainerTest, fix getter. --- .../dockerjava/api/model/Container.java | 65 +++++++++- .../com/github/dockerjava/api/model/Info.java | 118 ++++++++++++++---- .../dockerjava/api/model/ContainerTest.java | 46 +++++++ .../github/dockerjava/api/model/InfoTest.java | 88 +++++++++++++ .../dockerjava/test/serdes/JSONSamples.java | 64 ++++++++++ .../test/serdes/JSONTestHelper.java | 4 - src/test/resources/samples/1.22/info/1.json | 4 +- 7 files changed, 357 insertions(+), 32 deletions(-) create mode 100644 src/test/java/com/github/dockerjava/api/model/ContainerTest.java create mode 100644 src/test/java/com/github/dockerjava/api/model/InfoTest.java create mode 100644 src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java 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 44f5e80cc..5b3de804c 100644 --- a/src/main/java/com/github/dockerjava/api/model/Container.java +++ b/src/main/java/com/github/dockerjava/api/model/Container.java @@ -55,7 +55,7 @@ public class Container { private String status; /** - * @since > ~{@link RemoteApiVersion#VERSION_1_19} + * @since ~{@link RemoteApiVersion#VERSION_1_19} */ @JsonProperty("SizeRw") private Long sizeRw; @@ -63,11 +63,14 @@ public class Container { /** * Returns only when {@link ListContainersCmd#withShowSize(java.lang.Boolean)} set * - * @since > ~{@link RemoteApiVersion#VERSION_1_19} + * @since ~{@link RemoteApiVersion#VERSION_1_19} */ @JsonProperty("SizeRootFs") private Long sizeRootFs; + /** + * @since ~{@link RemoteApiVersion#VERSION_1_20} + */ @JsonProperty("HostConfig") private HostConfig hostConfig; @@ -75,7 +78,7 @@ public class Container { * Docker API docs says "list of networks", but json names `networkSettings`. * So, reusing existed NetworkSettings model object. * - * @since > ~{@link RemoteApiVersion#VERSION_1_22} + * @since ~{@link RemoteApiVersion#VERSION_1_22} */ @JsonProperty("NetworkSettings") private NetworkSettings networkSettings; @@ -141,6 +144,14 @@ public NetworkSettings getNetworkSettings() { return networkSettings; } + /** + * @see #hostConfig + */ + @CheckForNull + public HostConfig getHostConfig() { + return hostConfig; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); @@ -229,6 +240,7 @@ public static final class Network { /** * 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; @@ -260,51 +272,98 @@ public static final class Network { @JsonProperty("MacAddress") private String macAddress; + /** + * @see #aliases + */ @CheckForNull public List getAliases() { return aliases; } + /** + * @see #endpointId + */ + @CheckForNull public String getEndpointId() { return endpointId; } + /** + * @see #gateway + */ + @CheckForNull public String getGateway() { return gateway; } + /** + * @see #globalIPv6Address + */ + @CheckForNull public String getGlobalIPv6Address() { return globalIPv6Address; } + /** + * @see #globalIPv6PrefixLen + */ + @CheckForNull public Integer getGlobalIPv6PrefixLen() { return globalIPv6PrefixLen; } + /** + * @see #ipAddress + */ + @CheckForNull public String getIpAddress() { return ipAddress; } + /** + * @see #ipamConfig + */ + @CheckForNull public Ipam.Config getIpamConfig() { return ipamConfig; } + /** + * @see #ipPrefixLen + */ + @CheckForNull public Integer getIpPrefixLen() { return ipPrefixLen; } + /** + * @see #ipV6Gateway + */ + @CheckForNull public String getIpV6Gateway() { return ipV6Gateway; } + /** + * @see #links + */ + @CheckForNull public List getLinks() { return links; } + /** + * @see #macAddress + */ + @CheckForNull public String getMacAddress() { return macAddress; } + /** + * @see #networkID + */ + @CheckForNull public String getNetworkID() { return networkID; } 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 5233cc387..3c572fcad 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -265,14 +265,6 @@ public Integer getImages() { return images; } - public String getID() { - return id; - } - - public Boolean getIPv4Forwarding() { - return ipv4Forwarding; - } - public String getIndexServerAddress() { return indexServerAddress; } @@ -313,14 +305,6 @@ public String getName() { return name; } - public Integer getNCPU() { - return ncpu; - } - - public Integer getNFd() { - return nfd; - } - public Integer getNGoroutines() { return nGoroutines; } @@ -420,20 +404,15 @@ public Boolean getMemoryLimit() { } @CheckForNull - public Integer getNcpu() { + public Integer getNCPU() { return ncpu; } @CheckForNull - public Integer getNfd() { + public Integer getNFd() { return nfd; } - @CheckForNull - public Integer getnGoroutines() { - return nGoroutines; - } - @CheckForNull public String getNoProxy() { return noProxy; @@ -586,19 +565,66 @@ public static final class RegistryConfig { @JsonProperty("InsecureRegistryCIDRs") private List insecureRegistryCIDRs; + /** + * //FIXME unknown field + */ + @JsonProperty("Mirrors") + private Object mirrors; + + /** + * @see #indexConfigs + */ + @CheckForNull public Map getIndexConfigs() { return indexConfigs; } + /** + * @see #indexConfigs + */ + public RegistryConfig withIndexConfigs(Map indexConfigs) { + this.indexConfigs = indexConfigs; + return this; + } + + /** + * @see #insecureRegistryCIDRs + */ + @CheckForNull public List getInsecureRegistryCIDRs() { return insecureRegistryCIDRs; } + /** + * @see #insecureRegistryCIDRs + */ + public RegistryConfig withInsecureRegistryCIDRs(List insecureRegistryCIDRs) { + this.insecureRegistryCIDRs = insecureRegistryCIDRs; + return this; + } + + /** + * @see #mirrors + */ + @CheckForNull + public Object getMirrors() { + return mirrors; + } + + /** + * @see #mirrors + */ + public RegistryConfig withMirrors(Object mirrors) { + this.mirrors = mirrors; + return this; + } + @Override public String toString() { return new ToStringBuilder(this) .append("indexConfigs", indexConfigs) .append("insecureRegistryCIDRs", insecureRegistryCIDRs) + .append("mirrors", mirrors) .toString(); } @@ -613,6 +639,7 @@ public boolean equals(Object o) { return new EqualsBuilder() .append(indexConfigs, that.indexConfigs) .append(insecureRegistryCIDRs, that.insecureRegistryCIDRs) + .append(mirrors, that.mirrors) .isEquals(); } @@ -621,6 +648,7 @@ public int hashCode() { return new HashCodeBuilder(17, 37) .append(indexConfigs) .append(insecureRegistryCIDRs) + .append(mirrors) .toHashCode(); } @@ -641,26 +669,70 @@ public static final class IndexConfig { @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 new ToStringBuilder(this) 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..a45450b58 --- /dev/null +++ b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java @@ -0,0 +1,46 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.core.type.TypeReference; +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; +import static org.hamcrest.core.IsNot.not; + +/** + * @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 Container.HostConfig hostConfig = container.getHostConfig(); + assertThat(hostConfig, notNullValue()); + assertThat(hostConfig.getNetworkMode(), equalTo("default")); + } + +} 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..83d49a397 --- /dev/null +++ b/src/test/java/com/github/dockerjava/api/model/InfoTest.java @@ -0,0 +1,88 @@ +package com.github.dockerjava.api.model; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.dockerjava.api.model.Info.RegistryConfig; +import com.github.dockerjava.api.model.Info.RegistryConfig.IndexConfig; +import org.hamcrest.CoreMatchers; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.Collections; +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 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 + ); + + 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(), nullValue()); + assertThat(info.getDiscoveryBackend(), nullValue()); + assertThat(info.getOomScoreAdj(), nullValue()); + + assertThat(info.getDriverStatuses(), notNullValue()); + assertThat(info.getDriverStatuses(), hasSize(4)); + + assertThat(info.getNGoroutines(), is(40)); + + assertThat(info.getSystemStatus(), CoreMatchers.nullValue()); + + assertThat(info.getPlugins(), hasEntry("Volume", Collections.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 RegistryConfig 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(), equalTo("2016-02-17T14:56:35.212841831Z")); + assertThat(info.getServerVersion(), equalTo("1.10.1")); + } +} 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..99994eac8 --- /dev/null +++ b/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java @@ -0,0 +1,64 @@ +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; + +/** + * 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"); + + 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/resources/samples/1.22/info/1.json b/src/test/resources/samples/1.22/info/1.json index df9b3f4cb..42ceb1b6e 100644 --- a/src/test/resources/samples/1.22/info/1.json +++ b/src/test/resources/samples/1.22/info/1.json @@ -2,8 +2,8 @@ "ID": "HLN2:5SBU:SRQR:CQI6:AB52:LZZ2:DED5:REDM:BU73:JFHE:R37A:5HMX", "Containers": 2, "ContainersRunning": 2, - "ContainersPaused": 0, - "ContainersStopped": 0, + "ContainersPaused": 10, + "ContainersStopped": 3, "Images": 13, "Driver": "aufs", "DriverStatus": [ From dc5e6c63ec521036f6f9f7b687e48e2391851f9b Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Fri, 19 Feb 2016 22:50:37 +0300 Subject: [PATCH 07/34] Extract classes --- .../dockerjava/api/model/Container.java | 306 +---------------- .../api/model/ContainerHostConfig.java | 56 ++++ .../api/model/ContainerNetwork.java | 317 ++++++++++++++++++ .../api/model/ContainerNetworkSettings.java | 21 ++ .../dockerjava/api/model/ContainerPort.java | 124 +++++++ .../dockerjava/api/model/ContainerTest.java | 2 +- 6 files changed, 525 insertions(+), 301 deletions(-) create mode 100644 src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java create mode 100644 src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java create mode 100644 src/main/java/com/github/dockerjava/api/model/ContainerNetworkSettings.java create mode 100644 src/main/java/com/github/dockerjava/api/model/ContainerPort.java 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 5b3de804c..a92efd08c 100644 --- a/src/main/java/com/github/dockerjava/api/model/Container.java +++ b/src/main/java/com/github/dockerjava/api/model/Container.java @@ -5,14 +5,12 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.github.dockerjava.api.command.ListContainersCmd; -import com.github.dockerjava.api.model.Network.Ipam; 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; import java.util.Map; /** @@ -46,7 +44,7 @@ public class Container { private String[] names; @JsonProperty("Ports") - public Port[] ports; + public ContainerPort[] ports; @JsonProperty("Labels") public Map labels; @@ -72,7 +70,7 @@ public class Container { * @since ~{@link RemoteApiVersion#VERSION_1_20} */ @JsonProperty("HostConfig") - private HostConfig hostConfig; + private ContainerHostConfig hostConfig; /** * Docker API docs says "list of networks", but json names `networkSettings`. @@ -81,7 +79,7 @@ public class Container { * @since ~{@link RemoteApiVersion#VERSION_1_22} */ @JsonProperty("NetworkSettings") - private NetworkSettings networkSettings; + private ContainerNetworkSettings networkSettings; public String getId() { return id; @@ -108,7 +106,7 @@ public String getStatus() { return status; } - public Port[] getPorts() { + public ContainerPort[] getPorts() { return ports; } @@ -140,7 +138,7 @@ public Long getSizeRootFs() { * @see #networkSettings */ @CheckForNull - public NetworkSettings getNetworkSettings() { + public ContainerNetworkSettings getNetworkSettings() { return networkSettings; } @@ -148,7 +146,7 @@ public NetworkSettings getNetworkSettings() { * @see #hostConfig */ @CheckForNull - public HostConfig getHostConfig() { + public ContainerHostConfig getHostConfig() { return hostConfig; } @@ -200,296 +198,4 @@ public int hashCode() { .append(networkSettings) .toHashCode(); } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class HostConfig { - @JsonProperty("NetworkMode") - private String networkMode; - - public String getNetworkMode() { - return networkMode; - } - } - - /** - * @since {@link RemoteApiVersion#VERSION_1_22} - */ - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class NetworkSettings { - @JsonProperty("Networks") - private Map networks; - - public Map getNetworks() { - return networks; - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Network { - /** - * FIXME verify - */ - @JsonProperty("IPAMConfig") - private 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 #endpointId - */ - @CheckForNull - public String getEndpointId() { - return endpointId; - } - - /** - * @see #gateway - */ - @CheckForNull - public String getGateway() { - return gateway; - } - - /** - * @see #globalIPv6Address - */ - @CheckForNull - public String getGlobalIPv6Address() { - return globalIPv6Address; - } - - /** - * @see #globalIPv6PrefixLen - */ - @CheckForNull - public Integer getGlobalIPv6PrefixLen() { - return globalIPv6PrefixLen; - } - - /** - * @see #ipAddress - */ - @CheckForNull - public String getIpAddress() { - return ipAddress; - } - - /** - * @see #ipamConfig - */ - @CheckForNull - public Ipam.Config getIpamConfig() { - return ipamConfig; - } - - /** - * @see #ipPrefixLen - */ - @CheckForNull - public Integer getIpPrefixLen() { - return ipPrefixLen; - } - - /** - * @see #ipV6Gateway - */ - @CheckForNull - public String getIpV6Gateway() { - return ipV6Gateway; - } - - /** - * @see #links - */ - @CheckForNull - public List getLinks() { - return links; - } - - /** - * @see #macAddress - */ - @CheckForNull - public String getMacAddress() { - return macAddress; - } - - /** - * @see #networkID - */ - @CheckForNull - public String getNetworkID() { - return networkID; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("aliases", aliases) - .append("ipamConfig", ipamConfig) - .append("links", links) - .append("networkID", networkID) - .append("endpointId", endpointId) - .append("gateway", gateway) - .append("ipAddress", ipAddress) - .append("ipPrefixLen", ipPrefixLen) - .append("ipV6Gateway", ipV6Gateway) - .append("globalIPv6Address", globalIPv6Address) - .append("globalIPv6PrefixLen", globalIPv6PrefixLen) - .append("macAddress", macAddress) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Network network = (Network) o; - - return new EqualsBuilder() - .append(ipamConfig, network.ipamConfig) - .append(links, network.links) - .append(aliases, network.aliases) - .append(networkID, network.networkID) - .append(endpointId, network.endpointId) - .append(gateway, network.gateway) - .append(ipAddress, network.ipAddress) - .append(ipPrefixLen, network.ipPrefixLen) - .append(ipV6Gateway, network.ipV6Gateway) - .append(globalIPv6Address, network.globalIPv6Address) - .append(globalIPv6PrefixLen, network.globalIPv6PrefixLen) - .append(macAddress, network.macAddress) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(ipamConfig) - .append(links) - .append(aliases) - .append(networkID) - .append(endpointId) - .append(gateway) - .append(ipAddress) - .append(ipPrefixLen) - .append(ipV6Gateway) - .append(globalIPv6Address) - .append(globalIPv6PrefixLen) - .append(macAddress) - .toHashCode(); - } - } - } - - @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; - - public String getIp() { - return ip; - } - - public Integer getPrivatePort() { - return privatePort; - } - - public Integer getPublicPort() { - return publicPort; - } - - public String getType() { - return type; - } - - @Override - public String toString() { - return ToStringBuilder.reflectionToString(this); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Port port = (Port) o; - - return new EqualsBuilder() - .append(ip, port.ip) - .append(privatePort, port.privatePort) - .append(publicPort, port.publicPort) - .append(type, port.type) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(ip) - .append(privatePort) - .append(publicPort) - .append(type) - .toHashCode(); - } - } } 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..7ba797899 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java @@ -0,0 +1,56 @@ +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; + +/** + * @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 new ToStringBuilder(this) + .append("networkMode", networkMode) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + ContainerHostConfig that = (ContainerHostConfig) o; + + return new EqualsBuilder() + .append(networkMode, that.networkMode) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(networkMode) + .toHashCode(); + } +} 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..ece75e728 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java @@ -0,0 +1,317 @@ +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; + +/** + * @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 new ToStringBuilder(this) + .append("aliases", aliases) + .append("ipamConfig", ipamConfig) + .append("links", links) + .append("networkID", networkID) + .append("endpointId", endpointId) + .append("gateway", gateway) + .append("ipAddress", ipAddress) + .append("ipPrefixLen", ipPrefixLen) + .append("ipV6Gateway", ipV6Gateway) + .append("globalIPv6Address", globalIPv6Address) + .append("globalIPv6PrefixLen", globalIPv6PrefixLen) + .append("macAddress", macAddress) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + ContainerNetwork network = (ContainerNetwork) o; + + return new EqualsBuilder() + .append(ipamConfig, network.ipamConfig) + .append(links, network.links) + .append(aliases, network.aliases) + .append(networkID, network.networkID) + .append(endpointId, network.endpointId) + .append(gateway, network.gateway) + .append(ipAddress, network.ipAddress) + .append(ipPrefixLen, network.ipPrefixLen) + .append(ipV6Gateway, network.ipV6Gateway) + .append(globalIPv6Address, network.globalIPv6Address) + .append(globalIPv6PrefixLen, network.globalIPv6PrefixLen) + .append(macAddress, network.macAddress) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(ipamConfig) + .append(links) + .append(aliases) + .append(networkID) + .append(endpointId) + .append(gateway) + .append(ipAddress) + .append(ipPrefixLen) + .append(ipV6Gateway) + .append(globalIPv6Address) + .append(globalIPv6PrefixLen) + .append(macAddress) + .toHashCode(); + } +} 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..970a1eb32 --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerNetworkSettings.java @@ -0,0 +1,21 @@ +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 java.util.Map; + +/** + * @see Container + * @since {@link RemoteApiVersion#VERSION_1_22} + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContainerNetworkSettings { + @JsonProperty("Networks") + private Map networks; + + public Map getNetworks() { + return networks; + } +} 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..f3479d9ca --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/ContainerPort.java @@ -0,0 +1,124 @@ +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; + +/** + * @see Container + * @author Kanstantsin Shautsou + */ +@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) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + ContainerPort port = (ContainerPort) o; + + return new EqualsBuilder() + .append(ip, port.ip) + .append(privatePort, port.privatePort) + .append(publicPort, port.publicPort) + .append(type, port.type) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(ip) + .append(privatePort) + .append(publicPort) + .append(type) + .toHashCode(); + } +} diff --git a/src/test/java/com/github/dockerjava/api/model/ContainerTest.java b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java index a45450b58..8b7277e99 100644 --- a/src/test/java/com/github/dockerjava/api/model/ContainerTest.java +++ b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java @@ -38,7 +38,7 @@ public void serderJson1() throws IOException { equalTo("sha256:0cb40641836c461bc97c793971d84d758371ed682042457523e4ae701efe7ec9")); assertThat(container.getSizeRootFs(), equalTo(1113554L)); - final Container.HostConfig hostConfig = container.getHostConfig(); + final ContainerHostConfig hostConfig = container.getHostConfig(); assertThat(hostConfig, notNullValue()); assertThat(hostConfig.getNetworkMode(), equalTo("default")); } From d9a30cb654183e071f7d52cf002745ede581c499 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Fri, 19 Feb 2016 23:17:49 +0300 Subject: [PATCH 08/34] Document code rules. --- docs/devel.adoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/devel.adoc diff --git a/docs/devel.adoc b/docs/devel.adoc new file mode 100644 index 000000000..e3f3640d6 --- /dev/null +++ b/docs/devel.adoc @@ -0,0 +1,23 @@ +### 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. From 18a6307d7d039d97e47b31b2c3e280262f073dbe Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 02:15:48 +0300 Subject: [PATCH 09/34] Remove package prefix for already imported class. --- .../com/github/dockerjava/core/async/JsonStreamProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From c18177eed93687710b4fd97fbe44c5c72300fbb9 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 02:16:21 +0300 Subject: [PATCH 10/34] HostConfig.class: setXX() -> withXX() --- .../dockerjava/api/model/HostConfig.java | 430 ++++++++++++++---- .../core/command/CreateContainerCmdImpl.java | 54 +-- 2 files changed, 375 insertions(+), 109 deletions(-) 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 b15cf8cd6..495bdf9ce 100644 --- a/src/main/java/com/github/dockerjava/api/model/HostConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/HostConfig.java @@ -6,6 +6,8 @@ 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; @@ -428,189 +430,453 @@ 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; } - public void setCapAdd(Capability[] capAdd) { - this.capAdd = capAdd; + /** + * @see #blkioDeviceWriteIOps + */ + public HostConfig withBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { + this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; + return this; } - public void setCapDrop(Capability[] capDrop) { - this.capDrop = capDrop; + /** + * @see #blkioWeight + */ + public HostConfig withBlkioWeight(Integer blkioWeight) { + this.blkioWeight = blkioWeight; + return this; } - public void setContainerIDFile(String containerIDFile) { - this.containerIDFile = containerIDFile; + /** + * @see #blkioWeightDevice + */ + public HostConfig withBlkioWeightDevice(List blkioWeightDevice) { + this.blkioWeightDevice = blkioWeightDevice; + return this; } - public void setDevices(Device[] devices) { - this.devices = devices; + /** + * @see #capAdd + */ + public HostConfig withCapAdd(Capability[] capAdd) { + this.capAdd = capAdd; + return this; } - public void setDns(String[] dns) { - this.dns = dns; + /** + * @see #capDrop + */ + public HostConfig withCapDrop(Capability[] capDrop) { + this.capDrop = capDrop; + return this; } - public void setDnsSearch(String[] dnsSearch) { - this.dnsSearch = dnsSearch; + /** + * @see #cgroupParent + */ + public HostConfig withCgroupParent(String cgroupParent) { + this.cgroupParent = cgroupParent; + return this; } - public void setExtraHosts(String[] extraHosts) { - this.extraHosts = extraHosts; + /** + * @see #containerIDFile + */ + public HostConfig withContainerIDFile(String containerIDFile) { + this.containerIDFile = containerIDFile; + return this; } - @JsonIgnore - public void setLinks(Link... links) { - this.links = new Links(links); + /** + * @see #cpuPeriod + */ + public HostConfig withCpuPeriod(Integer cpuPeriod) { + this.cpuPeriod = cpuPeriod; + return this; } - @JsonIgnore - public void setLogConfig(LogConfig logConfig) { - this.logConfig = logConfig; + /** + * @see #cpuQuota + */ + public HostConfig withCpuQuota(Integer cpuQuota) { + this.cpuQuota = cpuQuota; + return this; } - public void setLxcConf(LxcConf[] lxcConf) { - this.lxcConf = lxcConf; + /** + * @see #cpusetCpus + */ + public HostConfig withCpusetCpus(String cpusetCpus) { + this.cpusetCpus = cpusetCpus; + return this; } - public void setMemory(Long memory) { - this.memory = memory; + /** + * @see #cpusetMems + */ + public HostConfig withCpusetMems(String cpusetMems) { + this.cpusetMems = cpusetMems; + return this; } - public void setMemorySwap(Long memorySwap) { - this.memorySwap = memorySwap; + /** + * @see #cpuShares + */ + public HostConfig withCpuShares(Integer cpuShares) { + this.cpuShares = cpuShares; + return this; } - public void setNetworkMode(String networkMode) { - this.networkMode = networkMode; + /** + * @see #devices + */ + public HostConfig withDevices(Device[] devices) { + this.devices = devices; + return this; } - public void setOomKillDisable(Boolean oomKillDisable) { - this.oomKillDisable = oomKillDisable; + /** + * @see #dns + */ + public HostConfig withDns(String[] dns) { + this.dns = dns; + return this; } - public void setPortBindings(Ports portBindings) { - this.portBindings = portBindings; + /** + * @see #dnsSearch + */ + public HostConfig withDnsSearch(String[] dnsSearch) { + this.dnsSearch = dnsSearch; + return this; } - public void setPrivileged(Boolean privileged) { - this.privileged = privileged; + /** + * @see #extraHosts + */ + public HostConfig withExtraHosts(String[] extraHosts) { + this.extraHosts = extraHosts; + return this; } - public void setPublishAllPorts(Boolean publishAllPorts) { - this.publishAllPorts = publishAllPorts; + /** + * @see #kernelMemory + */ + public HostConfig withKernelMemory(Long kernelMemory) { + this.kernelMemory = kernelMemory; + return this; } - public void setReadonlyRootfs(Boolean readonlyRootfs) { - this.readonlyRootfs = readonlyRootfs; + /** + * @see #links + */ + public HostConfig withLinks(Links links) { + this.links = links; + return this; } - public void setRestartPolicy(RestartPolicy restartPolicy) { - this.restartPolicy = restartPolicy; + /** + * @see #logConfig + */ + public HostConfig withLogConfig(LogConfig logConfig) { + this.logConfig = logConfig; + return this; } - public void setUlimits(Ulimit[] ulimits) { - this.ulimits = ulimits; + /** + * @see #lxcConf + */ + public HostConfig withLxcConf(LxcConf[] lxcConf) { + this.lxcConf = lxcConf; + return this; } - public void setVolumesFrom(VolumesFrom[] volumesFrom) { - this.volumesFrom = volumesFrom; + /** + * @see #memory + */ + public HostConfig withMemory(Long memory) { + this.memory = memory; + return this; } - public void setPidMode(String pidMode) { - this.pidMode = pidMode; + /** + * @see #memoryReservation + */ + public HostConfig withMemoryReservation(Long memoryReservation) { + this.memoryReservation = memoryReservation; + return this; } - public HostConfig setBlkioDeviceReadBps(List blkioDeviceReadBps) { - this.blkioDeviceReadBps = blkioDeviceReadBps; + /** + * @see #memorySwap + */ + public HostConfig withMemorySwap(Long memorySwap) { + this.memorySwap = memorySwap; return this; } - public HostConfig setBlkioDeviceReadIOps(List blkioDeviceReadIOps) { - this.blkioDeviceReadIOps = blkioDeviceReadIOps; + /** + * @see #memorySwappiness + */ + public HostConfig withMemorySwappiness(Integer memorySwappiness) { + this.memorySwappiness = memorySwappiness; return this; } - public HostConfig setBlkioDeviceWriteBps(List blkioDeviceWriteBps) { - this.blkioDeviceWriteBps = blkioDeviceWriteBps; + /** + * @see #networkMode + */ + public HostConfig withNetworkMode(String networkMode) { + this.networkMode = networkMode; return this; } - public HostConfig setBlkioDeviceWriteIOps(List blkioDeviceWriteIOps) { - this.blkioDeviceWriteIOps = blkioDeviceWriteIOps; + /** + * @see #oomKillDisable + */ + public HostConfig withOomKillDisable(Boolean oomKillDisable) { + this.oomKillDisable = oomKillDisable; return this; } - public HostConfig setBlkioWeightDevice(List blkioWeightDevice) { - this.blkioWeightDevice = blkioWeightDevice; + /** + * @see #oomScoreAdj + */ + public HostConfig withOomScoreAdj(Boolean oomScoreAdj) { + this.oomScoreAdj = oomScoreAdj; return this; } - public HostConfig setCpuQuota(Integer cpuQuota) { - this.cpuQuota = cpuQuota; + /** + * @see #pidMode + */ + public HostConfig withPidMode(String pidMode) { + this.pidMode = pidMode; return this; } - public HostConfig setKernelMemory(Long kernelMemory) { - this.kernelMemory = kernelMemory; + /** + * @see #portBindings + */ + public HostConfig withPortBindings(Ports portBindings) { + this.portBindings = portBindings; return this; } - public HostConfig setMemoryReservation(Long memoryReservation) { - this.memoryReservation = memoryReservation; + /** + * @see #privileged + */ + public HostConfig withPrivileged(Boolean privileged) { + this.privileged = privileged; return this; } - public HostConfig setMemorySwappiness(Integer memorySwappiness) { - this.memorySwappiness = memorySwappiness; + /** + * @see #publishAllPorts + */ + public HostConfig withPublishAllPorts(Boolean publishAllPorts) { + this.publishAllPorts = publishAllPorts; return this; } - public HostConfig setOomScoreAdj(Boolean oomScoreAdj) { - this.oomScoreAdj = oomScoreAdj; + /** + * @see #readonlyRootfs + */ + public HostConfig withReadonlyRootfs(Boolean readonlyRootfs) { + this.readonlyRootfs = readonlyRootfs; return this; } - public HostConfig setSecurityOpts(List securityOpts) { - this.securityOpts = securityOpts; + /** + * @see #restartPolicy + */ + public HostConfig withRestartPolicy(RestartPolicy restartPolicy) { + this.restartPolicy = restartPolicy; return this; } - public HostConfig setCgroupParent(String cgroupParent) { - this.cgroupParent = cgroupParent; + /** + * @see #securityOpts + */ + public HostConfig withSecurityOpts(List securityOpts) { + this.securityOpts = securityOpts; return this; } - public HostConfig setShmSize(String shmSize) { + /** + * @see #shmSize + */ + public HostConfig withShmSize(String shmSize) { this.shmSize = shmSize; return this; } - public HostConfig setVolumeDriver(String volumeDriver) { + /** + * @see #ulimits + */ + public HostConfig withUlimits(Ulimit[] ulimits) { + this.ulimits = ulimits; + return this; + } + + /** + * @see #volumeDriver + */ + public HostConfig withVolumeDriver(String volumeDriver) { this.volumeDriver = volumeDriver; return this; } + /** + * @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) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + HostConfig that = (HostConfig) o; + + return new EqualsBuilder() + .append(binds, that.binds) + .append(blkioWeight, that.blkioWeight) + .append(blkioWeightDevice, that.blkioWeightDevice) + .append(blkioDeviceReadBps, that.blkioDeviceReadBps) + .append(blkioDeviceReadIOps, that.blkioDeviceReadIOps) + .append(blkioDeviceWriteBps, that.blkioDeviceWriteBps) + .append(blkioDeviceWriteIOps, that.blkioDeviceWriteIOps) + .append(memorySwappiness, that.memorySwappiness) + .append(capAdd, that.capAdd) + .append(capDrop, that.capDrop) + .append(containerIDFile, that.containerIDFile) + .append(cpuPeriod, that.cpuPeriod) + .append(cpuShares, that.cpuShares) + .append(cpuQuota, that.cpuQuota) + .append(cpusetCpus, that.cpusetCpus) + .append(cpusetMems, that.cpusetMems) + .append(devices, that.devices) + .append(dns, that.dns) + .append(dnsSearch, that.dnsSearch) + .append(extraHosts, that.extraHosts) + .append(links, that.links) + .append(logConfig, that.logConfig) + .append(lxcConf, that.lxcConf) + .append(memory, that.memory) + .append(memorySwap, that.memorySwap) + .append(memoryReservation, that.memoryReservation) + .append(kernelMemory, that.kernelMemory) + .append(networkMode, that.networkMode) + .append(oomKillDisable, that.oomKillDisable) + .append(oomScoreAdj, that.oomScoreAdj) + .append(portBindings, that.portBindings) + .append(privileged, that.privileged) + .append(publishAllPorts, that.publishAllPorts) + .append(readonlyRootfs, that.readonlyRootfs) + .append(restartPolicy, that.restartPolicy) + .append(ulimits, that.ulimits) + .append(volumesFrom, that.volumesFrom) + .append(pidMode, that.pidMode) + .append(securityOpts, that.securityOpts) + .append(cgroupParent, that.cgroupParent) + .append(volumeDriver, that.volumeDriver) + .append(shmSize, that.shmSize) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(binds) + .append(blkioWeight) + .append(blkioWeightDevice) + .append(blkioDeviceReadBps) + .append(blkioDeviceReadIOps) + .append(blkioDeviceWriteBps) + .append(blkioDeviceWriteIOps) + .append(memorySwappiness) + .append(capAdd) + .append(capDrop) + .append(containerIDFile) + .append(cpuPeriod) + .append(cpuShares) + .append(cpuQuota) + .append(cpusetCpus) + .append(cpusetMems) + .append(devices) + .append(dns) + .append(dnsSearch) + .append(extraHosts) + .append(links) + .append(logConfig) + .append(lxcConf) + .append(memory) + .append(memorySwap) + .append(memoryReservation) + .append(kernelMemory) + .append(networkMode) + .append(oomKillDisable) + .append(oomScoreAdj) + .append(portBindings) + .append(privileged) + .append(publishAllPorts) + .append(readonlyRootfs) + .append(restartPolicy) + .append(ulimits) + .append(volumesFrom) + .append(pidMode) + .append(securityOpts) + .append(cgroupParent) + .append(volumeDriver) + .append(shmSize) + .toHashCode(); + } } 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 841292b0e..e03acbf7f 100644 --- a/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java +++ b/src/main/java/com/github/dockerjava/core/command/CreateContainerCmdImpl.java @@ -450,14 +450,14 @@ public CreateContainerCmd withBinds(List 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; } @@ -470,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; } @@ -496,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; } @@ -544,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; } @@ -557,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; } @@ -623,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; } @@ -670,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; } @@ -683,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; } @@ -697,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; } @@ -725,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; } @@ -752,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; } @@ -772,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; } @@ -821,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; } @@ -854,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; } @@ -874,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; } From cf39893a5f2c4ff9c73d459ae2e7cb6cf0a31ea3 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 02:22:14 +0300 Subject: [PATCH 11/34] Info.class - remove isXX that doesn't match primitives - added builder setters --- .../com/github/dockerjava/api/model/Info.java | 353 +++++++++++++++++- 1 file changed, 344 insertions(+), 9 deletions(-) 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 3c572fcad..ebf8b4ef1 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -209,10 +209,6 @@ public String getArchitecture() { return architecture; } - public Boolean isDebug() { - return debug; - } - public Integer getContainers() { return containers; } @@ -289,10 +285,6 @@ public String[] getSockets() { return sockets; } - public Boolean isMemoryLimit() { - return memoryLimit; - } - public Long getnEventListener() { return nEventListener; } @@ -362,7 +354,6 @@ public String getServerVersion() { } // autogenerated getters - // TODO remove `is*()` that doesn't match to primitives @CheckForNull public Integer getContainersPaused() { return containersPaused; @@ -445,6 +436,350 @@ public String getOsType() { return osType; } + /** + * @see #architecture + */ + public Info withArchitecture(String architecture) { + this.architecture = architecture; + return this; + } + + /** + * @see #containers + */ + public Info withContainers(Integer containers) { + this.containers = containers; + return this; + } + + /** + * @see #containersPaused + */ + public Info withContainersPaused(Integer containersPaused) { + this.containersPaused = containersPaused; + return this; + } + + /** + * @see #containersRunning + */ + public Info withContainersRunning(Integer containersRunning) { + this.containersRunning = containersRunning; + return this; + } + + /** + * @see #containersStopped + */ + public Info withContainersStopped(Integer containersStopped) { + this.containersStopped = containersStopped; + return this; + } + + /** + * @see #cpuCfsPeriod + */ + public Info withCpuCfsPeriod(Boolean cpuCfsPeriod) { + this.cpuCfsPeriod = cpuCfsPeriod; + return this; + } + + /** + * @see #cpuCfsQuota + */ + public Info withCpuCfsQuota(Boolean cpuCfsQuota) { + this.cpuCfsQuota = cpuCfsQuota; + return this; + } + + /** + * @see #debug + */ + public Info withDebug(Boolean debug) { + this.debug = debug; + return this; + } + + /** + * @see #discoveryBackend + */ + public Info withDiscoveryBackend(String discoveryBackend) { + this.discoveryBackend = discoveryBackend; + return this; + } + + /** + * @see #dockerRootDir + */ + public Info withDockerRootDir(String dockerRootDir) { + this.dockerRootDir = dockerRootDir; + return this; + } + + /** + * @see #driver + */ + public Info withDriver(String driver) { + this.driver = driver; + return this; + } + + /** + * @see #driverStatuses + */ + public Info withDriverStatuses(List> driverStatuses) { + this.driverStatuses = driverStatuses; + return this; + } + + /** + * @see #executionDriver + */ + public Info withExecutionDriver(String executionDriver) { + this.executionDriver = executionDriver; + return this; + } + + /** + * @see #experimentalBuild + */ + public Info withExperimentalBuild(Boolean experimentalBuild) { + this.experimentalBuild = experimentalBuild; + return this; + } + + /** + * @see #httpProxy + */ + public Info withHttpProxy(String httpProxy) { + this.httpProxy = httpProxy; + return this; + } + + /** + * @see #httpsProxy + */ + public Info withHttpsProxy(String httpsProxy) { + this.httpsProxy = httpsProxy; + return this; + } + + /** + * @see #id + */ + public Info withId(String id) { + this.id = id; + return this; + } + + /** + * @see #images + */ + public Info withImages(Integer images) { + this.images = images; + return this; + } + + /** + * @see #indexServerAddress + */ + public Info withIndexServerAddress(String indexServerAddress) { + this.indexServerAddress = indexServerAddress; + return this; + } + + /** + * @see #initPath + */ + public Info withInitPath(String initPath) { + this.initPath = initPath; + return this; + } + + /** + * @see #initSha1 + */ + public Info withInitSha1(String initSha1) { + this.initSha1 = initSha1; + return this; + } + + /** + * @see #ipv4Forwarding + */ + public Info withIpv4Forwarding(Boolean ipv4Forwarding) { + this.ipv4Forwarding = ipv4Forwarding; + return this; + } + + /** + * @see #kernelVersion + */ + public Info withKernelVersion(String kernelVersion) { + this.kernelVersion = kernelVersion; + return this; + } + + /** + * @see #labels + */ + public Info withLabels(String[] labels) { + this.labels = labels; + return this; + } + + /** + * @see #memoryLimit + */ + public Info withMemoryLimit(Boolean memoryLimit) { + this.memoryLimit = memoryLimit; + return this; + } + + /** + * @see #memTotal + */ + public Info withMemTotal(Long memTotal) { + this.memTotal = memTotal; + return this; + } + + /** + * @see #name + */ + public Info withName(String name) { + this.name = name; + return this; + } + + /** + * @see #ncpu + */ + public Info withNcpu(Integer ncpu) { + this.ncpu = ncpu; + return this; + } + + /** + * @see #nEventListener + */ + public Info withnEventListener(Long nEventListener) { + this.nEventListener = nEventListener; + return this; + } + + /** + * @see #nfd + */ + public Info withNfd(Integer nfd) { + this.nfd = nfd; + return this; + } + + /** + * @see #nGoroutines + */ + public Info withnGoroutines(Integer nGoroutines) { + this.nGoroutines = nGoroutines; + return this; + } + + /** + * @see #noProxy + */ + public Info withNoProxy(String noProxy) { + this.noProxy = noProxy; + return this; + } + + /** + * @see #oomKillDisable + */ + public Info withOomKillDisable(Boolean oomKillDisable) { + this.oomKillDisable = oomKillDisable; + return this; + } + + /** + * @see #oomScoreAdj + */ + public Info withOomScoreAdj(Integer oomScoreAdj) { + this.oomScoreAdj = oomScoreAdj; + return this; + } + + /** + * @see #operatingSystem + */ + public Info withOperatingSystem(String operatingSystem) { + this.operatingSystem = operatingSystem; + return this; + } + + /** + * @see #osType + */ + public Info withOsType(String osType) { + this.osType = osType; + return this; + } + + /** + * @see #plugins + */ + public Info withPlugins(Map> plugins) { + this.plugins = plugins; + return this; + } + + /** + * @see #registryConfig + */ + public Info withRegistryConfig(RegistryConfig registryConfig) { + this.registryConfig = registryConfig; + return this; + } + + /** + * @see #serverVersion + */ + public Info withServerVersion(String serverVersion) { + this.serverVersion = serverVersion; + return this; + } + + /** + * @see #sockets + */ + public Info withSockets(String[] sockets) { + this.sockets = sockets; + return this; + } + + /** + * @see #swapLimit + */ + public Info withSwapLimit(Boolean swapLimit) { + this.swapLimit = swapLimit; + return this; + } + + /** + * @see #systemStatus + */ + public Info withSystemStatus(List systemStatus) { + this.systemStatus = systemStatus; + return this; + } + + /** + * @see #systemTime + */ + public Info withSystemTime(String systemTime) { + this.systemTime = systemTime; + return this; + } + @Override public String toString() { return ToStringBuilder.reflectionToString(this); From f69c0564563047915baa9fe81c54fa2716da2072 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 02:54:55 +0300 Subject: [PATCH 12/34] Extract nested class from Info.class --- .../com/github/dockerjava/api/model/Info.java | 759 ++++++++---------- .../api/model/InfoRegistryConfig.java | 228 ++++++ .../github/dockerjava/api/model/InfoTest.java | 5 +- 3 files changed, 556 insertions(+), 436 deletions(-) create mode 100644 src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java 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 ebf8b4ef1..bb132b500 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -181,7 +181,7 @@ public class Info { private String operatingSystem; @JsonProperty("RegistryConfig") - private RegistryConfig registryConfig; + private InfoRegistryConfig registryConfig; @JsonProperty("Sockets") private String[] sockets; @@ -209,311 +209,164 @@ public String getArchitecture() { return architecture; } - public Integer getContainers() { - return containers; - } - - /** - * @see #cpuCfsPeriod - */ - @CheckForNull - public Boolean getCpuCfsPeriod() { - return cpuCfsPeriod; - } - /** - * @see #cpuCfsQuota + * @see #architecture */ - @CheckForNull - public Boolean getCpuCfsQuota() { - return cpuCfsQuota; - } - - public String getDockerRootDir() { - return dockerRootDir; - } - - public String getDriver() { - return driver; - } - - public List> getDriverStatuses() { - return driverStatuses; + public Info withArchitecture(String architecture) { + this.architecture = architecture; + return this; } /** - * @see #systemStatus + * @see #containers */ @CheckForNull - public List getSystemStatus() { - return systemStatus; + public Integer getContainers() { + return containers; } /** - * @see #plugins + * @see #containers */ - @CheckForNull - public Map> getPlugins() { - return plugins; - } - - public Integer getImages() { - return images; - } - - public String getIndexServerAddress() { - return indexServerAddress; - } - - public String getInitPath() { - return initPath; - } - - public String getInitSha1() { - return initSha1; - } - - public String getKernelVersion() { - return kernelVersion; - } - - public String[] getLabels() { - return labels; - } - - public String[] getSockets() { - return sockets; - } - - public Long getnEventListener() { - return nEventListener; - } - - public Long getMemTotal() { - return memTotal; - } - - public String getName() { - return name; - } - - public Integer getNGoroutines() { - return nGoroutines; - } - - public String getOperatingSystem() { - return operatingSystem; - } - - public Boolean getSwapLimit() { - return swapLimit; - } - - public String getExecutionDriver() { - return executionDriver; + public Info withContainers(Integer containers) { + this.containers = containers; + return this; } /** - * @see #experimentalBuild + * @see #containersPaused */ @CheckForNull - public Boolean getExperimentalBuild() { - return experimentalBuild; + public Integer getContainersPaused() { + return containersPaused; } /** - * @see #httpProxy + * @see #containersPaused */ - @CheckForNull - public String getHttpProxy() { - return httpProxy; + public Info withContainersPaused(Integer containersPaused) { + this.containersPaused = containersPaused; + return this; } /** - * @see #httpsProxy + * @see #containersRunning */ @CheckForNull - public String getHttpsProxy() { - return httpsProxy; + public Integer getContainersRunning() { + return containersRunning; } /** - * @see #systemTime + * @see #containersRunning */ - @CheckForNull - public String getSystemTime() { - return systemTime; + public Info withContainersRunning(Integer containersRunning) { + this.containersRunning = containersRunning; + return this; } /** - * @see #serverVersion + * @see #containersStopped */ - @CheckForNull - public String getServerVersion() { - return serverVersion; - } - - // autogenerated getters - @CheckForNull - public Integer getContainersPaused() { - return containersPaused; - } - - @CheckForNull - public Integer getContainersRunning() { - return containersRunning; - } - @CheckForNull public Integer getContainersStopped() { return containersStopped; } - @CheckForNull - public Boolean getDebug() { - return debug; - } - - @CheckForNull - public String getDiscoveryBackend() { - return discoveryBackend; - } - - @CheckForNull - public String getId() { - return id; - } - - @CheckForNull - public Boolean getIpv4Forwarding() { - return ipv4Forwarding; - } - - @CheckForNull - public Boolean getMemoryLimit() { - return memoryLimit; - } - - @CheckForNull - public Integer getNCPU() { - return ncpu; - } - - @CheckForNull - public Integer getNFd() { - return nfd; - } - - @CheckForNull - public String getNoProxy() { - return noProxy; - } - - @CheckForNull - public Boolean getOomKillDisable() { - return oomKillDisable; - } - - @CheckForNull - public RegistryConfig getRegistryConfig() { - return registryConfig; - } - // end of autogeneration - /** - * @see #oomScoreAdj + * @see #containersStopped */ - @CheckForNull - public Integer getOomScoreAdj() { - return oomScoreAdj; + public Info withContainersStopped(Integer containersStopped) { + this.containersStopped = containersStopped; + return this; } /** - * @see #osType + * @see #cpuCfsPeriod */ @CheckForNull - public String getOsType() { - return osType; + public Boolean getCpuCfsPeriod() { + return cpuCfsPeriod; } /** - * @see #architecture + * @see #cpuCfsPeriod */ - public Info withArchitecture(String architecture) { - this.architecture = architecture; + public Info withCpuCfsPeriod(Boolean cpuCfsPeriod) { + this.cpuCfsPeriod = cpuCfsPeriod; return this; } /** - * @see #containers + * @see #cpuCfsQuota */ - public Info withContainers(Integer containers) { - this.containers = containers; - return this; + @CheckForNull + public Boolean getCpuCfsQuota() { + return cpuCfsQuota; } /** - * @see #containersPaused + * @see #cpuCfsQuota */ - public Info withContainersPaused(Integer containersPaused) { - this.containersPaused = containersPaused; + public Info withCpuCfsQuota(Boolean cpuCfsQuota) { + this.cpuCfsQuota = cpuCfsQuota; return this; } /** - * @see #containersRunning + * @see #debug */ - public Info withContainersRunning(Integer containersRunning) { - this.containersRunning = containersRunning; - return this; + @CheckForNull + public Boolean getDebug() { + return debug; } /** - * @see #containersStopped + * @see #debug */ - public Info withContainersStopped(Integer containersStopped) { - this.containersStopped = containersStopped; + public Info withDebug(Boolean debug) { + this.debug = debug; return this; } /** - * @see #cpuCfsPeriod + * @see #discoveryBackend */ - public Info withCpuCfsPeriod(Boolean cpuCfsPeriod) { - this.cpuCfsPeriod = cpuCfsPeriod; - return this; + @CheckForNull + public String getDiscoveryBackend() { + return discoveryBackend; } /** - * @see #cpuCfsQuota + * @see #discoveryBackend */ - public Info withCpuCfsQuota(Boolean cpuCfsQuota) { - this.cpuCfsQuota = cpuCfsQuota; + public Info withDiscoveryBackend(String discoveryBackend) { + this.discoveryBackend = discoveryBackend; return this; } /** - * @see #debug + * @see #dockerRootDir */ - public Info withDebug(Boolean debug) { - this.debug = debug; - return this; + @CheckForNull + public String getDockerRootDir() { + return dockerRootDir; } /** - * @see #discoveryBackend + * @see #dockerRootDir */ - public Info withDiscoveryBackend(String discoveryBackend) { - this.discoveryBackend = discoveryBackend; + public Info withDockerRootDir(String dockerRootDir) { + this.dockerRootDir = dockerRootDir; return this; } /** - * @see #dockerRootDir + * @see #driver */ - public Info withDockerRootDir(String dockerRootDir) { - this.dockerRootDir = dockerRootDir; - return this; + @CheckForNull + public String getDriver() { + return driver; } /** @@ -524,6 +377,14 @@ public Info withDriver(String driver) { return this; } + /** + * @see #driverStatuses + */ + @CheckForNull + public List> getDriverStatuses() { + return driverStatuses; + } + /** * @see #driverStatuses */ @@ -532,6 +393,14 @@ public Info withDriverStatuses(List> driverStatuses) { return this; } + /** + * @see #executionDriver + */ + @CheckForNull + public String getExecutionDriver() { + return executionDriver; + } + /** * @see #executionDriver */ @@ -540,6 +409,14 @@ public Info withExecutionDriver(String executionDriver) { return this; } + /** + * @see #experimentalBuild + */ + @CheckForNull + public Boolean getExperimentalBuild() { + return experimentalBuild; + } + /** * @see #experimentalBuild */ @@ -548,6 +425,14 @@ public Info withExperimentalBuild(Boolean experimentalBuild) { return this; } + /** + * @see #httpProxy + */ + @CheckForNull + public String getHttpProxy() { + return httpProxy; + } + /** * @see #httpProxy */ @@ -556,6 +441,14 @@ public Info withHttpProxy(String httpProxy) { return this; } + /** + * @see #httpsProxy + */ + @CheckForNull + public String getHttpsProxy() { + return httpsProxy; + } + /** * @see #httpsProxy */ @@ -564,6 +457,14 @@ public Info withHttpsProxy(String httpsProxy) { return this; } + /** + * @see #id + */ + @CheckForNull + public String getId() { + return id; + } + /** * @see #id */ @@ -572,6 +473,14 @@ public Info withId(String id) { return this; } + /** + * @see #images + */ + @CheckForNull + public Integer getImages() { + return images; + } + /** * @see #images */ @@ -580,6 +489,14 @@ public Info withImages(Integer images) { return this; } + /** + * @see #indexServerAddress + */ + @CheckForNull + public String getIndexServerAddress() { + return indexServerAddress; + } + /** * @see #indexServerAddress */ @@ -588,6 +505,14 @@ public Info withIndexServerAddress(String indexServerAddress) { return this; } + /** + * @see #initPath + */ + @CheckForNull + public String getInitPath() { + return initPath; + } + /** * @see #initPath */ @@ -596,6 +521,14 @@ public Info withInitPath(String initPath) { return this; } + /** + * @see #initSha1 + */ + @CheckForNull + public String getInitSha1() { + return initSha1; + } + /** * @see #initSha1 */ @@ -604,6 +537,14 @@ public Info withInitSha1(String initSha1) { return this; } + /** + * @see #ipv4Forwarding + */ + @CheckForNull + public Boolean getIpv4Forwarding() { + return ipv4Forwarding; + } + /** * @see #ipv4Forwarding */ @@ -612,6 +553,14 @@ public Info withIpv4Forwarding(Boolean ipv4Forwarding) { return this; } + /** + * @see #kernelVersion + */ + @CheckForNull + public String getKernelVersion() { + return kernelVersion; + } + /** * @see #kernelVersion */ @@ -620,6 +569,14 @@ public Info withKernelVersion(String kernelVersion) { return this; } + /** + * @see #labels + */ + @CheckForNull + public String[] getLabels() { + return labels; + } + /** * @see #labels */ @@ -628,6 +585,14 @@ public Info withLabels(String[] labels) { return this; } + /** + * @see #memoryLimit + */ + @CheckForNull + public Boolean getMemoryLimit() { + return memoryLimit; + } + /** * @see #memoryLimit */ @@ -636,6 +601,14 @@ public Info withMemoryLimit(Boolean memoryLimit) { return this; } + /** + * @see #memTotal + */ + @CheckForNull + public Long getMemTotal() { + return memTotal; + } + /** * @see #memTotal */ @@ -644,6 +617,14 @@ public Info withMemTotal(Long memTotal) { return this; } + /** + * @see #name + */ + @CheckForNull + public String getName() { + return name; + } + /** * @see #name */ @@ -652,6 +633,14 @@ public Info withName(String name) { return this; } + /** + * @see #ncpu + */ + @CheckForNull + public Integer getNcpu() { + return ncpu; + } + /** * @see #ncpu */ @@ -660,6 +649,14 @@ public Info withNcpu(Integer ncpu) { return this; } + /** + * @see #nEventListener + */ + @CheckForNull + public Long getnEventListener() { + return nEventListener; + } + /** * @see #nEventListener */ @@ -668,6 +665,14 @@ public Info withnEventListener(Long nEventListener) { return this; } + /** + * @see #nfd + */ + @CheckForNull + public Integer getNfd() { + return nfd; + } + /** * @see #nfd */ @@ -676,6 +681,14 @@ public Info withNfd(Integer nfd) { return this; } + /** + * @see #nGoroutines + */ + @CheckForNull + public Integer getnGoroutines() { + return nGoroutines; + } + /** * @see #nGoroutines */ @@ -684,6 +697,14 @@ public Info withnGoroutines(Integer nGoroutines) { return this; } + /** + * @see #noProxy + */ + @CheckForNull + public String getNoProxy() { + return noProxy; + } + /** * @see #noProxy */ @@ -692,6 +713,14 @@ public Info withNoProxy(String noProxy) { return this; } + /** + * @see #oomKillDisable + */ + @CheckForNull + public Boolean getOomKillDisable() { + return oomKillDisable; + } + /** * @see #oomKillDisable */ @@ -700,6 +729,14 @@ public Info withOomKillDisable(Boolean oomKillDisable) { return this; } + /** + * @see #oomScoreAdj + */ + @CheckForNull + public Integer getOomScoreAdj() { + return oomScoreAdj; + } + /** * @see #oomScoreAdj */ @@ -708,6 +745,14 @@ public Info withOomScoreAdj(Integer oomScoreAdj) { return this; } + /** + * @see #operatingSystem + */ + @CheckForNull + public String getOperatingSystem() { + return operatingSystem; + } + /** * @see #operatingSystem */ @@ -716,6 +761,14 @@ public Info withOperatingSystem(String operatingSystem) { return this; } + /** + * @see #osType + */ + @CheckForNull + public String getOsType() { + return osType; + } + /** * @see #osType */ @@ -724,6 +777,14 @@ public Info withOsType(String osType) { return this; } + /** + * @see #plugins + */ + @CheckForNull + public Map> getPlugins() { + return plugins; + } + /** * @see #plugins */ @@ -735,11 +796,27 @@ public Info withPlugins(Map> plugins) { /** * @see #registryConfig */ - public Info withRegistryConfig(RegistryConfig 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 */ @@ -748,6 +825,14 @@ public Info withServerVersion(String serverVersion) { return this; } + /** + * @see #sockets + */ + @CheckForNull + public String[] getSockets() { + return sockets; + } + /** * @see #sockets */ @@ -756,6 +841,14 @@ public Info withSockets(String[] sockets) { return this; } + /** + * @see #swapLimit + */ + @CheckForNull + public Boolean getSwapLimit() { + return swapLimit; + } + /** * @see #swapLimit */ @@ -764,6 +857,14 @@ public Info withSwapLimit(Boolean swapLimit) { return this; } + /** + * @see #systemStatus + */ + @CheckForNull + public List getSystemStatus() { + return systemStatus; + } + /** * @see #systemStatus */ @@ -772,6 +873,14 @@ public Info withSystemStatus(List systemStatus) { return this; } + /** + * @see #systemTime + */ + @CheckForNull + public String getSystemTime() { + return systemTime; + } + /** * @see #systemTime */ @@ -889,220 +998,4 @@ public int hashCode() { .toHashCode(); } - /** - * @since ~{@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} - */ - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class RegistryConfig { - @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 RegistryConfig withIndexConfigs(Map indexConfigs) { - this.indexConfigs = indexConfigs; - return this; - } - - /** - * @see #insecureRegistryCIDRs - */ - @CheckForNull - public List getInsecureRegistryCIDRs() { - return insecureRegistryCIDRs; - } - - /** - * @see #insecureRegistryCIDRs - */ - public RegistryConfig withInsecureRegistryCIDRs(List insecureRegistryCIDRs) { - this.insecureRegistryCIDRs = insecureRegistryCIDRs; - return this; - } - - /** - * @see #mirrors - */ - @CheckForNull - public Object getMirrors() { - return mirrors; - } - - /** - * @see #mirrors - */ - public RegistryConfig withMirrors(Object mirrors) { - this.mirrors = mirrors; - return this; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("indexConfigs", indexConfigs) - .append("insecureRegistryCIDRs", insecureRegistryCIDRs) - .append("mirrors", mirrors) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - RegistryConfig that = (RegistryConfig) o; - - return new EqualsBuilder() - .append(indexConfigs, that.indexConfigs) - .append(insecureRegistryCIDRs, that.insecureRegistryCIDRs) - .append(mirrors, that.mirrors) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(indexConfigs) - .append(insecureRegistryCIDRs) - .append(mirrors) - .toHashCode(); - } - - /** - * @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 new ToStringBuilder(this) - .append("mirrors", mirrors) - .append("name", name) - .append("official", official) - .append("secure", secure) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - IndexConfig that = (IndexConfig) o; - - return new EqualsBuilder() - .append(mirrors, that.mirrors) - .append(name, that.name) - .append(official, that.official) - .append(secure, that.secure) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(mirrors) - .append(name) - .append(official) - .append(secure) - .toHashCode(); - } - } - } } 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..384c1a04c --- /dev/null +++ b/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java @@ -0,0 +1,228 @@ +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 new ToStringBuilder(this) + .append("indexConfigs", indexConfigs) + .append("insecureRegistryCIDRs", insecureRegistryCIDRs) + .append("mirrors", mirrors) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + InfoRegistryConfig that = (InfoRegistryConfig) o; + + return new EqualsBuilder() + .append(indexConfigs, that.indexConfigs) + .append(insecureRegistryCIDRs, that.insecureRegistryCIDRs) + .append(mirrors, that.mirrors) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(indexConfigs) + .append(insecureRegistryCIDRs) + .append(mirrors) + .toHashCode(); + } + + /** + * @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 new ToStringBuilder(this) + .append("mirrors", mirrors) + .append("name", name) + .append("official", official) + .append("secure", secure) + .toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + + if (o == null || getClass() != o.getClass()) return false; + + IndexConfig that = (IndexConfig) o; + + return new EqualsBuilder() + .append(mirrors, that.mirrors) + .append(name, that.name) + .append(official, that.official) + .append(secure, that.secure) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(mirrors) + .append(name) + .append(official) + .append(secure) + .toHashCode(); + } + } +} diff --git a/src/test/java/com/github/dockerjava/api/model/InfoTest.java b/src/test/java/com/github/dockerjava/api/model/InfoTest.java index 83d49a397..3bf6b0ec5 100644 --- a/src/test/java/com/github/dockerjava/api/model/InfoTest.java +++ b/src/test/java/com/github/dockerjava/api/model/InfoTest.java @@ -2,8 +2,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.dockerjava.api.model.Info.RegistryConfig; -import com.github.dockerjava.api.model.Info.RegistryConfig.IndexConfig; +import com.github.dockerjava.api.model.InfoRegistryConfig.IndexConfig; import org.hamcrest.CoreMatchers; import org.testng.annotations.Test; @@ -69,7 +68,7 @@ public void serder1Json() throws IOException { assertThat(info.getOomKillDisable(), is(true)); assertThat(info.getOsType(), equalTo("linux")); - final RegistryConfig registryConfig = info.getRegistryConfig(); + final InfoRegistryConfig registryConfig = info.getRegistryConfig(); assertThat(registryConfig, notNullValue()); final List cidRs = registryConfig.getInsecureRegistryCIDRs(); assertThat(cidRs, notNullValue()); From 25018fc86a0bb4245ed569a6e185a266b7265085 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 02:58:19 +0300 Subject: [PATCH 13/34] Restore getter name. IDEA generated it as javabean getter but docker-java uses other style? --- .../java/com/github/dockerjava/api/model/Info.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 bb132b500..327166bb5 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -637,14 +637,14 @@ public Info withName(String name) { * @see #ncpu */ @CheckForNull - public Integer getNcpu() { + public Integer getNCPU() { return ncpu; } /** * @see #ncpu */ - public Info withNcpu(Integer ncpu) { + public Info withNCPU(Integer ncpu) { this.ncpu = ncpu; return this; } @@ -669,14 +669,14 @@ public Info withnEventListener(Long nEventListener) { * @see #nfd */ @CheckForNull - public Integer getNfd() { + public Integer getNFd() { return nfd; } /** * @see #nfd */ - public Info withNfd(Integer nfd) { + public Info withNFd(Integer nfd) { this.nfd = nfd; return this; } @@ -685,7 +685,7 @@ public Info withNfd(Integer nfd) { * @see #nGoroutines */ @CheckForNull - public Integer getnGoroutines() { + public Integer getNGoroutines() { return nGoroutines; } From 57a2807270fea4cdba36c73d5ace153ac9dea424 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 05:40:11 +0300 Subject: [PATCH 14/34] Test case Info and fix. --- .../com/github/dockerjava/api/model/Info.java | 254 ++++++++++-------- .../api/model/InfoRegistryConfig.java | 51 +--- .../github/dockerjava/api/model/InfoTest.java | 95 ++++++- .../dockerjava/test/serdes/JSONSamples.java | 2 + 4 files changed, 244 insertions(+), 158 deletions(-) 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 327166bb5..7270eceb8 100644 --- a/src/main/java/com/github/dockerjava/api/model/Info.java +++ b/src/main/java/com/github/dockerjava/api/model/Info.java @@ -57,9 +57,15 @@ public class Info { /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} */ - @JsonProperty("cpuCfsQuota") + @JsonProperty("CpuCfsQuota") private Boolean cpuCfsQuota; + @JsonProperty("CPUShares") + private Boolean cpuShares; + + @JsonProperty("CPUSet") + private Boolean cpuSet; + @JsonProperty("Debug") private Boolean debug; @@ -90,6 +96,9 @@ public class Info { @JsonProperty("ExecutionDriver") private String executionDriver; + @JsonProperty("LoggingDriver") + private String loggingDriver; + /** * @since {@link com.github.dockerjava.core.RemoteApiVersion#VERSION_1_20} */ @@ -114,6 +123,12 @@ public class Info { @JsonProperty("IPv4Forwarding") private Boolean ipv4Forwarding; + @JsonProperty("BridgeNfIptables") + private Boolean bridgeNfIptables; + + @JsonProperty("BridgeNfIp6tables") + private Boolean bridgeNfIp6tables; + @JsonProperty("Images") private Integer images; @@ -145,7 +160,7 @@ public class Info { private Integer ncpu; @JsonProperty("NEventsListener") - private Long nEventListener; + private Integer nEventsListener; @JsonProperty("NFd") private Integer nfd; @@ -201,6 +216,12 @@ public class Info { @JsonProperty("ServerVersion") private String serverVersion; + @JsonProperty("ClusterStore") + private String clusterStore; + + @JsonProperty("ClusterAdvertise") + private String clusterAdvertise; + /** * @see #architecture */ @@ -313,6 +334,38 @@ public Info withCpuCfsQuota(Boolean 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 */ @@ -409,6 +462,22 @@ public Info withExecutionDriver(String executionDriver) { return this; } + /** + * @see #loggingDriver + */ + @CheckForNull + public String getLoggingDriver() { + return loggingDriver; + } + + /** + * @see #loggingDriver + */ + public Info withLoggingDriver(String loggingDriver) { + this.loggingDriver = loggingDriver; + return this; + } + /** * @see #experimentalBuild */ @@ -541,18 +610,50 @@ public Info withInitSha1(String initSha1) { * @see #ipv4Forwarding */ @CheckForNull - public Boolean getIpv4Forwarding() { + public Boolean getIPv4Forwarding() { return ipv4Forwarding; } /** * @see #ipv4Forwarding */ - public Info withIpv4Forwarding(Boolean 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 */ @@ -650,18 +751,18 @@ public Info withNCPU(Integer ncpu) { } /** - * @see #nEventListener + * @see #nEventsListener */ @CheckForNull - public Long getnEventListener() { - return nEventListener; + public Integer getNEventsListener() { + return nEventsListener; } /** - * @see #nEventListener + * @see #nEventsListener */ - public Info withnEventListener(Long nEventListener) { - this.nEventListener = nEventListener; + public Info withNEventsListener(Integer nEventListener) { + this.nEventsListener = nEventListener; return this; } @@ -692,7 +793,7 @@ public Integer getNGoroutines() { /** * @see #nGoroutines */ - public Info withnGoroutines(Integer nGoroutines) { + public Info withNGoroutines(Integer nGoroutines) { this.nGoroutines = nGoroutines; return this; } @@ -825,6 +926,38 @@ public Info withServerVersion(String 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 */ @@ -896,106 +1029,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Info info = (Info) o; - - return new EqualsBuilder() - .append(architecture, info.architecture) - .append(containers, info.containers) - .append(containersStopped, info.containersStopped) - .append(containersPaused, info.containersPaused) - .append(containersRunning, info.containersRunning) - .append(cpuCfsPeriod, info.cpuCfsPeriod) - .append(cpuCfsQuota, info.cpuCfsQuota) - .append(debug, info.debug) - .append(discoveryBackend, info.discoveryBackend) - .append(dockerRootDir, info.dockerRootDir) - .append(driver, info.driver) - .append(driverStatuses, info.driverStatuses) - .append(systemStatus, info.systemStatus) - .append(plugins, info.plugins) - .append(executionDriver, info.executionDriver) - .append(experimentalBuild, info.experimentalBuild) - .append(httpProxy, info.httpProxy) - .append(httpsProxy, info.httpsProxy) - .append(id, info.id) - .append(ipv4Forwarding, info.ipv4Forwarding) - .append(images, info.images) - .append(indexServerAddress, info.indexServerAddress) - .append(initPath, info.initPath) - .append(initSha1, info.initSha1) - .append(kernelVersion, info.kernelVersion) - .append(labels, info.labels) - .append(memoryLimit, info.memoryLimit) - .append(memTotal, info.memTotal) - .append(name, info.name) - .append(ncpu, info.ncpu) - .append(nEventListener, info.nEventListener) - .append(nfd, info.nfd) - .append(nGoroutines, info.nGoroutines) - .append(noProxy, info.noProxy) - .append(oomKillDisable, info.oomKillDisable) - .append(osType, info.osType) - .append(oomScoreAdj, info.oomScoreAdj) - .append(operatingSystem, info.operatingSystem) - .append(registryConfig, info.registryConfig) - .append(sockets, info.sockets) - .append(swapLimit, info.swapLimit) - .append(systemTime, info.systemTime) - .append(serverVersion, info.serverVersion) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(architecture) - .append(containers) - .append(containersStopped) - .append(containersPaused) - .append(containersRunning) - .append(cpuCfsPeriod) - .append(cpuCfsQuota) - .append(debug) - .append(discoveryBackend) - .append(dockerRootDir) - .append(driver) - .append(driverStatuses) - .append(systemStatus) - .append(plugins) - .append(executionDriver) - .append(experimentalBuild) - .append(httpProxy) - .append(httpsProxy) - .append(id) - .append(ipv4Forwarding) - .append(images) - .append(indexServerAddress) - .append(initPath) - .append(initSha1) - .append(kernelVersion) - .append(labels) - .append(memoryLimit) - .append(memTotal) - .append(name) - .append(ncpu) - .append(nEventListener) - .append(nfd) - .append(nGoroutines) - .append(noProxy) - .append(oomKillDisable) - .append(osType) - .append(oomScoreAdj) - .append(operatingSystem) - .append(registryConfig) - .append(sockets) - .append(swapLimit) - .append(systemTime) - .append(serverVersion) - .toHashCode(); + 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 index 384c1a04c..cc67994a5 100644 --- a/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java @@ -77,35 +77,17 @@ public InfoRegistryConfig withMirrors(Object mirrors) { @Override public String toString() { - return new ToStringBuilder(this) - .append("indexConfigs", indexConfigs) - .append("insecureRegistryCIDRs", insecureRegistryCIDRs) - .append("mirrors", mirrors) - .toString(); + return ToStringBuilder.reflectionToString(this); } @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - InfoRegistryConfig that = (InfoRegistryConfig) o; - - return new EqualsBuilder() - .append(indexConfigs, that.indexConfigs) - .append(insecureRegistryCIDRs, that.insecureRegistryCIDRs) - .append(mirrors, that.mirrors) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(indexConfigs) - .append(insecureRegistryCIDRs) - .append(mirrors) - .toHashCode(); + return HashCodeBuilder.reflectionHashCode(this); } /** @@ -191,38 +173,17 @@ public IndexConfig withSecure(Boolean secure) { @Override public String toString() { - return new ToStringBuilder(this) - .append("mirrors", mirrors) - .append("name", name) - .append("official", official) - .append("secure", secure) - .toString(); + return ToStringBuilder.reflectionToString(this); } @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - IndexConfig that = (IndexConfig) o; - - return new EqualsBuilder() - .append(mirrors, that.mirrors) - .append(name, that.name) - .append(official, that.official) - .append(secure, that.secure) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(mirrors) - .append(name) - .append(official) - .append(secure) - .toHashCode(); + return HashCodeBuilder.reflectionHashCode(this); } } } diff --git a/src/test/java/com/github/dockerjava/api/model/InfoTest.java b/src/test/java/com/github/dockerjava/api/model/InfoTest.java index 3bf6b0ec5..6d4c76471 100644 --- a/src/test/java/com/github/dockerjava/api/model/InfoTest.java +++ b/src/test/java/com/github/dockerjava/api/model/InfoTest.java @@ -7,12 +7,14 @@ import org.testng.annotations.Test; import java.io.IOException; -import java.util.Collections; +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; @@ -38,6 +40,18 @@ public void serder1Json() throws IOException { 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)); @@ -46,18 +60,20 @@ public void serder1Json() throws IOException { assertThat(info.getCpuCfsPeriod(), is(true)); // not available in this dump - assertThat(info.getCpuCfsQuota(), nullValue()); + 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(), hasEntry("Volume", Collections.singletonList("local"))); + assertThat(info.getPlugins(), equalTo(plugins)); + assertThat(info.getPlugins(), hasEntry("Volume", singletonList("local"))); assertThat(info.getPlugins(), hasEntry("Authorization", null)); assertThat(info.getExperimentalBuild(), is(false)); @@ -81,7 +97,76 @@ public void serder1Json() throws IOException { assertThat(indexConfigs, hasEntry("docker.io", indexConfig)); assertThat(registryConfig.getMirrors(), nullValue()); - assertThat(info.getSystemTime(), equalTo("2016-02-17T14:56:35.212841831Z")); - assertThat(info.getServerVersion(), equalTo("1.10.1")); + 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/test/serdes/JSONSamples.java b/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java index 99994eac8..1b5337aa6 100644 --- a/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java +++ b/src/test/java/com/github/dockerjava/test/serdes/JSONSamples.java @@ -11,6 +11,7 @@ import java.io.IOException; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotSame; /** * Samples helper @@ -58,6 +59,7 @@ public static TClass testRoundTrip(TClass item, JavaType 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; } From 5ca5e63db6991a0215918103e33f47df72e832ef Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 22:16:36 +0300 Subject: [PATCH 15/34] Switch to reflection methods. Easier fields detection. --- .../dockerjava/api/model/Container.java | 38 +------------- .../api/model/ContainerHostConfig.java | 20 ++----- .../api/model/ContainerNetwork.java | 52 ++----------------- .../api/model/ContainerNetworkSettings.java | 34 ++++++++++++ 4 files changed, 45 insertions(+), 99 deletions(-) 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 a92efd08c..47492920d 100644 --- a/src/main/java/com/github/dockerjava/api/model/Container.java +++ b/src/main/java/com/github/dockerjava/api/model/Container.java @@ -157,45 +157,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Container container = (Container) o; - - return new EqualsBuilder() - .append(command, container.command) - .append(created, container.created) - .append(id, container.id) - .append(image, container.image) - .append(imageId, container.imageId) - .append(names, container.names) - .append(ports, container.ports) - .append(labels, container.labels) - .append(status, container.status) - .append(sizeRw, container.sizeRw) - .append(sizeRootFs, container.sizeRootFs) - .append(hostConfig, container.hostConfig) - .append(networkSettings, container.networkSettings) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(command) - .append(created) - .append(id) - .append(image) - .append(imageId) - .append(names) - .append(ports) - .append(labels) - .append(status) - .append(sizeRw) - .append(sizeRootFs) - .append(hostConfig) - .append(networkSettings) - .toHashCode(); + 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 index 7ba797899..43a5a94b1 100644 --- a/src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/ContainerHostConfig.java @@ -7,6 +7,8 @@ import org.apache.commons.lang.builder.ToStringBuilder; /** + * Used in {@link Container} + * * @see Container * @author Kanstantsin Shautsou */ @@ -29,28 +31,16 @@ public ContainerHostConfig withNetworkMode(String networkMode) { @Override public String toString() { - return new ToStringBuilder(this) - .append("networkMode", networkMode) - .toString(); + return ToStringBuilder.reflectionToString(this); } @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - ContainerHostConfig that = (ContainerHostConfig) o; - - return new EqualsBuilder() - .append(networkMode, that.networkMode) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(networkMode) - .toHashCode(); + 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 index ece75e728..4bfde8bfd 100644 --- a/src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java +++ b/src/main/java/com/github/dockerjava/api/model/ContainerNetwork.java @@ -11,6 +11,7 @@ import java.util.List; /** + * @see ContainerNetworkSettings * @author Kanstantsin Shautsou */ @JsonIgnoreProperties(ignoreUnknown = true) @@ -257,61 +258,16 @@ public ContainerNetwork withNetworkID(String networkID) { @Override public String toString() { - return new ToStringBuilder(this) - .append("aliases", aliases) - .append("ipamConfig", ipamConfig) - .append("links", links) - .append("networkID", networkID) - .append("endpointId", endpointId) - .append("gateway", gateway) - .append("ipAddress", ipAddress) - .append("ipPrefixLen", ipPrefixLen) - .append("ipV6Gateway", ipV6Gateway) - .append("globalIPv6Address", globalIPv6Address) - .append("globalIPv6PrefixLen", globalIPv6PrefixLen) - .append("macAddress", macAddress) - .toString(); + return ToStringBuilder.reflectionToString(this); } @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - ContainerNetwork network = (ContainerNetwork) o; - - return new EqualsBuilder() - .append(ipamConfig, network.ipamConfig) - .append(links, network.links) - .append(aliases, network.aliases) - .append(networkID, network.networkID) - .append(endpointId, network.endpointId) - .append(gateway, network.gateway) - .append(ipAddress, network.ipAddress) - .append(ipPrefixLen, network.ipPrefixLen) - .append(ipV6Gateway, network.ipV6Gateway) - .append(globalIPv6Address, network.globalIPv6Address) - .append(globalIPv6PrefixLen, network.globalIPv6PrefixLen) - .append(macAddress, network.macAddress) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(ipamConfig) - .append(links) - .append(aliases) - .append(networkID) - .append(endpointId) - .append(gateway) - .append(ipAddress) - .append(ipPrefixLen) - .append(ipV6Gateway) - .append(globalIPv6Address) - .append(globalIPv6PrefixLen) - .append(macAddress) - .toHashCode(); + 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 index 970a1eb32..7f4b17be5 100644 --- a/src/main/java/com/github/dockerjava/api/model/ContainerNetworkSettings.java +++ b/src/main/java/com/github/dockerjava/api/model/ContainerNetworkSettings.java @@ -3,19 +3,53 @@ 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); + } } From 308707811880d68bef00f4c36f5b6b0a39bee665 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 22:36:10 +0300 Subject: [PATCH 16/34] Version.class to use reflection. --- .../github/dockerjava/api/model/Version.java | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) 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 c7cf6f68c..004c85f22 100644 --- a/src/main/java/com/github/dockerjava/api/model/Version.java +++ b/src/main/java/com/github/dockerjava/api/model/Version.java @@ -102,37 +102,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Version version1 = (Version) o; - - return new EqualsBuilder() - .append(apiVersion, version1.apiVersion) - .append(arch, version1.arch) - .append(gitCommit, version1.gitCommit) - .append(goVersion, version1.goVersion) - .append(kernelVersion, version1.kernelVersion) - .append(operatingSystem, version1.operatingSystem) - .append(version, version1.version) - .append(buildTime, version1.buildTime) - .append(experimental, version1.experimental) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(apiVersion) - .append(arch) - .append(gitCommit) - .append(goVersion) - .append(kernelVersion) - .append(operatingSystem) - .append(version) - .append(buildTime) - .append(experimental) - .toHashCode(); + return HashCodeBuilder.reflectionHashCode(this); } } From aaa5e4b34127a0fb597d54ad322b49898965ed57 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 22:36:23 +0300 Subject: [PATCH 17/34] Clean-up imports. --- .../java/com/github/dockerjava/api/model/ContainerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/github/dockerjava/api/model/ContainerTest.java b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java index 8b7277e99..a143e6c57 100644 --- a/src/test/java/com/github/dockerjava/api/model/ContainerTest.java +++ b/src/test/java/com/github/dockerjava/api/model/ContainerTest.java @@ -1,6 +1,5 @@ package com.github.dockerjava.api.model; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.CollectionType; import com.github.dockerjava.core.RemoteApiVersion; @@ -13,7 +12,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.core.IsNot.not; /** * @author Kanstantsin Shautsou From a39d5fc0d776c6579e654dad8d793ea54d7f1427 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 22:36:36 +0300 Subject: [PATCH 18/34] Version.class serder test --- .../dockerjava/api/model/VersionTest.java | 40 +++++++++++++++++++ .../resources/samples/1.22/version/1.json | 10 +++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/java/com/github/dockerjava/api/model/VersionTest.java create mode 100644 src/test/resources/samples/1.22/version/1.json 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/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" +} From 642c94f6ec7d95e603f963035c85389e28ce28e6 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 22:54:00 +0300 Subject: [PATCH 19/34] AuthConfig.class add serder tests. --- .../dockerjava/api/model/AuthConfigTest.java | 65 +++++++++++++++---- .../samples/1.22/other/AuthConfig/docs1.json | 5 ++ .../samples/1.22/other/AuthConfig/docs2.json | 3 + 3 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 src/test/resources/samples/1.22/other/AuthConfig/docs1.json create mode 100644 src/test/resources/samples/1.22/other/AuthConfig/docs2.json 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/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..." +} From 7a8513de65a8a88ebef0454e7a82938c05336279 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 22:57:46 +0300 Subject: [PATCH 20/34] ContainerPort.class to reflection. --- .../dockerjava/api/model/ContainerPort.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/github/dockerjava/api/model/ContainerPort.java b/src/main/java/com/github/dockerjava/api/model/ContainerPort.java index f3479d9ca..09f718ef6 100644 --- a/src/main/java/com/github/dockerjava/api/model/ContainerPort.java +++ b/src/main/java/com/github/dockerjava/api/model/ContainerPort.java @@ -9,8 +9,8 @@ import javax.annotation.CheckForNull; /** - * @see Container * @author Kanstantsin Shautsou + * @see Container */ @JsonIgnoreProperties(ignoreUnknown = true) public class ContainerPort { @@ -98,27 +98,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - ContainerPort port = (ContainerPort) o; - - return new EqualsBuilder() - .append(ip, port.ip) - .append(privatePort, port.privatePort) - .append(publicPort, port.publicPort) - .append(type, port.type) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(ip) - .append(privatePort) - .append(publicPort) - .append(type) - .toHashCode(); + return HashCodeBuilder.reflectionHashCode(this); } } From 051a0fa293ebbaf733fd86e49fbcf6e4f7e68e47 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sun, 21 Feb 2016 23:01:18 +0300 Subject: [PATCH 21/34] HostConfig.class to refleciton. --- .../dockerjava/api/model/HostConfig.java | 96 +------------------ 1 file changed, 2 insertions(+), 94 deletions(-) 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 495bdf9ce..e5d974c2d 100644 --- a/src/main/java/com/github/dockerjava/api/model/HostConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/HostConfig.java @@ -780,103 +780,11 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - HostConfig that = (HostConfig) o; - - return new EqualsBuilder() - .append(binds, that.binds) - .append(blkioWeight, that.blkioWeight) - .append(blkioWeightDevice, that.blkioWeightDevice) - .append(blkioDeviceReadBps, that.blkioDeviceReadBps) - .append(blkioDeviceReadIOps, that.blkioDeviceReadIOps) - .append(blkioDeviceWriteBps, that.blkioDeviceWriteBps) - .append(blkioDeviceWriteIOps, that.blkioDeviceWriteIOps) - .append(memorySwappiness, that.memorySwappiness) - .append(capAdd, that.capAdd) - .append(capDrop, that.capDrop) - .append(containerIDFile, that.containerIDFile) - .append(cpuPeriod, that.cpuPeriod) - .append(cpuShares, that.cpuShares) - .append(cpuQuota, that.cpuQuota) - .append(cpusetCpus, that.cpusetCpus) - .append(cpusetMems, that.cpusetMems) - .append(devices, that.devices) - .append(dns, that.dns) - .append(dnsSearch, that.dnsSearch) - .append(extraHosts, that.extraHosts) - .append(links, that.links) - .append(logConfig, that.logConfig) - .append(lxcConf, that.lxcConf) - .append(memory, that.memory) - .append(memorySwap, that.memorySwap) - .append(memoryReservation, that.memoryReservation) - .append(kernelMemory, that.kernelMemory) - .append(networkMode, that.networkMode) - .append(oomKillDisable, that.oomKillDisable) - .append(oomScoreAdj, that.oomScoreAdj) - .append(portBindings, that.portBindings) - .append(privileged, that.privileged) - .append(publishAllPorts, that.publishAllPorts) - .append(readonlyRootfs, that.readonlyRootfs) - .append(restartPolicy, that.restartPolicy) - .append(ulimits, that.ulimits) - .append(volumesFrom, that.volumesFrom) - .append(pidMode, that.pidMode) - .append(securityOpts, that.securityOpts) - .append(cgroupParent, that.cgroupParent) - .append(volumeDriver, that.volumeDriver) - .append(shmSize, that.shmSize) - .isEquals(); + return EqualsBuilder.reflectionEquals(this, o); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(binds) - .append(blkioWeight) - .append(blkioWeightDevice) - .append(blkioDeviceReadBps) - .append(blkioDeviceReadIOps) - .append(blkioDeviceWriteBps) - .append(blkioDeviceWriteIOps) - .append(memorySwappiness) - .append(capAdd) - .append(capDrop) - .append(containerIDFile) - .append(cpuPeriod) - .append(cpuShares) - .append(cpuQuota) - .append(cpusetCpus) - .append(cpusetMems) - .append(devices) - .append(dns) - .append(dnsSearch) - .append(extraHosts) - .append(links) - .append(logConfig) - .append(lxcConf) - .append(memory) - .append(memorySwap) - .append(memoryReservation) - .append(kernelMemory) - .append(networkMode) - .append(oomKillDisable) - .append(oomScoreAdj) - .append(portBindings) - .append(privileged) - .append(publishAllPorts) - .append(readonlyRootfs) - .append(restartPolicy) - .append(ulimits) - .append(volumesFrom) - .append(pidMode) - .append(securityOpts) - .append(cgroupParent) - .append(volumeDriver) - .append(shmSize) - .toHashCode(); + return HashCodeBuilder.reflectionHashCode(this); } } From 5e70093b3de13df6c69f3430e893fc330a1b6f7f Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 22 Feb 2016 17:52:05 +0300 Subject: [PATCH 22/34] Test for CreateContainer with stopSignal --- .../command/CreateContainerCmdImplTest.java | 171 ++++++++++++------ 1 file changed, 114 insertions(+), 57 deletions(-) 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..963952f49 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,59 @@ 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(); FIXME https://github.com/docker-java/docker-java/issues/476 + Thread.sleep(TimeUnit.SECONDS.toMillis(5)); + + 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); + } + } } From 35865baf6e56dee7bb7cd77eec0759248d463f48 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 22 Feb 2016 20:25:32 +0300 Subject: [PATCH 23/34] Implement UpdateContainerCmd with tests --- .../github/dockerjava/api/DockerClient.java | 10 + .../api/command/DockerCmdExecFactory.java | 2 + .../api/command/UpdateContainerCmd.java | 68 +++++ .../github/dockerjava/api/model/Update.java | 203 -------------- ...onse.java => UpdateContainerResponse.java} | 5 +- .../dockerjava/core/DockerClientImpl.java | 9 + .../core/command/UpdateContainerCmdImpl.java | 264 ++++++++++++++++++ .../jaxrs/DockerCmdExecFactoryImpl.java | 7 + .../jaxrs/UpdateContainerCmdExec.java | 36 +++ .../netty/DockerCmdExecFactoryImpl.java | 7 + .../netty/exec/UpdateContainerCmdExec.java | 34 +++ .../core/TestDockerCmdExecFactory.java | 5 + .../command/UpdateContainerCmdImplTest.java | 113 ++++++++ .../exec/UpdateContainerCmdExecTest.java | 97 +++++++ .../containers/container/update/docs.json | 12 + 15 files changed, 666 insertions(+), 206 deletions(-) create mode 100644 src/main/java/com/github/dockerjava/api/command/UpdateContainerCmd.java delete mode 100644 src/main/java/com/github/dockerjava/api/model/Update.java rename src/main/java/com/github/dockerjava/api/model/{UpdateResponse.java => UpdateContainerResponse.java} (86%) create mode 100644 src/main/java/com/github/dockerjava/core/command/UpdateContainerCmdImpl.java create mode 100644 src/main/java/com/github/dockerjava/jaxrs/UpdateContainerCmdExec.java create mode 100644 src/main/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExec.java create mode 100644 src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java create mode 100644 src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java create mode 100644 src/test/resources/samples/1.22/containers/container/update/docs.json 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/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/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/Update.java b/src/main/java/com/github/dockerjava/api/model/Update.java deleted file mode 100644 index c1b5355c7..000000000 --- a/src/main/java/com/github/dockerjava/api/model/Update.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.github.dockerjava.api.model; - -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; - -/** - * FIXME test case - * TODO add command - * @author Kanstantsin Shautsou - * @see - * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.22/ - * @since {@link RemoteApiVersion#VERSION_1_22} - */ -public class Update { - @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 Integer memory; - - @JsonProperty("MemorySwap") - private Integer memorySwap; - - @JsonProperty("MemoryReservation") - private Integer memoryReservation; - - @JsonProperty("KernelMemory") - private Integer kernelMemory; - - @CheckForNull - public Integer getBlkioWeight() { - return blkioWeight; - } - - public Update setBlkioWeight(Integer blkioWeight) { - this.blkioWeight = blkioWeight; - return this; - } - - @CheckForNull - public Integer getCpuPeriod() { - return cpuPeriod; - } - - public Update setCpuPeriod(Integer cpuPeriod) { - this.cpuPeriod = cpuPeriod; - return this; - } - - @CheckForNull - public Integer getCpuQuota() { - return cpuQuota; - } - - public Update setCpuQuota(Integer cpuQuota) { - this.cpuQuota = cpuQuota; - return this; - } - - @CheckForNull - public String getCpusetCpus() { - return cpusetCpus; - } - - public Update setCpusetCpus(String cpusetCpus) { - this.cpusetCpus = cpusetCpus; - return this; - } - - @CheckForNull - public String getCpusetMems() { - return cpusetMems; - } - - public Update setCpusetMems(String cpusetMems) { - this.cpusetMems = cpusetMems; - return this; - } - - @CheckForNull - public Integer getCpuShares() { - return cpuShares; - } - - public Update setCpuShares(Integer cpuShares) { - this.cpuShares = cpuShares; - return this; - } - - @CheckForNull - public Integer getKernelMemory() { - return kernelMemory; - } - - public Update setKernelMemory(Integer kernelMemory) { - this.kernelMemory = kernelMemory; - return this; - } - - @CheckForNull - public Integer getMemory() { - return memory; - } - - public Update setMemory(Integer memory) { - this.memory = memory; - return this; - } - - @CheckForNull - public Integer getMemoryReservation() { - return memoryReservation; - } - - public Update setMemoryReservation(Integer memoryReservation) { - this.memoryReservation = memoryReservation; - return this; - } - - @CheckForNull - public Integer getMemorySwap() { - return memorySwap; - } - - public Update setMemorySwap(Integer memorySwap) { - this.memorySwap = memorySwap; - return this; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("blkioWeight", blkioWeight) - .append("cpuShares", cpuShares) - .append("cpuPeriod", cpuPeriod) - .append("cpuQuota", cpuQuota) - .append("cpusetCpus", cpusetCpus) - .append("cpusetMems", cpusetMems) - .append("memory", memory) - .append("memorySwap", memorySwap) - .append("memoryReservation", memoryReservation) - .append("kernelMemory", kernelMemory) - .toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Update update = (Update) o; - - return new EqualsBuilder() - .append(blkioWeight, update.blkioWeight) - .append(cpuShares, update.cpuShares) - .append(cpuPeriod, update.cpuPeriod) - .append(cpuQuota, update.cpuQuota) - .append(cpusetCpus, update.cpusetCpus) - .append(cpusetMems, update.cpusetMems) - .append(memory, update.memory) - .append(memorySwap, update.memorySwap) - .append(memoryReservation, update.memoryReservation) - .append(kernelMemory, update.kernelMemory) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(blkioWeight) - .append(cpuShares) - .append(cpuPeriod) - .append(cpuQuota) - .append(cpusetCpus) - .append(cpusetMems) - .append(memory) - .append(memorySwap) - .append(memoryReservation) - .append(kernelMemory) - .toHashCode(); - } -} diff --git a/src/main/java/com/github/dockerjava/api/model/UpdateResponse.java b/src/main/java/com/github/dockerjava/api/model/UpdateContainerResponse.java similarity index 86% rename from src/main/java/com/github/dockerjava/api/model/UpdateResponse.java rename to src/main/java/com/github/dockerjava/api/model/UpdateContainerResponse.java index e6b1305eb..b1b1188d0 100644 --- a/src/main/java/com/github/dockerjava/api/model/UpdateResponse.java +++ b/src/main/java/com/github/dockerjava/api/model/UpdateContainerResponse.java @@ -8,15 +8,14 @@ import java.util.List; /** - * TODO update command - * * @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 UpdateResponse extends ResponseItem { +public class UpdateContainerResponse extends ResponseItem { private static final long serialVersionUID = 1L; @JsonProperty("Warnings") 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/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/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/UpdateContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java new file mode 100644 index 000000000..f432a1bf8 --- /dev/null +++ b/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java @@ -0,0 +1,113 @@ +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 + */ +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/netty/exec/UpdateContainerCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java new file mode 100644 index 000000000..db0a8fc64 --- /dev/null +++ b/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java @@ -0,0 +1,97 @@ +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 + */ +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(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)); + } + +} 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 +} From 6482e77b055123ae578813ba975cb1af3ae508ee Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 22 Feb 2016 20:31:05 +0300 Subject: [PATCH 24/34] Update devel doc. --- docs/devel.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/devel.adoc b/docs/devel.adoc index e3f3640d6..50c6a7279 100644 --- a/docs/devel.adoc +++ b/docs/devel.adoc @@ -21,3 +21,5 @@ ### 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. From 97baacd9d65c5875add2daf4d11c776990f96bf7 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Mon, 22 Feb 2016 22:43:09 +0300 Subject: [PATCH 25/34] Fix junit errors? --- .../com/github/dockerjava/api/model/IdentifierTest.java | 9 +++++++-- .../core/command/UpdateContainerCmdImplTest.java | 1 + .../core/dockerfile/DockerfileStatementAddTest.java | 5 ++--- .../netty/exec/UpdateContainerCmdExecTest.java | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) 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/core/command/UpdateContainerCmdImplTest.java b/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java index f432a1bf8..76708f889 100644 --- a/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/UpdateContainerCmdImplTest.java @@ -28,6 +28,7 @@ /** * @author Kanstantsin Shautsou */ +@Test(groups = "integration") public class UpdateContainerCmdImplTest extends AbstractDockerClientTest { public static final String BUSYBOX_IMAGE = "busybox"; 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/UpdateContainerCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java index db0a8fc64..94c8242e5 100644 --- a/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java +++ b/src/test/java/com/github/dockerjava/netty/exec/UpdateContainerCmdExecTest.java @@ -25,6 +25,7 @@ /** * @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"; @@ -49,7 +50,7 @@ public void afterMethod(ITestResult result) { super.afterMethod(result); } - @Test(groups = "ignoreInCircleCi") + @Test public void updateContainer() throws DockerException, IOException { CreateContainerResponse response = dockerClient.createContainerCmd(BUSYBOX_IMAGE) .withCmd("sleep", "9999") From 284d145228947998296c87d35eeb22b29aa1e375 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Fri, 26 Feb 2016 20:36:16 +0300 Subject: [PATCH 26/34] Update maven surefire --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 14778ebde..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 From 2f3aa8b4e263c55345e45843324a5ecdcbddcc8f Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Fri, 26 Feb 2016 20:36:40 +0300 Subject: [PATCH 27/34] Fix and update test. --- .../api/command/InspectExecResponse.java | 44 +++++++++++++++ .../api/command/InspectExecResponseTest.java | 56 +++++++++++++++++++ .../netty/exec/InspectExecCmdExecTest.java | 14 ++++- .../resources/samples/1.22/exec/ID/1.json | 18 ++++++ 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/github/dockerjava/api/command/InspectExecResponseTest.java create mode 100644 src/test/resources/samples/1.22/exec/ID/1.json 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..1dabf399d 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,6 +28,12 @@ public class InspectExecResponse { @JsonProperty("Running") private Boolean running; + /** + * @since {@link RemoteApiVersion#VERSION_1_22} + */ + @JsonProperty("CanRemove") + private Boolean canRemove; + @JsonProperty("ExitCode") private Integer exitCode; @@ -35,6 +43,18 @@ public class InspectExecResponse { @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; } @@ -67,6 +87,30 @@ 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/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/netty/exec/InspectExecCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java index ecf5ed568..6e5c6d349 100644 --- a/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java +++ b/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyString; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; import java.io.IOException; import java.lang.reflect.Method; @@ -114,8 +115,15 @@ 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())); + + // 1.22 doesn't return it + // TODO conditional it against docker connection somehow +// assertNotNull(inspectExecResponse.getContainer().getNetworkSettings().getNetworks().get("bridge")); } } 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": "" +} From 71d5ecb0a3549bd9a6f54aaa1132aa27a9695aea Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Fri, 26 Feb 2016 23:30:12 +0300 Subject: [PATCH 28/34] Fix jaxrs test --- .../core/command/InspectExecCmdImplTest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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..d877800b3 100644 --- a/src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/InspectExecCmdImplTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.isEmptyString; import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; import java.io.IOException; import java.lang.reflect.Method; @@ -112,8 +113,15 @@ 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())); + + // 1.22 doesn't return it + // TODO conditional it against docker connection somehow +// assertNotNull(inspectExecResponse.getContainer().getNetworkSettings().getNetworks().get("bridge")); } } From 7631991caa980295897d7272583e18c605818e2d Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sat, 27 Feb 2016 01:28:58 +0300 Subject: [PATCH 29/34] Add helper for api version extraction --- .../com/github/dockerjava/utils/TestUtils.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/java/com/github/dockerjava/utils/TestUtils.java 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); + } +} From 0e9ba9387565d9352c19804c3dc259cded0ec860 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sat, 27 Feb 2016 01:29:25 +0300 Subject: [PATCH 30/34] Deprecate container field --- .../api/command/InspectExecResponse.java | 8 ++++++++ .../core/command/InspectExecCmdImplTest.java | 16 +++++++++++++--- .../netty/exec/InspectExecCmdExecTest.java | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) 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 1dabf399d..2833a5ade 100644 --- a/src/main/java/com/github/dockerjava/api/command/InspectExecResponse.java +++ b/src/main/java/com/github/dockerjava/api/command/InspectExecResponse.java @@ -40,6 +40,10 @@ public class InspectExecResponse { @JsonProperty("ProcessConfig") private ProcessConfig processConfig; + /** + * @deprecated @since {@link RemoteApiVersion#VERSION_1_22} + */ + @Deprecated @JsonProperty("Container") private Container container; @@ -83,6 +87,10 @@ public ProcessConfig getProcessConfig() { return processConfig; } + /** + * @see #container + */ + @Deprecated public Container getContainer() { return container; } 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 d877800b3..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,15 +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; @@ -98,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") @@ -120,8 +126,12 @@ public void inspectExecNetworkSettings() throws IOException { assertThat(inspectExecResponse.getCanRemove(), is(false)); assertThat(inspectExecResponse.getContainerID(), is(container.getId())); - // 1.22 doesn't return it - // TODO conditional it against docker connection somehow -// assertNotNull(inspectExecResponse.getContainer().getNetworkSettings().getNetworks().get("bridge")); + 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/InspectExecCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/InspectExecCmdExecTest.java index 6e5c6d349..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,15 +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; @@ -100,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") @@ -122,8 +127,12 @@ public void inspectExecNetworkSettings() throws IOException { assertThat(inspectExecResponse.getCanRemove(), is(false)); assertThat(inspectExecResponse.getContainerID(), is(container.getId())); - // 1.22 doesn't return it - // TODO conditional it against docker connection somehow -// assertNotNull(inspectExecResponse.getContainer().getNetworkSettings().getNetworks().get("bridge")); + 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")); + } } } From 3e79e88f31313f7707aa309df79669b2342b3266 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sat, 27 Feb 2016 01:30:44 +0300 Subject: [PATCH 31/34] Do test conditional. Value set according to response. --- .../core/command/StopContainerCmdImplTest.java | 12 +++++++++++- .../netty/exec/StopContainerCmdExecTest.java | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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/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 From 5336f8c62093172e90e2e2b8dbd7f88a6b532d23 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Sat, 27 Feb 2016 02:11:40 +0300 Subject: [PATCH 32/34] Fix sync test to be async. --- .../core/command/FrameReaderITest.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 { From 2ec5fb32ca08bfdc4997850440190cdde3298159 Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Tue, 1 Mar 2016 01:24:08 +0300 Subject: [PATCH 33/34] Fix NegativeArraySizeException in awaitCompletion() Signed-off-by: Kanstantsin Shautsou --- .../com/github/dockerjava/core/command/FrameReader.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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]; From 01f14686f30e19269df1da98c1bfe4c150146dad Mon Sep 17 00:00:00 2001 From: Kanstantsin Shautsou Date: Tue, 1 Mar 2016 01:32:25 +0300 Subject: [PATCH 34/34] Cleanup test code after fix. --- .../dockerjava/core/command/CreateContainerCmdImplTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 963952f49..7800a8c12 100644 --- a/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java +++ b/src/test/java/com/github/dockerjava/core/command/CreateContainerCmdImplTest.java @@ -597,9 +597,8 @@ public void testWithStopSignal() throws Exception { .withStdErr(true) .withStdOut(true) .withTailAll() - .exec(callback); -// .awaitCompletion(); FIXME https://github.com/docker-java/docker-java/issues/476 - Thread.sleep(TimeUnit.SECONDS.toMillis(5)); + .exec(callback) + .awaitCompletion(); String log = callback.builder.toString(); assertThat(log, is("exit trapped 10"));