Skip to content

Commit

Permalink
added container.wait()
Browse files Browse the repository at this point in the history
  • Loading branch information
ry99 committed Apr 2, 2020
1 parent 5eba97c commit 00f57ba
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/main/java/com/amihaiemil/docker/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,17 @@ void remove(final boolean volumes, final boolean force, final boolean link)
* the expected one (204 NO CONTENT).
*/
void unpause() throws IOException;



/**
* Waits on this container.
* @param state The state to wait for. One of "not-running"
* (the default if null), "next-exit", or "removed"
* @see <a href="https://docs.docker.com/engine/api/v1.35/#operation/ContainerWait">
* Wait Container</a>.
* @throws IOException If something goes wrong.
* the expected one (200).
*/
void waitOn(String state) throws IOException;

}
19 changes: 19 additions & 0 deletions src/main/java/com/amihaiemil/docker/RtContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,23 @@ public void unpause() throws IOException {
unpause.releaseConnection();
}
}

@Override
public void waitOn(final String state) throws IOException {
String end = "";
if(null == state || state.isEmpty()){
end = String.format("?condition=%s", state);
}
final HttpPost waiter = new HttpPost(
this.baseUri.toString() + "/wait" + end
);
try {
this.client.execute(
waiter,
new MatchStatus(waiter.getURI(), HttpStatus.SC_OK)
);
} finally {
waiter.releaseConnection();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/amihaiemil/docker/UnixDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Docker engine.
*
* <pre>
* final Docker docker = new LocalUnixDocker("unix:///var/run/dicker.sock");
* final Docker docker = new LocalUnixDocker("unix:///var/run/docker.sock");
* </pre>
*
* This implementation manages an internal pool of 10 http connections. Users
Expand Down

0 comments on commit 00f57ba

Please sign in to comment.