forked from TrueCloudLab/frostfs-node
[#1556] Upgrade NeoFS SDK Go with changed container API
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
f699e82ea7
commit
c165d1a9b5
36 changed files with 207 additions and 480 deletions
|
@ -11,7 +11,6 @@ import (
|
|||
core "github.com/nspcc-dev/neofs-node/pkg/core/container"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
|
||||
"github.com/nspcc-dev/neofs-sdk-go/session"
|
||||
|
@ -90,7 +89,6 @@ func (c *Client) Get(cid []byte) (*containercore.Container, error) {
|
|||
|
||||
var cnr containercore.Container
|
||||
|
||||
cnr.Value = container.New()
|
||||
if err := cnr.Value.Unmarshal(cnrBytes); err != nil {
|
||||
// use other major version if there any
|
||||
return nil, fmt.Errorf("can't unmarshal container: %w", err)
|
||||
|
|
|
@ -2,7 +2,6 @@ package container
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
|
@ -13,14 +12,14 @@ import (
|
|||
|
||||
// AnnounceLoadPrm groups parameters of AnnounceLoad operation.
|
||||
type AnnounceLoadPrm struct {
|
||||
a container.UsedSpaceAnnouncement
|
||||
a container.SizeEstimation
|
||||
key []byte
|
||||
|
||||
client.InvokePrmOptional
|
||||
}
|
||||
|
||||
// SetAnnouncement sets announcement.
|
||||
func (a2 *AnnounceLoadPrm) SetAnnouncement(a container.UsedSpaceAnnouncement) {
|
||||
func (a2 *AnnounceLoadPrm) SetAnnouncement(a container.SizeEstimation) {
|
||||
a2.a = a
|
||||
}
|
||||
|
||||
|
@ -34,17 +33,12 @@ func (a2 *AnnounceLoadPrm) SetReporter(key []byte) {
|
|||
//
|
||||
// Returns any error encountered that caused the saving to interrupt.
|
||||
func (c *Client) AnnounceLoad(p AnnounceLoadPrm) error {
|
||||
cnr, ok := p.a.ContainerID()
|
||||
if !ok {
|
||||
return errors.New("missing container for load announcement")
|
||||
}
|
||||
|
||||
binCnr := make([]byte, sha256.Size)
|
||||
cnr.Encode(binCnr)
|
||||
p.a.Container().Encode(binCnr)
|
||||
|
||||
prm := client.InvokePrm{}
|
||||
prm.SetMethod(putSizeMethod)
|
||||
prm.SetArgs(p.a.Epoch(), binCnr, p.a.UsedSpace(), p.key)
|
||||
prm.SetArgs(p.a.Epoch(), binCnr, p.a.Value(), p.key)
|
||||
prm.InvokePrmOptional = p.InvokePrmOptional
|
||||
|
||||
err := c.client.Invoke(prm)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
|
@ -16,21 +15,14 @@ import (
|
|||
//
|
||||
// Returns error if container is nil.
|
||||
func Put(c *Client, cnr containercore.Container) (*cid.ID, error) {
|
||||
if cnr.Value == nil {
|
||||
return nil, errNilArgument
|
||||
}
|
||||
data := cnr.Value.Marshal()
|
||||
|
||||
data, err := cnr.Value.Marshal()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't marshal container: %w", err)
|
||||
}
|
||||
|
||||
name, zone := container.GetNativeNameWithZone(cnr.Value)
|
||||
d := container.ReadDomain(cnr.Value)
|
||||
|
||||
var prm PutPrm
|
||||
prm.SetContainer(data)
|
||||
prm.SetName(name)
|
||||
prm.SetZone(zone)
|
||||
prm.SetName(d.Name())
|
||||
prm.SetZone(d.Zone())
|
||||
|
||||
if cnr.Session != nil {
|
||||
prm.SetToken(cnr.Session.Marshal())
|
||||
|
@ -43,13 +35,13 @@ func Put(c *Client, cnr containercore.Container) (*cid.ID, error) {
|
|||
prm.SetKey(sigV2.GetKey())
|
||||
prm.SetSignature(sigV2.GetSign())
|
||||
|
||||
err = c.Put(prm)
|
||||
err := c.Put(prm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var id cid.ID
|
||||
id.SetSHA256(sha256.Sum256(data))
|
||||
container.CalculateIDFromBinary(&id, data)
|
||||
|
||||
return &id, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue