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