Search in sources :

Example 91 with DockerClient

use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.

the class DockerService method getRunningContainersByImageName.

public List<Container> getRunningContainersByImageName(String imageName) throws Exception {
    imageName += ":";
    DockerClient dockerClient = getDockerClient();
    List<Container> allContainers = dockerClient.listContainers(ListContainersParam.allContainers());
    List<Container> imageContainers = new ArrayList<>();
    for (Container currentContainer : allContainers) {
        if (currentContainer.image().startsWith(imageName)) {
            imageContainers.add(currentContainer);
        }
    }
    return imageContainers;
}
Also used : DockerContainer(io.elastest.epm.client.DockerContainer) Container(com.spotify.docker.client.messages.Container) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) ArrayList(java.util.ArrayList)

Example 92 with DockerClient

use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.

the class DockerService method stopAndRemoveContainerWithKillTimeout.

public void stopAndRemoveContainerWithKillTimeout(String containerId, int killAfterSeconds) throws Exception {
    DockerClient dockerClient = getDockerClient();
    dockerClient.stopContainer(containerId, killAfterSeconds);
    this.removeDockerContainer(containerId);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient)

Example 93 with DockerClient

use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.

the class DockerService method getContainerIpByNetwork.

public String getContainerIpByNetwork(String containerId, String network) throws Exception {
    DockerClient client = getDockerClient();
    ContainerInfo info = client.inspectContainer(containerId);
    String ip = info.networkSettings().networks().get(network).ipAddress();
    return ip.split("/")[0];
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo)

Example 94 with DockerClient

use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.

the class DockerService method getContainerLogsByGivenLogContainerCmd.

public String getContainerLogsByGivenLogContainerCmd(String containerId, List<LogsParam> params) throws Exception {
    params.add(LogsParam.stdout(true));
    params.add(LogsParam.stderr(true));
    params.add(LogsParam.timestamps(true));
    DockerClient dockerClient = getDockerClient();
    LogStream logStream = dockerClient.logs(containerId, params.toArray(new LogsParam[params.size()]));
    return logStream.readFully();
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) LogsParam(com.spotify.docker.client.DockerClient.LogsParam) LogStream(com.spotify.docker.client.LogStream)

Example 95 with DockerClient

use of com.spotify.docker.client.DockerClient in project elastest-torm by elastest.

the class DockerService method removeDockerContainer.

public void removeDockerContainer(String containerId, boolean removeVolumes) throws Exception {
    DockerClient dockerClient = getDockerClient();
    List<ContainerMount> volumes = null;
    try {
        volumes = getContainerVolumes(containerId);
    } catch (Exception e) {
        logger.error("Error on get container {} volumes. Volumes have not been removed", containerId);
    }
    // Remove container
    dockerClient.removeContainer(containerId);
    if (removeVolumes) {
        this.removeVolumes(volumes);
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) DockerException(com.spotify.docker.client.exceptions.DockerException) IOException(java.io.IOException) ContainerMount(com.spotify.docker.client.messages.ContainerMount)

Aggregations

DockerClient (com.spotify.docker.client.DockerClient)185 Test (org.junit.Test)102 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)75 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)38 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)20 JobId (com.spotify.helios.common.descriptors.JobId)19 DockerException (com.spotify.docker.client.exceptions.DockerException)18 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)18 LogStream (com.spotify.docker.client.LogStream)17 SWTBotMenu (org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu)15 Container (com.spotify.docker.client.messages.Container)14 Path (java.nio.file.Path)12 DockerException (org.eclipse.linuxtools.docker.core.DockerException)12 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)12 Matchers.containsString (org.hamcrest.Matchers.containsString)11 HostConfig (com.spotify.docker.client.messages.HostConfig)10 HeliosClient (com.spotify.helios.client.HeliosClient)10 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)9 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)9 RunWithProject (org.eclipse.linuxtools.internal.docker.ui.testutils.RunWithProject)9