use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.
the class DockerConnector method startExec.
/**
* Starts a previously set up exec instance.
*
* @param execOutputProcessor
* processor for exec output
* @throws IOException
* when a problem occurs with docker api calls
*/
public void startExec(final StartExecParams params, @Nullable MessageProcessor<LogMessage> execOutputProcessor) throws IOException {
final ExecStart execStart = new ExecStart().withDetach(params.isDetach() == Boolean.TRUE).withTty(params.isTty() == Boolean.TRUE);
byte[] entityBytesArray = toJson(execStart).getBytes(StandardCharsets.UTF_8);
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("POST").path(apiVersionPathPrefix + "/exec/" + params.getExecId() + "/start").header("Content-Type", MediaType.APPLICATION_JSON).header("Content-Length", entityBytesArray.length).entity(entityBytesArray)) {
final DockerResponse response = connection.request();
final int status = response.getStatus();
// in fact docker API returns 200 or 204 status.
if (status / 100 != 2) {
throw getDockerException(response);
}
if (status != NO_CONTENT.getStatusCode() && execOutputProcessor != null) {
try (InputStream responseStream = response.getInputStream()) {
new LogMessagePumper(responseStream, execOutputProcessor).start();
}
}
}
}
use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.
the class DockerConnector method inspectContainer.
/**
* Gets detailed information about docker container.
*
* @return detailed information about {@code container}
* @throws IOException
* when a problem occurs with docker api calls
*/
public ContainerInfo inspectContainer(final InspectContainerParams params) throws IOException {
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("GET").path(apiVersionPathPrefix + "/containers/" + params.getContainer() + "/json")) {
addQueryParamIfNotNull(connection, "size", params.isReturnContainerSize());
final DockerResponse response = connection.request();
if (OK.getStatusCode() != response.getStatus()) {
throw getDockerException(response);
}
return parseResponseStreamAndClose(response.getInputStream(), ContainerInfo.class);
}
}
use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.
the class DockerConnector method removeNetwork.
/**
* Removes network matching provided params
*
* @throws NetworkNotFoundException
* if network is not found
* @throws IOException
* when a problem occurs with docker api calls
*/
public void removeNetwork(RemoveNetworkParams params) throws IOException {
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("DELETE").path(apiVersionPathPrefix + "/networks/" + params.getNetworkId())) {
final DockerResponse response = connection.request();
int status = response.getStatus();
if (status == 404) {
throw new NetworkNotFoundException(readAndCloseQuietly(response.getInputStream()));
}
if (status / 100 != 2) {
throw getDockerException(response);
}
}
}
use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.
the class DockerConnector method removeImage.
/**
* Removes docker image.
*
* @throws IOException
* when a problem occurs with docker api calls
*/
public void removeImage(final RemoveImageParams params) throws IOException {
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("DELETE").path(apiVersionPathPrefix + "/images/" + params.getImage())) {
addQueryParamIfNotNull(connection, "force", params.isForce());
final DockerResponse response = connection.request();
if (OK.getStatusCode() != response.getStatus()) {
throw getDockerException(response);
}
}
}
use of org.eclipse.che.plugin.docker.client.connection.DockerResponse in project che by eclipse.
the class DockerConnector method getResource.
/**
* Gets files from the specified container.
*
* @return stream of resources from the specified container filesystem, with retention connection
* @throws IOException
* when a problem occurs with docker api calls
* @apiNote this method implements 1.20 docker API and requires docker not less than 1.8.0 version
*/
public InputStream getResource(final GetResourceParams params) throws IOException {
DockerConnection connection = null;
try {
connection = connectionFactory.openConnection(dockerDaemonUri).method("GET").path(apiVersionPathPrefix + "/containers/" + params.getContainer() + "/archive").query("path", params.getSourcePath());
final DockerResponse response = connection.request();
if (response.getStatus() != OK.getStatusCode()) {
throw getDockerException(response);
}
return new CloseConnectionInputStream(response.getInputStream(), connection);
} catch (IOException io) {
connection.close();
throw io;
}
}
Aggregations