use of com.spotify.docker.client.exceptions.ImageNotFoundException in project helios by spotify.
the class SystemTestBase method assertDockerReachable.
private void assertDockerReachable(final int probePort) throws Exception {
try (final DockerClient docker = getNewDockerClient()) {
// Pull our base images
try {
docker.inspectImage(BUSYBOX);
} catch (ImageNotFoundException e) {
docker.pull(BUSYBOX);
}
try {
docker.inspectImage(ALPINE);
} catch (ImageNotFoundException e) {
docker.pull(ALPINE);
}
// Start a container with an exposed port
final HostConfig hostConfig = HostConfig.builder().portBindings(ImmutableMap.of("4711/tcp", singletonList(PortBinding.of("0.0.0.0", probePort)))).build();
final ContainerConfig config = ContainerConfig.builder().image(BUSYBOX).cmd("nc", "-p", "4711", "-lle", "cat").exposedPorts(ImmutableSet.of("4711/tcp")).hostConfig(hostConfig).build();
final ContainerCreation creation = docker.createContainer(config, testTag + "-probe");
final String containerId = creation.id();
docker.startContainer(containerId);
// Wait for container to come up
Polling.await(5, SECONDS, new Callable<Object>() {
@Override
public Object call() throws Exception {
final ContainerInfo info = docker.inspectContainer(containerId);
return info.state().running() ? true : null;
}
});
log.info("Verifying that docker containers are reachable");
try {
Polling.awaitUnchecked(5, SECONDS, new Callable<Object>() {
@Override
public Object call() throws Exception {
log.info("Probing: {}:{}", DOCKER_HOST.address(), probePort);
try (final Socket ignored = new Socket(DOCKER_HOST.address(), probePort)) {
return true;
} catch (IOException e) {
return false;
}
}
});
} catch (TimeoutException e) {
fail("Please ensure that DOCKER_HOST is set to an address that where containers can " + "be reached. If docker is running in a local VM, DOCKER_HOST must be set to the " + "address of that VM. If docker can only be reached on a limited port range, " + "set the environment variable DOCKER_PORT_RANGE=start:end");
}
docker.killContainer(containerId);
}
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project helios by spotify.
the class TaskRunner method pullImage.
private void pullImage(final String image) throws DockerException, InterruptedException {
listener.pulling();
DockerTimeoutException wasTimeout = null;
final Stopwatch pullTime = Stopwatch.createStarted();
// Attempt to pull. Failure, while less than ideal, is ok.
try {
docker.pull(image);
listener.pulled();
log.info("Pulled image {} in {}s", image, pullTime.elapsed(SECONDS));
} catch (DockerTimeoutException e) {
log.warn("Pulling image {} failed with timeout after {}s", image, pullTime.elapsed(SECONDS), e);
listener.pullFailed();
wasTimeout = e;
} catch (DockerException e) {
log.warn("Pulling image {} failed after {}s", image, pullTime.elapsed(SECONDS), e);
listener.pullFailed();
}
try {
// If we don't have the image by now, fail.
docker.inspectImage(image);
} catch (ImageNotFoundException e) {
// to know, as the pull should have fixed the not found-ness.
if (wasTimeout != null) {
throw new ImagePullFailedException("Failed pulling image " + image + " because of timeout", wasTimeout);
}
throw e;
}
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project helios by spotify.
the class TaskMonitorTest method verifyImageMissingTrumpsFlappingState.
@Test
public void verifyImageMissingTrumpsFlappingState() throws Exception {
when(flapController.isFlapping()).thenReturn(true);
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();
}
use of com.spotify.docker.client.exceptions.ImageNotFoundException in project flink by apache.
the class GCloudEmulatorManager method launchDocker.
public static void launchDocker() throws DockerException, InterruptedException, DockerCertificateException {
// Create a client based on DOCKER_HOST and DOCKER_CERT_PATH env vars
docker = DefaultDockerClient.fromEnv().build();
terminateAndDiscardAnyExistingContainers(true);
LOG.info("");
LOG.info("/===========================================");
LOG.info("| GCloud Emulator");
ContainerInfo containerInfo;
String id;
try {
docker.inspectImage(DOCKER_IMAGE_NAME);
} catch (ImageNotFoundException e) {
// No such image so we must download it first.
LOG.info("| - Getting docker image \"{}\"", DOCKER_IMAGE_NAME);
docker.pull(DOCKER_IMAGE_NAME, message -> {
if (message.id() != null && message.progress() != null) {
LOG.info("| - Downloading > {} : {}", message.id(), message.progress());
}
});
}
// No such container. Good, we create one!
LOG.info("| - Creating new container");
// Bind container ports to host ports
final Map<String, List<PortBinding>> portBindings = new HashMap<>();
portBindings.put(INTERNAL_PUBSUB_PORT, Collections.singletonList(PortBinding.randomPort("0.0.0.0")));
final HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();
// Create new container with exposed ports
final ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).exposedPorts(INTERNAL_PUBSUB_PORT).image(DOCKER_IMAGE_NAME).cmd("sh", "-c", "mkdir -p /opt/data/pubsub ; gcloud beta emulators pubsub start --data-dir=/opt/data/pubsub --host-port=0.0.0.0:" + INTERNAL_PUBSUB_PORT).build();
LOG.debug("Launching container with configuration {}", containerConfig);
final ContainerCreation creation = docker.createContainer(containerConfig, CONTAINER_NAME_JUNIT);
id = creation.id();
containerInfo = docker.inspectContainer(id);
if (!containerInfo.state().running()) {
LOG.warn("| - Starting it up ....");
docker.startContainer(id);
Thread.sleep(1000);
}
containerInfo = docker.inspectContainer(id);
dockerIpAddress = "127.0.0.1";
Map<String, List<PortBinding>> ports = containerInfo.networkSettings().ports();
assertNotNull("Unable to retrieve the ports where to connect to the emulators", ports);
assertEquals("We expect 1 port to be mapped", 1, ports.size());
pubsubPort = getPort(ports, INTERNAL_PUBSUB_PORT, "PubSub");
LOG.info("| Waiting for the emulators to be running");
// PubSub exposes an "Ok" at the root url when running.
if (!waitForOkStatus("PubSub", pubsubPort)) {
// Oops, we did not get an "Ok" within 10 seconds
startHasFailedKillEverything();
}
LOG.info("\\===========================================");
LOG.info("");
}
Aggregations