@ -104,6 +104,8 @@ func toStorageErr(err error) error {
type StorageRPCClient struct {
type StorageRPCClient struct {
* RPCClient
* RPCClient
connected bool
connected bool
// Plain error of the last RPC call
lastRPCError error
}
}
// Stringer provides a canonicalized representation of network device.
// Stringer provides a canonicalized representation of network device.
@ -114,6 +116,11 @@ func (client *StorageRPCClient) String() string {
return url . String ( )
return url . String ( )
}
}
// LastError - returns the last RPC call result, nil or error if any
func ( client * StorageRPCClient ) LastError ( ) error {
return client . lastRPCError
}
// Close - closes underneath RPC client.
// Close - closes underneath RPC client.
func ( client * StorageRPCClient ) Close ( ) error {
func ( client * StorageRPCClient ) Close ( ) error {
client . connected = false
client . connected = false
@ -125,14 +132,22 @@ func (client *StorageRPCClient) IsOnline() bool {
return client . connected
return client . connected
}
}
func ( client * StorageRPCClient ) connect ( ) {
err := client . Call ( storageServiceName + ".Connect" , & AuthArgs { } , & VoidReply { } )
client . lastRPCError = err
client . connected = err == nil
}
func ( client * StorageRPCClient ) call ( handler string , args interface {
func ( client * StorageRPCClient ) call ( handler string , args interface {
SetAuthArgs ( args AuthArgs )
SetAuthArgs ( args AuthArgs )
} , reply interface { } ) error {
} , reply interface { } ) error {
if ! client . connected {
if ! client . connected {
return errDiskNotFound
return errDiskNotFound
}
}
err := client . Call ( handler , args , reply )
err := client . Call ( handler , args , reply )
client . lastRPCError = err
if err == nil {
if err == nil {
return nil
return nil
}
}
@ -318,6 +333,7 @@ func newStorageRPC(endpoint Endpoint) *StorageRPCClient {
logger . FatalIf ( err , "Unable to parse storage RPC Host" , context . Background ( ) )
logger . FatalIf ( err , "Unable to parse storage RPC Host" , context . Background ( ) )
rpcClient , err := NewStorageRPCClient ( host , endpoint . Path )
rpcClient , err := NewStorageRPCClient ( host , endpoint . Path )
logger . FatalIf ( err , "Unable to initialize storage RPC client" , context . Background ( ) )
logger . FatalIf ( err , "Unable to initialize storage RPC client" , context . Background ( ) )
rpcClient . connected = rpcClient . Call ( storageServiceName + ".Connect" , & AuthArgs { } , & VoidReply { } ) == nil
// Attempt first try connection and save error if any.
rpcClient . connect ( )
return rpcClient
return rpcClient
}
}