Search in sources :

Example 1 with Jersey1TransportClientFactories

use of com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories in project eureka by Netflix.

the class EurekaHttpClientsTest method setUp.

@Before
public void setUp() throws IOException {
    clientConfig = mock(EurekaClientConfig.class);
    transportConfig = mock(EurekaTransportConfig.class);
    when(clientConfig.getEurekaServerTotalConnectionsPerHost()).thenReturn(10);
    when(clientConfig.getEurekaServerTotalConnections()).thenReturn(10);
    when(transportConfig.getSessionedClientReconnectIntervalSeconds()).thenReturn(10);
    writeServer = new SimpleEurekaHttpServer(writeRequestHandler);
    clusterResolver = new StaticClusterResolver<EurekaEndpoint>("regionA", new DefaultEndpoint("localhost", writeServer.getServerPort(), false, "/v2/"));
    readServer = new SimpleEurekaHttpServer(readRequestHandler);
    readServerURI = "http://localhost:" + readServer.getServerPort();
    clientFactory = EurekaHttpClients.canonicalClientFactory("test", transportConfig, clusterResolver, new Jersey1TransportClientFactories().newTransportClientFactory(clientConfig, Collections.<ClientFilter>emptyList(), applicationInfoManager.getInfo()));
}
Also used : Jersey1TransportClientFactories(com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) DefaultEndpoint(com.netflix.discovery.shared.resolver.DefaultEndpoint) EurekaEndpoint(com.netflix.discovery.shared.resolver.EurekaEndpoint) Before(org.junit.Before)

Example 2 with Jersey1TransportClientFactories

use of com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories in project eureka by Netflix.

the class EurekaHttpClientsTest method testAddingAdditionalFilters.

@Test
public void testAddingAdditionalFilters() throws Exception {
    TestFilter testFilter = new TestFilter();
    Collection<ClientFilter> additionalFilters = Arrays.<ClientFilter>asList(testFilter);
    TransportClientFactory transportClientFactory = new Jersey1TransportClientFactories().newTransportClientFactory(clientConfig, additionalFilters, MY_INSTANCE);
    EurekaHttpClient client = transportClientFactory.newClient(clusterResolver.getClusterEndpoints().get(0));
    client.getApplication("foo");
    assertThat(testFilter.await(30, TimeUnit.SECONDS), is(true));
}
Also used : Jersey1TransportClientFactories(com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories) ClientFilter(com.sun.jersey.api.client.filter.ClientFilter) Test(org.junit.Test)

Example 3 with Jersey1TransportClientFactories

use of com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories in project eureka by Netflix.

the class DiscoveryClient method scheduleServerEndpointTask.

private void scheduleServerEndpointTask(EurekaTransport eurekaTransport, AbstractDiscoveryClientOptionalArgs args) {
    Collection<?> additionalFilters = args == null ? Collections.emptyList() : args.additionalFilters;
    EurekaJerseyClient providedJerseyClient = args == null ? null : args.eurekaJerseyClient;
    TransportClientFactories argsTransportClientFactories = null;
    if (args != null && args.getTransportClientFactories() != null) {
        argsTransportClientFactories = args.getTransportClientFactories();
    }
    // Ignore the raw types warnings since the client filter interface changed between jersey 1/2
    @SuppressWarnings("rawtypes") TransportClientFactories transportClientFactories = argsTransportClientFactories == null ? new Jersey1TransportClientFactories() : argsTransportClientFactories;
    // If the transport factory was not supplied with args, assume they are using jersey 1 for passivity
    eurekaTransport.transportClientFactory = providedJerseyClient == null ? transportClientFactories.newTransportClientFactory(clientConfig, additionalFilters, applicationInfoManager.getInfo()) : transportClientFactories.newTransportClientFactory(additionalFilters, providedJerseyClient);
    ApplicationsResolver.ApplicationsSource applicationsSource = new ApplicationsResolver.ApplicationsSource() {

        @Override
        public Applications getApplications(int stalenessThreshold, TimeUnit timeUnit) {
            long thresholdInMs = TimeUnit.MILLISECONDS.convert(stalenessThreshold, timeUnit);
            long delay = getLastSuccessfulRegistryFetchTimePeriod();
            if (delay > thresholdInMs) {
                logger.info("Local registry is too stale for local lookup. Threshold:{}, actual:{}", thresholdInMs, delay);
                return null;
            } else {
                return localRegionApps.get();
            }
        }
    };
    eurekaTransport.bootstrapResolver = EurekaHttpClients.newBootstrapResolver(clientConfig, transportConfig, eurekaTransport.transportClientFactory, applicationInfoManager.getInfo(), applicationsSource);
    if (clientConfig.shouldRegisterWithEureka()) {
        EurekaHttpClientFactory newRegistrationClientFactory = null;
        EurekaHttpClient newRegistrationClient = null;
        try {
            newRegistrationClientFactory = EurekaHttpClients.registrationClientFactory(eurekaTransport.bootstrapResolver, eurekaTransport.transportClientFactory, transportConfig);
            newRegistrationClient = newRegistrationClientFactory.newClient();
        } catch (Exception e) {
            logger.warn("Transport initialization failure", e);
        }
        eurekaTransport.registrationClientFactory = newRegistrationClientFactory;
        eurekaTransport.registrationClient = newRegistrationClient;
    }
    // Configure new transport layer (candidate for injecting in the future)
    if (clientConfig.shouldFetchRegistry()) {
        EurekaHttpClientFactory newQueryClientFactory = null;
        EurekaHttpClient newQueryClient = null;
        try {
            newQueryClientFactory = EurekaHttpClients.queryClientFactory(eurekaTransport.bootstrapResolver, eurekaTransport.transportClientFactory, clientConfig, transportConfig, applicationInfoManager.getInfo(), applicationsSource);
            newQueryClient = newQueryClientFactory.newClient();
        } catch (Exception e) {
            logger.warn("Transport initialization failure", e);
        }
        eurekaTransport.queryClientFactory = newQueryClientFactory;
        eurekaTransport.queryClient = newQueryClient;
    }
}
Also used : ApplicationsResolver(com.netflix.discovery.shared.resolver.aws.ApplicationsResolver) EurekaHttpClientFactory(com.netflix.discovery.shared.transport.EurekaHttpClientFactory) EurekaJerseyClient(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient) Jersey1TransportClientFactories(com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories) EurekaHttpClient(com.netflix.discovery.shared.transport.EurekaHttpClient) Jersey1TransportClientFactories(com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) TimeUnit(java.util.concurrent.TimeUnit)

Aggregations

Jersey1TransportClientFactories (com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories)3 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 DefaultEndpoint (com.netflix.discovery.shared.resolver.DefaultEndpoint)1 EurekaEndpoint (com.netflix.discovery.shared.resolver.EurekaEndpoint)1 ApplicationsResolver (com.netflix.discovery.shared.resolver.aws.ApplicationsResolver)1 EurekaHttpClient (com.netflix.discovery.shared.transport.EurekaHttpClient)1 EurekaHttpClientFactory (com.netflix.discovery.shared.transport.EurekaHttpClientFactory)1 EurekaJerseyClient (com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient)1 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)1 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)1 TimeUnit (java.util.concurrent.TimeUnit)1 Before (org.junit.Before)1 Test (org.junit.Test)1