diff --git a/apis/filter_indexes.go b/apis/filter_indexes.go index bbeb92708..fab5f135d 100644 --- a/apis/filter_indexes.go +++ b/apis/filter_indexes.go @@ -17,6 +17,7 @@ package apis import ( "strings" + "time" "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" @@ -37,6 +38,7 @@ type AttrRemFilterIndexes struct { Tenant string Context string ItemType string + APIOpts map[string]interface{} } func (adms *AdminSv1) RemoveFilterIndexes(ctx *context.Context, arg *AttrRemFilterIndexes, reply *string) (err error) { @@ -75,6 +77,15 @@ func (adms *AdminSv1) RemoveFilterIndexes(ctx *context.Context, arg *AttrRemFilt if err = adms.dm.RemoveIndexes(ctx, arg.ItemType, tntCtx, utils.EmptyString); err != nil { return } + //generate a loadID for CacheFilterIndexes and store it in database + if err := adms.dm.SetLoadIDs(ctx, + map[string]int64{arg.ItemType: time.Now().UnixNano()}); err != nil { + return utils.APIErrorHandler(err) + } + if err := adms.callCacheForIndexes(ctx, utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, + arg.ItemType, arg.APIOpts); err != nil { + return utils.APIErrorHandler(err) + } *reply = utils.OK return } diff --git a/apis/filter_indexes_it_test.go b/apis/filter_indexes_it_test.go index 5d8a0ce8b..f439cfbb9 100644 --- a/apis/filter_indexes_it_test.go +++ b/apis/filter_indexes_it_test.go @@ -578,7 +578,9 @@ func testV1FIdxAttributeSRemoveComputedIndexesIDs(t *testing.T) { } if err := tFIdxRpc.Call(context.Background(), utils.AdminSv1RemoveFilterIndexes, &AttrRemFilterIndexes{Tenant: utils.CGRateSorg, Context: utils.MetaSessionS, - ItemType: utils.MetaAttributes}, + ItemType: utils.MetaAttributes, APIOpts: map[string]interface{}{ + utils.CacheOpt: utils.MetaClear, + }}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { diff --git a/apis/libadmin.go b/apis/libadmin.go index d573fa791..ee7d74101 100644 --- a/apis/libadmin.go +++ b/apis/libadmin.go @@ -137,6 +137,21 @@ func (admS *AdminSv1) composeArgsReload(ctx *context.Context, tnt, cacheID, item return } +// callCacheForIndexes will only call CacheClear because don't have access at ItemID +func (admS *AdminSv1) callCacheForIndexes(ctx *context.Context, cacheopt string, tnt, cacheID string, + opts map[string]interface{}) (err error) { + if utils.FirstNonEmpty(cacheopt, admS.cfg.GeneralCfg().DefaultCaching) == utils.MetaClear { + var reply string + return admS.connMgr.Call(ctx, admS.cfg.AdminSCfg().CachesConns, + utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + Tenant: tnt, + CacheIDs: []string{cacheID}, + APIOpts: opts, + }, &reply) + } + return +} + /* // callCacheRevDestinations used for reverse destination, loadIDs and indexes replication func (apierSv1 *AdminS) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs []string, opts map[string]interface{}) (err error) { diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index 608507685..ec4fd1892 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -342,6 +342,8 @@ func TestThresholdsmatchingThresholdsForEvent(t *testing.T) { }, }, } + dmTH.SetFilter(context.TODO(), fltrTh2, true) + dmTH.SetFilter(context.TODO(), fltrTh3, true) for _, th := range tPrfls { if err = dmTH.SetThresholdProfile(th, true); err != nil { t.Errorf("Error: %+v", err) diff --git a/engine/z_filterhelpers_test.go b/engine/z_filterhelpers_test.go index 503304385..b7174a5af 100644 --- a/engine/z_filterhelpers_test.go +++ b/engine/z_filterhelpers_test.go @@ -154,6 +154,7 @@ func TestFilterMatchingItemIDsForEvent2(t *testing.T) { Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "stringFilter", Rules: stringFilter} + dmMatch.SetFilter(context.TODO(), attribStringF, true) x, err = NewFilterRule(utils.MetaPrefix, "~*req.CallCost.Field", []string{"profile"}) if err != nil { @@ -164,6 +165,7 @@ func TestFilterMatchingItemIDsForEvent2(t *testing.T) { Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "prefFilter", Rules: prefixFilter} + dmMatch.SetFilter(context.TODO(), attribPrefF, true) x, err = NewFilterRule(utils.MetaGreaterOrEqual, "~*req.Weight", []string{"200.00"}) if err != nil { @@ -173,8 +175,9 @@ func TestFilterMatchingItemIDsForEvent2(t *testing.T) { attribDefaultF := &Filter{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "defaultFilter", - Rules: defaultFilter} - + Rules: defaultFilter, + } + dmMatch.SetFilter(context.TODO(), attribDefaultF, true) tnt := config.CgrConfig().GeneralCfg().DefaultTenant if err = addItemToFilterIndex(context.TODO(), dmMatch, utils.CacheAttributeFilterIndexes,