Search in sources :

Example 1 with DiscoveryEnabledNIWSServerList

use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project spring-cloud-netflix by spring-cloud.

the class EurekaRibbonClientConfiguration method ribbonServerList.

@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(IClientConfig config, Provider<EurekaClient> eurekaClientProvider) {
    if (this.propertiesFactory.isSet(ServerList.class, serviceId)) {
        return this.propertiesFactory.get(ServerList.class, config, serviceId);
    }
    DiscoveryEnabledNIWSServerList discoveryServerList = new DiscoveryEnabledNIWSServerList(config, eurekaClientProvider);
    DomainExtractingServerList serverList = new DomainExtractingServerList(discoveryServerList, config, this.approximateZoneFromHostname);
    return serverList;
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with DiscoveryEnabledNIWSServerList

use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project ribbon by Netflix.

the class EurekaDynamicServerListLoadBalancerTest method testShutdownMultiple.

@Test
public void testShutdownMultiple() {
    try {
        eurekaClientMock.registerEventListener(EasyMock.anyObject(EurekaEventListener.class));
        EasyMock.expectLastCall().anyTimes();
        PowerMock.replay(DiscoveryClient.class);
        PowerMock.replay(eurekaClientMock);
        DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb1 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb2 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb3 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        lb3.shutdown();
        lb1.shutdown();
        lb2.shutdown();
    } finally {
        PowerMock.verify(eurekaClientMock);
        PowerMock.verify(DiscoveryClient.class);
    }
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) EurekaEventListener(com.netflix.discovery.EurekaEventListener) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with DiscoveryEnabledNIWSServerList

use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project nutzboot by nutzam.

the class FeignStarter method getLoadBalancer.

public Object getLoadBalancer(String name, FeignInject fc) {
    EurekaClient eurekaClient = ioc.get(EurekaClient.class, "eurekaClient");
    DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(name);
    ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(name, () -> eurekaClient);
    ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(clientConfig);
    ServerListUpdater updater = new EurekaNotificationServerListUpdater(() -> eurekaClient);
    IRule rule = null;
    switch(getLbRuleString(fc.lbRule())) {
        case "random":
            rule = new RandomRule();
            break;
        case "availability":
        default:
            AvailabilityFilteringRule _rule = new AvailabilityFilteringRule();
            _rule.initWithNiwsConfig(clientConfig);
            rule = _rule;
            break;
    }
    ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).withServerListUpdater(updater).withClientConfig(clientConfig).buildDynamicServerListLoadBalancerWithUpdater();
    return LBClient.create(lb, clientConfig);
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) EurekaClient(com.netflix.discovery.EurekaClient) RandomRule(com.netflix.loadbalancer.RandomRule) IRule(com.netflix.loadbalancer.IRule) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl)

Example 4 with DiscoveryEnabledNIWSServerList

use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project ribbon by Netflix.

the class EurekaDynamicServerListLoadBalancerTest method testLoadBalancerHappyCase.

@Test
public void testLoadBalancerHappyCase() throws Exception {
    Assert.assertNotEquals("the two test server list counts should be different", secondServerListSize, initialServerListSize);
    DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null;
    try {
        Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
        eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
        PowerMock.replay(DiscoveryClient.class);
        PowerMock.replay(eurekaClientMock);
        // actual testing
        // initial creation and loading of the first serverlist
        lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
        Assert.assertEquals(initialServerListSize, lb.getServerCount(false));
        // trigger an eureka CacheRefreshEvent
        eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
        Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb));
    } finally {
        if (lb != null) {
            lb.shutdown();
            PowerMock.verify(eurekaClientMock);
            PowerMock.verify(DiscoveryClient.class);
        }
    }
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) EurekaEventListener(com.netflix.discovery.EurekaEventListener) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) Capture(org.easymock.Capture) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

DiscoveryEnabledNIWSServerList (com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList)4 DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)3 EurekaNotificationServerListUpdater (com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater)3 EurekaEventListener (com.netflix.discovery.EurekaEventListener)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)1 EurekaClient (com.netflix.discovery.EurekaClient)1 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)1 IRule (com.netflix.loadbalancer.IRule)1 RandomRule (com.netflix.loadbalancer.RandomRule)1 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)1 ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)1 Capture (org.easymock.Capture)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1