use of com.github.dockerjava.api.model.Container in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method getRunningContainer.
private Container getRunningContainer(final List<Container> containers, final String extractorContainerName) {
Container extractorContainer = null;
for (final Container container : containers) {
for (final String name : container.getNames()) {
// name prefixed with '/' for some reason
logger.debug(String.format("Checking running container %s to see if it is %s", name, extractorContainerName));
if (name.contains(extractorContainerName)) {
logger.debug("The extractor container already exists");
extractorContainer = container;
break;
}
}
if (extractorContainer != null) {
break;
}
}
return extractorContainer;
}
use of com.github.dockerjava.api.model.Container in project vespa by vespa-engine.
the class DockerImageGarbageCollector method filterOutImagesUsedByContainers.
private Map<String, Image> filterOutImagesUsedByContainers(Map<String, Image> dockerImagesByImageId, List<com.github.dockerjava.api.model.Container> containerList) {
Map<String, Image> filteredDockerImagesByImageId = new HashMap<>(dockerImagesByImageId);
for (com.github.dockerjava.api.model.Container container : containerList) {
String imageToSpare = container.getImageId();
do {
// May be null if two images have have the same parent, the first image will remove the parent, the
// second will get null.
Image sparedImage = filteredDockerImagesByImageId.remove(imageToSpare);
imageToSpare = sparedImage == null ? "" : sparedImage.getParentId();
} while (!imageToSpare.isEmpty());
}
return filteredDockerImagesByImageId;
}
use of com.github.dockerjava.api.model.Container in project elastest-torm by elastest.
the class DockerService2 method getContainersByNamePrefix.
public List<Container> getContainersByNamePrefix(String prefix) {
DockerClient dockerClient = this.getDockerClient();
List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
return this.getContainersByNamePrefixByGivenList(containers, prefix, ContainersListActionEnum.NONE);
}
use of com.github.dockerjava.api.model.Container in project elastest-torm by elastest.
the class TJobExecOrchestratorService method endSutInContainer.
public void endSutInContainer(DockerExecution dockerExec) throws Exception {
SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
String containerName = null;
String sutPrefix = null;
boolean isDockerCompose = false;
// If is Docker compose Sut
if (sut.getCommandsOption() == CommandsOptionEnum.IN_DOCKER_COMPOSE) {
containerName = this.getCurrentExecSutMainServiceName(sut, dockerExec);
sutPrefix = this.dockerService.getSutPrefix(dockerExec);
isDockerCompose = true;
} else // If is unique Docker image Sut
if (sut.getCommandsOption() == CommandsOptionEnum.IN_NEW_CONTAINER) {
containerName = dockerService.getSutPrefix(dockerExec);
sutPrefix = containerName;
}
// Add containers to dockerService list
if (isDockerCompose) {
List<Container> containersList = this.dockerService.getContainersCreatedSinceId(dockerExec.getAppContainerId());
this.dockerService.getContainersByNamePrefixByGivenList(containersList, sutPrefix, ContainersListActionEnum.REMOVE);
} else {
this.dockerService.endContainer(containerName);
}
}
use of com.github.dockerjava.api.model.Container in project elastest-torm by elastest.
the class TJobExecOrchestratorService method waitForSutInContainer.
public String waitForSutInContainer(DockerExecution dockerExec, long timeout) throws Exception {
SutSpecification sut = dockerExec.gettJobexec().getTjob().getSut();
String containerName = null;
String sutPrefix = null;
boolean isDockerCompose = false;
// If is Docker compose Sut
if (sut.getCommandsOption() == CommandsOptionEnum.IN_DOCKER_COMPOSE) {
containerName = this.getCurrentExecSutMainServiceName(sut, dockerExec);
sutPrefix = this.dockerService.getSutPrefix(dockerExec);
isDockerCompose = true;
} else // If is unique Docker image Sut
if (sut.getCommandsOption() == CommandsOptionEnum.IN_NEW_CONTAINER) {
containerName = dockerService.getSutPrefix(dockerExec);
sutPrefix = containerName;
}
// Wait for created
this.dockerService.waitForContainerCreated(containerName, dockerExec, timeout);
// Insert main sut/service into ET network
this.dockerService.insertIntoNetwork(dockerExec.getNetwork(), this.dockerService.getContainerIdByName(containerName));
// Get Main sut/service ip from ET network
String sutIp = dockerService.waitForContainerIpWithDockerExecution(containerName, dockerExec, timeout);
// Add containers to dockerService list
if (isDockerCompose) {
List<Container> containersList = this.dockerService.getContainersCreatedSinceId(dockerExec.getAppContainerId());
this.dockerService.getContainersByNamePrefixByGivenList(containersList, sutPrefix, ContainersListActionEnum.ADD);
} else {
String containerId = this.dockerService.getContainerIdByName(containerName);
this.dockerService.insertCreatedContainer(containerId, containerName);
}
return sutIp;
}
Aggregations