From c63760942ee70236ea49c8b06ff22798a90ae9ce Mon Sep 17 00:00:00 2001 From: DanB Date: Fri, 14 Jul 2017 21:34:02 +0200 Subject: [PATCH] Storage.SetStoredSQ and GetStoredSQ --- engine/statsqueue.go | 1 + engine/storage_interface.go | 2 ++ engine/storage_map.go | 22 ++++++++++++++++++++++ engine/storage_mongo_datadb.go | 10 ++++++++++ engine/storage_redis.go | 10 ++++++++++ utils/consts.go | 1 + 6 files changed, 46 insertions(+) diff --git a/engine/statsqueue.go b/engine/statsqueue.go index 40abc08e7..65aeae8b8 100644 --- a/engine/statsqueue.go +++ b/engine/statsqueue.go @@ -33,6 +33,7 @@ type SQItem struct { // SQStored contains values saved in DB on store type StoredSQ struct { + SqID string // StatsQueueID SEvents map[string]StatsEvent // Events used by SQItems SQItems []*SQItem // SQItems SQMetrics map[string][]byte diff --git a/engine/storage_interface.go b/engine/storage_interface.go index fe3f68bc4..b4e371a7f 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -110,6 +110,8 @@ type DataDB interface { GetReqFilterIndexes(dbKey string) (indexes map[string]map[string]utils.StringMap, err error) SetReqFilterIndexes(dbKey string, indexes map[string]map[string]utils.StringMap) (err error) MatchReqFilterIndex(dbKey, fieldValKey string) (itemIDs utils.StringMap, err error) + SetStoredSQ(ssq *StoredSQ) (err error) // stores StatsQueue + GetStoredSQ(sqID string) (ssq *StoredSQ, err error) // CacheDataFromDB loads data to cache, prefix represents the cache prefix, IDs should be nil if all available data should be loaded CacheDataFromDB(prefix string, IDs []string, mustBeCached bool) error // ToDo: Move this to dataManager } diff --git a/engine/storage_map.go b/engine/storage_map.go index 221247d3b..73998cd2f 100644 --- a/engine/storage_map.go +++ b/engine/storage_map.go @@ -1548,3 +1548,25 @@ func (ms *MapStorage) SetVersions(vrs Versions, overwrite bool) (err error) { func (ms *MapStorage) RemoveVersions(vrs Versions) (err error) { return } + +// SetStoredSQ stores the variable part of a StatsQueue +func (ms *MapStorage) SetStoredSQ(ssq *StoredSQ) (err error) { + ms.mu.Lock() + defer ms.mu.Unlock() + var result []byte + result, err = ms.ms.Marshal(ssq) + ms.dict[utils.StoredSQPrefix+ssq.SqID] = result + return +} + +// GetStoredSQ retrieves the variable part of a StatsQueue +func (ms *MapStorage) GetStoredSQ(sqID string) (ssq *StoredSQ, err error) { + ms.mu.RLock() + defer ms.mu.RUnlock() + values, ok := ms.dict[utils.StoredSQPrefix+ssq.SqID] + if !ok { + return nil, utils.ErrNotFound + } + err = ms.ms.Unmarshal(values, &ssq) + return +} diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 6aebbbbaa..9db059b6f 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -2008,3 +2008,13 @@ func (ms *MongoStorage) MatchReqFilterIndex(dbKey, fieldValKey string) (itemIDs cache.Set(cacheKey, itemIDs, true, utils.NonTransactional) return } + +// SetStoredSQ stores the variable part of a StatsQueue +func (ms *MongoStorage) SetStoredSQ(ssq *StoredSQ) (err error) { + return +} + +// GetStoredSQ retrieves the variable part of a StatsQueue +func (ms *MongoStorage) GetStoredSQ(sqID string) (ssq *StoredSQ, err error) { + return +} diff --git a/engine/storage_redis.go b/engine/storage_redis.go index edc0cf0a8..064dd9c4d 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -1566,3 +1566,13 @@ func (rs *RedisStorage) SetVersions(vrs Versions, overwrite bool) (err error) { func (rs *RedisStorage) RemoveVersions(vrs Versions) (err error) { return } + +// SetStoredSQ stores the variable part of a StatsQueue +func (rs *RedisStorage) SetStoredSQ(ssq *StoredSQ) (err error) { + return +} + +// GetStoredSQ retrieves the variable part of a StatsQueue +func (rs *RedisStorage) GetStoredSQ(sqID string) (ssq *StoredSQ, err error) { + return +} diff --git a/utils/consts.go b/utils/consts.go index 978a20aff..367d006a1 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -223,6 +223,7 @@ const ( LOG_ERR = "ler_" LOG_CDR = "cdr_" LOG_MEDIATED_CDR = "mcd_" + StoredSQPrefix = "ssq_" LOADINST_KEY = "load_history" SESSION_MANAGER_SOURCE = "SMR" MEDIATOR_SOURCE = "MED"