From f39d08bda7c97bb6329b98646915e6ec6c61310a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 15 Jan 2021 14:51:15 +0300 Subject: [PATCH] [#315] control: Add SetNetmapStatus rpc Signed-off-by: Leonard Lyubich --- pkg/services/control/service.go | 143 +++++++++++++++++++++++++++ pkg/services/control/service.pb.go | Bin 30524 -> 42882 bytes pkg/services/control/service.proto | 31 ++++++ pkg/services/control/service_test.go | 24 +++++ 4 files changed, 198 insertions(+) diff --git a/pkg/services/control/service.go b/pkg/services/control/service.go index f4ce62439..083dc4809 100644 --- a/pkg/services/control/service.go +++ b/pkg/services/control/service.go @@ -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() +} diff --git a/pkg/services/control/service.pb.go b/pkg/services/control/service.pb.go index a253b35917d732bca6a0daf6fe85c74f37c4c57b..c5758b83c0850b2d33898072e9967d2ecb1a7c70 100644 GIT binary patch delta 4198 zcmb7IYiwId6_%aaiJe!Q=Fucha+4-b>^SzleqK9|wkf1>(mD_4K^mIWO`J!Y*lz4( zQ|(r4cX^40H1rdoE{~=lfhttmm4%Q10sXeV}^nuKM;ZgDn_N2$67NH53!#iBMuaF06&muZQCat3Gid z78Zy-z|28r#joiiJO2hkI(wsqleVFt8W!Z5KYuMkyVee~~ zu-ya{Lb} zW<)~BDH@MOBk^z!NnfeFoJG?5sv3^|`}%ifE?_i~Z63y~hCUbJ$L1>B)s~Ux1srd`k5ywa{%Fu+&|<>nlH!zKK7MVS z|4vn79zL>Ct{OyaM{!L{I8SQvs!@aA*y>T*asdnC{p6}~DNik*!u5tOY?pOm$oyC( zBU=1tTr002BTaJ9a$T+Vrae5k9V)`A?UBlx^4d#~!sLR~q$;=B=-NEnBY3r~JhN21 zZ}_ZJuOse(@JnQOM%O}%VIdNo52v^4a)g+oeL>3gQgrQ{K(?_}uR~drq>AHIlNHkk z8!EYuVf!1i)+%nsow~(5NlaJKnk)2jGq*1Ip4rUNePCWyOCnW(Gaa(HaNVO7l1J<2vKLalaOZFP9E$x9A3rQL)x#6SDV7HIq&PS+K2nNC_8IPBKJr94S` zq7!GIwT*Jv&u#4-R?`wuNr)8lyJ|{ubKc*S;w7%MFdLyYp%0BGjLD>3-rr%j6T{}2 zGxS%K*l)<9*NK~wn+{wK`s=3An;s{=SG$B3&Pm)u?&^~O;f{^l0xF&VE+#Do`NT3Jz9`%nB2g!a}T&Fk3|Dl`bQsKCysQ;*@Ew%Y9S$a&IS2cr8@$ znB0h6B6`4|kJzztZ2Pnb3>vWg@qFAoCgXOWmb$5WU1;iW#*SZ$m7c@+Vt?&Zu0&iv zn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AxTFMiViM`2)~CUf&Mfsp^c5nqn2oRhqDA~Q)Pmk;bzW`bE5_DjubJss!LQi!Z0fF zM5e{&BZPi4I;WLL9^ydVSZ2CE6byud?ZM%IPcM+jHm!tsh(ybl*h2!LLMk4QrT$OU zgh4i465=l=o}pF!sU diff --git a/pkg/services/control/service.proto b/pkg/services/control/service.proto index 50c23eeb3..2565a9df8 100644 --- a/pkg/services/control/service.proto +++ b/pkg/services/control/service.proto @@ -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; +} diff --git a/pkg/services/control/service_test.go b/pkg/services/control/service_test.go index 3c9bb6012..76933b4b2 100644 --- a/pkg/services/control/service_test.go +++ b/pkg/services/control/service_test.go @@ -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() +}