added history configuration options

This commit is contained in:
Radu Ioan Fericean
2013-08-03 20:19:05 +03:00
parent 80e5fa7403
commit 9411759bc9
4 changed files with 44 additions and 17 deletions

View File

@@ -217,10 +217,10 @@ func checkConfigSanity() error {
func startHistoryScribe() (err error) {
var scribe history.Scribe
flag.Parse()
if "*masterAddr" != "" {
scribe, err = history.NewProxyScribe("*masterAddr")
if cfg.HistoryMaster != "" {
scribe, err = history.NewProxyScribe(cfg.HistoryMaster)
} else {
scribe, err = history.NewFileScribe("*dataFile")
scribe, err = history.NewFileScribe(cfg.HistoryRoot)
}
rpc.RegisterName("Scribe", scribe)
rpc.HandleHTTP()
@@ -328,6 +328,10 @@ func main() {
engine.Logger.Info("Starting CGRateS CDR Server.")
go startCDRS(responder, loggerDb)
}
if cfg.HistoryEnabled {
engine.Logger.Info("Starting History Service.")
go startHistoryScribe()
}
<-exitChan
engine.Logger.Info("Stopped all components. CGRateS shutdown!")
}

View File

@@ -26,16 +26,15 @@ import (
)
const (
DISABLED = "disabled"
INTERNAL = "internal"
JSON = "json"
GOB = "gob"
POSTGRES = "postgres"
MONGO = "mongo"
REDIS = "redis"
SAME = "same"
FS = "freeswitch"
DISABLED = "disabled"
INTERNAL = "internal"
JSON = "json"
GOB = "gob"
POSTGRES = "postgres"
MONGO = "mongo"
REDIS = "redis"
SAME = "same"
FS = "freeswitch"
)
// Holds system configuration, defaults are overwritten with values from config file if found
@@ -57,8 +56,8 @@ type CGRConfig struct {
DefaultTOR string // set default type of record
DefaultTenant string // set default tenant
DefaultSubject string // set default rating subject, useful in case of fallback
RoundingMethod string // Rounding method for the end price: <*up|*middle|*down>
RoundingDecimals int // Number of decimals to round end prices at
RoundingMethod string // Rounding method for the end price: <*up|*middle|*down>
RoundingDecimals int // Number of decimals to round end prices at
RaterEnabled bool // start standalone server (no balancer)
RaterBalancer string // balancer address host:port
RaterListen string // listening address host:port
@@ -95,6 +94,9 @@ type CGRConfig struct {
FreeswitchServer string // freeswitch address host:port
FreeswitchPass string // FS socket password
FreeswitchReconnects int // number of times to attempt reconnect after connect fails
HistoryEnabled bool // Starts History service: <true|false>.
HistoryMaster string // Address where to reach the master history server: <internal|x.y.z.y:1234>
HistoryRoot string // Location on disk where to store hostory files.
}
func (self *CGRConfig) setDefaults() error {
@@ -111,7 +113,7 @@ func (self *CGRConfig) setDefaults() error {
self.StorDBUser = "cgrates"
self.StorDBPass = "CGRateS.org"
self.RPCEncoding = JSON
self.DefaultReqType = utils.RATED
self.DefaultReqType = utils.RATED
self.DefaultTOR = "0"
self.DefaultTenant = "0"
self.DefaultSubject = "0"
@@ -153,6 +155,9 @@ func (self *CGRConfig) setDefaults() error {
self.FreeswitchServer = "127.0.0.1:8021"
self.FreeswitchPass = "ClueCon"
self.FreeswitchReconnects = 5
self.HistoryEnabled = false
self.HistoryMaster = "127.0.0.1:2013"
self.HistoryRoot = "/var/log/cgrates/history"
return nil
}
@@ -370,6 +375,14 @@ func loadConfig(c *conf.ConfigFile) (*CGRConfig, error) {
if hasOpt = c.HasOption("freeswitch", "reconnects"); hasOpt {
cfg.FreeswitchReconnects, _ = c.GetInt("freeswitch", "reconnects")
}
if hasOpt = c.HasOption("history", "enabled"); hasOpt {
cfg.HistoryEnabled, _ = c.GetBool("history", "enabled")
}
if hasOpt = c.HasOption("history", "master"); hasOpt {
cfg.HistoryMaster, _ = c.GetString("history", "master")
}
if hasOpt = c.HasOption("history", "root"); hasOpt {
cfg.HistoryRoot, _ = c.GetString("history", "root")
}
return cfg, nil
}

View File

@@ -89,6 +89,9 @@ func TestDefaults(t *testing.T) {
eCfg.FreeswitchServer = "127.0.0.1:8021"
eCfg.FreeswitchPass = "ClueCon"
eCfg.FreeswitchReconnects = 5
eCfg.HistoryEnabled = false
eCfg.HistoryMaster = "127.0.0.1:2013"
eCfg.HistoryRoot = "/var/log/cgrates/history"
if !reflect.DeepEqual(cfg, eCfg) {
t.Log(eCfg)
t.Log(cfg)
@@ -180,6 +183,9 @@ func TestConfigFromFile(t *testing.T) {
eCfg.FreeswitchServer = "test"
eCfg.FreeswitchPass = "test"
eCfg.FreeswitchReconnects = 99
eCfg.HistoryEnabled = true
eCfg.HistoryMaster = "test"
eCfg.HistoryRoot = "test"
if !reflect.DeepEqual(cfg, eCfg) {
t.Log(eCfg)
t.Log(cfg)

View File

@@ -73,3 +73,7 @@ server = test # Adress where to connect to FreeSWITCH socket.
passwd = test # FreeSWITCH socket password.
reconnects = 99 # Number of attempts on connect failure.
[history]
enabled = true # Starts History service: <true|false>.
master = test # Address where to reach the master history server: <internal|x.y.z.y:1234>
root = test # Location on disk where to store hostory files.