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