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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations