From d0be12cc0a2d7c32d1d2e9b0dfd07f1280699b91 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 30 Aug 2017 05:33:34 -0400 Subject: [PATCH] Fix for rename from ResourceLimit -> Resource --- apier/v1/apier.go | 46 ++++++++++++++++----------------- apier/v1/apier_it_test.go | 2 +- apier/v1/smgenericv1_it_test.go | 2 +- apier/v1/tpresources.go | 24 ++++++++--------- apier/v2/apier.go | 2 +- cmd/cgr-loader/cgr-loader.go | 4 +-- engine/loader_csv_test.go | 6 ++--- engine/model_helpers.go | 2 +- engine/model_helpers_test.go | 2 +- engine/resources.go | 2 +- engine/resources_test.go | 2 +- engine/storage_csv.go | 4 +-- engine/storage_interface.go | 4 +-- engine/storage_map.go | 10 +++---- engine/storage_mongo_datadb.go | 16 ++++++------ engine/storage_mongo_stordb.go | 8 +++--- engine/storage_redis.go | 12 ++++----- engine/storage_sql.go | 8 +++--- engine/tp_reader.go | 16 ++++++------ engine/tpimporter_csv.go | 8 +++--- engine/version.go | 18 ++++++------- utils/apitpdata.go | 8 +++--- utils/consts.go | 8 +++--- 23 files changed, 107 insertions(+), 107 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 5de5cf5d1..0c4c37adf 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -358,7 +358,7 @@ func (self *ApierV1) LoadTariffPlanFromStorDb(attrs AttrLoadTpFromStorDb, reply for _, prfx := range []string{ utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX, - utils.ResourceLimitsPrefix} { + utils.ResourcesPrefix} { loadedIDs, _ := dbReader.GetLoadedIds(prfx) if err := self.DataDB.CacheDataFromDB(prfx, loadedIDs, true); err != nil { return utils.NewErrServerError(err) @@ -926,17 +926,17 @@ func (self *ApierV1) ReloadCache(attrs utils.AttrReloadCache, reply *string) (er if err = self.DataDB.CacheDataFromDB(utils.REVERSE_ALIASES_PREFIX, dataIDs, true); err != nil { return } - // ResourceLimits + // Resources dataIDs = make([]string, 0) - if attrs.ResourceLimitIDs == nil { + if attrs.ResourceIDs == nil { dataIDs = nil // Reload all - } else if len(*attrs.ResourceLimitIDs) > 0 { - dataIDs = make([]string, len(*attrs.ResourceLimitIDs)) - for idx, dId := range *attrs.ResourceLimitIDs { + } else if len(*attrs.ResourceIDs) > 0 { + dataIDs = make([]string, len(*attrs.ResourceIDs)) + for idx, dId := range *attrs.ResourceIDs { dataIDs[idx] = dId } } - if err = self.DataDB.CacheDataFromDB(utils.ResourceLimitsPrefix, dataIDs, true); err != nil { + if err = self.DataDB.CacheDataFromDB(utils.ResourcesPrefix, dataIDs, true); err != nil { return } *reply = utils.OK @@ -1013,10 +1013,10 @@ func (self *ApierV1) LoadCache(args utils.AttrReloadCache, reply *string) (err e } else { rvAlsIDs = *args.ReverseAliasIDs } - if args.ResourceLimitIDs == nil { + if args.ResourceIDs == nil { rlIDs = nil } else { - rlIDs = *args.ResourceLimitIDs + rlIDs = *args.ResourceIDs } if err := self.DataDB.LoadRatingCache(dstIDs, rvDstIDs, rplIDs, rpfIDs, actIDs, aplIDs, aapIDs, atrgIDs, sgIDs, lcrIDs, dcIDs); err != nil { return utils.NewErrServerError(err) @@ -1119,11 +1119,11 @@ func (self *ApierV1) FlushCache(args utils.AttrReloadCache, reply *string) (err cache.RemKey(utils.REVERSE_ALIASES_PREFIX+key, true, utils.NonTransactional) } } - if args.ResourceLimitIDs == nil { - cache.RemPrefixKey(utils.ResourceLimitsPrefix, true, utils.NonTransactional) - } else if len(*args.ResourceLimitIDs) != 0 { - for _, key := range *args.ResourceLimitIDs { - cache.RemKey(utils.ResourceLimitsPrefix+key, true, utils.NonTransactional) + if args.ResourceIDs == nil { + cache.RemPrefixKey(utils.ResourcesPrefix, true, utils.NonTransactional) + } else if len(*args.ResourceIDs) != 0 { + for _, key := range *args.ResourceIDs { + cache.RemKey(utils.ResourcesPrefix+key, true, utils.NonTransactional) } } *reply = utils.OK @@ -1144,7 +1144,7 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach cs.LcrProfiles = cache.CountEntries(utils.LCR_PREFIX) cs.Aliases = cache.CountEntries(utils.ALIASES_PREFIX) cs.ReverseAliases = cache.CountEntries(utils.REVERSE_ALIASES_PREFIX) - cs.ResourceLimits = cache.CountEntries(utils.ResourceLimitsPrefix) + cs.Resources = cache.CountEntries(utils.ResourcesPrefix) if self.CdrStatsSrv != nil { var queueIds []string @@ -1402,22 +1402,22 @@ func (v1 *ApierV1) GetCacheKeys(args utils.ArgsCacheKeys, reply *utils.ArgsCache reply.ReverseAliasIDs = &ids } } - if args.ResourceLimitIDs != nil { + if args.ResourceIDs != nil { var ids []string - if len(*args.ResourceLimitIDs) != 0 { - for _, id := range *args.ResourceLimitIDs { - if _, hasIt := cache.Get(utils.ResourceLimitsPrefix + id); hasIt { + if len(*args.ResourceIDs) != 0 { + for _, id := range *args.ResourceIDs { + if _, hasIt := cache.Get(utils.ResourcesPrefix + id); hasIt { ids = append(ids, id) } } } else { - for _, id := range cache.GetEntryKeys(utils.ResourceLimitsPrefix) { - ids = append(ids, id[len(utils.ResourceLimitsPrefix):]) + for _, id := range cache.GetEntryKeys(utils.ResourcesPrefix) { + ids = append(ids, id[len(utils.ResourcesPrefix):]) } } ids = args.Paginator.PaginateStringSlice(ids) if len(ids) != 0 { - reply.ResourceLimitIDs = &ids + reply.ResourceIDs = &ids } } return @@ -1494,7 +1494,7 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, for _, prfx := range []string{ utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX, - utils.ResourceLimitsPrefix} { + utils.ResourcesPrefix} { loadedIDs, _ := loader.GetLoadedIds(prfx) if err := self.DataDB.CacheDataFromDB(prfx, loadedIDs, true); err != nil { return utils.NewErrServerError(err) diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index 0d6ad6587..22bf7ff84 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -1272,7 +1272,7 @@ func TestApierResetDataAfterLoadFromFolder(t *testing.T) { rcvStats.LcrProfiles != 0 || rcvStats.Aliases != 1 || rcvStats.ReverseAliases != 2 || - rcvStats.ResourceLimits != 3 { + rcvStats.Resources != 3 { t.Errorf("Expecting: %+v, received: %+v", expStats, rcvStats) } } diff --git a/apier/v1/smgenericv1_it_test.go b/apier/v1/smgenericv1_it_test.go index c9e14a20f..3c87dcad6 100644 --- a/apier/v1/smgenericv1_it_test.go +++ b/apier/v1/smgenericv1_it_test.go @@ -102,7 +102,7 @@ func TestSMGV1CacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, - LcrProfiles: 5, CdrStats: 6, Users: 3, Aliases: 1, ReverseAliases: 2, ResourceLimits: 3} + LcrProfiles: 5, CdrStats: 6, Users: 3, Aliases: 1, ReverseAliases: 2, Resources: 3} var args utils.AttrCacheStats if err := smgV1Rpc.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) diff --git a/apier/v1/tpresources.go b/apier/v1/tpresources.go index b89cd23c8..788806861 100644 --- a/apier/v1/tpresources.go +++ b/apier/v1/tpresources.go @@ -21,12 +21,12 @@ import ( "github.com/cgrates/cgrates/utils" ) -// Creates a new resource limit within a tariff plan -func (self *ApierV1) SetTPResourceLimit(attr utils.TPResource, reply *string) error { +// Creates a new resource within a tariff plan +func (self *ApierV1) SetTPResource(attr utils.TPResource, reply *string) error { if missing := utils.MissingStructFields(&attr, []string{"TPid", "ID", "Limit"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.SetTPResource([]*utils.TPResource{&attr}); err != nil { + if err := self.StorDb.SetTPResources([]*utils.TPResource{&attr}); err != nil { return utils.APIErrorHandler(err) } *reply = utils.OK @@ -38,12 +38,12 @@ type AttrGetTPResource struct { ID string } -// Queries specific ResourceLimit on Tariff plan -func (self *ApierV1) GetTPResourceLimit(attr AttrGetTPResource, reply *utils.TPResource) error { +// Queries specific Resource on Tariff plan +func (self *ApierV1) GetTPResource(attr AttrGetTPResource, reply *utils.TPResource) error { if missing := utils.MissingStructFields(&attr, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if rls, err := self.StorDb.GetTPResource(attr.TPid, attr.ID); err != nil { + if rls, err := self.StorDb.GetTPResources(attr.TPid, attr.ID); err != nil { return utils.NewErrServerError(err) } else if len(rls) == 0 { return utils.ErrNotFound @@ -58,12 +58,12 @@ type AttrGetTPResourceIds struct { utils.Paginator } -// Queries ResourceLimit identities on specific tariff plan. -func (self *ApierV1) GetTPResourceLimitIDs(attrs AttrGetTPResourceIds, reply *[]string) error { +// Queries Resource identities on specific tariff plan. +func (self *ApierV1) GetTPResourceIDs(attrs AttrGetTPResourceIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPResource, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil { + if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPResources, utils.TPDistinctIds{"tag"}, nil, &attrs.Paginator); err != nil { return utils.NewErrServerError(err) } else if ids == nil { return utils.ErrNotFound @@ -73,12 +73,12 @@ func (self *ApierV1) GetTPResourceLimitIDs(attrs AttrGetTPResourceIds, reply *[] return nil } -// Removes specific ResourceLimit on Tariff plan -func (self *ApierV1) RemTPResourceLimit(attrs AttrGetTPResource, reply *string) error { +// Removes specific Resource on Tariff plan +func (self *ApierV1) RemTPResource(attrs AttrGetTPResource, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "ID"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } - if err := self.StorDb.RemTpData(utils.TBLTPResource, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { + if err := self.StorDb.RemTpData(utils.TBLTPResources, attrs.TPid, map[string]string{"tag": attrs.ID}); err != nil { return utils.NewErrServerError(err) } else { *reply = utils.OK diff --git a/apier/v2/apier.go b/apier/v2/apier.go index 8628dcea9..5a292a506 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -182,7 +182,7 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, for _, prfx := range []string{ utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX, - utils.ResourceLimitsPrefix} { + utils.ResourcesPrefix} { loadedIDs, _ := loader.GetLoadedIds(prfx) if err := self.DataDB.CacheDataFromDB(prfx, loadedIDs, true); err != nil { return utils.NewErrServerError(err) diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 6a46444d5..f082fbf01 100755 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -354,7 +354,7 @@ func main() { alsIds, _ = tpReader.GetLoadedIds(utils.ALIASES_PREFIX) lcrIds, _ = tpReader.GetLoadedIds(utils.LCR_PREFIX) dcsIds, _ = tpReader.GetLoadedIds(utils.DERIVEDCHARGERS_PREFIX) - rlIDs, _ = tpReader.GetLoadedIds(utils.ResourceLimitsPrefix) + rlIDs, _ = tpReader.GetLoadedIds(utils.ResourcesPrefix) aatIDs, _ = tpReader.GetLoadedIds(utils.ACTION_TRIGGER_PREFIX) ralsIDs, _ = tpReader.GetLoadedIds(utils.REVERSE_ALIASES_PREFIX) } @@ -392,7 +392,7 @@ func main() { DerivedChargerIDs: &dcsIds, AliasIDs: &alsIds, ReverseAliasIDs: &ralsIDs, - ResourceLimitIDs: &rlIDs}, + ResourceIDs: &rlIDs}, FlushAll: *flush, }, &reply); err != nil { log.Printf("WARNING: Got error on cache reload: %s\n", err.Error()) diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 5b6b7a8b3..ec604c377 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -335,8 +335,8 @@ func init() { if err := csvr.LoadAliases(); err != nil { log.Print("error in LoadAliases:", err) } - if err := csvr.LoadResourceLimits(); err != nil { - log.Print("error in LoadResourceLimits:", err) + if err := csvr.LoadResources(); err != nil { + log.Print("error in LoadResources:", err) } if err := csvr.LoadStats(); err != nil { @@ -1388,7 +1388,7 @@ func TestLoadReverseAliases(t *testing.T) { } } -func TestLoadResource(t *testing.T) { +func TestLoadResources(t *testing.T) { eResLimits := map[string]*utils.TPResource{ "ResGroup21": &utils.TPResource{ TPid: testTPID, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index fc38254d4..45e156624 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1813,7 +1813,7 @@ func APItoModelLcrRules(ts []*utils.TPLcrRules) (result TpLcrRules) { type TpResources []*TpResource -func (tps TpResources) AsTPResource() (result []*utils.TPResource) { +func (tps TpResources) AsTPResources() (result []*utils.TPResource) { mrl := make(map[string]*utils.TPResource) for _, tp := range tps { rl, found := mrl[tp.Tag] diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index a020c9594..1662db579 100755 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -786,7 +786,7 @@ func TestTpResourcesAsTpResources(t *testing.T) { Limit: tps[2].Limit, }, } - rcvTPs := TpResources(tps).AsTPResource() + rcvTPs := TpResources(tps).AsTPResources() if !(reflect.DeepEqual(eTPs, rcvTPs) || reflect.DeepEqual(eTPs[0], rcvTPs[1])) { t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v", utils.ToIJSON(eTPs), utils.ToIJSON(rcvTPs)) } diff --git a/engine/resources.go b/engine/resources.go index 0328e85c7..c99668e60 100755 --- a/engine/resources.go +++ b/engine/resources.go @@ -234,7 +234,7 @@ func (rS *ResourceService) ServiceShutdown() error { func (rS *ResourceService) matchingResourcesForEvent( ev map[string]interface{}) (rs Resources, err error) { matchingResources := make(map[string]*Resource) - rlIDs, err := matchingItemIDsForEvent(ev, rS.dataDB, utils.ResourceLimitsIndex) + rlIDs, err := matchingItemIDsForEvent(ev, rS.dataDB, utils.ResourcesIndex) if err != nil { return nil, err } diff --git a/engine/resources_test.go b/engine/resources_test.go index c6409ab57..705c034ee 100644 --- a/engine/resources_test.go +++ b/engine/resources_test.go @@ -30,7 +30,7 @@ var ( rs Resources ) -func TestResourceLimitRecordUsage(t *testing.T) { +func TestResourceRecordUsage(t *testing.T) { ru = &ResourceUsage{ ID: "RU1", ExpiryTime: time.Date(2014, 7, 3, 13, 43, 0, 1, time.UTC), diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 32528802d..359bc3ee4 100755 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -592,7 +592,7 @@ func (csvs *CSVStorage) GetTPAliases(filter *utils.TPAliases) ([]*utils.TPAliase } } -func (csvs *CSVStorage) GetTPResource(tpid, id string) ([]*utils.TPResource, error) { +func (csvs *CSVStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { csvReader, fp, err := csvs.readerFunc(csvs.resLimitsFn, csvs.sep, getColumnCount(TpResource{})) if err != nil { //log.Print("Could not load resource limits file: ", err) @@ -617,7 +617,7 @@ func (csvs *CSVStorage) GetTPResource(tpid, id string) ([]*utils.TPResource, err tpResLimits = append(tpResLimits, &tpLimit) } } - return tpResLimits.AsTPResource(), nil + return tpResLimits.AsTPResources(), nil } func (csvs *CSVStorage) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 834da7256..bcf1a71ea 100755 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -165,7 +165,7 @@ type LoadReader interface { GetTPActionPlans(string, string) ([]*utils.TPActionPlan, error) GetTPActionTriggers(string, string) ([]*utils.TPActionTriggers, error) GetTPAccountActions(*utils.TPAccountActions) ([]*utils.TPAccountActions, error) - GetTPResource(string, string) ([]*utils.TPResource, error) + GetTPResources(string, string) ([]*utils.TPResource, error) GetTPStats(string, string) ([]*utils.TPStats, error) GetTPThreshold(string, string) ([]*utils.TPThreshold, error) } @@ -188,7 +188,7 @@ type LoadWriter interface { SetTPActionPlans([]*utils.TPActionPlan) error SetTPActionTriggers([]*utils.TPActionTriggers) error SetTPAccountActions([]*utils.TPAccountActions) error - SetTPResource([]*utils.TPResource) error + SetTPResources([]*utils.TPResource) error SetTPStats([]*utils.TPStats) error SetTPThreshold([]*utils.TPThreshold) error } diff --git a/engine/storage_map.go b/engine/storage_map.go index 820ad8405..a835b0314 100755 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -220,7 +220,7 @@ func (ms *MapStorage) CacheDataFromDB(prefix string, IDs []string, mustBeCached utils.LCR_PREFIX, utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX, - utils.ResourceLimitsPrefix, + utils.ResourcesPrefix, utils.TimingsPrefix}, prefix) { return utils.NewCGRError(utils.REDIS, utils.MandatoryIEMissingCaps, @@ -284,7 +284,7 @@ func (ms *MapStorage) CacheDataFromDB(prefix string, IDs []string, mustBeCached _, err = ms.GetAlias(dataID, true, utils.NonTransactional) case utils.REVERSE_ALIASES_PREFIX: _, err = ms.GetReverseAlias(dataID, true, utils.NonTransactional) - case utils.ResourceLimitsPrefix: + case utils.ResourcesPrefix: _, err = ms.GetResourceCfg(dataID, true, utils.NonTransactional) case utils.TimingsPrefix: _, err = ms.GetTiming(dataID, true, utils.NonTransactional) @@ -1311,7 +1311,7 @@ func (ms *MapStorage) GetStructVersion() (rsv *StructVersion, err error) { func (ms *MapStorage) GetResourceCfg(id string, skipCache bool, transactionID string) (rl *ResourceCfg, err error) { ms.mu.RLock() defer ms.mu.RUnlock() - key := utils.ResourceLimitsPrefix + id + key := utils.ResourcesPrefix + id if !skipCache { if x, ok := cache.Get(key); ok { if x != nil { @@ -1345,7 +1345,7 @@ func (ms *MapStorage) SetResourceCfg(r *ResourceCfg, transactionID string) error if err != nil { return err } - key := utils.ResourceLimitsPrefix + r.ID + key := utils.ResourcesPrefix + r.ID ms.dict[key] = result return nil } @@ -1353,7 +1353,7 @@ func (ms *MapStorage) SetResourceCfg(r *ResourceCfg, transactionID string) error func (ms *MapStorage) RemoveResourceCfg(id string, transactionID string) error { ms.mu.Lock() defer ms.mu.Unlock() - key := utils.ResourceLimitsPrefix + id + key := utils.ResourcesPrefix + id delete(ms.dict, key) cache.RemKey(key, cacheCommit(transactionID), transactionID) return nil diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 3a8fdae85..95d110d8c 100755 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -323,7 +323,7 @@ func (ms *MongoStorage) getColNameForPrefix(prefix string) (name string, ok bool utils.CDR_STATS_PREFIX: colCrs, utils.LOADINST_KEY: colLht, utils.VERSION_PREFIX: colVer, - utils.ResourceLimitsPrefix: colRL, + utils.ResourcesPrefix: colRL, utils.StatsPrefix: colSts, utils.TimingsPrefix: colTmg, } @@ -440,7 +440,7 @@ func (ms *MongoStorage) LoadAccountingCache(alsIDs, rvAlsIDs, rlIDs []string) (e for key, ids := range map[string][]string{ utils.ALIASES_PREFIX: alsIDs, utils.REVERSE_ALIASES_PREFIX: rvAlsIDs, - utils.ResourceLimitsPrefix: rlIDs, + utils.ResourcesPrefix: rlIDs, } { if err = ms.CacheDataFromDB(key, ids, false); err != nil { return @@ -466,7 +466,7 @@ func (ms *MongoStorage) CacheDataFromDB(prfx string, ids []string, mustBeCached utils.LCR_PREFIX, utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX, - utils.ResourceLimitsPrefix, + utils.ResourcesPrefix, utils.TimingsPrefix}, prfx) { return utils.NewCGRError(utils.MONGO, utils.MandatoryIEMissingCaps, @@ -530,7 +530,7 @@ func (ms *MongoStorage) CacheDataFromDB(prfx string, ids []string, mustBeCached _, err = ms.GetAlias(dataID, true, utils.NonTransactional) case utils.REVERSE_ALIASES_PREFIX: _, err = ms.GetReverseAlias(dataID, true, utils.NonTransactional) - case utils.ResourceLimitsPrefix: + case utils.ResourcesPrefix: _, err = ms.GetResourceCfg(dataID, true, utils.NonTransactional) case utils.TimingsPrefix: _, err = ms.GetTiming(dataID, true, utils.NonTransactional) @@ -624,10 +624,10 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err er for iter.Next(&keyResult) { result = append(result, utils.REVERSE_ALIASES_PREFIX+keyResult.Key) } - case utils.ResourceLimitsPrefix: + case utils.ResourcesPrefix: iter := db.C(colRL).Find(bson.M{"id": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"id": 1}).Iter() for iter.Next(&idResult) { - result = append(result, utils.ResourceLimitsPrefix+idResult.Id) + result = append(result, utils.ResourcesPrefix+idResult.Id) } case utils.StatsPrefix: iter := db.C(colSts).Find(bson.M{"id": bson.M{"$regex": bson.RegEx{Pattern: subject}}}).Select(bson.M{"id": 1}).Iter() @@ -1842,7 +1842,7 @@ func (ms *MongoStorage) GetStructVersion() (rsv *StructVersion, err error) { } func (ms *MongoStorage) GetResourceCfg(id string, skipCache bool, transactionID string) (rl *ResourceCfg, err error) { - key := utils.ResourceLimitsPrefix + id + key := utils.ResourcesPrefix + id if !skipCache { if x, ok := cache.Get(key); ok { if x == nil { @@ -1883,7 +1883,7 @@ func (ms *MongoStorage) RemoveResourceCfg(id string, transactionID string) (err if err = col.Remove(bson.M{"id": id}); err != nil { return } - cache.RemKey(utils.ResourceLimitsPrefix+id, cacheCommit(transactionID), transactionID) + cache.RemKey(utils.ResourcesPrefix+id, cacheCommit(transactionID), transactionID) return nil } diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index b5e65ff27..1980540b1 100755 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -362,7 +362,7 @@ func (ms *MongoStorage) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases, e return results, err } -func (ms *MongoStorage) GetTPResource(tpid, id string) ([]*utils.TPResource, error) { +func (ms *MongoStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { filter := bson.M{ "tpid": tpid, } @@ -370,7 +370,7 @@ func (ms *MongoStorage) GetTPResource(tpid, id string) ([]*utils.TPResource, err filter["id"] = id } var results []*utils.TPResource - session, col := ms.conn(utils.TBLTPResource) + session, col := ms.conn(utils.TBLTPResources) defer session.Close() err := col.Find(filter).All(&results) if len(results) == 0 { @@ -844,11 +844,11 @@ func (ms *MongoStorage) SetTPAccountActions(tps []*utils.TPAccountActions) error return err } -func (ms *MongoStorage) SetTPResource(tpRLs []*utils.TPResource) (err error) { +func (ms *MongoStorage) SetTPResources(tpRLs []*utils.TPResource) (err error) { if len(tpRLs) == 0 { return } - session, col := ms.conn(utils.TBLTPResource) + session, col := ms.conn(utils.TBLTPResources) defer session.Close() tx := col.Bulk() for _, tp := range tpRLs { diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 022788c18..99ad1cc70 100755 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -144,7 +144,7 @@ func (rs *RedisStorage) LoadAccountingCache(alsIDs, rvAlsIDs, rlIDs []string) (e for key, ids := range map[string][]string{ utils.ALIASES_PREFIX: alsIDs, utils.REVERSE_ALIASES_PREFIX: rvAlsIDs, - utils.ResourceLimitsPrefix: rlIDs, + utils.ResourcesPrefix: rlIDs, } { if err = rs.CacheDataFromDB(key, ids, false); err != nil { return @@ -230,7 +230,7 @@ func (rs *RedisStorage) CacheDataFromDB(prfx string, ids []string, mustBeCached utils.LCR_PREFIX, utils.ALIASES_PREFIX, utils.REVERSE_ALIASES_PREFIX, - utils.ResourceLimitsPrefix, + utils.ResourcesPrefix, utils.TimingsPrefix}, prfx) { return utils.NewCGRError(utils.REDIS, utils.MandatoryIEMissingCaps, @@ -294,7 +294,7 @@ func (rs *RedisStorage) CacheDataFromDB(prfx string, ids []string, mustBeCached _, err = rs.GetAlias(dataID, true, utils.NonTransactional) case utils.REVERSE_ALIASES_PREFIX: _, err = rs.GetReverseAlias(dataID, true, utils.NonTransactional) - case utils.ResourceLimitsPrefix: + case utils.ResourcesPrefix: _, err = rs.GetResourceCfg(dataID, true, utils.NonTransactional) case utils.TimingsPrefix: _, err = rs.GetTiming(dataID, true, utils.NonTransactional) @@ -1372,7 +1372,7 @@ func (rs *RedisStorage) GetStructVersion() (rsv *StructVersion, err error) { func (rs *RedisStorage) GetResourceCfg(id string, skipCache bool, transactionID string) (rl *ResourceCfg, err error) { - key := utils.ResourceLimitsPrefix + id + key := utils.ResourcesPrefix + id if !skipCache { if x, ok := cache.Get(key); ok { if x == nil { @@ -1406,11 +1406,11 @@ func (rs *RedisStorage) SetResourceCfg(r *ResourceCfg, transactionID string) err if err != nil { return err } - return rs.Cmd("SET", utils.ResourceLimitsPrefix+r.ID, result).Err + return rs.Cmd("SET", utils.ResourcesPrefix+r.ID, result).Err } func (rs *RedisStorage) RemoveResourceCfg(id string, transactionID string) (err error) { - key := utils.ResourceLimitsPrefix + id + key := utils.ResourcesPrefix + id if err = rs.Cmd("DEL", key).Err; err != nil { return } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 83314da23..05d1cbeab 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -190,7 +190,7 @@ func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) er if len(table) == 0 { // Remove tpid out of all tables for _, tblName := range []string{utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, utils.TBLTPSharedGroups, utils.TBLTPCdrStats, utils.TBLTPLcrs, utils.TBLTPActions, utils.TBLTPActionPlans, utils.TBLTPActionTriggers, utils.TBLTPAccountActions, - utils.TBLTPDerivedChargers, utils.TBLTPAliases, utils.TBLTPUsers, utils.TBLTPResource, utils.TBLTPStats} { + utils.TBLTPDerivedChargers, utils.TBLTPAliases, utils.TBLTPUsers, utils.TBLTPResources, utils.TBLTPStats} { if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil { tx.Rollback() return err @@ -559,7 +559,7 @@ func (self *SQLStorage) SetTPAccountActions(aas []*utils.TPAccountActions) error return nil } -func (self *SQLStorage) SetTPResource(rls []*utils.TPResource) error { +func (self *SQLStorage) SetTPResources(rls []*utils.TPResource) error { if len(rls) == 0 { return nil } @@ -1542,7 +1542,7 @@ func (self *SQLStorage) GetTPAliases(filter *utils.TPAliases) ([]*utils.TPAliase } } -func (self *SQLStorage) GetTPResource(tpid, id string) ([]*utils.TPResource, error) { +func (self *SQLStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { var rls TpResources q := self.db.Where("tpid = ?", tpid) if len(id) != 0 { @@ -1551,7 +1551,7 @@ func (self *SQLStorage) GetTPResource(tpid, id string) ([]*utils.TPResource, err if err := q.Find(&rls).Error; err != nil { return nil, err } - arls := rls.AsTPResource() + arls := rls.AsTPResources() if len(arls) == 0 { return arls, utils.ErrNotFound } diff --git a/engine/tp_reader.go b/engine/tp_reader.go index 7f743bf7a..37217fb0f 100755 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -1591,8 +1591,8 @@ func (tpr *TpReader) LoadAliases() error { return err } -func (tpr *TpReader) LoadResourceFiltered(tag string) error { - rls, err := tpr.lr.GetTPResource(tpr.tpid, tag) +func (tpr *TpReader) LoadResourcesFiltered(tag string) error { + rls, err := tpr.lr.GetTPResources(tpr.tpid, tag) if err != nil { return err } @@ -1604,8 +1604,8 @@ func (tpr *TpReader) LoadResourceFiltered(tag string) error { return nil } -func (tpr *TpReader) LoadResourceLimits() error { - return tpr.LoadResourceFiltered("") +func (tpr *TpReader) LoadResources() error { + return tpr.LoadResourcesFiltered("") } func (tpr *TpReader) LoadStatsFiltered(tag string) error { @@ -1691,7 +1691,7 @@ func (tpr *TpReader) LoadAll() (err error) { if err = tpr.LoadAliases(); err != nil && err.Error() != utils.NotFoundCaps { return } - if err = tpr.LoadResourceLimits(); err != nil && err.Error() != utils.NotFoundCaps { + if err = tpr.LoadResources(); err != nil && err.Error() != utils.NotFoundCaps { return } if err = tpr.LoadStats(); err != nil && err.Error() != utils.NotFoundCaps { @@ -1933,7 +1933,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err } } if verbose { - log.Print("ResourceLimits:") + log.Print("Resources:") } for _, tpRL := range tpr.resLimits { rl, err := APItoResource(tpRL, tpr.timezone) @@ -2017,7 +2017,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err if verbose { log.Print("Indexing resource limits") } - rlIdxr, err := NewReqFilterIndexer(tpr.dataStorage, utils.ResourceLimitsIndex) + rlIdxr, err := NewReqFilterIndexer(tpr.dataStorage, utils.ResourcesIndex) if err != nil { return err } @@ -2253,7 +2253,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) { i++ } return keys, nil - case utils.ResourceLimitsPrefix: + case utils.ResourcesPrefix: keys := make([]string, len(tpr.resLimits)) i := 0 for k := range tpr.resLimits { diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 7044efc2f..fd53573fb 100755 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -56,7 +56,7 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{ utils.LCRS_CSV: (*TPCSVImporter).importLcrs, utils.USERS_CSV: (*TPCSVImporter).importUsers, utils.ALIASES_CSV: (*TPCSVImporter).importAliases, - utils.ResourcesCsv: (*TPCSVImporter).importResourceLimits, + utils.ResourcesCsv: (*TPCSVImporter).importResources, utils.StatsCsv: (*TPCSVImporter).importStats, utils.ThresholdsCsv: (*TPCSVImporter).importThresholds, } @@ -351,15 +351,15 @@ func (self *TPCSVImporter) importAliases(fn string) error { return self.StorDb.SetTPAliases(tps) } -func (self *TPCSVImporter) importResourceLimits(fn string) error { +func (self *TPCSVImporter) importResources(fn string) error { if self.Verbose { log.Printf("Processing file: <%s> ", fn) } - rls, err := self.csvr.GetTPResource(self.TPid, "") + rls, err := self.csvr.GetTPResources(self.TPid, "") if err != nil { return err } - return self.StorDb.SetTPResource(rls) + return self.StorDb.SetTPResources(rls) } func (self *TPCSVImporter) importStats(fn string) error { diff --git a/engine/version.go b/engine/version.go index f571e2f34..7ab66bd2c 100644 --- a/engine/version.go +++ b/engine/version.go @@ -73,7 +73,7 @@ var ( LoadHistory: "1", Cdrs: "1", SMCosts: "1", - ResourceLimits: "1", + Resources: "1", Timings: "1", } ) @@ -97,10 +97,10 @@ type StructVersion struct { PubSubs string LoadHistory string // cdr - Cdrs string - SMCosts string - ResourceLimits string - Timings string + Cdrs string + SMCosts string + Resources string + Timings string } type MigrationInfo struct { @@ -231,11 +231,11 @@ func (sv *StructVersion) CompareAndMigrate(dbVer *StructVersion) []*MigrationInf CurrentVersion: CurrentVersion.SMCosts, }) } - if sv.ResourceLimits != dbVer.ResourceLimits { + if sv.Resources != dbVer.Resources { migrationInfoList = append(migrationInfoList, &MigrationInfo{ - Prefix: utils.ResourceLimitsPrefix, - DbVersion: dbVer.ResourceLimits, - CurrentVersion: CurrentVersion.ResourceLimits, + Prefix: utils.ResourcesPrefix, + DbVersion: dbVer.Resources, + CurrentVersion: CurrentVersion.Resources, }) } return migrationInfoList diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 70e5b97ed..c263a0c8c 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -667,7 +667,7 @@ type ArgsCache struct { DerivedChargerIDs *[]string AliasIDs *[]string ReverseAliasIDs *[]string - ResourceLimitIDs *[]string + ResourceIDs *[]string StatsIDs *[]string ThresholdsIDs *[]string } @@ -704,7 +704,7 @@ type CacheStats struct { Users int Aliases int ReverseAliases int - ResourceLimits int + Resources int //Stats int //thresholds int } @@ -1292,8 +1292,8 @@ type TPActivationInterval struct { } type AttrRLsCache struct { - LoadID string - ResourceLimitIDs []string + LoadID string + ResourceIDs []string } type AttrRLsResourceUsage struct { diff --git a/utils/consts.go b/utils/consts.go index a8815d24c..9a9b69849 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -54,7 +54,7 @@ var ( CacheAliases: ALIASES_PREFIX, CacheReverseAliases: REVERSE_ALIASES_PREFIX, CacheDerivedChargers: DERIVEDCHARGERS_PREFIX, - CacheResources: ResourceLimitsPrefix, + CacheResources: ResourcesPrefix, CacheTimings: TimingsPrefix, } CachePrefixToInstance map[string]string // will be built on init @@ -99,7 +99,7 @@ const ( TBLTPDerivedChargers = "tp_derived_chargers" TBLTPUsers = "tp_users" TBLTPAliases = "tp_aliases" - TBLTPResource = "tp_resources" + TBLTPResources = "tp_resources" TBLTPStats = "tp_stats" TBLTPThresholds = "tp_thresholds" TBLSMCosts = "sm_costs" @@ -234,8 +234,8 @@ const ( USERS_PREFIX = "usr_" ALIASES_PREFIX = "als_" REVERSE_ALIASES_PREFIX = "rls_" - ResourceLimitsPrefix = "res_" - ResourceLimitsIndex = "rsi_" + ResourcesPrefix = "res_" + ResourcesIndex = "rsi_" StatsPrefix = "sts_" StatsIndex = "sti_" ThresholdsPrefix = "ths_"