From 865b20e8d9f3ef281bdafb9a0492fffb66b6e2f2 Mon Sep 17 00:00:00 2001 From: Hendrik Haddorp Date: Tue, 22 Mar 2016 21:34:01 +0100 Subject: [PATCH 1/2] fix for issue 507 --- .../api/model/InfoRegistryConfig.java | 6 +- .../github/dockerjava/api/model/InfoTest.java | 158 +++++++++++++++++ src/test/resources/samples/1.22/info/2.json | 165 ++++++++++++++++++ 3 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/samples/1.22/info/2.json 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 cc67994a5..956aaebe3 100644 --- a/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java +++ b/src/main/java/com/github/dockerjava/api/model/InfoRegistryConfig.java @@ -96,7 +96,7 @@ public int hashCode() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class IndexConfig { @JsonProperty("Mirrors") - private String mirrors; + private List mirrors; @JsonProperty("Name") private String name; @@ -111,14 +111,14 @@ public static final class IndexConfig { * @see #mirrors */ @CheckForNull - public String getMirrors() { + public List getMirrors() { return mirrors; } /** * @see #mirrors */ - public IndexConfig withMirrors(String mirrors) { + public IndexConfig withMirrors(List mirrors) { this.mirrors = mirrors; return 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 6d4c76471..806870ae6 100644 --- a/src/test/java/com/github/dockerjava/api/model/InfoTest.java +++ b/src/test/java/com/github/dockerjava/api/model/InfoTest.java @@ -7,6 +7,7 @@ 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; @@ -169,4 +170,161 @@ public void serder1Json() throws IOException { assertThat(info, is(withInfo)); } + + @Test + public void serder2Json() throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JavaType type = mapper.getTypeFactory().constructType(Info.class); + + final Info info = testRoundTrip(VERSION_1_22, + "info/2.json", + type + ); + + final List> driverStatus = asList( + asList("Pool Name", "docker-253:2-17567992-pool"), + asList("Pool Blocksize", "65.54 kB"), + asList("Base Device Size", "107.4 GB"), + asList("Backing Filesystem", "ext4"), + asList("Data file", "/dev/loop0"), + asList("Metadata file", "/dev/loop1"), + asList("Data Space Used", "3.89 GB"), + asList("Data Space Total", "107.4 GB"), + asList("Data Space Available", "103.5 GB"), + asList("Metadata Space Used", "5.46 MB"), + asList("Metadata Space Total", "2.147 GB"), + asList("Metadata Space Available", "2.142 GB"), + asList("Udev Sync Supported", "true"), + asList("Deferred Removal Enabled", "false"), + asList("Deferred Deletion Enabled", "false"), + asList("Deferred Deleted Device Count", "0"), + asList("Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"), + asList("Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"), + asList("Library Version", "1.02.107-RHEL7 (2015-12-01)") + ); + + final Map> plugins = new LinkedHashMap<>(); + plugins.put("Volume", singletonList("local")); + plugins.put("Network", asList("null", "host", "bridge")); + plugins.put("Authorization", null); + + assertThat(info, notNullValue()); + assertThat(info.getArchitecture(), equalTo("x86_64")); + assertThat(info.getContainersStopped(), is(2)); + assertThat(info.getContainersPaused(), is(0)); + assertThat(info.getContainersRunning(), is(0)); + assertThat(info.getCpuCfsPeriod(), is(true)); + + // not available in this dump + assertThat(info.getCpuCfsQuota(), is(true)); + assertThat(info.getDiscoveryBackend(), nullValue()); + assertThat(info.getOomScoreAdj(), nullValue()); + + assertThat(info.getDriverStatuses(), notNullValue()); + assertThat(info.getDriverStatuses(), hasSize(19)); + assertThat(info.getDriverStatuses(), equalTo(driverStatus)); + + assertThat(info.getNGoroutines(), is(30)); + + assertThat(info.getSystemStatus(), CoreMatchers.nullValue()); + + assertThat(info.getPlugins(), equalTo(plugins)); + assertThat(info.getPlugins(), hasEntry("Volume", singletonList("local"))); + assertThat(info.getPlugins(), hasEntry("Authorization", null)); + + assertThat(info.getExperimentalBuild(), is(false)); + + assertThat(info.getHttpProxy(), isEmptyString()); + assertThat(info.getHttpsProxy(), isEmptyString()); + assertThat(info.getNoProxy(), isEmptyString()); + assertThat(info.getOomKillDisable(), is(true)); + assertThat(info.getOsType(), equalTo("linux")); + + final InfoRegistryConfig registryConfig = info.getRegistryConfig(); + assertThat(registryConfig, notNullValue()); + final List cidRs = registryConfig.getInsecureRegistryCIDRs(); + assertThat(cidRs, notNullValue()); + assertThat(cidRs, contains("127.0.0.0/8")); + + final Map indexConfigs = registryConfig.getIndexConfigs(); + assertThat(indexConfigs, notNullValue()); + final IndexConfig indexConfig = new IndexConfig().withMirrors(null).withName("docker.io") + .withSecure(true).withOfficial(true); + assertThat(indexConfigs, hasEntry("docker.io", indexConfig)); + final IndexConfig indexConfig2 = new IndexConfig().withMirrors(Collections.emptyList()).withName("somehost:80") + .withSecure(false).withOfficial(false); + assertThat(indexConfigs, hasEntry("somehost:80", indexConfig2)); + assertThat(registryConfig.getMirrors(), nullValue()); + + assertThat(info.getSystemTime(), is("2016-03-20T17:32:06.598846244+01:00")); + assertThat(info.getServerVersion(), is("1.10.2")); + + assertThat(info.getCpuSet(), is(true)); + assertThat(info.getCpuShares(), is(true)); + assertThat(info.getIPv4Forwarding(), is(true)); + assertThat(info.getBridgeNfIptables(), is(false)); + assertThat(info.getBridgeNfIp6tables(), is(false)); + assertThat(info.getDebug(), is(false)); + assertThat(info.getNFd(), is(13)); + assertThat(info.getOomKillDisable(), is(true)); + assertThat(info.getLoggingDriver(), is("json-file")); + assertThat(info.getOperatingSystem(), is("Red Hat Enterprise Linux Workstation 7.2 (Maipo)")); + assertThat(info.getClusterStore(), is("")); + + + final Info withInfo = new Info().withArchitecture("x86_64") + .withContainers(2) + .withContainersRunning(0) + .withContainersPaused(0) + .withContainersStopped(2) + .withImages(55) + .withId("H52J:52LG:YP4W:EHKY:SRK5:RYG6:ETWR:7AR3:MTFJ:PC6C:4YF2:NTN2") + .withDriver("devicemapper") + .withDriverStatuses(driverStatus) + .withSystemStatus(null) + .withPlugins(plugins) + .withMemoryLimit(true) + .withSwapLimit(true) + .withCpuCfsPeriod(true) + .withCpuCfsQuota(true) + .withCpuShares(true) + .withCpuSet(true) + .withIPv4Forwarding(true) + .withBridgeNfIptables(false) + .withBridgeNfIp6tables(false) + .withDebug(false) + .withNFd(13) + .withOomKillDisable(true) + .withNGoroutines(30) + .withSystemTime("2016-03-20T17:32:06.598846244+01:00") + .withExecutionDriver("native-0.2") + .withLoggingDriver("json-file") + .withNEventsListener(0) + .withKernelVersion("3.10.0-327.10.1.el7.x86_64") + .withOperatingSystem("Red Hat Enterprise Linux Workstation 7.2 (Maipo)") + .withOsType("linux") + .withIndexServerAddress("https://index.docker.io/v1/") + .withRegistryConfig(registryConfig) + .withInitSha1("672d65f3cf8816fbda421afeed7e52c0ca17d5e7") + .withInitPath("/usr/libexec/docker/dockerinit") + .withNCPU(8) + .withMemTotal(33350918144L) + .withDockerRootDir("/var/lib/docker") + .withHttpProxy("") + .withHttpsProxy("") + .withNoProxy("") + .withName("somename") + .withLabels(null) + .withExperimentalBuild(false) + .withServerVersion("1.10.2") + .withClusterStore("") + .withClusterAdvertise("") + //shredinger-fields + .withDiscoveryBackend(null) + .withOomScoreAdj(null) + .withSockets(null) + ; + + assertThat(info, is(withInfo)); + } } diff --git a/src/test/resources/samples/1.22/info/2.json b/src/test/resources/samples/1.22/info/2.json new file mode 100644 index 000000000..c30dca325 --- /dev/null +++ b/src/test/resources/samples/1.22/info/2.json @@ -0,0 +1,165 @@ +{ + "ID":"H52J:52LG:YP4W:EHKY:SRK5:RYG6:ETWR:7AR3:MTFJ:PC6C:4YF2:NTN2", + "Containers":2, + "ContainersRunning":0, + "ContainersPaused":0, + "ContainersStopped":2, + "Images":55, + "Driver":"devicemapper", + "DriverStatus":[ + [ + "Pool Name", + "docker-253:2-17567992-pool" + ], + [ + "Pool Blocksize", + "65.54 kB" + ], + [ + "Base Device Size", + "107.4 GB" + ], + [ + "Backing Filesystem", + "ext4" + ], + [ + "Data file", + "/dev/loop0" + ], + [ + "Metadata file", + "/dev/loop1" + ], + [ + "Data Space Used", + "3.89 GB" + ], + [ + "Data Space Total", + "107.4 GB" + ], + [ + "Data Space Available", + "103.5 GB" + ], + [ + "Metadata Space Used", + "5.46 MB" + ], + [ + "Metadata Space Total", + "2.147 GB" + ], + [ + "Metadata Space Available", + "2.142 GB" + ], + [ + "Udev Sync Supported", + "true" + ], + [ + "Deferred Removal Enabled", + "false" + ], + [ + "Deferred Deletion Enabled", + "false" + ], + [ + "Deferred Deleted Device Count", + "0" + ], + [ + "Data loop file", + "/var/lib/docker/devicemapper/devicemapper/data" + ], + [ + "Metadata loop file", + "/var/lib/docker/devicemapper/devicemapper/metadata" + ], + [ + "Library Version", + "1.02.107-RHEL7 (2015-12-01)" + ] + ], + "SystemStatus":null, + "Plugins":{ + "Volume":[ + "local" + ], + "Network":[ + "null", + "host", + "bridge" + ], + "Authorization":null + }, + "MemoryLimit":true, + "SwapLimit":true, + "CpuCfsPeriod":true, + "CpuCfsQuota":true, + "CPUShares":true, + "CPUSet":true, + "IPv4Forwarding":true, + "BridgeNfIptables":false, + "BridgeNfIp6tables":false, + "Debug":false, + "NFd":13, + "OomKillDisable":true, + "NGoroutines":30, + "SystemTime":"2016-03-20T17:32:06.598846244+01:00", + "ExecutionDriver":"native-0.2", + "LoggingDriver":"json-file", + "NEventsListener":0, + "KernelVersion":"3.10.0-327.10.1.el7.x86_64", + "PkgVersion":"docker-1.10.2-6.git0f5ac89.el7.x86_64", + "OperatingSystem":"Red Hat Enterprise Linux Workstation 7.2 (Maipo)", + "OSType":"linux", + "Architecture":"x86_64", + "IndexServerAddress":"https://index.docker.io/v1/", + "IndexServerName":"docker.io", + "RegistryConfig":{ + "InsecureRegistryCIDRs":[ + "127.0.0.0/8" + ], + "IndexConfigs":{ + "docker.io":{ + "Name":"docker.io", + "Mirrors":null, + "Secure":true, + "Official":true + }, + "somehost:80":{ + "Name":"somehost:80", + "Mirrors":[ + + ], + "Secure":false, + "Official":false + } + }, + "Mirrors":null + }, + "InitSha1":"672d65f3cf8816fbda421afeed7e52c0ca17d5e7", + "InitPath":"/usr/libexec/docker/dockerinit", + "NCPU":8, + "MemTotal":33350918144, + "DockerRootDir":"/var/lib/docker", + "HttpProxy":"", + "HttpsProxy":"", + "NoProxy":"", + "Name":"somename", + "Labels":null, + "ExperimentalBuild":false, + "ServerVersion":"1.10.2", + "ClusterStore":"", + "ClusterAdvertise":"", + "Registries":[ + { + "Name":"docker.io", + "Secure":true + } + ] +} From f822c64def58607209bdee45a00acd0555dce0db Mon Sep 17 00:00:00 2001 From: Hendrik Haddorp Date: Tue, 22 Mar 2016 21:41:19 +0100 Subject: [PATCH 2/2] fix for issue 508 --- .../com/github/dockerjava/core/util/CertificateUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/dockerjava/core/util/CertificateUtils.java b/src/main/java/com/github/dockerjava/core/util/CertificateUtils.java index 65e6544f1..562a954a7 100644 --- a/src/main/java/com/github/dockerjava/core/util/CertificateUtils.java +++ b/src/main/java/com/github/dockerjava/core/util/CertificateUtils.java @@ -32,12 +32,13 @@ private CertificateUtils() { public static boolean verifyCertificatesExist(String dockerCertPath) { String[] files = {"ca.pem", "cert.pem", "key.pem"}; + boolean result = true; for (String file : files) { File path = new File(dockerCertPath, file); - return path.exists(); + result &= path.exists(); } - return true; + return result; } public static KeyStore createKeyStore(final String dockerCertPath) throws NoSuchAlgorithmException,