Search in sources :

Example 1 with ContainerNotFoundException

use of org.eclipse.che.plugin.docker.client.exception.ContainerNotFoundException in project che by eclipse.

the class DockerConnector method getContainerLogs.

/**
     * Get stdout and stderr logs from container.
     *
     * @param containerLogsProcessor
     *         output for container logs
     * @throws ContainerNotFoundException
     *         when container not found by docker (docker api returns 404)
     * @throws IOException
     *         when a problem occurs with docker api calls
     */
public void getContainerLogs(final GetContainerLogsParams params, MessageProcessor<LogMessage> containerLogsProcessor) throws IOException {
    try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("GET").path(apiVersionPathPrefix + "/containers/" + params.getContainer() + "/logs").query("stdout", 1).query("stderr", 1)) {
        addQueryParamIfNotNull(connection, "details", params.isDetails());
        addQueryParamIfNotNull(connection, "follow", params.isFollow());
        addQueryParamIfNotNull(connection, "since", params.getSince());
        addQueryParamIfNotNull(connection, "timestamps", params.isTimestamps());
        addQueryParamIfNotNull(connection, "tail", params.getTail());
        final DockerResponse response = connection.request();
        final int status = response.getStatus();
        if (status == 404) {
            throw new ContainerNotFoundException(readAndCloseQuietly(response.getInputStream()));
        }
        if (status != OK.getStatusCode()) {
            throw getDockerException(response);
        }
        try (InputStream responseStream = response.getInputStream()) {
            new LogMessagePumper(responseStream, containerLogsProcessor).start();
        }
    }
}
Also used : DockerConnection(org.eclipse.che.plugin.docker.client.connection.DockerConnection) DockerResponse(org.eclipse.che.plugin.docker.client.connection.DockerResponse) BufferedInputStream(java.io.BufferedInputStream) CloseConnectionInputStream(org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ContainerNotFoundException(org.eclipse.che.plugin.docker.client.exception.ContainerNotFoundException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 CloseConnectionInputStream (org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream)1 DockerConnection (org.eclipse.che.plugin.docker.client.connection.DockerConnection)1 DockerResponse (org.eclipse.che.plugin.docker.client.connection.DockerResponse)1 ContainerNotFoundException (org.eclipse.che.plugin.docker.client.exception.ContainerNotFoundException)1