-
Notifications
You must be signed in to change notification settings - Fork 8
/
commands.go
101 lines (85 loc) · 2.46 KB
/
commands.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
package cluster
// Command Creators
import (
"errors"
"time"
"github.com/b3scale/b3scale/pkg/store"
)
// Commands that can be handled by the controller
const (
// Backend
CmdUpdateNodeState = "update_node_state"
CmdDecommissionBackend = "decommission_backend"
// Meetings
CmdUpdateMeetingState = "update_meeting_state"
CmdEndAllMeetings = "end_all_meetings"
// Maintenance
CmdCollectGarbage = "collect_garbage"
)
var (
// ErrUnknownCommand indicates, that the command was not
// understood by the controller.
ErrUnknownCommand = errors.New("command unknown")
)
// DecommissionBackendRequest declares the removal
// of a backend node from the cluster state.
type DecommissionBackendRequest struct {
ID string `json:"id"`
}
// DecommissionBackend will remove a given cluster
// backend from the state.
func DecommissionBackend(req *DecommissionBackendRequest) *store.Command {
return &store.Command{
Action: CmdDecommissionBackend,
Params: req,
Deadline: store.NextDeadline(10 * time.Minute),
}
}
// UpdateNodeStateRequest requests a status update
// from a backend identified by ID
type UpdateNodeStateRequest struct {
ID string // the backend state id
}
// UpdateNodeState creates a update status command
func UpdateNodeState(req *UpdateNodeStateRequest) *store.Command {
return &store.Command{
Action: CmdUpdateNodeState,
Params: req,
Deadline: store.NextDeadline(10 * time.Minute),
}
}
// UpdateMeetingStateRequest requests the refresh of a meeting
type UpdateMeetingStateRequest struct {
ID string // the meeting ID
}
// UpdateMeetingState makes a new meeting refresh command
func UpdateMeetingState(
req *UpdateMeetingStateRequest,
) *store.Command {
return &store.Command{
Action: CmdUpdateMeetingState,
Params: req,
Deadline: store.NextDeadline(10 * time.Minute),
}
}
// EndAllMeetingsRequest contains parameters for the end
// all meetings command.
type EndAllMeetingsRequest struct {
BackendID string
}
// EndAllMeetings will send end meeting api requests to all running meetings
// on a backend. This can be usefull to force decommissioning.
func EndAllMeetings(req *EndAllMeetingsRequest) *store.Command {
return &store.Command{
Action: CmdEndAllMeetings,
Params: req,
Deadline: store.NextDeadline(5 * time.Minute),
}
}
// CollectGarbage requests removing stale states.
func CollectGarbage() *store.Command {
return &store.Command{
Action: CmdCollectGarbage,
Deadline: store.NextDeadline(5 * time.Minute),
}
}