blob: 4a8781b13adff3419b1b01992d0f09e76c672a61 [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 mts2mtc struct{ mts pb.MaintenanceServer }
26
27func MaintenanceServerToMaintenanceClient(mts pb.MaintenanceServer) pb.MaintenanceClient {
28 return &mts2mtc{mts}
29}
30
31func (s *mts2mtc) Alarm(ctx context.Context, r *pb.AlarmRequest, opts ...grpc.CallOption) (*pb.AlarmResponse, error) {
32 return s.mts.Alarm(ctx, r)
33}
34
35func (s *mts2mtc) Status(ctx context.Context, r *pb.StatusRequest, opts ...grpc.CallOption) (*pb.StatusResponse, error) {
36 return s.mts.Status(ctx, r)
37}
38
39func (s *mts2mtc) Defragment(ctx context.Context, dr *pb.DefragmentRequest, opts ...grpc.CallOption) (*pb.DefragmentResponse, error) {
40 return s.mts.Defragment(ctx, dr)
41}
42
43func (s *mts2mtc) Hash(ctx context.Context, r *pb.HashRequest, opts ...grpc.CallOption) (*pb.HashResponse, error) {
44 return s.mts.Hash(ctx, r)
45}
46
47func (s *mts2mtc) HashKV(ctx context.Context, r *pb.HashKVRequest, opts ...grpc.CallOption) (*pb.HashKVResponse, error) {
48 return s.mts.HashKV(ctx, r)
49}
50
51func (s *mts2mtc) MoveLeader(ctx context.Context, r *pb.MoveLeaderRequest, opts ...grpc.CallOption) (*pb.MoveLeaderResponse, error) {
52 return s.mts.MoveLeader(ctx, r)
53}
54
55func (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
63type ss2scClientStream struct{ chanClientStream }
64
65// ss2scServerStream implements Maintenance_SnapshotServer
66type ss2scServerStream struct{ chanServerStream }
67
68func (s *ss2scClientStream) Send(rr *pb.SnapshotRequest) error {
69 return s.SendMsg(rr)
70}
71func (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
79func (s *ss2scServerStream) Send(rr *pb.SnapshotResponse) error {
80 return s.SendMsg(rr)
81}
82func (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}