Line data Source code
1 : #pragma once 2 : 3 : #include <string> 4 : 5 : #include "envoy/config/route/v3/route.pb.h" 6 : #include "envoy/config/route/v3/route_components.pb.h" 7 : #include "envoy/rds/config_traits.h" 8 : #include "envoy/router/rds.h" 9 : #include "envoy/router/route_config_update_receiver.h" 10 : #include "envoy/server/factory_context.h" 11 : #include "envoy/service/discovery/v3/discovery.pb.h" 12 : 13 : #include "source/common/common/logger.h" 14 : #include "source/common/protobuf/utility.h" 15 : #include "source/common/rds/route_config_update_receiver_impl.h" 16 : #include "source/common/router/config_impl.h" 17 : 18 : namespace Envoy { 19 : namespace Router { 20 : 21 : class ConfigTraitsImpl : public Rds::ConfigTraits { 22 : public: 23 124 : ConfigTraitsImpl(ProtobufMessage::ValidationVisitor& validator) : validator_(validator) {} 24 : 25 : Rds::ConfigConstSharedPtr createNullConfig() const override; 26 : Rds::ConfigConstSharedPtr createConfig(const Protobuf::Message& rc, 27 : Server::Configuration::ServerFactoryContext& context, 28 : bool validate_clusters_default) const override; 29 : 30 : private: 31 : ProtobufMessage::ValidationVisitor& validator_; 32 : }; 33 : 34 : class RouteConfigUpdateReceiverImpl : public RouteConfigUpdateReceiver { 35 : public: 36 : RouteConfigUpdateReceiverImpl(Rds::ProtoTraits& proto_traits, 37 : Server::Configuration::ServerFactoryContext& factory_context) 38 : : config_traits_(factory_context.messageValidationContext().dynamicValidationVisitor()), 39 50 : base_(config_traits_, proto_traits, factory_context) {} 40 : 41 : using VirtualHostMap = std::map<std::string, envoy::config::route::v3::VirtualHost>; 42 : 43 : bool removeVhosts(VirtualHostMap& vhosts, 44 : const Protobuf::RepeatedPtrField<std::string>& removed_vhost_names); 45 : bool updateVhosts(VirtualHostMap& vhosts, const VirtualHostRefVector& added_vhosts); 46 : bool onDemandFetchFailed(const envoy::service::discovery::v3::Resource& resource) const; 47 : 48 : // Router::RouteConfigUpdateReceiver 49 : bool onRdsUpdate(const Protobuf::Message& rc, const std::string& version_info) override; 50 : bool onVhdsUpdate(const VirtualHostRefVector& added_vhosts, 51 : const std::set<std::string>& added_resource_ids, 52 : const Protobuf::RepeatedPtrField<std::string>& removed_resources, 53 : const std::string& version_info) override; 54 0 : uint64_t configHash() const override { return base_.configHash(); } 55 154 : const absl::optional<Rds::RouteConfigProvider::ConfigInfo>& configInfo() const override { 56 154 : return base_.configInfo(); 57 154 : } 58 0 : bool vhdsConfigurationChanged() const override { return vhds_configuration_changed_; } 59 72 : const Protobuf::Message& protobufConfiguration() const override { 60 72 : return base_.protobufConfiguration(); 61 72 : } 62 86 : Rds::ConfigConstSharedPtr parsedConfiguration() const override { 63 86 : return base_.parsedConfiguration(); 64 86 : } 65 36 : SystemTime lastUpdated() const override { return base_.lastUpdated(); } 66 36 : const std::set<std::string>& resourceIdsInLastVhdsUpdate() override { 67 36 : return resource_ids_in_last_update_; 68 36 : } 69 72 : const envoy::config::route::v3::RouteConfiguration& protobufConfigurationCast() const override { 70 72 : ASSERT(dynamic_cast<const envoy::config::route::v3::RouteConfiguration*>( 71 72 : &RouteConfigUpdateReceiverImpl::protobufConfiguration())); 72 72 : return static_cast<const envoy::config::route::v3::RouteConfiguration&>( 73 72 : RouteConfigUpdateReceiverImpl::protobufConfiguration()); 74 72 : } 75 : 76 : private: 77 : ConfigTraitsImpl config_traits_; 78 : 79 : Rds::RouteConfigUpdateReceiverImpl base_; 80 : 81 : uint64_t last_vhds_config_hash_{0ul}; 82 : // vhosts supplied by RDS, to be merged with VHDS vhosts in onVhdsUpdate. 83 : std::unique_ptr<VirtualHostMap> rds_virtual_hosts_; 84 : // vhosts supplied by VHDS, to be merged with RDS vhosts in onRdsUpdate. 85 : std::unique_ptr<VirtualHostMap> vhds_virtual_hosts_; 86 : std::set<std::string> resource_ids_in_last_update_; 87 : bool vhds_configuration_changed_{true}; 88 : }; 89 : 90 : } // namespace Router 91 : } // namespace Envoy