Added context for routes methods

This commit is contained in:
porosnicuadrian
2021-05-25 16:59:15 +03:00
committed by Dan Christian Bogos
parent 0f0f05d525
commit 788919bdaa
29 changed files with 193 additions and 160 deletions

View File

@@ -235,15 +235,15 @@ func (dbM *DataDBMock) RemoveFilterDrv(string, string) error {
return utils.ErrNotImplemented
}
func (dbM *DataDBMock) GetRouteProfileDrv(string, string) (*RouteProfile, error) {
func (dbM *DataDBMock) GetRouteProfileDrv(*context.Context, string, string) (*RouteProfile, error) {
return nil, utils.ErrNotImplemented
}
func (dbM *DataDBMock) SetRouteProfileDrv(*RouteProfile) error {
func (dbM *DataDBMock) SetRouteProfileDrv(*context.Context, *RouteProfile) error {
return utils.ErrNotImplemented
}
func (dbM *DataDBMock) RemoveRouteProfileDrv(string, string) error {
func (dbM *DataDBMock) RemoveRouteProfileDrv(*context.Context, string, string) error {
return utils.ErrNotImplemented
}

View File

@@ -167,7 +167,7 @@ func (dm *DataManager) CacheDataFromDB(ctx *context.Context, prfx string, ids []
_, err = dm.GetFilter(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
case utils.RouteProfilePrefix:
tntID := utils.NewTenantID(dataID)
_, err = dm.GetRouteProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
_, err = dm.GetRouteProfile(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
case utils.AttributeProfilePrefix:
tntID := utils.NewTenantID(dataID)
_, err = dm.GetAttributeProfile(ctx, tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
@@ -1174,7 +1174,7 @@ func (dm *DataManager) HasData(category, subject, tenant string) (has bool, err
return dm.DataDB().HasDataDrv(context.TODO(), category, subject, tenant)
}
func (dm *DataManager) GetRouteProfile(tenant, id string, cacheRead, cacheWrite bool,
func (dm *DataManager) GetRouteProfile(ctx *context.Context, tenant, id string, cacheRead, cacheWrite bool,
transactionID string) (rpp *RouteProfile, err error) {
tntID := utils.ConcatenatedKey(tenant, id)
if cacheRead {
@@ -1189,23 +1189,23 @@ func (dm *DataManager) GetRouteProfile(tenant, id string, cacheRead, cacheWrite
err = utils.ErrNoDatabaseConn
return
}
rpp, err = dm.dataDB.GetRouteProfileDrv(tenant, id)
rpp, err = dm.dataDB.GetRouteProfileDrv(ctx, tenant, id)
if err != nil {
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRouteProfiles]; err == utils.ErrNotFound && itm.Remote {
if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetRouteProfile,
if err = dm.connMgr.Call(ctx, config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetRouteProfile,
&utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{Tenant: tenant, ID: id},
APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString,
utils.FirstNonEmpty(config.CgrConfig().DataDbCfg().RmtConnID,
config.CgrConfig().GeneralCfg().NodeID)),
}, &rpp); err == nil {
err = dm.dataDB.SetRouteProfileDrv(rpp)
err = dm.dataDB.SetRouteProfileDrv(ctx, rpp)
}
}
if err != nil {
err = utils.CastRPCErr(err)
if err == utils.ErrNotFound && cacheWrite && dm.dataDB.GetStorageType() != utils.Internal {
if errCh := Cache.Set(context.TODO(), utils.CacheRouteProfiles, tntID, nil, nil,
if errCh := Cache.Set(ctx, utils.CacheRouteProfiles, tntID, nil, nil,
cacheCommit(transactionID), transactionID); errCh != nil {
return nil, errCh
}
@@ -1219,7 +1219,7 @@ func (dm *DataManager) GetRouteProfile(tenant, id string, cacheRead, cacheWrite
return nil, err
}
if cacheWrite {
if errCh := Cache.Set(context.TODO(), utils.CacheRouteProfiles, tntID, rpp, nil,
if errCh := Cache.Set(ctx, utils.CacheRouteProfiles, tntID, rpp, nil,
cacheCommit(transactionID), transactionID); errCh != nil {
return nil, errCh
}
@@ -1227,22 +1227,22 @@ func (dm *DataManager) GetRouteProfile(tenant, id string, cacheRead, cacheWrite
return
}
func (dm *DataManager) SetRouteProfile(rpp *RouteProfile, withIndex bool) (err error) {
func (dm *DataManager) SetRouteProfile(ctx *context.Context, rpp *RouteProfile, withIndex bool) (err error) {
if dm == nil {
return utils.ErrNoDatabaseConn
}
if withIndex {
if brokenReference := dm.checkFilters(context.TODO(), rpp.Tenant, rpp.FilterIDs); len(brokenReference) != 0 {
if brokenReference := dm.checkFilters(ctx, rpp.Tenant, rpp.FilterIDs); len(brokenReference) != 0 {
// if we get a broken filter do not set the profile
return fmt.Errorf("broken reference to filter: %+v for item with ID: %+v",
brokenReference, rpp.TenantID())
}
}
oldRpp, err := dm.GetRouteProfile(rpp.Tenant, rpp.ID, true, false, utils.NonTransactional)
oldRpp, err := dm.GetRouteProfile(ctx, rpp.Tenant, rpp.ID, true, false, utils.NonTransactional)
if err != nil && err != utils.ErrNotFound {
return err
}
if err = dm.DataDB().SetRouteProfileDrv(rpp); err != nil {
if err = dm.DataDB().SetRouteProfileDrv(ctx, rpp); err != nil {
return err
}
if withIndex {
@@ -1250,13 +1250,13 @@ func (dm *DataManager) SetRouteProfile(rpp *RouteProfile, withIndex bool) (err e
if oldRpp != nil {
oldFiltersIDs = &oldRpp.FilterIDs
}
if err := updatedIndexes(context.TODO(), dm, utils.CacheRouteFilterIndexes, rpp.Tenant,
if err := updatedIndexes(ctx, dm, utils.CacheRouteFilterIndexes, rpp.Tenant,
utils.EmptyString, rpp.ID, oldFiltersIDs, rpp.FilterIDs, false); err != nil {
return err
}
}
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRouteProfiles]; itm.Replicate {
err = replicate(context.TODO(), dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
err = replicate(ctx, dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
config.CgrConfig().DataDbCfg().RplFiltered,
utils.RouteProfilePrefix, rpp.TenantID(), // this are used to get the host IDs from cache
utils.ReplicatorSv1SetRouteProfile,
@@ -1272,27 +1272,27 @@ func (dm *DataManager) RemoveRouteProfile(tenant, id string, withIndex bool) (er
if dm == nil {
return utils.ErrNoDatabaseConn
}
oldRpp, err := dm.GetRouteProfile(tenant, id, true, false, utils.NonTransactional)
oldRpp, err := dm.GetRouteProfile(ctx, tenant, id, true, false, utils.NonTransactional)
if err != nil && err != utils.ErrNotFound {
return err
}
if err = dm.DataDB().RemoveRouteProfileDrv(tenant, id); err != nil {
if err = dm.DataDB().RemoveRouteProfileDrv(ctx, tenant, id); err != nil {
return
}
if oldRpp == nil {
return utils.ErrNotFound
}
if withIndex {
if err = removeIndexFiltersItem(context.TODO(), dm, utils.CacheRouteFilterIndexes, tenant, id, oldRpp.FilterIDs); err != nil {
if err = removeIndexFiltersItem(ctx, dm, utils.CacheRouteFilterIndexes, tenant, id, oldRpp.FilterIDs); err != nil {
return
}
if err = removeItemFromFilterIndex(context.TODO(), dm, utils.CacheRouteFilterIndexes,
if err = removeItemFromFilterIndex(ctx, dm, utils.CacheRouteFilterIndexes,
tenant, utils.EmptyString, id, oldRpp.FilterIDs); err != nil {
return
}
}
if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRouteProfiles]; itm.Replicate {
replicate(context.TODO(), dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
replicate(ctx, dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
config.CgrConfig().DataDbCfg().RplFiltered,
utils.RouteProfilePrefix, utils.ConcatenatedKey(tenant, id), // this are used to get the host IDs from cache
utils.ReplicatorSv1RemoveRouteProfile,
@@ -1384,7 +1384,7 @@ func (dm *DataManager) SetAttributeProfile(ctx *context.Context, ap *AttributePr
if oldAP != nil {
oldFiltersIDs = &oldAP.FilterIDs
}
if err := updatedIndexes(context.TODO(), dm, utils.CacheAttributeFilterIndexes, ap.Tenant,
if err := updatedIndexes(ctx, dm, utils.CacheAttributeFilterIndexes, ap.Tenant,
utils.EmptyString, ap.ID, oldFiltersIDs, ap.FilterIDs, false); err != nil {
return err
}

View File

@@ -110,17 +110,17 @@ func verifyPrefixes(rule *FilterRule, prefixes []string) (hasPrefix bool) {
//LazyPass is almost the same as Pass except that it verify if the
//Element of the Values from FilterRules has as prefix one of the pathPrfxs
func (fS *FilterS) LazyPass(tenant string, filterIDs []string,
func (fS *FilterS) LazyPass(ctx *context.Context, tenant string, filterIDs []string,
ev utils.DataProvider, pathPrfxs []string) (pass bool, lazyCheckRules []*FilterRule, err error) {
if len(filterIDs) == 0 {
return true, nil, nil
}
pass = true
dDP := newDynamicDP(context.TODO(), fS.cfg.FilterSCfg().ResourceSConns, fS.cfg.FilterSCfg().StatSConns,
dDP := newDynamicDP(ctx, fS.cfg.FilterSCfg().ResourceSConns, fS.cfg.FilterSCfg().StatSConns,
fS.cfg.FilterSCfg().AdminSConns, tenant, ev)
for _, fltrID := range filterIDs {
var f *Filter
f, err = fS.dm.GetFilter(context.TODO(), tenant, fltrID,
f, err = fS.dm.GetFilter(ctx, tenant, fltrID,
true, true, utils.NonTransactional)
if err != nil {
if err == utils.ErrNotFound {
@@ -133,7 +133,7 @@ func (fS *FilterS) LazyPass(tenant string, filterIDs []string,
lazyCheckRules = append(lazyCheckRules, rule)
continue
}
if pass, err = rule.Pass(context.TODO(), dDP); err != nil || !pass {
if pass, err = rule.Pass(ctx, dDP); err != nil || !pass {
return
}
}

View File

@@ -799,7 +799,7 @@ func TestPassPartial(t *testing.T) {
fEv := utils.MapStorage{}
fEv.Set([]string{utils.MetaReq}, passEvent)
prefixes := []string{utils.DynamicDataPrefix + utils.MetaReq}
if pass, ruleList, err := filterS.LazyPass("cgrates.org",
if pass, ruleList, err := filterS.LazyPass(context.Background(), "cgrates.org",
[]string{"*string:~*req.Account:1007"}, fEv, prefixes); err != nil {
t.Errorf(err.Error())
} else if !pass {
@@ -808,7 +808,7 @@ func TestPassPartial(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", 0, len(ruleList))
}
// in PartialPass we verify the filters matching the prefixes
if pass, ruleList, err := filterS.LazyPass("cgrates.org",
if pass, ruleList, err := filterS.LazyPass(context.Background(), "cgrates.org",
[]string{"*string:~*req.Account:1007", "*string:~*vars.Field1:Val1"}, fEv, prefixes); err != nil {
t.Errorf(err.Error())
} else if !pass {
@@ -816,7 +816,7 @@ func TestPassPartial(t *testing.T) {
} else if len(ruleList) != 1 {
t.Errorf("Expecting: %+v, received: %+v", 1, len(ruleList))
}
if pass, ruleList, err := filterS.LazyPass("cgrates.org",
if pass, ruleList, err := filterS.LazyPass(context.Background(), "cgrates.org",
[]string{"*string:~*req.Account:1010", "*string:~*vars.Field1:Val1"}, fEv, prefixes); err != nil {
t.Errorf(err.Error())
} else if pass {

View File

@@ -665,7 +665,7 @@ func UpdateFilterIndex(apiCtx *context.Context, dm *DataManager, oldFlt, newFlt
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(apiCtx, dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
rt, e := dm.GetRouteProfile(tnt, id, true, false, utils.NonTransactional)
rt, e := dm.GetRouteProfile(apiCtx, tnt, id, true, false, utils.NonTransactional)
if e != nil {
return nil, e
}

View File

@@ -23,6 +23,8 @@ import (
"sort"
"strings"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -216,7 +218,7 @@ func (sRoutes *SortedRoutes) AsNavigableMap() (nm *utils.DataNode) {
// RoutesSorter is the interface which needs to be implemented by routes sorters
type RoutesSorter interface {
SortRoutes(string, map[string]*Route, *utils.CGREvent, *optsGetRoutes) (*SortedRoutes, error)
SortRoutes(*context.Context, string, map[string]*Route, *utils.CGREvent, *optsGetRoutes) (*SortedRoutes, error)
}
// NewRouteSortDispatcher constructs RouteSortDispatcher
@@ -236,13 +238,13 @@ func NewRouteSortDispatcher(lcrS *RouteService) (rsd RouteSortDispatcher) {
// and dispatch requests to them
type RouteSortDispatcher map[string]RoutesSorter
func (ssd RouteSortDispatcher) SortRoutes(prflID, strategy string,
func (ssd RouteSortDispatcher) SortRoutes(ctx *context.Context, prflID, strategy string,
suppls map[string]*Route, suplEv *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sd, has := ssd[strategy]
if !has {
return nil, fmt.Errorf("unsupported sorting strategy: %s", strategy)
}
if sortedRoutes, err = sd.SortRoutes(prflID, suppls, suplEv, extraOpts); err != nil {
if sortedRoutes, err = sd.SortRoutes(ctx, prflID, suppls, suplEv, extraOpts); err != nil {
return
}
if len(sortedRoutes.Routes) == 0 {

View File

@@ -21,6 +21,8 @@ package engine
import (
"fmt"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -35,7 +37,7 @@ type HightCostSorter struct {
rS *RouteService
}
func (hcs *HightCostSorter) SortRoutes(prflID string, routes map[string]*Route,
func (hcs *HightCostSorter) SortRoutes(ctx *context.Context, prflID string, routes map[string]*Route,
ev *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{ProfileID: prflID,
Sorting: hcs.sorting,
@@ -47,7 +49,7 @@ func (hcs *HightCostSorter) SortRoutes(prflID string, routes map[string]*Route,
utils.RouteS, route.ID))
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs or AccountIDs")
}
if srtSpl, pass, err := hcs.rS.populateSortingData(ev, route, extraOpts); err != nil {
if srtSpl, pass, err := hcs.rS.populateSortingData(ctx, ev, route, extraOpts); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedRoutes.Routes = append(sortedRoutes.Routes, srtSpl)

View File

@@ -21,6 +21,8 @@ package engine
import (
"fmt"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -35,7 +37,7 @@ type LeastCostSorter struct {
rS *RouteService
}
func (lcs *LeastCostSorter) SortRoutes(prflID string, routes map[string]*Route,
func (lcs *LeastCostSorter) SortRoutes(ctx *context.Context, prflID string, routes map[string]*Route,
ev *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{ProfileID: prflID,
Sorting: lcs.sorting,
@@ -47,7 +49,7 @@ func (lcs *LeastCostSorter) SortRoutes(prflID string, routes map[string]*Route,
utils.RouteS, s.ID))
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs or AccountIDs")
}
if srtSpl, pass, err := lcs.rS.populateSortingData(ev, s, extraOpts); err != nil {
if srtSpl, pass, err := lcs.rS.populateSortingData(ctx, ev, s, extraOpts); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedRoutes.Routes = append(sortedRoutes.Routes, srtSpl)

View File

@@ -21,6 +21,8 @@ package engine
import (
"fmt"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -37,7 +39,7 @@ type LoadDistributionSorter struct {
}
// SortRoutes .
func (ws *LoadDistributionSorter) SortRoutes(prflID string,
func (ws *LoadDistributionSorter) SortRoutes(ctx *context.Context, prflID string,
routes map[string]*Route, suplEv *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{
ProfileID: prflID,
@@ -52,7 +54,7 @@ func (ws *LoadDistributionSorter) SortRoutes(prflID string,
utils.RouteS, route.ID))
return nil, utils.NewErrMandatoryIeMissing("StatIDs")
}
if srtSpl, pass, err := ws.rS.populateSortingData(suplEv, route, extraOpts); err != nil {
if srtSpl, pass, err := ws.rS.populateSortingData(ctx, suplEv, route, extraOpts); err != nil {
return nil, err
} else if pass && srtSpl != nil {
// Add the ratio in SortingData so we can used it later in SortLoadDistribution

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -33,13 +34,13 @@ type QOSRouteSorter struct {
rS *RouteService
}
func (qos *QOSRouteSorter) SortRoutes(prflID string, routes map[string]*Route,
func (qos *QOSRouteSorter) SortRoutes(ctx *context.Context, prflID string, routes map[string]*Route,
ev *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{ProfileID: prflID,
Sorting: qos.sorting,
Routes: make([]*SortedRoute, 0)}
for _, route := range routes {
if srtSpl, pass, err := qos.rS.populateSortingData(ev, route, extraOpts); err != nil {
if srtSpl, pass, err := qos.rS.populateSortingData(ctx, ev, route, extraOpts); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedRoutes.Routes = append(sortedRoutes.Routes, srtSpl)

View File

@@ -21,6 +21,8 @@ package engine
import (
"fmt"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -35,7 +37,7 @@ type ResourceAscendentSorter struct {
rS *RouteService
}
func (ws *ResourceAscendentSorter) SortRoutes(prflID string,
func (ws *ResourceAscendentSorter) SortRoutes(ctx *context.Context, prflID string,
routes map[string]*Route, suplEv *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{ProfileID: prflID,
Sorting: ws.sorting,
@@ -47,7 +49,7 @@ func (ws *ResourceAscendentSorter) SortRoutes(prflID string,
utils.RouteS, route.ID))
return nil, utils.NewErrMandatoryIeMissing("ResourceIDs")
}
if srtSpl, pass, err := ws.rS.populateSortingData(suplEv, route, extraOpts); err != nil {
if srtSpl, pass, err := ws.rS.populateSortingData(ctx, suplEv, route, extraOpts); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedRoutes.Routes = append(sortedRoutes.Routes, srtSpl)

View File

@@ -21,6 +21,7 @@ package engine
import (
"fmt"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -35,7 +36,7 @@ type ResourceDescendentSorter struct {
rS *RouteService
}
func (ws *ResourceDescendentSorter) SortRoutes(prflID string,
func (ws *ResourceDescendentSorter) SortRoutes(ctx *context.Context, prflID string,
routes map[string]*Route, suplEv *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{ProfileID: prflID,
Sorting: ws.sorting,
@@ -47,7 +48,7 @@ func (ws *ResourceDescendentSorter) SortRoutes(prflID string,
utils.RouteS, route.ID))
return nil, utils.NewErrMandatoryIeMissing("ResourceIDs")
}
if srtSpl, pass, err := ws.rS.populateSortingData(suplEv, route, extraOpts); err != nil {
if srtSpl, pass, err := ws.rS.populateSortingData(ctx, suplEv, route, extraOpts); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedRoutes.Routes = append(sortedRoutes.Routes, srtSpl)

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/utils"
)
@@ -33,13 +34,13 @@ type WeightSorter struct {
rS *RouteService
}
func (ws *WeightSorter) SortRoutes(prflID string,
func (ws *WeightSorter) SortRoutes(ctx *context.Context, prflID string,
routes map[string]*Route, suplEv *utils.CGREvent, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
sortedRoutes = &SortedRoutes{ProfileID: prflID,
Sorting: ws.sorting,
Routes: make([]*SortedRoute, 0)}
for _, route := range routes {
if srtRoute, pass, err := ws.rS.populateSortingData(suplEv, route, extraOpts); err != nil {
if srtRoute, pass, err := ws.rS.populateSortingData(ctx, suplEv, route, extraOpts); err != nil {
return nil, err
} else if pass && srtRoute != nil {
sortedRoutes.Routes = append(sortedRoutes.Routes, srtRoute)

View File

@@ -140,12 +140,12 @@ func (rpS *RouteService) Shutdown() {
}
// matchingRouteProfilesForEvent returns ordered list of matching resources which are active by the time of the call
func (rpS *RouteService) matchingRouteProfilesForEvent(tnt string, ev *utils.CGREvent) (matchingRPrf []*RouteProfile, err error) {
func (rpS *RouteService) matchingRouteProfilesForEvent(ctx *context.Context, tnt string, ev *utils.CGREvent) (matchingRPrf []*RouteProfile, err error) {
evNm := utils.MapStorage{
utils.MetaReq: ev.Event,
utils.MetaOpts: ev.APIOpts,
}
rPrfIDs, err := MatchingItemIDsForEvent(context.TODO(), evNm,
rPrfIDs, err := MatchingItemIDsForEvent(ctx, evNm,
rpS.cgrcfg.RouteSCfg().StringIndexedFields,
rpS.cgrcfg.RouteSCfg().PrefixIndexedFields,
rpS.cgrcfg.RouteSCfg().SuffixIndexedFields,
@@ -158,14 +158,14 @@ func (rpS *RouteService) matchingRouteProfilesForEvent(tnt string, ev *utils.CGR
}
matchingRPrf = make([]*RouteProfile, 0, len(rPrfIDs))
for lpID := range rPrfIDs {
rPrf, err := rpS.dm.GetRouteProfile(tnt, lpID, true, true, utils.NonTransactional)
rPrf, err := rpS.dm.GetRouteProfile(ctx, tnt, lpID, true, true, utils.NonTransactional)
if err != nil {
if err == utils.ErrNotFound {
continue
}
return nil, err
}
if pass, err := rpS.filterS.Pass(context.TODO(), tnt, rPrf.FilterIDs,
if pass, err := rpS.filterS.Pass(ctx, tnt, rPrf.FilterIDs,
evNm); err != nil {
return nil, err
} else if !pass {
@@ -272,13 +272,13 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent,
// statMetrics will query a list of statIDs and return composed metric values
// first metric found is always returned
func (rpS *RouteService) statMetrics(statIDs []string, tenant string) (stsMetric map[string]float64, err error) {
func (rpS *RouteService) statMetrics(ctx *context.Context, statIDs []string, tenant string) (stsMetric map[string]float64, err error) {
stsMetric = make(map[string]float64)
provStsMetrics := make(map[string][]float64)
if len(rpS.cgrcfg.RouteSCfg().StatSConns) != 0 {
for _, statID := range statIDs {
var metrics map[string]float64
if err = rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().StatSConns, utils.StatSv1GetQueueFloatMetrics,
if err = rpS.connMgr.Call(ctx, rpS.cgrcfg.RouteSCfg().StatSConns, utils.StatSv1GetQueueFloatMetrics,
&utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: statID}}, &metrics); err != nil &&
err.Error() != utils.ErrNotFound.Error() {
utils.Logger.Warning(
@@ -302,14 +302,14 @@ func (rpS *RouteService) statMetrics(statIDs []string, tenant string) (stsMetric
// statMetricsForLoadDistribution will query a list of statIDs and return the sum of metrics
// first metric found is always returned
func (rpS *RouteService) statMetricsForLoadDistribution(statIDs []string, tenant string) (result float64, err error) {
func (rpS *RouteService) statMetricsForLoadDistribution(ctx *context.Context, statIDs []string, tenant string) (result float64, err error) {
provStsMetrics := make(map[string][]float64)
if len(rpS.cgrcfg.RouteSCfg().StatSConns) != 0 {
for _, statID := range statIDs {
// check if we get an ID in the following form (StatID:MetricID)
statWithMetric := strings.Split(statID, utils.InInFieldSep)
var metrics map[string]float64
if err = rpS.connMgr.Call(context.TODO(),
if err = rpS.connMgr.Call(ctx,
rpS.cgrcfg.RouteSCfg().StatSConns,
utils.StatSv1GetQueueFloatMetrics,
&utils.TenantIDWithAPIOpts{
@@ -348,11 +348,11 @@ func (rpS *RouteService) statMetricsForLoadDistribution(statIDs []string, tenant
}
// resourceUsage returns sum of all resource usages out of list
func (rpS *RouteService) resourceUsage(resIDs []string, tenant string) (tUsage float64, err error) {
func (rpS *RouteService) resourceUsage(ctx *context.Context, resIDs []string, tenant string) (tUsage float64, err error) {
if len(rpS.cgrcfg.RouteSCfg().ResourceSConns) != 0 {
for _, resID := range resIDs {
var res Resource
if err = rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().ResourceSConns, utils.ResourceSv1GetResource,
if err = rpS.connMgr.Call(ctx, rpS.cgrcfg.RouteSCfg().ResourceSConns, utils.ResourceSv1GetResource,
&utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: resID}}, &res); err != nil && err.Error() != utils.ErrNotFound.Error() {
utils.Logger.Warning(
fmt.Sprintf("<%s> error: %s getting resource for ID : %s", utils.RouteS, err.Error(), resID))
@@ -364,7 +364,7 @@ func (rpS *RouteService) resourceUsage(resIDs []string, tenant string) (tUsage f
return
}
func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
func (rpS *RouteService) populateSortingData(ctx *context.Context, ev *utils.CGREvent, route *Route,
extraOpts *optsGetRoutes) (srtRoute *SortedRoute, pass bool, err error) {
sortedSpl := &SortedRoute{
RouteID: route.ID,
@@ -410,7 +410,7 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
//in case we have *load strategy we use statMetricsForLoadDistribution function to calculate the result
if len(route.StatIDs) != 0 {
if extraOpts.sortingStragety == utils.MetaLoad {
metricSum, err := rpS.statMetricsForLoadDistribution(route.StatIDs, ev.Tenant) //create metric map for route
metricSum, err := rpS.statMetricsForLoadDistribution(ctx, route.StatIDs, ev.Tenant) //create metric map for route
if err != nil {
if extraOpts.ignoreErrors {
utils.Logger.Warning(
@@ -423,7 +423,7 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
sortedSpl.SortingData[utils.Load] = metricSum
sortedSpl.sortingDataF64[utils.Load] = metricSum
} else {
metricSupp, err := rpS.statMetrics(route.StatIDs, ev.Tenant) //create metric map for route
metricSupp, err := rpS.statMetrics(ctx, route.StatIDs, ev.Tenant) //create metric map for route
if err != nil {
if extraOpts.ignoreErrors {
utils.Logger.Warning(
@@ -457,7 +457,7 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
}
//calculate resourceUsage
if len(route.ResourceIDs) != 0 {
resTotalUsage, err := rpS.resourceUsage(route.ResourceIDs, ev.Tenant)
resTotalUsage, err := rpS.resourceUsage(ctx, route.ResourceIDs, ev.Tenant)
if err != nil {
if extraOpts.ignoreErrors {
utils.Logger.Warning(
@@ -473,7 +473,7 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
//filter the route
if len(route.lazyCheckRules) != 0 {
//construct the DP and pass it to filterS
dynDP := newDynamicDP(context.TODO(), rpS.cgrcfg.FilterSCfg().ResourceSConns, rpS.cgrcfg.FilterSCfg().StatSConns,
dynDP := newDynamicDP(ctx, rpS.cgrcfg.FilterSCfg().ResourceSConns, rpS.cgrcfg.FilterSCfg().StatSConns,
rpS.cgrcfg.FilterSCfg().AdminSConns,
ev.Tenant, utils.MapStorage{
utils.MetaReq: ev.Event,
@@ -481,7 +481,7 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
})
for _, rule := range route.lazyCheckRules { // verify the rules remaining from PartialPass
if pass, err = rule.Pass(context.TODO(), dynDP); err != nil {
if pass, err = rule.Pass(ctx, dynDP); err != nil {
return nil, false, err
} else if !pass {
return nil, false, nil
@@ -558,7 +558,7 @@ type optsGetRoutes struct {
}
// V1GetRoutes returns the list of valid routes
func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutesList) (err error) {
func (rpS *RouteService) V1GetRoutes(ctx *context.Context, args *ArgsGetRoutes, reply *SortedRoutesList) (err error) {
if args.CGREvent == nil {
return utils.NewErrMandatoryIeMissing(utils.CGREventString)
}
@@ -590,7 +590,7 @@ func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutesLis
ProcessRuns: processRuns,
}
var rplyEv AttrSProcessEventReply
if err := rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().AttributeSConns,
if err := rpS.connMgr.Call(ctx, rpS.cgrcfg.RouteSCfg().AttributeSConns,
utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 {
args.CGREvent = rplyEv.CGREvent
args.APIOpts = rplyEv.APIOpts
@@ -599,7 +599,7 @@ func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutesLis
}
}
var sSps SortedRoutesList
if sSps, err = rpS.sortedRoutesForEvent(tnt, args); err != nil {
if sSps, err = rpS.sortedRoutesForEvent(ctx, tnt, args); err != nil {
if err != utils.ErrNotFound {
err = utils.NewErrServerError(err)
}
@@ -610,7 +610,7 @@ func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutesLis
}
// V1GetRouteProfilesForEvent returns the list of valid route profiles
func (rpS *RouteService) V1GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*RouteProfile) (err error) {
func (rpS *RouteService) V1GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*RouteProfile) (err error) {
if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
} else if args.Event == nil {
@@ -620,7 +620,7 @@ func (rpS *RouteService) V1GetRouteProfilesForEvent(args *utils.CGREvent, reply
if tnt == utils.EmptyString {
tnt = rpS.cgrcfg.GeneralCfg().DefaultTenant
}
sPs, err := rpS.matchingRouteProfilesForEvent(tnt, args)
sPs, err := rpS.matchingRouteProfilesForEvent(ctx, tnt, args)
if err != nil {
if err != utils.ErrNotFound {
err = utils.NewErrServerError(err)
@@ -633,7 +633,7 @@ func (rpS *RouteService) V1GetRouteProfilesForEvent(args *utils.CGREvent, reply
// sortedRoutesForEvent will return the list of valid route IDs
// for event based on filters and sorting algorithms
func (rpS *RouteService) sortedRoutesForProfile(tnt string, rPrfl *RouteProfile, ev *utils.CGREvent,
func (rpS *RouteService) sortedRoutesForProfile(ctx *context.Context, tnt string, rPrfl *RouteProfile, ev *utils.CGREvent,
pag utils.Paginator, extraOpts *optsGetRoutes) (sortedRoutes *SortedRoutes, err error) {
extraOpts.sortingParameters = rPrfl.SortingParameters // populate sortingParameters in extraOpts
extraOpts.sortingStragety = rPrfl.Sorting // populate sortingStrategy in extraOpts
@@ -645,7 +645,7 @@ func (rpS *RouteService) sortedRoutesForProfile(tnt string, rPrfl *RouteProfile,
passedRoutes := make(map[string]*Route)
// apply filters for event
for _, route := range rPrfl.Routes {
pass, lazyCheckRules, err := rpS.filterS.LazyPass(tnt,
pass, lazyCheckRules, err := rpS.filterS.LazyPass(ctx, tnt,
route.FilterIDs, nM,
[]string{utils.DynamicDataPrefix + utils.MetaReq,
utils.DynamicDataPrefix + utils.MetaAccounts,
@@ -663,7 +663,7 @@ func (rpS *RouteService) sortedRoutesForProfile(tnt string, rPrfl *RouteProfile,
passedRoutes[route.ID] = route
}
if sortedRoutes, err = rpS.sorter.SortRoutes(rPrfl.ID, rPrfl.Sorting,
if sortedRoutes, err = rpS.sorter.SortRoutes(ctx, rPrfl.ID, rPrfl.Sorting,
passedRoutes, ev, extraOpts); err != nil {
return nil, err
}
@@ -682,12 +682,12 @@ func (rpS *RouteService) sortedRoutesForProfile(tnt string, rPrfl *RouteProfile,
// sortedRoutesForEvent will return the list of valid route IDs
// for event based on filters and sorting algorithms
func (rpS *RouteService) sortedRoutesForEvent(tnt string, args *ArgsGetRoutes) (sortedRoutes SortedRoutesList, err error) {
func (rpS *RouteService) sortedRoutesForEvent(ctx *context.Context, tnt string, args *ArgsGetRoutes) (sortedRoutes SortedRoutesList, err error) {
if _, has := args.CGREvent.Event[utils.Usage]; !has {
args.CGREvent.Event[utils.Usage] = time.Minute // make sure we have default set for Usage
}
var rPrfs []*RouteProfile
if rPrfs, err = rpS.matchingRouteProfilesForEvent(tnt, args.CGREvent); err != nil {
if rPrfs, err = rpS.matchingRouteProfilesForEvent(ctx, tnt, args.CGREvent); err != nil {
return
}
prfCount := len(rPrfs) // if the option is not present return for all profiles
@@ -730,7 +730,7 @@ func (rpS *RouteService) sortedRoutesForEvent(tnt string, args *ArgsGetRoutes) (
prfPag.Offset = &offset
}
var sr *SortedRoutes
if sr, err = rpS.sortedRoutesForProfile(tnt, rPrfl, args.CGREvent, prfPag, extraOpts); err != nil {
if sr, err = rpS.sortedRoutesForProfile(ctx, tnt, rPrfl, args.CGREvent, prfPag, extraOpts); err != nil {
return
}
noSrtRoutes += len(sr.Routes)
@@ -743,9 +743,9 @@ func (rpS *RouteService) sortedRoutesForEvent(tnt string, args *ArgsGetRoutes) (
}
// V1GetRoutesList returns the list of valid routes
func (rpS *RouteService) V1GetRoutesList(args *ArgsGetRoutes, reply *[]string) (err error) {
func (rpS *RouteService) V1GetRoutesList(ctx *context.Context, args *ArgsGetRoutes, reply *[]string) (err error) {
sR := new(SortedRoutesList)
if err = rpS.V1GetRoutes(args, sR); err != nil {
if err = rpS.V1GetRoutes(ctx, args, sR); err != nil {
return
}
*reply = sR.RoutesWithParams()

View File

@@ -276,13 +276,13 @@ func TestRoutesCache(t *testing.T) {
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -494,20 +494,20 @@ func TestRoutesmatchingRouteProfilesForEvent(t *testing.T) {
}
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
t.Errorf("Expecting: %+v, received: %+v", spp, tempSpp)
}
}
sprf, err := routeService.matchingRouteProfilesForEvent(argsGetRoutes[0].Tenant, argsGetRoutes[0].CGREvent)
sprf, err := routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[0].Tenant, argsGetRoutes[0].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -515,7 +515,7 @@ func TestRoutesmatchingRouteProfilesForEvent(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sppTest[0], sprf[0])
}
sprf, err = routeService.matchingRouteProfilesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1].CGREvent)
sprf, err = routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -523,7 +523,7 @@ func TestRoutesmatchingRouteProfilesForEvent(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sppTest[1], sprf[0])
}
sprf, err = routeService.matchingRouteProfilesForEvent(argsGetRoutes[2].Tenant, argsGetRoutes[2].CGREvent)
sprf, err = routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[2].Tenant, argsGetRoutes[2].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -735,13 +735,13 @@ func TestRoutesSortedForEvent(t *testing.T) {
}
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -764,7 +764,7 @@ func TestRoutesSortedForEvent(t *testing.T) {
},
},
}}
sprf, err := routeService.sortedRoutesForEvent(argsGetRoutes[0].Tenant, argsGetRoutes[0])
sprf, err := routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes[0].Tenant, argsGetRoutes[0])
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -809,7 +809,7 @@ func TestRoutesSortedForEvent(t *testing.T) {
},
}}
sprf, err = routeService.sortedRoutesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1])
sprf, err = routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1])
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -834,7 +834,7 @@ func TestRoutesSortedForEvent(t *testing.T) {
},
}}
sprf, err = routeService.sortedRoutesForEvent(argsGetRoutes[2].Tenant, argsGetRoutes[2])
sprf, err = routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes[2].Tenant, argsGetRoutes[2])
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1046,13 +1046,13 @@ func TestRoutesSortedForEventWithLimit(t *testing.T) {
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -1089,7 +1089,7 @@ func TestRoutesSortedForEventWithLimit(t *testing.T) {
argsGetRoutes[1].Paginator = utils.Paginator{
Limit: utils.IntPointer(2),
}
sprf, err := routeService.sortedRoutesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1])
sprf, err := routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1])
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1301,13 +1301,13 @@ func TestRoutesSortedForEventWithOffset(t *testing.T) {
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -1334,7 +1334,7 @@ func TestRoutesSortedForEventWithOffset(t *testing.T) {
argsGetRoutes[1].Paginator = utils.Paginator{
Offset: utils.IntPointer(2),
}
sprf, err := routeService.sortedRoutesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1])
sprf, err := routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1])
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1546,13 +1546,13 @@ func TestRoutesSortedForEventWithLimitAndOffset(t *testing.T) {
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -1580,7 +1580,7 @@ func TestRoutesSortedForEventWithLimitAndOffset(t *testing.T) {
Limit: utils.IntPointer(1),
Offset: utils.IntPointer(1),
}
sprf, err := routeService.sortedRoutesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1])
sprf, err := routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1])
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1826,13 +1826,13 @@ func TestRoutesAsOptsGetRoutesMaxCost(t *testing.T) {
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -1841,7 +1841,7 @@ func TestRoutesAsOptsGetRoutesMaxCost(t *testing.T) {
}
routeService.cgrcfg.RouteSCfg().IndexedSelects = false
sprf, err := routeService.matchingRouteProfilesForEvent(argsGetRoutes[0].Tenant, argsGetRoutes[0].CGREvent)
sprf, err := routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[0].Tenant, argsGetRoutes[0].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1849,7 +1849,7 @@ func TestRoutesAsOptsGetRoutesMaxCost(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sppTest[0], sprf[0])
}
sprf, err = routeService.matchingRouteProfilesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1].CGREvent)
sprf, err = routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -1857,7 +1857,7 @@ func TestRoutesAsOptsGetRoutesMaxCost(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sppTest[1], sprf[0])
}
sprf, err = routeService.matchingRouteProfilesForEvent(argsGetRoutes[2].Tenant, argsGetRoutes[2].CGREvent)
sprf, err = routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[2].Tenant, argsGetRoutes[2].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2069,13 +2069,13 @@ func TestRoutesMatchWithIndexFalse(t *testing.T) {
dmSPP.SetFilter(context.Background(), fltrSupp3, true)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
}
//Test each route profile from cache
for _, spp := range sppTest {
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -2084,7 +2084,7 @@ func TestRoutesMatchWithIndexFalse(t *testing.T) {
}
routeService.cgrcfg.RouteSCfg().IndexedSelects = false
sprf, err := routeService.matchingRouteProfilesForEvent(argsGetRoutes[0].Tenant, argsGetRoutes[0].CGREvent)
sprf, err := routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[0].Tenant, argsGetRoutes[0].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2092,7 +2092,7 @@ func TestRoutesMatchWithIndexFalse(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sppTest[0], sprf[0])
}
sprf, err = routeService.matchingRouteProfilesForEvent(argsGetRoutes[1].Tenant, argsGetRoutes[1].CGREvent)
sprf, err = routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[1].Tenant, argsGetRoutes[1].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2100,7 +2100,7 @@ func TestRoutesMatchWithIndexFalse(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", sppTest[1], sprf[0])
}
sprf, err = routeService.matchingRouteProfilesForEvent(argsGetRoutes[2].Tenant, argsGetRoutes[2].CGREvent)
sprf, err = routeService.matchingRouteProfilesForEvent(context.Background(), argsGetRoutes[2].Tenant, argsGetRoutes[2].CGREvent)
if err != nil {
t.Errorf("Error: %+v", err)
}
@@ -2193,10 +2193,10 @@ func TestRoutesSortedForEventWithLimitAndOffset2(t *testing.T) {
dm: dmSPP, cfg: defaultCfg}, defaultCfg, nil)
for _, spp := range sppTest {
if err = dmSPP.SetRouteProfile(spp, true); err != nil {
if err = dmSPP.SetRouteProfile(context.Background(), spp, true); err != nil {
t.Errorf("Error: %+v", err)
}
if tempSpp, err := dmSPP.GetRouteProfile(spp.Tenant,
if tempSpp, err := dmSPP.GetRouteProfile(context.Background(), spp.Tenant,
spp.ID, true, true, utils.NonTransactional); err != nil {
t.Errorf("Error: %+v", err)
} else if !reflect.DeepEqual(spp, tempSpp) {
@@ -2242,7 +2242,7 @@ func TestRoutesSortedForEventWithLimitAndOffset2(t *testing.T) {
Limit: utils.IntPointer(2),
Offset: utils.IntPointer(1),
}
sprf, err := routeService.sortedRoutesForEvent(argsGetRoutes.Tenant, argsGetRoutes)
sprf, err := routeService.sortedRoutesForEvent(context.Background(), argsGetRoutes.Tenant, argsGetRoutes)
if err != nil {
t.Errorf("Error: %+v", err)
}

View File

@@ -75,9 +75,9 @@ type DataDB interface {
GetFilterDrv(ctx *context.Context, tnt string, id string) (*Filter, error)
SetFilterDrv(ctx *context.Context, f *Filter) error
RemoveFilterDrv(string, string) error
GetRouteProfileDrv(string, string) (*RouteProfile, error)
SetRouteProfileDrv(*RouteProfile) error
RemoveRouteProfileDrv(string, string) error
GetRouteProfileDrv(*context.Context, string, string) (*RouteProfile, error)
SetRouteProfileDrv(*context.Context, *RouteProfile) error
RemoveRouteProfileDrv(*context.Context, string, string) error
GetAttributeProfileDrv(ctx *context.Context, tnt string, id string) (*AttributeProfile, error)
SetAttributeProfileDrv(ctx *context.Context, attr *AttributeProfile) error
RemoveAttributeProfileDrv(*context.Context, string, string) error

View File

@@ -333,7 +333,7 @@ func (iDB *InternalDB) RemoveFilterDrv(tenant, id string) (err error) {
return
}
func (iDB *InternalDB) GetRouteProfileDrv(tenant, id string) (spp *RouteProfile, err error) {
func (iDB *InternalDB) GetRouteProfileDrv(ctx *context.Context, tenant, id string) (spp *RouteProfile, err error) {
x, ok := Cache.Get(utils.CacheRouteProfiles, utils.ConcatenatedKey(tenant, id))
if !ok || x == nil {
return nil, utils.ErrNotFound
@@ -341,7 +341,7 @@ func (iDB *InternalDB) GetRouteProfileDrv(tenant, id string) (spp *RouteProfile,
return x.(*RouteProfile), nil
}
func (iDB *InternalDB) SetRouteProfileDrv(spp *RouteProfile) (err error) {
func (iDB *InternalDB) SetRouteProfileDrv(ctx *context.Context, spp *RouteProfile) (err error) {
if err = spp.Compile(); err != nil {
return
}
@@ -350,7 +350,7 @@ func (iDB *InternalDB) SetRouteProfileDrv(spp *RouteProfile) (err error) {
return
}
func (iDB *InternalDB) RemoveRouteProfileDrv(tenant, id string) (err error) {
func (iDB *InternalDB) RemoveRouteProfileDrv(ctx *context.Context, tenant, id string) (err error) {
Cache.RemoveWithoutReplicate(utils.CacheRouteProfiles, utils.ConcatenatedKey(tenant, id),
cacheCommit(utils.NonTransactional), utils.NonTransactional)
return

View File

@@ -1012,9 +1012,9 @@ func (ms *MongoStorage) RemoveFilterDrv(tenant, id string) (err error) {
})
}
func (ms *MongoStorage) GetRouteProfileDrv(tenant, id string) (r *RouteProfile, err error) {
func (ms *MongoStorage) GetRouteProfileDrv(ctx *context.Context, tenant, id string) (r *RouteProfile, err error) {
r = new(RouteProfile)
err = ms.query(context.TODO(), func(sctx mongo.SessionContext) (err error) {
err = ms.query(ctx, func(sctx mongo.SessionContext) (err error) {
cur := ms.getCol(ColRts).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
if err := cur.Decode(r); err != nil {
r = nil
@@ -1028,8 +1028,8 @@ func (ms *MongoStorage) GetRouteProfileDrv(tenant, id string) (r *RouteProfile,
return
}
func (ms *MongoStorage) SetRouteProfileDrv(r *RouteProfile) (err error) {
return ms.query(context.TODO(), func(sctx mongo.SessionContext) (err error) {
func (ms *MongoStorage) SetRouteProfileDrv(ctx *context.Context, r *RouteProfile) (err error) {
return ms.query(ctx, func(sctx mongo.SessionContext) (err error) {
_, err = ms.getCol(ColRts).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID},
bson.M{"$set": r},
options.Update().SetUpsert(true),
@@ -1038,8 +1038,8 @@ func (ms *MongoStorage) SetRouteProfileDrv(r *RouteProfile) (err error) {
})
}
func (ms *MongoStorage) RemoveRouteProfileDrv(tenant, id string) (err error) {
return ms.query(context.TODO(), func(sctx mongo.SessionContext) (err error) {
func (ms *MongoStorage) RemoveRouteProfileDrv(ctx *context.Context, tenant, id string) (err error) {
return ms.query(ctx, func(sctx mongo.SessionContext) (err error) {
dr, err := ms.getCol(ColRts).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id})
if dr.DeletedCount == 0 {
return utils.ErrNotFound

View File

@@ -565,7 +565,7 @@ func (rs *RedisStorage) RemoveFilterDrv(tenant, id string) (err error) {
return rs.Cmd(nil, redisDEL, utils.FilterPrefix+utils.ConcatenatedKey(tenant, id))
}
func (rs *RedisStorage) GetRouteProfileDrv(tenant, id string) (r *RouteProfile, err error) {
func (rs *RedisStorage) GetRouteProfileDrv(ctx *context.Context, tenant, id string) (r *RouteProfile, err error) {
var values []byte
if err = rs.Cmd(&values, redisGET, utils.RouteProfilePrefix+utils.ConcatenatedKey(tenant, id)); err != nil {
return
@@ -577,7 +577,7 @@ func (rs *RedisStorage) GetRouteProfileDrv(tenant, id string) (r *RouteProfile,
return
}
func (rs *RedisStorage) SetRouteProfileDrv(r *RouteProfile) (err error) {
func (rs *RedisStorage) SetRouteProfileDrv(ctx *context.Context, r *RouteProfile) (err error) {
var result []byte
if result, err = rs.ms.Marshal(r); err != nil {
return
@@ -585,7 +585,7 @@ func (rs *RedisStorage) SetRouteProfileDrv(r *RouteProfile) (err error) {
return rs.Cmd(nil, redisSET, utils.RouteProfilePrefix+utils.ConcatenatedKey(r.Tenant, r.ID), string(result))
}
func (rs *RedisStorage) RemoveRouteProfileDrv(tenant, id string) (err error) {
func (rs *RedisStorage) RemoveRouteProfileDrv(ctx *context.Context, tenant, id string) (err error) {
return rs.Cmd(nil, redisDEL, utils.RouteProfilePrefix+utils.ConcatenatedKey(tenant, id))
}

View File

@@ -454,7 +454,7 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) {
if th, err = APItoRouteProfile(tpTH, tpr.timezone); err != nil {
return
}
if err = tpr.dm.SetRouteProfile(th, true); err != nil {
if err = tpr.dm.SetRouteProfile(context.TODO(), th, true); err != nil {
return
}
if verbose {