forked from TrueCloudLab/frostfs-sdk-go
[#131] client: Switch ResolveFrostFSFailures to DontResolveFrostFSFailures option
Signed-off-by: Egor Olefirenko <egor.olefirenko892@gmail.com>
This commit is contained in:
parent
ac8fc6d440
commit
16aec65709
17 changed files with 58 additions and 58 deletions
|
@ -42,7 +42,7 @@ Contains client for working with FrostFS.
|
||||||
```go
|
```go
|
||||||
var prmInit client.PrmInit
|
var prmInit client.PrmInit
|
||||||
prmInit.SetDefaultPrivateKey(key) // private key for request signing
|
prmInit.SetDefaultPrivateKey(key) // private key for request signing
|
||||||
prmInit.ResolveFrostFSFailures() // enable erroneous status parsing
|
prmInit.DontResolveFrostFSFailures() // disable erroneous status parsing
|
||||||
|
|
||||||
var c client.Client
|
var c client.Client
|
||||||
c.Init(prmInit)
|
c.Init(prmInit)
|
||||||
|
@ -77,8 +77,8 @@ if needed and perform any desired action. In the case above we may want to repor
|
||||||
these details to the user as well as retry an operation, possibly with different parameters.
|
these details to the user as well as retry an operation, possibly with different parameters.
|
||||||
Status wire-format is extendable and each node can report any set of details it wants.
|
Status wire-format is extendable and each node can report any set of details it wants.
|
||||||
The set of reserved status codes can be found in
|
The set of reserved status codes can be found in
|
||||||
[FrostFS API](https://git.frostfs.info/TrueCloudLab/frostfs-api/src/branch/master/status/types.proto). There is also
|
[FrostFS API](https://git.frostfs.info/TrueCloudLab/frostfs-api/src/branch/master/status/types.proto).
|
||||||
a `client.PrmInit.ResolveFrostFSFailures()` to seamlessly convert erroneous statuses into Go error type.
|
Use `client.PrmInit.DontResolveFrostFSFailures()` to avoid returning erroneous statuses as Go built-in errors.
|
||||||
|
|
||||||
### policy
|
### policy
|
||||||
Contains helpers allowing conversion of placing policy from/to JSON representation
|
Contains helpers allowing conversion of placing policy from/to JSON representation
|
||||||
|
|
|
@ -64,9 +64,9 @@ func (x ResBalanceGet) Amount() accounting.Decimal {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`,
|
// Any client's internal or transport errors are returned as `error`,
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmBalanceGet docs).
|
// Returns an error if parameters are set incorrectly (see PrmBalanceGet docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -144,7 +144,7 @@ func (c *Client) Close() error {
|
||||||
//
|
//
|
||||||
// See also Init.
|
// See also Init.
|
||||||
type PrmInit struct {
|
type PrmInit struct {
|
||||||
resolveFrostFSErrors bool
|
dontResolveFrostFSErrors bool
|
||||||
|
|
||||||
key ecdsa.PrivateKey
|
key ecdsa.PrivateKey
|
||||||
|
|
||||||
|
@ -161,12 +161,12 @@ func (x *PrmInit) SetDefaultPrivateKey(key ecdsa.PrivateKey) {
|
||||||
x.key = key
|
x.key = key
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveFrostFSFailures makes the Client to resolve failure statuses of the
|
// DontResolveFrostFSFailures makes the Client to preserve failure statuses of the
|
||||||
// FrostFS protocol into Go built-in errors. These errors are returned from
|
// FrostFS protocol only in resulting structure (see corresponding Res* docs).
|
||||||
// each protocol operation. By default, statuses aren't resolved and written
|
// These errors are returned from each protocol operation. By default, statuses
|
||||||
// to the resulting structure (see corresponding Res* docs).
|
// are resolved and returned as a Go built-in errors.
|
||||||
func (x *PrmInit) ResolveFrostFSFailures() {
|
func (x *PrmInit) DontResolveFrostFSFailures() {
|
||||||
x.resolveFrostFSErrors = true
|
x.dontResolveFrostFSErrors = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetResponseInfoCallback makes the Client to pass ResponseMetaInfo from each
|
// SetResponseInfoCallback makes the Client to pass ResponseMetaInfo from each
|
||||||
|
|
|
@ -119,7 +119,7 @@ func (c *Client) processResponse(resp responseV2) (apistatus.Status, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
st := apistatus.FromStatusV2(resp.GetMetaHeader().GetStatus())
|
st := apistatus.FromStatusV2(resp.GetMetaHeader().GetStatus())
|
||||||
if c.prm.resolveFrostFSErrors {
|
if !c.prm.dontResolveFrostFSErrors {
|
||||||
return st, apistatus.ErrFromStatus(st)
|
return st, apistatus.ErrFromStatus(st)
|
||||||
}
|
}
|
||||||
return st, nil
|
return st, nil
|
||||||
|
|
|
@ -101,9 +101,9 @@ type ResContainerDelete struct {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
||||||
// The required time is also not predictable.
|
// The required time is also not predictable.
|
||||||
|
|
|
@ -68,9 +68,9 @@ func (x ResContainerEACL) Table() eacl.Table {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmContainerEACL docs).
|
// Returns an error if parameters are set incorrectly (see PrmContainerEACL docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -71,9 +71,9 @@ func (x ResContainerGet) Container() container.Container {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmContainerGet docs).
|
// Returns an error if parameters are set incorrectly (see PrmContainerGet docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -65,9 +65,9 @@ func (x ResContainerList) Containers() []cid.ID {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmContainerList docs).
|
// Returns an error if parameters are set incorrectly (see PrmContainerList docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -110,9 +110,9 @@ func (x ResContainerPut) ID() cid.ID {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
||||||
// The required time is also not predictable.
|
// The required time is also not predictable.
|
||||||
|
|
|
@ -101,9 +101,9 @@ type ResContainerSetEACL struct {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
||||||
// The required time is also not predictable.
|
// The required time is also not predictable.
|
||||||
|
|
|
@ -57,9 +57,9 @@ type ResAnnounceSpace struct {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
// Operation is asynchronous and no guaranteed even in the absence of errors.
|
||||||
// The required time is also not predictable.
|
// The required time is also not predictable.
|
||||||
|
|
|
@ -53,9 +53,9 @@ func (x ResEndpointInfo) NodeInfo() netmap.NodeInfo {
|
||||||
// Method can be used as a health check to see if node is alive and responds to requests.
|
// Method can be used as a health check to see if node is alive and responds to requests.
|
||||||
//
|
//
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmEndpointInfo docs).
|
// Returns an error if parameters are set incorrectly (see PrmEndpointInfo docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
@ -140,9 +140,9 @@ func (x ResNetworkInfo) Info() netmap.NetworkInfo {
|
||||||
// NetworkInfo requests information about the FrostFS network of which the remote server is a part.
|
// NetworkInfo requests information about the FrostFS network of which the remote server is a part.
|
||||||
//
|
//
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmNetworkInfo docs).
|
// Returns an error if parameters are set incorrectly (see PrmNetworkInfo docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
@ -204,9 +204,9 @@ func (x ResNetMapSnapshot) NetMap() netmap.NetMap {
|
||||||
// NetMapSnapshot requests current network view of the remote server.
|
// NetMapSnapshot requests current network view of the remote server.
|
||||||
//
|
//
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly.
|
// Returns an error if parameters are set incorrectly.
|
||||||
// Context is required and MUST NOT be nil. It is used for network communication.
|
// Context is required and MUST NOT be nil. It is used for network communication.
|
||||||
|
|
|
@ -112,9 +112,9 @@ func (prm *PrmObjectDelete) buildRequest(c *Client) (*v2object.DeleteRequest, er
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`,
|
// Any client's internal or transport errors are returned as `error`,
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmObjectDelete docs).
|
// Returns an error if parameters are set incorrectly (see PrmObjectDelete docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -444,9 +444,9 @@ func (prm *PrmObjectHead) buildRequest(c *Client) (*v2object.HeadRequest, error)
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`,
|
// Any client's internal or transport errors are returned as `error`,
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmObjectHead docs).
|
// Returns an error if parameters are set incorrectly (see PrmObjectHead docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -152,9 +152,9 @@ func (prm *PrmObjectHash) buildRequest(c *Client) (*v2object.GetRangeHashRequest
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`,
|
// Any client's internal or transport errors are returned as `error`,
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmObjectHash docs).
|
// Returns an error if parameters are set incorrectly (see PrmObjectHash docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (it *internalTarget) putAsStream(ctx context.Context, o *object.Object) err
|
||||||
wrt.WritePayloadChunk(ctx, o.Payload())
|
wrt.WritePayloadChunk(ctx, o.Payload())
|
||||||
}
|
}
|
||||||
it.res, err = wrt.Close(ctx)
|
it.res, err = wrt.Close(ctx)
|
||||||
if err == nil && !it.client.prm.resolveFrostFSErrors && !apistatus.IsSuccessful(it.res.st) {
|
if err == nil && it.client.prm.dontResolveFrostFSErrors && !apistatus.IsSuccessful(it.res.st) {
|
||||||
err = apistatus.ErrFromStatus(it.res.st)
|
err = apistatus.ErrFromStatus(it.res.st)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -110,7 +110,7 @@ func (it *internalTarget) tryPutSingle(ctx context.Context, o *object.Object) (b
|
||||||
statusRes: res.statusRes,
|
statusRes: res.statusRes,
|
||||||
obj: id,
|
obj: id,
|
||||||
}
|
}
|
||||||
if !it.client.prm.resolveFrostFSErrors && !apistatus.IsSuccessful(it.res.st) {
|
if it.client.prm.dontResolveFrostFSErrors && !apistatus.IsSuccessful(it.res.st) {
|
||||||
return true, apistatus.ErrFromStatus(it.res.st)
|
return true, apistatus.ErrFromStatus(it.res.st)
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|
|
@ -89,9 +89,9 @@ func (x ResSessionCreate) PublicKey() []byte {
|
||||||
//
|
//
|
||||||
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
// Exactly one return value is non-nil. By default, server status is returned in res structure.
|
||||||
// Any client's internal or transport errors are returned as `error`.
|
// Any client's internal or transport errors are returned as `error`.
|
||||||
// If PrmInit.ResolveFrostFSFailures has been called, unsuccessful
|
// If PrmInit.DontResolveFrostFSFailures has been called, unsuccessful
|
||||||
// FrostFS status codes are returned as `error`, otherwise, are included
|
// FrostFS status codes are included in the returned result structure,
|
||||||
// in the returned result structure.
|
// otherwise, are also returned as `error`.
|
||||||
//
|
//
|
||||||
// Returns an error if parameters are set incorrectly (see PrmSessionCreate docs).
|
// Returns an error if parameters are set incorrectly (see PrmSessionCreate docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
|
|
Loading…
Reference in a new issue