From 14ebcb38120dc865ebce8b140cecd6eba18899f1 Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 27 May 2019 14:31:35 +0300 Subject: [PATCH] Replacing CGREvent with *CGRevent when inherited for ThresholdService --- apier/v1/filterindexecache_it_test.go | 18 +++++++++--------- apier/v1/thresholds_it_test.go | 18 +++++++++--------- dispatchers/thresholds.go | 8 ++++++++ dispatchers/thresholds_it_test.go | 6 +++--- engine/account.go | 4 ++-- engine/balances.go | 6 +++--- engine/cdrs.go | 2 +- engine/resources.go | 2 +- engine/stats.go | 2 +- engine/thresholds.go | 6 +++--- engine/thresholds_test.go | 6 +++--- sessions/sessions.go | 8 ++++---- 12 files changed, 47 insertions(+), 39 deletions(-) diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 7eb182f6d..b88d323d5 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -140,7 +140,7 @@ func testV1FIdxCaFromFolder(t *testing.T) { //ThresholdProfile func testV1FIdxCaProcessEventWithNotFound(t *testing.T) { tEv := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event1", Event: map[string]interface{}{ @@ -205,7 +205,7 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { //matches TEST_PROFILE1 tEv := &engine.ArgsProcessEvent{ ThresholdIDs: []string{"TEST_PROFILE1"}, - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event1", Event: map[string]interface{}{ @@ -226,7 +226,7 @@ func testV1FIdxCaGetThresholdFromTP(t *testing.T) { //matches THD_ACNT_BALANCE_1 tEv := &engine.ArgsProcessEvent{ ThresholdIDs: []string{"THD_ACNT_BALANCE_1"}, - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event1", Event: map[string]interface{}{ @@ -295,7 +295,7 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { } //make sure doesn't match the thresholdprofile after update tEv := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event1", Event: map[string]interface{}{ @@ -310,7 +310,7 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { } //matches thresholdprofile after update tEv2 := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event1", Event: map[string]interface{}{ @@ -374,7 +374,7 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { t.Error("Unexpected reply returned", result) } tEv := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event1", Event: map[string]interface{}{ @@ -387,7 +387,7 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { t.Error(err) } tEv2 := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event3", Event: map[string]interface{}{ @@ -405,7 +405,7 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { var resp string tEv := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event8", Event: map[string]interface{}{ @@ -420,7 +420,7 @@ func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { } tEv2 := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "event9", Event: map[string]interface{}{ diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index b06da489d..d64756bf5 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -247,53 +247,53 @@ func testV1TSGetThresholds(t *testing.T) { func testV1TSProcessEvent(t *testing.T) { var ids []string eIDs := []string{} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[0], &ids); err == nil || + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[0], &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } eIDs = []string{"THD_ACNT_BALANCE_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[1], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[1], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_STATS_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[2], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[2], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_STATS_2", "THD_STATS_1"} eIDs2 := []string{"THD_STATS_1", "THD_STATS_2"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[3], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[3], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) && !reflect.DeepEqual(ids, eIDs2) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_STATS_3"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[4], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[4], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_RES_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[5], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[5], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[6], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[6], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[7], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[7], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_CDRS_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[8], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[8], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) diff --git a/dispatchers/thresholds.go b/dispatchers/thresholds.go index df17aecd2..db2eff08f 100755 --- a/dispatchers/thresholds.go +++ b/dispatchers/thresholds.go @@ -57,11 +57,15 @@ func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *engine.Args return } } +<<<<<<< HEAD var routeID *string if args.ArgDispatcher != nil { routeID = args.ArgDispatcher.RouteID } return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, routeID, +======= + return dS.Dispatch(args.CGREvent, utils.MetaThresholds, args.RouteID, +>>>>>>> Replacing CGREvent with *CGRevent when inherited for ThresholdService utils.ThresholdSv1GetThresholdsForEvent, args, t) } @@ -77,11 +81,15 @@ func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *engine.ArgsProcessEv return } } +<<<<<<< HEAD var routeID *string if args.ArgDispatcher != nil { routeID = args.ArgDispatcher.RouteID } return dS.Dispatch(&args.CGREvent, utils.MetaThresholds, routeID, +======= + return dS.Dispatch(args.CGREvent, utils.MetaThresholds, args.RouteID, +>>>>>>> Replacing CGREvent with *CGRevent when inherited for ThresholdService utils.ThresholdSv1ProcessEvent, args, tIDs) } diff --git a/dispatchers/thresholds_it_test.go b/dispatchers/thresholds_it_test.go index 1d09e1b48..9a37e48f0 100755 --- a/dispatchers/thresholds_it_test.go +++ b/dispatchers/thresholds_it_test.go @@ -88,7 +88,7 @@ func testDspThProcessEventFailover(t *testing.T) { eIDs := []string{"THD_ACNT_1001"} nowTime := time.Now() args := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: utils.UUIDSha1Prefix(), Time: &nowTime, @@ -139,7 +139,7 @@ func testDspThTestAuthKey(t *testing.T) { var ids []string nowTime := time.Now() args := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: utils.UUIDSha1Prefix(), Time: &nowTime, @@ -167,7 +167,7 @@ func testDspThTestAuthKey2(t *testing.T) { eIDs := []string{"THD_ACNT_1002"} nowTime := time.Now() args := &engine.ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: utils.UUIDSha1Prefix(), Time: &nowTime, diff --git a/engine/account.go b/engine/account.go index 611235346..2fe9ec7f6 100644 --- a/engine/account.go +++ b/engine/account.go @@ -535,7 +535,7 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo //send default balance to thresholdS to be processed acntTnt := utils.NewTenantID(ub.ID) thEv := &ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: acntTnt.Tenant, ID: utils.GenUUID(), Event: map[string]interface{}{ @@ -1106,7 +1106,7 @@ func (acnt *Account) Publish() { if thresholdS != nil { var tIDs []string if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent, - &ArgsProcessEvent{CGREvent: cgrEv}, &tIDs); err != nil && + &ArgsProcessEvent{CGREvent: &cgrEv}, &tIDs); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( fmt.Sprintf(" error: %s processing account event %+v with ThresholdS.", err.Error(), cgrEv)) diff --git a/engine/balances.go b/engine/balances.go index 7579af278..d3813a1dc 100644 --- a/engine/balances.go +++ b/engine/balances.go @@ -715,7 +715,7 @@ func (b *Balance) Publish() { } if thresholdS != nil { var tIDs []string - if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent, &ArgsProcessEvent{CGREvent: cgrEv}, &tIDs); err != nil && + if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent, &ArgsProcessEvent{CGREvent: &cgrEv}, &tIDs); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( fmt.Sprintf(" error: %s processing balance event %+v with ThresholdS.", @@ -807,7 +807,7 @@ func (bc Balances) SaveDirtyBalances(acc *Account) { } acntTnt := utils.NewTenantID(b.account.ID) thEv := &ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: acntTnt.Tenant, ID: utils.GenUUID(), Event: map[string]interface{}{ @@ -838,7 +838,7 @@ func (bc Balances) SaveDirtyBalances(acc *Account) { for _, acnt := range savedAccounts { acntTnt := utils.NewTenantID(acnt.ID) thEv := &ArgsProcessEvent{ - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: acntTnt.Tenant, ID: utils.GenUUID(), Event: map[string]interface{}{ diff --git a/engine/cdrs.go b/engine/cdrs.go index fe85d806d..bfa5b4e65 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -348,7 +348,7 @@ func (cdrS *CDRServer) attrSProcessEvent(cgrEv *utils.CGREventWithArgDispatcher) // thdSProcessEvent will send the event to ThresholdS if the connection is configured func (cdrS *CDRServer) thdSProcessEvent(cgrEv *utils.CGREventWithArgDispatcher) { var tIDs []string - thArgs := &ArgsProcessEvent{CGREvent: *(cgrEv.CGREvent)} + thArgs := &ArgsProcessEvent{CGREvent: cgrEv.CGREvent} if cgrEv.ArgDispatcher != nil { thArgs.ArgDispatcher = cgrEv.ArgDispatcher } diff --git a/engine/resources.go b/engine/resources.go index f6aadf5e0..96c758975 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -417,7 +417,7 @@ func (rS *ResourceService) processThresholds(r *Resource, argDispatcher *utils.A thIDs = r.rPrf.ThresholdIDs } thEv := &ArgsProcessEvent{ThresholdIDs: thIDs, - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: r.Tenant, ID: utils.GenUUID(), Event: map[string]interface{}{ diff --git a/engine/stats.go b/engine/stats.go index 92dca3679..c5bb0bc33 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -276,7 +276,7 @@ func (sS *StatService) processEvent(args *StatsArgsProcessEvent) (statQueueIDs [ } thEv := &ArgsProcessEvent{ ThresholdIDs: thIDs, - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: sq.Tenant, ID: utils.GenUUID(), Event: map[string]interface{}{ diff --git a/engine/thresholds.go b/engine/thresholds.go index 9f5cdf7d3..91abe20ab 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -278,7 +278,7 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ArgsProcessEvent) ( type ArgsProcessEvent struct { ThresholdIDs []string - utils.CGREvent + *utils.CGREvent *utils.ArgDispatcher } @@ -342,7 +342,7 @@ func (tS *ThresholdService) processEvent(args *ArgsProcessEvent) (thresholdsIDs func (tS *ThresholdService) V1ProcessEvent(args *ArgsProcessEvent, reply *[]string) (err error) { if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) - } else if args.CGREvent.Event == nil { + } else if args.CGREvent == nil || args.CGREvent.Event == nil { return utils.NewErrMandatoryIeMissing("Event") } if ids, err := tS.processEvent(args); err != nil { @@ -357,7 +357,7 @@ func (tS *ThresholdService) V1ProcessEvent(args *ArgsProcessEvent, reply *[]stri func (tS *ThresholdService) V1GetThresholdsForEvent(args *ArgsProcessEvent, reply *Thresholds) (err error) { if missing := utils.MissingStructFields(args, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) - } else if args.CGREvent.Event == nil { + } else if args.CGREvent == nil || args.CGREvent.Event == nil { return utils.NewErrMandatoryIeMissing("Event") } var ts Thresholds diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index f6c76e1c6..382a3e4ee 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -91,7 +91,7 @@ var ( } argsGetThresholds = []*ArgsProcessEvent{ { - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "Ev1", Event: map[string]interface{}{ @@ -101,7 +101,7 @@ var ( }, }, { - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "Ev1", Event: map[string]interface{}{ @@ -111,7 +111,7 @@ var ( }, }, { - CGREvent: utils.CGREvent{ + CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "Ev1", Event: map[string]interface{}{ diff --git a/sessions/sessions.go b/sessions/sessions.go index 89079e65e..efea862ae 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1857,7 +1857,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection, } var tIDs []string thEv := &engine.ArgsProcessEvent{ - CGREvent: args.CGREvent, + CGREvent: &args.CGREvent, ArgDispatcher: args.ArgDispatcher, } if err := sS.thdS.Call(utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil && @@ -2105,7 +2105,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection, } var tIDs []string thEv := &engine.ArgsProcessEvent{ - CGREvent: args.CGREvent, + CGREvent: &args.CGREvent, ArgDispatcher: args.ArgDispatcher, } if err := sS.thdS.Call(utils.ThresholdSv1ProcessEvent, @@ -2431,7 +2431,7 @@ func (sS *SessionS) BiRPCv1TerminateSession(clnt rpcclient.RpcClientConnection, } var tIDs []string thEv := &engine.ArgsProcessEvent{ - CGREvent: args.CGREvent, + CGREvent: &args.CGREvent, ArgDispatcher: args.ArgDispatcher, } if err := sS.thdS.Call(utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil && @@ -2741,7 +2741,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.RpcClientConnection, } var tIDs []string thEv := &engine.ArgsProcessEvent{ - CGREvent: args.CGREvent, + CGREvent: &args.CGREvent, ArgDispatcher: args.ArgDispatcher, } if err := sS.thdS.Call(utils.ThresholdSv1ProcessEvent,