mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Process "replications_conns" after "partitions" for cache config
This commit is contained in:
committed by
Dan Christian Bogos
parent
984fbfb88a
commit
7d2f784a95
@@ -58,23 +58,14 @@ func (cParam *CacheParamCfg) loadFromJsonCfg(jsnCfg *CacheParamJsonCfg) error {
|
||||
|
||||
// CacheCfg used to store the cache config
|
||||
type CacheCfg struct {
|
||||
ReplicationConns []string
|
||||
Partitions map[string]*CacheParamCfg
|
||||
ReplicationConns []string
|
||||
}
|
||||
|
||||
func (cCfg *CacheCfg) loadFromJsonCfg(jsnCfg *CacheJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
if jsnCfg.Replication_conns != nil {
|
||||
cCfg.ReplicationConns = make([]string, len(*jsnCfg.Replication_conns))
|
||||
for idx, connID := range *jsnCfg.Replication_conns {
|
||||
if connID == utils.MetaInternal {
|
||||
return fmt.Errorf("replication connection ID needs to be different than *internal")
|
||||
}
|
||||
cCfg.ReplicationConns[idx] = connID
|
||||
}
|
||||
}
|
||||
if jsnCfg.Partitions != nil {
|
||||
for kJsn, vJsn := range *jsnCfg.Partitions {
|
||||
val := new(CacheParamCfg)
|
||||
@@ -84,6 +75,15 @@ func (cCfg *CacheCfg) loadFromJsonCfg(jsnCfg *CacheJsonCfg) (err error) {
|
||||
cCfg.Partitions[kJsn] = val
|
||||
}
|
||||
}
|
||||
if jsnCfg.Replication_conns != nil {
|
||||
cCfg.ReplicationConns = make([]string, len(*jsnCfg.Replication_conns))
|
||||
for idx, connID := range *jsnCfg.Replication_conns {
|
||||
if connID == utils.MetaInternal {
|
||||
return fmt.Errorf("replication connection ID needs to be different than *internal")
|
||||
}
|
||||
cCfg.ReplicationConns[idx] = connID
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ func TestDfGeneralJsonCfg(t *testing.T) {
|
||||
|
||||
func TestCacheJsonCfg(t *testing.T) {
|
||||
eCfg := &CacheJsonCfg{
|
||||
Replication_conns: &[]string{},
|
||||
Partitions: &map[string]*CacheParamJsonCfg{
|
||||
utils.CacheDestinations: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer(""), Static_ttl: utils.BoolPointer(false),
|
||||
@@ -174,6 +173,7 @@ func TestCacheJsonCfg(t *testing.T) {
|
||||
utils.CacheUCH: &CacheParamJsonCfg{Limit: utils.IntPointer(-1),
|
||||
Ttl: utils.StringPointer("3h"), Static_ttl: utils.BoolPointer(false)},
|
||||
},
|
||||
Replication_conns: &[]string{},
|
||||
}
|
||||
|
||||
if gCfg, err := dfCgrJsonCfg.CacheJsonCfg(); err != nil {
|
||||
|
||||
@@ -630,7 +630,6 @@ func TestCgrCfgJSONDefaultsSMGenericCfg(t *testing.T) {
|
||||
|
||||
func TestCgrCfgJSONDefaultsCacheCFG(t *testing.T) {
|
||||
eCacheCfg := &CacheCfg{
|
||||
ReplicationConns: []string{},
|
||||
Partitions: map[string]*CacheParamCfg{
|
||||
utils.CacheDestinations: &CacheParamCfg{Limit: -1,
|
||||
TTL: time.Duration(0), StaticTTL: false, Precache: false},
|
||||
@@ -709,6 +708,7 @@ func TestCgrCfgJSONDefaultsCacheCFG(t *testing.T) {
|
||||
utils.CacheUCH: &CacheParamCfg{Limit: -1,
|
||||
TTL: time.Duration(3 * time.Hour), StaticTTL: false},
|
||||
},
|
||||
ReplicationConns: []string{},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(eCacheCfg, cgrCfg.CacheCfg()) {
|
||||
|
||||
@@ -282,8 +282,8 @@ type CacheParamJsonCfg struct {
|
||||
}
|
||||
|
||||
type CacheJsonCfg struct {
|
||||
Replication_conns *[]string
|
||||
Partitions *map[string]*CacheParamJsonCfg
|
||||
Replication_conns *[]string
|
||||
}
|
||||
|
||||
// SM-Kamailio config section
|
||||
|
||||
Reference in New Issue
Block a user