Skip to content

Commit

Permalink
Merge pull request #7656 from gyuho/more-adapter
Browse files Browse the repository at this point in the history
*: add cluster API adapter
  • Loading branch information
gyuho authored Apr 5, 2017
2 parents 6335506 + 1e3274d commit d51d381
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions clientv3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func NewCluster(c *Client) Cluster {
return &cluster{remote: RetryClusterClient(c)}
}

func NewClusterFromClusterClient(remote pb.ClusterClient) Cluster {
return &cluster{remote: remote}
}

func (c *cluster) MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error) {
r := &pb.MemberAddRequest{PeerURLs: peerAddrs}
resp, err := c.remote.MemberAdd(ctx, r)
Expand Down
5 changes: 5 additions & 0 deletions etcdserver/api/v3client/v3client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,10 @@ func New(s *etcdserver.EtcdServer) *clientv3.Client {
mc := adapter.MaintenanceServerToMaintenanceClient(v3rpc.NewMaintenanceServer(s))
c.Maintenance = clientv3.NewMaintenanceFromMaintenanceClient(mc)

clc := adapter.ClusterServerToClusterClient(v3rpc.NewClusterServer(s))
c.Cluster = clientv3.NewClusterFromClusterClient(clc)

// TODO: implement clientv3.Auth interface?

return c
}
3 changes: 2 additions & 1 deletion integration/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ func toGRPC(c *clientv3.Client) grpcAPI {
wp, wpch := grpcproxy.NewWatchProxy(c)
lp, lpch := grpcproxy.NewLeaseProxy(c)
mp := grpcproxy.NewMaintenanceProxy(c)
clp, _ := grpcproxy.NewClusterProxy(c, "", "") // without registering proxy URLs

grpc := grpcAPI{
pb.NewClusterClient(c.ActiveConnection()),
adapter.ClusterServerToClusterClient(clp),
adapter.KvServerToKvClient(kvp),
adapter.LeaseServerToLeaseClient(lp),
adapter.WatchServerToWatchClient(wp),
Expand Down
44 changes: 44 additions & 0 deletions proxy/grpcproxy/adapter/cluster_client_adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2017 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package adapter

import (
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"

"golang.org/x/net/context"
"google.golang.org/grpc"
)

type cls2clc struct{ cls pb.ClusterServer }

func ClusterServerToClusterClient(cls pb.ClusterServer) pb.ClusterClient {
return &cls2clc{cls}
}

func (s *cls2clc) MemberList(ctx context.Context, r *pb.MemberListRequest, opts ...grpc.CallOption) (*pb.MemberListResponse, error) {
return s.cls.MemberList(ctx, r)
}

func (s *cls2clc) MemberAdd(ctx context.Context, r *pb.MemberAddRequest, opts ...grpc.CallOption) (*pb.MemberAddResponse, error) {
return s.cls.MemberAdd(ctx, r)
}

func (s *cls2clc) MemberUpdate(ctx context.Context, r *pb.MemberUpdateRequest, opts ...grpc.CallOption) (*pb.MemberUpdateResponse, error) {
return s.cls.MemberUpdate(ctx, r)
}

func (s *cls2clc) MemberRemove(ctx context.Context, r *pb.MemberRemoveRequest, opts ...grpc.CallOption) (*pb.MemberRemoveResponse, error) {
return s.cls.MemberRemove(ctx, r)
}

0 comments on commit d51d381

Please sign in to comment.