#pragma once #include #include "envoy/api/api.h" #include "envoy/config/cluster/v3/cluster.pb.h" #include "envoy/config/cluster/v3/cluster.pb.validate.h" #include "envoy/config/core/v3/config_source.pb.h" #include "envoy/config/subscription.h" #include "envoy/event/dispatcher.h" #include "envoy/local_info/local_info.h" #include "envoy/service/discovery/v3/discovery.pb.h" #include "envoy/stats/scope.h" #include "envoy/upstream/cluster_manager.h" #include "common/common/logger.h" #include "common/config/subscription_base.h" namespace Envoy { namespace Upstream { /** * CDS API implementation that fetches via Subscription. */ class CdsApiImpl : public CdsApi, Envoy::Config::SubscriptionBase, Logger::Loggable { public: static CdsApiPtr create(const envoy::config::core::v3::ConfigSource& cds_config, ClusterManager& cm, Stats::Scope& scope, ProtobufMessage::ValidationVisitor& validation_visitor); // Upstream::CdsApi void initialize() override { subscription_->start({}); } void setInitializedCb(std::function callback) override { initialize_callback_ = callback; } const std::string versionInfo() const override { return system_version_info_; } private: // Config::SubscriptionCallbacks void onConfigUpdate(const std::vector& resources, const std::string& version_info) override; void onConfigUpdate(const std::vector& added_resources, const Protobuf::RepeatedPtrField& removed_resources, const std::string& system_version_info) override; void onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason reason, const EnvoyException* e) override; CdsApiImpl(const envoy::config::core::v3::ConfigSource& cds_config, ClusterManager& cm, Stats::Scope& scope, ProtobufMessage::ValidationVisitor& validation_visitor); void runInitializeCallbackIfAny(); ClusterManager& cm_; Config::SubscriptionPtr subscription_; std::string system_version_info_; std::function initialize_callback_; Stats::ScopePtr scope_; }; } // namespace Upstream } // namespace Envoy