Search in sources :

Example 1 with NonSwarmNodeException

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

the class DefaultDockerClient method inspectConfig.

@Override
public Config inspectConfig(final String configId) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.30");
    final WebTarget resource = resource().path("configs").path(configId);
    try {
        return request(GET, Config.class, 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 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 2 with NonSwarmNodeException

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

the class DefaultDockerClient method createSecret.

@Override
public SecretCreateResponse createSecret(final SecretSpec secret) throws DockerException, InterruptedException {
    assertApiVersionIsAbove("1.25");
    final WebTarget resource = resource().path("secrets").path("create");
    try {
        return request(POST, SecretCreateResponse.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(secret));
    } catch (final DockerRequestException ex) {
        switch(ex.status()) {
            case 406:
                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)

Example 3 with NonSwarmNodeException

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

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

Example 5 with NonSwarmNodeException

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

Aggregations

DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)11 NonSwarmNodeException (com.spotify.docker.client.exceptions.NonSwarmNodeException)11 WebTarget (javax.ws.rs.client.WebTarget)11 NodeNotFoundException (com.spotify.docker.client.exceptions.NodeNotFoundException)7 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)4 ExecNotFoundException (com.spotify.docker.client.exceptions.ExecNotFoundException)4 ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)4 NetworkNotFoundException (com.spotify.docker.client.exceptions.NetworkNotFoundException)4 NotFoundException (com.spotify.docker.client.exceptions.NotFoundException)4 ServiceNotFoundException (com.spotify.docker.client.exceptions.ServiceNotFoundException)4 TaskNotFoundException (com.spotify.docker.client.exceptions.TaskNotFoundException)4 VolumeNotFoundException (com.spotify.docker.client.exceptions.VolumeNotFoundException)4 ConflictException (com.spotify.docker.client.exceptions.ConflictException)2 ContainerRenameConflictException (com.spotify.docker.client.exceptions.ContainerRenameConflictException)2 ExecCreateConflictException (com.spotify.docker.client.exceptions.ExecCreateConflictException)2 ExecStartConflictException (com.spotify.docker.client.exceptions.ExecStartConflictException)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 VolumeList (com.spotify.docker.client.messages.VolumeList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1