use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method disconnectFromNetwork.
@Override
public void disconnectFromNetwork(String containerId, String networkId, boolean force) throws DockerException, InterruptedException {
final WebTarget resource = resource().path("networks").path(networkId).path("disconnect");
final Map<String, Object> request = new HashMap<>();
request.put("Container", containerId);
request.put("Force", force);
try {
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(request));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
final String message = String.format("Container %s or network %s not found.", containerId, networkId);
throw new NotFoundException(message, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method stopContainer.
@Override
public void stopContainer(final String containerId, final int secondsToWaitBeforeKilling) throws DockerException, InterruptedException {
try {
final WebTarget resource = noTimeoutResource().path("containers").path(containerId).path("stop").queryParam("t", String.valueOf(secondsToWaitBeforeKilling));
request(POST, resource, resource.request());
} catch (DockerRequestException e) {
switch(e.status()) {
case // already stopped, so we're cool
304:
return;
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 deleteSecret.
@Override
public void deleteSecret(final String secretId) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.25");
final WebTarget resource = resource().path("secrets").path(secretId);
try {
request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (final DockerRequestException ex) {
switch(ex.status()) {
case 404:
throw new NotFoundException("Secret " + secretId + " not found.", ex);
default:
throw ex;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method unlock.
@Override
public void unlock(final UnlockKey unlockKey) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.24");
try {
final WebTarget resource = resource().path("swarm").path("unlock");
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(unlockKey));
} 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 copyContainer.
@Override
@Deprecated
public InputStream copyContainer(String containerId, String path) throws DockerException, InterruptedException {
final String apiVersion = version().apiVersion();
final int versionComparison = compareVersion(apiVersion, "1.24");
// Version above 1.24
if (versionComparison >= 0) {
throw new UnsupportedApiVersionException(apiVersion);
}
final WebTarget resource = resource().path("containers").path(containerId).path("copy");
// Internal JSON object; not worth it to create class for this
final JsonNodeFactory nf = JsonNodeFactory.instance;
final JsonNode params = nf.objectNode().set("Resource", nf.textNode(path));
try {
return request(POST, InputStream.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE), Entity.json(params));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ContainerNotFoundException(containerId, e);
default:
throw e;
}
}
}
Aggregations