Search in sources :

Example 1 with RoutingEndpoint

use of com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint in project vespa by vespa-engine.

the class MockRoutingGenerator method endpoints.

@Override
public List<RoutingEndpoint> endpoints(DeploymentId deployment) {
    List<RoutingEndpoint> endpoints = new ArrayList<>();
    // TODO: TLS: Update to HTTPS when ready.
    endpoints.add(new RoutingEndpoint("http://old-endpoint.vespa.yahooapis.com:4080", false));
    endpoints.add(new RoutingEndpoint("http://qrs-endpoint.vespa.yahooapis.com:4080", "host1", false));
    endpoints.add(new RoutingEndpoint("http://feeding-endpoint.vespa.yahooapis.com:4080", "host2", false));
    endpoints.add(new RoutingEndpoint("http://global-endpoint.vespa.yahooapis.com:4080", "host1", true));
    endpoints.add(new RoutingEndpoint("http://alias-endpoint.vespa.yahooapis.com:4080", "host1", true));
    return endpoints;
}
Also used : RoutingEndpoint(com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint) ArrayList(java.util.ArrayList)

Example 2 with RoutingEndpoint

use of com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint in project vespa by vespa-engine.

the class ApplicationController method getCanonicalGlobalEndpoint.

/**
 * Global rotations (plural as we can have aliases) map to exactly one service endpoint.
 * This method finds that one service endpoint and strips the URI part that
 * the routingGenerator is wrapping around the endpoint.
 *
 * @param deploymentId The deployment to retrieve global service endpoint for
 * @return Empty if no global endpoint exist, otherwise the service endpoint ([clustername.]app.tenant.region.env)
 */
Optional<String> getCanonicalGlobalEndpoint(DeploymentId deploymentId) throws IOException {
    Map<String, RoutingEndpoint> hostToGlobalEndpoint = new HashMap<>();
    Map<String, String> hostToCanonicalEndpoint = new HashMap<>();
    for (RoutingEndpoint endpoint : routingGenerator.endpoints(deploymentId)) {
        try {
            URI uri = new URI(endpoint.getEndpoint());
            String serviceEndpoint = uri.getHost();
            if (serviceEndpoint == null) {
                throw new IOException("Unexpected endpoints returned from the Routing Generator");
            }
            String canonicalEndpoint = serviceEndpoint.replaceAll(".vespa.yahooapis.com", "");
            String hostname = endpoint.getHostname();
            // RoutingEndpoints that lacks hostname is gone
            if (hostname != null) {
                // Book-keeping
                if (endpoint.isGlobal()) {
                    hostToGlobalEndpoint.put(hostname, endpoint);
                } else {
                    hostToCanonicalEndpoint.put(hostname, canonicalEndpoint);
                }
                // Return as soon as we have a map between a global and a canonical endpoint
                if (hostToGlobalEndpoint.containsKey(hostname) && hostToCanonicalEndpoint.containsKey(hostname)) {
                    return Optional.of(hostToCanonicalEndpoint.get(hostname));
                }
            }
        } catch (URISyntaxException use) {
            throw new IOException(use);
        }
    }
    return Optional.empty();
}
Also used : RoutingEndpoint(com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint) HashMap(java.util.HashMap) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

RoutingEndpoint (com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingEndpoint)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1