From be28b89312fe7972655e746eef813ce4f20dd797 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Thu, 3 Aug 2023 12:11:14 +0300 Subject: [PATCH] [#121] pool: Make PrmContainerDelete fields public * Refactor client PrmContainerDelete usage * Introduce WaitParams CheckValidity method Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- pool/pool.go | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index 3fb4e9e5..31bf84fc 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -487,10 +487,9 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel return err } - var cliPrm sdkClient.PrmContainerDelete - cliPrm.SetContainer(prm.cnrID) - if prm.stokenSet { - cliPrm.WithinSession(prm.stoken) + cliPrm := sdkClient.PrmContainerDelete{ + ContainerID: &prm.ContainerID, + Session: prm.Session, } start := time.Now() @@ -504,11 +503,14 @@ func (c *clientWrapper) containerDelete(ctx context.Context, prm PrmContainerDel return fmt.Errorf("container delete on client: %w", err) } - if !prm.waitParamsSet { - prm.waitParams.setDefaults() + if prm.WaitParams == nil { + prm.WaitParams = defaultWaitParams() + } + if err := prm.WaitParams.CheckValidity(); err != nil { + return fmt.Errorf("invalid wait parameters: %w", err) } - return waitForContainerRemoved(ctx, c, &prm.cnrID, &prm.waitParams) + return waitForContainerRemoved(ctx, c, &prm.ContainerID, prm.WaitParams) } // containerEACL invokes sdkClient.ContainerEACL parse response status to error and return result as is. @@ -1236,6 +1238,17 @@ func (x *WaitParams) checkForPositive() { } } +// CheckForValid checks if all wait params are non-negative. +func (waitPrm *WaitParams) CheckValidity() error { + if waitPrm.timeout <= 0 { + return errors.New("timeout cannot be negative") + } + if waitPrm.pollInterval <= 0 { + return errors.New("poll interval cannot be negative") + } + return nil +} + type prmContext struct { defaultSession bool verb session.ObjectVerb @@ -1467,33 +1480,35 @@ func (x *PrmContainerList) SetOwnerID(ownerID user.ID) { // PrmContainerDelete groups parameters of DeleteContainer operation. type PrmContainerDelete struct { - cnrID cid.ID + ContainerID cid.ID - stoken session.Container - stokenSet bool + Session *session.Container - waitParams WaitParams - waitParamsSet bool + WaitParams *WaitParams } // SetContainerID specifies identifier of the FrostFS container to be removed. +// +// Deprecated: Use PrmContainerDelete.ContainerID instead. func (x *PrmContainerDelete) SetContainerID(cnrID cid.ID) { - x.cnrID = cnrID + x.ContainerID = cnrID } // SetSessionToken specifies session within which operation should be performed. +// +// Deprecated: Use PrmContainerDelete.Session instead. func (x *PrmContainerDelete) SetSessionToken(token session.Container) { - x.stoken = token - x.stokenSet = true + x.Session = &token } // SetWaitParams specifies timeout params to complete operation. // If not provided the default one will be used. // Panics if any of the wait params isn't positive. +// +// Deprecated: Use PrmContainerDelete.WaitParams instead. func (x *PrmContainerDelete) SetWaitParams(waitParams WaitParams) { waitParams.checkForPositive() - x.waitParams = waitParams - x.waitParamsSet = true + x.WaitParams = &waitParams } // PrmContainerEACL groups parameters of GetEACL operation.