@Override default List<String> clusterMembers() { return cluster().uris(); } }
@Value.Default public HumanReadableDuration compactInterval() { return HumanReadableDuration.seconds(0); } }
@VisibleForTesting boolean shouldRunCompaction() { long compactIntervalMillis = config.compactInterval().toMilliseconds(); return compactIntervalMillis <= 0 || getMillisSinceLastCompact() >= compactIntervalMillis; }
/** * The code below is copied from http-remoting and should be removed when we switch the clients to use remoting. */ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }
/** * Creates a new {@link ClientConfiguration} instance from the given {@link ServiceConfiguration}, filling in * empty/absent configuration with the defaults specified as constants in this class. */ public static ClientConfiguration of(ServiceConfiguration config) { return ClientConfiguration.builder() .sslSocketFactory(SslSocketFactories.createSslSocketFactory(config.security())) .trustManager(SslSocketFactories.createX509TrustManager(config.security())) .uris(config.uris()) .connectTimeout(config.connectTimeout().orElse(DEFAULT_CONNECT_TIMEOUT)) .readTimeout(config.readTimeout().orElse(DEFAULT_READ_TIMEOUT)) .writeTimeout(config.writeTimeout().orElse(DEFAULT_WRITE_TIMEOUT)) .enableGcmCipherSuites(config.enableGcmCipherSuites().orElse(DEFAULT_ENABLE_GCM_CIPHERS)) .proxy(config.proxy().map(ClientConfigurations::createProxySelector).orElse(ProxySelector.getDefault())) .proxyCredentials(config.proxy().flatMap(ProxyConfiguration::credentials)) .meshProxy(meshProxy(config.proxy())) .maxNumRetries(config.maxNumRetries().orElse(DEFAULT_MAX_NUM_RETRIES)) .nodeSelectionStrategy(DEFAULT_NODE_SELECTION_STRATEGY) .failedUrlCooldown(DEFAULT_FAILED_URL_COOLDOWN) .backoffSlotSize(config.backoffSlotSize().orElse(DEFAULT_BACKOFF_SLOT_SIZE)) .build(); }
if (config.proxyCredentials().isPresent()) { BasicCredentials basicCreds = config.proxyCredentials().get(); final String credentials = Credentials.basic(basicCreds.username(), basicCreds.password()); client.proxyAuthenticator((route, response) -> response.request().newBuilder() .header(HttpHeaders.PROXY_AUTHORIZATION, credentials)
public static Optional<SslConfiguration> getSslConfigurationOptional(TimeLockInstallConfiguration install) { return getClusterConfiguration(install).cluster().security(); }
@Test public void shouldThrowIfLocalServerNotInServers() { assertThatThrownBy(ImmutableDefaultClusterConfiguration.builder() .localServer(ADDRESS_1) .cluster(PartialServiceConfiguration.of(ImmutableList.of(ADDRESS_2), Optional.empty())) ::build) .isInstanceOf(IllegalStateException.class); } }
@Before public void setUp() { postgresDdlTable = new PostgresDdlTable(TEST_TABLE, connectionSupplier, ImmutablePostgresDdlConfig.builder() .compactInterval(HumanReadableDuration.milliseconds(COMPACT_INTERVAL_MILLIS)) .build()); }
@Test public void shouldCompactIfCompactMillisIsSetToZero() throws Exception { postgresDdlTable = new PostgresDdlTable(TEST_TABLE, connectionSupplier, ImmutablePostgresDdlConfig.builder().compactInterval(HumanReadableDuration.valueOf("0 ms")).build()); SqlConnection sqlConnection = setUpSqlConnection(NOW_MILLIS - SMALL_POSITIVE_FACTOR, NOW_MILLIS); assertThatVacuumWasPerformed(sqlConnection, false); verify(sqlConnection, never()).selectResultSetUnregisteredQuery(startsWith("SELECT FLOOR"), any()); }
@Test public void httpProxyIsConfigurableOnClientRequests() { Optional<ProxySelector> httpProxySelector = Optional.of( ServiceCreator.createProxySelector(ProxyConfiguration.of(getHostAndPort(proxyPort)))); TestResource clientWithHttpProxy = AtlasDbHttpClients.createProxyWithFailover( new MetricRegistry(), NO_SSL, httpProxySelector, ImmutableSet.of(getUriForPort(availablePort)), TestResource.class); clientWithHttpProxy.getTestNumber(); String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE); proxyServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT)) .withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent))); availableServer.verify(0, getRequestedFor(urlMatching(TEST_ENDPOINT))); }
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 Optional<HostAndPort> meshProxy(Optional<ProxyConfiguration> proxy) { if (proxy.isPresent() && proxy.get().type() == ProxyConfiguration.Type.MESH) { return Optional.of(HostAndPort.fromString(proxy.get().hostAndPort().get())); } else { return Optional.empty(); } }
@Value.Default public HumanReadableDuration compactInterval() { return HumanReadableDuration.seconds(0); } }
@VisibleForTesting boolean shouldRunCompaction() { long compactIntervalMillis = config.compactInterval().toMilliseconds(); return compactIntervalMillis <= 0 || getMillisSinceLastCompact() >= compactIntervalMillis; }
/** * The code below is copied from http-remoting and should be removed when we switch the clients to use remoting. */ public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }
public static ProxySelector createProxySelector(ProxyConfiguration proxyConfig) { switch (proxyConfig.type()) { case DIRECT: return fixedProxySelectorFor(Proxy.NO_PROXY); case HTTP: HostAndPort hostAndPort = HostAndPort.fromString(proxyConfig.hostAndPort() .orElseThrow(() -> new IllegalArgumentException( "Expected to find proxy hostAndPort configuration for HTTP proxy"))); InetSocketAddress addr = new InetSocketAddress(hostAndPort.getHost(), hostAndPort.getPort()); return fixedProxySelectorFor(new Proxy(Proxy.Type.HTTP, addr)); case MESH: return ProxySelector.getDefault(); // MESH proxy is not a Java proxy default: // fall through } throw new IllegalStateException("Failed to create ProxySelector for proxy configuration: " + proxyConfig); }