1
#include "source/extensions/load_balancing_policies/ring_hash/config.h"
2

            
3
#include "source/extensions/load_balancing_policies/ring_hash/ring_hash_lb.h"
4

            
5
namespace Envoy {
6
namespace Extensions {
7
namespace LoadBalancingPolicies {
8
namespace RingHash {
9

            
10
Upstream::ThreadAwareLoadBalancerPtr
11
Factory::create(OptRef<const Upstream::LoadBalancerConfig> lb_config,
12
                const Upstream::ClusterInfo& cluster_info,
13
                const Upstream::PrioritySet& priority_set, Runtime::Loader& runtime,
14
42
                Random::RandomGenerator& random, TimeSource&) {
15

            
16
42
  const auto typed_lb_config =
17
42
      dynamic_cast<const Upstream::TypedRingHashLbConfig*>(lb_config.ptr());
18
42
  ASSERT(typed_lb_config != nullptr, "Invalid ring hash load balancer config");
19

            
20
42
  return std::make_unique<Upstream::RingHashLoadBalancer>(
21
42
      priority_set, cluster_info.lbStats(), cluster_info.statsScope(), runtime, random,
22
42
      PROTOBUF_PERCENT_TO_ROUNDED_INTEGER_OR_DEFAULT(cluster_info.lbConfig(),
23
42
                                                     healthy_panic_threshold, 100, 50),
24
42
      typed_lb_config->lb_config_, typed_lb_config->hash_policy_);
25
42
}
26

            
27
/**
28
 * Static registration for the Factory. @see RegisterFactory.
29
 */
30
REGISTER_FACTORY(Factory, Upstream::TypedLoadBalancerFactory);
31

            
32
} // namespace RingHash
33
} // namespace LoadBalancingPolicies
34
} // namespace Extensions
35
} // namespace Envoy