1
#pragma once
2

            
3
#include <chrono>
4
#include <cstdint>
5
#include <functional>
6
#include <list>
7
#include <memory>
8
#include <string>
9
#include <vector>
10

            
11
#include "envoy/access_log/access_log.h"
12
#include "envoy/api/api.h"
13
#include "envoy/common/random_generator.h"
14
#include "envoy/config/cluster/v3/cluster.pb.h"
15
#include "envoy/config/typed_config.h"
16
#include "envoy/event/dispatcher.h"
17
#include "envoy/local_info/local_info.h"
18
#include "envoy/network/dns.h"
19
#include "envoy/runtime/runtime.h"
20
#include "envoy/server/admin.h"
21
#include "envoy/server/factory_context.h"
22
#include "envoy/server/options.h"
23
#include "envoy/singleton/manager.h"
24
#include "envoy/ssl/context.h"
25
#include "envoy/ssl/context_manager.h"
26
#include "envoy/stats/stats.h"
27
#include "envoy/stats/store.h"
28
#include "envoy/thread_local/thread_local.h"
29
#include "envoy/upstream/cluster_manager.h"
30
#include "envoy/upstream/outlier_detection.h"
31

            
32
namespace Envoy {
33
namespace Upstream {
34

            
35
/**
36
 * Context passed to cluster factory to access Envoy resources. Cluster factory should only access
37
 * the rest of the server through this context object.
38
 */
39
class ClusterFactoryContext {
40
public:
41
18303
  virtual ~ClusterFactoryContext() = default;
42

            
43
  /**
44
   * @return Server::Configuration::ServerFactoryContext& the server factory context. All the
45
   *         server-wide resources should be accessed through this context.
46
   */
47
  virtual Server::Configuration::ServerFactoryContext& serverFactoryContext() PURE;
48

            
49
  /**
50
   * @return ProtobufMessage::ValidationVisitor& validation visitor for cluster configuration
51
   * messages.
52
   */
53
  virtual ProtobufMessage::ValidationVisitor& messageValidationVisitor() PURE;
54

            
55
  /**
56
   * @return bool flag indicating whether the cluster is added via api.
57
   */
58
  virtual bool addedViaApi() PURE;
59

            
60
  /**
61
   * @return Network::DnsResolverSharedPtr the dns resolver for the server.
62
   */
63
  virtual Network::DnsResolverSharedPtr dnsResolver() PURE;
64

            
65
  /**
66
   * @return Outlier::EventLoggerSharedPtr sink for outlier detection event logs.
67
   */
68
  virtual Outlier::EventLoggerSharedPtr outlierEventLogger() PURE;
69
};
70

            
71
/**
72
 * Implemented by cluster and registered via Registry::registerFactory() or the convenience class
73
 * RegisterFactory.
74
 */
75
class ClusterFactory : public Config::UntypedFactory {
76
public:
77
335
  ~ClusterFactory() override = default;
78

            
79
  /**
80
   * Create a new instance of cluster. If the implementation is unable to produce a cluster instance
81
   * with the provided parameters, it should throw an EnvoyException in the case of general error.
82
   * @param cluster supplies the general protobuf configuration for the cluster.
83
   * @param context supplies the cluster's context.
84
   * @return a pair containing the cluster instance as well as an option thread aware load balancer
85
   * if this cluster has an integrated load balancer or an absl::Satus error on failure.
86
   */
87
  virtual absl::StatusOr<std::pair<ClusterSharedPtr, ThreadAwareLoadBalancerPtr>>
88
  create(const envoy::config::cluster::v3::Cluster& cluster, ClusterFactoryContext& context) PURE;
89

            
90
1750
  std::string category() const override { return "envoy.clusters"; }
91
};
92

            
93
} // namespace Upstream
94
} // namespace Envoy