use of com.spotify.docker.client.exceptions.ImageNotFoundException in project docker-client by spotify.
the class DefaultDockerClientTest method testLoad.
@Test
public void testLoad() throws Exception {
// Ensure the local Docker instance has the busybox image so that save() will work
sut.pull(BUSYBOX_LATEST);
// duplicate busybox with another name
final String image1 = BUSYBOX + "test1" + System.nanoTime() + ":latest";
final String image2 = BUSYBOX + "test2" + System.nanoTime() + ":latest";
try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(save(BUSYBOX_LATEST)))) {
sut.create(image1, imagePayload);
}
try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(save(BUSYBOX_LATEST)))) {
sut.create(image2, imagePayload);
}
final File imagesFile = save(image1, image2);
// Remove image from the local Docker instance to test the load
sut.removeImage(image1);
sut.removeImage(image2);
// Try to inspect deleted images and make sure ImageNotFoundException is thrown
try {
sut.inspectImage(image1);
fail("inspectImage should have thrown ImageNotFoundException");
} catch (ImageNotFoundException e) {
// we should get exception because we deleted image
}
try {
sut.inspectImage(image2);
fail("inspectImage should have thrown ImageNotFoundException");
} catch (ImageNotFoundException e) {
// we should get exception because we deleted image
}
final List<ProgressMessage> messages = new ArrayList<>();
final Set<String> loadedImages;
try (InputStream imageFileInputStream = new FileInputStream(imagesFile)) {
loadedImages = sut.load(imageFileInputStream, new ProgressHandler() {
@Override
public void progress(ProgressMessage message) throws DockerException {
messages.add(message);
}
});
}
if (dockerApiVersionAtLeast("1.24")) {
// Verify that both images are loaded
assertEquals(loadedImages.size(), 2);
assertTrue(loadedImages.contains(image1));
assertTrue(loadedImages.contains(image2));
}
if (dockerApiVersionAtLeast("1.23")) {
// Verify that we have multiple messages, and each one has a non-null field
assertThat(messages, not(empty()));
for (final ProgressMessage message : messages) {
assertTrue(message.error() != null || message.id() != null || message.progress() != null || message.progressDetail() != null || message.status() != null || message.stream() != null);
}
}
// Try to inspect created images and make sure ImageNotFoundException is not thrown
try {
sut.inspectImage(image1);
sut.inspectImage(image2);
} catch (ImageNotFoundException e) {
fail("image not properly loaded in the local Docker instance");
}
// Clean created image
sut.removeImage(image1);
sut.removeImage(image2);
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project docker-client by spotify.
the class DefaultDockerClient method pull.
@Override
public void pull(final String image, final RegistryAuth registryAuth, final ProgressHandler handler) throws DockerException, InterruptedException {
final ImageRef imageRef = new ImageRef(image);
WebTarget resource = resource().path("images").path("create");
resource = resource.queryParam("fromImage", imageRef.getImage());
if (imageRef.getTag() != null) {
resource = resource.queryParam("tag", imageRef.getTag());
}
try (ProgressStream pull = request(POST, ProgressStream.class, resource, resource.request(APPLICATION_JSON_TYPE).header("X-Registry-Auth", authHeader(registryAuth)))) {
pull.tail(handler, POST, resource.getUri());
} catch (IOException e) {
throw new DockerException(e);
} catch (DockerRequestException e) {
switch(e.status()) {
case 404:
throw new ImageNotFoundException(image, e);
default:
throw e;
}
}
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project helios by spotify.
the class HeliosSoloDeploymentTest method testDoesPullAbsentProbeImage.
@Test
public void testDoesPullAbsentProbeImage() throws Exception {
when(this.dockerClient.inspectImage(HeliosSoloDeployment.PROBE_IMAGE)).thenThrow(new ImageNotFoundException(HeliosSoloDeployment.PROBE_IMAGE));
buildHeliosSoloDeployment();
verify(this.dockerClient).pull(HeliosSoloDeployment.PROBE_IMAGE);
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project helios by spotify.
the class TaskRunnerTest method testPullTimeoutVariation.
@Test
public void testPullTimeoutVariation() throws Throwable {
doThrow(new DockerTimeoutException("x", new URI("http://example.com"), null)).when(mockDocker).pull(IMAGE);
doThrow(new ImageNotFoundException("not found")).when(mockDocker).inspectImage(IMAGE);
final TaskRunner tr = TaskRunner.builder().delayMillis(0).config(TaskConfig.builder().namespace("test").host(HOST).job(JOB).containerDecorators(ImmutableList.of(containerDecorator)).build()).docker(mockDocker).listener(new TaskRunner.NopListener()).build();
tr.run();
try {
tr.resultFuture().get();
fail("this should throw");
} catch (Exception t) {
assertTrue(t instanceof ExecutionException);
assertEquals(ImagePullFailedException.class, t.getCause().getClass());
}
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project helios by spotify.
the class TaskMonitorTest method verifyMonitorPropagatesImageMissing.
@Test
public void verifyMonitorPropagatesImageMissing() throws Exception {
sut.failed(new ImageNotFoundException("foobar", "not found"), "container error");
verify(statusUpdater).setThrottleState(IMAGE_MISSING);
verify(statusUpdater).setState(FAILED);
verify(statusUpdater).setContainerError("container error");
verify(statusUpdater).update();
}
Aggregations