forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
118 lines (93 loc) · 2.78 KB
/
command.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package coordinator
import (
"github.com/influxdb/raft"
)
type DropDatabaseCommand struct {
Name string `json:"name"`
}
func NewDropDatabaseCommand(name string) *DropDatabaseCommand {
return &DropDatabaseCommand{name}
}
func (c *DropDatabaseCommand) CommandName() string {
return "drop_db"
}
func (c *DropDatabaseCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
err := config.DropDatabase(c.Name)
return nil, err
}
type CreateDatabaseCommand struct {
Name string `json:"name"`
}
func NewCreateDatabaseCommand(name string) *CreateDatabaseCommand {
return &CreateDatabaseCommand{name}
}
func (c *CreateDatabaseCommand) CommandName() string {
return "create_db"
}
func (c *CreateDatabaseCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
err := config.CreateDatabase(c.Name)
return nil, err
}
type SaveDbUserCommand struct {
User *dbUser `json:"user"`
}
func NewSaveDbUserCommand(u *dbUser) *SaveDbUserCommand {
return &SaveDbUserCommand{
User: u,
}
}
func (c *SaveDbUserCommand) CommandName() string {
return "save_db_user"
}
func (c *SaveDbUserCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
config.SaveDbUser(c.User)
return nil, nil
}
type SaveClusterAdminCommand struct {
User *clusterAdmin `json:"user"`
}
func NewSaveClusterAdminCommand(u *clusterAdmin) *SaveClusterAdminCommand {
return &SaveClusterAdminCommand{
User: u,
}
}
func (c *SaveClusterAdminCommand) CommandName() string {
return "save_cluster_admin_user"
}
func (c *SaveClusterAdminCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
config.SaveClusterAdmin(c.User)
return nil, nil
}
type AddPotentialServerCommand struct {
Server *ClusterServer
}
func NewAddPotentialServerCommand(s *ClusterServer) *AddPotentialServerCommand {
return &AddPotentialServerCommand{Server: s}
}
func (c *AddPotentialServerCommand) CommandName() string {
return "add_server"
}
func (c *AddPotentialServerCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
config.AddPotentialServer(c.Server)
return nil, nil
}
type UpdateServerStateCommand struct {
ServerId uint32
State ServerState
}
func NewUpdateServerStateCommand(serverId uint32, state ServerState) *UpdateServerStateCommand {
return &UpdateServerStateCommand{ServerId: serverId, State: state}
}
func (c *UpdateServerStateCommand) CommandName() string {
return "update_state"
}
func (c *UpdateServerStateCommand) Apply(server raft.Server) (interface{}, error) {
config := server.Context().(*ClusterConfiguration)
err := config.UpdateServerState(c.ServerId, c.State)
return nil, err
}