From 3d6b5d807b28b99fae9559129e5a5b1a373f2917 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 15 Sep 2022 08:51:24 +0300 Subject: [PATCH] [#315] netmap: Add maintenance node state Signed-off-by: Evgenii Stratonikov --- netmap/node_info.go | 18 ++++++++++++++++++ netmap/node_info_test.go | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/netmap/node_info.go b/netmap/node_info.go index 4689211..242807a 100644 --- a/netmap/node_info.go +++ b/netmap/node_info.go @@ -558,3 +558,21 @@ func (x *NodeInfo) SetOnline() { func (x NodeInfo) IsOnline() bool { return x.m.GetState() == netmap.Online } + +// SetMaintenance sets the state of the node to "maintenance". When a node updates +// information about itself in the network map, this +// state declares temporal unavailability for a node. +// +// See also IsMaintenance. +func (x *NodeInfo) SetMaintenance() { + x.m.SetState(netmap.Maintenance) +} + +// IsMaintenance checks if the node is in the "maintenance" state. +// +// Zero NodeInfo has undefined state. +// +// See also SetMaintenance. +func (x NodeInfo) IsMaintenance() bool { + return x.m.GetState() == netmap.Maintenance +} diff --git a/netmap/node_info_test.go b/netmap/node_info_test.go index 76194b7..f475132 100644 --- a/netmap/node_info_test.go +++ b/netmap/node_info_test.go @@ -22,3 +22,26 @@ func TestNodeInfo_SetAttribute(t *testing.T) { n.SetAttribute(key, val) require.Equal(t, val, n.Attribute(key)) } + +func TestNodeInfo_Status(t *testing.T) { + var n NodeInfo + + require.False(t, n.IsOnline()) + require.False(t, n.IsOffline()) + require.False(t, n.IsMaintenance()) + + n.SetOnline() + require.True(t, n.IsOnline()) + require.False(t, n.IsOffline()) + require.False(t, n.IsMaintenance()) + + n.SetOffline() + require.True(t, n.IsOffline()) + require.False(t, n.IsOnline()) + require.False(t, n.IsMaintenance()) + + n.SetMaintenance() + require.True(t, n.IsMaintenance()) + require.False(t, n.IsOnline()) + require.False(t, n.IsOffline()) +}