dubbo.apache.org/dubbo-go/v3@v3.1.1/xds/client/resource/type.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 resource 25 26 import ( 27 "time" 28 ) 29 30 import ( 31 "google.golang.org/protobuf/types/known/anypb" 32 ) 33 34 import ( 35 "dubbo.apache.org/dubbo-go/v3/xds/client/resource/version" 36 ) 37 38 // UpdateValidatorFunc performs validations on update structs using 39 // context/logic available at the xdsClient layer. Since these validation are 40 // performed on internal update structs, they can be shared between different 41 // API clients. 42 type UpdateValidatorFunc func(interface{}) error 43 44 // UpdateMetadata contains the metadata for each update, including timestamp, 45 // raw message, and so on. 46 type UpdateMetadata struct { 47 // Status is the status of this resource, e.g. ACKed, NACKed, or 48 // Not_exist(removed). 49 Status ServiceStatus 50 // Version is the version of the xds response. Note that this is the version 51 // of the resource in use (previous ACKed). If a response is NACKed, the 52 // NACKed version is in ErrState. 53 Version string 54 // Timestamp is when the response is received. 55 Timestamp time.Time 56 // ErrState is set when the update is NACKed. 57 ErrState *UpdateErrorMetadata 58 } 59 60 // IsListenerResource returns true if the provider URL corresponds to an xDS 61 // Listener resource. 62 func IsListenerResource(url string) bool { 63 return url == version.V2ListenerURL || url == version.V3ListenerURL 64 } 65 66 // IsHTTPConnManagerResource returns true if the provider URL corresponds to an xDS 67 // HTTPConnManager resource. 68 func IsHTTPConnManagerResource(url string) bool { 69 return url == version.V2HTTPConnManagerURL || url == version.V3HTTPConnManagerURL 70 } 71 72 // IsRouteConfigResource returns true if the provider URL corresponds to an xDS 73 // RouteConfig resource. 74 func IsRouteConfigResource(url string) bool { 75 return url == version.V2RouteConfigURL || url == version.V3RouteConfigURL 76 } 77 78 // IsClusterResource returns true if the provider URL corresponds to an xDS 79 // Cluster resource. 80 func IsClusterResource(url string) bool { 81 return url == version.V2ClusterURL || url == version.V3ClusterURL 82 } 83 84 // IsEndpointsResource returns true if the provider URL corresponds to an xDS 85 // Endpoints resource. 86 func IsEndpointsResource(url string) bool { 87 return url == version.V2EndpointsURL || url == version.V3EndpointsURL 88 } 89 90 // ServiceStatus is the status of the update. 91 type ServiceStatus int 92 93 const ( 94 // ServiceStatusUnknown is the default state, before a watch is started for 95 // the resource. 96 ServiceStatusUnknown ServiceStatus = iota 97 // ServiceStatusRequested is when the watch is started, but before and 98 // response is received. 99 ServiceStatusRequested 100 // ServiceStatusNotExist is when the resource doesn't exist in 101 // state-of-the-world responses (e.g. LDS and CDS), which means the resource 102 // is removed by the management server. 103 ServiceStatusNotExist // Resource is removed in the server, in LDS/CDS. 104 // ServiceStatusACKed is when the resource is ACKed. 105 ServiceStatusACKed 106 // ServiceStatusNACKed is when the resource is NACKed. 107 ServiceStatusNACKed 108 ) 109 110 // UpdateErrorMetadata is part of UpdateMetadata. It contains the error state 111 // when a response is NACKed. 112 type UpdateErrorMetadata struct { 113 // Version is the version of the NACKed response. 114 Version string 115 // Err contains why the response was NACKed. 116 Err error 117 // Timestamp is when the NACKed response was received. 118 Timestamp time.Time 119 } 120 121 // UpdateWithMD contains the raw message of the update and the metadata, 122 // including version, raw message, timestamp. 123 // 124 // This is to be used for config dump and CSDS, not directly by users (like 125 // resolvers/balancers). 126 type UpdateWithMD struct { 127 MD UpdateMetadata 128 Raw *anypb.Any 129 } 130 131 // ResourceType identifies resources in a transport protocol agnostic way. These 132 // will be used in transport version agnostic code, while the versioned API 133 // clients will map these to appropriate version URLs. 134 type ResourceType int 135 136 // Version agnostic resource type constants. 137 const ( 138 UnknownResource ResourceType = iota 139 ListenerResource 140 HTTPConnManagerResource 141 RouteConfigResource 142 ClusterResource 143 EndpointsResource 144 ) 145 146 func (r ResourceType) String() string { 147 switch r { 148 case ListenerResource: 149 return "ListenerResource" 150 case HTTPConnManagerResource: 151 return "HTTPConnManagerResource" 152 case RouteConfigResource: 153 return "RouteConfigResource" 154 case ClusterResource: 155 return "ClusterResource" 156 case EndpointsResource: 157 return "EndpointsResource" 158 default: 159 return "UnknownResource" 160 } 161 }