pool: Introduce ape-manager methods #233

Merged
fyrchik merged 1 commit from aarifullin/frostfs-sdk-go:feat/pool_apemngr into master 2024-07-04 12:04:38 +00:00
2 changed files with 167 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import (
sessionv2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session" sessionv2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
@ -103,6 +104,18 @@ func (m *mockClient) containerSetEACL(context.Context, PrmContainerSetEACL) erro
return nil return nil
} }
func (c *mockClient) apeManagerAddChain(ctx context.Context, prm PrmAddAPEChain) error {
return nil
}
func (c *mockClient) apeManagerRemoveChain(ctx context.Context, prm PrmRemoveAPEChain) error {
return nil
}
func (c *mockClient) apeManagerListChains(ctx context.Context, prm PrmListAPEChains) ([]ape.Chain, error) {
return []ape.Chain{}, nil
}
func (m *mockClient) endpointInfo(ctx context.Context, _ prmEndpointInfo) (netmap.NodeInfo, error) { func (m *mockClient) endpointInfo(ctx context.Context, _ prmEndpointInfo) (netmap.NodeInfo, error) {
var ni netmap.NodeInfo var ni netmap.NodeInfo

View file

@ -15,6 +15,7 @@ import (
"time" "time"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/ape"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer"
sdkClient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" sdkClient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
@ -53,6 +54,12 @@ type client interface {
containerEACL(context.Context, PrmContainerEACL) (eacl.Table, error) containerEACL(context.Context, PrmContainerEACL) (eacl.Table, error)
// see clientWrapper.containerSetEACL. // see clientWrapper.containerSetEACL.
containerSetEACL(context.Context, PrmContainerSetEACL) error containerSetEACL(context.Context, PrmContainerSetEACL) error
// see clientWrapper.apeManagerAddChain.
apeManagerAddChain(context.Context, PrmAddAPEChain) error
// see clientWrapper.apeManagerRemoveChain.
apeManagerRemoveChain(context.Context, PrmRemoveAPEChain) error
// see clientWrapper.apeManagerListChains.
apeManagerListChains(context.Context, PrmListAPEChains) ([]ape.Chain, error)
// see clientWrapper.endpointInfo. // see clientWrapper.endpointInfo.
endpointInfo(context.Context, prmEndpointInfo) (netmap.NodeInfo, error) endpointInfo(context.Context, prmEndpointInfo) (netmap.NodeInfo, error)
// see clientWrapper.networkInfo. // see clientWrapper.networkInfo.
@ -169,6 +176,9 @@ const (
methodObjectHead methodObjectHead
methodObjectRange methodObjectRange
methodSessionCreate methodSessionCreate
methodAPEManagerAddChain
methodAPEManagerRemoveChain
methodAPEManagerListChains
Review
Please add these method in NodeStatistics too https://git.frostfs.info/TrueCloudLab/frostfs-sdk-go/src/branch/master/pool/statistic.go
Review

FYI @aarifullin , please make a separate PR, want to merge this now

FYI @aarifullin , please make a separate PR, want to merge this now
methodLast methodLast
) )
@ -207,6 +217,12 @@ func (m MethodIndex) String() string {
return "objectRange" return "objectRange"
case methodSessionCreate: case methodSessionCreate:
return "sessionCreate" return "sessionCreate"
case methodAPEManagerAddChain:
return "apeManagerAddChain"
case methodAPEManagerRemoveChain:
return "apeManagerRemoveChain"
case methodAPEManagerListChains:
return "apeManagerListChains"
case methodLast: case methodLast:
return "it's a system name rather than a method" return "it's a system name rather than a method"
default: default:
@ -641,6 +657,83 @@ func (c *clientWrapper) containerSetEACL(ctx context.Context, prm PrmContainerSe
return nil return nil
} }
// apeManagerAddChain invokes sdkClient.APEManagerAddChain and parse response status to error.
func (c *clientWrapper) apeManagerAddChain(ctx context.Context, prm PrmAddAPEChain) error {
cl, err := c.getClient()
if err != nil {
return err
}
cliPrm := sdkClient.PrmAPEManagerAddChain{
ChainTarget: prm.Target,
Chain: prm.Chain,
}
start := time.Now()
res, err := cl.APEManagerAddChain(ctx, cliPrm)
c.incRequests(time.Since(start), methodAPEManagerAddChain)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return fmt.Errorf("add chain error: %w", err)
}
return nil
}
// apeManagerRemoveChain invokes sdkClient.APEManagerRemoveChain and parse response status to error.
func (c *clientWrapper) apeManagerRemoveChain(ctx context.Context, prm PrmRemoveAPEChain) error {
cl, err := c.getClient()
if err != nil {
return err
}
cliPrm := sdkClient.PrmAPEManagerRemoveChain{
ChainTarget: prm.Target,
ChainID: prm.ChainID,
}
start := time.Now()
res, err := cl.APEManagerRemoveChain(ctx, cliPrm)
c.incRequests(time.Since(start), methodAPEManagerRemoveChain)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return fmt.Errorf("remove chain error: %w", err)
}
return nil
}
// apeManagerListChains invokes sdkClient.APEManagerListChains. Returns chains and parsed response status to error.
func (c *clientWrapper) apeManagerListChains(ctx context.Context, prm PrmListAPEChains) ([]ape.Chain, error) {
cl, err := c.getClient()
if err != nil {
return nil, err
}
cliPrm := sdkClient.PrmAPEManagerListChains{
ChainTarget: prm.Target,
}
start := time.Now()
res, err := cl.APEManagerListChains(ctx, cliPrm)
c.incRequests(time.Since(start), methodAPEManagerListChains)
var st apistatus.Status
if res != nil {
st = res.Status()
}
if err = c.handleError(ctx, st, err); err != nil {
return nil, fmt.Errorf("list chains error: %w", err)
}
return res.Chains, nil
}
// endpointInfo invokes sdkClient.EndpointInfo parse response status to error and return result as is. // endpointInfo invokes sdkClient.EndpointInfo parse response status to error and return result as is.
func (c *clientWrapper) endpointInfo(ctx context.Context, _ prmEndpointInfo) (netmap.NodeInfo, error) { func (c *clientWrapper) endpointInfo(ctx context.Context, _ prmEndpointInfo) (netmap.NodeInfo, error) {
cl, err := c.getClient() cl, err := c.getClient()
@ -1723,6 +1816,22 @@ type PrmContainerSetEACL struct {
WaitParams *WaitParams WaitParams *WaitParams
} }
type PrmAddAPEChain struct {
Target ape.ChainTarget
Chain ape.Chain
}
type PrmRemoveAPEChain struct {
Target ape.ChainTarget
ChainID ape.ChainID
}
type PrmListAPEChains struct {
Target ape.ChainTarget
}
// SetTable sets structure of container's extended ACL to be used as a // SetTable sets structure of container's extended ACL to be used as a
// parameter of the base client's operation. // parameter of the base client's operation.
// //
@ -2727,6 +2836,51 @@ func (p *Pool) SetEACL(ctx context.Context, prm PrmContainerSetEACL) error {
return nil return nil
} }
// AddAPEChain sends a request to set APE chain rules for a target (basically, for a container).
func (p *Pool) AddAPEChain(ctx context.Context, prm PrmAddAPEChain) error {
cp, err := p.connection()
if err != nil {
return err
}
err = cp.apeManagerAddChain(ctx, prm)
if err != nil {
return fmt.Errorf("add ape chain via client '%s': %w", cp.address(), err)
}
return nil
}
// RemoveAPEChain sends a request to remove APE chain rules for a target.
func (p *Pool) RemoveAPEChain(ctx context.Context, prm PrmRemoveAPEChain) error {
cp, err := p.connection()
if err != nil {
return err
}
err = cp.apeManagerRemoveChain(ctx, prm)
if err != nil {
return fmt.Errorf("remove ape chain via client '%s': %w", cp.address(), err)
}
return nil
}
// ListAPEChains sends a request to list APE chains rules for a target.
func (p *Pool) ListAPEChains(ctx context.Context, prm PrmListAPEChains) ([]ape.Chain, error) {
cp, err := p.connection()
if err != nil {
return nil, err
}
chains, err := cp.apeManagerListChains(ctx, prm)
if err != nil {
return nil, fmt.Errorf("list ape chains via client '%s': %w", cp.address(), err)
}
return chains, nil
}
// Balance requests current balance of the FrostFS account. // Balance requests current balance of the FrostFS account.
// //
// Main return value MUST NOT be processed on an erroneous return. // Main return value MUST NOT be processed on an erroneous return.