From 10ba22d55295ff3dd45316fd1609d376d0cc02b5 Mon Sep 17 00:00:00 2001 From: Marcin Falkowski Date: Mon, 11 Nov 2019 20:37:43 +0100 Subject: [PATCH] split definition and implementation Signed-off-by: Marcin Falkowski --- source/common/upstream/load_balancer_impl.cc | 30 ++++++++++++++++++++ source/common/upstream/load_balancer_impl.h | 30 +------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/source/common/upstream/load_balancer_impl.cc b/source/common/upstream/load_balancer_impl.cc index 742978bf4f2f..226b24220fae 100644 --- a/source/common/upstream/load_balancer_impl.cc +++ b/source/common/upstream/load_balancer_impl.cc @@ -775,5 +775,35 @@ HostConstSharedPtr RandomLoadBalancer::chooseHostOnce(LoadBalancerContext* conte return hosts_to_use[random_.random() % hosts_to_use.size()]; } +SubsetSelectorImpl::SubsetSelectorImpl( + const Protobuf::RepeatedPtrField& selector_keys, + envoy::api::v2::Cluster::LbSubsetConfig::LbSubsetSelector::LbSubsetSelectorFallbackPolicy + fallback_policy, + const Protobuf::RepeatedPtrField& fallback_keys_subset) + : selector_keys_(selector_keys.begin(), selector_keys.end()), fallback_policy_(fallback_policy), + fallback_keys_subset_(fallback_keys_subset.begin(), fallback_keys_subset.end()) { + + if (fallback_policy_ != envoy::api::v2::Cluster::LbSubsetConfig::LbSubsetSelector::KEYS_SUBSET) { + if (!fallback_keys_subset_.empty()) { + throw EnvoyException("fallback_keys_subset can be set only for KEYS_SUBSET fallback_policy"); + } + return; + } + + if (fallback_keys_subset_.empty()) { + throw EnvoyException("fallback_keys_subset cannot be empty"); + } + + if (!std::includes(selector_keys_.begin(), selector_keys_.end(), fallback_keys_subset_.begin(), + fallback_keys_subset_.end())) { + throw EnvoyException("fallback_keys_subset must be a subset of selector keys"); + } + + // Enforce that the fallback_keys_subset_ set is smaller than the selector_keys_ set. Otherwise + // we could end up with a infinite recursion of SubsetLoadBalancer::chooseHost(). + if (selector_keys_.size() == fallback_keys_subset_.size()) { + throw EnvoyException("fallback_keys_subset cannot be equal to keys"); + } +} } // namespace Upstream } // namespace Envoy diff --git a/source/common/upstream/load_balancer_impl.h b/source/common/upstream/load_balancer_impl.h index 7f8e4bbbce9e..f2d71fb092c9 100644 --- a/source/common/upstream/load_balancer_impl.h +++ b/source/common/upstream/load_balancer_impl.h @@ -489,35 +489,7 @@ class SubsetSelectorImpl : public SubsetSelector { const Protobuf::RepeatedPtrField& selector_keys, envoy::api::v2::Cluster::LbSubsetConfig::LbSubsetSelector::LbSubsetSelectorFallbackPolicy fallback_policy, - const Protobuf::RepeatedPtrField& fallback_keys_subset) - : selector_keys_(selector_keys.begin(), selector_keys.end()), - fallback_policy_(fallback_policy), - fallback_keys_subset_(fallback_keys_subset.begin(), fallback_keys_subset.end()) { - - if (fallback_policy_ != - envoy::api::v2::Cluster::LbSubsetConfig::LbSubsetSelector::KEYS_SUBSET) { - if (!fallback_keys_subset_.empty()) { - throw EnvoyException( - "fallback_keys_subset can be set only for KEYS_SUBSET fallback_policy"); - } - return; - } - - if (fallback_keys_subset_.empty()) { - throw EnvoyException("fallback_keys_subset cannot be empty"); - } - - if (!std::includes(selector_keys_.begin(), selector_keys_.end(), fallback_keys_subset_.begin(), - fallback_keys_subset_.end())) { - throw EnvoyException("fallback_keys_subset must be a subset of selector keys"); - } - - // Enforce that the fallback_keys_subset_ set is smaller than the selector_keys_ set. Otherwise - // we could end up with a infinite recursion of SubsetLoadBalancer::chooseHost(). - if (selector_keys_.size() == fallback_keys_subset_.size()) { - throw EnvoyException("fallback_keys_subset cannot be equal to keys"); - } - } + const Protobuf::RepeatedPtrField& fallback_keys_subset); // SubsetSelector const std::set& selectorKeys() const override { return selector_keys_; }