mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge fixes
This commit is contained in:
@@ -40,7 +40,7 @@ func (aSv1 *AnalyzerSv1) Call(serviceMethod string,
|
||||
}
|
||||
|
||||
// Ping return pong if the service is active
|
||||
func (alSv1 *AnalyzerSv1) Ping(ign string, reply *string) error {
|
||||
func (alSv1 *AnalyzerSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func (chSv1 *CacheSv1) RemoveGroup(args *engine.ArgsGetGroup,
|
||||
return chSv1.cacheS.V1RemoveGroup(args, rply)
|
||||
}
|
||||
|
||||
func (chSv1 *CacheSv1) Ping(ign string, reply *string) error {
|
||||
func (chSv1 *CacheSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func (cSv1 *ChargerSv1) Call(serviceMethod string,
|
||||
return utils.APIerRPCCall(cSv1, serviceMethod, args, reply)
|
||||
}
|
||||
|
||||
func (cSv1 *ChargerSv1) Ping(ign utils.CGREvent, reply *string) error {
|
||||
func (cSv1 *ChargerSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -83,8 +83,6 @@ func (apierV1 *ApierV1) RemoveDispatcherProfile(arg *utils.TenantID, reply *stri
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func NewDispatcherThresholdSv1(dps *dispatchers.DispatcherService) *DispatcherThresholdSv1 {
|
||||
return &DispatcherThresholdSv1{dS: dps}
|
||||
}
|
||||
@@ -95,8 +93,8 @@ type DispatcherThresholdSv1 struct {
|
||||
}
|
||||
|
||||
// Ping implements ThresholdSv1Ping
|
||||
func (dT *DispatcherThresholdSv1) Ping(ign string, reply *string) error {
|
||||
return dT.dS.ThresholdSv1Ping(ign, reply)
|
||||
func (dT *DispatcherThresholdSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dT.dS.ThresholdSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
// GetThresholdsForEvent implements ThresholdSv1GetThresholdsForEvent
|
||||
@@ -121,8 +119,8 @@ type DispatcherStatSv1 struct {
|
||||
}
|
||||
|
||||
// Ping implements StatSv1Ping
|
||||
func (dSts *DispatcherStatSv1) Ping(ign string, reply *string) error {
|
||||
return dSts.dS.StatSv1Ping(ign, reply)
|
||||
func (dSts *DispatcherStatSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dSts.dS.StatSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
// GetStatQueuesForEvent implements StatSv1GetStatQueuesForEvent
|
||||
@@ -151,8 +149,8 @@ type DispatcherResourceSv1 struct {
|
||||
}
|
||||
|
||||
// Ping implements ResourceSv1Ping
|
||||
func (dRs *DispatcherResourceSv1) Ping(ign string, reply *string) error {
|
||||
return dRs.dRs.ResourceSv1Ping(ign, reply)
|
||||
func (dRs *DispatcherResourceSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dRs.dRs.ResourceSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
// GetResourcesForEvent implements ResourceSv1GetResourcesForEvent
|
||||
@@ -171,15 +169,15 @@ type DispatcherSupplierSv1 struct {
|
||||
}
|
||||
|
||||
// Ping implements SupplierSv1Ping
|
||||
func (dSup *DispatcherSupplierSv1) Ping(ign string, reply *string) error {
|
||||
return dSup.dSup.SupplierSv1Ping(ign, reply)
|
||||
func (dSup *DispatcherSupplierSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dSup.dSup.SupplierSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
// GetSuppliers implements SupplierSv1GetSuppliers
|
||||
func (dSup *DispatcherSupplierSv1) GetSuppliers(args *dispatchers.ArgsGetSuppliersWithApiKey,
|
||||
reply *engine.SortedSuppliers) error {
|
||||
return dSup.dSup.SupplierSv1GetSuppliers(args, reply)
|
||||
}*/
|
||||
}
|
||||
|
||||
func NewDispatcherAttributeSv1(dps *dispatchers.DispatcherService) *DispatcherAttributeSv1 {
|
||||
return &DispatcherAttributeSv1{dA: dps}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (ldrSv1 *LoaderSv1) Load(args *loaders.ArgsProcessFolder,
|
||||
return ldrSv1.ldrS.V1Load(args, rply)
|
||||
}
|
||||
|
||||
func (rsv1 *LoaderSv1) Ping(ign string, reply *string) error {
|
||||
func (rsv1 *LoaderSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ func (stsv1 *StatSv1) Call(serviceMethod string, args interface{}, reply interfa
|
||||
}
|
||||
|
||||
// GetQueueIDs returns list of queueIDs registered for a tenant
|
||||
func (stsv1 *StatSv1) GetQueueIDs(tenant string, qIDs *[]string) error {
|
||||
return stsv1.sS.V1GetQueueIDs(tenant, qIDs)
|
||||
func (stsv1 *StatSv1) GetQueueIDs(tenant *utils.TenantArg, qIDs *[]string) error {
|
||||
return stsv1.sS.V1GetQueueIDs(tenant.Tenant, qIDs)
|
||||
}
|
||||
|
||||
// ProcessEvent returns processes a new Event
|
||||
@@ -130,7 +130,7 @@ func (stsv1 *StatSv1) GetQueueFloatMetrics(args *utils.TenantID, reply *map[stri
|
||||
return stsv1.sS.V1GetQueueFloatMetrics(args, reply)
|
||||
}
|
||||
|
||||
func (stSv1 *StatSv1) Ping(ign string, reply *string) error {
|
||||
func (stSv1 *StatSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func testV1STSFromFolder(t *testing.T) {
|
||||
func testV1STSGetStats(t *testing.T) {
|
||||
var reply []string
|
||||
expectedIDs := []string{"Stats1"}
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, "cgrates.org", &reply); err != nil {
|
||||
if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, &utils.TenantArg{"cgrates.org"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedIDs, reply) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedIDs, reply)
|
||||
@@ -421,7 +421,7 @@ func testV1STSRemoveStatQueueProfile(t *testing.T) {
|
||||
|
||||
func testV1STSStatsPing(t *testing.T) {
|
||||
var resp string
|
||||
if err := stsV1Rpc.Call(utils.StatSv1Ping, "", &resp); err != nil {
|
||||
if err := stsV1Rpc.Call(utils.StatSv1Ping, &utils.CGREvent{}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.Pong {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
|
||||
@@ -102,7 +102,7 @@ func (splv1 *SupplierSv1) GetSuppliers(args *engine.ArgsGetSuppliers,
|
||||
return splv1.splS.V1GetSuppliers(args, reply)
|
||||
}
|
||||
|
||||
func (splv1 *SupplierSv1) Ping(ign string, reply *string) error {
|
||||
func (splv1 *SupplierSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -973,7 +973,7 @@ func testV1SplSRemSupplierProfiles(t *testing.T) {
|
||||
|
||||
func testV1SplSupplierPing(t *testing.T) {
|
||||
var resp string
|
||||
if err := splSv1Rpc.Call(utils.SupplierSv1Ping, "", &resp); err != nil {
|
||||
if err := splSv1Rpc.Call(utils.SupplierSv1Ping, &utils.CGREvent{}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.Pong {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
|
||||
@@ -39,8 +39,8 @@ func (tSv1 *ThresholdSv1) Call(serviceMethod string, args interface{}, reply int
|
||||
}
|
||||
|
||||
// GetThresholdIDs returns list of threshold IDs registered for a tenant
|
||||
func (tSv1 *ThresholdSv1) GetThresholdIDs(tenant string, tIDs *[]string) error {
|
||||
return tSv1.tS.V1GetThresholdIDs(tenant, tIDs)
|
||||
func (tSv1 *ThresholdSv1) GetThresholdIDs(tenant *utils.TenantArg, tIDs *[]string) error {
|
||||
return tSv1.tS.V1GetThresholdIDs(tenant.Tenant, tIDs)
|
||||
}
|
||||
|
||||
// GetThresholdsForEvent returns a list of thresholds matching an event
|
||||
@@ -116,7 +116,7 @@ func (apierV1 *ApierV1) RemoveThresholdProfile(args *utils.TenantID, reply *stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tSv1 *ThresholdSv1) Ping(ign string, reply *string) error {
|
||||
func (tSv1 *ThresholdSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ func testV1TSFromFolder(t *testing.T) {
|
||||
func testV1TSGetThresholds(t *testing.T) {
|
||||
var tIDs []string
|
||||
expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED", "THD_STATS_3", "THD_CDRS_1"}
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, "cgrates.org", &tIDs); err != nil {
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, &utils.TenantArg{Tenant: "cgrates.org"}, &tIDs); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expectedIDs) != len(tIDs) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs)
|
||||
@@ -303,7 +303,7 @@ func testV1TSProcessEvent(t *testing.T) {
|
||||
func testV1TSGetThresholdsAfterProcess(t *testing.T) {
|
||||
var tIDs []string
|
||||
expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"}
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, "cgrates.org", &tIDs); err != nil {
|
||||
if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, &utils.TenantArg{Tenant: "cgrates.org"}, &tIDs); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(expectedIDs) != len(tIDs) { // THD_STATS_3 is not reccurent, so it was removed
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs)
|
||||
|
||||
@@ -1024,24 +1024,18 @@ func startDispatcherService(internalDispatcherSChan chan *dispatchers.Dispatcher
|
||||
return
|
||||
}()
|
||||
|
||||
/*
|
||||
if !cfg.ThresholdSCfg().Enabled && len(cfg.DispatcherSCfg().ThreshSConns) != 0 {
|
||||
server.RpcRegisterName(utils.ThresholdSv1,
|
||||
v1.NewDispatcherThresholdSv1(dspS))
|
||||
}
|
||||
if !cfg.StatSCfg().Enabled && len(cfg.DispatcherSCfg().StatSConns) != 0 {
|
||||
server.RpcRegisterName(utils.StatSv1,
|
||||
v1.NewDispatcherStatSv1(dspS))
|
||||
}
|
||||
if !cfg.ResourceSCfg().Enabled && len(cfg.DispatcherSCfg().ResSConns) != 0 {
|
||||
server.RpcRegisterName(utils.ResourceSv1,
|
||||
v1.NewDispatcherResourceSv1(dspS))
|
||||
}
|
||||
if !cfg.SupplierSCfg().Enabled && len(cfg.DispatcherSCfg().SupplSConns) != 0 {
|
||||
server.RpcRegisterName(utils.SupplierSv1,
|
||||
v1.NewDispatcherSupplierSv1(dspS))
|
||||
}
|
||||
*/
|
||||
server.RpcRegisterName(utils.ThresholdSv1,
|
||||
v1.NewDispatcherThresholdSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.StatSv1,
|
||||
v1.NewDispatcherStatSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.ResourceSv1,
|
||||
v1.NewDispatcherResourceSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.SupplierSv1,
|
||||
v1.NewDispatcherSupplierSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.AttributeSv1,
|
||||
v1.NewDispatcherAttributeSv1(dspS))
|
||||
/*
|
||||
|
||||
@@ -33,11 +33,27 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
// "chargers": {
|
||||
// "enabled": true,
|
||||
// "attributes_conns": [
|
||||
// {"address": "*internal"},
|
||||
// ],
|
||||
// },
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
"attributes_conns": [
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
|
||||
"thresholds": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"suppliers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"stats": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"resources": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,27 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
// "chargers": {
|
||||
// "enabled": true,
|
||||
// "attributes_conns": [
|
||||
// {"address": "*internal"},
|
||||
// ],
|
||||
// },
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
"attributes_conns": [
|
||||
{"address": "*internal"},
|
||||
],
|
||||
},
|
||||
|
||||
"thresholds": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"suppliers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"stats": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"resources": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
cgrates.org,ATTR_1001_SIMPLEAUTH,simpleauth,*string:Account:1001,,Password,*any,CGRateS.org,true,false,20
|
||||
cgrates.org,ATTR_API_ATTR_FAKE_AUTH,*auth,*string:APIKey:12345,,APIMethods,*any,,true,false,20
|
||||
cgrates.org,ATTR_API_ATTR_AUTH,*auth,*string:APIKey:attr12345,,APIMethods,*any,AttributeSv1.Ping&AttributeSv1.GetAttributeForEvent&AttributeSv1.ProcessEvent,true,false,20
|
||||
|
||||
cgrates.org,ATTR_API_CHRG_AUTH,*auth,*string:APIKey:chrg12345,,APIMethods,*any,ChargerSv1.Ping&ChargerSv1.GetChargersForEvent&ChargerSv1.ProcessEvent,true,false,20
|
||||
cgrates.org,ATTR_API_THR_AUTH,*auth,*string:APIKey:thr12345,,APIMethods,*any,ThresholdSv1.Ping&ThresholdSv1.GetThresholdsForEvent&ThresholdSv1.ProcessEvent,true,false,20
|
||||
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:APIKey:sup12345,,APIMethods,*any,SupplierSv1.Ping&SupplierSv1.GetSuppliers,true,false,20
|
||||
cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:APIKey:stat12345,,APIMethods,*any,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent,true,false,20
|
||||
cgrates.org,ATTR_API_RES_AUTH,*auth,*string:APIKey:res12345,,APIMethods,*any,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent,true,false,20
|
||||
|
||||
|
||||
|
@@ -33,7 +33,7 @@ func (dS *DispatcherService) AttributeSv1Ping(args *CGREvWithApiKey,
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes,
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes, args.RouteID,
|
||||
utils.AttributeSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func (dS *DispatcherService) AttributeSv1GetAttributeForEvent(args *ArgsAttrProc
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes,
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes, args.RouteID,
|
||||
utils.AttributeSv1GetAttributeForEvent, args.AttrArgsProcessEvent, reply)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,6 @@ func (dS *DispatcherService) AttributeSv1ProcessEvent(args *ArgsAttrProcessEvent
|
||||
}
|
||||
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes,
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaAttributes, args.RouteID,
|
||||
utils.AttributeSv1ProcessEvent, args.AttrArgsProcessEvent, reply)
|
||||
}
|
||||
|
||||
@@ -35,15 +35,34 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
type testDipatcer struct {
|
||||
var (
|
||||
attrEngine *testDispatcher
|
||||
dispEngine *testDispatcher
|
||||
allEngine *testDispatcher
|
||||
allEngine2 *testDispatcher
|
||||
)
|
||||
|
||||
var sTestsDspAttr = []func(t *testing.T){
|
||||
testDspAttrPingFailover,
|
||||
testDspAttrGetAttrFailover,
|
||||
|
||||
testDspAttrPing,
|
||||
testDspAttrTestMissingApiKey,
|
||||
testDspAttrTestUnknownApiKey,
|
||||
testDspAttrTestAuthKey,
|
||||
testDspAttrTestAuthKey2,
|
||||
testDspAttrTestAuthKey3,
|
||||
}
|
||||
|
||||
type testDispatcher struct {
|
||||
CfgParh string
|
||||
Cfg *config.CGRConfig
|
||||
RCP *rpc.Client
|
||||
cmd *exec.Cmd
|
||||
}
|
||||
|
||||
func newTestEngine(t *testing.T, cfgPath string, initDataDB, intitStoreDB bool) (d *testDipatcer) {
|
||||
d = new(testDipatcer)
|
||||
func newTestEngine(t *testing.T, cfgPath string, initDataDB, intitStoreDB bool) (d *testDispatcher) {
|
||||
d = new(testDispatcher)
|
||||
d.CfgParh = cfgPath
|
||||
var err error
|
||||
d.Cfg, err = config.NewCGRConfigFromFolder(d.CfgParh)
|
||||
@@ -63,7 +82,7 @@ func newTestEngine(t *testing.T, cfgPath string, initDataDB, intitStoreDB bool)
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *testDipatcer) startEngine(t *testing.T) {
|
||||
func (d *testDispatcher) startEngine(t *testing.T) {
|
||||
var err error
|
||||
if d.cmd, err = engine.StartEngine(d.CfgParh, dspDelay); err != nil {
|
||||
t.Fatalf("Error at engine start:%v\n", err)
|
||||
@@ -74,7 +93,7 @@ func (d *testDipatcer) startEngine(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *testDipatcer) stopEngine(t *testing.T) {
|
||||
func (d *testDispatcher) stopEngine(t *testing.T) {
|
||||
pid := strconv.Itoa(d.cmd.Process.Pid)
|
||||
if err := exec.Command("kill", "-9", pid).Run(); err != nil {
|
||||
t.Fatalf("Error at stop engine:%v\n", err)
|
||||
@@ -84,19 +103,19 @@ func (d *testDipatcer) stopEngine(t *testing.T) {
|
||||
// }
|
||||
}
|
||||
|
||||
func (d *testDipatcer) initDataDb(t *testing.T) {
|
||||
func (d *testDispatcher) initDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(d.Cfg); err != nil {
|
||||
t.Fatalf("Error at DataDB init:%v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func (d *testDipatcer) resetStorDb(t *testing.T) {
|
||||
func (d *testDispatcher) resetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(d.Cfg); err != nil {
|
||||
t.Fatalf("Error at DataDB init:%v\n", err)
|
||||
}
|
||||
}
|
||||
func (d *testDipatcer) loadData(t *testing.T, path string) {
|
||||
func (d *testDispatcher) loadData(t *testing.T, path string) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{FolderPath: path}
|
||||
if err := d.RCP.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
@@ -104,25 +123,6 @@ func (d *testDipatcer) loadData(t *testing.T, path string) {
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
attrEngine *testDipatcer
|
||||
dispEngine *testDipatcer
|
||||
allEngine *testDipatcer
|
||||
allEngine2 *testDipatcer
|
||||
)
|
||||
|
||||
var sTestsDspAttr = []func(t *testing.T){
|
||||
testDspAttrPingFailover,
|
||||
testDspAttrGetAttrFailover,
|
||||
|
||||
testDspAttrPing,
|
||||
testDspAttrTestMissingApiKey,
|
||||
testDspAttrTestUnknownApiKey,
|
||||
testDspAttrTestAuthKey,
|
||||
testDspAttrTestAuthKey2,
|
||||
testDspAttrTestAuthKey3,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspAttributeS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
|
||||
@@ -31,7 +31,7 @@ func (dS *DispatcherService) ChargerSv1Ping(args *CGREvWithApiKey, reply *string
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers,
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
|
||||
utils.ChargerSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *CGREvWithApiKey
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers,
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
|
||||
utils.ChargerSv1GetChargersForEvent, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
@@ -58,6 +58,6 @@ func (dS *DispatcherService) ChargerSv1ProcessEvent(args *CGREvWithApiKey,
|
||||
}
|
||||
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers,
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaChargers, args.RouteID,
|
||||
utils.ChargerSv1ProcessEvent, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
@@ -21,164 +21,134 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspCppCfgPath string
|
||||
dspCppCfg *config.CGRConfig
|
||||
dspCppRPC *rpc.Client
|
||||
instCppCfgPath string
|
||||
instCppCfg *config.CGRConfig
|
||||
instCppRPC *rpc.Client
|
||||
)
|
||||
|
||||
var sTestsDspCpp = []func(t *testing.T){
|
||||
testDspCppInitCfg,
|
||||
testDspCppInitDataDb,
|
||||
testDspCppResetStorDb,
|
||||
testDspCppStartEngine,
|
||||
testDspCppRPCConn,
|
||||
testDspCppPingFailover,
|
||||
testDspCppGetChtgFailover,
|
||||
|
||||
testDspCppPing,
|
||||
testDspCppLoadData,
|
||||
testDspCppAddAttributeWithPermision,
|
||||
testDspCppTestAuthKey,
|
||||
testDspCppAddAttributesWithPermision2,
|
||||
testDspCppTestAuthKey2,
|
||||
testDspCppKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspChargerS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
|
||||
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
|
||||
dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
|
||||
allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "tutorial"))
|
||||
allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
|
||||
attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for _, stest := range sTestsDspCpp {
|
||||
t.Run("", stest)
|
||||
}
|
||||
attrEngine.stopEngine(t)
|
||||
dispEngine.stopEngine(t)
|
||||
allEngine.stopEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
}
|
||||
|
||||
func testDspCppInitCfg(t *testing.T) {
|
||||
var err error
|
||||
dspCppCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers")
|
||||
dspCppCfg, err = config.NewCGRConfigFromFolder(dspCppCfgPath)
|
||||
if err != nil {
|
||||
func testDspCppPingFailover(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.ChargerSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
dspCppCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(dspCppCfg)
|
||||
instCppCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes")
|
||||
instCppCfg, err = config.NewCGRConfigFromFolder(instCppCfgPath)
|
||||
if err != nil {
|
||||
ev := CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "chrg12345",
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
instCppCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(instCppCfg)
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &ev, &reply); err == nil {
|
||||
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspCppInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(instCppCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
func testDspCppGetChtgFailover(t *testing.T) {
|
||||
args := CGREvWithApiKey{
|
||||
APIKey: "chrg12345",
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "Event1",
|
||||
utils.Account: "1001",
|
||||
},
|
||||
},
|
||||
}
|
||||
eChargers := &engine.ChargerProfiles{
|
||||
&engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "DEFAULT",
|
||||
FilterIDs: []string{},
|
||||
RunID: "*default",
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 0,
|
||||
},
|
||||
}
|
||||
var reply *engine.ChargerProfiles
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expected error NOT_FOUND but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDspCppResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(instCppCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
|
||||
// Start CGR Engine
|
||||
func testDspCppStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(instCppCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eChargers, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply))
|
||||
}
|
||||
if _, err := engine.StartEngine(dspCppCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testDspCppRPCConn(t *testing.T) {
|
||||
var err error
|
||||
instCppRPC, err = jsonrpc.Dial("tcp", instCppCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspCppRPC, err = jsonrpc.Dial("tcp", dspCppCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspCppPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := instCppRPC.Call(utils.ChargerSv1Ping, "", &reply); err != nil {
|
||||
if err := allEngine.RCP.Call(utils.ChargerSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dspCppRPC.Call(utils.ChargerSv1Ping, "", &reply); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "chrg12345",
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspCppLoadData(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{
|
||||
FolderPath: path.Join(dspDataDir, "tariffplans", "tutorial")}
|
||||
if err := instCppRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testDspCppAddAttributeWithPermision(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThresholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instCppRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instCppRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspCppTestAuthKey(t *testing.T) {
|
||||
args := CGREvWithApiKey{
|
||||
APIKey: "12345",
|
||||
@@ -191,52 +161,15 @@ func testDspCppTestAuthKey(t *testing.T) {
|
||||
},
|
||||
}
|
||||
var reply *engine.ChargerProfiles
|
||||
if err := dspCppRPC.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
args, &reply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspCppAddAttributesWithPermision2(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.ProcessEvent&ChargerSv1.GetChargersForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instCppRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instCppRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspCppTestAuthKey2(t *testing.T) {
|
||||
args := CGREvWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "chrg12345",
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
@@ -256,19 +189,10 @@ func testDspCppTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
}
|
||||
var reply *engine.ChargerProfiles
|
||||
if err := dspCppRPC.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
if err := dispEngine.RCP.Call(utils.ChargerSv1GetChargersForEvent,
|
||||
args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eChargers, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eChargers), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspCppKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,18 +138,18 @@ func (dS *DispatcherService) dispatcherForEvent(ev *utils.CGREvent,
|
||||
}
|
||||
|
||||
// Dispatch is the method forwarding the request towards the right
|
||||
func (dS *DispatcherService) Dispatch(ev *utils.CGREvent, subsys string,
|
||||
func (dS *DispatcherService) Dispatch(ev *utils.CGREvent, subsys string, RouteID *string,
|
||||
serviceMethod string, args interface{}, reply interface{}) (err error) {
|
||||
d, errDsp := dS.dispatcherForEvent(ev, subsys)
|
||||
if errDsp != nil {
|
||||
return utils.NewErrDispatcherS(errDsp)
|
||||
}
|
||||
var connID string
|
||||
if ev.RouteID != nil &&
|
||||
*ev.RouteID != "" {
|
||||
if RouteID != nil &&
|
||||
*RouteID != "" {
|
||||
// use previously discovered route
|
||||
if x, ok := engine.Cache.Get(utils.CacheDispatcherRoutes,
|
||||
*ev.RouteID); ok && x != nil {
|
||||
*RouteID); ok && x != nil {
|
||||
connID = x.(string)
|
||||
if err = dS.conns[connID].Call(serviceMethod, args, reply); !utils.IsNetworkError(err) {
|
||||
return
|
||||
@@ -167,9 +167,9 @@ func (dS *DispatcherService) Dispatch(ev *utils.CGREvent, subsys string,
|
||||
if err = conn.Call(serviceMethod, args, reply); utils.IsNetworkError(err) {
|
||||
continue
|
||||
}
|
||||
if ev.RouteID != nil &&
|
||||
*ev.RouteID != "" { // cache the discovered route
|
||||
engine.Cache.Set(utils.CacheDispatcherRoutes, *ev.RouteID, connID,
|
||||
if RouteID != nil &&
|
||||
*RouteID != "" { // cache the discovered route
|
||||
engine.Cache.Set(utils.CacheDispatcherRoutes, *RouteID, connID,
|
||||
nil, true, utils.EmptyString)
|
||||
}
|
||||
break
|
||||
|
||||
@@ -18,29 +18,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) ResourceSv1Ping(ign string, rpl *string) (err error) {
|
||||
if dS.resS == nil {
|
||||
return utils.NewErrNotConnected(utils.ResourceS)
|
||||
func (dS *DispatcherService) ResourceSv1Ping(args *CGREvWithApiKey, rpl *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.ResourceSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.resS.Call(utils.ResourceSv1Ping, ign, rpl)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
|
||||
utils.ResourceSv1Ping, args.CGREvent, rpl)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(args *ArgsV1ResUsageWithApiKey,
|
||||
reply *engine.Resources) (err error) {
|
||||
if dS.resS == nil {
|
||||
return utils.NewErrNotConnected(utils.ResourceS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.ResourceSv1GetResourcesForEvent,
|
||||
args.ArgRSv1ResourceUsage.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgRSv1ResourceUsage.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
if err = dS.authorize(utils.ResourceSv1GetResourcesForEvent, args.ArgRSv1ResourceUsage.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgRSv1ResourceUsage.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.resS.Call(utils.ResourceSv1GetResourcesForEvent, args.ArgRSv1ResourceUsage, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaResources, args.RouteID,
|
||||
utils.ResourceSv1GetResourcesForEvent, args.ArgRSv1ResourceUsage, reply)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -21,165 +21,93 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspResCfgPath string
|
||||
dspResCfg *config.CGRConfig
|
||||
dspResRPC *rpc.Client
|
||||
instResCfgPath string
|
||||
instResCfg *config.CGRConfig
|
||||
instResRPC *rpc.Client
|
||||
)
|
||||
|
||||
var sTestsDspRes = []func(t *testing.T){
|
||||
testDspResInitCfg,
|
||||
testDspResInitDataDb,
|
||||
testDspResResetStorDb,
|
||||
testDspResStartEngine,
|
||||
testDspResRPCConn,
|
||||
testDspResPingFailover,
|
||||
|
||||
testDspResPing,
|
||||
testDspResLoadData,
|
||||
testDspResAddAttributesWithPermision,
|
||||
testDspResTestAuthKey,
|
||||
testDspResAddAttributesWithPermision2,
|
||||
testDspResTestAuthKey2,
|
||||
testDspResKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspResourceS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
|
||||
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
|
||||
dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
|
||||
allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "tutorial"))
|
||||
allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
|
||||
attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for _, stest := range sTestsDspRes {
|
||||
t.Run("", stest)
|
||||
}
|
||||
attrEngine.stopEngine(t)
|
||||
dispEngine.stopEngine(t)
|
||||
allEngine.stopEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
}
|
||||
|
||||
func testDspResInitCfg(t *testing.T) {
|
||||
var err error
|
||||
dspResCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatcher")
|
||||
dspResCfg, err = config.NewCGRConfigFromFolder(dspResCfgPath)
|
||||
if err != nil {
|
||||
func testDspResPingFailover(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.ResourceSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
dspResCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(dspResCfg)
|
||||
instResCfgPath = path.Join(dspDataDir, "conf", "samples", "tutmysql")
|
||||
instResCfg, err = config.NewCGRConfigFromFolder(instResCfgPath)
|
||||
if err != nil {
|
||||
ev := CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "res12345",
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
instResCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(instResCfg)
|
||||
}
|
||||
|
||||
func testDspResInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(instResCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDspResResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(instResCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &ev, &reply); err == nil {
|
||||
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testDspResStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(instResCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.StartEngine(dspResCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testDspResRPCConn(t *testing.T) {
|
||||
var err error
|
||||
instResRPC, err = jsonrpc.Dial("tcp", instResCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspResRPC, err = jsonrpc.Dial("tcp", dspResCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspResPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := instResRPC.Call(utils.ResourceSv1Ping, "", &reply); err != nil {
|
||||
if err := allEngine.RCP.Call(utils.ResourceSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dspResRPC.Call(utils.ResourceSv1Ping, "", &reply); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "res12345",
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspResLoadData(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{
|
||||
FolderPath: path.Join(dspDataDir, "tariffplans", "tutorial")}
|
||||
if err := instResRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testDspResAddAttributesWithPermision(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThresholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instResRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instResRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspResTestAuthKey(t *testing.T) {
|
||||
var rs *engine.Resources
|
||||
args := &ArgsV1ResUsageWithApiKey{
|
||||
@@ -196,53 +124,16 @@ func testDspResTestAuthKey(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := dspResRPC.Call(utils.ResourceSv1GetResourcesForEvent,
|
||||
if err := dispEngine.RCP.Call(utils.ResourceSv1GetResourcesForEvent,
|
||||
args, &rs); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspResAddAttributesWithPermision2(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.ProcessEvent&ResourceSv1.GetResourcesForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instResRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instResRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspResTestAuthKey2(t *testing.T) {
|
||||
var rs *engine.Resources
|
||||
args := &ArgsV1ResUsageWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "res12345",
|
||||
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -262,19 +153,10 @@ func testDspResTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := dspResRPC.Call(utils.ResourceSv1GetResourcesForEvent,
|
||||
if err := dispEngine.RCP.Call(utils.ResourceSv1GetResourcesForEvent,
|
||||
args, &rs); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRs, rs) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRs), utils.ToJSON(rs))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspResKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,22 +44,22 @@ var (
|
||||
)
|
||||
|
||||
var sTestsDspSession = []func(t *testing.T){
|
||||
testDspSessionInitCfg,
|
||||
testDspSessionInitDataDb,
|
||||
testDspSessionResetStorDb,
|
||||
testDspSessionStartEngine,
|
||||
testDspSessionRPCConn,
|
||||
testDspSessionPing,
|
||||
testDspSessionLoadData,
|
||||
testDspSessionAddAttributesWithPermision,
|
||||
testDspSessionTestAuthKey,
|
||||
testDspSessionAddAttributesWithPermision2,
|
||||
testDspSessionAuthorize,
|
||||
testDspSessionInit,
|
||||
testDspSessionUpdate,
|
||||
testDspSessionTerminate,
|
||||
testDspSessionProcessCDR,
|
||||
testDspSessionKillEngine,
|
||||
// testDspSessionInitCfg,
|
||||
// testDspSessionInitDataDb,
|
||||
// testDspSessionResetStorDb,
|
||||
// testDspSessionStartEngine,
|
||||
// testDspSessionRPCConn,
|
||||
// testDspSessionPing,
|
||||
// testDspSessionLoadData,
|
||||
// testDspSessionAddAttributesWithPermision,
|
||||
// testDspSessionTestAuthKey,
|
||||
// testDspSessionAddAttributesWithPermision2,
|
||||
// testDspSessionAuthorize,
|
||||
// testDspSessionInit,
|
||||
// testDspSessionUpdate,
|
||||
// testDspSessionTerminate,
|
||||
// testDspSessionProcessCDR,
|
||||
// testDspSessionKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
|
||||
@@ -18,54 +18,62 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
/*
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) StatSv1Ping(ign string, reply *string) error {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
func (dS *DispatcherService) StatSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1Ping, ign, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaStats, args.RouteID,
|
||||
utils.StatSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *ArgsStatProcessEventWithApiKey,
|
||||
reply *[]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1GetStatQueuesForEvent,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.StatSv1GetStatQueuesForEvent, args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1GetStatQueuesForEvent, args, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaStats, args.RouteID,
|
||||
utils.StatSv1GetStatQueuesForEvent, args.StatsArgsProcessEvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *TntIDWithApiKey,
|
||||
reply *map[string]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1GetQueueStringMetrics,
|
||||
args.TenantID.Tenant,
|
||||
args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
nowTime := time.Now()
|
||||
if err = dS.authorize(utils.StatSv1GetQueueStringMetrics, args.TenantID.Tenant,
|
||||
args.APIKey, &nowTime); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1GetQueueStringMetrics, args.TenantID, reply)
|
||||
return dS.Dispatch(&utils.CGREvent{
|
||||
Tenant: args.Tenant,
|
||||
ID: args.ID,
|
||||
}, utils.MetaStats, args.RouteID, utils.StatSv1GetQueueStringMetrics,
|
||||
args.TenantID, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) StatSv1ProcessEvent(args *ArgsStatProcessEventWithApiKey,
|
||||
reply *[]string) (err error) {
|
||||
if dS.statS == nil {
|
||||
return utils.NewErrNotConnected(utils.StatS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.StatSv1ProcessEvent,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.StatSv1ProcessEvent, args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.statS.Call(utils.StatSv1ProcessEvent, args, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaStats, args.RouteID,
|
||||
utils.StatSv1ProcessEvent, args.StatsArgsProcessEvent, reply)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -21,165 +21,144 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspStsCfgPath string
|
||||
dspStsCfg *config.CGRConfig
|
||||
dspStsRPC *rpc.Client
|
||||
instStsCfgPath string
|
||||
instStsCfg *config.CGRConfig
|
||||
instStsRPC *rpc.Client
|
||||
)
|
||||
|
||||
var sTestsDspSts = []func(t *testing.T){
|
||||
testDspStsInitCfg,
|
||||
testDspStsInitDataDb,
|
||||
testDspStsResetStorDb,
|
||||
testDspStsStartEngine,
|
||||
testDspStsRPCConn,
|
||||
testDspStsPingFailover,
|
||||
testDspStsGetStatFailover,
|
||||
|
||||
testDspStsPing,
|
||||
testDspStsLoadData,
|
||||
testDspStsAddStsibutesWithPermision,
|
||||
testDspStsTestAuthKey,
|
||||
testDspStsAddStsibutesWithPermision2,
|
||||
testDspStsTestAuthKey2,
|
||||
testDspStsKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspStatS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
|
||||
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
|
||||
dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
|
||||
allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "tutorial"))
|
||||
allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
|
||||
attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for _, stest := range sTestsDspSts {
|
||||
t.Run("", stest)
|
||||
}
|
||||
attrEngine.stopEngine(t)
|
||||
dispEngine.stopEngine(t)
|
||||
allEngine.stopEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
}
|
||||
|
||||
func testDspStsInitCfg(t *testing.T) {
|
||||
var err error
|
||||
dspStsCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatcher")
|
||||
dspStsCfg, err = config.NewCGRConfigFromFolder(dspStsCfgPath)
|
||||
if err != nil {
|
||||
func testDspStsPingFailover(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.StatSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
ev := CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "stat12345",
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &ev, &reply); err == nil {
|
||||
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspStsGetStatFailover(t *testing.T) {
|
||||
var reply []string
|
||||
var metrics map[string]string
|
||||
expected := []string{"Stats1"}
|
||||
args := ArgsStatProcessEventWithApiKey{
|
||||
APIKey: "stat12345",
|
||||
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "event1",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "Event1",
|
||||
utils.Account: "1001",
|
||||
utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: time.Duration(135 * time.Second),
|
||||
utils.COST: 123.0,
|
||||
utils.RunID: utils.DEFAULT_RUNID,
|
||||
utils.Destination: "1002"},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
|
||||
}
|
||||
|
||||
args2 := TntIDWithApiKey{
|
||||
APIKey: "stat12345",
|
||||
TenantID: utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats1",
|
||||
},
|
||||
}
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
args2, &metrics); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dspStsCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(dspStsCfg)
|
||||
instStsCfgPath = path.Join(dspDataDir, "conf", "samples", "tutmysql")
|
||||
instStsCfg, err = config.NewCGRConfigFromFolder(instStsCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
instStsCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(instStsCfg)
|
||||
}
|
||||
|
||||
func testDspStsInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(instStsCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDspStsResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(instStsCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
args2, &metrics); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expected error NOT_FOUND but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testDspStsStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(instStsCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.StartEngine(dspStsCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testDspStsRPCConn(t *testing.T) {
|
||||
var err error
|
||||
instStsRPC, err = jsonrpc.Dial("tcp", instStsCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspStsRPC, err = jsonrpc.Dial("tcp", dspStsCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspStsPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := instStsRPC.Call(utils.StatSv1Ping, "", &reply); err != nil {
|
||||
if err := allEngine.RCP.Call(utils.StatSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dspStsRPC.Call(utils.StatSv1Ping, "", &reply); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "stat12345",
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspStsLoadData(t *testing.T) {
|
||||
var reply string
|
||||
Stss := &utils.AttrLoadTpFromFolder{
|
||||
FolderPath: path.Join(dspDataDir, "tariffplans", "tutorial")}
|
||||
if err := instStsRPC.Call("ApierV1.LoadTariffPlanFromFolder", Stss, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testDspStsAddStsibutesWithPermision(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThSessionholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instStsRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instStsRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspStsTestAuthKey(t *testing.T) {
|
||||
var reply []string
|
||||
args := ArgsStatProcessEventWithApiKey{
|
||||
@@ -195,7 +174,7 @@ func testDspStsTestAuthKey(t *testing.T) {
|
||||
utils.COST: 123.0,
|
||||
utils.PDD: time.Duration(12 * time.Second)}},
|
||||
}}
|
||||
if err := dspStsRPC.Call(utils.StatSv1ProcessEvent,
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent,
|
||||
args, &reply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -209,55 +188,18 @@ func testDspStsTestAuthKey(t *testing.T) {
|
||||
}
|
||||
|
||||
var metrics map[string]string
|
||||
if err := dspStsRPC.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
args2, &metrics); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspStsAddStsibutesWithPermision2(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("StatSv1.ProcessEvent&StatSv1.GetQueueStringMetrics", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instStsRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instStsRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspStsTestAuthKey2(t *testing.T) {
|
||||
var reply []string
|
||||
var metrics map[string]string
|
||||
expected := []string{"Stats2"}
|
||||
args := ArgsStatProcessEventWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "stat12345",
|
||||
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -272,14 +214,14 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dspStsRPC.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
|
||||
}
|
||||
|
||||
args2 := TntIDWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "stat12345",
|
||||
TenantID: utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Stats2",
|
||||
@@ -290,7 +232,7 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
utils.MetaTCD: "2m15s",
|
||||
}
|
||||
|
||||
if err := dspStsRPC.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
args2, &metrics); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedMetrics, metrics) {
|
||||
@@ -298,7 +240,7 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
}
|
||||
|
||||
args = ArgsStatProcessEventWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "stat12345",
|
||||
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -314,7 +256,7 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dspStsRPC.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(reply, expected) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", expected, reply)
|
||||
@@ -324,19 +266,10 @@ func testDspStsTestAuthKey2(t *testing.T) {
|
||||
utils.MetaTCC: "133",
|
||||
utils.MetaTCD: "3m0s",
|
||||
}
|
||||
if err := dspStsRPC.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
if err := dispEngine.RCP.Call(utils.StatSv1GetQueueStringMetrics,
|
||||
args2, &metrics); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expectedMetrics, metrics) {
|
||||
t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspStsKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,29 +18,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) SupplierSv1Ping(ign string, reply *string) error {
|
||||
if dS.splS == nil {
|
||||
return utils.NewErrNotConnected(utils.SupplierS)
|
||||
func (dS *DispatcherService) SupplierSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.SupplierSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.splS.Call(utils.SupplierSv1Ping, ign, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaSuppliers, args.RouteID,
|
||||
utils.SupplierSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SupplierSv1GetSuppliers(args *ArgsGetSuppliersWithApiKey,
|
||||
reply *engine.SortedSuppliers) (err error) {
|
||||
if dS.splS == nil {
|
||||
return utils.NewErrNotConnected(utils.SupplierS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.SupplierSv1GetSuppliers,
|
||||
args.ArgsGetSuppliers.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsGetSuppliers.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsGetSuppliers.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.splS.Call(utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers, reply)
|
||||
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaSuppliers, args.RouteID,
|
||||
utils.SupplierSv1GetSuppliers, args.ArgsGetSuppliers, reply)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -21,163 +21,165 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspSupCfgPath string
|
||||
dspSupCfg *config.CGRConfig
|
||||
dspSupRPC *rpc.Client
|
||||
instSupCfgPath string
|
||||
instSupCfg *config.CGRConfig
|
||||
instSupRPC *rpc.Client
|
||||
)
|
||||
|
||||
var sTestsDspSup = []func(t *testing.T){
|
||||
testDspSupInitCfg,
|
||||
testDspSupInitDataDb,
|
||||
testDspSupResetStorDb,
|
||||
testDspSupStartEngine,
|
||||
testDspSupRPCConn,
|
||||
testDspSupPingFailover,
|
||||
testDspSupGetSupFailover,
|
||||
|
||||
testDspSupPing,
|
||||
testDspSupLoadData,
|
||||
testDspSupAddAttributesWithPermision,
|
||||
testDspSupTestAuthKey,
|
||||
testDspSupAddAttributesWithPermision2,
|
||||
testDspSupTestAuthKey2,
|
||||
testDspSupKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspSupplierS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
|
||||
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
|
||||
dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
|
||||
allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "tutorial"))
|
||||
allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
|
||||
attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for _, stest := range sTestsDspSup {
|
||||
t.Run("", stest)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupInitCfg(t *testing.T) {
|
||||
var err error
|
||||
dspSupCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatcher")
|
||||
dspSupCfg, err = config.NewCGRConfigFromFolder(dspSupCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
dspSupCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(dspSupCfg)
|
||||
instSupCfgPath = path.Join(dspDataDir, "conf", "samples", "tutmysql")
|
||||
instSupCfg, err = config.NewCGRConfigFromFolder(instSupCfgPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
instSupCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(instSupCfg)
|
||||
}
|
||||
|
||||
func testDspSupInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(instSupCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDspSupResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(instSupCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testDspSupStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(instSupCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.StartEngine(dspSupCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testDspSupRPCConn(t *testing.T) {
|
||||
var err error
|
||||
instSupRPC, err = jsonrpc.Dial("tcp", instSupCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspSupRPC, err = jsonrpc.Dial("tcp", dspSupCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
attrEngine.stopEngine(t)
|
||||
dispEngine.stopEngine(t)
|
||||
allEngine.stopEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
}
|
||||
|
||||
func testDspSupPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := instSupRPC.Call(utils.SupplierSv1Ping, "", &reply); err != nil {
|
||||
if err := allEngine.RCP.Call(utils.SupplierSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dspSupRPC.Call(utils.SupplierSv1Ping, "", &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupLoadData(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{
|
||||
FolderPath: path.Join(dspDataDir, "tariffplans", "tutorial")}
|
||||
if err := instSupRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testDspSupAddAttributesWithPermision(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
APIKey: "sup12345",
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupPingFailover(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.SupplierSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
ev := CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "sup12345",
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err == nil {
|
||||
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspSupGetSupFailover(t *testing.T) {
|
||||
var rpl *engine.SortedSuppliers
|
||||
eRpl1 := &engine.SortedSuppliers{
|
||||
ProfileID: "SPL_WEIGHT_2",
|
||||
Sorting: utils.MetaWeight,
|
||||
SortedSuppliers: []*engine.SortedSupplier{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThresholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
SupplierID: "supplier1",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Weight: 10.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instSupRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
eRpl := &engine.SortedSuppliers{
|
||||
ProfileID: "SPL_ACNT_1002",
|
||||
Sorting: utils.MetaLeastCost,
|
||||
SortedSuppliers: []*engine.SortedSupplier{
|
||||
{
|
||||
SupplierID: "supplier1",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.1166,
|
||||
utils.RatingPlanID: "RP_1002_LOW",
|
||||
utils.Weight: 10.0,
|
||||
},
|
||||
},
|
||||
{
|
||||
SupplierID: "supplier2",
|
||||
SupplierParameters: "",
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Cost: 0.2334,
|
||||
utils.RatingPlanID: "RP_1002",
|
||||
utils.Weight: 20.0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
args := &ArgsGetSuppliersWithApiKey{
|
||||
APIKey: "sup12345",
|
||||
ArgsGetSuppliers: engine.ArgsGetSuppliers{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Time: &nowTime,
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "Event1",
|
||||
utils.Account: "1002",
|
||||
utils.Subject: "1002",
|
||||
utils.Destination: "1001",
|
||||
utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
|
||||
utils.Usage: "1m20s",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
} else if !reflect.DeepEqual(eRpl1, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl1), utils.ToJSON(rpl))
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instSupRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRpl, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl), utils.ToJSON(rpl))
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspSupTestAuthKey(t *testing.T) {
|
||||
@@ -199,49 +201,12 @@ func testDspSupTestAuthKey(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dspSupRPC.Call(utils.SupplierSv1GetSuppliers,
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupAddAttributesWithPermision2(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.ProcessEvent&SupplierSv1.GetSuppliers", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instSupRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instSupRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupTestAuthKey2(t *testing.T) {
|
||||
var rpl *engine.SortedSuppliers
|
||||
eRpl := &engine.SortedSuppliers{
|
||||
@@ -269,7 +234,7 @@ func testDspSupTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
}
|
||||
args := &ArgsGetSuppliersWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "sup12345",
|
||||
ArgsGetSuppliers: engine.ArgsGetSuppliers{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -285,19 +250,10 @@ func testDspSupTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := dspSupRPC.Call(utils.SupplierSv1GetSuppliers,
|
||||
if err := dispEngine.RCP.Call(utils.SupplierSv1GetSuppliers,
|
||||
args, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eRpl, rpl) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl), utils.ToJSON(rpl))
|
||||
}
|
||||
}
|
||||
|
||||
func testDspSupKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,40 +18,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package dispatchers
|
||||
|
||||
/*
|
||||
import (
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) ThresholdSv1Ping(ign string, reply *string) error {
|
||||
if dS.thdS == nil {
|
||||
return utils.NewErrNotConnected(utils.ThresholdS)
|
||||
func (dS *DispatcherService) ThresholdSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.ThresholdSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.thdS.Call(utils.ThresholdSv1Ping, ign, reply)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, args.RouteID,
|
||||
utils.ThresholdSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *ArgsProcessEventWithApiKey,
|
||||
t *engine.Thresholds) (err error) {
|
||||
if dS.thdS == nil {
|
||||
return utils.NewErrNotConnected(utils.ThresholdS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.ThresholdSv1GetThresholdsForEvent,
|
||||
args.ArgsProcessEvent.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsProcessEvent.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.ThresholdSv1GetThresholdsForEvent, args.ArgsProcessEvent.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsProcessEvent.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.thdS.Call(utils.ThresholdSv1GetThresholdsForEvent, args.ArgsProcessEvent, t)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, args.RouteID,
|
||||
utils.ThresholdSv1GetThresholdsForEvent, args.ArgsProcessEvent, t)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *ArgsProcessEventWithApiKey,
|
||||
tIDs *[]string) (err error) {
|
||||
if dS.thdS == nil {
|
||||
return utils.NewErrNotConnected(utils.ThresholdS)
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.ThresholdSv1ProcessEvent,
|
||||
args.ArgsProcessEvent.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsProcessEvent.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = dS.authorize(utils.ThresholdSv1ProcessEvent, args.ArgsProcessEvent.CGREvent.Tenant,
|
||||
args.APIKey, args.ArgsProcessEvent.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
return dS.thdS.Call(utils.ThresholdSv1ProcessEvent, args.ArgsProcessEvent, tIDs)
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, args.RouteID,
|
||||
utils.ThresholdSv1ProcessEvent, args.ArgsProcessEvent, tIDs)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -21,164 +21,125 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"path"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
dspThCfgPath string
|
||||
dspThCfg *config.CGRConfig
|
||||
dspThRPC *rpc.Client
|
||||
instThCfgPath string
|
||||
instThCfg *config.CGRConfig
|
||||
instThRPC *rpc.Client
|
||||
)
|
||||
|
||||
var sTestsDspTh = []func(t *testing.T){
|
||||
testDspThInitCfg,
|
||||
testDspThInitDataDb,
|
||||
testDspThResetStorDb,
|
||||
testDspThStartEngine,
|
||||
testDspThRPCConn,
|
||||
testDspThPingFailover,
|
||||
testDspThProcessEventFailover,
|
||||
|
||||
testDspThPing,
|
||||
testDspThLoadData,
|
||||
testDspThAddAttributesWithPermision,
|
||||
testDspThTestAuthKey,
|
||||
testDspThAddAttributesWithPermision2,
|
||||
testDspThTestAuthKey2,
|
||||
testDspThKillEngine,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspThresholdS(t *testing.T) {
|
||||
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
|
||||
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
|
||||
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
|
||||
dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
|
||||
allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "tutorial"))
|
||||
allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
|
||||
attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
for _, stest := range sTestsDspTh {
|
||||
t.Run("", stest)
|
||||
}
|
||||
attrEngine.stopEngine(t)
|
||||
dispEngine.stopEngine(t)
|
||||
allEngine.stopEngine(t)
|
||||
allEngine2.stopEngine(t)
|
||||
}
|
||||
|
||||
func testDspThInitCfg(t *testing.T) {
|
||||
var err error
|
||||
dspThCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatcher")
|
||||
dspThCfg, err = config.NewCGRConfigFromFolder(dspThCfgPath)
|
||||
if err != nil {
|
||||
func testDspThPingFailover(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.ThresholdSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
dspThCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(dspThCfg)
|
||||
instThCfgPath = path.Join(dspDataDir, "conf", "samples", "tutmysql")
|
||||
instThCfg, err = config.NewCGRConfigFromFolder(instThCfgPath)
|
||||
if err != nil {
|
||||
ev := CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "thr12345",
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
instThCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
|
||||
config.SetCgrConfig(instThCfg)
|
||||
allEngine.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &ev, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &ev, &reply); err == nil {
|
||||
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
|
||||
}
|
||||
allEngine.startEngine(t)
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspThInitDataDb(t *testing.T) {
|
||||
if err := engine.InitDataDb(instThCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
func testDspThProcessEventFailover(t *testing.T) {
|
||||
var ids []string
|
||||
eIDs := []string{"THD_ACNT_1001"}
|
||||
nowTime := time.Now()
|
||||
args := &ArgsProcessEventWithApiKey{
|
||||
APIKey: "thr12345",
|
||||
ArgsProcessEvent: engine.ArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Time: &nowTime,
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "Event1",
|
||||
utils.Account: "1001"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Wipe out the cdr database
|
||||
func testDspThResetStorDb(t *testing.T) {
|
||||
if err := engine.InitStorDb(instThCfg); err != nil {
|
||||
t.Fatal(err)
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1ProcessEvent, args,
|
||||
&ids); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expected error NOT_FOUND but recived %v and reply %v\n", err, ids)
|
||||
}
|
||||
}
|
||||
|
||||
// Start CGR Engine
|
||||
func testDspThStartEngine(t *testing.T) {
|
||||
if _, err := engine.StartEngine(instThCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := engine.StartEngine(dspThCfgPath, dspDelay); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Connect rpc client to rater
|
||||
func testDspThRPCConn(t *testing.T) {
|
||||
var err error
|
||||
instThRPC, err = jsonrpc.Dial("tcp", instThCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dspThRPC, err = jsonrpc.Dial("tcp", dspThCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
allEngine2.stopEngine(t)
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1ProcessEvent, args, &ids); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eIDs, ids) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eIDs, ids)
|
||||
}
|
||||
allEngine2.startEngine(t)
|
||||
}
|
||||
|
||||
func testDspThPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := instThRPC.Call(utils.ThresholdSv1Ping, "", &reply); err != nil {
|
||||
if err := allEngine.RCP.Call(utils.ThresholdSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dspThRPC.Call(utils.ThresholdSv1Ping, "", &reply); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
APIKey: "thr12345",
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspThLoadData(t *testing.T) {
|
||||
var reply string
|
||||
attrs := &utils.AttrLoadTpFromFolder{
|
||||
FolderPath: path.Join(dspDataDir, "tariffplans", "tutorial")}
|
||||
if err := instThRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
|
||||
func testDspThAddAttributesWithPermision(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThresholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instThRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instThRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspThTestAuthKey(t *testing.T) {
|
||||
var ids []string
|
||||
nowTime := time.Now()
|
||||
@@ -195,59 +156,14 @@ func testDspThTestAuthKey(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := dspThRPC.Call(utils.ThresholdSv1ProcessEvent,
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1ProcessEvent,
|
||||
args, &ids); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
var th *engine.Thresholds
|
||||
eTh := &engine.Thresholds{
|
||||
&engine.Threshold{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "THD_ACNT_1002",
|
||||
Hits: 0,
|
||||
},
|
||||
}
|
||||
if err := dspThRPC.Call(utils.ThresholdSv1GetThresholdsForEvent, args, &th); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1GetThresholdsForEvent, args,
|
||||
&th); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eTh, th) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eTh, th)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspThAddAttributesWithPermision2(t *testing.T) {
|
||||
alsPrf := &engine.AttributeProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "AuthKey",
|
||||
Contexts: []string{utils.MetaAuth},
|
||||
FilterIDs: []string{"*string:APIKey:12345"},
|
||||
ActivationInterval: &utils.ActivationInterval{
|
||||
ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
|
||||
},
|
||||
Attributes: []*engine.Attribute{
|
||||
{
|
||||
FieldName: utils.APIMethods,
|
||||
Initial: utils.META_ANY,
|
||||
Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.ProcessEvent&ThresholdSv1.GetThresholdsForEvent", true, utils.INFIELD_SEP),
|
||||
Append: true,
|
||||
},
|
||||
},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := instThRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
alsPrf.Compile()
|
||||
var reply *engine.AttributeProfile
|
||||
if err := instThRPC.Call("ApierV1.GetAttributeProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
reply.Compile()
|
||||
if !reflect.DeepEqual(alsPrf, reply) {
|
||||
t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +172,7 @@ func testDspThTestAuthKey2(t *testing.T) {
|
||||
eIDs := []string{"THD_ACNT_1002"}
|
||||
nowTime := time.Now()
|
||||
args := &ArgsProcessEventWithApiKey{
|
||||
APIKey: "12345",
|
||||
APIKey: "thr12345",
|
||||
ArgsProcessEvent: engine.ArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
@@ -268,7 +184,7 @@ func testDspThTestAuthKey2(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
if err := dspThRPC.Call(utils.ThresholdSv1ProcessEvent, args, &ids); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1ProcessEvent, args, &ids); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(eIDs, ids) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eIDs, ids)
|
||||
@@ -281,7 +197,7 @@ func testDspThTestAuthKey2(t *testing.T) {
|
||||
Hits: 1,
|
||||
},
|
||||
}
|
||||
if err := dspThRPC.Call(utils.ThresholdSv1GetThresholdsForEvent, args, &th); err != nil {
|
||||
if err := dispEngine.RCP.Call(utils.ThresholdSv1GetThresholdsForEvent, args, &th); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual((*eTh)[0].Tenant, (*th)[0].Tenant) {
|
||||
t.Errorf("expecting: %+v, received: %+v", (*eTh)[0].Tenant, (*th)[0].Tenant)
|
||||
@@ -291,12 +207,3 @@ func testDspThTestAuthKey2(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received: %+v", (*eTh)[0].Hits, (*th)[0].Hits)
|
||||
}
|
||||
}
|
||||
|
||||
func testDspThKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := engine.KillEngine(dspDelay); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,68 +33,73 @@ var ( //var used in all tests
|
||||
nowTime = time.Now()
|
||||
)
|
||||
|
||||
type DispatcherResource struct {
|
||||
APIKey string
|
||||
RouteID *string // route over previous computed path
|
||||
}
|
||||
|
||||
type CGREvWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
utils.CGREvent
|
||||
}
|
||||
|
||||
type TntIDWithApiKey struct {
|
||||
utils.TenantID
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
}
|
||||
|
||||
type TntWithApiKey struct {
|
||||
Tenant string
|
||||
ApiKey string
|
||||
utils.TenantArg
|
||||
DispatcherResource
|
||||
}
|
||||
|
||||
type ArgsV1ResUsageWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
utils.ArgRSv1ResourceUsage
|
||||
}
|
||||
|
||||
type ArgsProcessEventWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
engine.ArgsProcessEvent
|
||||
}
|
||||
|
||||
type ArgsAttrProcessEventWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
engine.AttrArgsProcessEvent
|
||||
}
|
||||
|
||||
type ArgsGetSuppliersWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
engine.ArgsGetSuppliers
|
||||
}
|
||||
|
||||
type ArgsStatProcessEventWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
engine.StatsArgsProcessEvent
|
||||
}
|
||||
|
||||
type AuthorizeArgsWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
sessions.V1AuthorizeArgs
|
||||
}
|
||||
|
||||
type InitArgsWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
sessions.V1InitSessionArgs
|
||||
}
|
||||
|
||||
type ProcessEventWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
sessions.V1ProcessEventArgs
|
||||
}
|
||||
|
||||
type TerminateSessionWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
sessions.V1TerminateSessionArgs
|
||||
}
|
||||
|
||||
type UpdateSessionWithApiKey struct {
|
||||
APIKey string
|
||||
DispatcherResource
|
||||
sessions.V1UpdateSessionArgs
|
||||
}
|
||||
|
||||
|
||||
@@ -106,17 +106,17 @@ func testTLSRpcConn(t *testing.T) {
|
||||
func testTLSPing(t *testing.T) {
|
||||
var reply string
|
||||
|
||||
if err := tlsRpcClientJson.Call(utils.ThresholdSv1Ping, "", &reply); err != nil {
|
||||
if err := tlsRpcClientJson.Call(utils.ThresholdSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := tlsRpcClientGob.Call(utils.ThresholdSv1Ping, "", &reply); err != nil {
|
||||
if err := tlsRpcClientGob.Call(utils.ThresholdSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := tlsHTTPJson.Call(utils.ThresholdSv1Ping, "", &reply); err != nil {
|
||||
if err := tlsHTTPJson.Call(utils.ThresholdSv1Ping, &utils.CGREvent{}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
|
||||
@@ -31,7 +31,6 @@ type CGREvent struct {
|
||||
ID string
|
||||
Context *string // attach the event to a context
|
||||
Time *time.Time // event time
|
||||
RouteID *string // route over previous computed path
|
||||
Event map[string]interface{}
|
||||
}
|
||||
|
||||
|
||||
@@ -779,6 +779,10 @@ func NewTenantID(tntID string) *TenantID {
|
||||
return &TenantID{Tenant: tIDSplt[0], ID: tIDSplt[1]}
|
||||
}
|
||||
|
||||
type TenantArg struct {
|
||||
Tenant string
|
||||
}
|
||||
|
||||
type TenantID struct {
|
||||
Tenant string
|
||||
ID string
|
||||
|
||||
Reference in New Issue
Block a user