gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/grpc/xds/internal/xdsclient/attributes.go (about) 1 /* 2 * Copyright 2021 gRPC authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package xdsclient 19 20 import ( 21 "gitee.com/ks-custle/core-gm/grpc/resolver" 22 "gitee.com/ks-custle/core-gm/grpc/xds/internal/xdsclient/bootstrap" 23 "gitee.com/ks-custle/core-gm/grpc/xds/internal/xdsclient/load" 24 "gitee.com/ks-custle/core-gm/grpc/xds/internal/xdsclient/xdsresource" 25 ) 26 27 type clientKeyType string 28 29 const clientKey = clientKeyType("grpc.xds.internal.client.Client") 30 31 // XDSClient is a full fledged gRPC client which queries a set of discovery APIs 32 // (collectively termed as xDS) on a remote management server, to discover 33 // various dynamic resources. 34 type XDSClient interface { 35 WatchListener(string, func(xdsresource.ListenerUpdate, error)) func() 36 WatchRouteConfig(string, func(xdsresource.RouteConfigUpdate, error)) func() 37 WatchCluster(string, func(xdsresource.ClusterUpdate, error)) func() 38 WatchEndpoints(clusterName string, edsCb func(xdsresource.EndpointsUpdate, error)) (cancel func()) 39 ReportLoad(server string) (*load.Store, func()) 40 41 DumpLDS() map[string]xdsresource.UpdateWithMD 42 DumpRDS() map[string]xdsresource.UpdateWithMD 43 DumpCDS() map[string]xdsresource.UpdateWithMD 44 DumpEDS() map[string]xdsresource.UpdateWithMD 45 46 BootstrapConfig() *bootstrap.Config 47 Close() 48 } 49 50 // FromResolverState returns the Client from state, or nil if not present. 51 func FromResolverState(state resolver.State) XDSClient { 52 cs, _ := state.Attributes.Value(clientKey).(XDSClient) 53 return cs 54 } 55 56 // SetClient sets c in state and returns the new state. 57 func SetClient(state resolver.State, c XDSClient) resolver.State { 58 state.Attributes = state.Attributes.WithValue(clientKey, c) 59 return state 60 }