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;
}
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();
}
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);
}
Aggregations