From 0b1499f009c199e2b64737d785b49bb18e916a36 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Mon, 18 May 2020 13:45:22 +0300 Subject: [PATCH] Updated SipAgent tests --- agents/sipagent.go | 10 ++-- agents/sipagent_it_test.go | 45 +----------------- .../samples/sipagent_internal/cgrates.json | 1 + .../samples/sipagent_internal/redirect.json | 38 +++++++++++++-- data/conf/samples/sipagent_mongo/cgrates.json | 1 + .../conf/samples/sipagent_mongo/redirect.json | 38 +++++++++++++-- data/conf/samples/sipagent_mysql/cgrates.json | 1 + .../conf/samples/sipagent_mysql/redirect.json | 38 +++++++++++++-- .../tariffplans/sipagent/DestinationRates.csv | 4 ++ data/tariffplans/sipagent/Rates.csv | 6 +++ data/tariffplans/sipagent/RatingPlans.csv | 4 ++ data/tariffplans/sipagent/Routes.csv | 5 ++ engine/filters.go | 4 +- engine/ratingprofile.go | 10 ++-- engine/routes.go | 46 +++++++++++-------- 15 files changed, 168 insertions(+), 83 deletions(-) create mode 100644 data/tariffplans/sipagent/DestinationRates.csv create mode 100644 data/tariffplans/sipagent/Rates.csv create mode 100644 data/tariffplans/sipagent/RatingPlans.csv create mode 100644 data/tariffplans/sipagent/Routes.csv diff --git a/agents/sipagent.go b/agents/sipagent.go index 4aafacf20..df8b720be 100644 --- a/agents/sipagent.go +++ b/agents/sipagent.go @@ -242,16 +242,18 @@ func (sa *SIPAgent) handleMessage(sipMessage sipingo.Message, remoteHost string) utils.FirstNonEmpty(reqProcessor.Timezone, config.CgrConfig().GeneralCfg().DefaultTimezone), sa.filterS, nil, nil) - if processed, err = sa.processRequest(reqProcessor, agReq); err != nil { + var lclProcessed bool + if lclProcessed, err = sa.processRequest(reqProcessor, agReq); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> error: %s processing request: %s", utils.SIPAgent, err.Error(), utils.ToJSON(agReq))) continue } - if !processed { - continue + if lclProcessed { + processed = lclProcessed } - if processed && !reqProcessor.Flags.GetBool(utils.MetaContinue) { + if err != nil || + (lclProcessed && !reqProcessor.Flags.GetBool(utils.MetaContinue)) { break } } diff --git a/agents/sipagent_it_test.go b/agents/sipagent_it_test.go index 54e03144e..6f24ba37b 100644 --- a/agents/sipagent_it_test.go +++ b/agents/sipagent_it_test.go @@ -24,11 +24,9 @@ import ( "net" "net/rpc" "path" - "reflect" "testing" "time" - v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -48,9 +46,8 @@ var ( testSAitResetStorDb, testSAitStartEngine, testSAitApierRpcConn, - // testSAitTPFromFolder, + testSAitTPFromFolder, - testSAitSetRouteProfile, testSAitSIPRegister, testSAitSIPInvite, @@ -128,7 +125,7 @@ func testSAitApierRpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testSAitTPFromFolder(t *testing.T) { - attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} + attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "sipagent")} var loadInst utils.LoadInstance if err := saRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) @@ -142,44 +139,6 @@ func testSAitStopCgrEngine(t *testing.T) { } } -func testSAitSetRouteProfile(t *testing.T) { - var reply *engine.RouteProfile - splPrf := &v1.RouteWithCache{ - RouteProfile: &engine.RouteProfile{ - Tenant: "cgrates.org", - ID: "SPL_ACNT_1001", - FilterIDs: []string{"*string:~*req.Account:1001"}, - Sorting: utils.MetaWeight, - Routes: []*engine.Route{ - { - ID: "supplier1", - Weight: 20, - RouteParameters: "cgrates.org", - }, - { - ID: "supplier2", - Weight: 10, - RouteParameters: "cgrates.net", - }, - }, - Weight: 10, - }, - } - - var result string - if err := saRPC.Call(utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { - t.Error(err) - } else if result != utils.OK { - t.Error("Unexpected reply returned", result) - } - if err := saRPC.Call(utils.APIerSv1GetRouteProfile, - &utils.TenantID{Tenant: "cgrates.org", ID: "SPL_ACNT_1001"}, &reply); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(splPrf.RouteProfile, reply) { - t.Errorf("Expecting: %+v, received: %+v", splPrf.RouteProfile, reply) - } -} - func testSAitSIPRegister(t *testing.T) { registerMessage := "REGISTER sip:192.168.58.203 SIP/2.0\r\nCall-ID: d72a4ed6feb4167b5adb208525879db5@0:0:0:0:0:0:0:0\r\nCSeq: 1 REGISTER\r\nFrom: \"1002\" ;tag=d28739b9\r\nTo: \"1002\" \r\nVia: SIP/2.0/UDP 192.168.58.201:5060;branch=z9hG4bK-323131-311ce8716a7bf1f6094859ae516a44eb\r\nMax-Forwards: 70\r\nUser-Agent: Jitsi2.11.20200408Linux\r\nExpires: 600\r\nContact: \"1002\" ;expires=600\r\nContent-Length: 0\r\n" if saConn == nil { diff --git a/data/conf/samples/sipagent_internal/cgrates.json b/data/conf/samples/sipagent_internal/cgrates.json index 6c3b4ac8f..19affd140 100644 --- a/data/conf/samples/sipagent_internal/cgrates.json +++ b/data/conf/samples/sipagent_internal/cgrates.json @@ -60,6 +60,7 @@ "routes": { "enabled": true, + "rals_conns": ["*localhost"], }, diff --git a/data/conf/samples/sipagent_internal/redirect.json b/data/conf/samples/sipagent_internal/redirect.json index 9c5d69576..268ab9c8b 100644 --- a/data/conf/samples/sipagent_internal/redirect.json +++ b/data/conf/samples/sipagent_internal/redirect.json @@ -21,6 +21,10 @@ "value": "~*req.From{*sipuri_user}", "mandatory": true}, {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.To{*sipuri_user}", "mandatory": true}, + {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", + "value": "*now", "mandatory": true}, + {"tag": "Category", "path": "*cgreq.Category", "type": "*variable", + "value": "call", "mandatory": true}, ], "reply_fields":[ ] @@ -28,8 +32,10 @@ { "id": "NAPTRSuppliersOneSupplier", "filters": ["*string:~*vars.Method:INVITE", - ], - "flags": ["*none","*continue","*log"], // do not send request to CGRateS + "*gte:~*cgrep.Routes.Count:1", + "*gte:~*cgrep.Routes.SortedRoutes[0].SortingData.Cost:0.1", + ], + "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "Request", "path": "*rep.Request", "type": "*constant", "value": "SIP/2.0 302 Moved Temporarily"}, @@ -52,7 +58,9 @@ { "id": "NAPTRSuppliersTwoSuppliers", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes.Count:2"], + "*gte:~*cgrep.Routes.Count:2", + "*gte:~*cgrep.Routes.SortedRoutes[1].SortingData.Cost:0.1", + ], "flags": ["*none","*continue"], "reply_fields":[ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", @@ -70,6 +78,30 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"*constant:>;q=0.1"} ] + }, + { + "id": "NAPTRSuppliersThreeSuppliers", + "filters": ["*string:~*vars.Method:INVITE", + "*gte:~*cgrep.Routes.Count:3", + "*gte:~*cgrep.Routes.SortedRoutes[2].SortingData.Cost:0.1", + ], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":",\""}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*req.To{*sipuri_user}"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"\" ;q=0.1"} + ] } ] } diff --git a/data/conf/samples/sipagent_mongo/cgrates.json b/data/conf/samples/sipagent_mongo/cgrates.json index d4dc52da9..f37085ffe 100644 --- a/data/conf/samples/sipagent_mongo/cgrates.json +++ b/data/conf/samples/sipagent_mongo/cgrates.json @@ -64,6 +64,7 @@ "routes": { "enabled": true, + "rals_conns": ["*localhost"], }, diff --git a/data/conf/samples/sipagent_mongo/redirect.json b/data/conf/samples/sipagent_mongo/redirect.json index 9c5d69576..268ab9c8b 100644 --- a/data/conf/samples/sipagent_mongo/redirect.json +++ b/data/conf/samples/sipagent_mongo/redirect.json @@ -21,6 +21,10 @@ "value": "~*req.From{*sipuri_user}", "mandatory": true}, {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.To{*sipuri_user}", "mandatory": true}, + {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", + "value": "*now", "mandatory": true}, + {"tag": "Category", "path": "*cgreq.Category", "type": "*variable", + "value": "call", "mandatory": true}, ], "reply_fields":[ ] @@ -28,8 +32,10 @@ { "id": "NAPTRSuppliersOneSupplier", "filters": ["*string:~*vars.Method:INVITE", - ], - "flags": ["*none","*continue","*log"], // do not send request to CGRateS + "*gte:~*cgrep.Routes.Count:1", + "*gte:~*cgrep.Routes.SortedRoutes[0].SortingData.Cost:0.1", + ], + "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "Request", "path": "*rep.Request", "type": "*constant", "value": "SIP/2.0 302 Moved Temporarily"}, @@ -52,7 +58,9 @@ { "id": "NAPTRSuppliersTwoSuppliers", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes.Count:2"], + "*gte:~*cgrep.Routes.Count:2", + "*gte:~*cgrep.Routes.SortedRoutes[1].SortingData.Cost:0.1", + ], "flags": ["*none","*continue"], "reply_fields":[ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", @@ -70,6 +78,30 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"*constant:>;q=0.1"} ] + }, + { + "id": "NAPTRSuppliersThreeSuppliers", + "filters": ["*string:~*vars.Method:INVITE", + "*gte:~*cgrep.Routes.Count:3", + "*gte:~*cgrep.Routes.SortedRoutes[2].SortingData.Cost:0.1", + ], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":",\""}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*req.To{*sipuri_user}"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"\" ;q=0.1"} + ] } ] } diff --git a/data/conf/samples/sipagent_mysql/cgrates.json b/data/conf/samples/sipagent_mysql/cgrates.json index 56f79ef18..b2ff48fad 100644 --- a/data/conf/samples/sipagent_mysql/cgrates.json +++ b/data/conf/samples/sipagent_mysql/cgrates.json @@ -57,6 +57,7 @@ "routes": { "enabled": true, + "rals_conns": ["*localhost"], }, diff --git a/data/conf/samples/sipagent_mysql/redirect.json b/data/conf/samples/sipagent_mysql/redirect.json index 9c5d69576..268ab9c8b 100644 --- a/data/conf/samples/sipagent_mysql/redirect.json +++ b/data/conf/samples/sipagent_mysql/redirect.json @@ -21,6 +21,10 @@ "value": "~*req.From{*sipuri_user}", "mandatory": true}, {"tag": "Destination", "path": "*cgreq.Destination", "type": "*variable", "value": "~*req.To{*sipuri_user}", "mandatory": true}, + {"tag": "SetupTime", "path": "*cgreq.SetupTime", "type": "*variable", + "value": "*now", "mandatory": true}, + {"tag": "Category", "path": "*cgreq.Category", "type": "*variable", + "value": "call", "mandatory": true}, ], "reply_fields":[ ] @@ -28,8 +32,10 @@ { "id": "NAPTRSuppliersOneSupplier", "filters": ["*string:~*vars.Method:INVITE", - ], - "flags": ["*none","*continue","*log"], // do not send request to CGRateS + "*gte:~*cgrep.Routes.Count:1", + "*gte:~*cgrep.Routes.SortedRoutes[0].SortingData.Cost:0.1", + ], + "flags": ["*none","*continue"], // do not send request to CGRateS "reply_fields":[ {"tag": "Request", "path": "*rep.Request", "type": "*constant", "value": "SIP/2.0 302 Moved Temporarily"}, @@ -52,7 +58,9 @@ { "id": "NAPTRSuppliersTwoSuppliers", "filters": ["*string:~*vars.Method:INVITE", - "*gte:~*cgrep.Routes.Count:2"], + "*gte:~*cgrep.Routes.Count:2", + "*gte:~*cgrep.Routes.SortedRoutes[1].SortingData.Cost:0.1", + ], "flags": ["*none","*continue"], "reply_fields":[ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", @@ -70,6 +78,30 @@ {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", "value":"*constant:>;q=0.1"} ] + }, + { + "id": "NAPTRSuppliersThreeSuppliers", + "filters": ["*string:~*vars.Method:INVITE", + "*gte:~*cgrep.Routes.Count:3", + "*gte:~*cgrep.Routes.SortedRoutes[2].SortingData.Cost:0.1", + ], + "flags": ["*none","*continue"], + "reply_fields":[ + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":",\""}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"~*req.To{*sipuri_user}"}, + {"tag": "Contact", "path": "*rep.Contact", "type": "*composed", + "value":"\" ;q=0.1"} + ] } ] } diff --git a/data/tariffplans/sipagent/DestinationRates.csv b/data/tariffplans/sipagent/DestinationRates.csv new file mode 100644 index 000000000..695ede228 --- /dev/null +++ b/data/tariffplans/sipagent/DestinationRates.csv @@ -0,0 +1,4 @@ +#Id,DestinationId,RatesTag,RoundingMethod,RoundingDecimals,MaxCost,MaxCostStrategy +DR_20CNT,*any,RT_20CNT,*up,4,0, +DR_10CNT,*any,RT_10CNT,*up,4,0, +DR_1CNT,*any,RT_1CNT,*up,4,0, diff --git a/data/tariffplans/sipagent/Rates.csv b/data/tariffplans/sipagent/Rates.csv new file mode 100644 index 000000000..5f8339565 --- /dev/null +++ b/data/tariffplans/sipagent/Rates.csv @@ -0,0 +1,6 @@ +#Id,ConnectFee,Rate,RateUnit,RateIncrement,GroupIntervalStart +RT_10CNT,0.2,0.1,60s,60s,0s +RT_10CNT,0,0.05,60s,1s,60s +RT_20CNT,0.4,0.2,60s,60s,0s +RT_20CNT,0,0.1,60s,1s,60s +RT_1CNT,0,0.01,60s,60s,0s \ No newline at end of file diff --git a/data/tariffplans/sipagent/RatingPlans.csv b/data/tariffplans/sipagent/RatingPlans.csv new file mode 100644 index 000000000..f0e228a8c --- /dev/null +++ b/data/tariffplans/sipagent/RatingPlans.csv @@ -0,0 +1,4 @@ +#Id,DestinationRatesId,TimingTag,Weight +RP_20CNT,DR_20CNT,*any,10 +RP_10CNT,DR_10CNT,*any,10 +RP_1CNT,DR_1CNT,*any,10 \ No newline at end of file diff --git a/data/tariffplans/sipagent/Routes.csv b/data/tariffplans/sipagent/Routes.csv new file mode 100644 index 000000000..2afc6f1c8 --- /dev/null +++ b/data/tariffplans/sipagent/Routes.csv @@ -0,0 +1,5 @@ +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParameters,RouteID,RouteFilterIDs,RouteAccountIDs,RouteRatingPlanIDs,RouteResourceIDs,RouteStatIDs,RouteWeight,RouteBlocker,RouteParameters,Weight +cgrates.org,SPL_ACNT_1001,*string:~*req.Account:1001,2017-11-27T00:00:00Z,*weight,,supplier1,,,RP_10CNT,,,20,,cgrates.org,20 +cgrates.org,SPL_ACNT_1001,,,,,supplier2,,,RP_20CNT,,,10,,cgrates.net,10 +cgrates.org,SPL_ACNT_1001,,,,,supplier3,,,RP_1CNT,,,5,,cgrates.com,5 + diff --git a/engine/filters.go b/engine/filters.go index f4920f9ff..3fa2f3fd5 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -53,6 +53,7 @@ func (fS *FilterS) Pass(tenant string, filterIDs []string, if len(filterIDs) == 0 { return true, nil } + dDP := newDynamicDP(fS.cfg, fS.connMgr, tenant, ev) for _, fltrID := range filterIDs { f, err := fS.dm.GetFilter(tenant, fltrID, true, true, utils.NonTransactional) @@ -66,7 +67,6 @@ func (fS *FilterS) Pass(tenant string, filterIDs []string, !f.ActivationInterval.IsActiveAtTime(time.Now()) { // not active continue } - dDP := newDynamicDP(fS.cfg, fS.connMgr, tenant, ev) for _, fltr := range f.Rules { if pass, err = fltr.Pass(dDP); err != nil || !pass { return pass, err @@ -117,6 +117,7 @@ func (fS *FilterS) LazyPass(tenant string, filterIDs []string, return true, nil, nil } pass = true + dDP := newDynamicDP(fS.cfg, fS.connMgr, tenant, ev) for _, fltrID := range filterIDs { var f *Filter f, err = fS.dm.GetFilter(tenant, fltrID, @@ -137,7 +138,6 @@ func (fS *FilterS) LazyPass(tenant string, filterIDs []string, lazyCheckRules = append(lazyCheckRules, rule) continue } - dDP := newDynamicDP(fS.cfg, fS.connMgr, tenant, ev) if pass, err = rule.Pass(dDP); err != nil || !pass { return } diff --git a/engine/ratingprofile.go b/engine/ratingprofile.go index f41bfef25..199d83a53 100644 --- a/engine/ratingprofile.go +++ b/engine/ratingprofile.go @@ -167,14 +167,14 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error continue } prefix := "" - destinationId := "" + destinationID := "" var rps RateIntervalList if cd.Destination == utils.ANY || cd.Destination == "" { cd.Destination = utils.ANY if _, ok := rpl.DestinationRates[utils.ANY]; ok { rps = rpl.RateIntervalList(utils.ANY) prefix = utils.ANY - destinationId = utils.ANY + destinationID = utils.ANY } } else { for _, p := range utils.SplitPrefix(cd.Destination, MIN_PREFIX_MATCH) { @@ -198,7 +198,7 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error bestWeight = utils.Float64Pointer(currentWeight) rps = ril prefix = p - destinationId = dID + destinationID = dID } } } @@ -211,7 +211,7 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error if _, ok := rpl.DestinationRates[utils.ANY]; ok { rps = rpl.RateIntervalList(utils.ANY) prefix = utils.ANY - destinationId = utils.ANY + destinationID = utils.ANY } } } @@ -230,7 +230,7 @@ func (rpf *RatingProfile) GetRatingPlansForPrefix(cd *CallDescriptor) (err error MatchedSubject: rpf.Id, RatingPlanId: rpl.Id, MatchedPrefix: prefix, - MatchedDestId: destinationId, + MatchedDestId: destinationID, ActivationTime: rpa.ActivationTime, RateIntervals: rps, FallbackKeys: rpa.FallbackKeys}) diff --git a/engine/routes.go b/engine/routes.go index 4ed8cc9e4..884482fc2 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -59,7 +59,7 @@ type RouteProfile struct { cache map[string]interface{} } -// SupplierProfileWithArgDispatcher is used in replicatorV1 for dispatcher +// RouteProfileWithArgDispatcher is used in replicatorV1 for dispatcher type RouteProfileWithArgDispatcher struct { *RouteProfile *utils.ArgDispatcher @@ -211,6 +211,7 @@ func (rpS *RouteService) matchingRouteProfilesForEvent(ev *utils.CGREvent, singl // returns map[string]interface{} with cost and relevant matching information inside func (rpS *RouteService) costForEvent(ev *utils.CGREvent, acntIDs, rpIDs []string) (costData map[string]interface{}, err error) { + costData = make(map[string]interface{}) if err = ev.CheckMandatoryFields([]string{utils.Account, utils.Destination, utils.SetupTime}); err != nil { return @@ -241,6 +242,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, usage = time.Duration(1 * time.Minute) err = nil } + var rplyVals map[string]interface{} if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().ResponderSConns, nil, utils.ResponderGetMaxSessionTimeOnAccounts, &utils.GetMaxSessionTimeOnAccountsArgs{ Tenant: ev.Tenant, @@ -249,9 +251,13 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, SetupTime: sTime, Usage: usage, AccountIDs: acntIDs, - }, &costData); err != nil { + }, &rplyVals); err != nil { return nil, err } + for k, v := range rplyVals { // do not overwrite the return map + costData[k] = v + } + rplyVals = make(map[string]interface{}) // reset the map if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().ResponderSConns, nil, utils.ResponderGetCostOnRatingPlans, &utils.GetCostOnRatingPlansArgs{ Tenant: ev.Tenant, @@ -261,9 +267,12 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, SetupTime: sTime, Usage: usage, RatingPlanIDs: rpIDs, - }, &costData); err != nil { + }, &rplyVals); err != nil { return nil, err } + for k, v := range rplyVals { + costData[k] = v + } return } @@ -320,12 +329,12 @@ func (rpS *RouteService) statMetricsForLoadDistribution(statIDs []string, tenant } if len(statWithMetric) == 2 { // in case we have MetricID defined with StatID we consider only that metric // check if statQueue have metric defined - if metricVal, has := metrics[statWithMetric[1]]; !has { + metricVal, has := metrics[statWithMetric[1]] + if !has { return 0, fmt.Errorf("<%s> error: %s metric %s for statID: %s", utils.RouteS, utils.ErrNotFound, statWithMetric[1], statWithMetric[0]) - } else { - provStsMetrics[statWithMetric[1]] = append(provStsMetrics[statWithMetric[1]], metricVal) } + provStsMetrics[statWithMetric[1]] = append(provStsMetrics[statWithMetric[1]], metricVal) } else { // otherwise we consider all metrics for key, val := range metrics { //add value of metric in a slice in case that we get the same metric from different stat @@ -379,9 +388,8 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route, fmt.Sprintf("<%s> ignoring route with ID: %s, err: %s", utils.RouteS, route.ID, err.Error())) return nil, false, nil - } else { - return nil, false, err } + return nil, false, err } else if len(costData) == 0 { utils.Logger.Warning( fmt.Sprintf("<%s> ignoring route with ID: %s, missing cost information", @@ -407,9 +415,8 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route, fmt.Sprintf("<%s> ignoring supplier with ID: %s, err: %s", utils.RouteS, route.ID, err.Error())) return nil, false, nil - } else { - return nil, false, err } + return nil, false, err } sortedSpl.SortingData[utils.Load] = metricSum } else { @@ -420,9 +427,8 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route, fmt.Sprintf("<%s> ignoring supplier with ID: %s, err: %s", utils.RouteS, route.ID, err.Error())) return nil, false, nil - } else { - return nil, false, err } + return nil, false, err } //add metrics from statIDs in SortingData for key, val := range metricSupp { @@ -452,22 +458,21 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route, fmt.Sprintf("<%s> ignoring supplier with ID: %s, err: %s", utils.RouteS, route.ID, err.Error())) return nil, false, nil - } else { - return nil, false, err } + return nil, false, err } sortedSpl.SortingData[utils.ResourceUsage] = resTotalUsage } //filter the supplier if len(route.lazyCheckRules) != 0 { //construct the DP and pass it to filterS - nM := utils.MapStorage{ + dynDP := newDynamicDP(rpS.cgrcfg, rpS.connMgr, ev.Tenant, utils.MapStorage{ utils.MetaReq: ev.Event, utils.MetaVars: sortedSpl.SortingData, - } + }) for _, rule := range route.lazyCheckRules { // verify the rules remaining from PartialPass - if pass, err = rule.Pass(newDynamicDP(rpS.cgrcfg, rpS.connMgr, ev.Tenant, nM)); err != nil { + if pass, err = rule.Pass(dynDP); err != nil { return nil, false, err } else if !pass { return nil, false, nil @@ -532,6 +537,7 @@ func (rpS *RouteService) sortedRoutesForEvent(args *ArgsGetRoutes) (sortedRoutes return } +// ArgsGetRoutes the argument for GetRoutes API type ArgsGetRoutes struct { IgnoreErrors bool MaxCost string // toDo: try with interface{} here @@ -553,11 +559,11 @@ func (args *ArgsGetRoutes) asOptsGetRoutes() (opts *optsGetRoutes, err error) { if err != nil { return nil, err } - if cc, err := cd.GetCost(); err != nil { + cc, err := cd.GetCost() + if err != nil { return nil, err - } else { - opts.maxCost = cc.Cost } + opts.maxCost = cc.Cost } else if args.MaxCost != "" { if opts.maxCost, err = strconv.ParseFloat(args.MaxCost, 64); err != nil {