added cache config section

This commit is contained in:
Radu Ioan Fericean
2016-08-15 17:53:26 +03:00
parent b89725be46
commit cac660d1ef
6 changed files with 140 additions and 1 deletions

55
config/cacheconfig.go Normal file
View File

@@ -0,0 +1,55 @@
package config
import (
"time"
"github.com/cgrates/cgrates/utils"
)
type CacheParamConfig struct {
Limit int
TTL time.Duration
Precache bool
}
func (self *CacheParamConfig) loadFromJsonCfg(jsnCfg *CacheParamJsonCfg) error {
if jsnCfg == nil {
return nil
}
var err error
if jsnCfg.Limit != nil {
self.Limit = *jsnCfg.Limit
}
if jsnCfg.Ttl != nil {
if self.TTL, err = utils.ParseDurationWithSecs(*jsnCfg.Ttl); err != nil {
return err
}
}
if jsnCfg.Precache != nil {
self.Precache = *jsnCfg.Precache
}
return nil
}
type CacheConfig struct {
Destinations *CacheParamConfig
ReverseDestinations *CacheParamConfig
RatingPlans *CacheParamConfig
RatingProfiles *CacheParamConfig
Lcr *CacheParamConfig
CdrStats *CacheParamConfig
Actions *CacheParamConfig
ActionPlans *CacheParamConfig
ActionTriggers *CacheParamConfig
SharedGroups *CacheParamConfig
Aliases *CacheParamConfig
ReverseAliases *CacheParamConfig
}
func (self *CacheConfig) loadFromJsonCfg(jsnCfg *CacheJsonCfg) error {
if jsnCfg.Destinations != nil {
self.Destinations = &CacheParamConfig{}
self.Destinations.loadFromJsonCfg(jsnCfg.Destinations)
}
return nil
}

View File

@@ -49,6 +49,20 @@ const CGRATES_CFG_JSON = `
},
"cache":{
"destinations": {"limit": 10000, "ttl":"0s", "precache": false},
"reverse_destinations": {"limit": 10000, "ttl":"0s", "precache": false},
"rating_plans": {"limit": 10000, "ttl":"0s","precache": true},
"rating_profiles": {"limit": 10000, "ttl":"0s", "precache": false},
"lcr": {"limit": 10000, "ttl":"0s", "precache": false},
"cdr_stats": {"limit": 10000, "ttl":"0s", "precache": false},
"actions": {"limit": 10000, "ttl":"0s", "precache": false},
"action_plans": {"limit": 10000, "ttl":"0s", "precache": false},
"action_triggers": {"limit": 10000, "ttl":"0s", "precache": false},
"shared_groups": {"limit": 10000, "ttl":"0s", "precache": false},
"aliases": {"limit": 10000, "ttl":"0s", "precache": false},
"reverse_aliases": {"limit": 10000, "ttl":"0s", "precache": false},
},
"listen": {
"rpc_json": "127.0.0.1:2012", // RPC JSON listening address
@@ -386,7 +400,7 @@ const CGRATES_CFG_JSON = `
"rls": {
"enabled": false, // starts ResourceLimiter service: <true|false>.
"cdrstats_conns": [], // address where to reach the cdrstats service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234>
"cdrstats_conns": [], // address where to reach the cdrstats service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234>
"cache_dump_interval": "0s", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|*never|$dur>
"usage_ttl": "3h", // expire usage records if older than this duration <""|*never|$dur>
},

View File

@@ -28,6 +28,7 @@ import (
const (
GENERAL_JSN = "general"
CACHE_JSN = "cache"
LISTEN_JSN = "listen"
TPDB_JSN = "tariffplan_db"
DATADB_JSN = "data_db"
@@ -93,6 +94,18 @@ func (self CgrJsonCfg) GeneralJsonCfg() (*GeneralJsonCfg, error) {
return cfg, nil
}
func (self CgrJsonCfg) CacheJsonCfg() (*CacheJsonCfg, error) {
rawCfg, hasKey := self[CACHE_JSN]
if !hasKey {
return nil, nil
}
cfg := new(CacheJsonCfg)
if err := json.Unmarshal(*rawCfg, cfg); err != nil {
return nil, err
}
return cfg, nil
}
func (self CgrJsonCfg) ListenJsonCfg() (*ListenJsonCfg, error) {
rawCfg, hasKey := self[LISTEN_JSN]
if !hasKey {

View File

@@ -64,6 +64,28 @@ func TestDfGeneralJsonCfg(t *testing.T) {
}
}
func TestCacheJsonCfg(t *testing.T) {
eCfg := &CacheJsonCfg{
Destinations: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Reverse_destinations: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Rating_plans: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(true)},
Rating_profiles: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Lcr: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Cdr_stats: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Actions: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Action_plans: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Action_triggers: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Shared_groups: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Aliases: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
Reverse_aliases: &CacheParamJsonCfg{Limit: utils.IntPointer(10000), Ttl: utils.StringPointer("0s"), Precache: utils.BoolPointer(false)},
}
if gCfg, err := dfCgrJsonCfg.CacheJsonCfg(); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eCfg, gCfg) {
t.Error("Received: ", utils.ToIJSON(gCfg))
}
}
func TestDfListenJsonCfg(t *testing.T) {
eCfg := &ListenJsonCfg{
Rpc_json: utils.StringPointer("127.0.0.1:2012"),

View File

@@ -214,6 +214,27 @@ type HaPoolJsonCfg struct {
Transport *string
}
type CacheParamJsonCfg struct {
Limit *int
Ttl *string
Precache *bool
}
type CacheJsonCfg struct {
Destinations *CacheParamJsonCfg
Reverse_destinations *CacheParamJsonCfg
Rating_plans *CacheParamJsonCfg
Rating_profiles *CacheParamJsonCfg
Lcr *CacheParamJsonCfg
Cdr_stats *CacheParamJsonCfg
Actions *CacheParamJsonCfg
Action_plans *CacheParamJsonCfg
Action_triggers *CacheParamJsonCfg
Shared_groups *CacheParamJsonCfg
Aliases *CacheParamJsonCfg
Reverse_aliases *CacheParamJsonCfg
}
// Represents one connection instance towards FreeSWITCH
type FsConnJsonCfg struct {
Address *string

View File

@@ -27,6 +27,20 @@
// "cache_dump_dir": "/var/lib/cgrates/cache_dump" // cache dump for faster start (leave empty to disable)
// },
"cache":{
"destinations": {"limit": 10000, "ttl":0, "precache": false},
"reverse_destinations": {"limit": 10000, "ttl":0, "precache": false},
"rating_plans": {"limit": 10000, "ttl":0,"precache": true},
"rating_profiles": {"limit": 10000, "ttl":0, "precache": false},
"lcr": {"limit": 10000, "ttl":0, "precache": false},
"cdr_stats": {"limit": 10000, "ttl":0, "precache": false},
"actions": {"limit": 10000, "ttl":0, "precache": false},
"action_plans": {"limit": 10000, "ttl":0, "precache": false},
"action_triggers": {"limit": 10000, "ttl":0, "precache": false},
"shared_groups": {"limit": 10000, "ttl":0, "precache": false},
"aliases": {"limit": 10000, "ttl":0, "precache": false},
"reverse_aliases": {"limit": 10000, "ttl":0, "precache": false},
},
// "listen": {
// "rpc_json": "127.0.0.1:2012", // RPC JSON listening address