Search in sources :

Example 16 with GavLabel

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;
    }
}
Also used : ContainerShutdownDescriptor(io.fabric8.maven.docker.service.ContainerTracker.ContainerShutdownDescriptor) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) Network(io.fabric8.maven.docker.model.Network) ArrayList(java.util.ArrayList) StringJoiner(java.util.StringJoiner) HashSet(java.util.HashSet)

Aggregations

GavLabel (io.fabric8.maven.docker.util.GavLabel)7 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 Expectations (mockit.Expectations)5 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)4 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)4 RunService (io.fabric8.maven.docker.service.RunService)4 Test (org.junit.Test)4 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)3 Container (io.fabric8.maven.docker.model.Container)3 Network (io.fabric8.maven.docker.model.Network)3 PortBindingException (io.fabric8.maven.docker.model.PortBindingException)3 QueryService (io.fabric8.maven.docker.service.QueryService)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Properties (java.util.Properties)3 Gson (com.google.gson.Gson)2 PortMapping (io.fabric8.maven.docker.access.PortMapping)2 CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)2 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)2 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)2