From 5c9f48e8974e93cd25bb815e64f8b21faab8cb03 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Wed, 20 Apr 2016 14:30:47 +0300 Subject: [PATCH] integration tests passing --- cmd/cgr-engine/rater.go | 10 ++++++++++ engine/action.go | 12 ++++-------- utils/rpc_params.go | 13 ++++++++----- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/cmd/cgr-engine/rater.go b/cmd/cgr-engine/rater.go index 41535636d..22d5570d0 100644 --- a/cmd/cgr-engine/rater.go +++ b/cmd/cgr-engine/rater.go @@ -247,5 +247,15 @@ func startRater(internalRaterChan chan *engine.Responder, cacheDoneChan chan str server.RpcRegister(responder) server.RpcRegister(apierRpcV1) server.RpcRegister(apierRpcV2) + + utils.RegisterRpcParams("", &engine.Stats{}) + utils.RegisterRpcParams("", &history.FileScribe{}) + utils.RegisterRpcParams("", &engine.PubSub{}) + utils.RegisterRpcParams("", &engine.AliasHandler{}) + utils.RegisterRpcParams("", &engine.UserMap{}) + utils.RegisterRpcParams("", responder) + utils.RegisterRpcParams("", apierRpcV1) + utils.RegisterRpcParams("", apierRpcV2) + internalRaterChan <- responder // Rater done } diff --git a/engine/action.go b/engine/action.go index 84669ff1f..71a0fdf05 100644 --- a/engine/action.go +++ b/engine/action.go @@ -671,16 +671,12 @@ func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Acti } var client rpcclient.RpcClientConnection if req.Address != utils.INTERNAL { - if client, err = rpcclient.NewRpcClient(req.Method, req.Address, req.Attempts, 0, req.Transport, nil); err != nil { + if client, err = rpcclient.NewRpcClient("tcp", req.Address, req.Attempts, 0, req.Transport, nil); err != nil { return err } } else { - client = params.Object + client = params.Object.(rpcclient.RpcClientConnection) } - if client == nil { - return utils.ErrServerError - } - in, out := params.InParam, params.OutParam p, err := utils.FromMapStringInterfaceValue(req.Param, in) if err != nil { @@ -688,12 +684,12 @@ func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Acti } if !req.Async { err = client.Call(req.Method, p, out) - utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %+v err: %v", out, err)) + utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(out), err)) return err } go func() { err := client.Call(req.Method, p, out) - utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %+v err: %v", out, err)) + utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(out), err)) }() return nil } diff --git a/utils/rpc_params.go b/utils/rpc_params.go index 69020fdec..c48e84085 100644 --- a/utils/rpc_params.go +++ b/utils/rpc_params.go @@ -2,14 +2,12 @@ package utils import ( "reflect" - - "github.com/cgrates/rpcclient" ) var rpcParamsMap map[string]*RpcParams type RpcParams struct { - Object rpcclient.RpcClientConnection + Object interface{} InParam reflect.Value OutParam interface{} } @@ -18,7 +16,7 @@ func init() { rpcParamsMap = make(map[string]*RpcParams) } -func RegisterRpcParams(name string, obj rpcclient.RpcClientConnection) { +func RegisterRpcParams(name string, obj interface{}) { objType := reflect.TypeOf(obj) if name == "" { val := reflect.ValueOf(obj) @@ -31,10 +29,14 @@ func RegisterRpcParams(name string, obj rpcclient.RpcClientConnection) { method := objType.Method(i) methodType := method.Type if methodType.NumIn() == 3 { // if it has three parameters (one is self and two are rpc params) + out := methodType.In(2) + if out.Kind() == reflect.Ptr { + out = out.Elem() + } rpcParamsMap[name+"."+method.Name] = &RpcParams{ Object: obj, InParam: reflect.New(methodType.In(1)), - OutParam: reflect.New(methodType.In(2).Elem()).Interface(), + OutParam: reflect.New(out).Interface(), } } @@ -42,6 +44,7 @@ func RegisterRpcParams(name string, obj rpcclient.RpcClientConnection) { } func GetRpcParams(method string) (*RpcParams, error) { + Logger.Info("REGISTERED: " + ToJSON(rpcParamsMap)) x, found := rpcParamsMap[method] if !found { return nil, ErrNotFound