Search in sources :

Example 1 with PomLabel

use of io.fabric8.maven.docker.util.PomLabel in project docker-maven-plugin by fabric8io.

the class StopMojo method getNetworksToRemove.

private Set<Network> getNetworksToRemove(QueryService queryService, PomLabel pomLabel) throws DockerAccessException {
    if (!autoCreateCustomNetworks) {
        return Collections.emptySet();
    }
    Set<Network> customNetworks = new HashSet<>();
    Set<Network> networks = queryService.getNetworks();
    for (ImageConfiguration image : getResolvedImages()) {
        final NetworkConfig config = image.getRunConfiguration().getNetworkingConfig();
        if (config.isCustomNetwork()) {
            Network network = getNetworkByName(networks, config.getCustomNetwork());
            if (network != null) {
                customNetworks.add(network);
                for (Container container : getContainersToStop(queryService, image)) {
                    if (!shouldStopContainer(container, pomLabel, image)) {
                        // it's sill in use don't collect it
                        customNetworks.remove(network);
                    }
                }
            }
        }
    }
    return customNetworks;
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Network(io.fabric8.maven.docker.model.Network) NetworkConfig(io.fabric8.maven.docker.config.NetworkConfig) HashSet(java.util.HashSet)

Example 2 with PomLabel

use of io.fabric8.maven.docker.util.PomLabel in project docker-maven-plugin by fabric8io.

the class StopMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException, ExecException {
    QueryService queryService = hub.getQueryService();
    RunService runService = hub.getRunService();
    PomLabel pomLabel = getPomLabel();
    if (!keepRunning) {
        if (invokedTogetherWithDockerStart()) {
            runService.stopStartedContainers(keepContainer, removeVolumes, autoCreateCustomNetworks, pomLabel);
        } else {
            stopContainers(queryService, runService, pomLabel);
        }
    }
    // Switch off all logging
    LogDispatcher dispatcher = getLogDispatcher(hub);
    dispatcher.untrackAllContainerLogs();
}
Also used : RunService(io.fabric8.maven.docker.service.RunService) QueryService(io.fabric8.maven.docker.service.QueryService) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher) PomLabel(io.fabric8.maven.docker.util.PomLabel)

Example 3 with PomLabel

use of io.fabric8.maven.docker.util.PomLabel in project docker-maven-plugin by fabric8io.

the class StopMojo method stopContainers.

private void stopContainers(QueryService queryService, RunService runService, PomLabel pomLabel) throws DockerAccessException, ExecException {
    Collection<Network> networksToRemove = getNetworksToRemove(queryService, pomLabel);
    for (ImageConfiguration image : getResolvedImages()) {
        for (Container container : getContainersToStop(queryService, image)) {
            if (shouldStopContainer(container, pomLabel, image)) {
                runService.stopContainer(container.getId(), image, keepContainer, removeVolumes);
            }
        }
    }
    runService.removeCustomNetworks(networksToRemove);
}
Also used : Container(io.fabric8.maven.docker.model.Container) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) RunImageConfiguration(io.fabric8.maven.docker.config.RunImageConfiguration) Network(io.fabric8.maven.docker.model.Network)

Aggregations

ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)2 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)2 Container (io.fabric8.maven.docker.model.Container)2 Network (io.fabric8.maven.docker.model.Network)2 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)1 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)1 QueryService (io.fabric8.maven.docker.service.QueryService)1 RunService (io.fabric8.maven.docker.service.RunService)1 PomLabel (io.fabric8.maven.docker.util.PomLabel)1 HashSet (java.util.HashSet)1