...

Source file src/google.golang.org/grpc/xds/internal/xdsclient/clientimpl_dump.go

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

     1  /*
     2   *
     3   * Copyright 2021 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 xdsclient
    20  
    21  import (
    22  	"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
    23  )
    24  
    25  func appendMaps(dst, src map[string]map[string]xdsresource.UpdateWithMD) {
    26  	// Iterate through the resource types.
    27  	for rType, srcResources := range src {
    28  		// Lookup/create the resource type specific map in the destination.
    29  		dstResources := dst[rType]
    30  		if dstResources == nil {
    31  			dstResources = make(map[string]xdsresource.UpdateWithMD)
    32  			dst[rType] = dstResources
    33  		}
    34  
    35  		// Iterate through the resources within the resource type in the source,
    36  		// and copy them over to the destination.
    37  		for name, update := range srcResources {
    38  			dstResources[name] = update
    39  		}
    40  	}
    41  }
    42  
    43  // DumpResources returns the status and contents of all xDS resources.
    44  func (c *clientImpl) DumpResources() map[string]map[string]xdsresource.UpdateWithMD {
    45  	c.authorityMu.Lock()
    46  	defer c.authorityMu.Unlock()
    47  	dumps := make(map[string]map[string]xdsresource.UpdateWithMD)
    48  	for _, a := range c.authorities {
    49  		dump := a.dumpResources()
    50  		appendMaps(dumps, dump)
    51  	}
    52  	return dumps
    53  }
    54  

View as plain text