1 /* 2 * 3 * Copyright 2023 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 nop implements a balancer with all of its balancer operations as 20 // no-ops, other than returning a Transient Failure Picker on a Client Conn 21 // update. 22 package nop 23 24 import ( 25 "google.golang.org/grpc/balancer" 26 "google.golang.org/grpc/balancer/base" 27 "google.golang.org/grpc/connectivity" 28 ) 29 30 // bal is a balancer with all of its balancer operations as no-ops, other than 31 // returning a Transient Failure Picker on a Client Conn update. 32 type bal struct { 33 cc balancer.ClientConn 34 err error 35 } 36 37 // NewBalancer returns a no-op balancer. 38 func NewBalancer(cc balancer.ClientConn, err error) balancer.Balancer { 39 return &bal{ 40 cc: cc, 41 err: err, 42 } 43 } 44 45 // UpdateClientConnState updates the bal's Client Conn with an Error Picker 46 // and a Connectivity State of TRANSIENT_FAILURE. 47 func (b *bal) UpdateClientConnState(_ balancer.ClientConnState) error { 48 b.cc.UpdateState(balancer.State{ 49 Picker: base.NewErrPicker(b.err), 50 ConnectivityState: connectivity.TransientFailure, 51 }) 52 return nil 53 } 54 55 // ResolverError is a no-op. 56 func (b *bal) ResolverError(_ error) {} 57 58 // UpdateSubConnState is a no-op. 59 func (b *bal) UpdateSubConnState(_ balancer.SubConn, _ balancer.SubConnState) {} 60 61 // Close is a no-op. 62 func (b *bal) Close() {} 63