From d8eeddd3483a510e4847de00141aee477d718568 Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 27 Oct 2016 19:23:03 +0200 Subject: [PATCH] SMGeneric smg_replication_conns configuration --- config/config_defaults.go | 33 +++++++++++----------- config/config_json_test.go | 11 ++++---- config/libconfig_json.go | 6 ++-- config/smconfig.go | 38 +++++++++++++++++--------- general_tests/tut_smgeneric_it_test.go | 5 +--- 5 files changed, 53 insertions(+), 40 deletions(-) diff --git a/config/config_defaults.go b/config/config_defaults.go index f2868793f..eec70217b 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -273,11 +273,12 @@ const CGRATES_CFG_JSON = ` "enabled": false, // starts SessionManager service: "listen_bijson": "127.0.0.1:2014", // address where to listen for bidirectional JSON-RPC requests "rals_conns": [ - {"address": "*internal"} // address where to reach the Rater <""|*internal|127.0.0.1:2013> + {"address": "*internal"} // address where to reach the Rater <""|*internal|127.0.0.1:2013> ], "cdrs_conns": [ - {"address": "*internal"} // address where to reach CDR Server, empty to disable CDR capturing <*internal|x.y.z.y:1234> + {"address": "*internal"} // address where to reach CDR Server, empty to disable CDR capturing <*internal|x.y.z.y:1234> ], + "smg_replication_conns": [], // replicate sessions towards these SMGs "debit_interval": "0s", // interval to perform debits on. "min_call_duration": "0s", // only authorize calls with allowed duration higher than this "max_call_duration": "3h", // maximum call duration a prepaid call can last @@ -289,9 +290,9 @@ const CGRATES_CFG_JSON = ` "sm_asterisk": { - "enabled": false, // starts Asterisk SessionManager service: - "create_cdr": false, // create CDR out of events and sends it to CDRS component - "asterisk_conns":[ // instantiate connections to multiple Asterisk servers + "enabled": false, // starts Asterisk SessionManager service: + "create_cdr": false, // create CDR out of events and sends it to CDRS component + "asterisk_conns":[ // instantiate connections to multiple Asterisk servers {"address": "127.0.0.1:8088", "user": "cgrates", "password": "CGRateS.org", "connect_attempts": 3,"reconnects": 5} ], }, @@ -343,21 +344,21 @@ const CGRATES_CFG_JSON = ` "sm_opensips": { - "enabled": false, // starts SessionManager service: - "listen_udp": "127.0.0.1:2020", // address where to listen for datagram events coming from OpenSIPS + "enabled": false, // starts SessionManager service: + "listen_udp": "127.0.0.1:2020", // address where to listen for datagram events coming from OpenSIPS "rals_conns": [ - {"address": "*internal"} // address where to reach the Rater <""|*internal|127.0.0.1:2013> + {"address": "*internal"} // address where to reach the Rater <""|*internal|127.0.0.1:2013> ], "cdrs_conns": [ - {"address": "*internal"} // address where to reach CDR Server, empty to disable CDR capturing <*internal|x.y.z.y:1234> + {"address": "*internal"} // address where to reach CDR Server, empty to disable CDR capturing <*internal|x.y.z.y:1234> ], - "reconnects": 5, // number of reconnects if connection is lost - "create_cdr": false, // create CDR out of events and sends it to CDRS component - "debit_interval": "10s", // interval to perform debits on. - "min_call_duration": "0s", // only authorize calls with allowed duration higher than this - "max_call_duration": "3h", // maximum call duration a prepaid call can last - "events_subscribe_interval": "60s", // automatic events subscription to OpenSIPS, 0 to disable it - "mi_addr": "127.0.0.1:8020", // address where to reach OpenSIPS MI to send session disconnects + "reconnects": 5, // number of reconnects if connection is lost + "create_cdr": false, // create CDR out of events and sends it to CDRS component + "debit_interval": "10s", // interval to perform debits on. + "min_call_duration": "0s", // only authorize calls with allowed duration higher than this + "max_call_duration": "3h", // maximum call duration a prepaid call can last + "events_subscribe_interval": "60s", // automatic events subscription to OpenSIPS, 0 to disable it + "mi_addr": "127.0.0.1:8020", // address where to reach OpenSIPS MI to send session disconnects }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 92a351e4f..86ca3f96e 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -409,11 +409,12 @@ func TestSmGenericJsonCfg(t *testing.T) { &HaPoolJsonCfg{ Address: utils.StringPointer(utils.MetaInternal), }}, - Debit_interval: utils.StringPointer("0s"), - Min_call_duration: utils.StringPointer("0s"), - Max_call_duration: utils.StringPointer("3h"), - Session_ttl: utils.StringPointer("0s"), - Session_indexes: utils.StringSlicePointer([]string{}), + Smg_replication_conns: &[]*HaPoolJsonCfg{}, + Debit_interval: utils.StringPointer("0s"), + Min_call_duration: utils.StringPointer("0s"), + Max_call_duration: utils.StringPointer("3h"), + Session_ttl: utils.StringPointer("0s"), + Session_indexes: utils.StringSlicePointer([]string{}), } if cfg, err := dfCgrJsonCfg.SmGenericJsonCfg(); err != nil { t.Error(err) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 5fe70d3af..6cbd8e7fc 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -182,6 +182,7 @@ type SmGenericJsonCfg struct { Listen_bijson *string Rals_conns *[]*HaPoolJsonCfg Cdrs_conns *[]*HaPoolJsonCfg + Smg_replication_conns *[]*HaPoolJsonCfg Debit_interval *string Min_call_duration *string Max_call_duration *string @@ -214,8 +215,9 @@ type SmFsJsonCfg struct { // Represents one connection instance towards a rater/cdrs server type HaPoolJsonCfg struct { - Address *string - Transport *string + Address *string + Transport *string + Synchronous *bool } type AstConnJsonCfg struct { diff --git a/config/smconfig.go b/config/smconfig.go index ff366450f..8f375398e 100644 --- a/config/smconfig.go +++ b/config/smconfig.go @@ -34,8 +34,9 @@ func NewDfltHaPoolConfig() *HaPoolConfig { // One connection to Rater type HaPoolConfig struct { - Address string - Transport string + Address string + Transport string + Synchronous bool } func (self *HaPoolConfig) loadFromJsonCfg(jsnCfg *HaPoolJsonCfg) error { @@ -48,6 +49,9 @@ func (self *HaPoolConfig) loadFromJsonCfg(jsnCfg *HaPoolJsonCfg) error { if jsnCfg.Transport != nil { self.Transport = *jsnCfg.Transport } + if jsnCfg.Synchronous != nil { + self.Synchronous = *jsnCfg.Synchronous + } return nil } @@ -84,17 +88,18 @@ func (self *FsConnConfig) loadFromJsonCfg(jsnCfg *FsConnJsonCfg) error { } type SmGenericConfig struct { - Enabled bool - ListenBijson string - RALsConns []*HaPoolConfig - CDRsConns []*HaPoolConfig - DebitInterval time.Duration - MinCallDuration time.Duration - MaxCallDuration time.Duration - SessionTTL time.Duration - SessionTTLLastUsed *time.Duration - SessionTTLUsage *time.Duration - SessionIndexes []string + Enabled bool + ListenBijson string + RALsConns []*HaPoolConfig + CDRsConns []*HaPoolConfig + SMGReplicationConns []*HaPoolConfig + DebitInterval time.Duration + MinCallDuration time.Duration + MaxCallDuration time.Duration + SessionTTL time.Duration + SessionTTLLastUsed *time.Duration + SessionTTLUsage *time.Duration + SessionIndexes []string } func (self *SmGenericConfig) loadFromJsonCfg(jsnCfg *SmGenericJsonCfg) error { @@ -122,6 +127,13 @@ func (self *SmGenericConfig) loadFromJsonCfg(jsnCfg *SmGenericJsonCfg) error { self.CDRsConns[idx].loadFromJsonCfg(jsnHaCfg) } } + if jsnCfg.Smg_replication_conns != nil { + self.SMGReplicationConns = make([]*HaPoolConfig, len(*jsnCfg.Smg_replication_conns)) + for idx, jsnHaCfg := range *jsnCfg.Smg_replication_conns { + self.CDRsConns[idx] = NewDfltHaPoolConfig() + self.SMGReplicationConns[idx].loadFromJsonCfg(jsnHaCfg) + } + } if jsnCfg.Debit_interval != nil { if self.DebitInterval, err = utils.ParseDurationWithSecs(*jsnCfg.Debit_interval); err != nil { return err diff --git a/general_tests/tut_smgeneric_it_test.go b/general_tests/tut_smgeneric_it_test.go index e533c6ef7..99e0e1d60 100644 --- a/general_tests/tut_smgeneric_it_test.go +++ b/general_tests/tut_smgeneric_it_test.go @@ -100,8 +100,6 @@ func TestTutSMGLoadTariffPlanFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} if err := tutSMGRpc.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &smgLoadInst); err != nil { t.Error(err) - } else if smgLoadInst.RatingLoadID == "" || smgLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", smgLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -113,8 +111,7 @@ func TestTutSMGCacheStats(t *testing.T) { } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, ResourceLimits: 0, - DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3} + expectedStats := &utils.CacheStats{RatingPlans: 4, Actions: 7, ActionPlans: 4, CdrStats: 6, Users: 3} var args utils.AttrCacheStats if err := tutSMGRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error())