[#270] client: Use RPC call instead of Dial
After api-go upgrade created client doesn't establish connection after created, so RPC call is required to establish and check connection. RPC call returns status error, so conversion from status error to context error is required to satisfy Dial contract and unit tests. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
3e455777fd
commit
6009d089fc
1 changed files with 14 additions and 4 deletions
|
@ -11,6 +11,8 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client represents virtual connection to the FrostFS network to communicate
|
// Client represents virtual connection to the FrostFS network to communicate
|
||||||
|
@ -98,14 +100,22 @@ func (c *Client) Dial(ctx context.Context, prm PrmDial) error {
|
||||||
|
|
||||||
c.setFrostFSAPIServer((*coreServer)(&c.c))
|
c.setFrostFSAPIServer((*coreServer)(&c.c))
|
||||||
|
|
||||||
// TODO: (neofs-api-go#382) perform generic dial stage of the client.Client
|
|
||||||
_, err := rpc.Balance(&c.c, new(v2accounting.BalanceRequest),
|
_, err := rpc.Balance(&c.c, new(v2accounting.BalanceRequest),
|
||||||
client.WithContext(ctx),
|
client.WithContext(ctx),
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
// return context errors since they signal about dial problem
|
// return context errors since they signal about dial problem
|
||||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
st, ok := status.FromError(err)
|
||||||
|
if ok && st.Code() == codes.Canceled {
|
||||||
|
return context.Canceled
|
||||||
|
}
|
||||||
|
if ok && st.Code() == codes.DeadlineExceeded {
|
||||||
|
return context.DeadlineExceeded
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue