2022-05-12 19:37:38 +00:00
|
|
|
package native
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-05-23 11:42:48 +00:00
|
|
|
"context"
|
2022-05-12 19:37:38 +00:00
|
|
|
"crypto/ecdsa"
|
2022-05-23 11:42:48 +00:00
|
|
|
"crypto/sha256"
|
2022-09-02 19:23:33 +00:00
|
|
|
"encoding/hex"
|
2022-05-23 11:42:48 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2022-06-17 12:50:24 +00:00
|
|
|
"strconv"
|
2022-05-12 19:37:38 +00:00
|
|
|
"time"
|
|
|
|
|
2022-05-20 11:14:50 +00:00
|
|
|
"github.com/dop251/goja"
|
2022-05-23 11:42:48 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/checksum"
|
2022-05-12 19:37:38 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
2022-06-17 12:50:24 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
2022-10-26 19:13:14 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
|
2022-05-12 19:37:38 +00:00
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-05-23 11:42:48 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/netmap"
|
2022-05-12 19:37:38 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/user"
|
2022-05-23 11:42:48 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
|
|
|
"github.com/nspcc-dev/tzhash/tz"
|
2022-05-12 19:37:38 +00:00
|
|
|
"github.com/nspcc-dev/xk6-neofs/internal/stats"
|
|
|
|
"go.k6.io/k6/js/modules"
|
|
|
|
"go.k6.io/k6/metrics"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
Client struct {
|
2022-05-25 08:22:40 +00:00
|
|
|
vu modules.VU
|
|
|
|
key ecdsa.PrivateKey
|
|
|
|
tok session.Object
|
|
|
|
cli *client.Client
|
|
|
|
bufsize int
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PutResponse struct {
|
|
|
|
Success bool
|
|
|
|
ObjectID string
|
2022-05-20 09:22:11 +00:00
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
DeleteResponse struct {
|
|
|
|
Success bool
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-05-20 09:22:11 +00:00
|
|
|
GetResponse struct {
|
|
|
|
Success bool
|
|
|
|
Error string
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
2022-05-23 11:42:48 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
VerifyHashResponse struct {
|
|
|
|
Success bool
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-06-17 12:50:24 +00:00
|
|
|
PutContainerResponse struct {
|
|
|
|
Success bool
|
|
|
|
ContainerID string
|
|
|
|
Error string
|
|
|
|
}
|
|
|
|
|
2022-05-23 11:42:48 +00:00
|
|
|
PreparedObject struct {
|
2022-05-25 08:22:40 +00:00
|
|
|
vu modules.VU
|
|
|
|
key ecdsa.PrivateKey
|
|
|
|
cli *client.Client
|
|
|
|
bufsize int
|
2022-05-23 11:42:48 +00:00
|
|
|
|
|
|
|
hdr object.Object
|
|
|
|
payload []byte
|
|
|
|
}
|
2022-05-12 19:37:38 +00:00
|
|
|
)
|
|
|
|
|
2022-05-25 08:22:40 +00:00
|
|
|
const defaultBufferSize = 64 * 1024
|
|
|
|
|
|
|
|
func (c *Client) SetBufferSize(size int) {
|
|
|
|
if size < 0 {
|
|
|
|
panic("buffer size must be positive")
|
|
|
|
}
|
|
|
|
if size == 0 {
|
|
|
|
c.bufsize = defaultBufferSize
|
|
|
|
} else {
|
|
|
|
c.bufsize = size
|
|
|
|
}
|
|
|
|
}
|
2022-05-12 19:37:38 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
func (c *Client) Put(containerID string, headers map[string]string, payload goja.ArrayBuffer) PutResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
2022-05-12 19:37:38 +00:00
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectPut)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
2022-09-02 19:23:33 +00:00
|
|
|
err := tok.Sign(c.key)
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, c.key.PublicKey)
|
|
|
|
|
|
|
|
attrs := make([]object.Attribute, len(headers))
|
|
|
|
ind := 0
|
|
|
|
for k, v := range headers {
|
|
|
|
attrs[ind].SetKey(k)
|
|
|
|
attrs[ind].SetValue(v)
|
|
|
|
ind++
|
|
|
|
}
|
|
|
|
|
|
|
|
var o object.Object
|
2022-09-02 19:23:33 +00:00
|
|
|
o.SetContainerID(cliContainerID)
|
2022-05-12 19:37:38 +00:00
|
|
|
o.SetOwnerID(&owner)
|
|
|
|
o.SetAttributes(attrs...)
|
|
|
|
|
2022-05-25 08:22:40 +00:00
|
|
|
resp, err := put(c.vu, c.bufsize, c.cli, &tok, &o, payload.Bytes())
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
2022-05-20 09:22:11 +00:00
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
return PutResponse{Success: true, ObjectID: resp.StoredObjectID().String()}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
func (c *Client) Delete(containerID string, objectID string) DeleteResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
|
|
|
cliObjectID := parseObjectID(objectID)
|
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectDelete)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
|
|
|
tok.LimitByObjects(cliObjectID)
|
2022-09-27 16:01:43 +00:00
|
|
|
err := tok.Sign(c.key)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-11-29 13:08:58 +00:00
|
|
|
stats.Report(c.vu, objDeleteTotal, 1)
|
|
|
|
start := time.Now()
|
|
|
|
|
2022-09-27 16:01:43 +00:00
|
|
|
var prm client.PrmObjectDelete
|
|
|
|
prm.ByID(cliObjectID)
|
|
|
|
prm.FromContainer(cliContainerID)
|
|
|
|
prm.WithinSession(tok)
|
|
|
|
|
|
|
|
_, err = c.cli.ObjectDelete(c.vu.Context(), prm)
|
|
|
|
if err != nil {
|
2022-11-29 13:08:58 +00:00
|
|
|
stats.Report(c.vu, objDeleteFails, 1)
|
2022-09-27 16:01:43 +00:00
|
|
|
return DeleteResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
2022-11-29 13:08:58 +00:00
|
|
|
stats.Report(c.vu, objDeleteDuration, metrics.D(time.Since(start)))
|
2022-09-27 16:01:43 +00:00
|
|
|
return DeleteResponse{Success: true}
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
func (c *Client) Get(containerID, objectID string) GetResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
|
|
|
cliObjectID := parseObjectID(objectID)
|
2022-05-12 19:37:38 +00:00
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectGet)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
|
|
|
tok.LimitByObjects(cliObjectID)
|
2022-09-02 19:23:33 +00:00
|
|
|
err := tok.Sign(c.key)
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
stats.Report(c.vu, objGetTotal, 1)
|
|
|
|
start := time.Now()
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
var prm client.PrmObjectGet
|
|
|
|
prm.ByID(cliObjectID)
|
|
|
|
prm.FromContainer(cliContainerID)
|
|
|
|
prm.WithinSession(tok)
|
2022-05-12 19:37:38 +00:00
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
var objSize = 0
|
|
|
|
err = get(c.cli, prm, c.vu.Context(), c.bufsize, func(data []byte) {
|
|
|
|
objSize += len(data)
|
|
|
|
})
|
2022-05-12 19:37:38 +00:00
|
|
|
if err != nil {
|
|
|
|
stats.Report(c.vu, objGetFails, 1)
|
2022-05-20 09:22:11 +00:00
|
|
|
return GetResponse{Success: false, Error: err.Error()}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
stats.Report(c.vu, objGetDuration, metrics.D(time.Since(start)))
|
|
|
|
stats.ReportDataReceived(c.vu, float64(objSize))
|
|
|
|
return GetResponse{Success: true}
|
|
|
|
}
|
|
|
|
|
|
|
|
func get(
|
|
|
|
cli *client.Client,
|
|
|
|
prm client.PrmObjectGet,
|
|
|
|
ctx context.Context,
|
|
|
|
bufSize int,
|
|
|
|
onDataChunk func(chunk []byte),
|
|
|
|
) error {
|
|
|
|
var buf = make([]byte, bufSize)
|
|
|
|
|
|
|
|
objectReader, err := cli.ObjectGetInit(ctx, prm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-12 19:37:38 +00:00
|
|
|
var o object.Object
|
|
|
|
if !objectReader.ReadHeader(&o) {
|
2022-06-17 12:50:24 +00:00
|
|
|
if _, err = objectReader.Close(); err != nil {
|
2022-09-02 19:23:33 +00:00
|
|
|
return err
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
return errors.New("can't read object header")
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n, _ := objectReader.Read(buf)
|
|
|
|
for n > 0 {
|
2022-09-02 19:23:33 +00:00
|
|
|
onDataChunk(buf[:n])
|
2022-05-12 19:37:38 +00:00
|
|
|
n, _ = objectReader.Read(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = objectReader.Close()
|
|
|
|
if err != nil {
|
2022-09-02 19:23:33 +00:00
|
|
|
return err
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) VerifyHash(containerID, objectID, expectedHash string) VerifyHashResponse {
|
|
|
|
cliContainerID := parseContainerID(containerID)
|
|
|
|
cliObjectID := parseObjectID(objectID)
|
|
|
|
|
|
|
|
tok := c.tok
|
|
|
|
tok.ForVerb(session.VerbObjectGet)
|
2022-10-26 19:13:14 +00:00
|
|
|
tok.BindContainer(cliContainerID)
|
|
|
|
tok.LimitByObjects(cliObjectID)
|
2022-09-02 19:23:33 +00:00
|
|
|
err := tok.Sign(c.key)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var prm client.PrmObjectGet
|
|
|
|
prm.ByID(cliObjectID)
|
|
|
|
prm.FromContainer(cliContainerID)
|
|
|
|
prm.WithinSession(tok)
|
|
|
|
|
|
|
|
hasher := sha256.New()
|
|
|
|
err = get(c.cli, prm, c.vu.Context(), c.bufsize, func(data []byte) {
|
|
|
|
hasher.Write(data)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return VerifyHashResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
2022-09-22 16:57:21 +00:00
|
|
|
actualHash := hex.EncodeToString(hasher.Sum(nil))
|
2022-09-02 19:23:33 +00:00
|
|
|
if actualHash != expectedHash {
|
|
|
|
return VerifyHashResponse{Success: true, Error: "hash mismatch"}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VerifyHashResponse{Success: true}
|
2022-05-12 19:37:38 +00:00
|
|
|
}
|
2022-05-23 11:42:48 +00:00
|
|
|
|
2022-06-17 12:50:24 +00:00
|
|
|
func (c *Client) putCnrErrorResponse(err error) PutContainerResponse {
|
|
|
|
stats.Report(c.vu, cnrPutFails, 1)
|
|
|
|
return PutContainerResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) PutContainer(params map[string]string) PutContainerResponse {
|
|
|
|
stats.Report(c.vu, cnrPutTotal, 1)
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
var cnr container.Container
|
|
|
|
cnr.Init()
|
|
|
|
|
|
|
|
var usr user.ID
|
|
|
|
user.IDFromKey(&usr, c.key.PublicKey)
|
|
|
|
|
|
|
|
container.SetCreationTime(&cnr, time.Now())
|
|
|
|
cnr.SetOwner(usr)
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
if basicACLStr, ok := params["acl"]; ok {
|
2022-10-26 19:13:14 +00:00
|
|
|
var basicACL acl.Basic
|
|
|
|
err := basicACL.DecodeString(basicACLStr)
|
2022-06-17 12:50:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
cnr.SetBasicACL(basicACL)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
placementPolicyStr, ok := params["placement_policy"]
|
|
|
|
if ok {
|
2022-10-26 19:13:14 +00:00
|
|
|
var placementPolicy netmap.PlacementPolicy
|
|
|
|
err := placementPolicy.DecodeString(placementPolicyStr)
|
2022-06-17 12:50:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
cnr.SetPlacementPolicy(placementPolicy)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
containerName, hasName := params["name"]
|
|
|
|
if hasName {
|
2022-10-26 19:13:14 +00:00
|
|
|
container.SetName(&cnr, containerName)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var nameScopeGlobal bool
|
|
|
|
if nameScopeGlobalStr, ok := params["name_scope_global"]; ok {
|
|
|
|
if nameScopeGlobal, err = strconv.ParseBool(nameScopeGlobalStr); err != nil {
|
|
|
|
return c.putCnrErrorResponse(fmt.Errorf("invalid name_scope_global param: %w", err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if nameScopeGlobal {
|
|
|
|
if !hasName {
|
|
|
|
return c.putCnrErrorResponse(errors.New("you must provide container name if name_scope_global param is set"))
|
|
|
|
}
|
2022-10-26 19:13:14 +00:00
|
|
|
|
|
|
|
var domain container.Domain
|
|
|
|
domain.SetName(containerName)
|
|
|
|
|
|
|
|
container.WriteDomain(&cnr, domain)
|
2022-06-17 12:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start := time.Now()
|
|
|
|
var prm client.PrmContainerPut
|
2022-10-26 19:13:14 +00:00
|
|
|
prm.SetContainer(cnr)
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
res, err := c.cli.ContainerPut(c.vu.Context(), prm)
|
|
|
|
if err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var wp waitParams
|
|
|
|
wp.setDefaults()
|
|
|
|
|
|
|
|
if err = c.waitForContainerPresence(c.vu.Context(), res.ID(), &wp); err != nil {
|
|
|
|
return c.putCnrErrorResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
stats.Report(c.vu, cnrPutDuration, metrics.D(time.Since(start)))
|
|
|
|
return PutContainerResponse{Success: true, ContainerID: res.ID().EncodeToString()}
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
func (c *Client) Onsite(containerID string, payload goja.ArrayBuffer) PreparedObject {
|
2022-05-23 11:42:48 +00:00
|
|
|
maxObjectSize, epoch, hhDisabled, err := parseNetworkInfo(c.vu.Context(), c.cli)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
data := payload.Bytes()
|
|
|
|
ln := len(data)
|
|
|
|
if ln > int(maxObjectSize) {
|
|
|
|
// not sure if load test needs object transformation
|
|
|
|
// with parent-child relation; if needs, then replace
|
|
|
|
// this code with the usage of object transformer from
|
|
|
|
// neofs-loader or distribution.
|
|
|
|
msg := fmt.Sprintf("payload size %d is bigger than network limit %d", ln, maxObjectSize)
|
|
|
|
panic(msg)
|
|
|
|
}
|
|
|
|
|
2022-09-02 19:23:33 +00:00
|
|
|
cliContainerID := parseContainerID(containerID)
|
2022-05-23 11:42:48 +00:00
|
|
|
|
|
|
|
var owner user.ID
|
|
|
|
user.IDFromKey(&owner, c.key.PublicKey)
|
|
|
|
|
|
|
|
apiVersion := version.Current()
|
|
|
|
|
|
|
|
obj := object.New()
|
|
|
|
obj.SetVersion(&apiVersion)
|
|
|
|
obj.SetType(object.TypeRegular)
|
2022-09-02 19:23:33 +00:00
|
|
|
obj.SetContainerID(cliContainerID)
|
2022-05-23 11:42:48 +00:00
|
|
|
obj.SetOwnerID(&owner)
|
|
|
|
obj.SetPayloadSize(uint64(ln))
|
|
|
|
obj.SetCreationEpoch(epoch)
|
|
|
|
|
|
|
|
var sha, hh checksum.Checksum
|
|
|
|
sha.SetSHA256(sha256.Sum256(data))
|
|
|
|
obj.SetPayloadChecksum(sha)
|
|
|
|
if !hhDisabled {
|
|
|
|
hh.SetTillichZemor(tz.Sum(data))
|
|
|
|
obj.SetPayloadHomomorphicHash(hh)
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreparedObject{
|
2022-05-25 08:22:40 +00:00
|
|
|
vu: c.vu,
|
|
|
|
key: c.key,
|
|
|
|
cli: c.cli,
|
|
|
|
bufsize: c.bufsize,
|
2022-05-23 11:42:48 +00:00
|
|
|
|
|
|
|
hdr: *obj,
|
|
|
|
payload: data,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p PreparedObject) Put(headers map[string]string) PutResponse {
|
|
|
|
obj := p.hdr
|
|
|
|
|
|
|
|
attrs := make([]object.Attribute, len(headers))
|
|
|
|
ind := 0
|
|
|
|
for k, v := range headers {
|
|
|
|
attrs[ind].SetKey(k)
|
|
|
|
attrs[ind].SetValue(v)
|
|
|
|
ind++
|
|
|
|
}
|
|
|
|
obj.SetAttributes(attrs...)
|
|
|
|
|
|
|
|
id, err := object.CalculateID(&obj)
|
|
|
|
if err != nil {
|
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
obj.SetID(id)
|
|
|
|
|
|
|
|
if err = object.CalculateAndSetSignature(p.key, &obj); err != nil {
|
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
2022-05-25 08:22:40 +00:00
|
|
|
_, err = put(p.vu, p.bufsize, p.cli, nil, &obj, p.payload)
|
2022-05-23 11:56:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return PutResponse{Success: false, Error: err.Error()}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PutResponse{Success: true, ObjectID: id.String()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func put(vu modules.VU, bufSize int, cli *client.Client, tok *session.Object,
|
|
|
|
hdr *object.Object, payload []byte) (*client.ResObjectPut, error) {
|
|
|
|
buf := make([]byte, bufSize)
|
|
|
|
rdr := bytes.NewReader(payload)
|
|
|
|
sz := rdr.Size()
|
2022-05-23 11:42:48 +00:00
|
|
|
|
|
|
|
// starting upload
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.Report(vu, objPutTotal, 1)
|
2022-05-23 11:42:48 +00:00
|
|
|
start := time.Now()
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
var prm client.PrmObjectPutInit
|
|
|
|
if tok != nil {
|
|
|
|
prm.WithinSession(*tok)
|
|
|
|
}
|
|
|
|
|
|
|
|
objectWriter, err := cli.ObjectPutInit(vu.Context(), prm)
|
2022-05-23 11:42:48 +00:00
|
|
|
if err != nil {
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.Report(vu, objPutFails, 1)
|
|
|
|
return nil, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 11:56:38 +00:00
|
|
|
if !objectWriter.WriteHeader(*hdr) {
|
|
|
|
stats.Report(vu, objPutFails, 1)
|
|
|
|
_, err = objectWriter.Close()
|
|
|
|
return nil, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n, _ := rdr.Read(buf)
|
|
|
|
for n > 0 {
|
|
|
|
if !objectWriter.WritePayloadChunk(buf[:n]) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
n, _ = rdr.Read(buf)
|
|
|
|
}
|
|
|
|
|
2022-05-23 11:56:38 +00:00
|
|
|
resp, err := objectWriter.Close()
|
2022-05-23 11:42:48 +00:00
|
|
|
if err != nil {
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.Report(vu, objPutFails, 1)
|
|
|
|
return nil, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 11:56:38 +00:00
|
|
|
stats.ReportDataSent(vu, float64(sz))
|
|
|
|
stats.Report(vu, objPutDuration, metrics.D(time.Since(start)))
|
2022-05-23 11:42:48 +00:00
|
|
|
|
2022-05-23 11:56:38 +00:00
|
|
|
return resp, err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func parseNetworkInfo(ctx context.Context, cli *client.Client) (maxObjSize, epoch uint64, hhDisabled bool, err error) {
|
|
|
|
ni, err := cli.NetworkInfo(ctx, client.PrmNetworkInfo{})
|
|
|
|
if err != nil {
|
|
|
|
return 0, 0, false, err
|
|
|
|
}
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
ninfo := ni.Info()
|
|
|
|
|
|
|
|
return ninfo.MaxObjectSize(), ninfo.CurrentEpoch(), ninfo.HomomorphicHashingDisabled(), err
|
2022-05-23 11:42:48 +00:00
|
|
|
}
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
type waitParams struct {
|
|
|
|
timeout time.Duration
|
|
|
|
pollInterval time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *waitParams) setDefaults() {
|
|
|
|
x.timeout = 120 * time.Second
|
|
|
|
x.pollInterval = 5 * time.Second
|
|
|
|
}
|
|
|
|
|
2022-10-26 19:13:14 +00:00
|
|
|
func (c *Client) waitForContainerPresence(ctx context.Context, cnrID cid.ID, wp *waitParams) error {
|
2022-06-17 12:50:24 +00:00
|
|
|
return waitFor(ctx, wp, func(ctx context.Context) bool {
|
|
|
|
var prm client.PrmContainerGet
|
2022-10-26 19:13:14 +00:00
|
|
|
prm.SetContainer(cnrID)
|
2022-06-17 12:50:24 +00:00
|
|
|
|
|
|
|
_, err := c.cli.ContainerGet(ctx, prm)
|
|
|
|
return err == nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitFor(ctx context.Context, params *waitParams, condition func(context.Context) bool) error {
|
|
|
|
wctx, cancel := context.WithTimeout(ctx, params.timeout)
|
|
|
|
defer cancel()
|
|
|
|
ticker := time.NewTimer(params.pollInterval)
|
|
|
|
defer ticker.Stop()
|
|
|
|
wdone := wctx.Done()
|
|
|
|
done := ctx.Done()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return ctx.Err()
|
|
|
|
case <-wdone:
|
|
|
|
return wctx.Err()
|
|
|
|
case <-ticker.C:
|
|
|
|
if condition(ctx) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
ticker.Reset(params.pollInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-02 19:23:33 +00:00
|
|
|
|
|
|
|
func parseContainerID(strContainerID string) cid.ID {
|
|
|
|
var containerID cid.ID
|
|
|
|
err := containerID.DecodeString(strContainerID)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return containerID
|
|
|
|
}
|
|
|
|
|
|
|
|
func parseObjectID(strObjectID string) oid.ID {
|
|
|
|
var cliObjectID oid.ID
|
|
|
|
err := cliObjectID.DecodeString(strObjectID)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return cliObjectID
|
|
|
|
}
|