use of io.fabric8.maven.docker.util.GavLabel in project docker-maven-plugin by fabric8io.
the class RunService method stopStartedContainers.
/**
* Stop all registered container
* @param keepContainer whether to keep container or to remove them after stopping
* @param removeVolumes whether to remove volumes after stopping
* @throws DockerAccessException if during stopping of a container sth fails
*/
public void stopStartedContainers(boolean keepContainer, boolean removeVolumes, boolean removeCustomNetworks, GavLabel gavLabel) throws DockerAccessException, ExecException {
List<DockerAccessException> thrownExceptions = new ArrayList<>();
Set<Network> networksToRemove = new HashSet<>();
for (ContainerTracker.ContainerShutdownDescriptor descriptor : tracker.removeShutdownDescriptors(gavLabel)) {
try {
collectCustomNetworks(networksToRemove, descriptor, removeCustomNetworks);
shutdown(descriptor, keepContainer, removeVolumes);
} catch (DockerAccessException exc) {
thrownExceptions.add(exc);
}
}
try {
removeCustomNetworks(networksToRemove);
} catch (DockerAccessException exc) {
thrownExceptions.add(exc);
}
if (!thrownExceptions.isEmpty()) {
StringJoiner description = new StringJoiner(",", "(", ")");
for (DockerAccessException dae : thrownExceptions) {
description.add(dae.getLocalizedMessage());
}
DockerAccessException exception = new DockerAccessException(description.toString());
for (DockerAccessException dae : thrownExceptions) {
exception.addSuppressed(dae);
}
throw exception;
}
}
Aggregations