go.etcd.io/etcd@v3.3.27+incompatible/proxy/grpcproxy/adapter/maintenance_client_adapter.go (about) 1 // Copyright 2017 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package adapter 16 17 import ( 18 "context" 19 20 pb "github.com/coreos/etcd/etcdserver/etcdserverpb" 21 22 "google.golang.org/grpc" 23 ) 24 25 type mts2mtc struct{ mts pb.MaintenanceServer } 26 27 func MaintenanceServerToMaintenanceClient(mts pb.MaintenanceServer) pb.MaintenanceClient { 28 return &mts2mtc{mts} 29 } 30 31 func (s *mts2mtc) Alarm(ctx context.Context, r *pb.AlarmRequest, opts ...grpc.CallOption) (*pb.AlarmResponse, error) { 32 return s.mts.Alarm(ctx, r) 33 } 34 35 func (s *mts2mtc) Status(ctx context.Context, r *pb.StatusRequest, opts ...grpc.CallOption) (*pb.StatusResponse, error) { 36 return s.mts.Status(ctx, r) 37 } 38 39 func (s *mts2mtc) Defragment(ctx context.Context, dr *pb.DefragmentRequest, opts ...grpc.CallOption) (*pb.DefragmentResponse, error) { 40 return s.mts.Defragment(ctx, dr) 41 } 42 43 func (s *mts2mtc) Hash(ctx context.Context, r *pb.HashRequest, opts ...grpc.CallOption) (*pb.HashResponse, error) { 44 return s.mts.Hash(ctx, r) 45 } 46 47 func (s *mts2mtc) HashKV(ctx context.Context, r *pb.HashKVRequest, opts ...grpc.CallOption) (*pb.HashKVResponse, error) { 48 return s.mts.HashKV(ctx, r) 49 } 50 51 func (s *mts2mtc) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest, opts ...grpc.CallOption) (*pb.MoveLeaderResponse, error) { 52 return s.mts.MoveLeader(ctx, r) 53 } 54 55 func (s *mts2mtc) Snapshot(ctx context.Context, in *pb.SnapshotRequest, opts ...grpc.CallOption) (pb.Maintenance_SnapshotClient, error) { 56 cs := newPipeStream(ctx, func(ss chanServerStream) error { 57 return s.mts.Snapshot(in, &ss2scServerStream{ss}) 58 }) 59 return &ss2scClientStream{cs}, nil 60 } 61 62 // ss2scClientStream implements Maintenance_SnapshotClient 63 type ss2scClientStream struct{ chanClientStream } 64 65 // ss2scServerStream implements Maintenance_SnapshotServer 66 type ss2scServerStream struct{ chanServerStream } 67 68 func (s *ss2scClientStream) Send(rr *pb.SnapshotRequest) error { 69 return s.SendMsg(rr) 70 } 71 func (s *ss2scClientStream) Recv() (*pb.SnapshotResponse, error) { 72 var v interface{} 73 if err := s.RecvMsg(&v); err != nil { 74 return nil, err 75 } 76 return v.(*pb.SnapshotResponse), nil 77 } 78 79 func (s *ss2scServerStream) Send(rr *pb.SnapshotResponse) error { 80 return s.SendMsg(rr) 81 } 82 func (s *ss2scServerStream) Recv() (*pb.SnapshotRequest, error) { 83 var v interface{} 84 if err := s.RecvMsg(&v); err != nil { 85 return nil, err 86 } 87 return v.(*pb.SnapshotRequest), nil 88 }