Search in sources :

Example 1 with Container

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;
}
Also used : Container(com.github.dockerjava.api.model.Container)

Example 2 with Container

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;
}
Also used : HashMap(java.util.HashMap) Container(com.github.dockerjava.api.model.Container) Image(com.github.dockerjava.api.model.Image)

Example 3 with Container

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);
}
Also used : Container(com.github.dockerjava.api.model.Container) DockerClient(com.github.dockerjava.api.DockerClient)

Example 4 with Container

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);
    }
}
Also used : Container(com.github.dockerjava.api.model.Container) DockerContainer(io.elastest.epm.client.json.DockerContainerInfo.DockerContainer) SutSpecification(io.elastest.etm.model.SutSpecification)

Example 5 with Container

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;
}
Also used : Container(com.github.dockerjava.api.model.Container) DockerContainer(io.elastest.epm.client.json.DockerContainerInfo.DockerContainer) SutSpecification(io.elastest.etm.model.SutSpecification)

Aggregations

Container (com.github.dockerjava.api.model.Container)6 DockerContainer (io.elastest.epm.client.json.DockerContainerInfo.DockerContainer)2 SutSpecification (io.elastest.etm.model.SutSpecification)2 DockerClient (com.github.dockerjava.api.DockerClient)1 CreateContainerCmd (com.github.dockerjava.api.command.CreateContainerCmd)1 CreateContainerResponse (com.github.dockerjava.api.command.CreateContainerResponse)1 Image (com.github.dockerjava.api.model.Image)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1