Migrate from iodine to probe

This commit is contained in:
Harshavardhana
2015-08-03 16:17:21 -07:00
parent 7f13095260
commit d09fd8b0a1
38 changed files with 917 additions and 1339 deletions

View File

@@ -22,7 +22,7 @@ import (
jsonrpc "github.com/gorilla/rpc/v2/json"
"github.com/minio/minio/pkg/auth"
"github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/probe"
"github.com/minio/minio/pkg/server/rpc"
)
@@ -33,25 +33,31 @@ func closeResp(resp *http.Response) {
}
// GetMemStats get memory status of the server at given url
func GetMemStats(url string) ([]byte, error) {
func GetMemStats(url string) ([]byte, *probe.Error) {
op := RPCOps{
Method: "MemStats.Get",
Request: rpc.Args{Request: ""},
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
resp, err := req.Do()
defer closeResp(resp)
if err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
var reply rpc.MemStatsReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, iodine.New(err, nil)
return nil, probe.New(err)
}
{
jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
if err != nil {
return nil, probe.New(err)
}
return jsonRespBytes, nil
}
return json.MarshalIndent(reply, "", "\t")
}
// GetSysInfo get system status of the server at given url
@@ -62,18 +68,24 @@ func GetSysInfo(url string) ([]byte, error) {
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
resp, err := req.Do()
defer closeResp(resp)
if err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
var reply rpc.SysInfoReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, iodine.New(err, nil)
return nil, probe.New(err)
}
{
jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
if err != nil {
return nil, probe.New(err)
}
return jsonRespBytes, nil
}
return json.MarshalIndent(reply, "", "\t")
}
// GetAuthKeys get access key id and secret access key
@@ -84,16 +96,16 @@ func GetAuthKeys(url string) ([]byte, error) {
}
req, err := NewRequest(url, op, http.DefaultTransport)
if err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
resp, err := req.Do()
defer closeResp(resp)
if err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
var reply rpc.AuthReply
if err := jsonrpc.DecodeClientResponse(resp.Body, &reply); err != nil {
return nil, iodine.New(err, nil)
return nil, probe.New(err)
}
authConfig := &auth.Config{}
authConfig.Version = "0.0.1"
@@ -104,9 +116,15 @@ func GetAuthKeys(url string) ([]byte, error) {
user.SecretAccessKey = reply.SecretAccessKey
authConfig.Users[reply.AccessKeyID] = user
if err := auth.SaveConfig(authConfig); err != nil {
return nil, iodine.New(err, nil)
return nil, err.Trace()
}
{
jsonRespBytes, err := json.MarshalIndent(reply, "", "\t")
if err != nil {
return nil, probe.New(err)
}
return jsonRespBytes, nil
}
return json.MarshalIndent(reply, "", "\t")
}
// Add more functions here for other RPC messages

View File

@@ -21,7 +21,7 @@ import (
"net/http"
"github.com/gorilla/rpc/v2/json"
"github.com/minio/minio/pkg/iodine"
"github.com/minio/minio/pkg/probe"
)
// RPCOps RPC operation
@@ -37,14 +37,14 @@ type RPCRequest struct {
}
// NewRequest initiate a new client RPC request
func NewRequest(url string, op RPCOps, transport http.RoundTripper) (*RPCRequest, error) {
func NewRequest(url string, op RPCOps, transport http.RoundTripper) (*RPCRequest, *probe.Error) {
params, err := json.EncodeClientRequest(op.Method, op.Request)
if err != nil {
return nil, iodine.New(err, nil)
return nil, probe.New(err)
}
req, err := http.NewRequest("POST", url, bytes.NewReader(params))
if err != nil {
return nil, iodine.New(err, nil)
return nil, probe.New(err)
}
rpcReq := &RPCRequest{}
rpcReq.req = req
@@ -57,10 +57,10 @@ func NewRequest(url string, op RPCOps, transport http.RoundTripper) (*RPCRequest
}
// Do - make a http connection
func (r RPCRequest) Do() (*http.Response, error) {
func (r RPCRequest) Do() (*http.Response, *probe.Error) {
resp, err := r.transport.RoundTrip(r.req)
if err != nil {
return nil, iodine.New(err, nil)
return nil, probe.New(err)
}
return resp, nil
}