From dc1876a03827077b745c2073186ea7b528f0a606 Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 26 Mar 2019 16:56:22 +0200 Subject: [PATCH] Add LoadID when Set/Remove from APIer --- apier/v1/chargers.go | 5 +++++ apier/v1/dispatcher.go | 10 ++++++++++ apier/v1/filters.go | 10 ++++++++++ apier/v1/resourcesv1.go | 10 ++++++++++ apier/v1/stats.go | 9 +++++++++ apier/v1/suppliers.go | 10 ++++++++++ apier/v1/thresholds.go | 10 ++++++++++ apier/v2/attributes.go | 5 +++++ data/conf/samples/smgeneric/cgrates.json | 6 ------ data/conf/samples/smgreplcslave/cgrates.json | 6 ------ 10 files changed, 69 insertions(+), 12 deletions(-) diff --git a/apier/v1/chargers.go b/apier/v1/chargers.go index fe2361cf9..b10498c79 100644 --- a/apier/v1/chargers.go +++ b/apier/v1/chargers.go @@ -70,6 +70,11 @@ func (apierV1 *ApierV1) SetChargerProfile(arg *ChargerWrapper, reply *string) er if err := apierV1.DataManager.SetChargerProfile(arg.ChargerProfile, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheChargerProfiles: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for ChargerProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheChargerProfiles, diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index b6834255c..2e3d61926 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -75,6 +75,11 @@ func (apierV1 *ApierV1) SetDispatcherProfile(args *DispatcherWrapper, reply *str if err := apierV1.DataManager.SetDispatcherProfile(args.DispatcherProfile, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheDispatcherProfiles: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for DispatcherProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheDispatcherProfiles, @@ -96,6 +101,11 @@ func (apierV1 *ApierV1) RemoveDispatcherProfile(arg *utils.TenantIDWrapper, repl arg.ID, utils.NonTransactional, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheFilters: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for DispatcherProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheDispatcherProfiles, diff --git a/apier/v1/filters.go b/apier/v1/filters.go index 5b368d4fa..5893b2414 100644 --- a/apier/v1/filters.go +++ b/apier/v1/filters.go @@ -36,6 +36,11 @@ func (apierV1 *ApierV1) SetFilter(arg *FilterWrapper, reply *string) error { if err := apierV1.DataManager.SetFilter(arg.Filter); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheFilters: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for Filter argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheFilters, @@ -93,6 +98,11 @@ func (apierV1 *ApierV1) RemoveFilter(arg utils.TenantIDWrapper, reply *string) e } return err } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheFilters: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for Filter argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheFilters, diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go index 44d913f6c..4d95efb10 100644 --- a/apier/v1/resourcesv1.go +++ b/apier/v1/resourcesv1.go @@ -120,6 +120,12 @@ func (apierV1 *ApierV1) SetResourceProfile(arg *ResourceWrapper, reply *string) if err := apierV1.DataManager.SetResourceProfile(arg.ResourceProfile, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for thresholdProfile and store it in database + loadID := utils.UUIDSha1Prefix() + loadIDs := map[string]string{utils.CacheResourceProfiles: loadID} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for ResourceProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheResourceProfiles, @@ -134,6 +140,10 @@ func (apierV1 *ApierV1) SetResourceProfile(arg *ResourceWrapper, reply *string) Usages: make(map[string]*engine.ResourceUsage)}); err != nil { return utils.APIErrorHandler(err) } + loadIDs2 := map[string]string{utils.CacheResources: loadID} + if err := apierV1.DataManager.SetLoadIDs(loadIDs2); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for Resource argCache = engine.ArgsGetCacheItem{ CacheID: utils.CacheResources, diff --git a/apier/v1/stats.go b/apier/v1/stats.go index cf0895a5c..3cc6f3805 100644 --- a/apier/v1/stats.go +++ b/apier/v1/stats.go @@ -68,6 +68,11 @@ func (apierV1 *ApierV1) SetStatQueueProfile(arg *StatQueueWrapper, reply *string if err := apierV1.DataManager.SetStatQueueProfile(arg.StatQueueProfile, true); err != nil { return utils.APIErrorHandler(err) } + loadID := utils.UUIDSha1Prefix() + loadIDs := map[string]string{utils.CacheStatQueueProfiles: loadID} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for StatQueueProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheStatQueueProfiles, @@ -88,6 +93,10 @@ func (apierV1 *ApierV1) SetStatQueueProfile(arg *StatQueueWrapper, reply *string if err := apierV1.DataManager.SetStatQueue(&engine.StatQueue{Tenant: arg.Tenant, ID: arg.ID, SQMetrics: metrics}); err != nil { return utils.APIErrorHandler(err) } + loadIDs2 := map[string]string{utils.CacheStatQueues: loadID} + if err := apierV1.DataManager.SetLoadIDs(loadIDs2); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for StatQueues argCache = engine.ArgsGetCacheItem{ CacheID: utils.CacheStatQueues, diff --git a/apier/v1/suppliers.go b/apier/v1/suppliers.go index b7266d2b1..cd9fb2b4d 100644 --- a/apier/v1/suppliers.go +++ b/apier/v1/suppliers.go @@ -70,6 +70,11 @@ func (apierV1 *ApierV1) SetSupplierProfile(args *SupplierWrapper, reply *string) if err := apierV1.DataManager.SetSupplierProfile(args.SupplierProfile, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheSupplierProfiles: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for SupplierProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheSupplierProfiles, @@ -90,6 +95,11 @@ func (apierV1 *ApierV1) RemoveSupplierProfile(args *utils.TenantIDWrapper, reply if err := apierV1.DataManager.RemoveSupplierProfile(args.Tenant, args.ID, utils.NonTransactional, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheChargerProfiles: utils.UUIDSha1Prefix()} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for SupplierProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheSupplierProfiles, diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go index 07fa6a8d8..96b2c2f5d 100644 --- a/apier/v1/thresholds.go +++ b/apier/v1/thresholds.go @@ -102,6 +102,12 @@ func (apierV1 *ApierV1) SetThresholdProfile(args *ThresholdWrapper, reply *strin if err := apierV1.DataManager.SetThresholdProfile(args.ThresholdProfile, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for thresholdProfile and store it in database + loadID := utils.UUIDSha1Prefix() + loadIDs := map[string]string{utils.CacheThresholdProfiles: loadID} + if err := apierV1.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for ThresholdProfile argCache := engine.ArgsGetCacheItem{ CacheID: utils.CacheThresholdProfiles, @@ -113,6 +119,10 @@ func (apierV1 *ApierV1) SetThresholdProfile(args *ThresholdWrapper, reply *strin if err := apierV1.DataManager.SetThreshold(&engine.Threshold{Tenant: args.Tenant, ID: args.ID}); err != nil { return err } + loadIDs2 := map[string]string{utils.CacheThresholds: loadID} + if err := apierV1.DataManager.SetLoadIDs(loadIDs2); err != nil { + return utils.APIErrorHandler(err) + } //handle caching for Threshold argCache = engine.ArgsGetCacheItem{ CacheID: utils.CacheThresholds, diff --git a/apier/v2/attributes.go b/apier/v2/attributes.go index cb2aef98f..4ca8a16c7 100644 --- a/apier/v2/attributes.go +++ b/apier/v2/attributes.go @@ -41,6 +41,11 @@ func (apierV2 *ApierV2) SetAttributeProfile(extAlsPrfWrp *AttributeWrapper, repl if err := apierV2.DataManager.SetAttributeProfile(alsPrf, true); err != nil { return utils.APIErrorHandler(err) } + //generate a loadID for attributeProfile and store it in database + loadIDs := map[string]string{utils.CacheAttributeProfiles: utils.UUIDSha1Prefix()} + if err := apierV2.DataManager.SetLoadIDs(loadIDs); err != nil { + return utils.APIErrorHandler(err) + } args := engine.ArgsGetCacheItem{ CacheID: utils.CacheAttributeProfiles, ItemID: alsPrf.TenantID(), diff --git a/data/conf/samples/smgeneric/cgrates.json b/data/conf/samples/smgeneric/cgrates.json index 63a0e488b..59745303a 100644 --- a/data/conf/samples/smgeneric/cgrates.json +++ b/data/conf/samples/smgeneric/cgrates.json @@ -58,11 +58,5 @@ "enabled": true, // starts User service: . }, -"apier": { - "caches_conns":[ // connections to CacheS for reloads - {"address": "127.0.0.1:3012", "transport": "*json"}, - ], -}, - } diff --git a/data/conf/samples/smgreplcslave/cgrates.json b/data/conf/samples/smgreplcslave/cgrates.json index 3f6a90772..1f286dddb 100644 --- a/data/conf/samples/smgreplcslave/cgrates.json +++ b/data/conf/samples/smgreplcslave/cgrates.json @@ -47,10 +47,4 @@ ], }, -"apier": { - "caches_conns":[ // connections to CacheS for reloads - {"address": "127.0.0.1:22012", "transport": "*json"}, - ], -}, - }