New cases in updating indexes for new susbsystem's profiles

This commit is contained in:
porosnicuadrian
2021-03-09 17:55:20 +02:00
committed by Dan Christian Bogos
parent 993231f336
commit 5cc52cb490
3 changed files with 64 additions and 6 deletions

View File

@@ -41,7 +41,8 @@ func TestRPCCall(t *testing.T) {
}
}
func TestListenAndServe(t *testing.T) {
func TestShutDownCoverage(t *testing.T) {
//this is called in order to cover the ListenAndServe method
cfg := config.NewDefaultCGRConfig()
dm := engine.NewDataManager(nil, cfg.CacheCfg(), nil)
fltr := engine.NewFilterS(cfg, nil, dm)
@@ -54,11 +55,8 @@ func TestListenAndServe(t *testing.T) {
stopChan <- struct{}{}
}()
accnts.ListenAndServe(stopChan, cfgRld)
}
func TestShutDownCoverage(t *testing.T) {
//this is called in order to cover the ShutDown method
accnts := new(AccountS)
accnts.Shutdown()
}

View File

@@ -78,7 +78,7 @@ func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterI
if filterIDs == nil { // in case we remove a profile we do not need to reload the indexes
return
}
// popultate the indexes
// populate the indexes
idxCacheID := utils.CacheInstanceToArg[utils.CacheInstanceToCacheIndex[cacheID]]
if len(*filterIDs) == 0 { // in case we do not have any filters reload the *none filter indexes
indxID := utils.ConcatenatedKey(utils.MetaNone, utils.MetaAny, utils.MetaAny)

View File

@@ -226,7 +226,7 @@ func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFil
return
}
// updatedIndexesWithContexts will compare the old contexts with the new ones and only uptdate what is needed
// updatedIndexesWithContexts will compare the old contexts with the new ones and only update what is needed
// this is used by the profiles that have context(e.g. AttributeProfile)
func updatedIndexesWithContexts(dm *DataManager, idxItmType, tnt, itemID string,
oldContexts, oldFilterIDs *[]string, newContexts, newFilterIDs []string) (err error) {
@@ -673,6 +673,66 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) {
}); err != nil && err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheAccountProfilesFilterIndexes:
if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
removeIndexKeys, indx); err != nil {
return
}
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
ap, e := dm.GetAccountProfile(tnt, id)
if e != nil {
return nil, e
}
fltrIDs := make([]string, len(ap.FilterIDs))
for i, fltrID := range ap.FilterIDs {
fltrIDs[i] = fltrID
}
return &fltrIDs, nil
}); err != nil && err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheActionProfilesFilterIndexes:
if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
removeIndexKeys, indx); err != nil {
return
}
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
acp, e := dm.GetActionProfile(tnt, id, true, false, utils.NonTransactional)
if e != nil {
return nil, e
}
fltrIDs := make([]string, len(acp.FilterIDs))
for i, fltrID := range acp.FilterIDs {
fltrIDs[i] = fltrID
}
return &fltrIDs, nil
}); err != nil || err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheRateProfilesFilterIndexes:
if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
removeIndexKeys, indx); err != nil {
return
}
idxSlice := indx.AsSlice()
if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
&idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
rp, e := dm.GetRateProfile(tnt, id, true, false, utils.NonTransactional)
if e != nil {
return nil, e
}
fltrIDs := make([]string, len(rp.FilterIDs))
for i, fltrID := range rp.FilterIDs {
fltrIDs[i] = fltrID
}
return &fltrIDs, nil
}); err != nil || err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
case utils.CacheAttributeFilterIndexes:
for itemID := range indx {
var ap *AttributeProfile