Update RouteBlockers behaviour

This commit is contained in:
ionutboangiu
2022-05-03 17:03:37 +03:00
committed by Dan Christian Bogos
parent a8a68a418e
commit faae62f89a
10 changed files with 39 additions and 13 deletions

View File

@@ -216,7 +216,6 @@ func (aS *ActionS) scheduledActions(ctx *context.Context, tnt string, cgrEv *uti
}
for _, aPf := range aPfs {
ctx := context.Background()
trgActs := map[string][]actioner{} // build here the list of actioners based on the trgKey
var partExec bool
for _, aCfg := range aPf.Actions { // create actioners and attach them to the right target

View File

@@ -879,7 +879,6 @@ func testActionsBlockerSetActionProfile(t *testing.T) {
Type: utils.MetaAddBalance,
Diktats: []*engine.APDiktat{
{
// Path: "~*accounts.ACCOUNT_BLOCKER_TEST.Balances[BALANCE_TEST].Units",
Path: "*balance.BALANCE_TEST.Units",
Value: "1",
},

View File

@@ -774,17 +774,25 @@ func testRouteSGetRoutes(t *testing.T) {
Sorting: utils.MetaWeight,
Routes: []*engine.SortedRoute{
{
RouteID: "route2",
RouteID: "route3",
RouteParameters: utils.EmptyString,
SortingData: map[string]interface{}{
utils.Weight: 20.,
utils.Weight: 40.,
},
},
{
RouteID: "route1",
RouteID: "route4",
RouteParameters: utils.EmptyString,
SortingData: map[string]interface{}{
utils.Weight: 10.,
utils.Weight: 35.,
},
},
{
RouteID: "route2",
RouteParameters: utils.EmptyString,
SortingData: map[string]interface{}{
utils.Weight: 20.,
utils.Blocker: true,
},
},
},

View File

@@ -311,5 +311,6 @@ func routeLazyPass(ctx *context.Context, filters []*FilterRule, ev *utils.CGREve
type RouteWithWeight struct {
*Route
Weight float64
blocker bool
lazyCheckRules []*FilterRule
}

View File

@@ -51,6 +51,9 @@ func populateCostForRoutes(ctx *context.Context, cfg *config.CGRConfig,
},
RouteParameters: route.RouteParameters,
}
if route.blocker {
srtRoute.SortingData[utils.Blocker] = true
}
var cost *utils.Decimal
if len(route.AccountIDs) != 0 { // query AccountS for cost

View File

@@ -68,6 +68,9 @@ func (ws *LoadDistributionSorter) SortRoutes(ctx *context.Context, prflID string
},
RouteParameters: route.RouteParameters,
}
if route.blocker {
srtRoute.SortingData[utils.Blocker] = true
}
var metricSum *utils.Decimal
if metricSum, err = populateStatsForLoadRoute(ctx, ws.cfg, ws.connMgr, route.StatIDs, ev.Tenant); err != nil { //create metric map for route
if extraOpts.ignoreErrors {

View File

@@ -58,6 +58,9 @@ func (qos *QOSRouteSorter) SortRoutes(ctx *context.Context, prflID string, route
},
RouteParameters: route.RouteParameters,
}
if route.blocker {
srtRoute.SortingData[utils.Blocker] = true
}
var metricSupp map[string]*utils.Decimal
if metricSupp, err = populatStatsForQOSRoute(ctx, qos.cfg, qos.connMgr, route.StatIDs, ev.Tenant); err != nil { //create metric map for route
if extraOpts.ignoreErrors {

View File

@@ -51,6 +51,9 @@ func populateResourcesForRoutes(ctx *context.Context, cfg *config.CGRConfig,
},
RouteParameters: route.RouteParameters,
}
if route.blocker {
srtRoute.SortingData[utils.Blocker] = true
}
var tUsage float64
for _, resID := range route.ResourceIDs {
var res Resource

View File

@@ -51,6 +51,9 @@ func (ws *WeightSorter) SortRoutes(ctx *context.Context, prflID string,
},
RouteParameters: route.RouteParameters,
}
if route.blocker {
srtRoute.SortingData[utils.Blocker] = true
}
var pass bool
if pass, err = routeLazyPass(ctx, route.lazyCheckRules, ev, srtRoute.SortingData,
ws.cfg.FilterSCfg().ResourceSConns,

View File

@@ -369,25 +369,29 @@ func (rpS *RouteS) sortedRoutesForProfile(ctx *context.Context, tnt string, rPrf
return
}
if prev, has := passedRoutes[route.ID]; !has || prev.Weight < weight {
var blocker bool
if blocker, err = BlockerFromDynamics(ctx, route.Blockers, rpS.fltrS, tnt, nM); err != nil {
return
}
passedRoutes[route.ID] = &RouteWithWeight{
Route: route,
lazyCheckRules: lazyCheckRules,
Weight: weight,
blocker: blocker,
}
}
var blocker bool
if blocker, err = BlockerFromDynamics(ctx, route.Blockers, rpS.fltrS, tnt, nM); err != nil {
return
}
if blocker {
break
}
}
if sortedRoutes, err = rpS.sorter.SortRoutes(ctx, rPrfl.ID, rPrfl.Sorting,
passedRoutes, ev, extraOpts); err != nil {
return nil, err
}
for i, sortedRoute := range sortedRoutes.Routes {
if _, has := sortedRoute.SortingData[utils.Blocker]; has {
sortedRoutes.Routes = sortedRoutes.Routes[:i+1]
break
}
}
if pag.Offset != nil {
if *pag.Offset <= len(sortedRoutes.Routes) {
sortedRoutes.Routes = sortedRoutes.Routes[*pag.Offset:]