mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
integration tests passing
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user