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..fe9ef446 --- /dev/null +++ b/src/main/java/com/amihaiemil/docker/ListedVolumes.java @@ -0,0 +1,49 @@ +/** + * 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; + +/** + * 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. + */ + ListedVolumes(final HttpClient client, final URI uri, final 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..2aa869c2 --- /dev/null +++ b/src/main/java/com/amihaiemil/docker/RtVolumes.java @@ -0,0 +1,65 @@ +/** + * 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; + +/** + * 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. + */ + 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. + */ + 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..cc747473 --- /dev/null +++ b/src/main/java/com/amihaiemil/docker/Volume.java @@ -0,0 +1,38 @@ +/** + * 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; + +/** + * A volume manager. + * @author Marco Teixeira (marcoo.teixeira@gmail.com) + * @version $Id$ + * @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 258ceff4..8db330f8 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 + * 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() + ); + } }