Search in sources :

Example 21 with DockerResponse

use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.

the class DockerConnector method commit.

/**
     * Creates a new image from a container’s changes.
     *
     * @return id of a new image
     * @throws IOException
     *          when a problem occurs with docker api calls
     */
public String commit(final CommitParams params) throws IOException {
    // TODO: add option to pause container
    try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("POST").path(apiVersionPathPrefix + "/commit").query("container", params.getContainer())) {
        addQueryParamIfNotNull(connection, "repo", params.getRepository());
        addQueryParamIfNotNull(connection, "tag", params.getTag());
        addQueryParamIfNotNull(connection, "comment", (params.getComment() == null) ? null : URLEncoder.encode(params.getComment(), "UTF-8"));
        addQueryParamIfNotNull(connection, "author", (params.getAuthor() == null) ? null : URLEncoder.encode(params.getAuthor(), "UTF-8"));
        final DockerResponse response = connection.request();
        if (CREATED.getStatusCode() != response.getStatus()) {
            throw getDockerException(response);
        }
        return parseResponseStreamAndClose(response.getInputStream(), ContainerCommitted.class).getId();
    }
}
Also used : DockerConnection(org.eclipse.che.plugin.docker.client.connection.DockerConnection) ContainerCommitted(org.eclipse.che.plugin.docker.client.json.ContainerCommitted) DockerResponse(org.eclipse.che.plugin.docker.client.connection.DockerResponse)

Example 22 with DockerResponse

use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.

the class DockerConnector method getEvents.

/**
     * Get docker events.
     * Parameter {@code untilSecond} does nothing if {@code sinceSecond} is 0.<br>
     * If {@code untilSecond} and {@code sinceSecond} are 0 method gets new events only (streaming mode).<br>
     * If {@code untilSecond} and {@code sinceSecond} are not 0 (but less that current date)
     * methods get events that were generated between specified dates.<br>
     * If {@code untilSecond} is 0 but {@code sinceSecond} is not method gets old events and streams new ones.<br>
     * If {@code sinceSecond} is 0 no old events will be got.<br>
     * With some connection implementations method can fail due to connection timeout in streaming mode.
     *
     * @param messageProcessor
     *         processor of all found events that satisfy specified parameters
     * @throws IOException
     *          when a problem occurs with docker api calls
     */
public void getEvents(final GetEventsParams params, MessageProcessor<Event> messageProcessor) throws IOException {
    final Filters filters = params.getFilters();
    try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("GET").path(apiVersionPathPrefix + "/events")) {
        addQueryParamIfNotNull(connection, "since", params.getSinceSecond());
        addQueryParamIfNotNull(connection, "until", params.getUntilSecond());
        if (filters != null) {
            connection.query("filters", urlPathSegmentEscaper().escape(toJson(filters.getFilters())));
        }
        final DockerResponse response = connection.request();
        if (OK.getStatusCode() != response.getStatus()) {
            throw getDockerException(response);
        }
        try (InputStream responseStream = response.getInputStream()) {
            new MessagePumper<>(new JsonMessageReader<>(responseStream, Event.class), messageProcessor).start();
        }
    }
}
Also used : DockerConnection(org.eclipse.che.plugin.docker.client.connection.DockerConnection) Filters(org.eclipse.che.plugin.docker.client.json.Filters) 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)

Aggregations

DockerConnection (org.eclipse.che.plugin.docker.client.connection.DockerConnection)22 DockerResponse (org.eclipse.che.plugin.docker.client.connection.DockerResponse)22 CloseConnectionInputStream (org.eclipse.che.plugin.docker.client.connection.CloseConnectionInputStream)9 BufferedInputStream (java.io.BufferedInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 DockerException (org.eclipse.che.plugin.docker.client.exception.DockerException)4 ExecutionException (java.util.concurrent.ExecutionException)3 ProgressStatus (org.eclipse.che.plugin.docker.client.json.ProgressStatus)3 ImageNotFoundException (org.eclipse.che.plugin.docker.client.exception.ImageNotFoundException)2 Filters (org.eclipse.che.plugin.docker.client.json.Filters)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 List (java.util.List)1 ContainerNotFoundException (org.eclipse.che.plugin.docker.client.exception.ContainerNotFoundException)1 NetworkNotFoundException (org.eclipse.che.plugin.docker.client.exception.NetworkNotFoundException)1 ContainerCommitted (org.eclipse.che.plugin.docker.client.json.ContainerCommitted)1 ExecConfig (org.eclipse.che.plugin.docker.client.json.ExecConfig)1 ExecStart (org.eclipse.che.plugin.docker.client.json.ExecStart)1