Skip to content

Commit

Permalink
fix(clients): correly parse usage hosts (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3622

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Clément Vannicatte <vannicattec@gmail.com>
  • Loading branch information
algolia-bot and shortcuts committed Aug 30, 2024
1 parent 947f852 commit 629edea
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions algoliasearch/src/main/java/com/algolia/api/UsageClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import com.algolia.utils.*;
import com.fasterxml.jackson.core.type.TypeReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nonnull;

public class UsageClient extends ApiClient {
Expand All @@ -28,22 +24,14 @@ public UsageClient(String appId, String apiKey) {
}

public UsageClient(String appId, String apiKey, ClientOptions options) {
super(appId, apiKey, "Usage", options, getDefaultHosts(appId));
super(appId, apiKey, "Usage", options, getDefaultHosts());
}

private static List<Host> getDefaultHosts(String appId) {
private static List<Host> getDefaultHosts() {
List<Host> hosts = new ArrayList<>();
hosts.add(new Host(appId + "-dsn.algolia.net", EnumSet.of(CallType.READ)));
hosts.add(new Host(appId + ".algolia.net", EnumSet.of(CallType.WRITE)));

List<Host> commonHosts = new ArrayList<>();
hosts.add(new Host(appId + "-1.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
hosts.add(new Host(appId + "-2.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
hosts.add(new Host(appId + "-3.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));

Collections.shuffle(commonHosts, new Random());

return Stream.concat(hosts.stream(), commonHosts.stream()).collect(Collectors.toList());
hosts.add(new Host("usage.algolia.com", EnumSet.of(CallType.READ, CallType.WRITE)));
hosts.add(new Host("usage-dev.algolia.com", EnumSet.of(CallType.READ, CallType.WRITE)));
return hosts;
}

/**
Expand Down

0 comments on commit 629edea

Please sign in to comment.