Search in sources :

Example 1 with ExecStart

use of org.eclipse.che.plugin.docker.client.json.ExecStart 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();
            }
        }
    }
}
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) ExecStart(org.eclipse.che.plugin.docker.client.json.ExecStart)

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 ExecStart (org.eclipse.che.plugin.docker.client.json.ExecStart)1