forked from TrueCloudLab/frostfs-sdk-go
[#105] pool: Add balance command
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
b1770ecb92
commit
2fd5802c48
1 changed files with 26 additions and 0 deletions
26
pool/pool.go
26
pool/pool.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/accounting"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/client"
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
"github.com/nspcc-dev/neofs-sdk-go/container"
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
||||||
|
@ -122,6 +123,7 @@ func (pb *Builder) Build(ctx context.Context, options *BuilderOptions) (Pool, er
|
||||||
type Pool interface {
|
type Pool interface {
|
||||||
Object
|
Object
|
||||||
Container
|
Container
|
||||||
|
Accounting
|
||||||
Connection() (client.Client, *session.Token, error)
|
Connection() (client.Client, *session.Token, error)
|
||||||
OwnerID() *owner.ID
|
OwnerID() *owner.ID
|
||||||
WaitForContainerPresence(context.Context, *cid.ID, *ContainerPollingParams) error
|
WaitForContainerPresence(context.Context, *cid.ID, *ContainerPollingParams) error
|
||||||
|
@ -149,6 +151,10 @@ type Container interface {
|
||||||
AnnounceContainerUsedSpace(ctx context.Context, announce []container.UsedSpaceAnnouncement, opts ...CallOption) error
|
AnnounceContainerUsedSpace(ctx context.Context, announce []container.UsedSpaceAnnouncement, opts ...CallOption) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Accounting interface {
|
||||||
|
Balance(ctx context.Context, owner *owner.ID, opts ...CallOption) (*accounting.Decimal, error)
|
||||||
|
}
|
||||||
|
|
||||||
type clientPack struct {
|
type clientPack struct {
|
||||||
client client.Client
|
client client.Client
|
||||||
healthy bool
|
healthy bool
|
||||||
|
@ -891,6 +897,26 @@ func (p *pool) AnnounceContainerUsedSpace(ctx context.Context, announce []contai
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *pool) Balance(ctx context.Context, o *owner.ID, opts ...CallOption) (*accounting.Decimal, error) {
|
||||||
|
cfg := cfgFromOpts(opts...)
|
||||||
|
cp, options, err := p.conn(ctx, cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := cp.client.GetBalance(ctx, o, options...)
|
||||||
|
if err == nil {
|
||||||
|
// reflect status failures in err
|
||||||
|
err = apistatus.ErrFromStatus(res.Status())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Amount(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollParams *ContainerPollingParams) error {
|
func (p *pool) WaitForContainerPresence(ctx context.Context, cid *cid.ID, pollParams *ContainerPollingParams) error {
|
||||||
conn, _, err := p.Connection()
|
conn, _, err := p.Connection()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue