From a824ba69179608b8b5ed82f22a4602a8041c7aa0 Mon Sep 17 00:00:00 2001 From: unstablemark Date: Sun, 18 Nov 2018 14:03:40 -0200 Subject: [PATCH 1/4] New volumes classes and test. --- .../com/amihaiemil/docker/ListedVolumes.java | 45 ++++++++++++++ .../java/com/amihaiemil/docker/RtDocker.java | 7 ++- .../java/com/amihaiemil/docker/RtVolumes.java | 61 +++++++++++++++++++ .../java/com/amihaiemil/docker/Volume.java | 35 +++++++++++ .../java/com/amihaiemil/docker/Volumes.java | 2 + .../docker/LocalDockerTestCase.java | 13 ++++ .../docker/RemoteDockerTestCase.java | 14 +++++ 7 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/amihaiemil/docker/ListedVolumes.java create mode 100644 src/main/java/com/amihaiemil/docker/RtVolumes.java create mode 100644 src/main/java/com/amihaiemil/docker/Volume.java diff --git a/src/main/java/com/amihaiemil/docker/ListedVolumes.java b/src/main/java/com/amihaiemil/docker/ListedVolumes.java new file mode 100644 index 00000000..512a63fe --- /dev/null +++ b/src/main/java/com/amihaiemil/docker/ListedVolumes.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2018, Mihai Emil Andronache + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1)Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2)Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3)Neither the name of docker-java-api nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.amihaiemil.docker; + +import org.apache.http.client.HttpClient; + +import java.net.URI; + +public class ListedVolumes extends RtVolumes { + + /** + * Ctor. + * + * @param client The http client. + * @param uri The URI for this Images API. + * @param dkr The docker entry point. + * @checkstyle ParameterNumber (10 lines) + */ + ListedVolumes(HttpClient client, URI uri, Docker dkr) { + super(client, uri, dkr); + } +} diff --git a/src/main/java/com/amihaiemil/docker/RtDocker.java b/src/main/java/com/amihaiemil/docker/RtDocker.java index 2484f3c8..eeb40d72 100644 --- a/src/main/java/com/amihaiemil/docker/RtDocker.java +++ b/src/main/java/com/amihaiemil/docker/RtDocker.java @@ -96,9 +96,10 @@ public final Networks networks() { @Override public final Volumes volumes() { - throw new UnsupportedOperationException( - "Volumes API is not yet implemented. If you can contribute please," - + " do it here: https://www.github.com/amihaiemil/docker-java-api" + return new ListedVolumes( + this.client, + URI.create(this.baseUri.toString() + "/volumes"), + this ); } diff --git a/src/main/java/com/amihaiemil/docker/RtVolumes.java b/src/main/java/com/amihaiemil/docker/RtVolumes.java new file mode 100644 index 00000000..f6c5319c --- /dev/null +++ b/src/main/java/com/amihaiemil/docker/RtVolumes.java @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2018, Mihai Emil Andronache + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1)Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2)Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3)Neither the name of docker-java-api nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.amihaiemil.docker; + +import org.apache.http.client.HttpClient; + +import java.net.URI; + +public abstract class RtVolumes implements Volumes { + /** + * Apache HttpClient which sends the requests. + */ + private final HttpClient client; + + /** + * Base URI for Images API. + */ + private final URI baseUri; + + /** + * Docker API. + */ + private final Docker docker; + + /** + * Ctor. + * @param client The http client. + * @param uri The URI for this Images API. + * @param dkr The docker entry point. + * @checkstyle ParameterNumber (10 lines) + */ + + RtVolumes(final HttpClient client, final URI uri, final Docker dkr) { + this.client = client; + this.baseUri = uri; + this.docker = dkr; + } +} diff --git a/src/main/java/com/amihaiemil/docker/Volume.java b/src/main/java/com/amihaiemil/docker/Volume.java new file mode 100644 index 00000000..1404144a --- /dev/null +++ b/src/main/java/com/amihaiemil/docker/Volume.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2018, Mihai Emil Andronache + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1)Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2)Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3)Neither the name of docker-java-api nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package com.amihaiemil.docker; + +/** + * Volume API. + * @author Marco Teixeira (marcoo.teixeira@gmail.com) + * @version $Id$ + * @since 0.0.1 + */ +public interface Volume { +} diff --git a/src/main/java/com/amihaiemil/docker/Volumes.java b/src/main/java/com/amihaiemil/docker/Volumes.java index 258ceff4..909a4b9e 100644 --- a/src/main/java/com/amihaiemil/docker/Volumes.java +++ b/src/main/java/com/amihaiemil/docker/Volumes.java @@ -30,6 +30,8 @@ * @author Mihai Andronache (amihaiemil@gmail.com) * @version $Id$ * @since 0.0.1 + * @todo #169:30min Extend Iterable of Volumes to and continue implementing the rest of the operations + * for the volume. */ public interface Volumes { } diff --git a/src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java b/src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java index f9782445..d6c0ec02 100644 --- a/src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java +++ b/src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java @@ -142,4 +142,17 @@ public void returnsHttpClient() { ) ); } + + /** + * LocalDocker can return Volumes. + */ + @Test + public void returnsVolumes() { + MatcherAssert.assertThat( + new LocalDocker( + new File("/var/run/docker.sock") + ).volumes(), + Matchers.notNullValue() + ); + } } diff --git a/src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java b/src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java index 59a6521a..49c1627b 100644 --- a/src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java +++ b/src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java @@ -140,4 +140,18 @@ public void returnsHttpClient() { ) ); } + + /** + * RemoteDocker can return Volumes. + */ + @Test + public void returnsVolumes() { + MatcherAssert.assertThat( + new RemoteDocker( + Mockito.mock(HttpClient.class), + URI.create("http://localhost") + ).volumes(), + Matchers.notNullValue() + ); + } } From e94211da525ca8604dda94636b05af0e8ea6722e Mon Sep 17 00:00:00 2001 From: unstablemark Date: Sun, 18 Nov 2018 14:16:37 -0200 Subject: [PATCH 2/4] Fixing checkstyle. --- .../java/com/amihaiemil/docker/ListedVolumes.java | 15 ++++++++++----- .../java/com/amihaiemil/docker/RtVolumes.java | 6 ++++++ src/main/java/com/amihaiemil/docker/Volumes.java | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/amihaiemil/docker/ListedVolumes.java b/src/main/java/com/amihaiemil/docker/ListedVolumes.java index 512a63fe..a48bbd28 100644 --- a/src/main/java/com/amihaiemil/docker/ListedVolumes.java +++ b/src/main/java/com/amihaiemil/docker/ListedVolumes.java @@ -29,17 +29,22 @@ import java.net.URI; +/** + * Listed volumes. + * @author Marco Teixeira (marcoo.teixeira@gmail.com) + * @version $Id$ + * @since 0.0.6 + */ public class ListedVolumes extends RtVolumes { /** * Ctor. - * * @param client The http client. - * @param uri The URI for this Images API. - * @param dkr The docker entry point. - * @checkstyle ParameterNumber (10 lines) + * @param uri The URI for this Images API. + * @param dkr The docker entry point. + * @checkstyle ParameterNumber (2 lines) */ - ListedVolumes(HttpClient client, URI uri, Docker dkr) { + ListedVolumes(final HttpClient client, final URI uri, final Docker dkr) { super(client, uri, dkr); } } diff --git a/src/main/java/com/amihaiemil/docker/RtVolumes.java b/src/main/java/com/amihaiemil/docker/RtVolumes.java index f6c5319c..b643a09b 100644 --- a/src/main/java/com/amihaiemil/docker/RtVolumes.java +++ b/src/main/java/com/amihaiemil/docker/RtVolumes.java @@ -29,6 +29,12 @@ import java.net.URI; +/** + * Runtime {@link Volumes}. + * @author Marco Teixeira (marcoo.teixeira@gmail.com) + * @version $Id$ + * @since 0.0.6 + */ public abstract class RtVolumes implements Volumes { /** * Apache HttpClient which sends the requests. diff --git a/src/main/java/com/amihaiemil/docker/Volumes.java b/src/main/java/com/amihaiemil/docker/Volumes.java index 909a4b9e..e0c37a62 100644 --- a/src/main/java/com/amihaiemil/docker/Volumes.java +++ b/src/main/java/com/amihaiemil/docker/Volumes.java @@ -30,8 +30,8 @@ * @author Mihai Andronache (amihaiemil@gmail.com) * @version $Id$ * @since 0.0.1 - * @todo #169:30min Extend Iterable of Volumes to and continue implementing the rest of the operations - * for the volume. + * @todo #169:30min Extend Iterable of Volumes to and + * continue implementing the rest of the operations for the volume. */ public interface Volumes { } From bff49ef5dccd0413ba1b3ea2750c09868900571f Mon Sep 17 00:00:00 2001 From: unstablemark Date: Mon, 19 Nov 2018 09:23:46 -0200 Subject: [PATCH 3/4] Fixing code by PR. --- src/main/java/com/amihaiemil/docker/RtVolumes.java | 2 -- src/main/java/com/amihaiemil/docker/Volume.java | 7 +++++-- src/main/java/com/amihaiemil/docker/Volumes.java | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/amihaiemil/docker/RtVolumes.java b/src/main/java/com/amihaiemil/docker/RtVolumes.java index b643a09b..2aa869c2 100644 --- a/src/main/java/com/amihaiemil/docker/RtVolumes.java +++ b/src/main/java/com/amihaiemil/docker/RtVolumes.java @@ -56,9 +56,7 @@ public abstract class RtVolumes implements Volumes { * @param client The http client. * @param uri The URI for this Images API. * @param dkr The docker entry point. - * @checkstyle ParameterNumber (10 lines) */ - RtVolumes(final HttpClient client, final URI uri, final Docker dkr) { this.client = client; this.baseUri = uri; diff --git a/src/main/java/com/amihaiemil/docker/Volume.java b/src/main/java/com/amihaiemil/docker/Volume.java index 1404144a..cc747473 100644 --- a/src/main/java/com/amihaiemil/docker/Volume.java +++ b/src/main/java/com/amihaiemil/docker/Volume.java @@ -26,10 +26,13 @@ package com.amihaiemil.docker; /** - * Volume API. + * A volume manager. * @author Marco Teixeira (marcoo.teixeira@gmail.com) * @version $Id$ - * @since 0.0.1 + * @see Docker Volume API + * @since 0.0.6 + * @todo #169:30min Continue the implementation of Volume. + * */ public interface Volume { } diff --git a/src/main/java/com/amihaiemil/docker/Volumes.java b/src/main/java/com/amihaiemil/docker/Volumes.java index e0c37a62..8db330f8 100644 --- a/src/main/java/com/amihaiemil/docker/Volumes.java +++ b/src/main/java/com/amihaiemil/docker/Volumes.java @@ -30,8 +30,8 @@ * @author Mihai Andronache (amihaiemil@gmail.com) * @version $Id$ * @since 0.0.1 - * @todo #169:30min Extend Iterable of Volumes to and - * continue implementing the rest of the operations for the volume. + * @todo #169:30min Extend Iterable of Volumes to + * continue implementing the rest of the operations for the volume. */ public interface Volumes { } From f2b7c203dcd213923b095b276cc9f62ae5a25928 Mon Sep 17 00:00:00 2001 From: unstablemark Date: Mon, 19 Nov 2018 09:35:09 -0200 Subject: [PATCH 4/4] Fixing code issues. --- src/main/java/com/amihaiemil/docker/ListedVolumes.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/amihaiemil/docker/ListedVolumes.java b/src/main/java/com/amihaiemil/docker/ListedVolumes.java index a48bbd28..fe9ef446 100644 --- a/src/main/java/com/amihaiemil/docker/ListedVolumes.java +++ b/src/main/java/com/amihaiemil/docker/ListedVolumes.java @@ -42,7 +42,6 @@ public class ListedVolumes extends RtVolumes { * @param client The http client. * @param uri The URI for this Images API. * @param dkr The docker entry point. - * @checkstyle ParameterNumber (2 lines) */ ListedVolumes(final HttpClient client, final URI uri, final Docker dkr) { super(client, uri, dkr);