2021-01-15 11:51:34 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
2024-05-16 09:11:57 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/server/ctrlmessage"
|
2021-01-15 11:51:34 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
)
|
|
|
|
|
2023-02-03 16:58:09 +00:00
|
|
|
// SetNetmapStatus sets node status in FrostFS network.
|
2021-01-15 11:51:34 +00:00
|
|
|
//
|
|
|
|
// If request is unsigned or signed by disallowed key, permission error returns.
|
2023-04-26 08:24:40 +00:00
|
|
|
func (s *Server) SetNetmapStatus(_ context.Context, req *control.SetNetmapStatusRequest) (*control.SetNetmapStatusResponse, error) {
|
2021-01-15 11:51:34 +00:00
|
|
|
// verify request
|
|
|
|
if err := s.isValidRequest(req); err != nil {
|
|
|
|
return nil, status.Error(codes.PermissionDenied, err.Error())
|
|
|
|
}
|
|
|
|
|
2022-10-18 15:42:14 +00:00
|
|
|
var err error
|
|
|
|
bodyReq := req.GetBody()
|
|
|
|
st := bodyReq.GetStatus()
|
|
|
|
force := bodyReq.GetForceMaintenance()
|
|
|
|
|
|
|
|
if force {
|
|
|
|
if st != control.NetmapStatus_MAINTENANCE {
|
|
|
|
return nil, status.Errorf(codes.InvalidArgument,
|
|
|
|
"force_maintenance MUST be set for %s status only", control.NetmapStatus_MAINTENANCE)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.nodeState.ForceMaintenance()
|
|
|
|
} else {
|
|
|
|
err = s.nodeState.SetNetmapStatus(st)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2021-01-15 11:51:34 +00:00
|
|
|
return nil, status.Error(codes.Aborted, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// create and fill response
|
|
|
|
resp := new(control.SetNetmapStatusResponse)
|
|
|
|
|
|
|
|
body := new(control.SetNetmapStatusResponse_Body)
|
|
|
|
resp.SetBody(body)
|
|
|
|
|
|
|
|
// sign the response
|
2024-05-16 09:11:57 +00:00
|
|
|
if err := ctrlmessage.Sign(s.key, resp); err != nil {
|
2021-01-15 11:51:34 +00:00
|
|
|
return nil, status.Error(codes.Internal, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|