dubbo.apache.org/dubbo-go/v3@v3.1.1/xds/client/pubsub/dump.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. 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 * 20 * Copyright 2021 gRPC authors. 21 * 22 */ 23 24 package pubsub 25 26 import ( 27 anypb "github.com/golang/protobuf/ptypes/any" 28 ) 29 30 import ( 31 "dubbo.apache.org/dubbo-go/v3/xds/client/resource" 32 ) 33 34 func rawFromCache(s string, cache interface{}) *anypb.Any { 35 switch c := cache.(type) { 36 case map[string]resource.ListenerUpdate: 37 if v, ok := c[s]; ok { 38 return v.Raw 39 } 40 return nil 41 case map[string]resource.RouteConfigUpdate: 42 if v, ok := c[s]; ok { 43 return v.Raw 44 } 45 return nil 46 case map[string]resource.ClusterUpdate: 47 if v, ok := c[s]; ok { 48 return v.Raw 49 } 50 return nil 51 case map[string]resource.EndpointsUpdate: 52 if v, ok := c[s]; ok { 53 return v.Raw 54 } 55 return nil 56 default: 57 return nil 58 } 59 } 60 61 // Dump dumps the resource for the given type. 62 func (pb *Pubsub) Dump(t resource.ResourceType) map[string]resource.UpdateWithMD { 63 pb.mu.Lock() 64 defer pb.mu.Unlock() 65 66 var ( 67 md map[string]resource.UpdateMetadata 68 cache interface{} 69 ) 70 switch t { 71 case resource.ListenerResource: 72 md = pb.ldsMD 73 cache = pb.ldsCache 74 case resource.RouteConfigResource: 75 md = pb.rdsMD 76 cache = pb.rdsCache 77 case resource.ClusterResource: 78 md = pb.cdsMD 79 cache = pb.cdsCache 80 case resource.EndpointsResource: 81 md = pb.edsMD 82 cache = pb.edsCache 83 default: 84 pb.logger.Errorf("dumping resource of unknown type: %v", t) 85 return nil 86 } 87 88 ret := make(map[string]resource.UpdateWithMD, len(md)) 89 for s, md := range md { 90 ret[s] = resource.UpdateWithMD{ 91 MD: md, 92 Raw: rawFromCache(s, cache), 93 } 94 } 95 return ret 96 }