From c26bfcdb1f2b575738a8949ce279d581ba87d730 Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 19 Mar 2015 10:51:42 +0100 Subject: [PATCH] Adding CdrReplication config for raw CDRS --- config/config.go | 44 ++++++++++++++++++++++++++++++++------ config/config_defaults.go | 1 + config/config_json_test.go | 11 +++++----- config/libconfig_json.go | 11 +++++----- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index 5ae21a113..5cd11d905 100644 --- a/config/config.go +++ b/config/config.go @@ -183,13 +183,14 @@ type CGRConfig struct { RaterBalancer string // balancer address host:port BalancerEnabled bool SchedulerEnabled bool - CDRSEnabled bool // Enable CDR Server service - CDRSExtraFields []*utils.RSRField // Extra fields to store in CDRs - CDRSMediator string // Address where to reach the Mediator. Empty for disabling mediation. <""|internal> - CDRSStats string // Address where to reach the Mediator. <""|intenal> - CDRSStoreDisable bool // When true, CDRs will not longer be saved in stordb, useful for cdrstats only scenario - CDRStatsEnabled bool // Enable CDR Stats service - CDRStatConfig *CdrStatsConfig // Active cdr stats configuration instances, platform level + CDRSEnabled bool // Enable CDR Server service + CDRSExtraFields []*utils.RSRField // Extra fields to store in CDRs + CDRSMediator string // Address where to reach the Mediator. Empty for disabling mediation. <""|internal> + CDRSStats string // Address where to reach the Mediator. <""|intenal> + CDRSStoreDisable bool // When true, CDRs will not longer be saved in stordb, useful for cdrstats only scenario + CDRSCdrReplication []*CdrReplicationCfg // Replicate raw CDRs to a number of servers + CDRStatsEnabled bool // Enable CDR Stats service + CDRStatConfig *CdrStatsConfig // Active cdr stats configuration instances, platform level CdreProfiles map[string]*CdreConfig CdrcProfiles map[string]map[string]*CdrcConfig // Number of CDRC instances running imports, format map[dirPath]map[instanceName]{Configs} SmFsConfig *SmFsConfig // SM-FreeSWITCH configuration @@ -200,6 +201,7 @@ type CGRConfig struct { MediatorRater string MediatorStats string // Address where to reach the Rater: MediatorStoreDisable bool // When true, CDRs will not longer be saved in stordb, useful for cdrstats only scenario + MediCdrReplication []*CdrReplicationCfg // Replicate CDRs to a number of servers HistoryAgentEnabled bool // Starts History as an agent: . HistoryServer string // Address where to reach the master history server: HistoryServerEnabled bool // Starts History as server: . @@ -464,6 +466,20 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { if jsnCdrsCfg.Store_disable != nil { self.CDRSStoreDisable = *jsnCdrsCfg.Store_disable } + if jsnCdrsCfg.Cdr_replication != nil { + for idx, rplJsonCfg := range *jsnCdrsCfg.Cdr_replication { + self.MediCdrReplication[idx] = new(CdrReplicationCfg) + if rplJsonCfg.Transport != nil { + self.MediCdrReplication[idx].Transport = *rplJsonCfg.Transport + } + if rplJsonCfg.Server != nil { + self.MediCdrReplication[idx].Server = *rplJsonCfg.Server + } + if rplJsonCfg.Synchronous != nil { + self.MediCdrReplication[idx].Synchronous = *rplJsonCfg.Synchronous + } + } + } } if jsnCdrstatsCfg != nil { if jsnCdrstatsCfg.Enabled != nil { @@ -545,6 +561,20 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) error { if jsnMediatorCfg.Store_disable != nil { self.MediatorStoreDisable = *jsnMediatorCfg.Store_disable } + if jsnMediatorCfg.Cdr_replication != nil { + for idx, rplJsonCfg := range *jsnMediatorCfg.Cdr_replication { + self.MediCdrReplication[idx] = new(CdrReplicationCfg) + if rplJsonCfg.Transport != nil { + self.MediCdrReplication[idx].Transport = *rplJsonCfg.Transport + } + if rplJsonCfg.Server != nil { + self.MediCdrReplication[idx].Server = *rplJsonCfg.Server + } + if rplJsonCfg.Synchronous != nil { + self.MediCdrReplication[idx].Synchronous = *rplJsonCfg.Synchronous + } + } + } } if jsnHistAgentCfg != nil { diff --git a/config/config_defaults.go b/config/config_defaults.go index 4042f41bf..0e7a5a6ae 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -100,6 +100,7 @@ const CGRATES_CFG_JSON = ` "mediator": "", // address where to reach the Mediator. Empty for disabling mediation. <""|internal> "cdrstats": "", // address where to reach the cdrstats service. Empty to disable stats gathering from raw CDRs <""|internal|x.y.z.y:1234> "store_disable": false, // when true, CDRs will not longer be saved in stordb, useful for cdrstats only scenario + "cdr_replication":[], // replicate the raw CDR to a number of servers }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 23f0d253b..a4c6e65e7 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -137,11 +137,12 @@ func TestDfSchedulerJsonCfg(t *testing.T) { func TestDfCdrsJsonCfg(t *testing.T) { eCfg := &CdrsJsonCfg{ - Enabled: utils.BoolPointer(false), - Extra_fields: utils.StringSlicePointer([]string{}), - Mediator: utils.StringPointer(""), - Cdrstats: utils.StringPointer(""), - Store_disable: utils.BoolPointer(false), + Enabled: utils.BoolPointer(false), + Extra_fields: utils.StringSlicePointer([]string{}), + Mediator: utils.StringPointer(""), + Cdrstats: utils.StringPointer(""), + Store_disable: utils.BoolPointer(false), + Cdr_replication: &[]*CdrReplicationJsonCfg{}, } if cfg, err := dfCgrJsonCfg.CdrsJsonCfg(); err != nil { t.Error(err) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index c8a188969..ac7022b77 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -67,11 +67,12 @@ type SchedulerJsonCfg struct { // Cdrs config section type CdrsJsonCfg struct { - Enabled *bool - Extra_fields *[]string - Mediator *string - Cdrstats *string - Store_disable *bool + Enabled *bool + Extra_fields *[]string + Mediator *string + Cdrstats *string + Store_disable *bool + Cdr_replication *[]*CdrReplicationJsonCfg } type CdrReplicationJsonCfg struct {