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));
}
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() + '}';
}
};
}
Aggregations