Search in sources :

Example 1 with ImageNotFoundException

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);
}
Also used : ProgressMessage(com.spotify.docker.client.messages.ProgressMessage) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) InputStream(java.io.InputStream) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) SecretFile(com.spotify.docker.client.messages.swarm.SecretFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with ImageNotFoundException

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;
        }
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) WebTarget(javax.ws.rs.client.WebTarget) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException)

Example 3 with ImageNotFoundException

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);
}
Also used : ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) Test(org.junit.Test)

Example 4 with ImageNotFoundException

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());
    }
}
Also used : ImagePullFailedException(com.spotify.docker.client.exceptions.ImagePullFailedException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) DockerException(com.spotify.docker.client.exceptions.DockerException) ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ImagePullFailedException(com.spotify.docker.client.exceptions.ImagePullFailedException) Test(org.junit.Test)

Example 5 with ImageNotFoundException

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();
}
Also used : ImageNotFoundException(com.spotify.docker.client.exceptions.ImageNotFoundException) Test(org.junit.Test)

Aggregations

ImageNotFoundException (com.spotify.docker.client.exceptions.ImageNotFoundException)14 DockerException (com.spotify.docker.client.exceptions.DockerException)7 Test (org.junit.Test)7 DockerRequestException (com.spotify.docker.client.exceptions.DockerRequestException)5 IOException (java.io.IOException)4 WebTarget (javax.ws.rs.client.WebTarget)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)2 DockerClient (com.spotify.docker.client.DockerClient)2 ContainerNotFoundException (com.spotify.docker.client.exceptions.ContainerNotFoundException)2 DockerTimeoutException (com.spotify.docker.client.exceptions.DockerTimeoutException)2 ImagePullFailedException (com.spotify.docker.client.exceptions.ImagePullFailedException)2 ContainerConfig (com.spotify.docker.client.messages.ContainerConfig)2 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)2 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)2 HostConfig (com.spotify.docker.client.messages.HostConfig)2 InterruptedIOException (java.io.InterruptedIOException)2 Long.toHexString (java.lang.Long.toHexString)2 ExecutionException (java.util.concurrent.ExecutionException)2 Stopwatch (com.google.common.base.Stopwatch)1