forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_subscription_impl.h
65 lines (56 loc) · 2.95 KB
/
http_subscription_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "envoy/common/random_generator.h"
#include "envoy/config/subscription.h"
#include "envoy/event/dispatcher.h"
#include "envoy/service/discovery/v3/discovery.pb.h"
#include "source/common/config/api_version.h"
#include "source/common/http/rest_api_fetcher.h"
namespace Envoy {
namespace Config {
/**
* REST implementation of the API Subscription interface. This fetches the API via periodic polling
* with jitter (based on RestApiFetcher). The REST requests are POSTs of the JSON canonical
* representation of the DiscoveryRequest proto and the responses are in the form of the JSON
* canonical representation of DiscoveryResponse. This implementation is responsible for translating
* between the proto serializable objects in the Subscription API and the REST JSON representation.
*/
class HttpSubscriptionImpl : public Http::RestApiFetcher,
public Config::Subscription,
Logger::Loggable<Logger::Id::config> {
public:
HttpSubscriptionImpl(const LocalInfo::LocalInfo& local_info, Upstream::ClusterManager& cm,
const std::string& remote_cluster_name, Event::Dispatcher& dispatcher,
Random::RandomGenerator& random, std::chrono::milliseconds refresh_interval,
std::chrono::milliseconds request_timeout,
const Protobuf::MethodDescriptor& service_method, absl::string_view type_url,
SubscriptionCallbacks& callbacks, OpaqueResourceDecoder& resource_decoder,
SubscriptionStats stats, std::chrono::milliseconds init_fetch_timeout,
ProtobufMessage::ValidationVisitor& validation_visitor);
// Config::Subscription
void start(const absl::flat_hash_set<std::string>& resource_names) override;
void
updateResourceInterest(const absl::flat_hash_set<std::string>& update_to_these_names) override;
void requestOnDemandUpdate(const absl::flat_hash_set<std::string>&) override {
ENVOY_BUG(false, "unexpected request for on demand update");
}
// Http::RestApiFetcher
void createRequest(Http::RequestMessage& request) override;
void parseResponse(const Http::ResponseMessage& response) override;
void onFetchComplete() override;
void onFetchFailure(Config::ConfigUpdateFailureReason reason, const EnvoyException* e) override;
private:
void handleFailure(Config::ConfigUpdateFailureReason reason, const EnvoyException* e);
void disableInitFetchTimeoutTimer();
std::string path_;
Protobuf::RepeatedPtrField<std::string> resources_;
envoy::service::discovery::v3::DiscoveryRequest request_;
Config::SubscriptionCallbacks& callbacks_;
Config::OpaqueResourceDecoder& resource_decoder_;
SubscriptionStats stats_;
Event::Dispatcher& dispatcher_;
std::chrono::milliseconds init_fetch_timeout_;
Event::TimerPtr init_fetch_timeout_timer_;
ProtobufMessage::ValidationVisitor& validation_visitor_;
};
} // namespace Config
} // namespace Envoy