Search in sources :

Example 1 with PollingServerListUpdater

use of com.netflix.loadbalancer.PollingServerListUpdater in project camel by apache.

the class RibbonLoadBalancer method createLoadBalancer.

// ************************
// Helpers
// ************************
private ZoneAwareLoadBalancer<RibbonServiceDefinition> createLoadBalancer(String serviceName, ServiceDiscovery serviceDiscovery) {
    // setup client config
    IClientConfig config = configuration.getClientName() != null ? IClientConfig.Builder.newBuilder(configuration.getClientName()).build() : IClientConfig.Builder.newBuilder().build();
    if (configuration.getClientConfig() != null) {
        for (Map.Entry<String, String> entry : configuration.getClientConfig().entrySet()) {
            IClientConfigKey key = IClientConfigKey.Keys.valueOf(entry.getKey());
            String value = entry.getValue();
            LOGGER.debug("RibbonClientConfig: {}={}", key.key(), value);
            config.set(key, value);
        }
    }
    return new ZoneAwareLoadBalancer<>(config, configuration.getRuleOrDefault(RoundRobinRule::new), configuration.getPingOrDefault(DummyPing::new), new RibbonServerList(serviceName, serviceDiscovery, serviceFilter), null, new PollingServerListUpdater(config));
}
Also used : PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) IClientConfig(com.netflix.client.config.IClientConfig) ZoneAwareLoadBalancer(com.netflix.loadbalancer.ZoneAwareLoadBalancer) IClientConfigKey(com.netflix.client.config.IClientConfigKey) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with PollingServerListUpdater

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

the class RibbonClientConfigurationIntegrationTests method testLoadBalancerConstruction.

@Test
public void testLoadBalancerConstruction() {
    ILoadBalancer loadBalancer = clientFactory.getInstance("test", ILoadBalancer.class);
    assertThat(loadBalancer, is(instanceOf(ZoneAwareLoadBalancer.class)));
    ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) loadBalancer;
    ServerListUpdater serverListUpdater = (PollingServerListUpdater) ReflectionTestUtils.getField(loadBalancer, "serverListUpdater");
    Long refreshIntervalMs = (Long) ReflectionTestUtils.getField(serverListUpdater, "refreshIntervalMs");
    // assertThat(refreshIntervalMs, equalTo(999L));
    ServerListUpdater updater = clientFactory.getInstance("test", ServerListUpdater.class);
    assertThat(updater, is(sameInstance(serverListUpdater)));
}
Also used : PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) ZoneAwareLoadBalancer(com.netflix.loadbalancer.ZoneAwareLoadBalancer) PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PollingServerListUpdater

use of com.netflix.loadbalancer.PollingServerListUpdater in project ribbon by Netflix.

the class LBBuilderTest method testBuildWithArchaiusProperties.

@Test
public void testBuildWithArchaiusProperties() {
    Configuration config = ConfigurationManager.getConfigInstance();
    config.setProperty("client1.niws.client." + Keys.DeploymentContextBasedVipAddresses, "dummy:7001");
    config.setProperty("client1.niws.client." + Keys.InitializeNFLoadBalancer, "true");
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerClassName, DynamicServerListLoadBalancer.class.getName());
    config.setProperty("client1.niws.client." + Keys.NFLoadBalancerRuleClassName, RoundRobinRule.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
    config.setProperty("client1.niws.client." + Keys.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName());
    config.setProperty("client1.niws.client." + Keys.ServerListUpdaterClassName, PollingServerListUpdater.class.getName());
    IClientConfig clientConfig = IClientConfig.Builder.newBuilder(NiwsClientConfig.class, "client1").build();
    ILoadBalancer lb = LoadBalancerBuilder.newBuilder().withClientConfig(clientConfig).buildLoadBalancerFromConfigWithReflection();
    assertNotNull(lb);
    assertEquals(DynamicServerListLoadBalancer.class.getName(), lb.getClass().getName());
    DynamicServerListLoadBalancer<Server> dynamicLB = (DynamicServerListLoadBalancer<Server>) lb;
    assertTrue(dynamicLB.getServerListUpdater() instanceof PollingServerListUpdater);
    assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
    assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
    assertTrue(dynamicLB.getPing() instanceof DummyPing);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
}
Also used : Configuration(org.apache.commons.configuration.Configuration) Server(com.netflix.loadbalancer.Server) PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) RoundRobinRule(com.netflix.loadbalancer.RoundRobinRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with PollingServerListUpdater

use of com.netflix.loadbalancer.PollingServerListUpdater in project ribbon by Netflix.

the class LBBuilderTest method testBuildWithDiscoveryEnabledNIWSServerListAndUpdater.

@Test
public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() {
    IRule rule = new AvailabilityFilteringRule();
    ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
    ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<>();
    ServerListUpdater updater = new PollingServerListUpdater();
    ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).withServerListUpdater(updater).buildDynamicServerListLoadBalancerWithUpdater();
    assertNotNull(lb);
    assertEquals(Lists.newArrayList(expected), lb.getAllServers());
    assertSame(filter, lb.getFilter());
    assertSame(list, lb.getServerListImpl());
    assertSame(updater, lb.getServerListUpdater());
    Server server = lb.chooseServer();
    // make sure load balancer does not recreate the server instance
    assertTrue(server instanceof DiscoveryEnabledServer);
}
Also used : Server(com.netflix.loadbalancer.Server) PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) IRule(com.netflix.loadbalancer.IRule) PollingServerListUpdater(com.netflix.loadbalancer.PollingServerListUpdater) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PollingServerListUpdater (com.netflix.loadbalancer.PollingServerListUpdater)4 Test (org.junit.Test)3 IClientConfig (com.netflix.client.config.IClientConfig)2 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)2 Server (com.netflix.loadbalancer.Server)2 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)2 ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)2 ZoneAwareLoadBalancer (com.netflix.loadbalancer.ZoneAwareLoadBalancer)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 IClientConfigKey (com.netflix.client.config.IClientConfigKey)1 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)1 DummyPing (com.netflix.loadbalancer.DummyPing)1 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)1 IRule (com.netflix.loadbalancer.IRule)1 RoundRobinRule (com.netflix.loadbalancer.RoundRobinRule)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Configuration (org.apache.commons.configuration.Configuration)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1