public com.palantir.docker.compose.connection.Container getContainer(String containerName) { synchronized (Containers.class) { return dockerComposeRule.containers().container(containerName); } }
private static InetSocketAddress connect(DockerComposeRule docker, int dbPort) { try { if (docker == null) { throw new IllegalStateException("Docker compose rule cannot be run, is null."); } else { docker.before(); return InetSocketAddress.createUnresolved( docker.containers().ip(), docker.hostNetworkedPort(dbPort).getExternalPort()); } } catch (IOException | InterruptedException | IllegalStateException e) { throw new RuntimeException("Could not run docker compose rule.", e); } }
private Object dockerPort(Class<?> parameterContext, Cluster cluster, Port port) { Container container = cluster.container(port.container()); Preconditions.checkNotNull(container, "Could not find container '%s'", port.container()); DockerPort dockerPort = container.port(port.internalPort()); Preconditions.checkNotNull(container, "Could not find internalPort '%s' for container '%s'", port.internalPort(), port.container()); if (InetSocketAddress.class.isAssignableFrom(parameterContext)) { try { final InetAddress address = InetAddress.getByName(cluster.ip()); return new InetSocketAddress(address, dockerPort.getExternalPort()); } catch (UnknownHostException e) { throw new ParameterResolutionException("Could not resolve ip", e); } } else if (Integer.class.equals(parameterContext)) { return dockerPort.getExternalPort(); } else if (int.class.equals(parameterContext)) { return dockerPort.getExternalPort(); } else { return null; } }
public Container container(String name) { return containerCache().container(name); }
static ClusterHealthCheck serviceHealthCheck(List<String> containerNames, HealthCheck<List<Container>> delegate) { return transformingHealthCheck(cluster -> cluster.containers(containerNames), delegate); }
private void awaitClusterHealth() { try { containers().allContainers().forEach(this::awaitContainerStart); } catch (Exception e) { LOG.SEVERE(e); } }
public Container container(String name) { return containerCache().container(name); }
static ClusterHealthCheck serviceHealthCheck(List<String> containerNames, HealthCheck<List<Container>> delegate) { return transformingHealthCheck(cluster -> cluster.containers(containerNames), delegate); }
/** * 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); } }; }
/** * Set environment variable "kafkaServer" to the host and port specified by * docker */ public static void setKafkaEnvironment(DockerComposeRule docker) { DockerPort kafka = docker.containers().container("kafka").port(9092); Map<String, String> newEnv = new HashMap<>(); newEnv.put(ServiceProperties.KAFKA_SERVER_KEY, kafka.inFormat("$HOST:$EXTERNAL_PORT")); newEnv.putAll(System.getenv()); setEnv(newEnv); }
public Builder waitingForHostNetworkedPort(int port, HealthCheck<DockerPort> healthCheck, ReadableDuration timeout) { ClusterHealthCheck clusterHealthCheck = transformingHealthCheck(cluster -> new DockerPort(cluster.ip(), port, port), healthCheck); return addClusterWait(new ClusterWait(clusterHealthCheck, timeout)); }
public Set<Container> allContainers() throws IOException, InterruptedException { return containerCache().containers(); }
static ClusterHealthCheck serviceHealthCheck(List<String> containerNames, HealthCheck<List<Container>> delegate) { return transformingHealthCheck(cluster -> cluster.containers(containerNames), delegate); }
try { LOG.INFO("Executing docker-compose stop..."); containers().allContainers().forEach(c -> { try { LOG.INFO("Executing docker-compose stop for '%s'...", c.getContainerName());
/** * Set environment variable "etcd_endpoints" to the host and port specified by * docker */ public static void setEtcdEnvironment(DockerComposeRule docker) { DockerPort etcd = docker.containers().container("etcd").port(2379); Map<String, String> newEnv = new HashMap<>(); newEnv.put("etcd_endpoints", etcd.inFormat("http://$HOST:$EXTERNAL_PORT")); newEnv.putAll(System.getenv()); setEnv(newEnv); }
public Builder waitingForHostNetworkedPort(int port, HealthCheck<DockerPort> healthCheck, ReadableDuration timeout) { ClusterHealthCheck clusterHealthCheck = transformingHealthCheck(cluster -> new DockerPort(cluster.ip(), port, port), healthCheck); return addClusterWait(new ClusterWait(clusterHealthCheck, timeout)); }
public Container container(String name) { return containerCache().container(name); }
/** * Set environment variable "registryServer" to the host and port specified by * docker */ public static void setConsulEnvironment(DockerComposeRule docker) { DockerPort consul = docker.containers().container("consul").port(8500); Map<String, String> newEnv = new HashMap<>(); newEnv.put(ServiceProperties.REGISTRY_SERVER_KEY, consul.inFormat("$HOST:$EXTERNAL_PORT")); newEnv.putAll(System.getenv()); setEnv(newEnv); }
public Builder waitingForHostNetworkedPort(int port, HealthCheck<DockerPort> healthCheck, ReadableDuration timeout) { ClusterHealthCheck clusterHealthCheck = transformingHealthCheck(cluster -> new DockerPort(cluster.ip(), port, port), healthCheck); return addClusterWait(new ClusterWait(clusterHealthCheck, timeout)); }
/** * Get the server name of the postgres docker instance * * @param docker The used docker compose rule * @return postgresServerName */ public static String getPostgresServerName(DockerComposeRule docker) { DockerPort postgres = docker.containers().container("postgres").port(5432); return postgres.inFormat("$HOST"); }