...

Source file src/google.golang.org/grpc/xds/internal/resolver/watch_service.go

Documentation: google.golang.org/grpc/xds/internal/resolver

     1  /*
     2   *
     3   * Copyright 2020 gRPC authors.
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   */
    18  
    19  package resolver
    20  
    21  import (
    22  	"context"
    23  
    24  	"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
    25  )
    26  
    27  type listenerWatcher struct {
    28  	resourceName string
    29  	cancel       func()
    30  	parent       *xdsResolver
    31  }
    32  
    33  func newListenerWatcher(resourceName string, parent *xdsResolver) *listenerWatcher {
    34  	lw := &listenerWatcher{resourceName: resourceName, parent: parent}
    35  	lw.cancel = xdsresource.WatchListener(parent.xdsClient, resourceName, lw)
    36  	return lw
    37  }
    38  
    39  func (l *listenerWatcher) OnUpdate(update *xdsresource.ListenerResourceData) {
    40  	l.parent.serializer.Schedule(func(context.Context) {
    41  		l.parent.onListenerResourceUpdate(update.Resource)
    42  	})
    43  }
    44  
    45  func (l *listenerWatcher) OnError(err error) {
    46  	l.parent.serializer.Schedule(func(context.Context) {
    47  		l.parent.onListenerResourceError(err)
    48  	})
    49  }
    50  
    51  func (l *listenerWatcher) OnResourceDoesNotExist() {
    52  	l.parent.serializer.Schedule(func(context.Context) {
    53  		l.parent.onListenerResourceNotFound()
    54  	})
    55  }
    56  
    57  func (l *listenerWatcher) stop() {
    58  	l.cancel()
    59  	l.parent.logger.Infof("Canceling watch on Listener resource %q", l.resourceName)
    60  }
    61  
    62  type routeConfigWatcher struct {
    63  	resourceName string
    64  	cancel       func()
    65  	parent       *xdsResolver
    66  }
    67  
    68  func newRouteConfigWatcher(resourceName string, parent *xdsResolver) *routeConfigWatcher {
    69  	rw := &routeConfigWatcher{resourceName: resourceName, parent: parent}
    70  	rw.cancel = xdsresource.WatchRouteConfig(parent.xdsClient, resourceName, rw)
    71  	return rw
    72  }
    73  
    74  func (r *routeConfigWatcher) OnUpdate(update *xdsresource.RouteConfigResourceData) {
    75  	r.parent.serializer.Schedule(func(context.Context) {
    76  		r.parent.onRouteConfigResourceUpdate(r.resourceName, update.Resource)
    77  	})
    78  }
    79  
    80  func (r *routeConfigWatcher) OnError(err error) {
    81  	r.parent.serializer.Schedule(func(context.Context) {
    82  		r.parent.onRouteConfigResourceError(r.resourceName, err)
    83  	})
    84  }
    85  
    86  func (r *routeConfigWatcher) OnResourceDoesNotExist() {
    87  	r.parent.serializer.Schedule(func(context.Context) {
    88  		r.parent.onRouteConfigResourceNotFound(r.resourceName)
    89  	})
    90  }
    91  
    92  func (r *routeConfigWatcher) stop() {
    93  	r.cancel()
    94  	r.parent.logger.Infof("Canceling watch on RouteConfiguration resource %q", r.resourceName)
    95  }
    96  

View as plain text