From 3de8febe5727eca7652468e4a116c8d5221c8d93 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 16 Nov 2020 12:43:52 +0300 Subject: [PATCH] [#174] Update to latest neofs-api-go changes Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/accounting.go | 10 +-- cmd/neofs-cli/modules/container.go | 67 ++++++++---------- cmd/neofs-cli/modules/netmap.go | 2 +- cmd/neofs-cli/modules/object.go | 50 ++++++------- cmd/neofs-cli/modules/util.go | 5 +- go.mod | 3 +- go.sum | Bin 59747 -> 59747 bytes pkg/core/container/fmt.go | 10 +-- pkg/core/container/fmt_test.go | 8 +-- pkg/core/object/fmt.go | 12 ++-- pkg/core/object/object.go | 18 +---- pkg/core/object/tombstone.go | 2 +- .../localstore/methods.go | 4 +- pkg/local_object_storage/metabase/db_test.go | 2 +- pkg/local_object_storage/metabase/get.go | 4 +- pkg/local_object_storage/metabase/put.go | 18 ++--- .../metabase/select_test.go | 16 ++--- pkg/services/object/acl/acl.go | 6 +- pkg/services/object/acl/classifier.go | 6 +- pkg/services/object/acl/eacl/types.go | 4 +- pkg/services/object/acl/eacl/v2/eacl_test.go | 4 +- pkg/services/object/acl/eacl/v2/headers.go | 3 +- pkg/services/object/acl/eacl/v2/object.go | 14 ++-- pkg/services/object/acl/eacl/validator.go | 6 +- pkg/services/object/delete/service.go | 22 +++--- pkg/services/object/head/distributed.go | 4 +- pkg/services/object/head/relation.go | 2 +- pkg/services/object/head/service.go | 2 +- pkg/services/object/put/distributed.go | 6 +- pkg/services/object/put/local.go | 4 +- pkg/services/object/put/streamer.go | 4 +- pkg/services/object/put/validation.go | 6 +- pkg/services/object/range/chain.go | 12 ++-- pkg/services/object/range/local.go | 2 +- pkg/services/object/range/service.go | 4 +- pkg/services/object/range/streamer.go | 4 +- pkg/services/object/rangehash/distributed.go | 4 +- pkg/services/object/rangehash/local.go | 2 +- pkg/services/object/rangehash/service.go | 4 +- pkg/services/object/search/local.go | 2 +- pkg/services/object/search/relation.go | 6 +- pkg/services/object/util/chain.go | 12 ++-- pkg/services/object_manager/gc/gc.go | 4 +- .../object_manager/placement/traverser.go | 2 +- .../object_manager/transformer/fmt.go | 6 +- .../object_manager/transformer/transformer.go | 10 +-- pkg/services/policer/check.go | 4 +- 47 files changed, 188 insertions(+), 214 deletions(-) diff --git a/cmd/neofs-cli/modules/accounting.go b/cmd/neofs-cli/modules/accounting.go index 02f42a0fd..b5e03e18a 100644 --- a/cmd/neofs-cli/modules/accounting.go +++ b/cmd/neofs-cli/modules/accounting.go @@ -86,15 +86,15 @@ func prettyPrintDecimal(decimal *accounting.Decimal) { } if verbose { - fmt.Println("value:", decimal.GetValue()) - fmt.Println("precision:", decimal.GetPrecision()) + fmt.Println("value:", decimal.Value()) + fmt.Println("precision:", decimal.Precision()) } else { // divider = 10^{precision}; v:365, p:2 => 365 / 10^2 = 3.65 - divider := math.Pow(10, float64(decimal.GetPrecision())) + divider := math.Pow(10, float64(decimal.Precision())) // %0.8f\n for precision 8 - format := fmt.Sprintf("%%0.%df\n", decimal.GetPrecision()) + format := fmt.Sprintf("%%0.%df\n", decimal.Precision()) - fmt.Printf(format, float64(decimal.GetValue())/divider) + fmt.Printf(format, float64(decimal.Value())/divider) } } diff --git a/cmd/neofs-cli/modules/container.go b/cmd/neofs-cli/modules/container.go index 17aef7940..721059de2 100644 --- a/cmd/neofs-cli/modules/container.go +++ b/cmd/neofs-cli/modules/container.go @@ -21,8 +21,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" - v2ACL "github.com/nspcc-dev/neofs-api-go/v2/acl" - grpcACL "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc" v2container "github.com/nspcc-dev/neofs-api-go/v2/container" grpccontainer "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" "github.com/nspcc-dev/neofs-node/pkg/policy" @@ -139,7 +137,7 @@ It will be stored in sidechain when inner ring will accepts it.`, } cnr := container.New() - cnr.SetPlacementPolicy(placementPolicy.ToV2()) + cnr.SetPlacementPolicy(placementPolicy) cnr.SetBasicACL(basicACL) cnr.SetAttributes(attributes) cnr.SetNonce(nonce[:]) @@ -312,7 +310,7 @@ var getContainerInfoCmd = &cobra.Command{ ) if containerJSON { - data, err = v2container.ContainerToJSON(cnr.ToV2()) + data, err = cnr.MarshalJSON() if err != nil { return fmt.Errorf("can't JSON encode container: %w", err) } @@ -356,7 +354,7 @@ var getExtendedACLCmd = &cobra.Command{ } v := eaclTable.Version() - if v.GetMajor() == 0 && v.GetMajor() == 0 { + if v.Major() == 0 && v.Major() == 0 { fmt.Println("extended ACL table is not set for this container") return nil } @@ -369,7 +367,7 @@ var getExtendedACLCmd = &cobra.Command{ var data []byte if containerJSON { - data, err = v2ACL.TableToJSON(eaclTable.ToV2()) + data, err = eaclTable.MarshalJSON() if err != nil { return fmt.Errorf("can't enode to JSON: %w", err) } @@ -533,8 +531,8 @@ func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error) return result, nil } - result, err = netmap.PlacementPolicyFromJSON([]byte(policyString)) - if err == nil { + result = netmap.NewPlacementPolicy() + if err = result.UnmarshalJSON([]byte(policyString)); err == nil { printVerbose("Parsed JSON encoded policy") return result, nil } @@ -542,8 +540,8 @@ func parseContainerPolicy(policyString string) (*netmap.PlacementPolicy, error) return nil, errors.New("can't parse placement policy") } -func parseAttributes(attributes []string) ([]*v2container.Attribute, error) { - result := make([]*v2container.Attribute, 0, len(attributes)+2) // name + timestamp attributes +func parseAttributes(attributes []string) ([]*container.Attribute, error) { + result := make([]*container.Attribute, 0, len(attributes)+2) // name + timestamp attributes for i := range attributes { kvPair := strings.Split(attributes[i], attributeDelimiter) @@ -551,7 +549,7 @@ func parseAttributes(attributes []string) ([]*v2container.Attribute, error) { return nil, errors.New("invalid container attribute") } - parsedAttribute := new(v2container.Attribute) + parsedAttribute := container.NewAttribute() parsedAttribute.SetKey(kvPair[0]) parsedAttribute.SetValue(kvPair[1]) @@ -559,7 +557,7 @@ func parseAttributes(attributes []string) ([]*v2container.Attribute, error) { } if !containerNoTimestamp { - timestamp := new(v2container.Attribute) + timestamp := container.NewAttribute() timestamp.SetKey(container.AttributeTimestamp) timestamp.SetValue(strconv.FormatInt(time.Now().Unix(), 10)) @@ -567,7 +565,7 @@ func parseAttributes(attributes []string) ([]*v2container.Attribute, error) { } if containerName != "" { - cnrName := new(v2container.Attribute) + cnrName := container.NewAttribute() cnrName.SetKey(container.AttributeName) cnrName.SetValue(containerName) @@ -629,7 +627,7 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) { } if jsonEncoding { - data, err := v2container.ContainerToJSON(cnr.ToV2()) + data, err := cnr.MarshalJSON() if err != nil { printVerbose("Can't convert container to json: %w", err) return @@ -647,14 +645,12 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) { id := container.CalculateID(cnr) fmt.Println("container ID:", id) - version := cnr.GetVersion() - fmt.Printf("version: %d.%d\n", version.GetMajor(), version.GetMinor()) + version := cnr.Version() + fmt.Printf("version: %d.%d\n", version.Major(), version.Minor()) - // todo: return pkg structures instead of v2 structures - ownerID := owner.NewIDFromV2(cnr.GetOwnerID()) - fmt.Println("owner ID:", ownerID) + fmt.Println("owner ID:", cnr.OwnerID()) - basicACL := cnr.GetBasicACL() + basicACL := cnr.BasicACL() fmt.Printf("basic ACL: %s", strconv.FormatUint(uint64(basicACL), 16)) switch basicACL { case acl.PublicBasicRule: @@ -667,27 +663,26 @@ func prettyPrintContainer(cnr *container.Container, jsonEncoding bool) { fmt.Println() } - for _, attribute := range cnr.GetAttributes() { - if attribute.GetKey() == container.AttributeTimestamp { + for _, attribute := range cnr.Attributes() { + if attribute.Key() == container.AttributeTimestamp { fmt.Printf("attribute: %s=%s (%s)\n", - attribute.GetKey(), - attribute.GetValue(), - prettyPrintUnixTime(attribute.GetValue())) + attribute.Key(), + attribute.Value(), + prettyPrintUnixTime(attribute.Value())) continue } - fmt.Printf("attribute: %s=%s\n", attribute.GetKey(), attribute.GetValue()) + fmt.Printf("attribute: %s=%s\n", attribute.Key(), attribute.Value()) } - nonce, err := uuid.FromBytes(cnr.GetNonce()) + nonce, err := uuid.FromBytes(cnr.Nonce()) if err == nil { fmt.Println("nonce:", nonce) } fmt.Println("placement policy:") - cnrPolicy := netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy()) - fmt.Println(strings.Join(policy.Encode(cnrPolicy), "\n")) + fmt.Println(strings.Join(policy.Encode(cnr.PlacementPolicy()), "\n")) } func parseEACL(eaclPath string) (*eacl.Table, error) { @@ -703,23 +698,17 @@ func parseEACL(eaclPath string) (*eacl.Table, error) { return nil, fmt.Errorf("can't read file with EACL: %w", err) } - msg := new(grpcACL.EACLTable) - if proto.Unmarshal(data, msg) == nil { - printVerbose("Parsed binary encoded EACL table") - v2 := v2ACL.TableFromGRPCMessage(msg) - return eacl.NewTableFromV2(v2), nil - } - - if v2, err := v2ACL.TableFromJSON(data); err == nil { + table := eacl.NewTable() + if err = table.UnmarshalJSON(data); err == nil { printVerbose("Parsed JSON encoded EACL table") - return eacl.NewTableFromV2(v2), nil + return table, nil } return nil, fmt.Errorf("can't parse EACL table: %w", err) } func prettyPrintEACL(table *eacl.Table) { - data, err := v2ACL.TableToJSON(table.ToV2()) + data, err := table.MarshalJSON() if err != nil { printVerbose("Can't convert container to json: %w", err) return diff --git a/cmd/neofs-cli/modules/netmap.go b/cmd/neofs-cli/modules/netmap.go index daa451eeb..3b67ef35b 100644 --- a/cmd/neofs-cli/modules/netmap.go +++ b/cmd/neofs-cli/modules/netmap.go @@ -81,7 +81,7 @@ var localNodeInfoCmd = &cobra.Command{ func prettyPrintNodeInfo(i *netmap.NodeInfo, jsonEncoding bool) { if jsonEncoding { - data, err := netmap.NodeInfoToJSON(i) + data, err := i.MarshalJSON() if err != nil { printVerbose("Can't convert container to json: %w", err) return diff --git a/cmd/neofs-cli/modules/object.go b/cmd/neofs-cli/modules/object.go index 0ef3d2969..6470f6891 100644 --- a/cmd/neofs-cli/modules/object.go +++ b/cmd/neofs-cli/modules/object.go @@ -20,10 +20,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/token" - v2ACL "github.com/nspcc-dev/neofs-api-go/v2/acl" - grpcACL "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc" "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" ) var ( @@ -236,7 +233,7 @@ func deleteObject(cmd *cobra.Command, _ []string) error { } cmd.Println("Object removed successfully.") - cmd.Printf(" ID: %s\n CID: %s\n", objAddr.GetObjectID(), objAddr.GetContainerID()) + cmd.Printf(" ID: %s\n CID: %s\n", objAddr.ObjectID(), objAddr.ContainerID()) return nil } @@ -390,9 +387,9 @@ func getObjectHash(cmd *cobra.Command, _ []string) error { } switch typ { case hashSha256: - cmd.Println(hex.EncodeToString(obj.GetPayloadChecksum().GetSum())) + cmd.Println(hex.EncodeToString(obj.PayloadChecksum().Sum())) case hashTz: - cmd.Println(hex.EncodeToString(obj.GetPayloadHomomorphicHash().GetSum())) + cmd.Println(hex.EncodeToString(obj.PayloadHomomorphicHash().Sum())) } return nil } @@ -592,14 +589,14 @@ func printHeader(cmd *cobra.Command, obj *object.Object, filename string) error cmd.Printf("[%s] Header successfully saved.", filename) } - cmd.Printf("ID: %s\n", obj.GetID()) - cmd.Printf("CID: %s\n", obj.GetContainerID()) - cmd.Printf("Owner: %s\n", obj.GetOwnerID()) - cmd.Printf("CreatedAt: %d\n", obj.GetCreationEpoch()) - cmd.Printf("Size: %d\n", obj.GetPayloadSize()) - cmd.Printf("HomoHash: %s\n", hex.EncodeToString(obj.GetPayloadHomomorphicHash().GetSum())) - cmd.Printf("Checksum: %s\n", hex.EncodeToString(obj.GetPayloadChecksum().GetSum())) - switch obj.GetType() { + cmd.Printf("ID: %s\n", obj.ID()) + cmd.Printf("CID: %s\n", obj.ContainerID()) + cmd.Printf("Owner: %s\n", obj.OwnerID()) + cmd.Printf("CreatedAt: %d\n", obj.CreationEpoch()) + cmd.Printf("Size: %d\n", obj.PayloadSize()) + cmd.Printf("HomoHash: %s\n", hex.EncodeToString(obj.PayloadHomomorphicHash().Sum())) + cmd.Printf("Checksum: %s\n", hex.EncodeToString(obj.PayloadChecksum().Sum())) + switch obj.Type() { case object.TypeRegular: cmd.Println("Type: regular") case object.TypeTombstone: @@ -611,15 +608,15 @@ func printHeader(cmd *cobra.Command, obj *object.Object, filename string) error } cmd.Println("Attributes:") - for _, attr := range obj.GetAttributes() { - if attr.GetKey() == object.AttributeTimestamp { + for _, attr := range obj.Attributes() { + if attr.Key() == object.AttributeTimestamp { cmd.Printf(" %s=%s (%s)\n", - attr.GetKey(), - attr.GetValue(), - prettyPrintUnixTime(attr.GetValue())) + attr.Key(), + attr.Value(), + prettyPrintUnixTime(attr.Value())) continue } - cmd.Printf(" %s=%s\n", attr.GetKey(), attr.GetValue()) + cmd.Printf(" %s=%s\n", attr.Key(), attr.Value()) } return nil } @@ -650,19 +647,16 @@ func getBearerToken(cmd *cobra.Command, flagname string) (*token.BearerToken, er return nil, fmt.Errorf("can't read bearer token file: %w", err) } - v2token, err := v2ACL.BearerTokenFromJSON(data) - if err != nil { - msg := new(grpcACL.BearerToken) - if proto.Unmarshal(data, msg) != nil { - return nil, fmt.Errorf("can't decode beare token: %w", err) + tok := token.NewBearerToken() + if err := tok.UnmarshalJSON(data); err != nil { + if err = tok.Unmarshal(data); err != nil { + return nil, fmt.Errorf("can't decode bearer token: %w", err) } - v2token = v2ACL.BearerTokenFromGRPCMessage(msg) - printVerbose("Using binary encoded bearer token") } else { printVerbose("Using JSON encoded bearer token") } - return token.NewBearerTokenFromV2(v2token), nil + return tok, nil } diff --git a/cmd/neofs-cli/modules/util.go b/cmd/neofs-cli/modules/util.go index f3ec57b75..0510d08e1 100644 --- a/cmd/neofs-cli/modules/util.go +++ b/cmd/neofs-cli/modules/util.go @@ -13,7 +13,6 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/token" - v2ACL "github.com/nspcc-dev/neofs-api-go/v2/acl" "github.com/nspcc-dev/neofs-node/pkg/util/keyer" "github.com/spf13/cobra" ) @@ -108,7 +107,7 @@ func signBearerToken(cmd *cobra.Command, _ []string) error { var data []byte if jsonFlag || len(to) == 0 { - data, err = v2ACL.BearerTokenToJSON(btok.ToV2()) + data, err = btok.MarshalJSON() if err != nil { return fmt.Errorf("can't JSON encode bearer token: %w", err) } @@ -147,7 +146,7 @@ func convertEACLTable(cmd *cobra.Command, _ []string) error { var data []byte if jsonFlag || len(to) == 0 { - data, err = v2ACL.TableToJSON(table.ToV2()) + data, err = table.MarshalJSON() if err != nil { return fmt.Errorf("can't JSON encode extended ACL table: %w", err) } diff --git a/go.mod b/go.mod index bfce12ce2..4ac5fc017 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/multiformats/go-multiaddr-net v0.1.2 // v0.1.1 => v0.1.2 github.com/multiformats/go-multihash v0.0.13 // indirect github.com/nspcc-dev/neo-go v0.91.1-pre.0.20201030072836-71216865717b - github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201111110701-789474906015 + github.com/nspcc-dev/neofs-api-go v1.3.1-0.20201116094437-fe336fd5ba28 github.com/nspcc-dev/neofs-crypto v0.3.0 github.com/nspcc-dev/tzhash v1.4.0 github.com/panjf2000/ants/v2 v2.3.0 @@ -36,7 +36,6 @@ require ( golang.org/x/sys v0.0.0-20201024232916-9f70ab9862d5 // indirect golang.org/x/tools v0.0.0-20200123022218-593de606220b // indirect google.golang.org/grpc v1.29.1 - google.golang.org/protobuf v1.23.0 ) // Used for debug reasons diff --git a/go.sum b/go.sum index 1453f505ddab322030ac38ab5f11948d6b13d9cf..904341e5fba0c8ce19380a4443cbf482558dab5e 100644 GIT binary patch delta 107 zcmaESiTUv*<_#iQ&SnOdCML$_x@oD##%5_Lrb&rL777`LR&D{oCaGQ(rUt2Qd6j7y tnI6tzxrzQMWyXbO1}UYErJ+&2Vfn?LJ`oWnlOJT7h+s2k^ZcwMbpVQzBk2GD delta 110 zcmaESiTUv*<_#iQPKJht2IdBay5<&^CgvuV24)6^rV1H`R>jGISwT)-`NpP!MV>i^ x7S1J^;UTUrhMon%5!$I)0VT#pS+1dxi5C8oCuT@b{*@^ug3YMS^RtfB0RU*{A{_t# diff --git a/pkg/core/container/fmt.go b/pkg/core/container/fmt.go index e5c45f6fe..1fbcdbce6 100644 --- a/pkg/core/container/fmt.go +++ b/pkg/core/container/fmt.go @@ -10,24 +10,24 @@ import ( var errNilPolicy = errors.New("placement policy is nil") -// CheckFormat conducts an initial check of the container data. +// CheckFormat conducts an initial check of the v2 container data. // // It is expected that if a container fails this test, // it will not be inner-ring approved. func CheckFormat(c *container.Container) error { - if c.GetPlacementPolicy() == nil { + if c.PlacementPolicy() == nil { return errNilPolicy } - if err := pkg.IsSupportedVersion(pkg.NewVersionFromV2(c.GetVersion())); err != nil { + if err := pkg.IsSupportedVersion(c.Version()); err != nil { return errors.Wrap(err, "incorrect version") } - if len(c.GetOwnerID().GetValue()) != owner.NEO3WalletSize { + if len(c.OwnerID().ToV2().GetValue()) != owner.NEO3WalletSize { return errors.Wrap(owner.ErrBadID, "incorrect owner identifier") } - if _, err := uuid.FromBytes(c.GetNonce()); err != nil { + if _, err := uuid.FromBytes(c.Nonce()); err != nil { return errors.Wrap(err, "incorrect nonce") } diff --git a/pkg/core/container/fmt_test.go b/pkg/core/container/fmt_test.go index 0b8b5bc65..61e568f9e 100644 --- a/pkg/core/container/fmt_test.go +++ b/pkg/core/container/fmt_test.go @@ -17,19 +17,19 @@ func TestCheckFormat(t *testing.T) { require.Error(t, CheckFormat(c)) - policy := new(netmap.PlacementPolicy) - c.SetPlacementPolicy(policy.ToV2()) + policy := netmap.NewPlacementPolicy() + c.SetPlacementPolicy(policy) require.Error(t, CheckFormat(c)) - c.SetVersion(pkg.SDKVersion().ToV2()) + c.SetVersion(pkg.SDKVersion()) require.Error(t, CheckFormat(c)) wallet, err := owner.NEO3WalletFromPublicKey(&test.DecodeKey(-1).PublicKey) require.NoError(t, err) - c.SetOwnerID(owner.NewIDFromNeo3Wallet(wallet).ToV2()) + c.SetOwnerID(owner.NewIDFromNeo3Wallet(wallet)) c.SetNonce(nil) diff --git a/pkg/core/object/fmt.go b/pkg/core/object/fmt.go index c1bf35e4f..2de56c0cf 100644 --- a/pkg/core/object/fmt.go +++ b/pkg/core/object/fmt.go @@ -57,9 +57,9 @@ func NewFormatValidator(opts ...FormatValidatorOption) *FormatValidator { func (v *FormatValidator) Validate(obj *Object) error { if obj == nil { return errNilObject - } else if obj.GetID() == nil { + } else if obj.ID() == nil { return errNilID - } else if obj.GetContainerID() == nil { + } else if obj.ContainerID() == nil { return errNilCID } @@ -77,11 +77,11 @@ func (v *FormatValidator) Validate(obj *Object) error { } func (v *FormatValidator) validateSignatureKey(obj *Object) error { - token := obj.GetSessionToken() - key := obj.GetSignature().GetKey() + token := obj.SessionToken() + key := obj.Signature().Key() if token == nil || !bytes.Equal(token.SessionKey(), key) { - return v.checkOwnerKey(obj.GetOwnerID(), obj.GetSignature().GetKey()) + return v.checkOwnerKey(obj.OwnerID(), obj.Signature().Key()) } // FIXME: perform token verification @@ -123,7 +123,7 @@ func (v *FormatValidator) ValidateContent(t object.Type, payload []byte) error { addrList := content.GetAddressList() for _, addr := range addrList { - if addr.GetContainerID() == nil || addr.GetObjectID() == nil { + if addr.ContainerID() == nil || addr.ObjectID() == nil { return errors.Errorf("(%T) empty address reference in tombstone", v) } } diff --git a/pkg/core/object/object.go b/pkg/core/object/object.go index 4ee263ad6..acc1dff4c 100644 --- a/pkg/core/object/object.go +++ b/pkg/core/object/object.go @@ -19,8 +19,8 @@ type Object struct { func (o *Object) Address() *object.Address { if o != nil { aV2 := new(refs.Address) - aV2.SetObjectID(o.GetID().ToV2()) - aV2.SetContainerID(o.GetContainerID().ToV2()) + aV2.SetObjectID(o.ID().ToV2()) + aV2.SetContainerID(o.ContainerID().ToV2()) return object.NewAddressFromV2(aV2) } @@ -56,22 +56,10 @@ func New() *Object { return NewFromSDK(object.New()) } -// FromBytes restores Object from binary format. -func FromBytes(data []byte) (*Object, error) { - o, err := object.FromBytes(data) - if err != nil { - return nil, err - } - - return &Object{ - Object: o, - }, nil -} - // GetParent returns parent object. func (o *Object) GetParent() *Object { if o != nil { - if par := o.Object.GetParent(); par != nil { + if par := o.Object.Parent(); par != nil { return &Object{ Object: par, } diff --git a/pkg/core/object/tombstone.go b/pkg/core/object/tombstone.go index 924d4690a..8ad04be9b 100644 --- a/pkg/core/object/tombstone.go +++ b/pkg/core/object/tombstone.go @@ -122,7 +122,7 @@ func (c *TombstoneContentV2) StableUnmarshal(data []byte) error { data = data[ln:] addr := new(refs.Address) - if err := addr.StableUnmarshal(data[:sz]); err != nil { + if err := addr.Unmarshal(data[:sz]); err != nil { fmt.Println(err) return err } diff --git a/pkg/local_object_storage/localstore/methods.go b/pkg/local_object_storage/localstore/methods.go index b30cab007..db59c41dd 100644 --- a/pkg/local_object_storage/localstore/methods.go +++ b/pkg/local_object_storage/localstore/methods.go @@ -67,7 +67,9 @@ func (s *Storage) Get(addr *objectSDK.Address) (*object.Object, error) { return nil, errors.Wrap(err, "could not get object from BLOB storage") } - return object.FromBytes(objBytes) + obj := object.New() + + return obj, obj.Unmarshal(objBytes) } func (s *Storage) Head(addr *objectSDK.Address) (*object.Object, error) { diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index 586b6b208..5782e82e5 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -128,7 +128,7 @@ func TestDB_Delete(t *testing.T) { require.NoError(t, err) fs := objectSDK.SearchFilters{} - fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, o.GetContainerID()) + fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, o.ContainerID()) testSelect(t, db, fs, o.Address()) diff --git a/pkg/local_object_storage/metabase/get.go b/pkg/local_object_storage/metabase/get.go index 498cc2a06..21556bc5f 100644 --- a/pkg/local_object_storage/metabase/get.go +++ b/pkg/local_object_storage/metabase/get.go @@ -34,7 +34,9 @@ func (db *DB) Get(addr *objectSDK.Address) (*object.Object, error) { var err error - obj, err = object.FromBytes(data) + obj = object.New() + + err = obj.Unmarshal(data) return err }); err != nil { diff --git a/pkg/local_object_storage/metabase/put.go b/pkg/local_object_storage/metabase/put.go index 625dd82e9..11a77c166 100644 --- a/pkg/local_object_storage/metabase/put.go +++ b/pkg/local_object_storage/metabase/put.go @@ -94,27 +94,27 @@ func addressKey(addr *objectSDK.Address) []byte { } func objectIndices(obj *object.Object, parent bool) []bucketItem { - as := obj.GetAttributes() + as := obj.Attributes() res := make([]bucketItem, 0, 7+len(as)) // 7 predefined buckets and object attributes childfreeVal := v2object.BooleanPropertyValueTrue - if len(obj.GetChildren()) > 0 { + if len(obj.Children()) > 0 { childfreeVal = "" } res = append(res, bucketItem{ key: v2object.FilterHeaderVersion, - val: obj.GetVersion().String(), + val: obj.Version().String(), }, bucketItem{ key: v2object.FilterHeaderContainerID, - val: obj.GetContainerID().String(), + val: obj.ContainerID().String(), }, bucketItem{ key: v2object.FilterHeaderOwnerID, - val: obj.GetOwnerID().String(), + val: obj.OwnerID().String(), }, bucketItem{ key: v2object.FilterPropertyChildfree, @@ -122,12 +122,12 @@ func objectIndices(obj *object.Object, parent bool) []bucketItem { }, bucketItem{ key: v2object.FilterHeaderParent, - val: obj.GetParentID().String(), + val: obj.ParentID().String(), }, // TODO: add remaining fields after neofs-api#72 ) - if obj.GetType() == objectSDK.TypeRegular && !obj.HasParent() { + if obj.Type() == objectSDK.TypeRegular && !obj.HasParent() { res = append(res, bucketItem{ key: v2object.FilterPropertyRoot, }) @@ -141,8 +141,8 @@ func objectIndices(obj *object.Object, parent bool) []bucketItem { for _, a := range as { res = append(res, bucketItem{ - key: a.GetKey(), - val: a.GetValue(), + key: a.Key(), + val: a.Value(), }) } diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index 0383fa631..04708db87 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -100,15 +100,15 @@ func TestMismatchAfterMatch(t *testing.T) { require.NoError(t, db.Put(obj)) - a := obj.GetAttributes()[0] + a := obj.Attributes()[0] fs := objectSDK.SearchFilters{} // 1st - mismatching filter - fs.AddFilter(a.GetKey(), a.GetValue()+"1", objectSDK.MatchStringEqual) + fs.AddFilter(a.Key(), a.Value()+"1", objectSDK.MatchStringEqual) // 2nd - matching filter - fs.AddFilter(a.GetKey(), a.GetValue(), objectSDK.MatchStringEqual) + fs.AddFilter(a.Key(), a.Value(), objectSDK.MatchStringEqual) testSelect(t, db, fs) } @@ -120,7 +120,7 @@ func addCommonAttribute(objs ...*object.Object) *objectSDK.Attribute { for _, o := range objs { object.NewRawFromObject(o).SetAttributes( - append(o.GetAttributes(), aCommon)..., + append(o.Attributes(), aCommon)..., ) } @@ -143,7 +143,7 @@ func TestSelectRemoved(t *testing.T) { require.NoError(t, db.Put(obj2)) fs := objectSDK.SearchFilters{} - fs.AddFilter(a.GetKey(), a.GetValue(), objectSDK.MatchStringEqual) + fs.AddFilter(a.Key(), a.Value(), objectSDK.MatchStringEqual) testSelect(t, db, fs, obj1.Address(), obj2.Address()) @@ -165,7 +165,7 @@ func TestMissingObjectAttribute(t *testing.T) { // add object w/o attribute obj2 := generateObject(t, testPrm{}) - a1 := obj1.GetAttributes()[0] + a1 := obj1.Attributes()[0] // add common attribute aCommon := addCommonAttribute(obj1, obj2) @@ -177,10 +177,10 @@ func TestMissingObjectAttribute(t *testing.T) { fs := objectSDK.SearchFilters{} // 1st filter by common attribute - fs.AddFilter(aCommon.GetKey(), aCommon.GetValue(), objectSDK.MatchStringEqual) + fs.AddFilter(aCommon.Key(), aCommon.Value(), objectSDK.MatchStringEqual) // next filter by attribute from 1st object only - fs.AddFilter(a1.GetKey(), a1.GetValue(), objectSDK.MatchStringEqual) + fs.AddFilter(a1.Key(), a1.Value(), objectSDK.MatchStringEqual) testSelect(t, db, fs, obj1.Address()) } diff --git a/pkg/services/object/acl/acl.go b/pkg/services/object/acl/acl.go index 5f0e1ee43..4294aba25 100644 --- a/pkg/services/object/acl/acl.go +++ b/pkg/services/object/acl/acl.go @@ -399,7 +399,7 @@ func (b Service) findRequestInfo( // fetch actual container cnr, err := b.containers.Get(cid) - if err != nil || cnr.GetOwnerID() == nil { + if err != nil || cnr.OwnerID() == nil { return info, ErrUnknownContainer } @@ -417,10 +417,10 @@ func (b Service) findRequestInfo( verb := sourceVerbOfRequest(req, op) // todo: check verb sanity, if it was generated correctly. Do we need it ? - info.basicACL = basicACLHelper(cnr.GetBasicACL()) + info.basicACL = basicACLHelper(cnr.BasicACL()) info.requestRole = role info.operation = verb - info.owner = owner.NewIDFromV2(cnr.GetOwnerID()) + info.owner = cnr.OwnerID() info.cid = cid // it is assumed that at the moment the key will be valid, diff --git a/pkg/services/object/acl/classifier.go b/pkg/services/object/acl/classifier.go index 2bff0f34b..9bc3d262e 100644 --- a/pkg/services/object/acl/classifier.go +++ b/pkg/services/object/acl/classifier.go @@ -62,7 +62,7 @@ func (c SenderClassifier) Classify( // todo: get owner from neofs.id if present // if request owner is the same as container owner, return RoleUser - if bytes.Equal(cnr.GetOwnerID().GetValue(), ownerID.ToV2().GetValue()) { + if bytes.Equal(cnr.OwnerID().ToV2().GetValue(), ownerID.ToV2().GetValue()) { return acl.RoleUser, ownerKeyInBytes, nil } @@ -101,7 +101,7 @@ func requestOwner(req metaWithToken) (*owner.ID, *ecdsa.PublicKey, error) { return nil, nil, errors.Wrap(ErrMalformedRequest, "nil at body signature") } - key := crypto.UnmarshalPublicKey(bodySignature.GetKey()) + key := crypto.UnmarshalPublicKey(bodySignature.Key()) neo3wallet, err := owner.NEO3WalletFromPublicKey(key) if err != nil { return nil, nil, errors.Wrap(err, "can't create neo3 wallet") @@ -174,7 +174,7 @@ func lookupKeyInContainer( owner, cid []byte, cnr *container.Container) (bool, error) { - cnrNodes, err := nm.GetContainerNodes(netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy()), cid) + cnrNodes, err := nm.GetContainerNodes(cnr.PlacementPolicy(), cid) if err != nil { return false, err } diff --git a/pkg/services/object/acl/eacl/types.go b/pkg/services/object/acl/eacl/types.go index c2ec8ac8d..a75bf7bf0 100644 --- a/pkg/services/object/acl/eacl/types.go +++ b/pkg/services/object/acl/eacl/types.go @@ -18,8 +18,8 @@ type Storage interface { // Header is an interface of string key-value header. type Header interface { - GetKey() string - GetValue() string + Key() string + Value() string } // TypedHeaderSource is the interface that wraps diff --git a/pkg/services/object/acl/eacl/v2/eacl_test.go b/pkg/services/object/acl/eacl/v2/eacl_test.go index bb14cf161..0c6f9ff3f 100644 --- a/pkg/services/object/acl/eacl/v2/eacl_test.go +++ b/pkg/services/object/acl/eacl/v2/eacl_test.go @@ -40,7 +40,7 @@ func (s *testEACLStorage) GetEACL(id *container.ID) (*eacl.Table, error) { } func (s *testLocalStorage) Head(addr *objectSDK.Address) (*object.Object, error) { - require.True(s.t, addr.GetContainerID().Equal(addr.GetContainerID()) && addr.GetObjectID().Equal(addr.GetObjectID())) + require.True(s.t, addr.ContainerID().Equal(addr.ContainerID()) && addr.ObjectID().Equal(addr.ObjectID())) return s.obj, nil } @@ -139,7 +139,7 @@ func TestHeadRequest(t *testing.T) { obj: obj.Object(), } - cid := addr.GetContainerID() + cid := addr.ContainerID() unit := new(eacl2.ValidationUnit). WithContainerID(cid). WithOperation(eacl.OperationHead). diff --git a/pkg/services/object/acl/eacl/v2/headers.go b/pkg/services/object/acl/eacl/v2/headers.go index 6cf47f7b0..3076a1b03 100644 --- a/pkg/services/object/acl/eacl/v2/headers.go +++ b/pkg/services/object/acl/eacl/v2/headers.go @@ -3,6 +3,7 @@ package v2 import ( "fmt" + "github.com/nspcc-dev/neofs-api-go/pkg" eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" @@ -71,7 +72,7 @@ func requestHeaders(msg xHeaderSource) []eacl.Header { res := make([]eacl.Header, 0, len(xHdrs)) for i := range xHdrs { - res = append(res, xHdrs[i]) + res = append(res, pkg.NewXHeaderFromV2(xHdrs[i])) } return res diff --git a/pkg/services/object/acl/eacl/v2/object.go b/pkg/services/object/acl/eacl/v2/object.go index 2b824b4a2..c3e8481c0 100644 --- a/pkg/services/object/acl/eacl/v2/object.go +++ b/pkg/services/object/acl/eacl/v2/object.go @@ -15,11 +15,11 @@ type sysObjHdr struct { k, v string } -func (s *sysObjHdr) GetKey() string { +func (s *sysObjHdr) Key() string { return s.k } -func (s *sysObjHdr) GetValue() string { +func (s *sysObjHdr) Value() string { return s.v } @@ -48,27 +48,27 @@ func headersFromObject(obj *object.Object) []eacl.Header { // container ID &sysObjHdr{ k: acl.FilterObjectContainerID, - v: cidValue(obj.GetContainerID()), + v: cidValue(obj.ContainerID()), }, // owner ID &sysObjHdr{ k: acl.FilterObjectOwnerID, - v: ownerIDValue(obj.GetOwnerID()), + v: ownerIDValue(obj.OwnerID()), }, // creation epoch &sysObjHdr{ k: acl.FilterObjectCreationEpoch, - v: u64Value(obj.GetCreationEpoch()), + v: u64Value(obj.CreationEpoch()), }, // payload size &sysObjHdr{ k: acl.FilterObjectPayloadLength, - v: u64Value(obj.GetPayloadSize()), + v: u64Value(obj.PayloadSize()), }, // TODO: add others fields after neofs-api#84 ) - attrs := obj.GetAttributes() + attrs := obj.Attributes() hs := make([]eacl.Header, 0, len(attrs)) for i := range attrs { diff --git a/pkg/services/object/acl/eacl/validator.go b/pkg/services/object/acl/eacl/validator.go index fad0c9e26..9cb3c6d78 100644 --- a/pkg/services/object/acl/eacl/validator.go +++ b/pkg/services/object/acl/eacl/validator.go @@ -124,7 +124,7 @@ func matchFilters(hdrSrc TypedHeaderSource, filters []eacl.Filter) int { } // check header name - if header.GetKey() != filter.Key() { + if header.Key() != filter.Key() { continue } @@ -172,10 +172,10 @@ func targetMatches(unit *ValidationUnit, record eacl.Record) bool { // Maps match type to corresponding function. var mMatchFns = map[eacl.Match]func(Header, eacl.Filter) bool{ eacl.MatchStringEqual: func(header Header, filter eacl.Filter) bool { - return header.GetValue() == filter.Value() + return header.Value() == filter.Value() }, eacl.MatchStringNotEqual: func(header Header, filter eacl.Filter) bool { - return header.GetValue() != filter.Value() + return header.Value() != filter.Value() }, } diff --git a/pkg/services/object/delete/service.go b/pkg/services/object/delete/service.go index 94a9d928e..b2175cb4b 100644 --- a/pkg/services/object/delete/service.go +++ b/pkg/services/object/delete/service.go @@ -84,7 +84,7 @@ func (s *Service) Delete(ctx context.Context, prm *Prm) (*Response, error) { // content address storage (CAS) and one tombstone for several split // objects. if err := r.Init(new(putsvc.PutInitPrm). - WithObject(newTombstone(ownerID, prm.addr.GetContainerID())). + WithObject(newTombstone(ownerID, prm.addr.ContainerID())). WithCommonPrm(prm.common). WithTraverseOption(placement.WithoutSuccessTracking()), // broadcast tombstone, maybe one ); err != nil { @@ -108,9 +108,9 @@ func (s *Service) getRelations(ctx context.Context, prm *Prm) ([]*objectSDK.Addr var res []*objectSDK.Address if linking, err := s.hdrLinking.HeadRelation(ctx, prm.addr, prm.common); err != nil { - cid := prm.addr.GetContainerID() + cid := prm.addr.ContainerID() - for prev := prm.addr.GetObjectID(); prev != nil; { + for prev := prm.addr.ObjectID(); prev != nil; { addr := objectSDK.NewAddress() addr.SetObjectID(prev) addr.SetContainerID(cid) @@ -124,12 +124,12 @@ func (s *Service) getRelations(ctx context.Context, prm *Prm) ([]*objectSDK.Addr } hdr := headResult.Header() - id := hdr.GetID() - prev = hdr.GetPreviousID() + id := hdr.ID() + prev = hdr.PreviousID() if rightChild := headResult.RightChild(); rightChild != nil { - id = rightChild.GetID() - prev = rightChild.GetPreviousID() + id = rightChild.ID() + prev = rightChild.PreviousID() } addr.SetObjectID(id) @@ -137,20 +137,20 @@ func (s *Service) getRelations(ctx context.Context, prm *Prm) ([]*objectSDK.Addr res = append(res, addr) } } else { - childList := linking.GetChildren() + childList := linking.Children() res = make([]*objectSDK.Address, 0, len(childList)+2) // 1 for parent, 1 for linking for i := range childList { addr := objectSDK.NewAddress() addr.SetObjectID(childList[i]) - addr.SetContainerID(prm.addr.GetContainerID()) + addr.SetContainerID(prm.addr.ContainerID()) res = append(res, addr) } addr := objectSDK.NewAddress() - addr.SetObjectID(linking.GetID()) - addr.SetContainerID(prm.addr.GetContainerID()) + addr.SetObjectID(linking.ID()) + addr.SetContainerID(prm.addr.ContainerID()) res = append(res, addr) } diff --git a/pkg/services/object/head/distributed.go b/pkg/services/object/head/distributed.go index da5f6b9fb..235610170 100644 --- a/pkg/services/object/head/distributed.go +++ b/pkg/services/object/head/distributed.go @@ -37,7 +37,7 @@ func (h *distributedHeader) prepare(ctx context.Context, prm *Prm) error { } // get container to store the object - cnr, err := h.cnrSrc.Get(prm.addr.GetContainerID()) + cnr, err := h.cnrSrc.Get(prm.addr.ContainerID()) if err != nil { return errors.Wrapf(err, "(%T) could not get container by ID", h) } @@ -54,7 +54,7 @@ func (h *distributedHeader) prepare(ctx context.Context, prm *Prm) error { placement.SuccessAfter(1), // set identifier of the processing object - placement.ForObject(prm.addr.GetObjectID()), + placement.ForObject(prm.addr.ObjectID()), ) // create placement builder from network map diff --git a/pkg/services/object/head/relation.go b/pkg/services/object/head/relation.go index 933b76e56..da7b7510f 100644 --- a/pkg/services/object/head/relation.go +++ b/pkg/services/object/head/relation.go @@ -29,7 +29,7 @@ func (h *RelationHeader) HeadRelation(ctx context.Context, addr *objectSDK.Addre } a := objectSDK.NewAddress() - a.SetContainerID(addr.GetContainerID()) + a.SetContainerID(addr.ContainerID()) a.SetObjectID(id) r, err := h.svc.Head(ctx, new(Prm). diff --git a/pkg/services/object/head/service.go b/pkg/services/object/head/service.go index 4b658cef8..eeb1a3e2d 100644 --- a/pkg/services/object/head/service.go +++ b/pkg/services/object/head/service.go @@ -75,7 +75,7 @@ func (s *Service) Head(ctx context.Context, prm *Prm) (*Response, error) { } addr := objectSDK.NewAddress() - addr.SetContainerID(prm.addr.GetContainerID()) + addr.SetContainerID(prm.addr.ContainerID()) addr.SetObjectID(rightChildID) r, err = s.Head(ctx, new(Prm).WithAddress(addr).WithCommonPrm(prm.common)) diff --git a/pkg/services/object/put/distributed.go b/pkg/services/object/put/distributed.go index bcc51516d..1f64035e9 100644 --- a/pkg/services/object/put/distributed.go +++ b/pkg/services/object/put/distributed.go @@ -41,7 +41,7 @@ func (t *distributedTarget) Write(p []byte) (n int, err error) { func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { traverser, err := placement.NewTraverser( - append(t.traverseOpts, placement.ForObject(t.obj.GetID()))..., + append(t.traverseOpts, placement.ForObject(t.obj.ID()))..., ) if err != nil { return nil, errors.Wrapf(err, "(%T) could not create object placement traverser", t) @@ -59,7 +59,7 @@ func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { payload = append(payload, t.chunks[i]...) } - if err := t.fmt.ValidateContent(t.obj.GetType(), payload); err != nil { + if err := t.fmt.ValidateContent(t.obj.Type(), payload); err != nil { return nil, errors.Wrapf(err, "(%T) could not validate payload content", t) } @@ -108,5 +108,5 @@ loop: } return new(transformer.AccessIdentifiers). - WithSelfID(t.obj.GetID()), nil + WithSelfID(t.obj.ID()), nil } diff --git a/pkg/services/object/put/local.go b/pkg/services/object/put/local.go index cc0616485..b30275e98 100644 --- a/pkg/services/object/put/local.go +++ b/pkg/services/object/put/local.go @@ -18,7 +18,7 @@ type localTarget struct { func (t *localTarget) WriteHeader(obj *object.RawObject) error { t.obj = obj - t.payload = make([]byte, 0, obj.GetPayloadSize()) + t.payload = make([]byte, 0, obj.PayloadSize()) return nil } @@ -35,5 +35,5 @@ func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) { } return new(transformer.AccessIdentifiers). - WithSelfID(t.obj.GetID()), nil + WithSelfID(t.obj.ID()), nil } diff --git a/pkg/services/object/put/streamer.go b/pkg/services/object/put/streamer.go index d7558d45f..ab29331b2 100644 --- a/pkg/services/object/put/streamer.go +++ b/pkg/services/object/put/streamer.go @@ -96,7 +96,7 @@ func (p *Streamer) preparePrm(prm *PutInitPrm) error { } // get container to store the object - cnr, err := p.cnrSrc.Get(prm.hdr.GetContainerID()) + cnr, err := p.cnrSrc.Get(prm.hdr.ContainerID()) if err != nil { return errors.Wrapf(err, "(%T) could not get container by ID", p) } @@ -107,7 +107,7 @@ func (p *Streamer) preparePrm(prm *PutInitPrm) error { placement.ForContainer(cnr), // set identifier of the processing object - placement.ForObject(prm.hdr.GetID()), + placement.ForObject(prm.hdr.ID()), ) // create placement builder from network map diff --git a/pkg/services/object/put/validation.go b/pkg/services/object/put/validation.go index a384822a9..dd1bdb245 100644 --- a/pkg/services/object/put/validation.go +++ b/pkg/services/object/put/validation.go @@ -23,8 +23,8 @@ type validatingTarget struct { } func (t *validatingTarget) WriteHeader(obj *object.RawObject) error { - cs := obj.GetPayloadChecksum() - switch typ := cs.GetType(); typ { + cs := obj.PayloadChecksum() + switch typ := cs.Type(); typ { default: return errors.Errorf("(%T) unsupported payload checksum type %v", t, typ) case pkg.ChecksumSHA256: @@ -33,7 +33,7 @@ func (t *validatingTarget) WriteHeader(obj *object.RawObject) error { t.hash = tz.New() } - t.checksum = cs.GetSum() + t.checksum = cs.Sum() if err := t.fmt.Validate(obj.Object()); err != nil { return errors.Wrapf(err, "(%T) coult not validate object format", t) diff --git a/pkg/services/object/range/chain.go b/pkg/services/object/range/chain.go index 8b45ca9eb..000198e7c 100644 --- a/pkg/services/object/range/chain.go +++ b/pkg/services/object/range/chain.go @@ -35,14 +35,14 @@ type rangeChain struct { func newRangeTraverser(originSize uint64, rightElement *object.Object, rngSeek *objectSDK.Range) *rangeTraverser { right := &rangeChain{ bounds: &rangeBounds{ - left: originSize - rightElement.GetPayloadSize(), + left: originSize - rightElement.PayloadSize(), right: originSize, }, - id: rightElement.GetID(), + id: rightElement.ID(), } left := &rangeChain{ - id: rightElement.GetPreviousID(), + id: rightElement.PreviousID(), } left.next, right.prev = right, left @@ -83,12 +83,12 @@ func min(a, b uint64) uint64 { } func (c *rangeTraverser) pushHeader(obj *object.Object) { - id := obj.GetID() + id := obj.ID() if !id.Equal(c.chain.prev.id) { panic(fmt.Sprintf("(%T) unexpected identifier in header", c)) } - sz := obj.GetPayloadSize() + sz := obj.PayloadSize() c.chain.prev.bounds = &rangeBounds{ left: c.chain.bounds.left - sz, @@ -97,7 +97,7 @@ func (c *rangeTraverser) pushHeader(obj *object.Object) { c.chain = c.chain.prev - if prev := obj.GetPreviousID(); prev != nil { + if prev := obj.PreviousID(); prev != nil { c.chain.prev = &rangeChain{ next: c.chain, id: prev, diff --git a/pkg/services/object/range/local.go b/pkg/services/object/range/local.go index 5934a9dd1..f57b0fcbc 100644 --- a/pkg/services/object/range/local.go +++ b/pkg/services/object/range/local.go @@ -22,7 +22,7 @@ func (l *localRangeWriter) WriteTo(w io.Writer) (int64, error) { return 0, errors.Wrapf(err, "(%T) could not get object from local storage", l) } - payload := obj.GetPayload() + payload := obj.Payload() left := l.rng.GetOffset() right := left + l.rng.GetLength() diff --git a/pkg/services/object/range/service.go b/pkg/services/object/range/service.go index 459c74133..5d088e0f5 100644 --- a/pkg/services/object/range/service.go +++ b/pkg/services/object/range/service.go @@ -66,7 +66,7 @@ func (s *Service) GetRange(ctx context.Context, prm *Prm) (*Result, error) { origin := headResult.Header() - originSize := origin.GetPayloadSize() + originSize := origin.PayloadSize() if prm.full { prm.rng = new(object.Range) @@ -101,7 +101,7 @@ func (s *Service) GetRange(ctx context.Context, prm *Prm) (*Result, error) { func (s *Service) fillTraverser(ctx context.Context, prm *Prm, traverser *objutil.RangeTraverser) error { addr := object.NewAddress() - addr.SetContainerID(prm.addr.GetContainerID()) + addr.SetContainerID(prm.addr.ContainerID()) for { nextID, nextRng := traverser.Next() diff --git a/pkg/services/object/range/streamer.go b/pkg/services/object/range/streamer.go index e5a1cef83..54a95610c 100644 --- a/pkg/services/object/range/streamer.go +++ b/pkg/services/object/range/streamer.go @@ -81,7 +81,7 @@ func (p *streamer) switchToObject(id *object.ID) error { } // get container to read payload range - cnr, err := p.cnrSrc.Get(p.prm.addr.GetContainerID()) + cnr, err := p.cnrSrc.Get(p.prm.addr.ContainerID()) if err != nil { return errors.Wrapf(err, "(%T) could not get container by ID", p) } @@ -124,7 +124,7 @@ func (p *streamer) start() { defer close(p.ch) objAddr := object.NewAddress() - objAddr.SetContainerID(p.prm.addr.GetContainerID()) + objAddr.SetContainerID(p.prm.addr.ContainerID()) loop: for { diff --git a/pkg/services/object/rangehash/distributed.go b/pkg/services/object/rangehash/distributed.go index da956974e..79872cd6b 100644 --- a/pkg/services/object/rangehash/distributed.go +++ b/pkg/services/object/rangehash/distributed.go @@ -35,7 +35,7 @@ func (h *distributedHasher) prepare(ctx context.Context, prm *Prm) error { } // get container to read the object - cnr, err := h.cnrSrc.Get(prm.addr.GetContainerID()) + cnr, err := h.cnrSrc.Get(prm.addr.ContainerID()) if err != nil { return errors.Wrapf(err, "(%T) could not get container by ID", h) } @@ -52,7 +52,7 @@ func (h *distributedHasher) prepare(ctx context.Context, prm *Prm) error { placement.SuccessAfter(1), // set identifier of the processing object - placement.ForObject(prm.addr.GetObjectID()), + placement.ForObject(prm.addr.ObjectID()), ) // create placement builder from network map diff --git a/pkg/services/object/rangehash/local.go b/pkg/services/object/rangehash/local.go index 13b85c502..813e7d460 100644 --- a/pkg/services/object/rangehash/local.go +++ b/pkg/services/object/rangehash/local.go @@ -23,7 +23,7 @@ func (h *localHasher) hashRange(ctx context.Context, prm *Prm, handler func([][] return errors.Wrapf(err, "(%T) could not get object from local storage", h) } - payload := obj.GetPayload() + payload := obj.Payload() hashes := make([][]byte, 0, len(prm.rngs)) var hasher hash.Hash diff --git a/pkg/services/object/rangehash/service.go b/pkg/services/object/rangehash/service.go index 54980c90b..df2052f01 100644 --- a/pkg/services/object/rangehash/service.go +++ b/pkg/services/object/rangehash/service.go @@ -72,7 +72,7 @@ func (s *Service) GetRangeHash(ctx context.Context, prm *Prm) (*Response, error) origin := headResult.Header() - originSize := origin.GetPayloadSize() + originSize := origin.PayloadSize() var minLeft, maxRight uint64 for i := range prm.rngs { @@ -106,7 +106,7 @@ func (s *Service) GetRangeHash(ctx context.Context, prm *Prm) (*Response, error) func (s *Service) getHashes(ctx context.Context, prm *Prm, traverser *objutil.RangeTraverser) (*Response, error) { addr := object.NewAddress() - addr.SetContainerID(prm.addr.GetContainerID()) + addr.SetContainerID(prm.addr.ContainerID()) resp := &Response{ hashes: make([][]byte, 0, len(prm.rngs)), diff --git a/pkg/services/object/search/local.go b/pkg/services/object/search/local.go index d0075bf1b..7a221db09 100644 --- a/pkg/services/object/search/local.go +++ b/pkg/services/object/search/local.go @@ -30,7 +30,7 @@ func (s *localStream) stream(ctx context.Context, ch chan<- []*objectSDK.ID) err idList := make([]*objectSDK.ID, 0, len(addrList)) for i := range addrList { - idList = append(idList, addrList[i].GetObjectID()) + idList = append(idList, addrList[i].ObjectID()) } select { diff --git a/pkg/services/object/search/relation.go b/pkg/services/object/search/relation.go index af8dbd06c..95b55d971 100644 --- a/pkg/services/object/search/relation.go +++ b/pkg/services/object/search/relation.go @@ -21,7 +21,7 @@ var ErrRelationNotFound = errors.New("relation not found") func (s *RelationSearcher) SearchRelation(ctx context.Context, addr *object.Address, prm *util.CommonPrm) (*object.ID, error) { streamer, err := s.svc.Search(ctx, new(Prm). - WithContainerID(addr.GetContainerID()).WithCommonPrm(prm). + WithContainerID(addr.ContainerID()).WithCommonPrm(prm). WithSearchQuery(s.queryGenerator(addr)), ) if err != nil { @@ -65,7 +65,7 @@ func NewRightChildSearcher(svc *Service) *RelationSearcher { return &RelationSearcher{ svc: svc, queryGenerator: func(addr *object.Address) query.Query { - return queryV1.NewRightChildQuery(addr.GetObjectID()) + return queryV1.NewRightChildQuery(addr.ObjectID()) }, } } @@ -74,7 +74,7 @@ func NewLinkingSearcher(svc *Service) *RelationSearcher { return &RelationSearcher{ svc: svc, queryGenerator: func(addr *object.Address) query.Query { - return queryV1.NewLinkingQuery(addr.GetObjectID()) + return queryV1.NewLinkingQuery(addr.ObjectID()) }, } } diff --git a/pkg/services/object/util/chain.go b/pkg/services/object/util/chain.go index 46d28dfd6..cd8e224fb 100644 --- a/pkg/services/object/util/chain.go +++ b/pkg/services/object/util/chain.go @@ -29,14 +29,14 @@ type rangeChain struct { func NewRangeTraverser(originSize uint64, rightElement *object.Object, rngSeek *objectSDK.Range) *RangeTraverser { right := &rangeChain{ bounds: &rangeBounds{ - left: originSize - rightElement.GetPayloadSize(), + left: originSize - rightElement.PayloadSize(), right: originSize, }, - id: rightElement.GetID(), + id: rightElement.ID(), } left := &rangeChain{ - id: rightElement.GetPreviousID(), + id: rightElement.PreviousID(), } left.next, right.prev = right, left @@ -75,12 +75,12 @@ func min(a, b uint64) uint64 { } func (c *RangeTraverser) PushHeader(obj *object.Object) { - id := obj.GetID() + id := obj.ID() if !id.Equal(c.chain.prev.id) { panic(fmt.Sprintf("(%T) unexpected identifier in header", c)) } - sz := obj.GetPayloadSize() + sz := obj.PayloadSize() c.chain.prev.bounds = &rangeBounds{ left: c.chain.bounds.left - sz, @@ -89,7 +89,7 @@ func (c *RangeTraverser) PushHeader(obj *object.Object) { c.chain = c.chain.prev - if prev := obj.GetPreviousID(); prev != nil { + if prev := obj.PreviousID(); prev != nil { c.chain.prev = &rangeChain{ next: c.chain, id: prev, diff --git a/pkg/services/object_manager/gc/gc.go b/pkg/services/object_manager/gc/gc.go index 69290a96c..1f75870c3 100644 --- a/pkg/services/object_manager/gc/gc.go +++ b/pkg/services/object_manager/gc/gc.go @@ -116,8 +116,8 @@ func (gc *GC) Run(ctx context.Context) { ) } else { gc.log.Info("object removed", - zap.String("CID", stringifyCID(addr.GetContainerID())), - zap.String("ID", stringifyID(addr.GetObjectID())), + zap.String("CID", stringifyCID(addr.ContainerID())), + zap.String("ID", stringifyID(addr.ObjectID())), ) } } diff --git a/pkg/services/object_manager/placement/traverser.go b/pkg/services/object_manager/placement/traverser.go index a3b7f0464..d9ce2eef3 100644 --- a/pkg/services/object_manager/placement/traverser.go +++ b/pkg/services/object_manager/placement/traverser.go @@ -181,7 +181,7 @@ func UseBuilder(b Builder) Option { // ForContainer is a traversal container setting option. func ForContainer(cnr *container.Container) Option { return func(c *cfg) { - c.policy = netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy()) + c.policy = cnr.PlacementPolicy() c.addr.SetContainerID(container.CalculateID(cnr)) } } diff --git a/pkg/services/object_manager/transformer/fmt.go b/pkg/services/object_manager/transformer/fmt.go index 2bab28616..c44e9f95e 100644 --- a/pkg/services/object_manager/transformer/fmt.go +++ b/pkg/services/object_manager/transformer/fmt.go @@ -71,7 +71,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { var parID *objectSDK.ID - if par := f.obj.GetParent(); par != nil { + if par := f.obj.Parent(); par != nil { rawPar := objectSDK.NewRawFromV2(par.ToV2()) rawPar.SetSessionToken(f.prm.SessionToken) @@ -81,7 +81,7 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { return nil, errors.Wrap(err, "could not finalize parent object") } - parID = rawPar.GetID() + parID = rawPar.ID() f.obj.SetParent(rawPar.Object()) } @@ -99,6 +99,6 @@ func (f *formatter) Close() (*AccessIdentifiers, error) { } return new(AccessIdentifiers). - WithSelfID(f.obj.GetID()). + WithSelfID(f.obj.ID()). WithParentID(parID), nil } diff --git a/pkg/services/object_manager/transformer/transformer.go b/pkg/services/object_manager/transformer/transformer.go index e748644af..19ebdce7f 100644 --- a/pkg/services/object_manager/transformer/transformer.go +++ b/pkg/services/object_manager/transformer/transformer.go @@ -90,10 +90,10 @@ func (s *payloadSizeLimiter) initialize() { func fromObject(obj *object.RawObject) *object.RawObject { res := object.NewRaw() - res.SetContainerID(obj.GetContainerID()) - res.SetOwnerID(obj.GetOwnerID()) - res.SetAttributes(obj.GetAttributes()...) - res.SetType(obj.GetType()) + res.SetContainerID(obj.ContainerID()) + res.SetOwnerID(obj.OwnerID()) + res.SetAttributes(obj.Attributes()...) + res.SetType(obj.Type()) return res } @@ -207,7 +207,7 @@ func writeHashes(hashers []*payloadChecksumHasher) { } func (s *payloadSizeLimiter) initializeLinking() { - id := s.current.GetParentID() + id := s.current.ParentID() s.current = fromObject(s.current) s.current.SetParentID(id) diff --git a/pkg/services/policer/check.go b/pkg/services/policer/check.go index 11070cd3c..943df4857 100644 --- a/pkg/services/policer/check.go +++ b/pkg/services/policer/check.go @@ -13,7 +13,7 @@ import ( ) func (p *Policer) processObject(ctx context.Context, addr *object.Address) { - cnr, err := p.cnrSrc.Get(addr.GetContainerID()) + cnr, err := p.cnrSrc.Get(addr.ContainerID()) if err != nil { p.log.Error("could not get container", zap.String("error", err.Error()), @@ -22,7 +22,7 @@ func (p *Policer) processObject(ctx context.Context, addr *object.Address) { return } - policy := netmap.NewPlacementPolicyFromV2(cnr.GetPlacementPolicy()) + policy := cnr.PlacementPolicy() nn, err := p.placementBuilder.BuildPlacement(addr, policy) if err != nil {