// NewVtctlPipe creates a new VtctlPipe based on the given topo server. func NewVtctlPipe(t *testing.T, ts topo.Server) *VtctlPipe { // Register all vtctl commands servenvInitialized.Do(func() { // make sure we use the right protocol flag.Set("vtctl_client_protocol", "grpc") // Enable all query groups flag.Set("enable_queries", "true") servenv.FireRunHooks() }) // Listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } // Create a gRPC server and listen on the port server := grpc.NewServer() grpcvtctlserver.StartServer(server, ts) go server.Serve(listener) // Create a VtctlClient gRPC client to talk to the fake server client, err := vtctlclient.New(listener.Addr().String(), 30*time.Second) if err != nil { t.Fatalf("Cannot create client: %v", err) } return &VtctlPipe{ listener: listener, client: client, t: t, } }
func main() { flag.Parse() // create the client client, err := vtctlclient.New(*server, *dialTimeout) if err != nil { log.Fatalf("Cannot dial to server %v: %v", *server, err) } defer client.Close() // run the command c, errFunc := client.ExecuteVtctlCommand(flag.Args(), *actionTimeout, *lockWaitTimeout) if err = errFunc(); err != nil { log.Fatalf("Cannot execute remote command: %v", err) } // stream the result for e := range c { switch e.Level { case logutil.LOGGER_INFO: log.Info(e.String()) case logutil.LOGGER_WARNING: log.Warning(e.String()) case logutil.LOGGER_ERROR: log.Error(e.String()) case logutil.LOGGER_CONSOLE: fmt.Print(e.Value) } } // then display the overall error if err = errFunc(); err != nil { log.Fatalf("Remote error: %v", err) } }
// NewVtctlPipe creates a new VtctlPipe based on the given topo server. func NewVtctlPipe(t *testing.T, ts topo.Server) *VtctlPipe { // Listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } // Create a Go Rpc server and listen on the port server := rpcplus.NewServer() server.Register(gorpcvtctlserver.NewVtctlServer(ts)) // Create the HTTP server, serve the server from it handler := http.NewServeMux() bsonrpc.ServeCustomRPC(handler, server, false) httpServer := http.Server{ Handler: handler, } go httpServer.Serve(listener) // Create a VtctlClient Go Rpc client to talk to the fake server client, err := vtctlclient.New(listener.Addr().String(), 30*time.Second) if err != nil { t.Fatalf("Cannot create client: %v", err) } return &VtctlPipe{ listener: listener, client: client, t: t, } }
// NewVtctlPipe creates a new VtctlPipe based on the given topo server. func NewVtctlPipe(t *testing.T, ts topo.Server) *VtctlPipe { // Listen on a random port listener, err := net.Listen("tcp", ":0") if err != nil { t.Fatalf("Cannot listen: %v", err) } // Create a gRPC server and listen on the port server := grpc.NewServer() grpcvtctlserver.StartServer(server, ts) go server.Serve(listener) // Create a VtctlClient gRPC client to talk to the fake server client, err := vtctlclient.New(listener.Addr().String(), 30*time.Second) if err != nil { t.Fatalf("Cannot create client: %v", err) } return &VtctlPipe{ listener: listener, client: client, t: t, } }