Search in sources :

Example 16 with LogStream

use of com.spotify.docker.client.LogStream in project helios by spotify.

the class DnsServerTest method testDnsParam.

@Test
public void testDnsParam() throws Exception {
    final String server1 = "127.0.0.1";
    final String server2 = "127.0.0.2";
    startDefaultMaster();
    startDefaultAgent(testHost(), "--dns", server1, "--dns", server2);
    awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
    final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, asList("cat", "/etc/resolv.conf"));
    deployJob(jobId, testHost());
    final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
    try (final DockerClient dockerClient = getNewDockerClient()) {
        final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr());
        final String log = logs.readFully();
        assertThat(log, containsString(server1));
        assertThat(log, containsString(server2));
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Matchers.containsString(org.hamcrest.Matchers.containsString) LogStream(com.spotify.docker.client.LogStream) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 17 with LogStream

use of com.spotify.docker.client.LogStream in project helios by spotify.

the class AddExtraHostTest method test.

@Test
public void test() throws Exception {
    try (final DockerClient docker = getNewDockerClient()) {
        // Start Helios agent, configured to bind host /etc/hostname into container /mnt/hostname
        startDefaultMaster();
        startDefaultAgent(testHost(), "--add-host", "secrethost:169.254.169.254");
        awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS);
        // a job that cat's /etc/hosts
        final List<String> command = ImmutableList.of("cat", "/etc/hosts");
        final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, command);
        deployJob(jobId, testHost());
        final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED);
        final String log;
        try (LogStream logs = docker.logs(taskStatus.getContainerId(), stdout(), stderr())) {
            log = logs.readFully();
            assertThat(log, containsString("169.254.169.254\tsecrethost"));
        }
    }
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Matchers.containsString(org.hamcrest.Matchers.containsString) LogStream(com.spotify.docker.client.LogStream) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 18 with LogStream

use of com.spotify.docker.client.LogStream in project linuxtools by eclipse.

the class DockerConnection method execShell.

public void execShell(final String id) throws DockerException {
    try {
        final ExecCreation execCreation = client.execCreate(id, // $NON-NLS-1$
        new String[] { "/bin/sh" }, ExecCreateParam.attachStdout(), ExecCreateParam.attachStderr(), ExecCreateParam.attachStdin(), ExecCreateParam.tty());
        final String execId = execCreation.id();
        final LogStream pty_stream = client.execStart(execId, DockerClient.ExecStartParameter.TTY);
        final IDockerContainerInfo info = getContainerInfo(id);
        // $NON-NLS-1$
        openTerminal(pty_stream, info.name() + " [shell]", null);
    } catch (Exception e) {
        throw new DockerException(e.getMessage(), e.getCause());
    }
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ExecCreation(com.spotify.docker.client.messages.ExecCreation) LogStream(com.spotify.docker.client.LogStream) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) DockerPingConnectionException(org.eclipse.linuxtools.docker.core.DockerPingConnectionException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ProcessingException(javax.ws.rs.ProcessingException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) DockerCertificateException(com.spotify.docker.client.exceptions.DockerCertificateException) SocketException(java.net.SocketException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) StorageException(org.eclipse.equinox.security.storage.StorageException) DockerContainerNotFoundException(org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerOpenConnectionException(org.eclipse.linuxtools.docker.core.DockerOpenConnectionException)

Aggregations

LogStream (com.spotify.docker.client.LogStream)18 DockerClient (com.spotify.docker.client.DockerClient)15 JobId (com.spotify.helios.common.descriptors.JobId)10 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)10 Test (org.junit.Test)10 Matchers.containsString (org.hamcrest.Matchers.containsString)8 DockerException (org.eclipse.linuxtools.docker.core.DockerException)6 IOException (java.io.IOException)4 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)3 DockerCertificateException (com.spotify.docker.client.exceptions.DockerCertificateException)3 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)3 ExecCreation (com.spotify.docker.client.messages.ExecCreation)3 SocketException (java.net.SocketException)3 UnknownHostException (java.net.UnknownHostException)3 ProcessingException (javax.ws.rs.ProcessingException)3 StorageException (org.eclipse.equinox.security.storage.StorageException)3 DockerContainerNotFoundException (org.eclipse.linuxtools.docker.core.DockerContainerNotFoundException)3 DockerOpenConnectionException (org.eclipse.linuxtools.docker.core.DockerOpenConnectionException)3 DockerPingConnectionException (org.eclipse.linuxtools.docker.core.DockerPingConnectionException)3 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)2