Added tenant to automatic cache calls. Fixes #2928

This commit is contained in:
Trial97
2021-05-12 09:44:21 +03:00
committed by Dan Christian Bogos
parent a21280e8bc
commit a8ecf36bec
12 changed files with 37 additions and 30 deletions

View File

@@ -1220,7 +1220,7 @@ func (apiv1 *APIerSv1) ReplayFailedPosts(args ArgsReplyFailedPosts, reply *strin
// CallCache caching the item based on cacheopt
// visible in APIerSv2
func (apiv1 *APIerSv1) CallCache(cacheOpt string, args utils.ArgsGetCacheItem) (err error) {
func (apiv1 *APIerSv1) CallCache(tnt, cacheOpt string, args utils.ArgsGetCacheItem) (err error) {
var reply string
switch cacheOpt {
case utils.META_NONE:
@@ -1228,24 +1228,29 @@ func (apiv1 *APIerSv1) CallCache(cacheOpt string, args utils.ArgsGetCacheItem) (
case utils.MetaReload:
if err = apiv1.ConnMgr.Call(apiv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithArgDispatcher{
TenantArg: utils.TenantArg{Tenant: tnt},
AttrReloadCache: composeArgsReload(args)}, &reply); err != nil {
return err
}
case utils.MetaLoad:
if err = apiv1.ConnMgr.Call(apiv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1LoadCache, utils.AttrReloadCacheWithArgDispatcher{
TenantArg: utils.TenantArg{Tenant: tnt},
AttrReloadCache: composeArgsReload(args)}, &reply); err != nil {
return err
}
case utils.MetaRemove:
if err = apiv1.ConnMgr.Call(apiv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1RemoveItem,
&utils.ArgsGetCacheItemWithArgDispatcher{ArgsGetCacheItem: args}, &reply); err != nil {
&utils.ArgsGetCacheItemWithArgDispatcher{
TenantArg: utils.TenantArg{Tenant: tnt},
ArgsGetCacheItem: args}, &reply); err != nil {
return err
}
case utils.MetaClear:
if err = apiv1.ConnMgr.Call(apiv1.Config.ApierCfg().CachesConns, nil,
utils.CacheSv1FlushCache, utils.AttrReloadCacheWithArgDispatcher{
TenantArg: utils.TenantArg{Tenant: tnt},
AttrReloadCache: composeArgsReload(args)}, &reply); err != nil {
return err
}

View File

@@ -1020,6 +1020,7 @@ func testApierReloadCache(t *testing.T) {
expectedStats[utils.CacheReverseDestinations].Items = 10
expectedStats[utils.CacheLoadIDs].Items = 20
expectedStats[utils.CacheRPCConnections].Items = 1
expectedStats[utils.CacheActionTriggers].Items = 1
if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithArgDispatcher), &rcvStats); err != nil {
t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
} else if !reflect.DeepEqual(expectedStats, rcvStats) {

View File

@@ -96,7 +96,7 @@ func (APIerSv1 *APIerSv1) SetAttributeProfile(alsWrp *AttributeWithCache, reply
CacheID: utils.CacheAttributeProfiles,
ItemID: alsWrp.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(alsWrp.Cache), args); err != nil {
if err := APIerSv1.CallCache(alsWrp.Tenant, GetCacheOpt(alsWrp.Cache), args); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -120,7 +120,7 @@ func (APIerSv1 *APIerSv1) RemoveAttributeProfile(arg *utils.TenantIDWithCache, r
CacheID: utils.CacheAttributeProfiles,
ItemID: utils.ConcatenatedKey(arg.Tenant, arg.ID),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), args); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), args); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -81,7 +81,7 @@ func (APIerSv1 *APIerSv1) SetChargerProfile(arg *ChargerWithCache, reply *string
CacheID: utils.CacheChargerProfiles,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -106,7 +106,7 @@ func (APIerSv1 *APIerSv1) RemoveChargerProfile(arg *utils.TenantIDWithCache, rep
CacheID: utils.CacheChargerProfiles,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -152,10 +152,10 @@ func testConfigSReloadConfigFromJSONSessionS(t *testing.T) {
"StoreSCosts": false,
"AlterableFields": map[string]interface{}{},
"DefaultUsage": map[string]interface{}{
utils.META_ANY: "3h0m0s",
utils.VOICE: "3h0m0s",
utils.DATA: "1048576",
utils.SMS: "1",
utils.META_ANY: 10800000000000.,
utils.VOICE: 10800000000000.,
utils.DATA: 1048576.,
utils.SMS: 1.,
},
}
if *encoding == utils.MetaGOB {

View File

@@ -86,7 +86,7 @@ func (APIerSv1 *APIerSv1) SetDispatcherProfile(args *DispatcherWithCache, reply
CacheID: utils.CacheDispatcherProfiles,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -111,7 +111,7 @@ func (APIerSv1 *APIerSv1) RemoveDispatcherProfile(arg *utils.TenantIDWithCache,
CacheID: utils.CacheDispatcherProfiles,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -175,7 +175,7 @@ func (APIerSv1 *APIerSv1) SetDispatcherHost(args *DispatcherHostWithCache, reply
CacheID: utils.CacheDispatcherHosts,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -200,7 +200,7 @@ func (APIerSv1 *APIerSv1) RemoveDispatcherHost(arg *utils.TenantIDWithCache, rep
CacheID: utils.CacheDispatcherHosts,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -47,7 +47,7 @@ func (APIerSv1 *APIerSv1) SetFilter(arg *FilterWithCache, reply *string) error {
CacheID: utils.CacheFilters,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -105,7 +105,7 @@ func (APIerSv1 *APIerSv1) RemoveFilter(arg utils.TenantIDWithCache, reply *strin
CacheID: utils.CacheFilters,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -124,7 +124,7 @@ func (APIerSv1 *APIerSv1) SetResourceProfile(arg *ResourceWithCache, reply *stri
CacheID: utils.CacheResourceProfiles,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
//add the resource only if it's not present
@@ -142,7 +142,7 @@ func (APIerSv1 *APIerSv1) SetResourceProfile(arg *ResourceWithCache, reply *stri
CacheID: utils.CacheResources,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
}
@@ -164,7 +164,7 @@ func (APIerSv1 *APIerSv1) RemoveResourceProfile(arg utils.TenantIDWithCache, rep
CacheID: utils.CacheResourceProfiles,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
if err := APIerSv1.DataManager.RemoveResource(arg.Tenant, arg.ID, utils.NonTransactional); err != nil {
@@ -181,7 +181,7 @@ func (APIerSv1 *APIerSv1) RemoveResourceProfile(arg utils.TenantIDWithCache, rep
CacheID: utils.CacheResources,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -79,7 +79,7 @@ func (APIerSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueWithCache, re
CacheID: utils.CacheStatQueueProfiles,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
if has, err := APIerSv1.DataManager.HasData(utils.StatQueuePrefix, arg.ID, arg.Tenant); err != nil {
@@ -102,7 +102,7 @@ func (APIerSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueWithCache, re
CacheID: utils.CacheStatQueues,
ItemID: arg.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(arg.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(arg.Tenant, GetCacheOpt(arg.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
}
@@ -124,7 +124,7 @@ func (APIerSv1 *APIerSv1) RemoveStatQueueProfile(args *utils.TenantIDWithCache,
CacheID: utils.CacheStatQueueProfiles,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
if err := APIerSv1.DataManager.RemoveStatQueue(args.Tenant, args.ID, utils.NonTransactional); err != nil {
@@ -141,7 +141,7 @@ func (APIerSv1 *APIerSv1) RemoveStatQueueProfile(args *utils.TenantIDWithCache,
CacheID: utils.CacheStatQueues,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -81,7 +81,7 @@ func (APIerSv1 *APIerSv1) SetSupplierProfile(args *SupplierWithCache, reply *str
CacheID: utils.CacheSupplierProfiles,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK
@@ -105,7 +105,7 @@ func (APIerSv1 *APIerSv1) RemoveSupplierProfile(args *utils.TenantIDWithCache, r
CacheID: utils.CacheSupplierProfiles,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -113,7 +113,7 @@ func (APIerSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, r
CacheID: utils.CacheThresholdProfiles,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
@@ -128,7 +128,7 @@ func (APIerSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdWithCache, r
CacheID: utils.CacheThresholds,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
}
@@ -150,7 +150,7 @@ func (APIerSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithCache,
CacheID: utils.CacheThresholdProfiles,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
if err := APIerSv1.DataManager.RemoveThreshold(args.Tenant, args.ID, utils.NonTransactional); err != nil {
@@ -167,7 +167,7 @@ func (APIerSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithCache,
CacheID: utils.CacheThresholds,
ItemID: args.TenantID(),
}
if err := APIerSv1.CallCache(GetCacheOpt(args.Cache), argCache); err != nil {
if err := APIerSv1.CallCache(args.Tenant, GetCacheOpt(args.Cache), argCache); err != nil {
return utils.APIErrorHandler(err)
}
*reply = utils.OK

View File

@@ -53,6 +53,7 @@ func (APIerSv2 *APIerSv2) SetAttributeProfile(arg *AttributeWithCache, reply *st
ItemID: alsPrf.TenantID(),
}
if err := APIerSv2.APIerSv1.CallCache(
arg.Tenant,
v1.GetCacheOpt(arg.Cache),
args); err != nil {
return utils.APIErrorHandler(err)