public ServerListConfig toNamespacedServerList() { return ServerListConfigs.namespaceUris(serversList(), getClientOrThrow()); }
public static ServerListConfig parseInstallAndRuntimeConfigs(TimeLockClientConfig installClientConfig, Supplier<Optional<TimeLockRuntimeConfig>> runtimeConfig, String namespace) { ServerListConfig nonNamespacedConfig = runtimeConfig.get() .map(TimeLockRuntimeConfig::serversList) .orElse(installClientConfig.serversList()); return namespaceUris(nonNamespacedConfig, namespace); }
@Test public void canCopyAddingClient() { TimeLockClientConfig newConfig = TimeLockClientConfigs.copyWithClient(CONFIG_WITHOUT_CLIENT, CLIENT_1); assertThat(newConfig.getClientOrThrow()).isEqualTo(CLIENT_1); }
@Test public void preservesSslOnConversionToNamespacedServerListIfPresent() { ServerListConfig namespacedConfig = CLIENT_CONFIG.toNamespacedServerList(); assertThat(namespacedConfig.sslConfiguration(), equalTo(Optional.of(SSL_CONFIGURATION))); }
private static Optional<TimeLockClientConfig> addFallbackSslConfigurationToTimeLockClientConfig( Optional<TimeLockClientConfig> config, Optional<SslConfiguration> sslConfiguration) { //noinspection ConstantConditions - function returns an existing ServerListConfig, maybe with different SSL. return config.map(clientConfig -> ImmutableTimeLockClientConfig.builder() .from(clientConfig) .serversList(addSslConfigurationToServerListFunction(sslConfiguration) .apply(clientConfig.serversList())) .build()); }
@Test public void canCopyReplacingClient() { TimeLockClientConfig newConfig = TimeLockClientConfigs.copyWithClient(CONFIG_WITH_CLIENT, CLIENT_1); assertThat(newConfig.getClientOrThrow()).isEqualTo(CLIENT_1); } }
@Test public void migrationDoesNotProceedIfInvalidationFails() { when(invalidator.backupAndInvalidate()).thenThrow(new IllegalStateException()); TimeLockMigrator migrator = TimeLockMigrator.create( MetricsManagers.createForTests(), timelockConfig.toNamespacedServerList(), invalidator, USER_AGENT); assertThatThrownBy(migrator::migrate).isInstanceOf(IllegalStateException.class); wireMockRule.verify(0, postRequestedFor(urlEqualTo(TEST_ENDPOINT))); }
private void assertTimeLockConfigDeserializedCorrectly(TimeLockClientConfig timeLockClientConfig) { assertThat(timeLockClientConfig.getClientOrThrow()).isEqualTo("brian"); assertThat(timeLockClientConfig.serversList().servers()).containsExactlyInAnyOrder( "timelock1:8080", "timelock2:8080", "timelock3:8080"); assertThat(timeLockClientConfig.serversList().sslConfiguration().isPresent()).isTrue(); SslConfiguration sslConfiguration = timeLockClientConfig.serversList().sslConfiguration().get(); assertSslConfigDeserializedCorrectly(sslConfiguration); }
@Test public void otherPropertiesConservedWhenAddingClient() { TimeLockClientConfig newConfig = TimeLockClientConfigs.copyWithClient(CONFIG_WITHOUT_CLIENT, CLIENT_1); assertThat(newConfig.serversList()).isEqualTo(SERVERS_LIST); }
@JsonIgnore @Value.Lazy public String getClientOrThrow() { return client().orElseThrow(() -> new IllegalStateException( "Tried to read a client from a TimeLockClientConfig, but it hadn't been initialised.")); }
@Test public void invalidationDoesNotProceedIfTimelockPingUnsuccessful() { wireMockRule.stubFor(PING_MAPPING.willReturn(aResponse().withStatus(500))); TimeLockMigrator migrator = TimeLockMigrator.create( MetricsManagers.createForTests(), timelockConfig.toNamespacedServerList(), invalidator, USER_AGENT); assertThatThrownBy(migrator::migrate).isInstanceOf(AtlasDbDependencyException.class); verify(invalidator, never()).backupAndInvalidate(); }
public ServerListConfig toNamespacedServerList() { return ServerListConfigs.namespaceUris(serversList(), getClientOrThrow()); }
@Test public void addingFallbackSslAddsItToTimelockServersBlock() { AtlasDbConfig withoutSsl = ImmutableAtlasDbConfig.builder() .keyValueService(KVS_CONFIG_WITH_NAMESPACE) .timelock(TIMELOCK_CONFIG) .build(); AtlasDbConfig withSsl = AtlasDbConfigs.addFallbackSslConfigurationToAtlasDbConfig(withoutSsl, SSL_CONFIG); assertThat(withSsl.timelock().get().serversList().sslConfiguration(), is(SSL_CONFIG)); }
+ " atlas root-level namespace config.")); timelock().ifPresent(timelock -> timelock.client().ifPresent(client -> Preconditions.checkState(client.equals(namespaceConfigValue), "If present, the TimeLock client config should be the same as the" TimeLockClientConfig timeLockConfig = timelock().get(); Preconditions.checkState(timeLockConfig.client().isPresent(), "Either the atlas root-level namespace config or the TimeLock client config" + " should be present."); Preconditions.checkState(timeLockConfig.client().equals(Optional.of(keyValueServiceNamespace)), "AtlasDB refused to start, in order to avoid potential data corruption." + " Please contact AtlasDB support to remediate this. Specific steps are required;" keyValueService().getClass()); if (timelock().isPresent()) { return timelock().get().client() .orElseThrow(() -> new IllegalStateException("For InMemoryKVS, the TimeLock client should not be empty"));
@Test public void preservesAbsenceOfSslOnConversionToNamespacedServerListIfAbsent() { ImmutableServerListConfig serversListWithoutSsl = ImmutableServerListConfig.copyOf(SERVERS_LIST) .withSslConfiguration(Optional.empty()); TimeLockClientConfig config = ImmutableTimeLockClientConfig.copyOf(CLIENT_CONFIG) .withServersList(serversListWithoutSsl); assertThat(config.toNamespacedServerList().sslConfiguration(), equalTo(Optional.empty())); }
public static ServerListConfig parseInstallAndRuntimeConfigs(TimeLockClientConfig installClientConfig, Supplier<Optional<TimeLockRuntimeConfig>> runtimeConfig, String namespace) { ServerListConfig nonNamespacedConfig = runtimeConfig.get() .map(TimeLockRuntimeConfig::serversList) .orElse(installClientConfig.serversList()); return namespaceUris(nonNamespacedConfig, namespace); }
private static Supplier<ServerListConfig> getServerListConfigSupplierForTimeLock( AtlasDbConfig config, Supplier<AtlasDbRuntimeConfig> runtimeConfigSupplier) { Preconditions.checkState(!remoteTimestampAndLockOrLeaderBlocksPresent(config), "Cannot create raw services from timelock with another source of timestamps/locks configured!"); TimeLockClientConfig clientConfig = config.timelock().orElse(ImmutableTimeLockClientConfig.builder().build()); String resolvedClient = OptionalResolver.resolve(clientConfig.client(), config.namespace()); return () -> ServerListConfigs.parseInstallAndRuntimeConfigs( clientConfig, () -> runtimeConfigSupplier.get().timelockRuntime(), resolvedClient); }
@Test public void canGetNamespacedConfigsFromTimelockBlock() { ServerListConfig namespacedConfig = MULTIPLE_SERVER_CONFIG.toNamespacedServerList(); assertThat(namespacedConfig.servers(), hasItems(SERVER_1 + "/" + CLIENT, SERVER_2 + "/" + CLIENT)); }
private static Optional<TimeLockClientConfig> addFallbackSslConfigurationToTimeLockClientConfig( Optional<TimeLockClientConfig> config, Optional<SslConfiguration> sslConfiguration) { //noinspection ConstantConditions - function returns an existing ServerListConfig, maybe with different SSL. return config.map(clientConfig -> ImmutableTimeLockClientConfig.builder() .from(clientConfig) .serversList(addSslConfigurationToServerListFunction(sslConfiguration) .apply(clientConfig.serversList())) .build()); }