Adding LoadID methods in storage_interface

This commit is contained in:
TeoV
2019-03-26 10:19:57 +02:00
committed by Dan Christian Bogos
parent b2cd78af5d
commit ba419ec67e
7 changed files with 64 additions and 1 deletions

View File

@@ -85,6 +85,9 @@ func (apierV1 *ApierV1) SetAttributeProfile(alsWrp *AttributeWrapper, reply *str
if err := apierV1.DataManager.SetAttributeProfile(alsWrp.AttributeProfile, true); err != nil {
return utils.APIErrorHandler(err)
}
loadId := map[string]string{utils.AttributeProfilePrefix: utils.UUIDSha1Prefix()}
//generez un nou id pentru load_ids
//fac update in datadb
args := engine.ArgsGetCacheItem{
CacheID: utils.CacheAttributeProfiles,
ItemID: alsWrp.TenantID(),

View File

@@ -152,7 +152,8 @@ const CGRATES_CFG_JSON = `
"dispatcher_routes": {"limit": -1, "ttl": "", "static_ttl": false}, // control dispatcher routes caching
"diameter_messages": {"limit": -1, "ttl": "3h", "static_ttl": false}, // diameter messages caching
"rpc_responses": {"limit": 0, "ttl": "2s", "static_ttl": false}, // RPC responses caching
"closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs
"closed_sessions": {"limit": -1, "ttl": "10s", "static_ttl": false}, // closed sessions cached for CDRs
"load_ids": {"limit": -1, "ttl": "", "static_ttl": false, "precache": false}, // control the load_ids for items
},

View File

@@ -65,6 +65,7 @@ var precachedPartitions = utils.StringMap{
utils.CacheSupplierFilterIndexes: true,
utils.CacheChargerFilterIndexes: true,
utils.CacheDispatcherFilterIndexes: true,
utils.CacheLoadIDs: true,
}
// InitCache will instantiate the cache with specific or default configuraiton

View File

@@ -128,6 +128,8 @@ type DataDB interface {
GetDispatcherProfileDrv(string, string) (*DispatcherProfile, error)
SetDispatcherProfileDrv(*DispatcherProfile) error
RemoveDispatcherProfileDrv(string, string) error
GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error)
SetLoadIDsDrv(loadIDs map[string]string) error
GetDispatcherHostDrv(string, string) (*DispatcherHost, error)
SetDispatcherHostDrv(*DispatcherHost) error
RemoveDispatcherHostDrv(string, string) error

View File

@@ -1422,3 +1422,32 @@ func (ms *MapStorage) RemoveVersions(vrs Versions) (err error) {
func (ms *MapStorage) GetStorageType() string {
return utils.MAPSTOR
}
func (ms *MapStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
values, ok := ms.dict[utils.LoadIDs]
if !ok {
return nil, utils.ErrNotFound
}
err = ms.ms.Unmarshal(values, &loadIDs)
if err != nil {
return nil, err
}
if itemIDPrefix != "" {
return map[string]string{itemIDPrefix: loadIDs[itemIDPrefix]}, nil
}
return loadIDs, nil
}
func (ms *MapStorage) SetLoadIDsDrv(loadIDs map[string]string) (err error) {
var result []byte
result, err = ms.ms.Marshal(loadIDs)
if err != nil {
return err
}
ms.mu.Lock()
ms.dict[utils.LoadIDs] = result
ms.mu.Unlock()
return
}

View File

@@ -1593,3 +1593,28 @@ func (rs *RedisStorage) RemoveDispatcherHostDrv(tenant, id string) (err error) {
func (rs *RedisStorage) GetStorageType() string {
return utils.REDIS
}
func (rs *RedisStorage) GetItemLoadIDsDrv(itemIDPrefix string) (loadIDs map[string]string, err error) {
if itemIDPrefix != "" {
fldVal, err := rs.Cmd("HGET", utils.LoadIDs, itemIDPrefix).Str()
if err != nil {
if err == redis.ErrRespNil {
err = utils.ErrNotFound
}
return nil, err
}
return map[string]string{itemIDPrefix: fldVal}, nil
}
loadIDs, err = rs.Cmd("HGETALL", utils.LoadIDs).Map()
if err != nil {
return nil, err
}
if len(loadIDs) == 0 {
return nil, utils.ErrNotFound
}
return
}
func (rs *RedisStorage) SetLoadIDsDrv(loadIDs map[string]string) error {
return rs.Cmd("HMSET", utils.LoadIDs, loadIDs).Err
}

View File

@@ -559,6 +559,7 @@ const (
MetaLoad = "*load"
MetaRemove = "*remove"
MetaClear = "*clear"
LoadIDs = "load_ids"
)
// Migrator Action
@@ -979,6 +980,7 @@ const (
CacheClosedSessions = "closed_sessions"
MetaPrecaching = "*precaching"
MetaReady = "*ready"
CacheLoadIDs = "load_ids"
)
// Prefix for indexing