Search in sources :

Example 1 with EndpointGroup

use of com.linecorp.armeria.client.endpoint.EndpointGroup in project zipkin by openzipkin.

the class InitialEndpointSupplier method get.

@Override
public EndpointGroup get() {
    List<EndpointGroup> endpointGroups = new ArrayList<>();
    for (String hostText : hosts.split(",", 100)) {
        // possibly extra comma
        if ("".equals(hostText))
            continue;
        URI url;
        if (hostText.startsWith("http://") || hostText.startsWith("https://")) {
            url = URI.create(hostText);
        } else if (!sessionProtocol.isTls() && hostText.indexOf(':') == -1) {
            url = URI.create(sessionProtocol.uriText() + "://" + hostText + ":9200");
        } else {
            url = URI.create(sessionProtocol.uriText() + "://" + hostText);
        }
        String host = url.getHost();
        if (host == null) {
            LOGGER.warn("Skipping invalid ES host {}", url);
            continue;
        }
        int port = getPort(url);
        if (port == 9300) {
            LOGGER.warn("Native transport no longer supported. Changing {} to http port 9200", host);
            port = 9200;
        }
        if (isIpAddress(host) || host.equals("localhost")) {
            endpointGroups.add(EndpointGroup.of(Endpoint.of(host, port)));
        } else {
            // A host that isn't an IP may resolve to multiple IP addresses, so we use a endpoint
            // group to round-robin over them. Users can mix addresses that resolve to multiple IPs
            // with single IPs freely, they'll all get used.
            endpointGroups.add(DnsAddressEndpointGroup.builder(host).port(port).build());
        }
    }
    if (endpointGroups.isEmpty()) {
        throw new IllegalArgumentException("No valid endpoints found in ES hosts: " + hosts);
    }
    return EndpointGroup.of(endpointGroups);
}
Also used : DnsAddressEndpointGroup(com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup) EndpointGroup(com.linecorp.armeria.client.endpoint.EndpointGroup) ArrayList(java.util.ArrayList) URI(java.net.URI) Endpoint(com.linecorp.armeria.client.Endpoint)

Aggregations

Endpoint (com.linecorp.armeria.client.Endpoint)1 EndpointGroup (com.linecorp.armeria.client.endpoint.EndpointGroup)1 DnsAddressEndpointGroup (com.linecorp.armeria.client.endpoint.dns.DnsAddressEndpointGroup)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1