[#315] control: Add SetNetmapStatus rpc

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-01-15 14:51:15 +03:00 committed by Alex Vanin
parent e5dc4ede57
commit f39d08bda7
4 changed files with 198 additions and 0 deletions

View file

@ -310,3 +310,146 @@ func (x *NetmapSnapshotResponse) ReadSignedData(buf []byte) ([]byte, error) {
func (x *NetmapSnapshotResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}
// SetStatus sets new storage node status in NeoFS network map.
func (x *SetNetmapStatusRequest_Body) SetStatus(v NetmapStatus) {
if x != nil {
x.Status = v
}
}
const (
_ = iota
setNetmapStatusReqBodyStatusFNum
)
// StableMarshal reads binary representation of set netmap status request body
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *SetNetmapStatusRequest_Body) StableMarshal(buf []byte) ([]byte, error) {
if x == nil {
return []byte{}, nil
}
if sz := x.StableSize(); len(buf) < sz {
buf = make([]byte, sz)
}
_, err := proto.EnumMarshal(setNetmapStatusReqBodyStatusFNum, buf, int32(x.Status))
if err != nil {
return nil, err
}
return buf, nil
}
// StableSize returns binary size of health check response body
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *SetNetmapStatusRequest_Body) StableSize() int {
if x == nil {
return 0
}
size := 0
size += proto.EnumSize(setNetmapStatusReqBodyStatusFNum, int32(x.Status))
return size
}
// SetBody sets body of the set netmap status request .
func (x *SetNetmapStatusRequest) SetBody(v *SetNetmapStatusRequest_Body) {
if x != nil {
x.Body = v
}
}
// SetSignature sets signature of the set netmap status request body.
func (x *SetNetmapStatusRequest) SetSignature(body *Signature) {
if x != nil {
x.Signature = body
}
}
// ReadSignedData reads signed data of set netmap status request to buf.
//
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *SetNetmapStatusRequest) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf)
}
// SignedDataSize returns binary size of the signed data
// of set netmap status request.
//
// Structures with the same field values have the same signed data size.
func (x *SetNetmapStatusRequest) SignedDataSize() int {
return x.GetBody().StableSize()
}
// StableMarshal reads binary representation of set netmap status response body
// in protobuf binary format.
//
// If buffer length is less than x.StableSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same binary format.
func (x *SetNetmapStatusResponse_Body) StableMarshal(buf []byte) ([]byte, error) {
return buf, nil
}
// StableSize returns binary size of set netmap status response body
// in protobuf binary format.
//
// Structures with the same field values have the same binary size.
func (x *SetNetmapStatusResponse_Body) StableSize() int {
return 0
}
// SetBody sets set body of the netmap status response.
func (x *SetNetmapStatusResponse) SetBody(v *SetNetmapStatusResponse_Body) {
if x != nil {
x.Body = v
}
}
// SetSignature sets signature of the set netmap status response body.
func (x *SetNetmapStatusResponse) SetSignature(v *Signature) {
if x != nil {
x.Signature = v
}
}
// ReadSignedData reads signed data of set netmap status response to buf.
//
// If buffer length is less than x.SignedDataSize(), new buffer is allocated.
//
// Returns any error encountered which did not allow writing the data completely.
// Otherwise, returns the buffer in which the data is written.
//
// Structures with the same field values have the same signed data.
func (x *SetNetmapStatusResponse) ReadSignedData(buf []byte) ([]byte, error) {
return x.GetBody().StableMarshal(buf)
}
// SignedDataSize returns binary size of the signed data
// of set netmap status response.
//
// Structures with the same field values have the same signed data size.
func (x *SetNetmapStatusResponse) SignedDataSize() int {
return x.GetBody().StableSize()
}

Binary file not shown.

View file

@ -13,6 +13,9 @@ service ControlService {
// Returns network map snapshot of the current NeoFS epoch.
rpc NetmapSnapshot (NetmapSnapshotRequest) returns (NetmapSnapshotResponse);
// Sets status of the storage node in NeoFS network map.
rpc SetNetmapStatus (SetNetmapStatusRequest) returns (SetNetmapStatusResponse);
}
// Health check request.
@ -73,3 +76,31 @@ message NetmapSnapshotResponse {
// Body signature.
Signature signature = 2;
}
// Set netmap status request.
message SetNetmapStatusRequest {
// Set netmap status request body.
message Body {
// New storage node status in NeoFS network map.
NetmapStatus status = 1;
}
// Body of set netmap status request message.
Body body = 1;
// Body signature.
Signature signature = 2;
}
// Set netmap status response.
message SetNetmapStatusResponse {
// Set netmap status response body
message Body {
}
// Body of set netmap status response message.
Body body = 1;
// Body signature.
Signature signature = 2;
}

View file

@ -55,3 +55,27 @@ func generateNetmapSnapshotResponseBody() *control.NetmapSnapshotResponse_Body {
func equalNetmapSnapshotResponseBodies(b1, b2 *control.NetmapSnapshotResponse_Body) bool {
return equalNetmaps(b1.GetNetmap(), b2.GetNetmap())
}
func TestSetNetmapStatusRequest_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateSetNetmapStatusRequestBody(),
new(control.SetNetmapStatusRequest_Body),
func(m1, m2 protoMessage) bool {
return equalSetnetmapStatusRequestBodies(
m1.(*control.SetNetmapStatusRequest_Body),
m2.(*control.SetNetmapStatusRequest_Body),
)
},
)
}
func generateSetNetmapStatusRequestBody() *control.SetNetmapStatusRequest_Body {
body := new(control.SetNetmapStatusRequest_Body)
body.SetStatus(control.NetmapStatus_ONLINE)
return body
}
func equalSetnetmapStatusRequestBodies(b1, b2 *control.SetNetmapStatusRequest_Body) bool {
return b1.GetStatus() == b2.GetStatus()
}