Search in sources :

Example 36 with LoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.LoadBalancerStrategy in project rest.li by linkedin.

the class SimpleLoadBalancerState method buildTrackerClient.

@Nullable
private TrackerClient buildTrackerClient(URI uri, UriProperties uriProperties, String serviceName, ServiceProperties serviceProperties) {
    TransportClient transportClient = getTransportClient(serviceName, uri);
    LoadBalancerStrategy loadBalancerStrategy = _serviceStrategies.get(serviceName).get(uri.getScheme().toLowerCase());
    if (transportClient == null) {
        return null;
    }
    if (loadBalancerStrategy == null) {
        return null;
    }
    return serviceProperties == null ? null : TrackerClientFactory.createTrackerClient(uri, uriProperties, serviceProperties, loadBalancerStrategy.getName(), transportClient);
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) Nullable(javax.annotation.Nullable)

Example 37 with LoadBalancerStrategy

use of com.linkedin.d2.balancer.strategies.LoadBalancerStrategy in project rest.li by linkedin.

the class SimpleLoadBalancerState method createNewStrategies.

private Map<String, LoadBalancerStrategy> createNewStrategies(ServiceProperties serviceProperties) {
    List<String> strategyList = serviceProperties.getLoadBalancerStrategyList();
    LoadBalancerStrategyFactory<? extends LoadBalancerStrategy> factory = null;
    if (strategyList != null && !strategyList.isEmpty()) {
        for (String strategy : strategyList) {
            factory = _loadBalancerStrategyFactories.get(strategy);
            if (factory != null) {
                break;
            }
        }
    }
    Map<String, LoadBalancerStrategy> newStrategies = new ConcurrentHashMap<>();
    if (factory == null && strategyList != null && strategyList.size() == 1 && strategyList.contains(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME) && !_loadBalancerStrategyFactories.containsKey(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME)) {
        factory = _loadBalancerStrategyFactories.get(DegraderLoadBalancerStrategyV3.DEGRADER_STRATEGY_NAME);
        warn(_log, "unable to find cluster or factory for ", serviceProperties, ", defaulting to ", factory);
    }
    if (factory == null || serviceProperties.getPrioritizedSchemes() == null || serviceProperties.getPrioritizedSchemes().isEmpty()) {
        warn(_log, "unable to find cluster or factory for ", serviceProperties, ": ", factory);
    } else {
        List<String> schemes = serviceProperties.getPrioritizedSchemes();
        for (String scheme : schemes) {
            LoadBalancerStrategy strategy = factory.newLoadBalancer(serviceProperties);
            newStrategies.put(scheme, strategy);
        }
    }
    info(_log, "putting strategies ", serviceProperties.getServiceName(), ": ", newStrategies);
    return newStrategies;
}
Also used : RelativeLoadBalancerStrategy(com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy) LoadBalancerStrategy(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)36 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)21 URI (java.net.URI)19 LoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.LoadBalancerStrategyFactory)18 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)17 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)16 DegraderLoadBalancerStrategyFactoryV3 (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyFactoryV3)16 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)16 Test (org.testng.annotations.Test)16 RandomLoadBalancerStrategyFactory (com.linkedin.d2.balancer.strategies.random.RandomLoadBalancerStrategyFactory)15 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)13 RelativeLoadBalancerStrategy (com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy)13 Map (java.util.Map)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)11 None (com.linkedin.common.util.None)10 SynchronousExecutorService (com.linkedin.d2.discovery.event.SynchronousExecutorService)10 FutureCallback (com.linkedin.common.callback.FutureCallback)9 DarkClusterConfigMap (com.linkedin.d2.DarkClusterConfigMap)9