2022-09-19 10:34:55 +00:00
|
|
|
/*
|
|
|
|
Package state collects functionality for verifying states of network map members.
|
|
|
|
|
|
|
|
NetMapCandidateValidator type provides an interface for checking the network
|
|
|
|
map candidates.
|
|
|
|
*/
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
2022-09-19 10:34:55 +00:00
|
|
|
)
|
|
|
|
|
2022-09-19 14:36:54 +00:00
|
|
|
// ErrMaintenanceModeDisallowed is returned when maintenance mode is disallowed.
|
|
|
|
var ErrMaintenanceModeDisallowed = errors.New("maintenance mode is disallowed")
|
|
|
|
|
2023-02-05 15:59:38 +00:00
|
|
|
// NetworkSettings encapsulates current settings of the FrostFS network and
|
2022-09-19 14:36:54 +00:00
|
|
|
// provides interface used for processing the network map candidates.
|
|
|
|
type NetworkSettings interface {
|
|
|
|
// MaintenanceModeAllowed checks if maintenance state of the storage nodes
|
|
|
|
// is allowed to be set, and returns:
|
|
|
|
// no error if allowed;
|
|
|
|
// ErrMaintenanceModeDisallowed if disallowed;
|
|
|
|
// other error if there are any problems with the check.
|
|
|
|
MaintenanceModeAllowed() error
|
|
|
|
}
|
|
|
|
|
2022-09-19 10:34:55 +00:00
|
|
|
// NetMapCandidateValidator represents tool which checks state of nodes which
|
2023-02-05 15:59:38 +00:00
|
|
|
// are going to register in the FrostFS network (enter the network map).
|
2022-09-19 10:34:55 +00:00
|
|
|
//
|
|
|
|
// NetMapCandidateValidator can be instantiated using built-in var declaration
|
|
|
|
// and currently doesn't require any additional initialization.
|
|
|
|
//
|
|
|
|
// NetMapCandidateValidator implements
|
2022-12-23 17:35:35 +00:00
|
|
|
// github.com/nspcc-dev/frostfs-node/pkg/innerring/processors/netmap.NodeValidator.
|
2022-09-19 10:34:55 +00:00
|
|
|
type NetMapCandidateValidator struct {
|
2022-09-19 14:36:54 +00:00
|
|
|
netSettings NetworkSettings
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetNetworkSettings specifies provider of the NetworkSettings interface.
|
|
|
|
// MUST be called before any VerifyAndUpdate call. Parameter MUST NOT be nil.
|
|
|
|
func (x *NetMapCandidateValidator) SetNetworkSettings(netSettings NetworkSettings) {
|
|
|
|
x.netSettings = netSettings
|
2022-09-19 10:34:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyAndUpdate checks state of the network map candidate described by
|
|
|
|
// netmap.NodeInfo parameter. Returns no error if status is correct, otherwise
|
|
|
|
// returns an error describing a violation of the rules:
|
|
|
|
//
|
2022-09-19 14:36:54 +00:00
|
|
|
// status MUST be either ONLINE or MAINTENANCE;
|
|
|
|
// if status is MAINTENANCE, then it SHOULD be allowed by the network.
|
2022-09-19 10:34:55 +00:00
|
|
|
//
|
|
|
|
// VerifyAndUpdate does not mutate the parameter in a binary format.
|
2022-09-19 14:36:54 +00:00
|
|
|
// MUST NOT be called before SetNetworkSettings.
|
2022-09-19 10:34:55 +00:00
|
|
|
//
|
2022-09-19 14:36:54 +00:00
|
|
|
// See also netmap.NodeInfo.IsOnline/SetOnline and other similar methods.
|
2022-09-19 10:34:55 +00:00
|
|
|
func (x *NetMapCandidateValidator) VerifyAndUpdate(node *netmap.NodeInfo) error {
|
2024-09-18 09:24:53 +00:00
|
|
|
if node.Status().IsOnline() {
|
2022-09-19 10:34:55 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-09-18 09:24:53 +00:00
|
|
|
if node.Status().IsMaintenance() {
|
2022-09-19 14:36:54 +00:00
|
|
|
return x.netSettings.MaintenanceModeAllowed()
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.New("invalid status: MUST be either ONLINE or MAINTENANCE")
|
2022-09-19 10:34:55 +00:00
|
|
|
}
|