mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Add sessions_conns to rals section
Update ActionConnCfg constructor to take into account this new field.
This commit is contained in:
committed by
Dan Christian Bogos
parent
98265a122a
commit
eaeb04404e
@@ -328,6 +328,7 @@ const CGRATES_CFG_JSON = `
|
||||
"enabled": false, // enable Rating/Accounting service: <true|false>
|
||||
"thresholds_conns": [], // connections to ThresholdS for account/balance updates, empty to disable thresholds functionality: <""|*internal|$rpc_conns_id>
|
||||
"stats_conns": [], // connections to StatS for account/balance updates, empty to disable stats functionality: <""|*internal|$rpc_conns_id>
|
||||
"sessions_conns": [], // connections to SessionS for actions requiring them: <""|*internal|$rpc_conns_id>
|
||||
"rp_subject_prefix_matching": false, // enables prefix matching for the rating profile subject
|
||||
"remove_expired":true, // enables automatic removal of expired balances
|
||||
"max_computed_usage": { // do not compute usage higher than this, prevents memory overload
|
||||
|
||||
@@ -488,6 +488,7 @@ func testCGRConfigReloadRALs(t *testing.T) {
|
||||
BalanceRatingSubject: blMap,
|
||||
ThresholdSConns: []string{utils.MetaLocalHost},
|
||||
StatSConns: []string{utils.MetaLocalHost},
|
||||
SessionSConns: []string{},
|
||||
MaxIncrements: 1000000,
|
||||
FallbackDepth: 3,
|
||||
}
|
||||
|
||||
@@ -744,6 +744,7 @@ func TestDfRalsJsonCfg(t *testing.T) {
|
||||
eCfg := &RalsJsonCfg{
|
||||
Enabled: utils.BoolPointer(false),
|
||||
Thresholds_conns: &[]string{},
|
||||
Sessions_conns: &[]string{},
|
||||
Stats_conns: &[]string{},
|
||||
Rp_subject_prefix_matching: utils.BoolPointer(false),
|
||||
Remove_expired: utils.BoolPointer(true),
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -166,6 +166,7 @@ type RalsJsonCfg struct {
|
||||
Enabled *bool
|
||||
Thresholds_conns *[]string
|
||||
Stats_conns *[]string
|
||||
Sessions_conns *[]string
|
||||
Rp_subject_prefix_matching *bool
|
||||
Remove_expired *bool
|
||||
Max_computed_usage *map[string]string
|
||||
|
||||
@@ -30,6 +30,7 @@ type RalsCfg struct {
|
||||
Enabled bool // start standalone server (no balancer)
|
||||
ThresholdSConns []string // address where to reach ThresholdS config
|
||||
StatSConns []string
|
||||
SessionSConns []string
|
||||
RpSubjectPrefixMatching bool // enables prefix matching for the rating profile subject
|
||||
RemoveExpired bool
|
||||
MaxComputedUsage map[string]time.Duration
|
||||
@@ -66,6 +67,16 @@ func (ralsCfg *RalsCfg) loadFromJSONCfg(jsnRALsCfg *RalsJsonCfg) (err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnRALsCfg.Sessions_conns != nil {
|
||||
ralsCfg.SessionSConns = make([]string, len(*jsnRALsCfg.Sessions_conns))
|
||||
for idx, conn := range *jsnRALsCfg.Sessions_conns {
|
||||
// if we have the connection internal we change the name so we can have internal rpc for each subsystem
|
||||
ralsCfg.SessionSConns[idx] = conn
|
||||
if conn == utils.MetaInternal {
|
||||
ralsCfg.SessionSConns[idx] = utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS)
|
||||
}
|
||||
}
|
||||
}
|
||||
if jsnRALsCfg.Rp_subject_prefix_matching != nil {
|
||||
ralsCfg.RpSubjectPrefixMatching = *jsnRALsCfg.Rp_subject_prefix_matching
|
||||
}
|
||||
@@ -123,6 +134,16 @@ func (ralsCfg *RalsCfg) AsMapInterface() (initialMP map[string]any) {
|
||||
}
|
||||
initialMP[utils.StatSConnsCfg] = statS
|
||||
}
|
||||
if ralsCfg.SessionSConns != nil {
|
||||
sessionsConns := make([]string, len(ralsCfg.SessionSConns))
|
||||
for i, item := range ralsCfg.SessionSConns {
|
||||
sessionsConns[i] = item
|
||||
if item == utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS) {
|
||||
sessionsConns[i] = utils.MetaInternal
|
||||
}
|
||||
}
|
||||
initialMP[utils.SessionSConnsCfg] = sessionsConns
|
||||
}
|
||||
maxComputed := make(map[string]any)
|
||||
for key, item := range ralsCfg.MaxComputedUsage {
|
||||
if key == utils.MetaAny || key == utils.MetaVoice {
|
||||
@@ -160,6 +181,10 @@ func (ralsCfg RalsCfg) Clone() (cln *RalsCfg) {
|
||||
cln.StatSConns = make([]string, len(ralsCfg.StatSConns))
|
||||
copy(cln.StatSConns, ralsCfg.StatSConns)
|
||||
}
|
||||
if ralsCfg.SessionSConns != nil {
|
||||
cln.SessionSConns = make([]string, len(ralsCfg.SessionSConns))
|
||||
copy(cln.SessionSConns, ralsCfg.SessionSConns)
|
||||
}
|
||||
|
||||
for k, u := range ralsCfg.MaxComputedUsage {
|
||||
cln.MaxComputedUsage[k] = u
|
||||
|
||||
@@ -30,6 +30,7 @@ func TestRalsCfgFromJsonCfgCase1(t *testing.T) {
|
||||
Enabled: utils.BoolPointer(true),
|
||||
Thresholds_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Stats_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Sessions_conns: &[]string{utils.MetaInternal, "*conn1"},
|
||||
Rp_subject_prefix_matching: utils.BoolPointer(true),
|
||||
Remove_expired: utils.BoolPointer(true),
|
||||
Max_computed_usage: &map[string]string{
|
||||
@@ -49,6 +50,7 @@ func TestRalsCfgFromJsonCfgCase1(t *testing.T) {
|
||||
Enabled: true,
|
||||
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds), "*conn1"},
|
||||
StatSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats), "*conn1"},
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
RpSubjectPrefixMatching: true,
|
||||
RemoveExpired: true,
|
||||
MaxComputedUsage: map[string]time.Duration{
|
||||
@@ -93,6 +95,7 @@ func TestRalsCfgAsMapInterfaceCase1(t *testing.T) {
|
||||
"thresholds_conns": ["*internal:*thresholds", "*conn1"],
|
||||
"caches_conns": ["*internal:*caches", "*conn1"],
|
||||
"stats_conns": ["*internal:*stats", "*conn1"],
|
||||
"sessions_conns": ["*internal:*sessions", "*conn1"],
|
||||
"rp_subject_prefix_matching": true,
|
||||
"max_computed_usage": { // do not compute usage higher than this, prevents memory overload
|
||||
"*voice": "48h",
|
||||
@@ -104,6 +107,7 @@ func TestRalsCfgAsMapInterfaceCase1(t *testing.T) {
|
||||
utils.EnabledCfg: true,
|
||||
utils.ThresholdSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.StatSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.SessionSConnsCfg: []string{utils.MetaInternal, "*conn1"},
|
||||
utils.RpSubjectPrefixMatchingCfg: true,
|
||||
utils.RemoveExpiredCfg: true,
|
||||
utils.MaxComputedUsageCfg: map[string]any{
|
||||
@@ -138,6 +142,7 @@ func TestRalsCfgAsMapInterfaceCase2(t *testing.T) {
|
||||
utils.EnabledCfg: false,
|
||||
utils.ThresholdSConnsCfg: []string{},
|
||||
utils.StatSConnsCfg: []string{utils.MetaInternal},
|
||||
utils.SessionSConnsCfg: []string{},
|
||||
utils.RpSubjectPrefixMatchingCfg: false,
|
||||
utils.RemoveExpiredCfg: true,
|
||||
utils.MaxComputedUsageCfg: map[string]any{
|
||||
@@ -166,6 +171,7 @@ func TestRalsCfgClone(t *testing.T) {
|
||||
Enabled: true,
|
||||
ThresholdSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds), "*conn1"},
|
||||
StatSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats), "*conn1"},
|
||||
SessionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS), "*conn1"},
|
||||
RpSubjectPrefixMatching: true,
|
||||
RemoveExpired: true,
|
||||
MaxComputedUsage: map[string]time.Duration{
|
||||
@@ -192,6 +198,9 @@ func TestRalsCfgClone(t *testing.T) {
|
||||
if rcv.StatSConns[1] = ""; ban.StatSConns[1] != "*conn1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.SessionSConns[1] = ""; ban.SessionSConns[1] != "*conn1" {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
if rcv.MaxComputedUsage[utils.MetaAny] = 0; ban.MaxComputedUsage[utils.MetaAny] != 189*time.Hour {
|
||||
t.Errorf("Expected clone to not modify the cloned")
|
||||
}
|
||||
|
||||
@@ -86,6 +86,11 @@ func newActionConnCfg(source, action string, cfg *config.CGRConfig) ActionConnCf
|
||||
case utils.MetaAlterSessions:
|
||||
act.ConnIDs = cfg.ThresholdSCfg().SessionSConns
|
||||
}
|
||||
case utils.RALs:
|
||||
switch action {
|
||||
case utils.MetaAlterSessions:
|
||||
act.ConnIDs = cfg.RalsCfg().SessionSConns
|
||||
}
|
||||
}
|
||||
return act
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user