private static void waitForCassandraContainer(Container container) { org.awaitility.Awaitility.await() .atMost(60, TimeUnit.SECONDS) .pollInterval(1, TimeUnit.SECONDS) .until(() -> { // TODO (jkong): hack String curlOutput = EteSetup.execCliCommand("ete1", String.format("bash -c 'curl %s:%s; echo $?; exit 0;'", container.getContainerName(), CASSANDRA_PORT)); return curlOutput.contains("52"); }); } }
@Override public Optional<String> id(Container container) throws IOException, InterruptedException { return id(container.getContainerName()); }
@Override public void up(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "up", "-d", container.getContainerName()); }
@Override public void start(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "start", container.getContainerName()); }
@Override public void kill(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "kill", container.getContainerName()); }
@Override public void kill(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "kill", container.getContainerName()); }
@Override public void stop(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "stop", container.getContainerName()); }
@Override public void start(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "start", container.getContainerName()); }
@Override public void start(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "start", container.getContainerName()); }
@Override public void kill(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "kill", container.getContainerName()); }
@Override public void up(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "up", "-d", container.getContainerName()); }
@Override public void stop(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "stop", container.getContainerName()); }
@Override public void stop(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "stop", container.getContainerName()); }
@Override public void up(Container container) throws IOException, InterruptedException { command.execute(Command.throwingOnError(), "up", "-d", container.getContainerName()); }
/** * Returns a check that the native "healthcheck" status of the docker containers is not unhealthy. * * <p>Does not wait for DOWN or PAUSED containers, or containers with no healthcheck defined. */ static ClusterHealthCheck nativeHealthChecks() { return cluster -> { Set<String> unhealthyContainers = new LinkedHashSet<>(); try { for (Container container : cluster.allContainers()) { State state = container.state(); if (state == State.UNHEALTHY) { unhealthyContainers.add(container.getContainerName()); } } if (!unhealthyContainers.isEmpty()) { return SuccessOrFailure.failure( "The following containers are not healthy: " + unhealthyContainers.stream().collect(joining(", "))); } return SuccessOrFailure.success(); } catch (IOException e) { return SuccessOrFailure.fromException(e); } }; }
private void awaitContainerStart(Container container) { LOG.INFO("Waiting for '%s' to become ready...", container.getContainerName()); try { int retries = MAX_WAIT_SECONDS; while (container.areAllPortsOpen().failed()) { Wait.seconds(1); if (retries-- <= 0) { LOG.WARN("Failed to start '%s' - Ports: %s", container.getContainerName(), container.ports().stream().map(Object::toString).collect(Collectors.joining(", "))); return; } } LOG.INFO("Container '%s' is ONLINE - Ports: %s", container.getContainerName(), container.ports().stream().map(Object::toString).collect(Collectors.joining(", "))); } catch (Exception e) { LOG.SEVERE(e); } }
@Before public void before() throws IOException { when(dockerMachine.getIp()).thenReturn("0.0.0.0"); when(executor.execute(anyVararg())).thenReturn(executedProcess); when(executedProcess.getInputStream()).thenReturn(toInputStream("0.0.0.0:7000->7000/tcp")); when(executedProcess.exitValue()).thenReturn(0); when(container.getContainerName()).thenReturn("my-container"); }
containers().allContainers().forEach(c -> { try { LOG.INFO("Executing docker-compose stop for '%s'...", c.getContainerName()); dockerCompose.stop(c); } catch (Exception e) { LOG.WARN("docker-compose stop for '%s' failed: %s (%s)", c.getContainerName(), e.getMessage(), e.getClass().getName());