forked from TrueCloudLab/frostfs-node
[#1681] morph/netmap: Support MAINTENANCE state notification
After recent changes Netmap contract can send `UpdateState` notification event with `MAINTENANCE` node's state. There is a need to provide functionality to work with the status. Provide `UpdatePeer.Maintenance` method. Support new state in `ParseUpdatePeer` and `ParseUpdatePeerNotary` functions. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
0903b2af93
commit
bdb8243a5a
2 changed files with 17 additions and 4 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
const (
|
||||
_ int8 = iota
|
||||
stateOnline
|
||||
stateMaintenance
|
||||
)
|
||||
|
||||
type UpdatePeer struct {
|
||||
|
@ -31,10 +32,18 @@ type UpdatePeer struct {
|
|||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (UpdatePeer) MorphEvent() {}
|
||||
|
||||
// Online returns true if node's state is requested to be switched
|
||||
// to "online".
|
||||
func (s UpdatePeer) Online() bool {
|
||||
return s.state == stateOnline
|
||||
}
|
||||
|
||||
// Maintenance returns true if node's state is requested to be switched
|
||||
// to "maintenance".
|
||||
func (s UpdatePeer) Maintenance() bool {
|
||||
return s.state == stateMaintenance
|
||||
}
|
||||
|
||||
func (s UpdatePeer) PublicKey() *keys.PublicKey {
|
||||
return s.publicKey
|
||||
}
|
||||
|
@ -85,6 +94,8 @@ func ParseUpdatePeer(e *state.ContainedNotificationEvent) (event.Event, error) {
|
|||
case int64(netmap.OfflineState):
|
||||
case int64(netmap.OnlineState):
|
||||
ev.state = stateOnline
|
||||
case int64(netmap.OfflineState) + 1: // FIXME: use named constant after neofs-contract#269
|
||||
ev.state = stateMaintenance
|
||||
}
|
||||
|
||||
return ev, nil
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||
"github.com/nspcc-dev/neofs-contract/netmap"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
)
|
||||
|
||||
|
@ -61,12 +61,14 @@ func ParseUpdatePeerNotary(ne event.NotaryEvent) (event.Event, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
switch v2netmap.NodeState(state) {
|
||||
switch state {
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported node state %d", err)
|
||||
case v2netmap.Offline:
|
||||
case v2netmap.Online:
|
||||
case int64(netmap.OfflineState):
|
||||
case int64(netmap.OnlineState):
|
||||
ev.state = stateOnline
|
||||
case int64(netmap.OfflineState) + 1: // FIXME: use named constant after neofs-contract#269
|
||||
ev.state = stateMaintenance
|
||||
}
|
||||
|
||||
fieldNum++
|
||||
|
|
Loading…
Reference in a new issue