Search in sources :

Example 1 with UnsupportedApiVersionException

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

the class DefaultDockerClient method archiveContainer.

@Override
public InputStream archiveContainer(String containerId, String path) throws DockerException, InterruptedException {
    final String apiVersion = version().apiVersion();
    final int versionComparison = compareVersion(apiVersion, "1.20");
    // Version below 1.20
    if (versionComparison < 0) {
        throw new UnsupportedApiVersionException(apiVersion);
    }
    final WebTarget resource = resource().path("containers").path(containerId).path("archive").queryParam("path", path);
    try {
        return request(GET, InputStream.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ContainerNotFoundException(containerId, e);
            default:
                throw e;
        }
    }
}
Also used : UnsupportedApiVersionException(com.spotify.docker.client.exceptions.UnsupportedApiVersionException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException)

Example 2 with UnsupportedApiVersionException

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

the class DefaultDockerClient method copyContainer.

@Override
@Deprecated
public InputStream copyContainer(String containerId, String path) throws DockerException, InterruptedException {
    final String apiVersion = version().apiVersion();
    final int versionComparison = compareVersion(apiVersion, "1.24");
    // Version above 1.24
    if (versionComparison >= 0) {
        throw new UnsupportedApiVersionException(apiVersion);
    }
    final WebTarget resource = resource().path("containers").path(containerId).path("copy");
    // Internal JSON object; not worth it to create class for this
    final JsonNodeFactory nf = JsonNodeFactory.instance;
    final JsonNode params = nf.objectNode().set("Resource", nf.textNode(path));
    try {
        return request(POST, InputStream.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE), Entity.json(params));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ContainerNotFoundException(containerId, e);
            default:
                throw e;
        }
    }
}
Also used : UnsupportedApiVersionException(com.spotify.docker.client.exceptions.UnsupportedApiVersionException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) WebTarget(javax.ws.rs.client.WebTarget) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Aggregations

ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)2 DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)2 UnsupportedApiVersionException (com.spotify.docker.client.exceptions.UnsupportedApiVersionException)2 WebTarget (javax.ws.rs.client.WebTarget)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1