From 70aa73cbd20a4c694f85e7b885029545a73d3080 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 28 Jan 2021 14:39:08 +0300 Subject: [PATCH] [#355] moprh/client: Add start/stop container estimation methods Signed-off-by: Alex Vanin --- pkg/morph/client/audit/wrapper/result.go | 3 +- pkg/morph/client/container/client.go | 51 ++++++++++++++++--- pkg/morph/client/container/estimations.go | 35 +++++++++++++ .../client/container/wrapper/estimations.go | 21 ++++++++ 4 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 pkg/morph/client/container/estimations.go create mode 100644 pkg/morph/client/container/wrapper/estimations.go diff --git a/pkg/morph/client/audit/wrapper/result.go b/pkg/morph/client/audit/wrapper/result.go index cb8c71660..0cd8cbc8c 100644 --- a/pkg/morph/client/audit/wrapper/result.go +++ b/pkg/morph/client/audit/wrapper/result.go @@ -15,8 +15,7 @@ var errUnsupported = errors.New("unsupported structure version") // PutAuditResult saves passed audit result structure in NeoFS system // through Audit contract call. // -// Returns calculated container identifier and any error -// encountered that caused the saving to interrupt. +// Returns encountered error that caused the saving to interrupt. func (w *ClientWrapper) PutAuditResult(result *auditAPI.Result) error { rawResult, err := result.Marshal() if err != nil { diff --git a/pkg/morph/client/container/client.go b/pkg/morph/client/container/client.go index 451127040..e6e10f5de 100644 --- a/pkg/morph/client/container/client.go +++ b/pkg/morph/client/container/client.go @@ -33,7 +33,9 @@ type cfg struct { getMethod, // get container method name for invocation listMethod, // list container method name for invocation setEACLMethod, // set eACL method name for invocation - eaclMethod string // get eACL method name for invocation + eaclMethod, // get eACL method name for invocation + startEstimation, + stopEstimation string } const ( @@ -43,16 +45,21 @@ const ( defaultListMethod = "list" // default list containers method name defaultEACLMethod = "eACL" // default get eACL method name defaultSetEACLMethod = "setEACL" // default set eACL method name + + defaultStartEstimation = "startContainerEstimation" + defaultStopEstimation = "stopContainerEstimation" ) func defaultConfig() *cfg { return &cfg{ - putMethod: defaultPutMethod, - deleteMethod: defaultDeleteMethod, - getMethod: defaultGetMethod, - listMethod: defaultListMethod, - setEACLMethod: defaultSetEACLMethod, - eaclMethod: defaultEACLMethod, + putMethod: defaultPutMethod, + deleteMethod: defaultDeleteMethod, + getMethod: defaultGetMethod, + listMethod: defaultListMethod, + setEACLMethod: defaultSetEACLMethod, + eaclMethod: defaultEACLMethod, + startEstimation: defaultStartEstimation, + stopEstimation: defaultStopEstimation, } } @@ -67,6 +74,8 @@ func defaultConfig() *cfg { // * list containers method name: List; // * set eACL method name: SetEACL; // * get eACL method name: EACL. +// * start estimation method name: startContainerEstimation +// * stop estimation method name: stopContainerEstimation // // If desired option satisfies the default value, it can be omitted. // If multiple options of the same config value are supplied, @@ -172,3 +181,31 @@ func WithEACLMethod(n string) Option { } } } + +// WithStartEstimationMethod returns a client constructor option that +// specifies the method name of vote to start container size estimation. +// +// Ignores empty value. +// +// If option not provided, "startContainerEstimation" is used. +func WithStartEstimationMethod(n string) Option { + return func(c *cfg) { + if n != "" { + c.startEstimation = n + } + } +} + +// WithStopEstimationMethod returns a client constructor option that +// specifies the method name of vote to stop container size estimation. +// +// Ignores empty value. +// +// If option not provided, "stopContainerEstimation" is used. +func WithStopEstimationMethod(n string) Option { + return func(c *cfg) { + if n != "" { + c.stopEstimation = n + } + } +} diff --git a/pkg/morph/client/container/estimations.go b/pkg/morph/client/container/estimations.go new file mode 100644 index 000000000..be21e8cd7 --- /dev/null +++ b/pkg/morph/client/container/estimations.go @@ -0,0 +1,35 @@ +package container + +import ( + "github.com/pkg/errors" +) + +type StartEstimation struct { + epoch int64 +} + +func (e *StartEstimation) SetEpoch(v int64) { + e.epoch = v +} + +type StopEstimation struct { + epoch int64 +} + +func (e *StopEstimation) SetEpoch(v int64) { + e.epoch = v +} + +func (c *Client) StartEstimation(args StartEstimation) error { + return errors.Wrapf(c.client.Invoke( + c.startEstimation, + args.epoch, + ), "could not invoke method (%s)", c.startEstimation) +} + +func (c *Client) StopEstimation(args StopEstimation) error { + return errors.Wrapf(c.client.Invoke( + c.stopEstimation, + args.epoch, + ), "could not invoke method (%s)", c.stopEstimation) +} diff --git a/pkg/morph/client/container/wrapper/estimations.go b/pkg/morph/client/container/wrapper/estimations.go new file mode 100644 index 000000000..49785992e --- /dev/null +++ b/pkg/morph/client/container/wrapper/estimations.go @@ -0,0 +1,21 @@ +package wrapper + +import ( + "github.com/nspcc-dev/neofs-node/pkg/morph/client/container" +) + +// StartEstimation votes to produce start estimation notification. +func (w *Wrapper) StartEstimation(epoch uint64) error { + args := container.StartEstimation{} + args.SetEpoch(int64(epoch)) + + return w.client.StartEstimation(args) +} + +// StopEstimation votes to produce stop estimation notification. +func (w *Wrapper) StopEstimation(epoch uint64) error { + args := container.StopEstimation{} + args.SetEpoch(int64(epoch)) + + return w.client.StopEstimation(args) +}