Search in sources :

Example 1 with Network

use of com.github.dockerjava.api.model.Network in project tutorials by eugenp.

the class NetworkLiveTest method whenInspectingNetwork_thenSizeMustBeGreaterThanZero.

@Test
public void whenInspectingNetwork_thenSizeMustBeGreaterThanZero() {
    // when
    String networkName = "bridge";
    Network network = dockerClient.inspectNetworkCmd().withNetworkId(networkName).exec();
    // then
    assertThat(network.getName(), is(networkName));
}
Also used : Network(com.github.dockerjava.api.model.Network) Test(org.junit.Test)

Example 2 with Network

use of com.github.dockerjava.api.model.Network in project testcontainers-java by testcontainers.

the class ResourceReaper method removeNetwork.

private void removeNetwork(String id) {
    try {
        List<Network> networks;
        try {
            // Try to find the network if it still exists
            // Listing by ID first prevents docker-java logging an error if we just go blindly into removeNetworkCmd
            networks = dockerClient.listNetworksCmd().withIdFilter(id).exec();
        } catch (Exception e) {
            LOGGER.trace("Error encountered when looking up network for removal (name: {}) - it may not have been removed", id);
            return;
        }
        // using a for loop we essentially treat the network like an optional, only applying the removal if it exists
        for (Network network : networks) {
            try {
                dockerClient.removeNetworkCmd(network.getId()).exec();
                registeredNetworks.remove(network.getId());
                LOGGER.debug("Removed network: {}", id);
            } catch (Exception e) {
                LOGGER.trace("Error encountered removing network (name: {}) - it may not have been removed", network.getName());
            }
        }
    } finally {
        registeredNetworks.remove(id);
    }
}
Also used : Network(com.github.dockerjava.api.model.Network) DockerException(com.github.dockerjava.api.exception.DockerException) InternalServerErrorException(com.github.dockerjava.api.exception.InternalServerErrorException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException)

Aggregations

Network (com.github.dockerjava.api.model.Network)2 DockerException (com.github.dockerjava.api.exception.DockerException)1 InternalServerErrorException (com.github.dockerjava.api.exception.InternalServerErrorException)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 IOException (java.io.IOException)1 Test (org.junit.Test)1