khenaidoo | ab1f7bd | 2019-11-14 14:00:27 -0500 | [diff] [blame] | 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 "go.etcd.io/etcd/etcdserver/etcdserverpb" |
| 21 | |
| 22 | "google.golang.org/grpc" |
| 23 | ) |
| 24 | |
| 25 | type ls2lc struct { |
| 26 | leaseServer pb.LeaseServer |
| 27 | } |
| 28 | |
| 29 | func LeaseServerToLeaseClient(ls pb.LeaseServer) pb.LeaseClient { |
| 30 | return &ls2lc{ls} |
| 31 | } |
| 32 | |
| 33 | func (c *ls2lc) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (*pb.LeaseGrantResponse, error) { |
| 34 | return c.leaseServer.LeaseGrant(ctx, in) |
| 35 | } |
| 36 | |
| 37 | func (c *ls2lc) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (*pb.LeaseRevokeResponse, error) { |
| 38 | return c.leaseServer.LeaseRevoke(ctx, in) |
| 39 | } |
| 40 | |
| 41 | func (c *ls2lc) LeaseKeepAlive(ctx context.Context, opts ...grpc.CallOption) (pb.Lease_LeaseKeepAliveClient, error) { |
| 42 | cs := newPipeStream(ctx, func(ss chanServerStream) error { |
| 43 | return c.leaseServer.LeaseKeepAlive(&ls2lcServerStream{ss}) |
| 44 | }) |
| 45 | return &ls2lcClientStream{cs}, nil |
| 46 | } |
| 47 | |
| 48 | func (c *ls2lc) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*pb.LeaseTimeToLiveResponse, error) { |
| 49 | return c.leaseServer.LeaseTimeToLive(ctx, in) |
| 50 | } |
| 51 | |
| 52 | func (c *ls2lc) LeaseLeases(ctx context.Context, in *pb.LeaseLeasesRequest, opts ...grpc.CallOption) (*pb.LeaseLeasesResponse, error) { |
| 53 | return c.leaseServer.LeaseLeases(ctx, in) |
| 54 | } |
| 55 | |
| 56 | // ls2lcClientStream implements Lease_LeaseKeepAliveClient |
| 57 | type ls2lcClientStream struct{ chanClientStream } |
| 58 | |
| 59 | // ls2lcServerStream implements Lease_LeaseKeepAliveServer |
| 60 | type ls2lcServerStream struct{ chanServerStream } |
| 61 | |
| 62 | func (s *ls2lcClientStream) Send(rr *pb.LeaseKeepAliveRequest) error { |
| 63 | return s.SendMsg(rr) |
| 64 | } |
| 65 | func (s *ls2lcClientStream) Recv() (*pb.LeaseKeepAliveResponse, error) { |
| 66 | var v interface{} |
| 67 | if err := s.RecvMsg(&v); err != nil { |
| 68 | return nil, err |
| 69 | } |
| 70 | return v.(*pb.LeaseKeepAliveResponse), nil |
| 71 | } |
| 72 | |
| 73 | func (s *ls2lcServerStream) Send(rr *pb.LeaseKeepAliveResponse) error { |
| 74 | return s.SendMsg(rr) |
| 75 | } |
| 76 | func (s *ls2lcServerStream) Recv() (*pb.LeaseKeepAliveRequest, error) { |
| 77 | var v interface{} |
| 78 | if err := s.RecvMsg(&v); err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | return v.(*pb.LeaseKeepAliveRequest), nil |
| 82 | } |