|
|
|
@ -28,7 +28,10 @@ |
|
|
|
|
#include "src/core/ext/xds/xds_api.h" |
|
|
|
|
#include "src/core/ext/xds/xds_bootstrap.h" |
|
|
|
|
#include "src/core/ext/xds/xds_client_stats.h" |
|
|
|
|
#include "src/core/ext/xds/xds_resource_type.h" |
|
|
|
|
#include "src/core/ext/xds/xds_cluster.h" |
|
|
|
|
#include "src/core/ext/xds/xds_endpoint.h" |
|
|
|
|
#include "src/core/ext/xds/xds_listener.h" |
|
|
|
|
#include "src/core/ext/xds/xds_route_config.h" |
|
|
|
|
#include "src/core/lib/channel/channelz.h" |
|
|
|
|
#include "src/core/lib/gprpp/dual_ref_counted.h" |
|
|
|
|
#include "src/core/lib/gprpp/memory.h" |
|
|
|
@ -36,7 +39,6 @@ |
|
|
|
|
#include "src/core/lib/gprpp/ref_counted.h" |
|
|
|
|
#include "src/core/lib/gprpp/ref_counted_ptr.h" |
|
|
|
|
#include "src/core/lib/gprpp/sync.h" |
|
|
|
|
#include "src/core/lib/iomgr/work_serializer.h" |
|
|
|
|
|
|
|
|
|
namespace grpc_core { |
|
|
|
|
|
|
|
|
@ -57,6 +59,67 @@ class XdsClient : public DualRefCounted<XdsClient> { |
|
|
|
|
ABSL_EXCLUSIVE_LOCKS_REQUIRED(&work_serializer_) = 0; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// TODO(roth): Consider removing these resource-type-specific APIs in
|
|
|
|
|
// favor of some mechanism for automatic type-deduction for the generic
|
|
|
|
|
// API.
|
|
|
|
|
|
|
|
|
|
// Listener data watcher interface. Implemented by callers.
|
|
|
|
|
class ListenerWatcherInterface : public ResourceWatcherInterface { |
|
|
|
|
public: |
|
|
|
|
virtual void OnListenerChanged(XdsListenerResource listener) = 0; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void OnResourceChanged( |
|
|
|
|
const XdsResourceType::ResourceData* resource) override { |
|
|
|
|
OnListenerChanged( |
|
|
|
|
static_cast<const XdsListenerResourceType::ListenerData*>(resource) |
|
|
|
|
->resource); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// RouteConfiguration data watcher interface. Implemented by callers.
|
|
|
|
|
class RouteConfigWatcherInterface : public ResourceWatcherInterface { |
|
|
|
|
public: |
|
|
|
|
virtual void OnRouteConfigChanged(XdsRouteConfigResource route_config) = 0; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void OnResourceChanged( |
|
|
|
|
const XdsResourceType::ResourceData* resource) override { |
|
|
|
|
OnRouteConfigChanged( |
|
|
|
|
static_cast<const XdsRouteConfigResourceType::RouteConfigData*>( |
|
|
|
|
resource) |
|
|
|
|
->resource); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Cluster data watcher interface. Implemented by callers.
|
|
|
|
|
class ClusterWatcherInterface : public ResourceWatcherInterface { |
|
|
|
|
public: |
|
|
|
|
virtual void OnClusterChanged(XdsClusterResource cluster_data) = 0; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void OnResourceChanged( |
|
|
|
|
const XdsResourceType::ResourceData* resource) override { |
|
|
|
|
OnClusterChanged( |
|
|
|
|
static_cast<const XdsClusterResourceType::ClusterData*>(resource) |
|
|
|
|
->resource); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Endpoint data watcher interface. Implemented by callers.
|
|
|
|
|
class EndpointWatcherInterface : public ResourceWatcherInterface { |
|
|
|
|
public: |
|
|
|
|
virtual void OnEndpointChanged(XdsEndpointResource update) = 0; |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void OnResourceChanged( |
|
|
|
|
const XdsResourceType::ResourceData* resource) override { |
|
|
|
|
OnEndpointChanged( |
|
|
|
|
static_cast<const XdsEndpointResourceType::EndpointData*>(resource) |
|
|
|
|
->resource); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// Factory function to get or create the global XdsClient instance.
|
|
|
|
|
// If *error is not GRPC_ERROR_NONE upon return, then there was
|
|
|
|
|
// an error initializing the client.
|
|
|
|
@ -96,6 +159,58 @@ class XdsClient : public DualRefCounted<XdsClient> { |
|
|
|
|
ResourceWatcherInterface* watcher, |
|
|
|
|
bool delay_unsubscription = false); |
|
|
|
|
|
|
|
|
|
// Start and cancel listener data watch for a listener.
|
|
|
|
|
// The XdsClient takes ownership of the watcher, but the caller may
|
|
|
|
|
// keep a raw pointer to the watcher, which may be used only for
|
|
|
|
|
// cancellation. (Because the caller does not own the watcher, the
|
|
|
|
|
// pointer must not be used for any other purpose.)
|
|
|
|
|
// If the caller is going to start a new watch after cancelling the
|
|
|
|
|
// old one, it should set delay_unsubscription to true.
|
|
|
|
|
void WatchListenerData(absl::string_view listener_name, |
|
|
|
|
RefCountedPtr<ListenerWatcherInterface> watcher); |
|
|
|
|
void CancelListenerDataWatch(absl::string_view listener_name, |
|
|
|
|
ListenerWatcherInterface* watcher, |
|
|
|
|
bool delay_unsubscription = false); |
|
|
|
|
|
|
|
|
|
// Start and cancel route config data watch for a listener.
|
|
|
|
|
// The XdsClient takes ownership of the watcher, but the caller may
|
|
|
|
|
// keep a raw pointer to the watcher, which may be used only for
|
|
|
|
|
// cancellation. (Because the caller does not own the watcher, the
|
|
|
|
|
// pointer must not be used for any other purpose.)
|
|
|
|
|
// If the caller is going to start a new watch after cancelling the
|
|
|
|
|
// old one, it should set delay_unsubscription to true.
|
|
|
|
|
void WatchRouteConfigData(absl::string_view route_config_name, |
|
|
|
|
RefCountedPtr<RouteConfigWatcherInterface> watcher); |
|
|
|
|
void CancelRouteConfigDataWatch(absl::string_view route_config_name, |
|
|
|
|
RouteConfigWatcherInterface* watcher, |
|
|
|
|
bool delay_unsubscription = false); |
|
|
|
|
|
|
|
|
|
// Start and cancel cluster data watch for a cluster.
|
|
|
|
|
// The XdsClient takes ownership of the watcher, but the caller may
|
|
|
|
|
// keep a raw pointer to the watcher, which may be used only for
|
|
|
|
|
// cancellation. (Because the caller does not own the watcher, the
|
|
|
|
|
// pointer must not be used for any other purpose.)
|
|
|
|
|
// If the caller is going to start a new watch after cancelling the
|
|
|
|
|
// old one, it should set delay_unsubscription to true.
|
|
|
|
|
void WatchClusterData(absl::string_view cluster_name, |
|
|
|
|
RefCountedPtr<ClusterWatcherInterface> watcher); |
|
|
|
|
void CancelClusterDataWatch(absl::string_view cluster_name, |
|
|
|
|
ClusterWatcherInterface* watcher, |
|
|
|
|
bool delay_unsubscription = false); |
|
|
|
|
|
|
|
|
|
// Start and cancel endpoint data watch for a cluster.
|
|
|
|
|
// The XdsClient takes ownership of the watcher, but the caller may
|
|
|
|
|
// keep a raw pointer to the watcher, which may be used only for
|
|
|
|
|
// cancellation. (Because the caller does not own the watcher, the
|
|
|
|
|
// pointer must not be used for any other purpose.)
|
|
|
|
|
// If the caller is going to start a new watch after cancelling the
|
|
|
|
|
// old one, it should set delay_unsubscription to true.
|
|
|
|
|
void WatchEndpointData(absl::string_view eds_service_name, |
|
|
|
|
RefCountedPtr<EndpointWatcherInterface> watcher); |
|
|
|
|
void CancelEndpointDataWatch(absl::string_view eds_service_name, |
|
|
|
|
EndpointWatcherInterface* watcher, |
|
|
|
|
bool delay_unsubscription = false); |
|
|
|
|
|
|
|
|
|
// Adds and removes drop stats for cluster_name and eds_service_name.
|
|
|
|
|
RefCountedPtr<XdsClusterDropStats> AddClusterDropStats( |
|
|
|
|
absl::string_view lrs_server, absl::string_view cluster_name, |
|
|
|
|