Search in sources :

Example 6 with DockerRequestException

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

the class DefaultDockerClient method joinSwarm.

@Override
public void joinSwarm(final SwarmJoin swarmJoin) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.24");
    try {
        final WebTarget resource = resource().path("swarm").path("join");
        request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(swarmJoin));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 400:
                throw new DockerException("bad parameter", e);
            case 500:
                throw new DockerException("server error", e);
            case 503:
                throw new DockerException("node is already part of a swarm", e);
            default:
                throw e;
        }
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget)

Example 7 with DockerRequestException

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

the class DefaultDockerClient method listConfigs.

@Override
public List<Config> listConfigs(final Config.Criteria criteria) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.30");
    final Map<String, List<String>> filters = new HashMap<>();
    if (criteria.configId() != null) {
        filters.put("id", Collections.singletonList(criteria.configId()));
    }
    if (criteria.label() != null) {
        filters.put("label", Collections.singletonList(criteria.label()));
    }
    if (criteria.name() != null) {
        filters.put("name", Collections.singletonList(criteria.name()));
    }
    final WebTarget resource = resource().path("configs").queryParam("filters", urlEncodeFilters(filters));
    try {
        return request(GET, CONFIG_LIST, resource, resource.request(APPLICATION_JSON_TYPE));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 503:
                throw new NonSwarmNodeException("node is not part of a swarm", e);
            default:
                throw e;
        }
    }
}
Also used : Maps.newHashMap(com.google.common.collect.Maps.newHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) ArrayList(java.util.ArrayList) VolumeList(com.spotify.docker.client.messages.VolumeList) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) NonSwarmNodeException(com.spotify.docker.client.exceptions.NonSwarmNodeException)

Example 8 with DockerRequestException

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

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

the class DefaultDockerClient method updateService.

@Override
public void updateService(final String serviceId, final Long version, final ServiceSpec spec, final RegistryAuth config) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.24");
    try {
        WebTarget resource = resource().path("services").path(serviceId).path("update");
        resource = resource.queryParam("version", version);
        request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE).header("X-Registry-Auth", authHeader(config)), Entity.json(spec));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ServiceNotFoundException(serviceId);
            default:
                throw e;
        }
    }
}
Also used : DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) ServiceNotFoundException(com.spotify.docker.client.exceptions.ServiceNotFoundException) WebTarget(javax.ws.rs.client.WebTarget)

Example 10 with DockerRequestException

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

the class DefaultDockerClient method inspectNode.

@Override
public NodeInfo inspectNode(final String nodeId) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.24");
    WebTarget resource = resource().path("nodes").path(nodeId);
    try {
        return request(GET, NodeInfo.class, resource, resource.request(APPLICATION_JSON_TYPE));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new NodeNotFoundException(nodeId);
            case 503:
                throw new NonSwarmNodeException("Node " + nodeId + " is not in a swarm", e);
            default:
                throw e;
        }
    }
}
Also used : NodeNotFoundException(com.spotify.docker.client.exceptions.NodeNotFoundException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget) NonSwarmNodeException(com.spotify.docker.client.exceptions.NonSwarmNodeException)

Aggregations

DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)45 WebTarget (javax.ws.rs.client.WebTarget)37 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)18 DockerException (com.spotify.docker.client.exceptions.DockerException)14 ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)12 NonSwarmNodeException (com.spotify.docker.client.exceptions.NonSwarmNodeException)11 NetworkNotFoundException (com.spotify.docker.client.exceptions.NetworkNotFoundException)9 NodeNotFoundException (com.spotify.docker.client.exceptions.NodeNotFoundException)9 ExecNotFoundException (com.spotify.docker.client.exceptions.ExecNotFoundException)8 NotFoundException (com.spotify.docker.client.exceptions.NotFoundException)8 ServiceNotFoundException (com.spotify.docker.client.exceptions.ServiceNotFoundException)8 VolumeNotFoundException (com.spotify.docker.client.exceptions.VolumeNotFoundException)8 ContainerRenameConflictException (com.spotify.docker.client.exceptions.ContainerRenameConflictException)7 TaskNotFoundException (com.spotify.docker.client.exceptions.TaskNotFoundException)6 Test (org.junit.Test)6 BadParamException (com.spotify.docker.client.exceptions.BadParamException)5 ConflictException (com.spotify.docker.client.exceptions.ConflictException)5 IOException (java.io.IOException)5 ExecCreateConflictException (com.spotify.docker.client.exceptions.ExecCreateConflictException)4 ExecStartConflictException (com.spotify.docker.client.exceptions.ExecStartConflictException)4