use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method updateNode.
@Override
public void updateNode(final String nodeId, final Long version, final NodeSpec nodeSpec) throws DockerException, InterruptedException {
assertApiVersionIsAbove("1.24");
WebTarget resource = resource().path("nodes").path(nodeId).path("update").queryParam("version", version);
try {
request(POST, String.class, resource, resource.request(APPLICATION_JSON_TYPE), Entity.json(nodeSpec));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new NodeNotFoundException(nodeId);
case 503:
throw new NonSwarmNodeException("Node " + nodeId + " is not a swarm node", e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method tag.
@Override
public void tag(final String image, final String name, final boolean force) throws DockerException, InterruptedException {
final ImageRef imageRef = new ImageRef(name);
WebTarget resource = resource().path("images").path(image).path("tag");
resource = resource.queryParam("repo", imageRef.getImage());
if (imageRef.getTag() != null) {
resource = resource.queryParam("tag", imageRef.getTag());
}
if (force) {
resource = resource.queryParam("force", true);
}
try {
request(POST, resource, resource.request());
} catch (DockerRequestException e) {
switch(e.status()) {
case 400:
throw new BadParamException(getQueryParamMap(resource), e);
case 404:
throw new ImageNotFoundException(image, e);
case 409:
throw new ConflictException(e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClient method removeNetwork.
@Override
public void removeNetwork(String networkId) throws DockerException, InterruptedException {
try {
final WebTarget resource = resource().path("networks").path(networkId);
request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new NetworkNotFoundException(networkId, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project docker-client by spotify.
the class DefaultDockerClientTest method testResizeTty.
@Test
public void testResizeTty() throws Exception {
sut.pull(BUSYBOX_LATEST);
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX_LATEST).cmd("/bin/sh", "-c", "while :; do sleep 1; done").build();
final ContainerCreation creation = sut.createContainer(config, randomName());
final String id = creation.id();
try {
sut.resizeTty(id, 100, 0);
fail("Should get an exception resizing TTY with width=0");
} catch (BadParamException e) {
final Map<String, String> params = e.getParams();
assertThat(params, hasKey("w"));
assertEquals("0", params.get("w"));
}
try {
sut.resizeTty(id, 100, 80);
fail("Should get an exception resizing TTY for non-running container");
} catch (DockerRequestException e) {
if (dockerApiVersionLessThan("1.20")) {
assertEquals(String.format("Cannot resize container %s, container is not running\n", id), e.getResponseBody());
} else if (dockerApiVersionLessThan("1.24")) {
assertEquals(String.format("Container %s is not running\n", id), e.getResponseBody());
} else {
final ObjectMapper mapper = ObjectMapperProvider.objectMapper();
final Map<String, String> jsonMessage = mapper.readValue(e.getResponseBody(), new TypeReference<Map<String, String>>() {
});
assertThat(jsonMessage, hasKey("message"));
assertEquals(String.format("Container %s is not running", id), jsonMessage.get("message"));
}
}
sut.startContainer(id);
sut.resizeTty(id, 100, 80);
// We didn't get an exception, so everything went fine
}
use of com.spotify.docker.client.exceptions.DockerRequestException in project helios by spotify.
the class DockerDaemonHealthCheckerTest method testUnhealthy.
@Test
public void testUnhealthy() throws Exception {
when(dockerClient.ping()).thenThrow(new DockerRequestException("GET", new URI("/ping"), 500, null, null));
final HealthCheck.Result result = sut.check();
assertThat(result.isHealthy(), is(false));
}
Aggregations