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;
}
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");
}
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();
}
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();
}
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());
}
}
Aggregations