1
#pragma once
2

            
3
#include <string>
4
#include <vector>
5

            
6
#include "envoy/config/subscription.h"
7
#include "envoy/config/xds_manager.h"
8
#include "envoy/upstream/cluster_manager.h"
9

            
10
#include "source/common/common/logger.h"
11
#include "source/common/protobuf/protobuf.h"
12

            
13
namespace Envoy {
14
namespace Upstream {
15

            
16
/**
17
 * A named helper class for handling a successful cluster configuration update from Subscription. A
18
 * name is used mostly for logging to differentiate between different users of the helper class.
19
 */
20
class CdsApiHelper : Logger::Loggable<Logger::Id::upstream> {
21
public:
22
  CdsApiHelper(ClusterManager& cm, Config::XdsManager& xds_manager, std::string name)
23
913
      : cm_(cm), xds_manager_(xds_manager), name_(std::move(name)) {}
24
  /**
25
   * onConfigUpdate handles the addition and removal of clusters by notifying the ClusterManager
26
   * about the cluster changes. It closely follows the onConfigUpdate API from
27
   * Config::SubscriptionCallbacks, with the exception of the return value documented below.
28
   *
29
   * @param added_resources clusters newly added since the previous fetch.
30
   * @param removed_resources names of clusters that this fetch instructed to be removed.
31
   * @param system_version_info aggregate response data "version", for debugging.
32
   * @return std::pair<uint32_t, std::vector<std::string>> the actual number of added or updated
33
   * clusters and a list of errors that occurred while updating the clusters.
34
   */
35
  std::pair<uint32_t, std::vector<std::string>>
36
  onConfigUpdate(const std::vector<Config::DecodedResourceRef>& added_resources,
37
                 const Protobuf::RepeatedPtrField<std::string>& removed_resources,
38
                 const std::string& system_version_info);
39
38
  const std::string versionInfo() const { return system_version_info_; }
40

            
41
private:
42
  ClusterManager& cm_;
43
  Config::XdsManager& xds_manager_;
44
  const std::string name_;
45
  std::string system_version_info_;
46
};
47

            
48
} // namespace Upstream
49
} // namespace Envoy