use of com.palantir.dialogue.clients.DialogueClients.ReloadingFactory in project atlasdb by palantir.
the class AtlasBackupService method create.
public static AtlasBackupService create(AuthHeader authHeader, Refreshable<ServicesConfigBlock> servicesConfigBlock, String serviceName, Function<AtlasService, Path> backupFolderFactory, Function<AtlasService, KeyValueService> keyValueServiceFactory, int completeBackupNumThreads) {
ReloadingFactory reloadingFactory = DialogueClients.create(servicesConfigBlock).withUserAgent(UserAgent.of(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT_AGENT));
AtlasBackupClient atlasBackupClient = new DialogueAdaptingAtlasBackupClient(reloadingFactory.get(AtlasBackupClientBlocking.class, serviceName));
KvsRunner kvsRunner = KvsRunner.create(keyValueServiceFactory);
return createAtlasBackupService(authHeader, atlasBackupClient, backupFolderFactory, kvsRunner, completeBackupNumThreads);
}
use of com.palantir.dialogue.clients.DialogueClients.ReloadingFactory in project dialogue by palantir.
the class IntegrationTest method before.
@BeforeEach
public void before() {
undertow = Undertow.builder().addHttpListener(0, "localhost", new BlockingHandler(exchange -> undertowHandler.handleRequest(exchange))).build();
undertow.start();
ServiceConfiguration config = ServiceConfiguration.builder().addUris(getUri(undertow)).security(SSL_CONFIG).readTimeout(Duration.ofSeconds(1)).writeTimeout(Duration.ofSeconds(1)).connectTimeout(Duration.ofSeconds(1)).build();
ReloadingFactory factory = DialogueClients.create(Refreshable.only(ServicesConfigBlock.builder().build())).withUserAgent(USER_AGENT);
blocking = factory.getNonReloading(SampleServiceBlocking.class, config);
async = factory.getNonReloading(SampleServiceAsync.class, config);
}
use of com.palantir.dialogue.clients.DialogueClients.ReloadingFactory in project dialogue by palantir.
the class DialogueClientsIntegrationTest method testSticky.
private <F> void testSticky(BiFunction<ReloadingFactory, String, F> factoryFactory, BiFunction<F, Class<SampleServiceAsync>, SampleServiceAsync> clientFactory) {
List<StringToVoidRequestPath> requestPaths = Collections.synchronizedList(new ArrayList<>());
int maxConcurrentRequestsPerServer = 10;
Map<String, Integer> activeRequestsPerServer = new ConcurrentHashMap<>();
undertowHandler = exchange -> {
String requestPath = exchange.getRequestPath();
StringToVoidRequestPath path = parse(requestPath);
String server = path.requestPath();
try {
int activeRequests = activeRequestsPerServer.compute(server, (_ignore, activeRequests1) -> {
if (activeRequests1 == null) {
return 1;
} else {
return activeRequests1 + 1;
}
});
if (activeRequests > maxConcurrentRequestsPerServer) {
exchange.setStatusCode(200);
} else {
exchange.setStatusCode(429);
}
} finally {
activeRequestsPerServer.compute(server, (_ignore, activeRequests12) -> {
Preconditions.checkNotNull(activeRequests12, "activeRequests");
Preconditions.checkState(activeRequests12 > 0, "activeRequests");
return activeRequests12 - 1;
});
requestPaths.add(path);
}
};
SettableRefreshable<ServicesConfigBlock> refreshable = Refreshable.create(ServicesConfigBlock.builder().from(scb).putServices(FOO_SERVICE, threeFoos).build());
DialogueClients.ReloadingFactory factory = DialogueClients.create(refreshable).withUserAgent(TestConfigurations.AGENT);
F stickyChannels = factoryFactory.apply(factory, FOO_SERVICE);
int numClients = 3;
int numRequestPerClient = 1000;
List<ListenableFuture<?>> requests = new ArrayList<>();
for (int i = 0; i < numClients; i++) {
SampleServiceAsync client = clientFactory.apply(stickyChannels, SampleServiceAsync.class);
String clientId = Integer.toString(i);
IntStream.range(0, numRequestPerClient).forEach(_ignore -> requests.add(client.stringToVoid(clientId)));
}
assertThat(Futures.whenAllComplete(requests).run(() -> {
}, MoreExecutors.directExecutor())).succeedsWithin(Duration.ofMinutes(1));
assertThat(requestPaths).hasSizeGreaterThanOrEqualTo(numClients * numRequestPerClient);
Set<StringToVoidRequestPath> uniquePaths = new HashSet<>(requestPaths);
assertThat(uniquePaths).hasSize(numClients);
// *I think* this technically has a chance to flake, but let's see how it goes. I am trying to make sure the
// requests are actually being pinned and not just because all the requests went to a single node.
assertThat(uniquePaths.stream().map(StringToVoidRequestPath::server)).hasSizeGreaterThanOrEqualTo(2);
List<String> clientIds = uniquePaths.stream().map(StringToVoidRequestPath::client).collect(Collectors.toList());
assertThat(clientIds).containsExactlyInAnyOrder("0", "1", "2");
}
use of com.palantir.dialogue.clients.DialogueClients.ReloadingFactory in project dialogue by palantir.
the class DialogueClientsTest method legacyClientConfigurationDoesntRequireUserAgent.
@Test
// testing deprecated functionality
@SuppressWarnings("deprecation")
void legacyClientConfigurationDoesntRequireUserAgent() {
ClientConfiguration minimalConfiguration = ClientConfiguration.builder().from(ClientConfigurations.of(ServiceConfigurationFactory.of(scb).get("email-service"))).hostEventsSink(Optional.empty()).userAgent(Optional.empty()).build();
ReloadingFactory factory = DialogueClients.create(Refreshable.only(ServicesConfigBlock.builder().build())).withUserAgent(TestConfigurations.AGENT);
assertThatCode(() -> factory.getNonReloading(SampleServiceBlocking.class, minimalConfiguration)).doesNotThrowAnyException();
}
use of com.palantir.dialogue.clients.DialogueClients.ReloadingFactory in project atlasdb by palantir.
the class AtlasBackupService method create.
public static AtlasBackupService create(AuthHeader authHeader, Refreshable<ServicesConfigBlock> servicesConfigBlock, String serviceName, Function<Namespace, Path> backupFolderFactory, Function<Namespace, KeyValueService> keyValueServiceFactory) {
ReloadingFactory reloadingFactory = DialogueClients.create(servicesConfigBlock).withUserAgent(UserAgent.of(AtlasDbRemotingConstants.ATLASDB_HTTP_CLIENT_AGENT));
AtlasBackupClient atlasBackupClient = new DialogueAdaptingAtlasBackupClient(reloadingFactory.get(AtlasBackupClientBlocking.class, serviceName));
BackupPersister backupPersister = new ExternalBackupPersister(backupFolderFactory);
KvsRunner kvsRunner = KvsRunner.create(keyValueServiceFactory);
CoordinationServiceRecorder coordinationServiceRecorder = new CoordinationServiceRecorder(kvsRunner, backupPersister);
return new AtlasBackupService(authHeader, atlasBackupClient, coordinationServiceRecorder, backupPersister);
}
Aggregations