use of com.spotify.docker.client.exceptions.BadParamException in project docker-client by spotify.
the class DefaultDockerClient method listContainers.
@Override
public List<Container> listContainers(final ListContainersParam... params) throws DockerException, InterruptedException {
WebTarget resource = resource().path("containers").path("json");
resource = addParameters(resource, params);
try {
return request(GET, CONTAINER_LIST, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (DockerRequestException e) {
switch(e.status()) {
case 400:
throw new BadParamException(getQueryParamMap(resource), e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.BadParamException in project docker-client by spotify.
the class DefaultDockerClient method removeContainer.
@Override
public void removeContainer(final String containerId, final RemoveContainerParam... params) throws DockerException, InterruptedException {
try {
WebTarget resource = resource().path("containers").path(containerId);
for (final RemoveContainerParam param : params) {
resource = resource.queryParam(param.name(), param.value());
}
request(DELETE, resource, resource.request(APPLICATION_JSON_TYPE));
} catch (DockerRequestException e) {
switch(e.status()) {
case 400:
throw new BadParamException(getQueryParamMap(resource()), e);
case 404:
throw new ContainerNotFoundException(containerId, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.BadParamException 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.BadParamException 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
}
Aggregations