Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Add the boolean parameter 'Force' to DockerClient#disconnectFromNetwork and fix issue on exceptions being swalled #839

Merged
merged 2 commits into from
Jul 29, 2017
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
19 changes: 10 additions & 9 deletions src/main/java/com/spotify/docker/client/DefaultDockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ public void removeNetwork(String networkId) throws DockerException, InterruptedE
@Override
public void connectToNetwork(String containerId, String networkId)
throws DockerException, InterruptedException {
manageNetworkConnection(containerId, "connect", networkId);
connectToNetwork(networkId, NetworkConnection.builder().containerId(containerId).build());
}

@Override
Expand All @@ -2239,7 +2239,7 @@ public void connectToNetwork(String networkId, NetworkConnection networkConnecti
final WebTarget resource = resource().path("networks").path(networkId).path("connect");

try {
request(POST, Response.class, resource, resource.request(APPLICATION_JSON_TYPE),
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE),
Entity.json(networkConnection));
} catch (DockerRequestException e) {
switch (e.status()) {
Expand All @@ -2256,18 +2256,20 @@ public void connectToNetwork(String networkId, NetworkConnection networkConnecti
@Override
public void disconnectFromNetwork(String containerId, String networkId)
throws DockerException, InterruptedException {
manageNetworkConnection(containerId, "disconnect", networkId);
disconnectFromNetwork(containerId, networkId, false);
}

private void manageNetworkConnection(String containerId, String methodname, String networkId)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning this up.

throws DockerException, InterruptedException {
final WebTarget resource = resource().path("networks").path(networkId).path(methodname);
@Override
public void disconnectFromNetwork(String containerId, String networkId, boolean force)
throws DockerException, InterruptedException {
final WebTarget resource = resource().path("networks").path(networkId).path("disconnect");

final Map<String, String> request = new HashMap<>();
final Map<String, Object> request = new HashMap<>();
request.put("Container", containerId);
request.put("Force", force);

try {
request(POST, Response.class, resource, resource.request(APPLICATION_JSON_TYPE),
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE),
Entity.json(request));
} catch (DockerRequestException e) {
switch (e.status()) {
Expand Down Expand Up @@ -2844,5 +2846,4 @@ public DefaultDockerClient build() {
return new DefaultDockerClient(this);
}
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/spotify/docker/client/DockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,19 @@ void connectToNetwork(String networkId, NetworkConnection networkConnection)
void disconnectFromNetwork(String containerId, String networkId)
throws DockerException, InterruptedException;

/**
* Disconnects a docker container to a network.
*
* @param containerId The id of the container to disconnect.
* @param networkId The id of the network to disconnect.
* @param force Force the container to disconnect from the network.
* @throws NotFoundException if either container or network is not found (404)
* @throws DockerException if a server error occurred (500)
* @throws InterruptedException If the thread is interrupted
*/
void disconnectFromNetwork(String containerId, String networkId, boolean force)
throws DockerException, InterruptedException;

/**
* Closes any and all underlying connections to docker, and release resources.
*/
Expand Down