Search in sources :

Example 6 with ExecCreateCmdResponse

use of com.github.dockerjava.api.command.ExecCreateCmdResponse in project druid by druid-io.

the class DruidClusterAdminClient method runCommandInDockerContainer.

public Pair<String, String> runCommandInDockerContainer(String serviceName, String... cmd) throws Exception {
    DockerClient dockerClient = newClient();
    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    ByteArrayOutputStream stderr = new ByteArrayOutputStream();
    ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(findDockerContainer(dockerClient, serviceName)).withAttachStderr(true).withAttachStdout(true).withCmd(cmd).exec();
    dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(new ExecStartResultCallback(stdout, stderr)).awaitCompletion();
    return new Pair<>(stdout.toString(StandardCharsets.UTF_8.name()), stderr.toString(StandardCharsets.UTF_8.name()));
}
Also used : ExecCreateCmdResponse(com.github.dockerjava.api.command.ExecCreateCmdResponse) DockerClient(com.github.dockerjava.api.DockerClient) ExecStartResultCallback(com.github.dockerjava.core.command.ExecStartResultCallback) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Pair(org.apache.druid.java.util.common.Pair)

Aggregations

ExecCreateCmdResponse (com.github.dockerjava.api.command.ExecCreateCmdResponse)6 ExecStartResultCallback (com.github.dockerjava.core.command.ExecStartResultCallback)5 DockerClient (com.github.dockerjava.api.DockerClient)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ExecCreateCmd (com.github.dockerjava.api.command.ExecCreateCmd)2 ExecStartCmd (com.github.dockerjava.api.command.ExecStartCmd)2 InspectExecResponse (com.github.dockerjava.api.command.InspectExecResponse)2 InspectExecCmd (com.github.dockerjava.api.command.InspectExecCmd)1 OutputStream (java.io.OutputStream)1 Pair (org.apache.druid.java.util.common.Pair)1 Test (org.junit.Test)1 FrameConsumerResultCallback (org.testcontainers.containers.output.FrameConsumerResultCallback)1 ToStringConsumer (org.testcontainers.containers.output.ToStringConsumer)1