Search in sources :

Example 1 with ExecStartConflictException

use of com.spotify.docker.client.exceptions.ExecStartConflictException in project docker-client by spotify.

the class DefaultDockerClient method execStart.

@Override
public LogStream execStart(final String execId, final ExecStartParameter... params) throws DockerException, InterruptedException {
    final WebTarget resource = noTimeoutResource().path("exec").path(execId).path("start");
    final StringWriter writer = new StringWriter();
    try {
        final JsonGenerator generator = objectMapper().getFactory().createGenerator(writer);
        generator.writeStartObject();
        for (final ExecStartParameter param : params) {
            generator.writeBooleanField(param.getName(), true);
        }
        generator.writeEndObject();
        generator.close();
    } catch (IOException e) {
        throw new DockerException(e);
    }
    try {
        return request(POST, LogStream.class, resource, resource.request("application/vnd.docker.raw-stream"), Entity.json(writer.toString()));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ExecNotFoundException(execId, e);
            case 409:
                throw new ExecStartConflictException(execId, e);
            default:
                throw e;
        }
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) StringWriter(java.io.StringWriter) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) WebTarget(javax.ws.rs.client.WebTarget) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ExecNotFoundException(com.spotify.docker.client.exceptions.ExecNotFoundException) ExecStartConflictException(com.spotify.docker.client.exceptions.ExecStartConflictException)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 DockerException (com.spotify.docker.client.exceptions.DockerException)1 DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)1 ExecNotFoundException (com.spotify.docker.client.exceptions.ExecNotFoundException)1 ExecStartConflictException (com.spotify.docker.client.exceptions.ExecStartConflictException)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 StringWriter (java.io.StringWriter)1 WebTarget (javax.ws.rs.client.WebTarget)1