Search in sources :

Example 16 with DockerRequestException

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

the class DefaultDockerClient method updateConfig.

@Override
public void updateConfig(final String configId, final Long version, final ConfigSpec nodeSpec) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.30");
    final WebTarget resource = resource().path("configs").path(configId).path("update").queryParam("version", version);
    try {
        request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(nodeSpec));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new NotFoundException("Config " + configId + " not found.");
            case 503:
                throw new NonSwarmNodeException("Config not part of a swarm.", e);
            default:
                throw e;
        }
    }
}
Also used : DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) TaskNotFoundException(com.spotify.docker.client.exceptions.TaskNotFoundException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) NotFoundException(com.spotify.docker.client.exceptions.NotFoundException) NodeNotFoundException(com.spotify.docker.client.exceptions.NodeNotFoundException) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) ServiceNotFoundException(com.spotify.docker.client.exceptions.ServiceNotFoundException) ExecNotFoundException(com.spotify.docker.client.exceptions.ExecNotFoundException) VolumeNotFoundException(com.spotify.docker.client.exceptions.VolumeNotFoundException) NetworkNotFoundException(com.spotify.docker.client.exceptions.NetworkNotFoundException) WebTarget(javax.ws.rs.client.WebTarget) NonSwarmNodeException(com.spotify.docker.client.exceptions.NonSwarmNodeException)

Example 17 with DockerRequestException

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

the class DefaultDockerClient method listContainers.

@Override
public List<Container> listContainers(final ListContainersParam... params) throws DockerException, InterruptedException {
    WebTarget resource = resource().path("containers").path("json");
    resource = addParameters(resource, params);
    try {
        return request(GET, CONTAINER_LIST, resource, resource.request(APPLICATION_JSON_TYPE));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 400:
                throw new BadParamException(getQueryParamMap(resource), e);
            default:
                throw e;
        }
    }
}
Also used : BadParamException(com.spotify.docker.client.exceptions.BadParamException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget)

Example 18 with DockerRequestException

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

the class DefaultDockerClient method inspectSecret.

@Override
public Secret inspectSecret(final String secretId) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.25");
    final WebTarget resource = resource().path("secrets").path(secretId);
    try {
        return request(GET, Secret.class, resource, resource.request(APPLICATION_JSON_TYPE));
    } catch (final DockerRequestException ex) {
        switch(ex.status()) {
            case 404:
                throw new NotFoundException("Secret " + secretId + " not found.", ex);
            case 406:
                throw new NonSwarmNodeException("Server not part of swarm.", ex);
            default:
                throw ex;
        }
    }
}
Also used : DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) TaskNotFoundException(com.spotify.docker.client.exceptions.TaskNotFoundException) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) NotFoundException(com.spotify.docker.client.exceptions.NotFoundException) NodeNotFoundException(com.spotify.docker.client.exceptions.NodeNotFoundException) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) ServiceNotFoundException(com.spotify.docker.client.exceptions.ServiceNotFoundException) ExecNotFoundException(com.spotify.docker.client.exceptions.ExecNotFoundException) VolumeNotFoundException(com.spotify.docker.client.exceptions.VolumeNotFoundException) NetworkNotFoundException(com.spotify.docker.client.exceptions.NetworkNotFoundException) WebTarget(javax.ws.rs.client.WebTarget) NonSwarmNodeException(com.spotify.docker.client.exceptions.NonSwarmNodeException)

Example 19 with DockerRequestException

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

the class DefaultDockerClient method pull.

@Override
public void pull(final String image, final RegistryAuth registryAuth, final ProgressHandler handler) throws DockerException, InterruptedException {
    final ImageRef imageRef = new ImageRef(image);
    WebTarget resource = resource().path("images").path("create");
    resource = resource.queryParam("fromImage", imageRef.getImage());
    if (imageRef.getTag() != null) {
        resource = resource.queryParam("tag", imageRef.getTag());
    }
    try (ProgressStream pull = request(POST, ProgressStream.class, resource, resource.request(APPLICATION_JSON_TYPE).header("X-Registry-Auth", authHeader(registryAuth)))) {
        pull.tail(handler, POST, resource.getUri());
    } catch (IOException e) {
        throw new DockerException(e);
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ImageNotFoundException(image, 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) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException)

Example 20 with DockerRequestException

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

the class DefaultDockerClient method createConfig.

@Override
public ConfigCreateResponse createConfig(final ConfigSpec config) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.30");
    final WebTarget resource = resource().path("configs").path("create");
    try {
        return request(POST, ConfigCreateResponse.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(config));
    } catch (final DockerRequestException ex) {
        switch(ex.status()) {
            case 503:
                throw new NonSwarmNodeException("Server not part of swarm.", ex);
            case 409:
                throw new ConflictException("Name conflicts with an existing object.", ex);
            default:
                throw ex;
        }
    }
}
Also used : DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) ContainerRenameConflictException(com.spotify.docker.client.exceptions.ContainerRenameConflictException) ConflictException(com.spotify.docker.client.exceptions.ConflictException) ExecStartConflictException(com.spotify.docker.client.exceptions.ExecStartConflictException) ExecCreateConflictException(com.spotify.docker.client.exceptions.ExecCreateConflictException) 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