[#355] moprh/client: Add start/stop container estimation methods

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-01-28 14:39:08 +03:00 committed by Alex Vanin
parent 7a7a351f1f
commit 70aa73cbd2
4 changed files with 101 additions and 9 deletions

View file

@ -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 {

View file

@ -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
}
}
}

View file

@ -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)
}

View file

@ -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)
}