[JCLOUDS-1118] fix configuration options location; mark some fields Nullable

This commit is contained in:
Josef Cacek 2016-05-24 14:51:45 +02:00 committed by Ignasi Barrera
parent d4cf774389
commit c0469cc9b7
13 changed files with 712 additions and 132 deletions

View File

@ -23,6 +23,7 @@ import static org.jclouds.docker.internal.NullSafeCopies.copyWithNullOf;
import java.util.List;
import java.util.Map;
import org.jclouds.docker.domain.HostConfig.Builder;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
@ -76,30 +77,6 @@ public abstract class Config {
@Nullable public abstract HostConfig hostConfig();
@Nullable public abstract List<String> binds();
@Nullable public abstract List<String> links();
public abstract List<Map<String, String>> lxcConf();
public abstract Map<String, List<Map<String, String>>> portBindings();
public abstract boolean publishAllPorts();
public abstract boolean privileged();
@Nullable public abstract List<String> dns();
@Nullable public abstract List<String> dnsSearch();
@Nullable public abstract List<String> volumesFrom();
@Nullable public abstract List<String> capAdd();
@Nullable public abstract List<String> capDrop();
public abstract Map<String, String> restartPolicy();
Config() {
}
@ -107,24 +84,17 @@ public abstract class Config {
{
"Hostname", "Domainname", "User", "Memory", "MemorySwap", "CpuShares", "AttachStdin", "AttachStdout",
"AttachStderr", "Tty", "OpenStdin", "StdinOnce", "Env", "Cmd", "Entrypoint", "Image", "Volumes",
"WorkingDir", "NetworkDisabled", "ExposedPorts", "SecurityOpts", "HostConfig", "Binds", "Links",
"LxcConf", "PortBindings", "PublishAllPorts", "Privileged", "Dns", "DnsSearch", "VolumesFrom",
"CapAdd", "CapDrop", "RestartPolicy"
"WorkingDir", "NetworkDisabled", "ExposedPorts", "SecurityOpts", "HostConfig"
})
public static Config create(String hostname, String domainname, String user, int memory, int memorySwap,
int cpuShares, boolean attachStdin, boolean attachStdout, boolean attachStderr, boolean tty,
boolean openStdin, boolean stdinOnce, List<String> env, List<String> cmd, List<String> entrypoint,
String image, Map<String, ?> volumes, String workingDir, boolean networkDisabled,
Map<String, ?> exposedPorts, List<String> securityOpts, HostConfig hostConfig, List<String> binds,
List<String> links, List<Map<String, String>> lxcConf, Map<String, List<Map<String, String>>> portBindings,
boolean publishAllPorts, boolean privileged, List<String> dns, List<String> dnsSearch, List<String> volumesFrom,
List<String> capAdd, List<String> capDrop, Map<String, String> restartPolicy) {
Map<String, ?> exposedPorts, List<String> securityOpts, HostConfig hostConfig) {
return new AutoValue_Config(hostname, domainname, user, memory, memorySwap, cpuShares, attachStdin,
attachStdout, attachStderr, tty, openStdin, stdinOnce, copyWithNullOf(env), copyWithNullOf(cmd),
copyWithNullOf(entrypoint), image, copyWithNullOf(volumes), workingDir, networkDisabled,
copyOf(exposedPorts), copyOf(securityOpts), hostConfig,
copyWithNullOf(binds), copyWithNullOf(links), copyOf(lxcConf), copyOf(portBindings), publishAllPorts, privileged,
copyWithNullOf(dns), copyWithNullOf(dnsSearch), copyWithNullOf(volumesFrom), copyWithNullOf(capAdd), copyWithNullOf(capDrop), copyOf(restartPolicy));
copyOf(exposedPorts), copyOf(securityOpts), hostConfig);
}
public static Builder builder() {
@ -158,18 +128,6 @@ public abstract class Config {
private Map<String, ?> exposedPorts = Maps.newHashMap();
private List<String> securityOpts = Lists.newArrayList();
private HostConfig hostConfig;
private List<String> binds;
private List<String> links;
private List<Map<String, String>> lxcConf = Lists.newArrayList();
private Map<String, List<Map<String, String>>> portBindings = Maps.newHashMap();
private boolean publishAllPorts;
private boolean privileged;
private List<String> dns;
private List<String> dnsSearch;
private List<String> volumesFrom;
private List<String> capAdd;
private List<String> capDrop;
private Map<String, String> restartPolicy = Maps.newHashMap();
public Builder hostname(String hostname) {
this.hostname = hostname;
@ -287,71 +245,10 @@ public abstract class Config {
return this;
}
public Builder binds(List<String> binds) {
this.binds = binds;
return this;
}
public Builder links(List<String> links) {
this.links = links;
return this;
}
public Builder lxcConf(List<Map<String, String>> lxcConf) {
this.lxcConf = lxcConf;
return this;
}
public Builder portBindings(Map<String, List<Map<String, String>>> portBindings) {
this.portBindings = portBindings;
return this;
}
public Builder publishAllPorts(boolean publishAllPorts) {
this.publishAllPorts = publishAllPorts;
return this;
}
public Builder privileged(boolean privileged) {
this.privileged = privileged;
return this;
}
public Builder dns(List<String> dns) {
this.dns = dns;
return this;
}
public Builder dnsSearch(List<String> dnsSearch) {
this.dnsSearch = dnsSearch;
return this;
}
public Builder volumesFrom(List<String> volumesFrom) {
this.volumesFrom = volumesFrom;
return this;
}
public Builder capAdd(List<String> capAdd) {
this.capAdd = capAdd;
return this;
}
public Builder capDrop(List<String> capDrop) {
this.capDrop = capDrop;
return this;
}
public Builder restartPolicy(Map<String, String> restartPolicy) {
this.restartPolicy = restartPolicy;
return this;
}
public Config build() {
return Config.create(hostname, domainname, user, memory, memorySwap, cpuShares, attachStdin, attachStdout,
attachStderr, tty, openStdin, stdinOnce, env, cmd, entrypoint, image, volumes, workingDir,
networkDisabled, exposedPorts, securityOpts, hostConfig, binds, links, lxcConf, portBindings,
publishAllPorts, privileged, dns, dnsSearch, volumesFrom, capAdd, capDrop, restartPolicy);
networkDisabled, exposedPorts, securityOpts, hostConfig);
}
public Builder fromConfig(Config in) {
@ -360,11 +257,8 @@ public abstract class Config {
.attachStdout(in.attachStdout()).attachStderr(in.attachStderr()).tty(in.tty())
.openStdin(in.openStdin()).stdinOnce(in.stdinOnce()).env(in.env()).cmd(in.cmd())
.entrypoint(in.entrypoint()).image(in.image()).volumes(in.volumes()).workingDir(in.workingDir())
.networkDisabled(in.networkDisabled()).exposedPorts(in.exposedPorts()).securityOpts(in.securityOpts())
.hostConfig(in.hostConfig()).binds(in.binds()).links(in.links()).lxcConf(in.lxcConf())
.portBindings(in.portBindings()).publishAllPorts(in.publishAllPorts()).privileged(in.privileged())
.dns(in.dns()).dnsSearch(in.dnsSearch()).volumesFrom(in.volumesFrom()).capAdd(in.capAdd())
.capDrop(in.capDrop()).restartPolicy(in.restartPolicy());
.networkDisabled(in.networkDisabled()).exposedPorts(in.exposedPorts())
.securityOpts(in.securityOpts()).hostConfig(in.hostConfig());
}
}

View File

@ -55,16 +55,29 @@ public abstract class HostConfig {
@Nullable public abstract String networkMode();
@Nullable public abstract List<String> securityOpt();
@Nullable public abstract List<String> capAdd();
@Nullable public abstract List<String> capDrop();
public abstract Map<String, String> restartPolicy();
HostConfig() {
}
@SerializedNames({ "ContainerIDFile", "Binds", "LxcConf", "Privileged", "Dns", "DnsSearch", "PortBindings",
"Links", "ExtraHosts", "PublishAllPorts", "VolumesFrom", "NetworkMode" })
"Links", "ExtraHosts", "PublishAllPorts", "VolumesFrom", "NetworkMode", "SecurityOpt",
"CapAdd", "CapDrop", "RestartPolicy" })
public static HostConfig create(String containerIDFile, List<String> binds, List<Map<String, String>> lxcConf,
boolean privileged, List<String> dns, List<String> dnsSearch, Map<String, List<Map<String, String>>> portBindings,
List<String> links, List<String> extraHosts, boolean publishAllPorts, List<String> volumesFrom, String networkMode) {
List<String> links, List<String> extraHosts, boolean publishAllPorts, List<String> volumesFrom, String networkMode,
List<String> securityOpt, List<String> capAdd, List<String> capDrop, Map<String, String> restartPolicy) {
return new AutoValue_HostConfig(containerIDFile, copyWithNullOf(binds), copyOf(lxcConf), privileged, copyWithNullOf(dns), copyWithNullOf(dnsSearch),
copyOf(portBindings), copyWithNullOf(links), copyWithNullOf(extraHosts), publishAllPorts, copyWithNullOf(volumesFrom), networkMode);
copyOf(portBindings), copyWithNullOf(links), copyWithNullOf(extraHosts), publishAllPorts, copyWithNullOf(volumesFrom), networkMode,
copyOf(securityOpt), copyWithNullOf(capAdd), copyWithNullOf(capDrop), copyOf(restartPolicy));
}
public static Builder builder() {
@ -89,7 +102,11 @@ public abstract class HostConfig {
private boolean publishAllPorts;
private List<String> volumesFrom;
private String networkMode;
private List<String> securityOpt = Lists.newArrayList();
private List<String> capAdd;
private List<String> capDrop;
private Map<String, String> restartPolicy = Maps.newHashMap();
public Builder containerIDFile(String containerIDFile) {
this.containerIDFile = containerIDFile;
return this;
@ -150,16 +167,37 @@ public abstract class HostConfig {
return this;
}
public Builder securityOpt(List<String> securityOpt) {
this.securityOpt = securityOpt;
return this;
}
public Builder capAdd(List<String> capAdd) {
this.capAdd = capAdd;
return this;
}
public Builder capDrop(List<String> capDrop) {
this.capDrop = capDrop;
return this;
}
public Builder restartPolicy(Map<String, String> restartPolicy) {
this.restartPolicy = restartPolicy;
return this;
}
public HostConfig build() {
return HostConfig.create(containerIDFile, binds, lxcConf, privileged, dns, dnsSearch, portBindings, links,
extraHosts, publishAllPorts, volumesFrom, networkMode);
extraHosts, publishAllPorts, volumesFrom, networkMode, securityOpt, capAdd, capDrop, restartPolicy);
}
public Builder fromHostConfig(HostConfig in) {
return this.containerIDFile(in.containerIDFile()).binds(in.binds()).lxcConf(in.lxcConf())
.privileged(in.privileged()).dns(in.dns()).dnsSearch(in.dnsSearch()).links(in.links())
.extraHosts(in.extraHosts()).portBindings(in.portBindings()).publishAllPorts(in.publishAllPorts())
.volumesFrom(in.volumesFrom()).networkMode(in.networkMode());
.volumesFrom(in.volumesFrom()).networkMode(in.networkMode()).securityOpt(in.securityOpt())
.capAdd(in.capAdd()).capDrop(in.capDrop()).restartPolicy(in.restartPolicy());
}
}
}

View File

@ -42,9 +42,9 @@ public abstract class Info {
public abstract String indexServerAddress();
public abstract String initPath();
@Nullable public abstract String initPath();
public abstract String initSha1();
@Nullable public abstract String initSha1();
public abstract String kernelVersion();

View File

@ -16,16 +16,16 @@
*/
package org.jclouds.docker.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.docker.internal.NullSafeCopies.copyOf;
import java.util.List;
import java.util.Map;
import org.jclouds.docker.internal.NullSafeCopies;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
@ -135,7 +135,7 @@ public abstract class NetworkSettings {
private String gateway;
private String bridge;
private String portMapping;
private Map<String, List<Map<String, String>>> ports = ImmutableMap.of();
private Map<String, List<Map<String, String>>> ports;
private String sandboxId;
private boolean hairpinMode;
private String linkLocalIPv6Address;
@ -176,7 +176,7 @@ public abstract class NetworkSettings {
}
public Builder ports(Map<String, List<Map<String, String>>> ports) {
this.ports = ImmutableMap.copyOf(checkNotNull(ports, "ports"));
this.ports = NullSafeCopies.copyWithNullOf(ports);
return this;
}

View File

@ -58,8 +58,5 @@ public class ConfigTest {
assertThat(config.domainname()).isNull();
assertThat(config.workingDir()).isNull();
assertThat(config.hostConfig()).isNull();
assertThat(config.dns()).isNull();
assertThat(config.dnsSearch()).isNull();
assertThat(config.volumesFrom()).isNull();
}
}

View File

@ -85,7 +85,10 @@ public class ContainerApiLiveTest extends BaseDockerApiLiveTest {
}
@Test(dependsOnMethods = "testStartContainer")
public void testAttachContainer() {
public void testAttachContainer() throws InterruptedException {
// wait 2 seconds - give a container chance to echo the string
Thread.sleep(2000L);
InputStream attachStream = api().attach(container.id(), AttachOptions.Builder.logs(true).stream(false).stdout(true));
String stream = consumeStream(attachStream);
assertThat(stream.trim()).contains("hello world");

View File

@ -111,10 +111,13 @@ public class ContainerParseTest extends BaseDockerParseTest<Container> {
"6783/tcp", ImmutableList.<Map<String, String>>of(ImmutableMap.of("HostIp", "", "HostPort", "6783")),
"6783/udp", ImmutableList.<Map<String, String>>of(ImmutableMap.of("HostIp", "", "HostPort", "6783")))
)
.capAdd(ImmutableList.of("NET_ADMIN"))
.capDrop(ImmutableList.of("MKNOD"))
.dns(ImmutableList.of("8.8.8.8", "8.8.4.4"))
.extraHosts(ImmutableList.<String>of("extra:169.254.0.1"))
.privileged(true)
.networkMode("bridge")
.restartPolicy(ImmutableMap.<String, String> of("MaximumRetryCount", "0", "Name", ""))
.build())
.driver("aufs")
.execDriver("native-0.2")

View File

@ -0,0 +1,263 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.docker.parse;
import java.util.List;
import java.util.Map;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.docker.domain.Config;
import org.jclouds.docker.domain.Container;
import org.jclouds.docker.domain.HostConfig;
import org.jclouds.docker.domain.NetworkSettings;
import org.jclouds.docker.domain.State;
import org.jclouds.docker.internal.BaseDockerParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
/**
* This class tests Containers and Config parsing for Docker API in version 1.21. The input JSON comes from examples in
* <a href="https://docs.docker.com/engine/reference/api/docker_remote_api_v1.21/">Docker Remote API documentation 1.21</a>.
* <p>
* Two modifications were made in the "/container-1.21-create.json" due to incompatible types
* <ul>
* <li>the Entrypoint field value was changed from String to List<li>
* <li>the LxcConf field value was changed from Map to List</li>
* <ul>
*/
public class ContainerVersionMajor1Minor21 {
@Test(groups = "unit")
public static class CreateTest extends BaseDockerParseTest<Config> {
@Override
public String resource() {
return "/container-1.21-create.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Config expected() {
return Config.builder()
.hostname("")
.domainname("")
.user("")
.attachStdin(false)
.attachStdout(true)
.attachStderr(true)
.tty(false)
.openStdin(false)
.stdinOnce(false)
.env(ImmutableList.of("FOO=bar", "BAZ=quux"))
.cmd(ImmutableList.of("date"))
//original value of the "Entrypoint" in JSON doesn't contain List but String!
//Both types are allowed by docker Remote API, but we are not able to parse both.
.entrypoint(ImmutableList.of(""))
.image("ubuntu")
// "Labels": {
// "com.example.vendor": "Acme",
// "com.example.license": "GPL",
// "com.example.version": "1.0"
// },
.volumes(ImmutableMap.of("/volumes/data", ImmutableMap.of()))
.workingDir("")
.networkDisabled(false)
// "MacAddress": "12:34:56:78:9a:bc",
.exposedPorts(ImmutableMap.of("22/tcp", ImmutableMap.of()))
// "StopSignal": "SIGTERM",
.hostConfig(HostConfig.builder()
.binds(ImmutableList.of("/tmp:/tmp"))
.links(ImmutableList.of("redis3:redis"))
//The LxcConf causes the type mismatch too (Map vs List<Map>)
.lxcConf(ImmutableList.<Map<String, String>> of(
ImmutableMap.<String, String> of("lxc.utsname", "docker")))
// "Memory": 0,
// "MemorySwap": 0,
// "MemoryReservation": 0,
// "KernelMemory": 0,
// "CpuShares": 512,
// "CpuPeriod": 100000,
// "CpuQuota": 50000,
// "CpusetCpus": "0,1",
// "CpusetMems": "0,1",
// "BlkioWeight": 300,
// "MemorySwappiness": 60,
// "OomKillDisable": false,
.portBindings(ImmutableMap.<String, List<Map<String, String>>> of(
"22/tcp", ImmutableList.<Map<String, String>> of(ImmutableMap.of("HostPort", "11022"))))
.publishAllPorts(false)
.privileged(false)
// "ReadonlyRootfs": false,
.dns(ImmutableList.of("8.8.8.8"))
// "DnsOptions": [""],
.dnsSearch(ImmutableList.of(""))
.extraHosts(null)
.volumesFrom(ImmutableList.of("parent", "other:ro"))
.capAdd(ImmutableList.of("NET_ADMIN"))
.capDrop(ImmutableList.of("MKNOD"))
// "GroupAdd": ["newgroup"],
.restartPolicy(ImmutableMap.of("Name", "", "MaximumRetryCount", "0"))
.networkMode("bridge")
// "Devices": [],
// "Ulimits": [{}],
// "LogConfig": { "Type": "json-file", "Config": {} },
.securityOpt(ImmutableList.<String>of())
// "CgroupParent": "",
// "VolumeDriver": ""
.build()
)
.build();
}
}
@Test(groups = "unit")
public static class InspectTest extends BaseDockerParseTest<Container> {
@Override
public String resource() {
return "/container-1.21-inspect.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Container expected() {
return Container.builder()
// "AppArmorProfile": "",
.args(ImmutableList.<String>of("-c", "exit 9"))
.config(Config.builder()
.attachStderr(true)
.attachStdin(false)
.attachStdout(true)
.cmd(ImmutableList.<String> of("/bin/sh", "-c", "exit 9"))
.domainname("")
.entrypoint(null)
.env(ImmutableList.<String> of("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"))
.exposedPorts(null)
.hostname("ba033ac44011")
.image("ubuntu")
// "Labels": {
// "com.example.vendor": "Acme",
// "com.example.license": "GPL",
// "com.example.version": "1.0"
// },
// "MacAddress": "",
.networkDisabled(false)
// "OnBuild": null,
.openStdin(false)
.stdinOnce(false)
.tty(false)
.user("")
.volumes(null)
.workingDir("")
// "StopSignal": "SIGTERM"
.build())
.created(new SimpleDateFormatDateService().iso8601DateParse("2015-01-06T15:47:31.485331387Z"))
.driver("devicemapper")
.execDriver("native-0.2")
// "ExecIDs": null,
.hostConfig(HostConfig.builder()
.binds(null)
// "BlkioWeight": 0,
.capAdd(null)
.capDrop(null)
.containerIDFile("")
// "CpusetCpus": "",
// "CpusetMems": "",
// "CpuShares": 0,
// "CpuPeriod": 100000,
// "Devices": [],
.dns(null)
// "DnsOptions": null,
.dnsSearch(null)
.extraHosts(null)
// "IpcMode": "",
.links(null)
.lxcConf(ImmutableList.<Map<String, String>> of())
// "Memory": 0,
// "MemorySwap": 0,
// "MemoryReservation": 0,
// "KernelMemory": 0,
// "OomKillDisable": false,
.networkMode("bridge")
.portBindings(ImmutableMap.<String, List<Map<String, String>>> of())
.privileged(false)
// "ReadonlyRootfs": false,
.publishAllPorts(false)
.restartPolicy(ImmutableMap.<String, String> of("MaximumRetryCount", "2", "Name", "on-failure"))
// "LogConfig": {
// "Config": null,
// "Type": "json-file"
// },
.securityOpt(null)
.volumesFrom(null)
// "Ulimits": [{}],
// "VolumeDriver": ""
.build())
.hostnamePath("/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname")
.hostsPath("/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts")
// "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log",
.id("ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39")
.image("04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2")
.mountLabel("")
.name("/boring_euclid")
.networkSettings(NetworkSettings.builder()
.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(ImmutableMap.<String, NetworkSettings.Details> of(
"bridge", NetworkSettings.Details.create("", "", "", 0, "", "", 0, "")))
.build())
.path("/bin/sh")
.processLabel("")
.resolvConfPath("/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf")
// "RestartCount": 1,
.state(State.create(0, true, 9, "2015-01-06T15:47:32.072697474Z", "2015-01-06T15:47:32.080254511Z", false, false, "running", false,
// We don't have the "Dead" field in this API version!
false,
""
// "Paused": false,
// "Running": true,
))
// "Mounts": [
// {
// "Source": "/data",
// "Destination": "/data",
// "Mode": "ro,Z",
// "RW": false
// }
.build();
}
}
}

View File

@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.docker.parse;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.docker.domain.Info;
import org.jclouds.docker.internal.BaseDockerParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class Info2ParseTest extends BaseDockerParseTest<Info> {
@Override
public String resource() {
return "/info2.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public Info expected() {
return Info.create(
0, // containers
false, // debug
"aufs", // driver
ImmutableList.<List<String>>of(
ImmutableList.of("Root Dir", "/var/lib/docker/aufs"),
ImmutableList.of("Backing Filesystem", "extfs"),
ImmutableList.of("Dirs", "117"),
ImmutableList.of( "Dirperm1 Supported", "true")
), // driverStatus
"", // ExecutionDriver
true, // IPv4Forwarding
39, // Images
"https://index.docker.io/v1/", // IndexServerAddress
null, // InitPath
null, // InitSha1
"4.4.0-22-generic", // KernelVersion
true, // MemoryLimit
0, // NEventsListener
33, // NFd
83, // NGoroutines
"Ubuntu 16.04 LTS", // OperatingSystem
false, // SwapLimit
"/var/lib/docker", // DockerRootDir
null, // Labels
8248356864L, // MemTotal
4, // NCPU
"KFWR:PMVY:BEWE:TD52:5WEU:NXF4:I6S3:WDIE:GCRD:L3YA:VWC4:ZRYZ", // ID
"test" // name
);
}
}

View File

@ -0,0 +1,72 @@
{
"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"
},
"Volumes": {
"/volumes/data": {}
},
"WorkingDir": "",
"NetworkDisabled": false,
"MacAddress": "12:34:56:78:9a:bc",
"ExposedPorts": {
"22/tcp": {}
},
"StopSignal": "SIGTERM",
"HostConfig": {
"Binds": ["/tmp:/tmp"],
"Links": ["redis3:redis"],
"LxcConf": [{"lxc.utsname":"docker"}],
"Memory": 0,
"MemorySwap": 0,
"MemoryReservation": 0,
"KernelMemory": 0,
"CpuShares": 512,
"CpuPeriod": 100000,
"CpuQuota": 50000,
"CpusetCpus": "0,1",
"CpusetMems": "0,1",
"BlkioWeight": 300,
"MemorySwappiness": 60,
"OomKillDisable": false,
"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": ""
}
}

View File

@ -0,0 +1,147 @@
{
"AppArmorProfile": "",
"Args": [
"-c",
"exit 9"
],
"Config": {
"AttachStderr": true,
"AttachStdin": false,
"AttachStdout": true,
"Cmd": [
"/bin/sh",
"-c",
"exit 9"
],
"Domainname": "",
"Entrypoint": null,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"ExposedPorts": null,
"Hostname": "ba033ac44011",
"Image": "ubuntu",
"Labels": {
"com.example.vendor": "Acme",
"com.example.license": "GPL",
"com.example.version": "1.0"
},
"MacAddress": "",
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": false,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": null,
"WorkingDir": "",
"StopSignal": "SIGTERM"
},
"Created": "2015-01-06T15:47:31.485331387Z",
"Driver": "devicemapper",
"ExecDriver": "native-0.2",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"BlkioWeight": 0,
"CapAdd": null,
"CapDrop": null,
"ContainerIDFile": "",
"CpusetCpus": "",
"CpusetMems": "",
"CpuShares": 0,
"CpuPeriod": 100000,
"Devices": [],
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"IpcMode": "",
"Links": null,
"LxcConf": [],
"Memory": 0,
"MemorySwap": 0,
"MemoryReservation": 0,
"KernelMemory": 0,
"OomKillDisable": false,
"NetworkMode": "bridge",
"PortBindings": {},
"Privileged": false,
"ReadonlyRootfs": false,
"PublishAllPorts": false,
"RestartPolicy": {
"MaximumRetryCount": 2,
"Name": "on-failure"
},
"LogConfig": {
"Config": null,
"Type": "json-file"
},
"SecurityOpt": null,
"VolumesFrom": null,
"Ulimits": [{}],
"VolumeDriver": ""
},
"HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname",
"HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts",
"LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log",
"Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39",
"Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2",
"MountLabel": "",
"Name": "/boring_euclid",
"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": {
"EndpointID": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": ""
}
}
},
"Path": "/bin/sh",
"ProcessLabel": "",
"ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf",
"RestartCount": 1,
"State": {
"Error": "",
"ExitCode": 9,
"FinishedAt": "2015-01-06T15:47:32.080254511Z",
"OOMKilled": false,
"Paused": false,
"Pid": 0,
"Restarting": false,
"Running": true,
"StartedAt": "2015-01-06T15:47:32.072697474Z",
"Status": "running"
},
"Mounts": [
{
"Source": "/data",
"Destination": "/data",
"Mode": "ro,Z",
"RW": false
}
]
}

View File

@ -40,7 +40,7 @@
"OnBuild": null,
"OpenStdin": false,
"PortSpecs": null,
"SecurityOpt": null,
"SecurityOpts": null,
"StdinOnce": false,
"Tty": false,
"User": "",
@ -52,8 +52,8 @@
"ExecDriver": "native-0.2",
"HostConfig": {
"Binds": null,
"CapAdd": null,
"CapDrop": null,
"CapAdd": ["NET_ADMIN"],
"CapDrop": ["MKNOD"],
"ContainerIDFile": "",
"Devices": [],
"Dns": [
@ -137,6 +137,7 @@
"Path": "/home/weave/weaver",
"ProcessLabel": "",
"ResolvConfPath": "/var/lib/docker/containers/6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524/resolv.conf",
"SecurityOpt": [],
"State": {
"Status": "running",
"Running": true,

View File

@ -0,0 +1,90 @@
{
"Architecture": "x86_64",
"BridgeNfIp6tables": true,
"BridgeNfIptables": true,
"CPUSet": true,
"CPUShares": true,
"CgroupDriver": "cgroupfs",
"ClusterAdvertise": "",
"ClusterStore": "",
"Containers": 0,
"ContainersPaused": 0,
"ContainersRunning": 0,
"ContainersStopped": 0,
"CpuCfsPeriod": true,
"CpuCfsQuota": true,
"Debug": false,
"DockerRootDir": "/var/lib/docker",
"Driver": "aufs",
"DriverStatus": [
[
"Root Dir",
"/var/lib/docker/aufs"
],
[
"Backing Filesystem",
"extfs"
],
[
"Dirs",
"117"
],
[
"Dirperm1 Supported",
"true"
]
],
"ExecutionDriver": "",
"ExperimentalBuild": false,
"HttpProxy": "",
"HttpsProxy": "",
"ID": "KFWR:PMVY:BEWE:TD52:5WEU:NXF4:I6S3:WDIE:GCRD:L3YA:VWC4:ZRYZ",
"IPv4Forwarding": true,
"Images": 39,
"IndexServerAddress": "https://index.docker.io/v1/",
"KernelMemory": true,
"KernelVersion": "4.4.0-22-generic",
"Labels": null,
"LoggingDriver": "json-file",
"MemTotal": 8248356864,
"MemoryLimit": true,
"NCPU": 4,
"NEventsListener": 0,
"NFd": 33,
"NGoroutines": 83,
"Name": "test",
"NoProxy": "",
"OSType": "linux",
"OomKillDisable": true,
"OperatingSystem": "Ubuntu 16.04 LTS",
"Plugins": {
"Authorization": null,
"Network": [
"bridge",
"null",
"host"
],
"Volume": [
"local"
]
},
"RegistryConfig": {
"IndexConfigs": {
"docker.io": {
"Mirrors": null,
"Name": "docker.io",
"Official": true,
"Secure": true
}
},
"InsecureRegistryCIDRs": [
"0.0.0.0/0",
"127.0.0.0/8"
],
"Mirrors": null
},
"ServerVersion": "1.11.1",
"SwapLimit": false,
"SystemStatus": null,
"SystemTime": "2016-05-24T15:20:15.407969411+02:00"
}