blob: a58408f9f291649855a4f112f8353df9442eb525 [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001// 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
15package adapter
16
17import (
18 "context"
19
20 pb "go.etcd.io/etcd/etcdserver/etcdserverpb"
21
22 "google.golang.org/grpc"
23)
24
25type ls2lc struct {
26 leaseServer pb.LeaseServer
27}
28
29func LeaseServerToLeaseClient(ls pb.LeaseServer) pb.LeaseClient {
30 return &ls2lc{ls}
31}
32
33func (c *ls2lc) LeaseGrant(ctx context.Context, in *pb.LeaseGrantRequest, opts ...grpc.CallOption) (*pb.LeaseGrantResponse, error) {
34 return c.leaseServer.LeaseGrant(ctx, in)
35}
36
37func (c *ls2lc) LeaseRevoke(ctx context.Context, in *pb.LeaseRevokeRequest, opts ...grpc.CallOption) (*pb.LeaseRevokeResponse, error) {
38 return c.leaseServer.LeaseRevoke(ctx, in)
39}
40
41func (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
48func (c *ls2lc) LeaseTimeToLive(ctx context.Context, in *pb.LeaseTimeToLiveRequest, opts ...grpc.CallOption) (*pb.LeaseTimeToLiveResponse, error) {
49 return c.leaseServer.LeaseTimeToLive(ctx, in)
50}
51
52func (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
57type ls2lcClientStream struct{ chanClientStream }
58
59// ls2lcServerStream implements Lease_LeaseKeepAliveServer
60type ls2lcServerStream struct{ chanServerStream }
61
62func (s *ls2lcClientStream) Send(rr *pb.LeaseKeepAliveRequest) error {
63 return s.SendMsg(rr)
64}
65func (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
73func (s *ls2lcServerStream) Send(rr *pb.LeaseKeepAliveResponse) error {
74 return s.SendMsg(rr)
75}
76func (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}