Search in sources :

Example 1 with EurekaEndpoint

use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.

the class RetryableEurekaHttpClient method getHostCandidates.

private List<EurekaEndpoint> getHostCandidates() {
    List<EurekaEndpoint> candidateHosts = clusterResolver.getClusterEndpoints();
    quarantineSet.retainAll(candidateHosts);
    // If enough hosts are bad, we have no choice but start over again
    int threshold = (int) (candidateHosts.size() * transportConfig.getRetryableClientQuarantineRefreshPercentage());
    if (quarantineSet.isEmpty()) {
    // no-op
    } else if (quarantineSet.size() >= threshold) {
        logger.debug("Clearing quarantined list of size {}", quarantineSet.size());
        quarantineSet.clear();
    } else {
        List<EurekaEndpoint> remainingHosts = new ArrayList<>(candidateHosts.size());
        for (EurekaEndpoint endpoint : candidateHosts) {
            if (!quarantineSet.contains(endpoint)) {
                remainingHosts.add(endpoint);
            }
        }
        candidateHosts = remainingHosts;
    }
    return candidateHosts;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Example 2 with EurekaEndpoint

use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.

the class RetryableEurekaHttpClient method execute.

@Override
protected <R> EurekaHttpResponse<R> execute(RequestExecutor<R> requestExecutor) {
    List<EurekaEndpoint> candidateHosts = null;
    int endpointIdx = 0;
    for (int retry = 0; retry < numberOfRetries; retry++) {
        EurekaHttpClient currentHttpClient = delegate.get();
        EurekaEndpoint currentEndpoint = null;
        if (currentHttpClient == null) {
            if (candidateHosts == null) {
                candidateHosts = getHostCandidates();
                if (candidateHosts.isEmpty()) {
                    throw new TransportException("There is no known eureka server; cluster server list is empty");
                }
            }
            if (endpointIdx >= candidateHosts.size()) {
                throw new TransportException("Cannot execute request on any known server");
            }
            currentEndpoint = candidateHosts.get(endpointIdx++);
            currentHttpClient = clientFactory.newClient(currentEndpoint);
        }
        try {
            EurekaHttpResponse<R> response = requestExecutor.execute(currentHttpClient);
            if (serverStatusEvaluator.accept(response.getStatusCode(), requestExecutor.getRequestType())) {
                delegate.set(currentHttpClient);
                if (retry > 0) {
                    logger.info("Request execution succeeded on retry #{}", retry);
                }
                return response;
            }
            logger.warn("Request execution failure with status code {}; retrying on another server if available", response.getStatusCode());
        } catch (Exception e) {
            // just log message as the underlying client should log the stacktrace
            logger.warn("Request execution failed with message: {}", e.getMessage());
        }
        // Connection error or 5xx from the server that must be retried on another server
        delegate.compareAndSet(currentHttpClient, null);
        if (currentEndpoint != null) {
            quarantineSet.add(currentEndpoint);
        }
    }
    throw new TransportException("Retry limit reached; giving up on completing the request");
}
Also used : EurekaHttpClient(com.netflix.discovery.shared.transport.EurekaHttpClient) TransportException(com.netflix.discovery.shared.transport.TransportException) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) TransportException(com.netflix.discovery.shared.transport.TransportException) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Example 3 with EurekaEndpoint

use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.

the class Jersey1TransportClientFactories method newTransportClientFactory.

@Deprecated
public TransportClientFactory newTransportClientFactory(final Collection<ClientFilter> additionalFilters, final EurekaJerseyClient providedJerseyClient) {
    ApacheHttpClient4 apacheHttpClient = providedJerseyClient.getClient();
    if (additionalFilters != null) {
        for (ClientFilter filter : additionalFilters) {
            if (filter != null) {
                apacheHttpClient.addFilter(filter);
            }
        }
    }
    final TransportClientFactory jerseyFactory = new JerseyEurekaHttpClientFactory(providedJerseyClient, false);
    final TransportClientFactory metricsFactory = MetricsCollectingEurekaHttpClient.createFactory(jerseyFactory);
    return new TransportClientFactory() {

        @Override
        public EurekaHttpClient newClient(EurekaEndpoint serviceUrl) {
            return metricsFactory.newClient(serviceUrl);
        }

        @Override
        public void shutdown() {
            metricsFactory.shutdown();
            jerseyFactory.shutdown();
        }
    };
}
Also used : ClientFilter(com.sun.jersey.api.client.filter.ClientFilter) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4) TransportClientFactory(com.netflix.discovery.shared.transport.TransportClientFactory) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Example 4 with EurekaEndpoint

use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.

the class Jersey1TransportClientFactories method newTransportClientFactory.

public TransportClientFactory newTransportClientFactory(final EurekaClientConfig clientConfig, final Collection<ClientFilter> additionalFilters, final InstanceInfo myInstanceInfo) {
    final TransportClientFactory jerseyFactory = JerseyEurekaHttpClientFactory.create(clientConfig, additionalFilters, myInstanceInfo, new EurekaClientIdentity(myInstanceInfo.getIPAddr()));
    final TransportClientFactory metricsFactory = MetricsCollectingEurekaHttpClient.createFactory(jerseyFactory);
    return new TransportClientFactory() {

        @Override
        public EurekaHttpClient newClient(EurekaEndpoint serviceUrl) {
            return metricsFactory.newClient(serviceUrl);
        }

        @Override
        public void shutdown() {
            metricsFactory.shutdown();
            jerseyFactory.shutdown();
        }
    };
}
Also used : EurekaClientIdentity(com.netflix.appinfo.EurekaClientIdentity) TransportClientFactory(com.netflix.discovery.shared.transport.TransportClientFactory) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Example 5 with EurekaEndpoint

use of com.netflix.discovery.shared.resolver.EurekaEndpoint in project eureka by Netflix.

the class MetricsCollectingEurekaHttpClient method createFactory.

public static TransportClientFactory createFactory(final TransportClientFactory delegateFactory) {
    final Map<RequestType, EurekaHttpClientRequestMetrics> metricsByRequestType = initializeMetrics();
    final ExceptionsMetric exceptionMetrics = new ExceptionsMetric(EurekaClientNames.METRIC_TRANSPORT_PREFIX + "exceptions");
    return new TransportClientFactory() {

        @Override
        public EurekaHttpClient newClient(EurekaEndpoint endpoint) {
            return new MetricsCollectingEurekaHttpClient(delegateFactory.newClient(endpoint), metricsByRequestType, exceptionMetrics, false);
        }

        @Override
        public void shutdown() {
            shutdownMetrics(metricsByRequestType);
            exceptionMetrics.shutdown();
        }
    };
}
Also used : ExceptionsMetric(com.netflix.discovery.util.ExceptionsMetric) TransportClientFactory(com.netflix.discovery.shared.transport.TransportClientFactory) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint)

Aggregations

EurekaEndpoint (com.netflix.discovery.shared.resolver.EurekaEndpoint)10 TransportClientFactory (com.netflix.discovery.shared.transport.TransportClientFactory)4 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)3 EurekaClientIdentity (com.netflix.appinfo.EurekaClientIdentity)2 TransportException (com.netflix.discovery.shared.transport.TransportException)2 Test (org.junit.Test)2 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 DefaultEndpoint (com.netflix.discovery.shared.resolver.DefaultEndpoint)1 EurekaHttpClient (com.netflix.discovery.shared.transport.EurekaHttpClient)1 Jersey1TransportClientFactories (com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories)1 ExceptionsMetric (com.netflix.discovery.util.ExceptionsMetric)1 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)1 ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1