Search in sources :

Example 1 with ExecNotFoundException

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

the class DefaultDockerClient method execResizeTty.

@Override
public void execResizeTty(final String execId, final Integer height, final Integer width) throws DockerException, InterruptedException {
    checkTtyParams(height, width);
    WebTarget resource = resource().path("exec").path(execId).path("resize");
    if (height != null && height > 0) {
        resource = resource.queryParam("h", height);
    }
    if (width != null && width > 0) {
        resource = resource.queryParam("w", width);
    }
    try {
        request(POST, resource, resource.request(TEXT_PLAIN_TYPE));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ExecNotFoundException(execId, e);
            default:
                throw e;
        }
    }
}
Also used : DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget) ExecNotFoundException(com.spotify.docker.client.exceptions.ExecNotFoundException)

Example 2 with ExecNotFoundException

use of com.spotify.docker.client.exceptions.ExecNotFoundException 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

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