Search in sources :

Example 6 with Refreshable

use of com.palantir.refreshable.Refreshable in project atlasdb by palantir.

the class AtlasDbEteServer method createAndRegisterBackupAndRestoreResource.

private void createAndRegisterBackupAndRestoreResource(AtlasDbEteConfiguration config, Environment environment, TransactionManager txManager, TaggedMetricRegistry taggedMetrics) throws IOException {
    AuthHeader authHeader = AuthHeader.of(BearerToken.valueOf("test-auth"));
    URL localServer = new URL("https://localhost:1234");
    Path backupFolder = Paths.get("/var/data/backup");
    Files.createDirectories(backupFolder);
    Function<AtlasService, Path> backupFolderFactory = _unused -> backupFolder;
    ExternalBackupPersister externalBackupPersister = new ExternalBackupPersister(backupFolderFactory);
    Function<String, BackupTimeLockServiceView> timelockServices = _unused -> createBackupTimeLockServiceView(txManager);
    AuthHeaderValidator authHeaderValidator = new AuthHeaderValidator(() -> Optional.of(authHeader.getBearerToken()));
    RedirectRetryTargeter redirectRetryTargeter = RedirectRetryTargeter.create(localServer, ImmutableList.of(localServer));
    AtlasBackupClient atlasBackupClient = AtlasBackupResource.jersey(authHeaderValidator, redirectRetryTargeter, timelockServices);
    AtlasRestoreClient atlasRestoreClient = AtlasRestoreResource.jersey(authHeaderValidator, redirectRetryTargeter, timelockServices);
    Refreshable<ServerListConfig> serverListConfig = getServerListConfigForTimeLock(config);
    TimeLockManagementService timeLockManagementService = getRemoteTimeLockManagementService(serverListConfig, taggedMetrics);
    AtlasBackupService atlasBackupService = AtlasBackupService.createForTests(authHeader, atlasBackupClient, txManager, backupFolderFactory);
    Function<AtlasService, CassandraKeyValueServiceConfig> keyValueServiceConfigFactory = _unused -> (CassandraKeyValueServiceConfig) config.getAtlasDbConfig().keyValueService();
    Function<AtlasService, CassandraKeyValueServiceRuntimeConfig> runtimeConfigFactory = _unused -> (CassandraKeyValueServiceRuntimeConfig) config.getAtlasDbRuntimeConfig().flatMap(AtlasDbRuntimeConfig::keyValueService).orElseThrow();
    Function<AtlasService, CassandraClusterConfig> cassandraClusterConfigFactory = atlasService -> CassandraClusterConfig.of(keyValueServiceConfigFactory.apply(atlasService), runtimeConfigFactory.apply(atlasService));
    Function<AtlasService, Refreshable<CassandraServersConfig>> refreshableCassandraServersConfigFactory = runtimeConfigFactory.andThen(runtimeConfig -> Refreshable.only(runtimeConfig.servers()));
    AtlasRestoreService atlasRestoreService = AtlasRestoreService.createForTests(authHeader, atlasRestoreClient, timeLockManagementService, externalBackupPersister, txManager, cassandraClusterConfigFactory, refreshableCassandraServersConfigFactory);
    environment.jersey().register(new SimpleBackupAndRestoreResource(atlasBackupService, atlasRestoreService, externalBackupPersister));
}
Also used : TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) ServerListConfigs(com.palantir.atlasdb.config.ServerListConfigs) NotInitializedExceptionMapper(com.palantir.atlasdb.http.NotInitializedExceptionMapper) LongSupplier(java.util.function.LongSupplier) SimpleLockResource(com.palantir.atlasdb.lock.SimpleLockResource) URL(java.net.URL) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) AuthHeader(com.palantir.tokens.auth.AuthHeader) BlobSchema(com.palantir.atlasdb.blob.BlobSchema) TargetedSweepFollower(com.palantir.atlasdb.sweep.queue.TargetedSweepFollower) SimpleTodoResource(com.palantir.atlasdb.todo.SimpleTodoResource) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) AtlasBackupService(com.palantir.atlasdb.backup.AtlasBackupService) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) TransactionServices(com.palantir.atlasdb.transaction.service.TransactionServices) CoordinationServices(com.palantir.atlasdb.internalschema.persistence.CoordinationServices) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) Path(java.nio.file.Path) InternalSchemaMetadata(com.palantir.atlasdb.internalschema.InternalSchemaMetadata) CassandraServersConfig(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CassandraServersConfig) Refreshable(com.palantir.refreshable.Refreshable) Application(io.dropwizard.Application) ImmutableSet(com.google.common.collect.ImmutableSet) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) CoordinationService(com.palantir.atlasdb.coordination.CoordinationService) AtlasDbDialogueServiceProvider(com.palantir.atlasdb.factory.AtlasDbDialogueServiceProvider) BackupTimeLockServiceView(com.palantir.atlasdb.timelock.BackupTimeLockServiceView) SharedMetricRegistries(com.codahale.metrics.SharedMetricRegistries) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) MetricsManagers(com.palantir.atlasdb.util.MetricsManagers) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) SimpleBackupAndRestoreResource(com.palantir.atlasdb.backup.SimpleBackupAndRestoreResource) Response(javax.ws.rs.core.Response) AtlasBackupResource(com.palantir.atlasdb.backup.AtlasBackupResource) AtlasRestoreService(com.palantir.atlasdb.backup.AtlasRestoreService) Optional(java.util.Optional) SpecialTimestampsSupplier(com.palantir.atlasdb.sweep.queue.SpecialTimestampsSupplier) SimpleEteTimestampResource(com.palantir.atlasdb.timestamp.SimpleEteTimestampResource) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) TodoClient(com.palantir.atlasdb.todo.TodoClient) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) Bootstrap(io.dropwizard.setup.Bootstrap) Stopwatch(com.google.common.base.Stopwatch) TodoSchema(com.palantir.atlasdb.todo.TodoSchema) ExternalBackupPersister(com.palantir.atlasdb.backup.ExternalBackupPersister) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TransactionManagers(com.palantir.atlasdb.factory.TransactionManagers) SafeLogger(com.palantir.logsafe.logger.SafeLogger) AtlasRestoreResource(com.palantir.atlasdb.backup.AtlasRestoreResource) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) BearerToken(com.palantir.tokens.auth.BearerToken) SubstitutingSourceProvider(io.dropwizard.configuration.SubstitutingSourceProvider) ImmutableList(com.google.common.collect.ImmutableList) EnvironmentVariableSubstitutor(io.dropwizard.configuration.EnvironmentVariableSubstitutor) TransactionSchemaVersionEnforcement(com.palantir.atlasdb.transaction.impl.TransactionSchemaVersionEnforcement) Suppliers(com.google.common.base.Suppliers) SimpleCoordinationResource(com.palantir.atlasdb.coordination.SimpleCoordinationResource) SharedTaggedMetricRegistries(com.palantir.tritium.metrics.registry.SharedTaggedMetricRegistries) Environment(io.dropwizard.setup.Environment) Files(java.nio.file.Files) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) TargetedSweeper(com.palantir.atlasdb.sweep.queue.TargetedSweeper) IOException(java.io.IOException) TransactionSchemaManager(com.palantir.atlasdb.internalschema.TransactionSchemaManager) TimelockService(com.palantir.lock.v2.TimelockService) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DelegatingBackupTimeLockServiceView(com.palantir.atlasdb.backup.DelegatingBackupTimeLockServiceView) TimeUnit(java.util.concurrent.TimeUnit) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig) EmptyOptionalException(io.dropwizard.jersey.optional.EmptyOptionalException) Follower(com.palantir.atlasdb.cleaner.Follower) Paths(java.nio.file.Paths) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ConjureJerseyFeature(com.palantir.conjure.java.server.jersey.ConjureJerseyFeature) AtlasDbRemotingConstants(com.palantir.atlasdb.http.AtlasDbRemotingConstants) CellsSweeper(com.palantir.atlasdb.sweep.CellsSweeper) AuthHeaderValidator(com.palantir.atlasdb.backup.AuthHeaderValidator) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DialogueClients(com.palantir.dialogue.clients.DialogueClients) Schema(com.palantir.atlasdb.table.description.Schema) CleanupFollower(com.palantir.atlasdb.cleaner.CleanupFollower) AtlasDbConfig(com.palantir.atlasdb.config.AtlasDbConfig) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) URL(java.net.URL) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) Path(java.nio.file.Path) ExternalBackupPersister(com.palantir.atlasdb.backup.ExternalBackupPersister) SimpleBackupAndRestoreResource(com.palantir.atlasdb.backup.SimpleBackupAndRestoreResource) AuthHeader(com.palantir.tokens.auth.AuthHeader) BackupTimeLockServiceView(com.palantir.atlasdb.timelock.BackupTimeLockServiceView) DelegatingBackupTimeLockServiceView(com.palantir.atlasdb.backup.DelegatingBackupTimeLockServiceView) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) Refreshable(com.palantir.refreshable.Refreshable) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) AuthHeaderValidator(com.palantir.atlasdb.backup.AuthHeaderValidator) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) AtlasRestoreService(com.palantir.atlasdb.backup.AtlasRestoreService) AtlasBackupService(com.palantir.atlasdb.backup.AtlasBackupService) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig)

Example 7 with Refreshable

use of com.palantir.refreshable.Refreshable in project dialogue by palantir.

the class ReloadingClientFactory method getStickyChannels.

@Override
public StickyChannelFactory getStickyChannels(String serviceName) {
    Refreshable<List<Channel>> perHostChannels = perHost(serviceName).getPerHostChannels();
    Refreshable<Supplier<Channel>> bestSupplier = perHostChannels.map(singleHostChannels -> {
        if (singleHostChannels.isEmpty()) {
            EmptyInternalDialogueChannel alwaysThrowing = new EmptyInternalDialogueChannel(() -> new SafeIllegalStateException("Service not configured", SafeArg.of("serviceName", serviceName)));
            return () -> alwaysThrowing;
        }
        if (singleHostChannels.size() == 1) {
            return () -> singleHostChannels.get(0);
        }
        return StickyEndpointChannels.builder().channels(singleHostChannels.stream().map(c -> (DialogueChannel) c).collect(Collectors.toList())).channelName(ChannelNames.reloading(serviceName, params)).taggedMetricRegistry(params.taggedMetrics()).build();
    });
    return new StickyChannelFactory() {

        @Override
        public Channel getStickyChannel() {
            return bestSupplier.get().get();
        }

        @Override
        public <T> T getCurrentBest(Class<T> clientInterface) {
            return Reflection.callStaticFactoryMethod(clientInterface, getStickyChannel(), params.runtime());
        }

        @Override
        public String toString() {
            return "StickyChannelFactory{" + bestSupplier.get() + '}';
        }
    };
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) Supplier(java.util.function.Supplier) StickyChannelFactory2(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory2) SafeArg(com.palantir.logsafe.SafeArg) NodeSelectionStrategy(com.palantir.conjure.java.client.config.NodeSelectionStrategy) ConjureRuntime(com.palantir.dialogue.ConjureRuntime) ImmutableList(com.google.common.collect.ImmutableList) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Value(org.immutables.value.Value) Duration(java.time.Duration) Map(java.util.Map) Suppliers(com.google.common.base.Suppliers) DefaultConjureRuntime(com.palantir.conjure.java.dialogue.serde.DefaultConjureRuntime) Endpoint(com.palantir.dialogue.Endpoint) ApacheHttpClientChannels(com.palantir.dialogue.hc5.ApacheHttpClientChannels) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) Request(com.palantir.dialogue.Request) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory) ExecutorService(java.util.concurrent.ExecutorService) EndpointChannelFactory(com.palantir.dialogue.EndpointChannelFactory) Refreshable(com.palantir.refreshable.Refreshable) ServiceConfigurationFactory(com.palantir.conjure.java.api.config.service.ServiceConfigurationFactory) Clients(com.palantir.dialogue.Clients) PerHostClientFactory(com.palantir.dialogue.clients.DialogueClients.PerHostClientFactory) Channel(com.palantir.dialogue.Channel) Maps(com.google.common.collect.Maps) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) Collectors(java.util.stream.Collectors) Provider(java.security.Provider) HostEventsSink(com.palantir.conjure.java.client.config.HostEventsSink) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) StickyEndpointChannels(com.palantir.dialogue.core.StickyEndpointChannels) Futures(com.google.common.util.concurrent.Futures) EndpointChannel(com.palantir.dialogue.EndpointChannel) List(java.util.List) DialogueChannel(com.palantir.dialogue.core.DialogueChannel) PartialServiceConfiguration(com.palantir.conjure.java.api.config.service.PartialServiceConfiguration) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Response(com.palantir.dialogue.Response) Preconditions(com.palantir.logsafe.Preconditions) DialogueChannel(com.palantir.dialogue.core.DialogueChannel) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Supplier(java.util.function.Supplier) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) StickyChannelFactory(com.palantir.dialogue.clients.DialogueClients.StickyChannelFactory)

Aggregations

Refreshable (com.palantir.refreshable.Refreshable)7 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)4 CassandraKeyValueServiceRuntimeConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig)4 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)4 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)4 List (java.util.List)4 Optional (java.util.Optional)4 Suppliers (com.google.common.base.Suppliers)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 AtlasDbConfig (com.palantir.atlasdb.config.AtlasDbConfig)3 AtlasDbRuntimeConfig (com.palantir.atlasdb.config.AtlasDbRuntimeConfig)3 ServerListConfig (com.palantir.atlasdb.config.ServerListConfig)3 ServerListConfigs (com.palantir.atlasdb.config.ServerListConfigs)3 CassandraClusterConfig (com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig)3 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)3 SafeLogger (com.palantir.logsafe.logger.SafeLogger)3 SafeLoggerFactory (com.palantir.logsafe.logger.SafeLoggerFactory)3 Map (java.util.Map)3