forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
56 lines (44 loc) · 1.82 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2014, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package mysqlctlclient contains the generic client side of the remote
// mysqlctl protocol.
package mysqlctlclient
import (
"flag"
"fmt"
"time"
log "github.com/golang/glog"
"golang.org/x/net/context"
)
var protocol = flag.String("mysqlctl_client_protocol", "grpc", "the protocol to use to talk to the mysqlctl server")
var connectionTimeout = flag.Duration("mysqlctl_client_connection_timeout", 30*time.Second, "the connection timeout to use to talk to the mysqlctl server")
// MysqlctlClient defines the interface used to send remote mysqlctl commands
type MysqlctlClient interface {
// Start calls Mysqld.Start remotely.
Start(ctx context.Context) error
// Shutdown calls Mysqld.Shutdown remotely.
Shutdown(ctx context.Context, waitForMysqld bool) error
// RunMysqlUpgrade calls Mysqld.RunMysqlUpgrade remotely.
RunMysqlUpgrade(ctx context.Context) error
// Close will terminate the connection. This object won't be used anymore.
Close()
}
// Factory functions are registered by client implementations.
type Factory func(network, addr string, dialTimeout time.Duration) (MysqlctlClient, error)
var factories = make(map[string]Factory)
// RegisterFactory allows a client implementation to register itself
func RegisterFactory(name string, factory Factory) {
if _, ok := factories[name]; ok {
log.Fatalf("RegisterFactory %s already exists", name)
}
factories[name] = factory
}
// New creates a client implementation as specified by a flag.
func New(network, addr string) (MysqlctlClient, error) {
factory, ok := factories[*protocol]
if !ok {
return nil, fmt.Errorf("unknown mysqlctl client protocol: %v", *protocol)
}
return factory(network, addr, *connectionTimeout)
}