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;
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
}
}
Aggregations