Search in sources :

Example 11 with DockerRequestException

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

the class DefaultDockerClient method leaveSwarm.

@Override
public void leaveSwarm(final boolean force) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.24");
    try {
        final WebTarget resource = resource().path("swarm").path("leave").queryParam("force", force);
        request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 500:
                throw new DockerException("server error", e);
            case 503:
                throw new DockerException("node is not 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 12 with DockerRequestException

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

the class DefaultDockerClient method renameContainer.

@Override
public void renameContainer(final String containerId, final String name) throws DockerException, InterruptedException {
    WebTarget resource = resource().path("containers").path(containerId).path("rename");
    if (name == null) {
        throw new IllegalArgumentException("Cannot rename container to null");
    }
    checkArgument(CONTAINER_NAME_PATTERN.matcher(name).matches(), "Invalid container name: \"%s\"", name);
    resource = resource.queryParam("name", name);
    log.info("Renaming container with id {}. New name {}.", containerId, name);
    try {
        request(POST, resource, resource.request());
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ContainerNotFoundException(containerId, e);
            case 409:
                throw new ContainerRenameConflictException(containerId, name, e);
            default:
                throw e;
        }
    }
}
Also used : ContainerRenameConflictException(com.spotify.docker.client.exceptions.ContainerRenameConflictException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException)

Example 13 with DockerRequestException

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

the class DefaultDockerClient method containerAction.

private void containerAction(final String containerId, final String action, final MultivaluedMap<String, String> queryParameters) throws DockerException, InterruptedException {
    try {
        WebTarget resource = resource().path("containers").path(containerId).path(action);
        for (Map.Entry<String, List<String>> queryParameter : queryParameters.entrySet()) {
            for (String parameterValue : queryParameter.getValue()) {
                resource = resource.queryParam(queryParameter.getKey(), parameterValue);
            }
        }
        request(POST, resource, resource.request());
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ContainerNotFoundException(containerId, e);
            default:
                throw e;
        }
    }
}
Also used : 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) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException)

Example 14 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() throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.30");
    final WebTarget resource = resource().path("configs");
    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 : DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget) NonSwarmNodeException(com.spotify.docker.client.exceptions.NonSwarmNodeException)

Example 15 with DockerRequestException

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

the class DefaultDockerClient method deleteConfig.

@Override
public void deleteConfig(final String configId) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.30");
    final WebTarget resource = resource().path("configs").path(configId);
    try {
        request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE));
    } catch (final DockerRequestException ex) {
        switch(ex.status()) {
            case 404:
                throw new NotFoundException("Config " + configId + " not found.", ex);
            case 503:
                throw new NonSwarmNodeException("Config not part of a 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)

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