SMGeneric smg_replication_conns configuration

This commit is contained in:
DanB
2016-10-27 19:23:03 +02:00
parent 1f6ab1ba2f
commit d8eeddd348
5 changed files with 53 additions and 40 deletions

View File

@@ -273,11 +273,12 @@ const CGRATES_CFG_JSON = `
"enabled": false, // starts SessionManager service: <true|false>
"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: <true|false>
"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: <true|false>
"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: <true|false>
"listen_udp": "127.0.0.1:2020", // address where to listen for datagram events coming from OpenSIPS
"enabled": false, // starts SessionManager service: <true|false>
"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
},

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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

View File

@@ -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())