/proc/self/cwd/source/common/router/route_config_update_receiver_impl.h
Line | Count | Source (jump to first uncovered line) |
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 | | ConfigTraitsImpl(const OptionalHttpFilters& optional_http_filters, |
24 | | ProtobufMessage::ValidationVisitor& validator) |
25 | 6.98k | : optional_http_filters_(optional_http_filters), validator_(validator) {} |
26 | | |
27 | | Rds::ConfigConstSharedPtr createNullConfig() const override; |
28 | | Rds::ConfigConstSharedPtr createConfig(const Protobuf::Message& rc, |
29 | | Server::Configuration::ServerFactoryContext& context, |
30 | | bool validate_clusters_default) const override; |
31 | | |
32 | | private: |
33 | | const OptionalHttpFilters optional_http_filters_; |
34 | | ProtobufMessage::ValidationVisitor& validator_; |
35 | | }; |
36 | | |
37 | | class RouteConfigUpdateReceiverImpl : public RouteConfigUpdateReceiver { |
38 | | public: |
39 | | RouteConfigUpdateReceiverImpl(Rds::ProtoTraits& proto_traits, |
40 | | Server::Configuration::ServerFactoryContext& factory_context, |
41 | | const OptionalHttpFilters& optional_http_filters) |
42 | | : config_traits_(optional_http_filters, |
43 | | factory_context.messageValidationContext().dynamicValidationVisitor()), |
44 | 206 | base_(config_traits_, proto_traits, factory_context) {} |
45 | | |
46 | | using VirtualHostMap = std::map<std::string, envoy::config::route::v3::VirtualHost>; |
47 | | |
48 | | bool removeVhosts(VirtualHostMap& vhosts, |
49 | | const Protobuf::RepeatedPtrField<std::string>& removed_vhost_names); |
50 | | bool updateVhosts(VirtualHostMap& vhosts, const VirtualHostRefVector& added_vhosts); |
51 | | bool onDemandFetchFailed(const envoy::service::discovery::v3::Resource& resource) const; |
52 | | |
53 | | // Router::RouteConfigUpdateReceiver |
54 | | bool onRdsUpdate(const Protobuf::Message& rc, const std::string& version_info) override; |
55 | | bool onVhdsUpdate(const VirtualHostRefVector& added_vhosts, |
56 | | const std::set<std::string>& added_resource_ids, |
57 | | const Protobuf::RepeatedPtrField<std::string>& removed_resources, |
58 | | const std::string& version_info) override; |
59 | 0 | uint64_t configHash() const override { return base_.configHash(); } |
60 | 84 | const absl::optional<Rds::RouteConfigProvider::ConfigInfo>& configInfo() const override { |
61 | 84 | return base_.configInfo(); |
62 | 84 | } |
63 | 0 | bool vhdsConfigurationChanged() const override { return vhds_configuration_changed_; } |
64 | 72 | const Protobuf::Message& protobufConfiguration() const override { |
65 | 72 | return base_.protobufConfiguration(); |
66 | 72 | } |
67 | 224 | Rds::ConfigConstSharedPtr parsedConfiguration() const override { |
68 | 224 | return base_.parsedConfiguration(); |
69 | 224 | } |
70 | 18 | SystemTime lastUpdated() const override { return base_.lastUpdated(); } |
71 | 18 | const std::set<std::string>& resourceIdsInLastVhdsUpdate() override { |
72 | 18 | return resource_ids_in_last_update_; |
73 | 18 | } |
74 | 36 | const envoy::config::route::v3::RouteConfiguration& protobufConfigurationCast() const override { |
75 | 36 | ASSERT(dynamic_cast<const envoy::config::route::v3::RouteConfiguration*>( |
76 | 36 | &RouteConfigUpdateReceiverImpl::protobufConfiguration())); |
77 | 36 | return static_cast<const envoy::config::route::v3::RouteConfiguration&>( |
78 | 36 | RouteConfigUpdateReceiverImpl::protobufConfiguration()); |
79 | 36 | } |
80 | | |
81 | | private: |
82 | | ConfigTraitsImpl config_traits_; |
83 | | |
84 | | Rds::RouteConfigUpdateReceiverImpl base_; |
85 | | |
86 | | uint64_t last_vhds_config_hash_{0ul}; |
87 | | // vhosts supplied by RDS, to be merged with VHDS vhosts in onVhdsUpdate. |
88 | | std::unique_ptr<VirtualHostMap> rds_virtual_hosts_; |
89 | | // vhosts supplied by VHDS, to be merged with RDS vhosts in onRdsUpdate. |
90 | | std::unique_ptr<VirtualHostMap> vhds_virtual_hosts_; |
91 | | std::set<std::string> resource_ids_in_last_update_; |
92 | | bool vhds_configuration_changed_{true}; |
93 | | }; |
94 | | |
95 | | } // namespace Router |
96 | | } // namespace Envoy |