1
#pragma once
2

            
3
#include "envoy/event/dispatcher.h"
4
#include "envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.pb.h"
5
#include "envoy/server/factory_context.h"
6
#include "envoy/upstream/load_balancer.h"
7

            
8
#include "source/common/common/logger.h"
9
#include "source/extensions/load_balancing_policies/client_side_weighted_round_robin/client_side_weighted_round_robin_lb.h"
10
#include "source/extensions/load_balancing_policies/common/factory_base.h"
11

            
12
namespace Envoy {
13
namespace Extensions {
14
namespace LoadBalancingPolicies {
15
namespace ClientSideWeightedRoundRobin {
16

            
17
using ClientSideWeightedRoundRobinLbProto = envoy::extensions::load_balancing_policies::
18
    client_side_weighted_round_robin::v3::ClientSideWeightedRoundRobin;
19

            
20
class Factory : public Upstream::TypedLoadBalancerFactoryBase<ClientSideWeightedRoundRobinLbProto> {
21
public:
22
  Factory()
23
8
      : Upstream::TypedLoadBalancerFactoryBase<ClientSideWeightedRoundRobinLbProto>(
24
8
            "envoy.load_balancing_policies.client_side_weighted_round_robin") {}
25

            
26
  Upstream::ThreadAwareLoadBalancerPtr create(OptRef<const Upstream::LoadBalancerConfig> lb_config,
27
                                              const Upstream::ClusterInfo& cluster_info,
28
                                              const Upstream::PrioritySet& priority_set,
29
                                              Runtime::Loader& runtime,
30
                                              Envoy::Random::RandomGenerator& random,
31
19
                                              TimeSource& time_source) override {
32
19
    return std::make_unique<Upstream::ClientSideWeightedRoundRobinLoadBalancer>(
33
19
        lb_config, cluster_info, priority_set, runtime, random, time_source);
34
19
  }
35

            
36
  absl::StatusOr<Upstream::LoadBalancerConfigPtr>
37
  loadConfig(Server::Configuration::ServerFactoryContext& context,
38
19
             const Protobuf::Message& config) override {
39
19
    const auto& lb_config = dynamic_cast<const ClientSideWeightedRoundRobinLbProto&>(config);
40
19
    return Upstream::LoadBalancerConfigPtr{new Upstream::ClientSideWeightedRoundRobinLbConfig(
41
19
        lb_config, context.mainThreadDispatcher(), context.threadLocal())};
42
19
  }
43
};
44

            
45
DECLARE_FACTORY(Factory);
46

            
47
} // namespace ClientSideWeightedRoundRobin
48
} // namespace LoadBalancingPolicies
49
} // namespace Extensions
50
} // namespace Envoy