Search in sources :

Example 96 with DockerClient

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

the class DockerService method execCommand.

public String execCommand(String containerName, boolean awaitCompletion, String... command) throws Exception {
    assert (command.length > 0);
    String output = null;
    String commandStr = Arrays.toString(command);
    logger.debug("Executing command {} in container {} (await completion {})", commandStr, containerName, awaitCompletion);
    if (existsContainer(containerName)) {
        DockerClient dockerClient = getDockerClient();
        ExecCreation exec = dockerClient.execCreate(containerName, command, ExecCreateParam.tty(), ExecCreateParam.attachStdin(true), ExecCreateParam.attachStdout(true), ExecCreateParam.attachStderr(true), ExecCreateParam.detach(awaitCompletion));
        logger.debug("Command '{}' executed. Exec id: {}", commandStr, exec.id());
        LogStream startResultCallback = dockerClient.execStart(exec.id(), ExecStartParameter.TTY);
        if (awaitCompletion) {
            output = startResultCallback.readFully();
        }
        logger.debug("Callback terminated for command {} in container {}. Result: {}", commandStr, containerName, output);
    }
    return output;
}
Also used : ExecCreation(com.spotify.docker.client.messages.ExecCreation) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) LogStream(com.spotify.docker.client.LogStream)

Example 97 with DockerClient

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

the class DockerService method getImageInfoByName.

public ImageInfo getImageInfoByName(String imageName) throws Exception {
    ImageInfo response = null;
    DockerClient dockerClient = getDockerClient();
    try {
        if (existsImage(imageName)) {
            response = dockerClient.inspectImage(imageName);
        }
    } catch (Exception e) {
        logger.error("Error loading image \"{}\" information.", imageName);
        throw e;
    }
    return response;
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) ImageInfo(com.spotify.docker.client.messages.ImageInfo) DockerException(com.spotify.docker.client.exceptions.DockerException) IOException(java.io.IOException)

Example 98 with DockerClient

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

the class DockerService method getContainerIdByName.

public String getContainerIdByName(String containerName) throws Exception {
    DockerClient dockerClient = getDockerClient();
    String id = "";
    try {
        if (existsContainer(containerName)) {
            ContainerInfo response = dockerClient.inspectContainer(containerName);
            id = response.id();
        }
    } catch (Exception e) {
    }
    return id;
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) DockerException(com.spotify.docker.client.exceptions.DockerException) IOException(java.io.IOException)

Example 99 with DockerClient

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

the class DockerService method insertIntoNetwork.

public void insertIntoNetwork(String networkId, String containerId) throws Exception {
    boolean isAreadyInNetwork = this.isContainerIntoNetwork(networkId, containerId);
    if (!isAreadyInNetwork) {
        DockerClient client = getDockerClient();
        client.connectToNetwork(containerId, networkId);
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient)

Example 100 with DockerClient

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

the class DockerService method getRunningContainersByImageNameAndVersion.

public List<Container> getRunningContainersByImageNameAndVersion(String imageName, String version) throws Exception {
    DockerClient dockerClient = getDockerClient();
    List<Container> allContainers = dockerClient.listContainers(ListContainersParam.allContainers());
    List<Container> imageContainers = new ArrayList<>();
    for (Container currentContainer : allContainers) {
        String currentImageName = currentContainer.image();
        if (currentImageName != null && currentImageName.equals(imageName.trim())) {
            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)

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