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; } // at this point networks should contain either 0 or 1 entries, depending on whether the network exists // 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); } }
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; } // at this point networks should contain either 0 or 1 entries, depending on whether the network exists // 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); } }
log.info("Created new network [" + networkName + "] with id [" + networkId + "]", context); } else { networkName = existing.getName(); networkId = existing.getId(); log.info("Found existing network [" + networkName + "] with id [" + networkId + "]", context);