Line data Source code
1 : #pragma once 2 : 3 : #include <string> 4 : #include <vector> 5 : 6 : #include "envoy/config/subscription.h" 7 : #include "envoy/upstream/cluster_manager.h" 8 : 9 : #include "source/common/common/logger.h" 10 : #include "source/common/protobuf/protobuf.h" 11 : 12 : namespace Envoy { 13 : namespace Upstream { 14 : 15 : /** 16 : * A named helper class for handling a successful cluster configuration update from Subscription. A 17 : * name is used mostly for logging to differentiate between different users of the helper class. 18 : */ 19 : class CdsApiHelper : Logger::Loggable<Logger::Id::upstream> { 20 : public: 21 28 : CdsApiHelper(ClusterManager& cm, std::string name) : cm_(cm), name_(std::move(name)) {} 22 : /** 23 : * onConfigUpdate handles the addition and removal of clusters by notifying the ClusterManager 24 : * about the cluster changes. It closely follows the onConfigUpdate API from 25 : * Config::SubscriptionCallbacks, with the exception of the return value documented below. 26 : * 27 : * @param added_resources clusters newly added since the previous fetch. 28 : * @param removed_resources names of clusters that this fetch instructed to be removed. 29 : * @param system_version_info aggregate response data "version", for debugging. 30 : * @return std::vector<std::string> a list of errors that occurred while updating the clusters. 31 : */ 32 : std::vector<std::string> 33 : onConfigUpdate(const std::vector<Config::DecodedResourceRef>& added_resources, 34 : const Protobuf::RepeatedPtrField<std::string>& removed_resources, 35 : const std::string& system_version_info); 36 28 : const std::string versionInfo() const { return system_version_info_; } 37 : 38 : private: 39 : ClusterManager& cm_; 40 : const std::string name_; 41 : std::string system_version_info_; 42 : }; 43 : 44 : } // namespace Upstream 45 : } // namespace Envoy