Skip to content

Commit

Permalink
Merge pull request #7238 from tinyspeck/am_vtctldclient_generator
Browse files Browse the repository at this point in the history
[vtctldclient] vtctldclient generator
  • Loading branch information
deepthi authored Jan 5, 2021
2 parents 8e01691 + 8adcd2e commit f51ac19
Show file tree
Hide file tree
Showing 7 changed files with 436 additions and 33 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ install-testing: build
mkdir -p "$${PREFIX}/web/vtctld2"
cp -R web/vtctld2/app "$${PREFIX}/web/vtctld2"

grpcvtctldclient: go/vt/proto/vtctlservice/vtctlservice.pb.go
make -C go/vt/vtctl/grpcvtctldclient

parser:
make -C go/vt/sqlparser

Expand Down
19 changes: 19 additions & 0 deletions go/vt/vtctl/grpcvtctldclient/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 The Vitess 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.

MAKEFLAGS = -s

generate:
go generate ./...
gofmt -w client_gen.go
36 changes: 4 additions & 32 deletions go/vt/vtctl/grpcvtctldclient/client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Vitess Authors.
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,17 +19,13 @@ limitations under the License.
package grpcvtctldclient

import (
"context"
"flag"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"vitess.io/vitess/go/vt/grpcclient"
"vitess.io/vitess/go/vt/vtctl/vtctldclient"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice"
)

Expand All @@ -56,6 +52,9 @@ type gRPCVtctldClient struct {
c vtctlservicepb.VtctldClient
}

//go:generate -command grpcvtctldclient go run ./codegen
//go:generate grpcvtctldclient -out client_gen.go

func gRPCVtctldClientFactory(addr string) (vtctldclient.VtctldClient, error) {
opt, err := grpcclient.SecureDialOption(*cert, *key, *ca, *name)
if err != nil {
Expand All @@ -82,33 +81,6 @@ func (client *gRPCVtctldClient) Close() error {
return err
}

// (TODO:@amason) - This boilerplate should end up the same for all ~70 commands
// .... we should do this with code gen.

func (client *gRPCVtctldClient) FindAllShardsInKeyspace(ctx context.Context, in *vtctldatapb.FindAllShardsInKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.FindAllShardsInKeyspaceResponse, error) {
if client.c == nil {
return nil, status.Error(codes.Unavailable, connClosedMsg)
}

return client.c.FindAllShardsInKeyspace(ctx, in, opts...)
}

func (client *gRPCVtctldClient) GetKeyspace(ctx context.Context, in *vtctldatapb.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.GetKeyspaceResponse, error) {
if client.c == nil {
return nil, status.Error(codes.Unavailable, connClosedMsg)
}

return client.c.GetKeyspace(ctx, in, opts...)
}

func (client *gRPCVtctldClient) GetKeyspaces(ctx context.Context, in *vtctldatapb.GetKeyspacesRequest, opts ...grpc.CallOption) (*vtctldatapb.GetKeyspacesResponse, error) {
if client.c == nil {
return nil, status.Error(codes.Unavailable, connClosedMsg)
}

return client.c.GetKeyspaces(ctx, in, opts...)
}

func init() {
vtctldclient.Register("grpc", gRPCVtctldClientFactory)
}
56 changes: 56 additions & 0 deletions go/vt/vtctl/grpcvtctldclient/client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go/vt/vtctl/grpcvtctldclient/client_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Vitess Authors.
Copyright 2021 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit f51ac19

Please sign in to comment.