Updated SipAgent tests

This commit is contained in:
Trial97
2020-05-18 13:45:22 +03:00
committed by Dan Christian Bogos
parent c89a43dc54
commit 0b1499f009
15 changed files with 168 additions and 83 deletions

View File

@@ -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
}
}

View File

@@ -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\" <sip:1002@192.168.58.203>;tag=d28739b9\r\nTo: \"1002\" <sip:1002@192.168.58.203>\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\" <sip:1002@192.168.58.201:5060;transport=udp;registering_acc=192_168_58_203>;expires=600\r\nContent-Length: 0\r\n"
if saConn == nil {

View File

@@ -60,6 +60,7 @@
"routes": {
"enabled": true,
"rals_conns": ["*localhost"],
},

View File

@@ -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":"\" <sip:"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"~*req.To{*sipuri_user}"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"@"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"*constant:>;q=0.1"}
]
}
]
}

View File

@@ -64,6 +64,7 @@
"routes": {
"enabled": true,
"rals_conns": ["*localhost"],
},

View File

@@ -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":"\" <sip:"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"~*req.To{*sipuri_user}"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"@"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"*constant:>;q=0.1"}
]
}
]
}

View File

@@ -57,6 +57,7 @@
"routes": {
"enabled": true,
"rals_conns": ["*localhost"],
},

View File

@@ -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":"\" <sip:"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"~*req.To{*sipuri_user}"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"@"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value": "~*cgrep.Routes.SortedRoutes[2].RouteParameters"},
{"tag": "Contact", "path": "*rep.Contact", "type": "*composed",
"value":"*constant:>;q=0.1"}
]
}
]
}

View File

@@ -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,
1 #Id DestinationId RatesTag RoundingMethod RoundingDecimals MaxCost MaxCostStrategy
2 DR_20CNT *any RT_20CNT *up 4 0
3 DR_10CNT *any RT_10CNT *up 4 0
4 DR_1CNT *any RT_1CNT *up 4 0

View File

@@ -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
1 #Id ConnectFee Rate RateUnit RateIncrement GroupIntervalStart
2 RT_10CNT 0.2 0.1 60s 60s 0s
3 RT_10CNT 0 0.05 60s 1s 60s
4 RT_20CNT 0.4 0.2 60s 60s 0s
5 RT_20CNT 0 0.1 60s 1s 60s
6 RT_1CNT 0 0.01 60s 60s 0s

View File

@@ -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
1 #Id DestinationRatesId TimingTag Weight
2 RP_20CNT DR_20CNT *any 10
3 RP_10CNT DR_10CNT *any 10
4 RP_1CNT DR_1CNT *any 10

View File

@@ -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
1 #Tenant ID FilterIDs ActivationInterval Sorting SortingParameters RouteID RouteFilterIDs RouteAccountIDs RouteRatingPlanIDs RouteResourceIDs RouteStatIDs RouteWeight RouteBlocker RouteParameters Weight
2 cgrates.org SPL_ACNT_1001 *string:~*req.Account:1001 2017-11-27T00:00:00Z *weight supplier1 RP_10CNT 20 cgrates.org 20
3 cgrates.org SPL_ACNT_1001 supplier2 RP_20CNT 10 cgrates.net 10
4 cgrates.org SPL_ACNT_1001 supplier3 RP_1CNT 5 cgrates.com 5

View File

@@ -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
}

View File

@@ -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})

View File

@@ -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 {