[#189] client: Make PrmDial fields public
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
e91d40e250
commit
3787477133
4 changed files with 51 additions and 45 deletions
|
@ -78,31 +78,22 @@ func (c *Client) Init(prm PrmInit) {
|
||||||
//
|
//
|
||||||
// See also Init / Close.
|
// See also Init / Close.
|
||||||
func (c *Client) Dial(ctx context.Context, prm PrmDial) error {
|
func (c *Client) Dial(ctx context.Context, prm PrmDial) error {
|
||||||
if prm.endpoint == "" {
|
if prm.Endpoint == "" {
|
||||||
return errorServerAddrUnset
|
return errorServerAddrUnset
|
||||||
}
|
}
|
||||||
|
|
||||||
if prm.timeoutDialSet {
|
if prm.DialTimeout <= 0 {
|
||||||
if prm.timeoutDial <= 0 {
|
prm.DialTimeout = defaultDialTimeout
|
||||||
return errorNonPositiveTimeout
|
|
||||||
}
|
}
|
||||||
} else {
|
if prm.StreamTimeout <= 0 {
|
||||||
prm.timeoutDial = 5 * time.Second
|
prm.StreamTimeout = defaultStreamTimeout
|
||||||
}
|
|
||||||
|
|
||||||
if prm.streamTimeoutSet {
|
|
||||||
if prm.streamTimeout <= 0 {
|
|
||||||
return errorNonPositiveTimeout
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
prm.streamTimeout = 10 * time.Second
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.c = *client.New(append(
|
c.c = *client.New(append(
|
||||||
client.WithNetworkURIAddress(prm.endpoint, prm.tlsConfig),
|
client.WithNetworkURIAddress(prm.Endpoint, prm.TLSConfig),
|
||||||
client.WithDialTimeout(prm.timeoutDial),
|
client.WithDialTimeout(prm.DialTimeout),
|
||||||
client.WithRWTimeout(prm.streamTimeout),
|
client.WithRWTimeout(prm.StreamTimeout),
|
||||||
client.WithGRPCDialOptions(prm.dialOptions),
|
client.WithGRPCDialOptions(prm.GRPCDialOptions),
|
||||||
)...)
|
)...)
|
||||||
|
|
||||||
c.setFrostFSAPIServer((*coreServer)(&c.c))
|
c.setFrostFSAPIServer((*coreServer)(&c.c))
|
||||||
|
@ -185,21 +176,26 @@ func (x *PrmInit) SetResponseInfoCallback(f func(ResponseMetaInfo) error) {
|
||||||
x.ResponseInfoCallback = f
|
x.ResponseInfoCallback = f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultDialTimeout = 5 * time.Second
|
||||||
|
defaultStreamTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// PrmDial groups connection parameters for the Client.
|
// PrmDial groups connection parameters for the Client.
|
||||||
//
|
//
|
||||||
// See also Dial.
|
// See also Dial.
|
||||||
type PrmDial struct {
|
type PrmDial struct {
|
||||||
endpoint string
|
Endpoint string
|
||||||
|
|
||||||
tlsConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
timeoutDialSet bool
|
// If DialTimeout is non-positive, then it's set to defaultDialTimeout.
|
||||||
timeoutDial time.Duration
|
DialTimeout time.Duration
|
||||||
|
|
||||||
streamTimeoutSet bool
|
// If StreamTimeout is non-positive, then it's set to defaultStreamTimeout.
|
||||||
streamTimeout time.Duration
|
StreamTimeout time.Duration
|
||||||
|
|
||||||
dialOptions []grpc.DialOption
|
GRPCDialOptions []grpc.DialOption
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetServerURI sets server URI in the FrostFS network.
|
// SetServerURI sets server URI in the FrostFS network.
|
||||||
|
@ -215,33 +211,41 @@ type PrmDial struct {
|
||||||
// grpcs
|
// grpcs
|
||||||
//
|
//
|
||||||
// See also SetTLSConfig.
|
// See also SetTLSConfig.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmDial.Endpoint instead.
|
||||||
func (x *PrmDial) SetServerURI(endpoint string) {
|
func (x *PrmDial) SetServerURI(endpoint string) {
|
||||||
x.endpoint = endpoint
|
x.Endpoint = endpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTLSConfig sets tls.Config to open TLS client connection
|
// SetTLSConfig sets tls.Config to open TLS client connection
|
||||||
// to the FrostFS server. Nil (default) means insecure connection.
|
// to the FrostFS server. Nil (default) means insecure connection.
|
||||||
//
|
//
|
||||||
// See also SetServerURI.
|
// See also SetServerURI.
|
||||||
|
//
|
||||||
|
// Depreacted: Use PrmDial.TLSConfig instead.
|
||||||
func (x *PrmDial) SetTLSConfig(tlsConfig *tls.Config) {
|
func (x *PrmDial) SetTLSConfig(tlsConfig *tls.Config) {
|
||||||
x.tlsConfig = tlsConfig
|
x.TLSConfig = tlsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTimeout sets the timeout for connection to be established.
|
// SetTimeout sets the timeout for connection to be established.
|
||||||
// MUST BE positive. If not called, 5s timeout will be used by default.
|
// MUST BE positive. If not called, 5s timeout will be used by default.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmDial.DialTimeout instead.
|
||||||
func (x *PrmDial) SetTimeout(timeout time.Duration) {
|
func (x *PrmDial) SetTimeout(timeout time.Duration) {
|
||||||
x.timeoutDialSet = true
|
x.DialTimeout = timeout
|
||||||
x.timeoutDial = timeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStreamTimeout sets the timeout for individual operations in streaming RPC.
|
// SetStreamTimeout sets the timeout for individual operations in streaming RPC.
|
||||||
// MUST BE positive. If not called, 10s timeout will be used by default.
|
// MUST BE positive. If not called, 10s timeout will be used by default.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmDial.StreamTimeout instead.
|
||||||
func (x *PrmDial) SetStreamTimeout(timeout time.Duration) {
|
func (x *PrmDial) SetStreamTimeout(timeout time.Duration) {
|
||||||
x.streamTimeoutSet = true
|
x.StreamTimeout = timeout
|
||||||
x.streamTimeout = timeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetGRPCDialOptions sets the gRPC dial options for new gRPC client connection.
|
// SetGRPCDialOptions sets the gRPC dial options for new gRPC client connection.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmDial.GRPCDialOptions instead.
|
||||||
func (x *PrmDial) SetGRPCDialOptions(opts ...grpc.DialOption) {
|
func (x *PrmDial) SetGRPCDialOptions(opts ...grpc.DialOption) {
|
||||||
x.dialOptions = opts
|
x.GRPCDialOptions = opts
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,9 @@ func TestClient_DialContext(t *testing.T) {
|
||||||
var c Client
|
var c Client
|
||||||
|
|
||||||
// try to connect to any host
|
// try to connect to any host
|
||||||
var prm PrmDial
|
prm := PrmDial{
|
||||||
prm.SetServerURI("localhost:8080")
|
Endpoint: "localhost:8080",
|
||||||
|
}
|
||||||
|
|
||||||
assert := func(ctx context.Context, errExpected error) {
|
assert := func(ctx context.Context, errExpected error) {
|
||||||
// expect particular context error according to Dial docs
|
// expect particular context error according to Dial docs
|
||||||
|
|
|
@ -50,7 +50,6 @@ var (
|
||||||
errorMissingObject = errors.New("missing object")
|
errorMissingObject = errors.New("missing object")
|
||||||
errorAccountNotSet = errors.New("account not set")
|
errorAccountNotSet = errors.New("account not set")
|
||||||
errorServerAddrUnset = errors.New("server address is unset or empty")
|
errorServerAddrUnset = errors.New("server address is unset or empty")
|
||||||
errorNonPositiveTimeout = errors.New("non-positive timeout")
|
|
||||||
errorEACLTableNotSet = errors.New("eACL table not set")
|
errorEACLTableNotSet = errors.New("eACL table not set")
|
||||||
errorMissingAnnouncements = errors.New("missing announcements")
|
errorMissingAnnouncements = errors.New("missing announcements")
|
||||||
errorZeroRangeLength = errors.New("zero range length")
|
errorZeroRangeLength = errors.New("zero range length")
|
||||||
|
|
22
pool/pool.go
22
pool/pool.go
|
@ -341,11 +341,12 @@ func (c *clientWrapper) dial(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var prmDial sdkClient.PrmDial
|
prmDial := sdkClient.PrmDial{
|
||||||
prmDial.SetServerURI(c.prm.address)
|
Endpoint: c.prm.address,
|
||||||
prmDial.SetTimeout(c.prm.dialTimeout)
|
DialTimeout: c.prm.dialTimeout,
|
||||||
prmDial.SetStreamTimeout(c.prm.streamTimeout)
|
StreamTimeout: c.prm.streamTimeout,
|
||||||
prmDial.SetGRPCDialOptions(c.prm.dialOptions...)
|
GRPCDialOptions: c.prm.dialOptions,
|
||||||
|
}
|
||||||
|
|
||||||
if err = cl.Dial(ctx, prmDial); err != nil {
|
if err = cl.Dial(ctx, prmDial); err != nil {
|
||||||
c.setUnhealthyOnDial()
|
c.setUnhealthyOnDial()
|
||||||
|
@ -379,11 +380,12 @@ func (c *clientWrapper) restartIfUnhealthy(ctx context.Context) (healthy, change
|
||||||
|
|
||||||
cl.Init(prmInit)
|
cl.Init(prmInit)
|
||||||
|
|
||||||
var prmDial sdkClient.PrmDial
|
prmDial := sdkClient.PrmDial{
|
||||||
prmDial.SetServerURI(c.prm.address)
|
Endpoint: c.prm.address,
|
||||||
prmDial.SetTimeout(c.prm.dialTimeout)
|
DialTimeout: c.prm.dialTimeout,
|
||||||
prmDial.SetStreamTimeout(c.prm.streamTimeout)
|
StreamTimeout: c.prm.streamTimeout,
|
||||||
prmDial.SetGRPCDialOptions(c.prm.dialOptions...)
|
GRPCDialOptions: c.prm.dialOptions,
|
||||||
|
}
|
||||||
|
|
||||||
if err := cl.Dial(ctx, prmDial); err != nil {
|
if err := cl.Dial(ctx, prmDial); err != nil {
|
||||||
c.setUnhealthyOnDial()
|
c.setUnhealthyOnDial()
|
||||||
|
|
Loading…
Reference in a new issue