forked from TrueCloudLab/frostfs-node
[#114] Add remove-node IR control command
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
parent
ea10abb42a
commit
90799497d3
10 changed files with 676 additions and 54 deletions
59
pkg/morph/client/netmap/peer.go
Normal file
59
pkg/morph/client/netmap/peer.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package netmap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
||||
)
|
||||
|
||||
// AddPeerPrm groups parameters of AddPeer operation.
|
||||
type AddPeerPrm struct {
|
||||
nodeInfo netmap.NodeInfo
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetNodeInfo sets new peer NodeInfo.
|
||||
func (a *AddPeerPrm) SetNodeInfo(nodeInfo netmap.NodeInfo) {
|
||||
a.nodeInfo = nodeInfo
|
||||
}
|
||||
|
||||
// AddPeer registers peer in FrostFS network through
|
||||
// Netmap contract call.
|
||||
func (c *Client) AddPeer(p AddPeerPrm) error {
|
||||
var method = addPeerMethod
|
||||
|
||||
if c.client.WithNotary() && c.client.IsAlpha() {
|
||||
// In notary environments Alphabet must calls AddPeerIR method instead of AddPeer.
|
||||
// It differs from AddPeer only by name, so we can do this in the same form.
|
||||
// See https://github.com/nspcc-dev/frostfs-contract/issues/154.
|
||||
method += "IR"
|
||||
}
|
||||
|
||||
prm := client.InvokePrm{}
|
||||
prm.SetMethod(method)
|
||||
prm.SetArgs(p.nodeInfo.Marshal())
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
if err := c.client.Invoke(prm); err != nil {
|
||||
return fmt.Errorf("could not invoke method (%s): %w", method, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ForceRemovePeer marks the given peer as offline via a notary control transaction.
|
||||
func (c *Client) ForceRemovePeer(nodeInfo netmap.NodeInfo) error {
|
||||
if !c.client.WithNotary() {
|
||||
return fmt.Errorf("peer can be forcefully removed only in notary environment")
|
||||
}
|
||||
|
||||
prm := UpdatePeerPrm{}
|
||||
prm.SetKey(nodeInfo.PublicKey())
|
||||
prm.SetControlTX(true)
|
||||
|
||||
if err := c.UpdatePeerState(prm); err != nil {
|
||||
return fmt.Errorf("updating peer state: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue