cluster.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2016 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. package grpcproxy
  15. import (
  16. "github.com/coreos/etcd/clientv3"
  17. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  18. "golang.org/x/net/context"
  19. )
  20. type clusterProxy struct {
  21. client *clientv3.Client
  22. }
  23. func NewClusterProxy(c *clientv3.Client) pb.ClusterServer {
  24. return &clusterProxy{
  25. client: c,
  26. }
  27. }
  28. func (cp *clusterProxy) MemberAdd(ctx context.Context, r *pb.MemberAddRequest) (*pb.MemberAddResponse, error) {
  29. conn := cp.client.ActiveConnection()
  30. return pb.NewClusterClient(conn).MemberAdd(ctx, r)
  31. }
  32. func (cp *clusterProxy) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest) (*pb.MemberRemoveResponse, error) {
  33. conn := cp.client.ActiveConnection()
  34. return pb.NewClusterClient(conn).MemberRemove(ctx, r)
  35. }
  36. func (cp *clusterProxy) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest) (*pb.MemberUpdateResponse, error) {
  37. conn := cp.client.ActiveConnection()
  38. return pb.NewClusterClient(conn).MemberUpdate(ctx, r)
  39. }
  40. func (cp *clusterProxy) MemberList(ctx context.Context, r *pb.MemberListRequest) (*pb.MemberListResponse, error) {
  41. conn := cp.client.ActiveConnection()
  42. return pb.NewClusterClient(conn).MemberList(ctx, r)
  43. }