Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/main/java/com/amihaiemil/docker/ListedVolumes.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
7 changes: 4 additions & 3 deletions src/main/java/com/amihaiemil/docker/RtDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
65 changes: 65 additions & 0 deletions src/main/java/com/amihaiemil/docker/RtVolumes.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/amihaiemil/docker/Volume.java
Original file line number Diff line number Diff line change
@@ -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 <a href="https://docs.docker.com/engine/api/v1.35/#tag/Volume">Docker Volume API</a>
* @since 0.0.6
* @todo #169:30min Continue the implementation of Volume.
*
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unstablemark looks like we need another puzzle here for implementing Volume?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the added puzzle (it's new for me), let me know if I need to change something.

public interface Volume {
}
2 changes: 2 additions & 0 deletions src/main/java/com/amihaiemil/docker/Volumes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
13 changes: 13 additions & 0 deletions src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
14 changes: 14 additions & 0 deletions src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}