use of com.spotify.docker.client.messages.ContainerInfo in project linuxtools by eclipse.
the class DockerConnection method logContainer.
@Override
public void logContainer(final String id, final OutputStream stream) throws DockerException, InterruptedException {
try {
// or keep running
synchronized (loggingThreads) {
ContainerInfo info = client.inspectContainer(id);
LogThread t = loggingThreads.get(id);
if (t == null || !t.isAlive()) {
t = new LogThread(id, getClientCopy(), info.state().running());
loggingThreads.put(id, t);
t.setOutputStream(stream);
t.start();
} else {
// we aren't going to use the stream given...close it
try {
stream.close();
} catch (IOException e) {
// do nothing...we tried to close the stream
}
}
}
} catch (ContainerNotFoundException e) {
throw new DockerContainerNotFoundException(e);
} catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
throw new DockerException(e.message());
} catch (com.spotify.docker.client.exceptions.DockerException e) {
throw new DockerException(e.getMessage(), e.getCause());
}
}
use of com.spotify.docker.client.messages.ContainerInfo in project linuxtools by eclipse.
the class ImageRunSWTBotTest method shouldCreateLaunchConfigurationWhenRunningNamedContainer.
@Test
public void shouldCreateLaunchConfigurationWhenRunningNamedContainer() throws InterruptedException, DockerException, CoreException {
// images to use
final String imageName = "foo/bar:latest";
final Image image = MockImageFactory.id("1a2b3c4d5e6f7g").name(imageName).build();
final ImageInfo imageInfo = MockImageInfoFactory.volume("/foo/bar").command(Arrays.asList("the", "command")).entrypoint(Arrays.asList("the", "entrypoint")).build();
// container to be created
final String containerName = "foo_bar";
final Container createdContainer = MockContainerFactory.id("MockContainer").name(containerName).imageName("1a2b3c4d5e6f7g").status("Started 1 second ago").build();
final ContainerInfo containerInfo = MockContainerInfoFactory.build();
final DockerClient client = MockDockerClientFactory.image(image, imageInfo).build();
// expected response when creating the container
final ContainerCreation containerCreation = Mockito.mock(ContainerCreation.class);
Mockito.when(containerCreation.id()).thenReturn("MockContainer");
Mockito.when(client.createContainer(Matchers.any(), Matchers.any())).thenReturn(containerCreation);
final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
// configure the Connection Manager
DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
// when select images and click on run to open the wizard
SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo/bar").select();
dockerExplorerViewBot.bot().tree().contextMenu("Run...").click();
// $NON-NLS-1$
bot.waitUntil(Conditions.shellIsActive("Run a Docker Image"), TimeUnit.SECONDS.toMillis(1));
// configure container
bot.text(0).setText(containerName);
// bot.button("Next >").click();
// update the client to make sure the container exists once the call to "Finish" is done
MockDockerClientFactory.addContainer(client, createdContainer, containerInfo);
bot.button("Finish").click();
// wait for background job to complete
SWTUtils.waitForJobsToComplete();
// then
// check that the client was called
Mockito.verify(client).createContainer(Matchers.any(), Matchers.eq(containerName));
// check that a launch configuration was created
final ILaunchConfiguration launchConfiguration = LaunchConfigurationUtils.getLaunchConfigurationByName(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID, "foo_bar_latest");
assertThat(launchConfiguration).isNotNull();
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testLogsTail.
@Test
public void testLogsTail() throws Exception {
sut.pull(BUSYBOX_LATEST);
final String container = randomName();
final ContainerConfig volumeConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("sh", "-c", "echo 1 && echo 2 && echo 3 && echo 4").build();
sut.createContainer(volumeConfig, container);
sut.startContainer(container);
sut.waitContainer(container);
final ContainerInfo info = sut.inspectContainer(container);
assertThat(info.state().running(), is(false));
assertThat(info.state().exitCode(), is(0));
final String logs;
try (LogStream stream = sut.logs(info.id(), stdout(), stderr(), tail(2))) {
logs = stream.readFully();
}
assertThat(logs, not(containsString("1")));
assertThat(logs, not(containsString("2")));
assertThat(logs, containsString("3"));
assertThat(logs, containsString("4"));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testLogsTty.
@Test
public void testLogsTty() throws DockerException, InterruptedException {
final String container = randomName();
final ContainerConfig containerConfig = ContainerConfig.builder().image(BUSYBOX_LATEST).attachStdout(true).tty(true).cmd("sh", "-c", "ls").build();
sut.createContainer(containerConfig, container);
sut.startContainer(container);
final LogStream logStream = sut.logs(container, DockerClient.LogsParam.stdout());
while (logStream.hasNext()) {
final String line = UTF_8.decode(logStream.next().content()).toString();
log.info(line);
}
sut.waitContainer(container);
final ContainerInfo info = sut.inspectContainer(container);
assertThat(info.state().running(), is(false));
assertThat(info.state().exitCode(), is(0));
}
use of com.spotify.docker.client.messages.ContainerInfo in project docker-client by spotify.
the class DefaultDockerClientTest method testInspectContainerWithExposedPorts.
@Test
public void testInspectContainerWithExposedPorts() throws Exception {
sut.pull(MEMCACHED_LATEST);
final ContainerConfig config = ContainerConfig.builder().image(MEMCACHED_LATEST).build();
final ContainerCreation container = sut.createContainer(config, randomName());
sut.startContainer(container.id());
final ContainerInfo containerInfo = sut.inspectContainer(container.id());
assertThat(containerInfo, notNullValue());
assertThat(containerInfo.networkSettings().ports(), hasEntry("11211/tcp", Collections.<PortBinding>emptyList()));
}
Aggregations