mirror of
https://github.com/datarhei/core.git
synced 2025-10-04 23:53:12 +08:00
38 lines
667 B
Go
38 lines
667 B
Go
package cluster
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/datarhei/core/v16/cluster/store"
|
|
)
|
|
|
|
func (c *cluster) ListNodes() map[string]store.Node {
|
|
return c.store.ListNodes()
|
|
}
|
|
|
|
var ErrUnsupportedNodeState = errors.New("unsupported node state")
|
|
|
|
func (c *cluster) SetNodeState(origin, id, state string) error {
|
|
switch state {
|
|
case "online":
|
|
case "maintenance":
|
|
case "leave":
|
|
default:
|
|
return ErrUnsupportedNodeState
|
|
}
|
|
|
|
if !c.IsRaftLeader() {
|
|
return c.forwarder.SetNodeState(origin, id, state)
|
|
}
|
|
|
|
cmd := &store.Command{
|
|
Operation: store.OpSetNodeState,
|
|
Data: &store.CommandSetNodeState{
|
|
NodeID: id,
|
|
State: state,
|
|
},
|
|
}
|
|
|
|
return c.applyCommand(cmd)
|
|
}
|