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