use of io.fabric8.maven.docker.model.Network in project syndesis-qe by syndesisio.
the class OperatorValidationSteps method checkAffinity.
@When("^check (affinity|tolerations)( not set)? for (infra|integration) pods$")
public void checkAffinity(String test, String notSet, String method) {
List<Pod> pods = "infra".equals(method) ? ComponentUtils.getComponentPods().stream().filter(p -> !p.getMetadata().getName().contains("operator")).collect(Collectors.toList()) : OpenShiftUtils.findPodsByPredicates(p -> "integration".equals(p.getMetadata().getLabels().get("syndesis.io/type")));
for (Pod p : pods) {
String name = p.getMetadata().getName();
if ("affinity".equals(test)) {
Affinity podAffinity = p.getSpec().getAffinity();
if (notSet == null) {
assertThat(podAffinity).as(name + ": affinity is null").isNotNull();
NodeAffinity nodeAffinity = podAffinity.getNodeAffinity();
assertThat(nodeAffinity).as(name + ": node affinity is null").isNotNull();
NodeSelector selector = nodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution();
assertThat(selector).as(name + ": required is null").isNotNull();
List<NodeSelectorTerm> terms = selector.getNodeSelectorTerms();
assertThat(terms).as(name + ": node selector is null").isNotNull();
assertThat(terms).as(name + ": node selector size isn't 1").hasSize(1);
} else {
assertThat(podAffinity).isNull();
}
} else {
Optional<Toleration> toleration = p.getSpec().getTolerations().stream().filter(t -> "node.kubernetes.io/network-unavailable".equals(t.getKey())).findAny();
if (notSet == null) {
assertThat(toleration).as(name + ": Expected toleration setting is not present").isPresent();
} else {
assertThat(toleration).as(name + ": Toleration shouldn't be present").isNotPresent();
}
}
}
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class DockerAccessWithHcClient method removeNetwork.
@Override
public boolean removeNetwork(String networkId) throws DockerAccessException {
try {
String url = urlBuilder.removeNetwork(networkId);
log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_DELETE, url);
int status = delegate.delete(url, HTTP_OK, HTTP_NO_CONTENT, HTTP_NOT_FOUND);
return status == HTTP_OK || status == HTTP_NO_CONTENT;
} catch (IOException e) {
throw new DockerAccessException(e, "Unable to remove network [%s]", networkId);
}
}
use of io.fabric8.maven.docker.model.Network 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;
}
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class DockerAccessWithHcClient method createNetwork.
@Override
public String createNetwork(NetworkCreateConfig networkConfig) throws DockerAccessException {
String createJson = networkConfig.toJson();
log.debug("Network create config: " + createJson);
try {
String url = urlBuilder.createNetwork();
log.verbose(Logger.LogVerboseCategory.API, API_LOG_FORMAT_POST_WITH_REQUEST, url, createJson);
String response = delegate.post(url, createJson, new ApacheHttpClientDelegate.BodyResponseHandler(), HTTP_CREATED);
log.debug(response);
JsonObject json = JsonFactory.newJsonObject(response);
if (json.has("Warnings")) {
logWarnings(json);
}
// only need first 12 to id a container
return json.get("Id").getAsString().substring(0, 12);
} catch (IOException e) {
throw new DockerAccessException(e, "Unable to create network for [%s]", networkConfig.getName());
}
}
use of io.fabric8.maven.docker.model.Network in project docker-maven-plugin by fabric8io.
the class StopMojo method stopContainers.
private void stopContainers(QueryService queryService, RunService runService, GavLabel gavLabel) throws MojoExecutionException, IOException, ExecException {
Collection<Network> networksToRemove = getNetworksToRemove(queryService, gavLabel);
List<DockerAccessException> thrownExceptions = new ArrayList<>();
for (ImageConfiguration image : getResolvedImages()) {
Collection<Container> existingContainers = getContainersForImage(queryService, image);
for (Container container : existingContainers) {
if (shouldStopContainer(container, gavLabel)) {
try {
runService.stopContainer(container.getId(), image, keepContainer, removeVolumes);
} catch (DockerAccessException exc) {
thrownExceptions.add(exc);
}
}
}
}
// If the mojo has a stopNamePattern, check to see if there are matching containers
for (Container container : getContainersForMojo(queryService)) {
if (shouldStopContainer(container, gavLabel)) {
try {
runService.stopContainer(container.getId(), new ImageConfiguration.Builder().name(container.getImage()).build(), keepContainer, removeVolumes);
} catch (DockerAccessException exc) {
thrownExceptions.add(exc);
}
}
}
try {
runService.removeCustomNetworks(networksToRemove);
} catch (DockerAccessException exc) {
thrownExceptions.add(exc);
}
if (!thrownExceptions.isEmpty()) {
DockerAccessException exception = new DockerAccessException("At least one exception thrown during container removal.");
for (DockerAccessException dae : thrownExceptions) {
exception.addSuppressed(dae);
}
throw exception;
}
}
Aggregations