private static ConnectionConfig createConnectionConfig(int maxConnections) { DockerPort port = docker.containers() .container("postgres") .port(POSTGRES_PORT_NUMBER); InetSocketAddress postgresAddress = new InetSocketAddress(port.getIp(), port.getExternalPort()); return ImmutablePostgresConnectionConfig.builder() .dbName("atlas") .dbLogin("palantir") .dbPassword(ImmutableMaskedValue.of("palantir")) .host(postgresAddress.getHostName()) .port(postgresAddress.getPort()) .maxConnections(maxConnections) .checkoutTimeout(2000) .build(); }
public static DbKeyValueServiceConfig getKvsConfig() { DockerPort port = docker.containers() .container("postgres") .port(POSTGRES_PORT_NUMBER); InetSocketAddress postgresAddress = new InetSocketAddress(port.getIp(), port.getExternalPort()); ConnectionConfig connectionConfig = ImmutablePostgresConnectionConfig.builder() .dbName("atlas") .dbLogin("palantir") .dbPassword(ImmutableMaskedValue.of("palantir")) .host(postgresAddress.getHostName()) .port(postgresAddress.getPort()) .build(); return ImmutableDbKeyValueServiceConfig.builder() .connection(connectionConfig) .ddl(ImmutablePostgresDdlConfig.builder() .compactInterval(HumanReadableDuration.days(2)) .build()) .build(); }
private static Collection<String> buildClosedPortsErrorMessage(Collection<DockerPort> unavailablePorts) { return unavailablePorts.stream() .map(port -> "For host with ip address: " + port.getIp() + " external port '" + port.getExternalPort() + "' mapped to internal port '" + port.getInternalPort() + "' was unavailable") .collect(Collectors.toList()); }
private static Collection<String> buildClosedPortsErrorMessage(Collection<DockerPort> unavailablePorts) { return unavailablePorts.stream() .map(port -> "For host with ip address: " + port.getIp() + " external port '" + port.getExternalPort() + "' mapped to internal port '" + port.getInternalPort() + "' was unavailable") .collect(Collectors.toList()); }
private static Collection<String> buildClosedPortsErrorMessage(Collection<DockerPort> unavailablePorts) { return unavailablePorts.stream() .map(port -> "For host with ip address: " + port.getIp() + " external port '" + port.getExternalPort() + "' mapped to internal port '" + port.getInternalPort() + "' was unavailable") .collect(Collectors.toList()); }
/** * Formats the docker port into a particular form. * <p> * Example: dockerPort.inFormat("https://$HOST:$EXTERNAL_PORT/api") * </p> * Available options are: * <ul> * <li>$HOST - the hostname/ip address of the docker port</li> * <li>$EXTERNAL_PORT - the external version of the docker port</li> * <li>$INTERNAL_PORT - the internal version of the docker port</li> * </ul> * * @param format a format string using the substitutions listed above * @return formattedDockerPort the details of the {@link DockerPort} in the specified format */ public String inFormat(String format) { return format .replaceAll("\\$HOST", getIp()) .replaceAll("\\$EXTERNAL_PORT", String.valueOf(getExternalPort())) .replaceAll("\\$INTERNAL_PORT", String.valueOf(getInternalPort())); }
/** * Formats the docker port into a particular form. * <p> * Example: dockerPort.inFormat("https://$HOST:$EXTERNAL_PORT/api") * </p> * Available options are: * <ul> * <li>$HOST - the hostname/ip address of the docker port</li> * <li>$EXTERNAL_PORT - the external version of the docker port</li> * <li>$INTERNAL_PORT - the internal version of the docker port</li> * </ul> * * @param format a format string using the substitutions listed above * @return formattedDockerPort the details of the {@link DockerPort} in the specified format */ public String inFormat(String format) { return format .replaceAll("\\$HOST", getIp()) .replaceAll("\\$EXTERNAL_PORT", String.valueOf(getExternalPort())) .replaceAll("\\$INTERNAL_PORT", String.valueOf(getInternalPort())); }
/** * Formats the docker port into a particular form. * <p> * Example: dockerPort.inFormat("https://$HOST:$EXTERNAL_PORT/api") * </p> * Available options are: * <ul> * <li>$HOST - the hostname/ip address of the docker port</li> * <li>$EXTERNAL_PORT - the external version of the docker port</li> * <li>$INTERNAL_PORT - the internal version of the docker port</li> * </ul> * * @param format a format string using the substitutions listed above * @return formattedDockerPort the details of the {@link DockerPort} in the specified format */ public String inFormat(String format) { return format .replaceAll("\\$HOST", getIp()) .replaceAll("\\$EXTERNAL_PORT", String.valueOf(getExternalPort())) .replaceAll("\\$INTERNAL_PORT", String.valueOf(getInternalPort())); }
@Override public boolean attempt() throws Exception { final DockerPort dockerPort = container.port(port); final String jdbcUrl = dockerPort.inFormat(jdbcUrlFormat); log.trace("Container Ip = {}", dockerPort.getIp()); if (!dockerPort.isListeningNow()) { log.trace("Port {} is not listening on container {}.", port, containerName); return false; } log.trace("Attempting to authenticate to {} with user {}.", jdbcUrl, username); try (Connection connection = DriverManager.getConnection( jdbcUrl, username, password )) { return true; } catch (Exception ex) { log.trace("Exception thrown", ex); Thread.sleep(2500); return false; } } }
protected HttpsURLConnection openUrlConnection(String url, SSLContext sslContext) throws IOException { DockerPort dockerPort = docker.containers().container("squid").port(3128); HttpsURLConnection httpURLConnection = (HttpsURLConnection) new URL(url).openConnection( new Proxy(Proxy.Type.HTTP, new InetSocketAddress(dockerPort.getIp(), dockerPort.getExternalPort()))); httpURLConnection.setSSLSocketFactory(sslContext.getSocketFactory()); return httpURLConnection; }
private Object dockerHost(DockerComposeRule docker, Annotation annotation) { DockerHost dockerHost = (DockerHost) annotation; Container container = docker.containers().container(dockerHost.container()); DockerPort dockerPort = container.port(dockerHost.port()); return dockerPort.getIp(); }
@Override protected HttpURLConnection openConnection(String url) throws IOException { DockerPort dockerPort = proxyExtractor.apply(target).port(3128); return getHttpURLConnection(url, sslSocketFactorySupplier.get(), dockerPort.getIp(), dockerPort.getExternalPort()); } }.isHealthy(serverExtractor.apply(target));
public static String getUnsecureConfigUrl(Container container) { DockerPort dockerPort = container.port(10080); return "http://" + dockerPort.getIp() + ":" + dockerPort.getExternalPort() + "/c2/config"; }