From 93803b1a90309c9619edef71598407be56812487 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 9 Jun 2021 18:37:03 +0300 Subject: [PATCH] [#414] ir: Define Control service Define `ControlService` for IR similar to the one from storage node. Add `HealthStatus` RPC which returns health status of the IR application. Implement getters, setters and methods to sign/verify the messages. Signed-off-by: Leonard Lyubich --- pkg/services/control/ir/convert.go | 34 ++++++ pkg/services/control/ir/rpc.go | 34 ++++++ pkg/services/control/ir/service.go | 148 ++++++++++++++++++++++++ pkg/services/control/ir/service.pb.go | Bin 0 -> 17824 bytes pkg/services/control/ir/service.proto | 43 +++++++ pkg/services/control/ir/service_test.go | 47 ++++++++ pkg/services/control/ir/types.go | 15 +++ pkg/services/control/ir/types.pb.go | Bin 0 -> 7936 bytes pkg/services/control/ir/types.proto | 29 +++++ 9 files changed, 350 insertions(+) create mode 100644 pkg/services/control/ir/convert.go create mode 100644 pkg/services/control/ir/rpc.go create mode 100644 pkg/services/control/ir/service.go create mode 100644 pkg/services/control/ir/service.pb.go create mode 100644 pkg/services/control/ir/service.proto create mode 100644 pkg/services/control/ir/service_test.go create mode 100644 pkg/services/control/ir/types.go create mode 100644 pkg/services/control/ir/types.pb.go create mode 100644 pkg/services/control/ir/types.proto diff --git a/pkg/services/control/ir/convert.go b/pkg/services/control/ir/convert.go new file mode 100644 index 000000000..3536951f4 --- /dev/null +++ b/pkg/services/control/ir/convert.go @@ -0,0 +1,34 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/rpc/grpc" + "github.com/nspcc-dev/neofs-api-go/rpc/message" +) + +type requestWrapper struct { + message.Message + m grpc.Message +} + +func (w *requestWrapper) ToGRPCMessage() grpc.Message { + return w.m +} + +type healthCheckResponseWrapper struct { + m *HealthCheckResponse +} + +func (w *healthCheckResponseWrapper) ToGRPCMessage() grpc.Message { + return w.m +} + +func (w *healthCheckResponseWrapper) FromGRPCMessage(m grpc.Message) error { + var ok bool + + w.m, ok = m.(*HealthCheckResponse) + if !ok { + return message.NewUnexpectedMessageType(m, w.m) + } + + return nil +} diff --git a/pkg/services/control/ir/rpc.go b/pkg/services/control/ir/rpc.go new file mode 100644 index 000000000..8ed7cf44e --- /dev/null +++ b/pkg/services/control/ir/rpc.go @@ -0,0 +1,34 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/rpc/client" + "github.com/nspcc-dev/neofs-api-go/rpc/common" +) + +const serviceName = "ircontrol.ControlService" + +const ( + rpcHealthCheck = "HealthCheck" +) + +// HealthCheck executes ControlService.HealthCheck RPC. +func HealthCheck( + cli *client.Client, + req *HealthCheckRequest, + opts ...client.CallOption, +) (*HealthCheckResponse, error) { + wResp := &healthCheckResponseWrapper{ + m: new(HealthCheckResponse), + } + + wReq := &requestWrapper{ + m: req, + } + + err := client.SendUnary(cli, common.CallMethodInfoUnary(serviceName, rpcHealthCheck), wReq, wResp, opts...) + if err != nil { + return nil, err + } + + return wResp.m, nil +} diff --git a/pkg/services/control/ir/service.go b/pkg/services/control/ir/service.go new file mode 100644 index 000000000..8f7705c98 --- /dev/null +++ b/pkg/services/control/ir/service.go @@ -0,0 +1,148 @@ +package control + +import ( + "github.com/nspcc-dev/neofs-api-go/util/proto" +) + +// StableMarshal reads binary representation of health check 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 *HealthCheckRequest_Body) StableMarshal(buf []byte) ([]byte, error) { + return buf, nil +} + +// StableSize returns binary size of health check request body +// in protobuf binary format. +// +// Structures with the same field values have the same binary size. +func (x *HealthCheckRequest_Body) StableSize() int { + return 0 +} + +// SetBody sets health check request body. +func (x *HealthCheckRequest) SetBody(v *HealthCheckRequest_Body) { + if x != nil { + x.Body = v + } +} + +// SetSignature sets signature of the health check request body. +func (x *HealthCheckRequest) SetSignature(body *Signature) { + if x != nil { + x.Signature = body + } +} + +// ReadSignedData reads signed data of health check 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 *HealthCheckRequest) ReadSignedData(buf []byte) ([]byte, error) { + return x.GetBody().StableMarshal(buf) +} + +// SignedDataSize returns binary size of the signed data +// of health check request. +// +// Structures with the same field values have the same signed data size. +func (x *HealthCheckRequest) SignedDataSize() int { + return x.GetBody().StableSize() +} + +// SetHealthStatus sets health status of the IR application. +func (x *HealthCheckResponse_Body) SetHealthStatus(v HealthStatus) { + if x != nil { + x.HealthStatus = v + } +} + +const ( + _ = iota + healthRespBodyHealthStatusFNum +) + +// StableMarshal reads binary representation of health check 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 *HealthCheckResponse_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(healthRespBodyHealthStatusFNum, buf, int32(x.HealthStatus)) + 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 *HealthCheckResponse_Body) StableSize() int { + if x == nil { + return 0 + } + + size := 0 + + size += proto.EnumSize(healthRespBodyHealthStatusFNum, int32(x.HealthStatus)) + + return size +} + +// SetBody sets health check response body. +func (x *HealthCheckResponse) SetBody(v *HealthCheckResponse_Body) { + if x != nil { + x.Body = v + } +} + +// SetSignature sets signature of the health check response body. +func (x *HealthCheckResponse) SetSignature(v *Signature) { + if x != nil { + x.Signature = v + } +} + +// ReadSignedData reads signed data of health check 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 *HealthCheckResponse) ReadSignedData(buf []byte) ([]byte, error) { + return x.GetBody().StableMarshal(buf) +} + +// SignedDataSize returns binary size of the signed data +// of health check response. +// +// Structures with the same field values have the same signed data size. +func (x *HealthCheckResponse) SignedDataSize() int { + return x.GetBody().StableSize() +} diff --git a/pkg/services/control/ir/service.pb.go b/pkg/services/control/ir/service.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..0b60effb89386d18264bacfe13ff84236501c777 GIT binary patch literal 17824 zcmd^HdvDuD68~HJ6k8ttgCdo`WxCgE-$rsGsAJ@rbAhfq5w z!61a50g=q5)^4g@Yxcb#n3;ODGKV;tXX6{tvS68>_wLMK1R?EaomdCr3*r+0b75fP zi9gc2BtqrJFwF#ni!9t_Y^Ux(puzzbYcjE&(1Ahn*92set zb^zXa3R}I*zb;VT&MD7`nIk_Rw|RJ|RtHmfX>F!TmZ zhEDDTJ|Ybr2jz6o8W1w8=YUJ)c}D(c$RV+=BZJp}l6a2w%%};lsSt>?ZhIG~PSLbq>gqpn`%u$Su#3ag~@AIGG>>@Po+LneN>;IW=W+M`6H zt1jcR049;pNY**lu^0Ih*oyLTNNE?LQ~aV-i}`Zsq;~b0!bd}0eTMC^s~Ah!!r&wK z3juxm@6)qd-GKVqTyLgtbwaTWWRwspVGia2*%y>(=$kpT*On%eeP*O^H$F598=m#lAR+&?P7RUm3hXstLm zQc{*395VmJCx?YJ3s28=bnv}JQLVQ(B#7dAa>SS5k~wZdvH-^Yd4e19ETf11TVZ(80^l9?~dTRHkH&0T-z=)><0 zCfzo#ig-vl{lpIr%AHI`J}yppkiz4GETb13yge5FuoB8U7nk3}emuG1SDBtbZ_w+> zD;W|<=3%0tgX#E{ADKr0$A+K2xfCI7^l)JvU~8hNweoqx=>B&PqZVsVA4dzoHx8tW zyPh?YlFa{Fk<=3K<3gzg;Jd}rRvJsoUm*)5A!W5=1Y*4X=gQXyd!hXRVUPFTo&5aE z#k=15#m^U)=e^4h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NOyOL)%(?N5S;Bop@qEexi={bqv zY^BLBcx8)LKG4Toxk?zY419}_WiBEF2z>!M=?F*ufBAr5VL%rzL>`2g60;`}nV?auseKs%A6AV)*xhmN2H z^!ag*C6cuex!Qy;(Mm^A7@=2=yWH-T8&NY$ssN zBTbnLLJHC&sO=_6CUJKU?XUgNlg8H4R@cAf>To{jFDUK=SW}`~q&Q_RRT||>Ap8vZ zR~VreOfEF0SH$!}n)`+LZm1n}bQ>;M z)wwG6tef!;sUNDICZcbs8!!=R2<*a@grX$t*)AF4y?H1ril4L(w@7cF^4B`QWb-M9 z^8_w1Z~jGNmP^Tc6Nmp@29#>(F=DFjmy+wb0d>9V@wM*v(fdi!!M)QIl)ktTB1;}F zGf-S=8k;z<9!2I*sn672uH7_e$lopyGF0PUY#~zU>YUKIHK=jRzEhwI=4l=uEL-G5 zEt7-p@8rFspY#xq7CI`EaxGRb<+xz$YN$B6n+pPBh5Wu9J1Hy^m})P2MW|`#Ev1kQ zEGJ`rrA2)29gd0-8f^)C;ci?SbNkwpi?p@0E)kSG60CZfyDyou%fOB9g$X{nWe$PZ z+MUK<(gh+qLc&7K5Zlh&8%sb2VBm7Ofx9Cp*o0Yasz&wT+^H31X#{V-j!AR^QjQ@$ zI*^Ih7mIujLU2+M2$JXm0i~L6rlZk&e!A*z9OW3uWE3l}_*G>8^pc3g|LQa2l)nwi3hB`-F?cPu9-b=z literal 0 HcmV?d00001 diff --git a/pkg/services/control/ir/service.proto b/pkg/services/control/ir/service.proto new file mode 100644 index 000000000..e330d0fcf --- /dev/null +++ b/pkg/services/control/ir/service.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package ircontrol; + +import "pkg/services/control/ir/types.proto"; + +option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/ir/control"; + +// `ControlService` provides an interface for internal work with the Inner Ring node. +service ControlService { + // Performs health check of the IR node. + rpc HealthCheck (HealthCheckRequest) returns (HealthCheckResponse); +} + +// Health check request. +message HealthCheckRequest { + // Health check request body. + message Body { + } + + // Body of health check request message. + Body body = 1; + + // Body signature. + // Should be signed by node key or one of + // the keys configured by the node. + Signature signature = 2; +} + +// Health check response. +message HealthCheckResponse { + // Health check response body + message Body { + // Health status of IR node application. + HealthStatus health_status = 1; + } + + // Body of health check response message. + Body body = 1; + + // Body signature. + Signature signature = 2; +} diff --git a/pkg/services/control/ir/service_test.go b/pkg/services/control/ir/service_test.go new file mode 100644 index 000000000..9958e0a56 --- /dev/null +++ b/pkg/services/control/ir/service_test.go @@ -0,0 +1,47 @@ +package control_test + +import ( + "testing" + + control "github.com/nspcc-dev/neofs-node/pkg/services/control/ir" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +type protoMessage interface { + StableMarshal([]byte) ([]byte, error) + proto.Message +} + +func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) { + data, err := m1.StableMarshal(nil) + require.NoError(t, err) + + require.NoError(t, proto.Unmarshal(data, m2)) + + require.True(t, cmp(m1, m2)) +} + +func TestHealthCheckResponse_Body_StableMarshal(t *testing.T) { + testStableMarshal(t, + generateHealthCheckResponseBody(), + new(control.HealthCheckResponse_Body), + func(m1, m2 protoMessage) bool { + return equalHealthCheckResponseBodies( + m1.(*control.HealthCheckResponse_Body), + m2.(*control.HealthCheckResponse_Body), + ) + }, + ) +} + +func generateHealthCheckResponseBody() *control.HealthCheckResponse_Body { + body := new(control.HealthCheckResponse_Body) + body.SetHealthStatus(control.HealthStatus_SHUTTING_DOWN) + + return body +} + +func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bool { + return b1.GetHealthStatus() == b2.GetHealthStatus() +} diff --git a/pkg/services/control/ir/types.go b/pkg/services/control/ir/types.go new file mode 100644 index 000000000..97ffd3ce3 --- /dev/null +++ b/pkg/services/control/ir/types.go @@ -0,0 +1,15 @@ +package control + +// SetKey sets public key used for signing. +func (x *Signature) SetKey(v []byte) { + if x != nil { + x.Key = v + } +} + +// SetSign sets binary signature. +func (x *Signature) SetSign(v []byte) { + if x != nil { + x.Sign = v + } +} diff --git a/pkg/services/control/ir/types.pb.go b/pkg/services/control/ir/types.pb.go new file mode 100644 index 0000000000000000000000000000000000000000..07daaef73cae6020cd64d9aef87a7ccd1f26a483 GIT binary patch literal 7936 zcmcgxTT|o45`MOR#l#O=_Lh<5D~V6>uvr_HI$5AFB%4r_BgAWJG;yyj5;@9E3P z8W~JvQgtX0^33$tJzw|q%(Rxu>_pDQ^htzKkOa;Vv>h!1Qw%S~#pR6{ z4bN{(quCTI8O3hk#{>LODGU~?mf7x^mewQG&#Gg#y4({7Y2?U(2p<>CSVk+?k#W-r z{3HszrW-Yrr%=Ww0UJhWJCF843e|5I?lKIbMAQscEvgGQc}SgJSP(;nYvurDS0o4U$`>IavJUJEDru zs!=x#m{?5H0XBb?kvo49$%CE1!;Lk+IOry5iPQPqbzJEu-jhhfqa-+*f#Xc0G7%^2 zI#g|r{CNN@10p)B*0#iv*8A1?n?Qr|~b;k|)TXul8DL1Vh?Z9j6Y8Z*Z3I zYlDNAq3g*bq)^x~1V#deGZ*&0X=lNRP{AAqOX10d?WiCYS@eL0sdW8?NMkuO73W*R z%qxueD~`1DSlQVn1HVYyOCCg=*hv~^I?k_!9fqFk*l43^V8jX@Ip%?`pLE(q=id4= zId^?nV+__1@YzniM67HtMGxu-lP{xBzubJ8jBh^O+>R%=7sJu%`Ne2hRC6LM@?X&) za#&&mf&O9_7Vxfb&M(e(aawQTfX%iKcEe(o;49CgS6sKd@YkbH!{2wY+xxH|(gbZ3 zv*0_hSe*a(%k2#sIvHO6cCm}tQQH_3Qn3c2x`+8{1NvLgpHWB+ZD^oL)29x0>xN_NW=B1_Tj^)b_hbg@->ZBe zEYzPXA7q&|``@B|w&g`93~IA{!8(0hhfIZKIZq)$)z$?f>jJ5+)x}4hNdYE@VsIjS z`MsuhKvww}!W7q-0h2WHMQCjHA&-fDz-BTKG!w#gN$KMoB(!wNBQNK*wK}V(Asd+@q;}VcM2qg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0yvPA+o8=Hh~Bx>UD!_P9X7Aby9+nVo4hsotz1j=oUzX4Os B1}Ojl literal 0 HcmV?d00001 diff --git a/pkg/services/control/ir/types.proto b/pkg/services/control/ir/types.proto new file mode 100644 index 000000000..3a7791874 --- /dev/null +++ b/pkg/services/control/ir/types.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package ircontrol; + +option go_package = "github.com/nspcc-dev/neofs-node/pkg/services/ir/control"; + +// Signature of some message. +message Signature { + // Public key used for signing. + bytes key = 1 [json_name = "key"]; + + // Binary signature. + bytes sign = 2 [json_name = "signature"]; +} + +// Health status of the IR application. +enum HealthStatus { + // Undefined status, default value. + HEALTH_STATUS_UNDEFINED = 0; + + // IR application is starting. + STARTING = 1; + + // IR application is started and serves all services. + READY = 2; + + // IR application is shutting down. + SHUTTING_DOWN = 3; +}