Search in sources :

Example 1 with ReloadingFactory

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);
}
Also used : ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) AtlasBackupClientBlocking(com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient)

Example 2 with ReloadingFactory

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);
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) Iterables(com.google.common.collect.Iterables) AliasOfOptional(com.palantir.dialogue.example.AliasOfOptional) Arrays(java.util.Arrays) AliasOfAliasOfOptional(com.palantir.dialogue.example.AliasOfAliasOfOptional) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Stopwatch(com.google.common.base.Stopwatch) SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SslConfiguration(com.palantir.conjure.java.api.config.ssl.SslConfiguration) RateLimiter(com.google.common.util.concurrent.RateLimiter) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) Undertow(io.undertow.Undertow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ByteArrayInputStream(java.io.ByteArrayInputStream) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) Refreshable(com.palantir.refreshable.Refreshable) BlockingHandler(io.undertow.server.handlers.BlockingHandler) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) IOException(java.io.IOException) Ints(com.google.common.primitives.Ints) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) HttpHandler(io.undertow.server.HttpHandler) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) ByteStreams(com.google.common.io.ByteStreams) Headers(io.undertow.util.Headers) Optional(java.util.Optional) GZIPOutputStream(java.util.zip.GZIPOutputStream) DialogueClients(com.palantir.dialogue.clients.DialogueClients) Preconditions(com.palantir.logsafe.Preconditions) InputStream(java.io.InputStream) SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) ServiceConfiguration(com.palantir.conjure.java.api.config.service.ServiceConfiguration) BlockingHandler(io.undertow.server.handlers.BlockingHandler) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) SampleServiceBlocking(com.palantir.dialogue.example.SampleServiceBlocking) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ReloadingFactory

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");
}
Also used : ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SampleServiceAsync(com.palantir.dialogue.example.SampleServiceAsync) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DialogueClients(com.palantir.dialogue.clients.DialogueClients) HashSet(java.util.HashSet)

Example 4 with ReloadingFactory

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();
}
Also used : ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) ClientConfiguration(com.palantir.conjure.java.client.config.ClientConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with ReloadingFactory

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);
}
Also used : ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) AtlasBackupClientBlocking(com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient)

Aggregations

ReloadingFactory (com.palantir.dialogue.clients.DialogueClients.ReloadingFactory)7 UserAgent (com.palantir.conjure.java.api.config.service.UserAgent)3 DialogueClients (com.palantir.dialogue.clients.DialogueClients)3 Iterables (com.google.common.collect.Iterables)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 AtlasBackupClient (com.palantir.atlasdb.backup.api.AtlasBackupClient)2 AtlasBackupClientBlocking (com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking)2 ServicesConfigBlock (com.palantir.conjure.java.api.config.service.ServicesConfigBlock)2 SampleServiceAsync (com.palantir.dialogue.example.SampleServiceAsync)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.jupiter.api.Test)2 Stopwatch (com.google.common.base.Stopwatch)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ByteStreams (com.google.common.io.ByteStreams)1 Ints (com.google.common.primitives.Ints)1 Futures (com.google.common.util.concurrent.Futures)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 AtlasDbConfig (com.palantir.atlasdb.config.AtlasDbConfig)1