vitess.io/vitess@v0.16.2/go/vt/mysqlctl/grpcmysqlctlserver/server.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 Package grpcmysqlctlserver contains the gRPC implementation of the server 19 side of the remote execution of mysqlctl commands. 20 */ 21 package grpcmysqlctlserver 22 23 import ( 24 "google.golang.org/grpc" 25 26 "context" 27 28 "vitess.io/vitess/go/vt/mysqlctl" 29 30 mysqlctlpb "vitess.io/vitess/go/vt/proto/mysqlctl" 31 ) 32 33 // server is our gRPC server. 34 type server struct { 35 mysqlctlpb.UnimplementedMysqlCtlServer 36 cnf *mysqlctl.Mycnf 37 mysqld *mysqlctl.Mysqld 38 } 39 40 // Start implements the server side of the MysqlctlClient interface. 41 func (s *server) Start(ctx context.Context, request *mysqlctlpb.StartRequest) (*mysqlctlpb.StartResponse, error) { 42 return &mysqlctlpb.StartResponse{}, s.mysqld.Start(ctx, s.cnf, request.MysqldArgs...) 43 } 44 45 // Shutdown implements the server side of the MysqlctlClient interface. 46 func (s *server) Shutdown(ctx context.Context, request *mysqlctlpb.ShutdownRequest) (*mysqlctlpb.ShutdownResponse, error) { 47 return &mysqlctlpb.ShutdownResponse{}, s.mysqld.Shutdown(ctx, s.cnf, request.WaitForMysqld) 48 } 49 50 // RunMysqlUpgrade implements the server side of the MysqlctlClient interface. 51 func (s *server) RunMysqlUpgrade(ctx context.Context, request *mysqlctlpb.RunMysqlUpgradeRequest) (*mysqlctlpb.RunMysqlUpgradeResponse, error) { 52 return &mysqlctlpb.RunMysqlUpgradeResponse{}, s.mysqld.RunMysqlUpgrade() 53 } 54 55 // ReinitConfig implements the server side of the MysqlctlClient interface. 56 func (s *server) ReinitConfig(ctx context.Context, request *mysqlctlpb.ReinitConfigRequest) (*mysqlctlpb.ReinitConfigResponse, error) { 57 return &mysqlctlpb.ReinitConfigResponse{}, s.mysqld.ReinitConfig(ctx, s.cnf) 58 } 59 60 // RefreshConfig implements the server side of the MysqlctlClient interface. 61 func (s *server) RefreshConfig(ctx context.Context, request *mysqlctlpb.RefreshConfigRequest) (*mysqlctlpb.RefreshConfigResponse, error) { 62 return &mysqlctlpb.RefreshConfigResponse{}, s.mysqld.RefreshConfig(ctx, s.cnf) 63 } 64 65 // StartServer registers the Server for RPCs. 66 func StartServer(s *grpc.Server, cnf *mysqlctl.Mycnf, mysqld *mysqlctl.Mysqld) { 67 mysqlctlpb.RegisterMysqlCtlServer(s, &server{cnf: cnf, mysqld: mysqld}) 68 }