Skip to content

Commit

Permalink
#168 implemented Docker.execs()
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Apr 16, 2020
1 parent d97e08a commit 564cd5f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 17 deletions.
16 changes: 15 additions & 1 deletion src/main/java/com/amihaiemil/docker/Execs.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,19 @@
* @version $Id$
* @since 0.0.12
*/
public interface Execs extends Iterable<Exec> {
public interface Execs {

/**
* Get the Exec with the specified ID.
* @param execId The ID of the searched Exec.
* @return Exec.
*/
Exec get(final String execId);

/**
* Return the Docker engine where these Execs came from.
* @return Docker.
*/
Docker docker();

}
6 changes: 3 additions & 3 deletions src/main/java/com/amihaiemil/docker/RtDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public final Volumes volumes() {

@Override
public final Execs execs() {
throw new UnsupportedOperationException(
"Exec API is not yet implemented. If you can contribute please,"
+ " do it here: https://www.github.com/amihaiemil/docker-java-api"
return new RtExecs(
URI.create(this.baseUri.toString() + "/exec"),
this
);
}

Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/amihaiemil/docker/RtExecs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2018-2020, 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 java.net.URI;

/**
* RESTful Execs API.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.12
*/
final class RtExecs implements Execs {

/**
* Base URI for Images API.
*/
private final URI baseUri;

/**
* Docker API.
*/
private final Docker docker;

/**
* Ctor.
* @param uri The URI for this Images API.
* @param dkr The docker entry point.
* @checkstyle ParameterNumber (10 lines)
*/
RtExecs(final URI uri, final Docker dkr) {
this.baseUri = uri;
this.docker = dkr;
}

@Override
public Exec get(final String execId) {
return null;
}

@Override
public Docker docker() {
return this.docker;
}
}
15 changes: 9 additions & 6 deletions src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,16 @@ public void returnsNetworks() {
}

/**
* LocalUnixDocker throws UnsupportedOperationException for Exec.
* LocalUnixDocker can return Execs.
*/
@Test(expected = UnsupportedOperationException.class)
public void unsupportedOperationExec() {
new LocalDocker(
new File("/var/run/docker.sock")
).execs();
@Test
public void returnsExecs() {
MatcherAssert.assertThat(
new LocalDocker(
new File("/var/run/docker.sock")
).execs(),
Matchers.notNullValue()
);
}

/**
Expand Down
16 changes: 9 additions & 7 deletions src/test/java/com/amihaiemil/docker/UnixDockerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ public void returnsNetworks() {
}

/**
* UnixDocker throws UnsupportedOperationException for Exec.
* UnixDocker can return Execs.
*/
@Test(expected = UnsupportedOperationException.class)
public void unsupportedOperationExec() {
new UnixDocker(
new File(
"/var/run/docker.sock")
).execs();
@Test
public void returnsExecs() {
MatcherAssert.assertThat(
new UnixDocker(
new File("/var/run/docker.sock")
).execs(),
Matchers.notNullValue()
);
}

/**
Expand Down

0 comments on commit 564cd5f

Please sign in to comment.