Search in sources :

Example 1 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class WaitService method prepareWaitCheckers.

private List<WaitChecker> prepareWaitCheckers(ImageConfiguration imageConfig, Properties projectProperties, String containerId) throws IOException {
    WaitConfiguration wait = getWaitConfiguration(imageConfig);
    if (wait == null) {
        return Collections.emptyList();
    }
    List<WaitChecker> checkers = new ArrayList<>();
    if (wait.getUrl() != null) {
        checkers.add(getUrlWaitChecker(imageConfig.getDescription(), projectProperties, wait));
    }
    if (wait.getLog() != null) {
        log.debug("LogWaitChecker: Waiting on %s", wait.getLog());
        checkers.add(new LogWaitChecker(wait.getLog(), dockerAccess, containerId, log));
    }
    if (wait.getTcp() != null) {
        try {
            Container container = queryService.getMandatoryContainer(containerId);
            checkers.add(getTcpWaitChecker(container, imageConfig.getDescription(), projectProperties, wait.getTcp()));
        } catch (DockerAccessException e) {
            throw new IOException("Unable to access container " + containerId, e);
        }
    }
    if (wait.getHealthy() == Boolean.TRUE) {
        checkers.add(new HealthCheckChecker(dockerAccess, containerId, imageConfig.getDescription(), log));
    }
    if (wait.getExit() != null) {
        checkers.add(new ExitCodeChecker(wait.getExit(), queryService, containerId));
    }
    return checkers;
}
Also used : WaitConfiguration(org.eclipse.jkube.kit.config.image.WaitConfiguration) HealthCheckChecker(org.eclipse.jkube.kit.build.service.docker.wait.HealthCheckChecker) Container(org.eclipse.jkube.kit.build.api.model.Container) LogWaitChecker(org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) ArrayList(java.util.ArrayList) ExitCodeChecker(org.eclipse.jkube.kit.build.service.docker.wait.ExitCodeChecker) IOException(java.io.IOException) WaitChecker(org.eclipse.jkube.kit.build.service.docker.wait.WaitChecker) LogWaitChecker(org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker)

Example 2 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClientMockitoTest method pullImageThrowsException.

@Test
public void pullImageThrowsException() throws Exception {
    // Given
    when(mockDelegate.post(eq("tcp://1.2.3.4:2375/v1.18/images/create"), isNull(), any(Map.class), any(HcChunkedResponseHandlerWrapper.class), eq(200))).thenThrow(new IOException("Problem with images/create"));
    // When
    final DockerAccessException result = assertThrows(DockerAccessException.class, () -> client.pullImage("name", null, "registry", new CreateImageOptions()));
    // Then
    assertThat(result).hasMessageStartingWith("Unable to pull 'name' from registry 'registry'").hasMessageEndingWith("Problem with images/create");
}
Also used : CreateImageOptions(org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) IOException(java.io.IOException) Map(java.util.Map) Test(org.junit.Test)

Example 3 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClientTest method testRetriesExceeded.

@Test
public void testRetriesExceeded() throws Exception {
    givenAnImageName("test");
    givenANumberOfRetries(1);
    givenThePushWillFail(1);
    DockerAccessException dae = assertThrows(DockerAccessException.class, this::whenPushImage);
    assertThat(dae).isNotNull();
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) Test(org.junit.Test)

Example 4 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClientTest method testSaveImageFail.

@Test
public void testSaveImageFail() throws IOException {
    givenAnImageName("test");
    givenFilename("test.tar");
    givenCompression(ArchiveCompression.none);
    givenTheGetWillFail();
    DockerAccessException dae = assertThrows(DockerAccessException.class, this::whenSaveImage);
    assertThat(dae).isNotNull();
}
Also used : DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) Test(org.junit.Test)

Example 5 with DockerAccessException

use of org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException in project jkube by eclipse.

the class DockerAccessWithHcClient method getContainersForImage.

@Override
public List<Container> getContainersForImage(String image, boolean all) throws DockerAccessException {
    String url;
    String serverApiVersion = getServerApiVersion();
    if (EnvUtil.greaterOrEqualsVersion(serverApiVersion, "1.23")) {
        // For Docker >= 1.11 we can use a new filter when listing containers
        url = urlBuilder.listContainers(all, "ancestor", image);
    } else {
        // For older versions (< Docker 1.11) we need to iterate over the containers.
        url = urlBuilder.listContainers(all);
    }
    try {
        String response = delegate.get(url, HTTP_OK);
        JsonArray array = JsonFactory.newJsonArray(response);
        List<Container> containers = new ArrayList<>();
        for (int i = 0; i < array.size(); i++) {
            JsonObject element = array.get(i).getAsJsonObject();
            if (image.equals(element.get("Image").getAsString())) {
                containers.add(new ContainersListElement(element));
            }
        }
        return containers;
    } catch (IOException e) {
        throw new DockerAccessException(e.getMessage());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) Container(org.eclipse.jkube.kit.build.api.model.Container) ContainersListElement(org.eclipse.jkube.kit.build.api.model.ContainersListElement) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Aggregations

DockerAccessException (org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException)28 IOException (java.io.IOException)21 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 ImageName (org.eclipse.jkube.kit.config.image.ImageName)3 JsonArray (com.google.gson.JsonArray)2 File (java.io.File)2 HttpResponseException (org.apache.http.client.HttpResponseException)2 Container (org.eclipse.jkube.kit.build.api.model.Container)2 Map (java.util.Map)1 ContainerDetails (org.eclipse.jkube.kit.build.api.model.ContainerDetails)1 ContainersListElement (org.eclipse.jkube.kit.build.api.model.ContainersListElement)1 Network (org.eclipse.jkube.kit.build.api.model.Network)1 NetworksListElement (org.eclipse.jkube.kit.build.api.model.NetworksListElement)1 BuildOptions (org.eclipse.jkube.kit.build.service.docker.access.BuildOptions)1 CreateImageOptions (org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions)1 ExitCodeChecker (org.eclipse.jkube.kit.build.service.docker.wait.ExitCodeChecker)1 HealthCheckChecker (org.eclipse.jkube.kit.build.service.docker.wait.HealthCheckChecker)1 LogWaitChecker (org.eclipse.jkube.kit.build.service.docker.wait.LogWaitChecker)1