mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Refactoring the configuration into it's own struct
This commit is contained in:
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/goconf/conf"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
@@ -52,68 +51,15 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
config = flag.String("config", "/etc/cgrates/cgrates.cfg", "Configuration file location.")
|
||||
version = flag.Bool("version", false, "Prints the application version.")
|
||||
data_db_type = REDIS
|
||||
data_db_host = "localhost" // The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
data_db_port = "" // The port to bind to.
|
||||
data_db_name = "10" // The name of the database to connect to.
|
||||
data_db_user = "" // The user to sign in as.
|
||||
data_db_pass = "" // The user's password.
|
||||
log_db_type = MONGO
|
||||
log_db_host = "localhost" // The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
log_db_port = "" // The port to bind to.
|
||||
log_db_name = "cgrates" // The name of the database to connect to.
|
||||
log_db_user = "" // The user to sign in as.
|
||||
log_db_pass = "" // The user's password.
|
||||
|
||||
rater_enabled = false // start standalone server (no balancer)
|
||||
rater_balancer = DISABLED // balancer address host:port
|
||||
rater_listen = "127.0.0.1:1234" // listening address host:port
|
||||
rater_rpc_encoding = GOB // use JSON for RPC encoding
|
||||
|
||||
balancer_enabled = false
|
||||
balancer_listen = "127.0.0.1:2001" // Json RPC server address
|
||||
balancer_rpc_encoding = GOB // use JSON for RPC encoding
|
||||
|
||||
scheduler_enabled = false
|
||||
|
||||
sm_enabled = false
|
||||
sm_switch_type = FS
|
||||
sm_rater = INTERNAL // address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
sm_debit_period = 10 // the period to be debited in advanced during a call (in seconds)
|
||||
sm_rpc_encoding = GOB // use JSON for RPC encoding
|
||||
|
||||
mediator_enabled = false
|
||||
mediator_cdr_path = "" // Freeswitch Master CSV CDR path.
|
||||
mediator_cdr_out_path = "" // Freeswitch Master CSV CDR output path.
|
||||
mediator_rater = INTERNAL // address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
mediator_rpc_encoding = GOB // use JSON for RPC encoding
|
||||
mediator_skipdb = false
|
||||
mediator_pseudo_prepaid = false
|
||||
|
||||
freeswitch_server = "localhost:8021" // freeswitch address host:port
|
||||
freeswitch_pass = "ClueCon" // reeswitch address host:port
|
||||
freeswitch_direction = ""
|
||||
freeswitch_tor = ""
|
||||
freeswitch_tenant = ""
|
||||
freeswitch_subject = ""
|
||||
freeswitch_account = ""
|
||||
freeswitch_destination = ""
|
||||
freeswitch_time_start = ""
|
||||
freeswitch_duration = ""
|
||||
freeswitch_uuid = ""
|
||||
freeswitch_reconnects = 5
|
||||
|
||||
cfgParseErr error
|
||||
|
||||
cfgPath = flag.String("config", "/etc/cgrates/cgrates.cfg", "Configuration file location.")
|
||||
version = flag.Bool("version", false, "Prints the application version.")
|
||||
bal = balancer2go.NewBalancer()
|
||||
exitChan = make(chan bool)
|
||||
sm sessionmanager.SessionManager
|
||||
cfg *CGRConfig
|
||||
err error
|
||||
)
|
||||
|
||||
|
||||
|
||||
func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encoding string) {
|
||||
l, err := net.Listen("tcp", rpcAddress)
|
||||
if err != nil {
|
||||
@@ -145,15 +91,15 @@ func listenToRPCRequests(rpcResponder interface{}, rpcAddress string, rpc_encodi
|
||||
|
||||
func startMediator(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
var connector rater.Connector
|
||||
if mediator_rater == INTERNAL {
|
||||
if cfg.mediator_rater == INTERNAL {
|
||||
connector = responder
|
||||
} else {
|
||||
var client *rpc.Client
|
||||
var err error
|
||||
if mediator_rpc_encoding == JSON {
|
||||
client, err = jsonrpc.Dial("tcp", mediator_rater)
|
||||
if cfg.mediator_rpc_encoding == JSON {
|
||||
client, err = jsonrpc.Dial("tcp", cfg.mediator_rater)
|
||||
} else {
|
||||
client, err = rpc.Dial("tcp", mediator_rater)
|
||||
client, err = rpc.Dial("tcp", cfg.mediator_rater)
|
||||
}
|
||||
if err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not connect to rater: %v", err))
|
||||
@@ -161,42 +107,43 @@ func startMediator(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
}
|
||||
connector = &rater.RPCClientConnector{Client: client}
|
||||
}
|
||||
if _, err := os.Stat(mediator_cdr_path); err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("The input path for mediator does not exist: %v", mediator_cdr_path))
|
||||
if _, err := os.Stat(cfg.mediator_cdr_path); err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("The input path for mediator does not exist: %v", cfg.mediator_cdr_path))
|
||||
exitChan <- true
|
||||
}
|
||||
if _, err := os.Stat(mediator_cdr_out_path); err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("The output path for mediator does not exist: %v", mediator_cdr_out_path))
|
||||
if _, err := os.Stat(cfg.mediator_cdr_out_path); err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("The output path for mediator does not exist: %v", cfg.mediator_cdr_out_path))
|
||||
exitChan <- true
|
||||
}
|
||||
// ToDo: Why is here
|
||||
// Check parsing errors
|
||||
if cfgParseErr != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("Errors on config parsing: <%v>", cfgParseErr))
|
||||
exitChan <- true
|
||||
}
|
||||
//if cfgParseErr != nil {
|
||||
// rater.Logger.Crit(fmt.Sprintf("Errors on config parsing: <%v>", cfgParseErr))
|
||||
// exitChan <- true
|
||||
//}
|
||||
|
||||
m, err := mediator.NewMediator(connector, loggerDb, mediator_skipdb, mediator_cdr_out_path, mediator_pseudo_prepaid, freeswitch_direction,
|
||||
freeswitch_tor, freeswitch_tenant, freeswitch_subject, freeswitch_account, freeswitch_destination,
|
||||
freeswitch_time_start, freeswitch_duration, freeswitch_uuid)
|
||||
m, err := mediator.NewMediator(connector, loggerDb, cfg.mediator_skipdb, cfg.mediator_cdr_out_path, cfg.mediator_pseudo_prepaid,
|
||||
cfg.freeswitch_direction, cfg.freeswitch_tor, cfg.freeswitch_tenant, cfg.freeswitch_subject, cfg.freeswitch_account,
|
||||
cfg.freeswitch_destination, cfg.freeswitch_time_start, cfg.freeswitch_duration, cfg.freeswitch_uuid)
|
||||
if err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("Mediator config parsing error: %v", err))
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
m.TrackCDRFiles(mediator_cdr_path)
|
||||
m.TrackCDRFiles(cfg.mediator_cdr_path)
|
||||
}
|
||||
|
||||
func startSessionManager(responder *rater.Responder, loggerDb rater.DataStorage) {
|
||||
var connector rater.Connector
|
||||
if sm_rater == INTERNAL {
|
||||
if cfg.sm_rater == INTERNAL {
|
||||
connector = responder
|
||||
} else {
|
||||
var client *rpc.Client
|
||||
var err error
|
||||
if sm_rpc_encoding == JSON {
|
||||
client, err = jsonrpc.Dial("tcp", sm_rater)
|
||||
if cfg.sm_rpc_encoding == JSON {
|
||||
client, err = jsonrpc.Dial("tcp", cfg.sm_rater)
|
||||
} else {
|
||||
client, err = rpc.Dial("tcp", sm_rater)
|
||||
client, err = rpc.Dial("tcp", cfg.sm_rater)
|
||||
}
|
||||
if err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not connect to rater: %v", err))
|
||||
@@ -204,27 +151,27 @@ func startSessionManager(responder *rater.Responder, loggerDb rater.DataStorage)
|
||||
}
|
||||
connector = &rater.RPCClientConnector{Client: client}
|
||||
}
|
||||
switch sm_switch_type {
|
||||
switch cfg.sm_switch_type {
|
||||
case FS:
|
||||
dp, _ := time.ParseDuration(fmt.Sprintf("%vs", sm_debit_period))
|
||||
dp, _ := time.ParseDuration(fmt.Sprintf("%vs", cfg.sm_debit_period))
|
||||
sm = sessionmanager.NewFSSessionManager(loggerDb, connector, dp)
|
||||
errConn := sm.Connect(freeswitch_server, freeswitch_pass, freeswitch_reconnects)
|
||||
errConn := sm.Connect(cfg.freeswitch_server, cfg.freeswitch_pass, cfg.freeswitch_reconnects)
|
||||
if errConn != nil {
|
||||
rater.Logger.Err(fmt.Sprintf("<SessionManager> error: %s!", errConn))
|
||||
}
|
||||
default:
|
||||
rater.Logger.Err(fmt.Sprintf("<SessionManager> Unsupported session manger type: %s!", sm_switch_type))
|
||||
rater.Logger.Err(fmt.Sprintf("<SessionManager> Unsupported session manger type: %s!", cfg.sm_switch_type))
|
||||
exitChan <- true
|
||||
}
|
||||
exitChan <-true
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
func checkConfigSanity() {
|
||||
if sm_enabled && rater_enabled && rater_balancer != DISABLED {
|
||||
if cfg.sm_enabled && cfg.rater_enabled && cfg.rater_balancer != DISABLED {
|
||||
rater.Logger.Crit("The session manager must not be enabled on a worker rater (change [rater]/balancer to disabled)!")
|
||||
exitChan <- true
|
||||
}
|
||||
if balancer_enabled && rater_enabled && rater_balancer != DISABLED {
|
||||
if cfg.balancer_enabled && cfg.rater_enabled && cfg.rater_balancer != DISABLED {
|
||||
rater.Logger.Crit("The balancer is enabled so it cannot connect to anatoher balancer (change [rater]/balancer to disabled)!")
|
||||
exitChan <- true
|
||||
}
|
||||
@@ -233,29 +180,29 @@ func checkConfigSanity() {
|
||||
// if they are using the same encoding as the rater/balancer
|
||||
// this scenariou should be used for debug puropses only (it is racy anyway)
|
||||
// and it might be forbidden in the future
|
||||
if strings.Contains(sm_rater, "localhost") || strings.Contains(sm_rater, "127.0.0.1") {
|
||||
if balancer_enabled {
|
||||
if balancer_rpc_encoding != sm_rpc_encoding {
|
||||
if strings.Contains(cfg.sm_rater, "localhost") || strings.Contains(cfg.sm_rater, "127.0.0.1") {
|
||||
if cfg.balancer_enabled {
|
||||
if cfg.balancer_rpc_encoding != cfg.sm_rpc_encoding {
|
||||
rater.Logger.Crit("If you are connecting the session manager via the loopback to the balancer use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
if rater_enabled {
|
||||
if rater_rpc_encoding != sm_rpc_encoding {
|
||||
if cfg.rater_enabled {
|
||||
if cfg.rater_rpc_encoding != cfg.sm_rpc_encoding {
|
||||
rater.Logger.Crit("If you are connecting the session manager via the loopback to the arter use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
}
|
||||
if strings.Contains(mediator_rater, "localhost") || strings.Contains(mediator_rater, "127.0.0.1") {
|
||||
if balancer_enabled {
|
||||
if balancer_rpc_encoding != mediator_rpc_encoding {
|
||||
if strings.Contains(cfg.mediator_rater, "localhost") || strings.Contains(cfg.mediator_rater, "127.0.0.1") {
|
||||
if cfg.balancer_enabled {
|
||||
if cfg.balancer_rpc_encoding != cfg.mediator_rpc_encoding {
|
||||
rater.Logger.Crit("If you are connecting the mediator via the loopback to the balancer use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
}
|
||||
if rater_enabled {
|
||||
if rater_rpc_encoding != mediator_rpc_encoding {
|
||||
if cfg.rater_enabled {
|
||||
if cfg.rater_rpc_encoding != cfg.mediator_rpc_encoding {
|
||||
rater.Logger.Crit("If you are connecting the mediator via the loopback to the arter use the same type of rpc encoding!")
|
||||
exitChan <- true
|
||||
}
|
||||
@@ -299,60 +246,60 @@ func main() {
|
||||
return
|
||||
}
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
c, err := conf.ReadConfigFile(*config)
|
||||
|
||||
cfg, err = NewCGRConfig( cfgPath )
|
||||
if err != nil {
|
||||
rater.Logger.Err(fmt.Sprintf("Could not open the configuration file: %v", err))
|
||||
rater.Logger.Crit(fmt.Sprintf("Could not parse config: %s exiting!", err))
|
||||
return
|
||||
}
|
||||
readConfig(c)
|
||||
// some consitency checks
|
||||
go checkConfigSanity()
|
||||
|
||||
var getter, loggerDb rater.DataStorage
|
||||
getter, err = configureDatabase(data_db_type, data_db_host, data_db_port, data_db_name, data_db_user, data_db_pass)
|
||||
getter, err = configureDatabase(cfg.data_db_type, cfg.data_db_host, cfg.data_db_port, cfg.data_db_name, cfg.data_db_user, cfg.data_db_pass)
|
||||
|
||||
if err == nil {
|
||||
defer getter.Close()
|
||||
rater.SetDataStorage(getter)
|
||||
}
|
||||
|
||||
if log_db_type == SAME {
|
||||
if cfg.log_db_type == SAME {
|
||||
loggerDb = getter
|
||||
} else {
|
||||
loggerDb, err = configureDatabase(log_db_type, log_db_host, log_db_port, log_db_name, log_db_user, log_db_pass)
|
||||
loggerDb, err = configureDatabase(cfg.log_db_type, cfg.log_db_host, cfg.log_db_port, cfg.log_db_name, cfg.log_db_user, cfg.log_db_pass)
|
||||
}
|
||||
if err == nil {
|
||||
defer loggerDb.Close()
|
||||
rater.SetStorageLogger(loggerDb)
|
||||
}
|
||||
|
||||
if sm_debit_period > 0 {
|
||||
if dp, err := time.ParseDuration(fmt.Sprintf("%vs", sm_debit_period)); err == nil {
|
||||
if cfg.sm_debit_period > 0 {
|
||||
if dp, err := time.ParseDuration(fmt.Sprintf("%vs", cfg.sm_debit_period)); err == nil {
|
||||
rater.SetDebitPeriod(dp)
|
||||
}
|
||||
}
|
||||
|
||||
if rater_enabled && rater_balancer != DISABLED && !balancer_enabled {
|
||||
if cfg.rater_enabled && cfg.rater_balancer != DISABLED && !cfg.balancer_enabled {
|
||||
go registerToBalancer()
|
||||
go stopRaterSingnalHandler()
|
||||
}
|
||||
responder := &rater.Responder{ExitChan: exitChan}
|
||||
if rater_enabled && !balancer_enabled && rater_listen != INTERNAL {
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS Rater on %s.", rater_listen))
|
||||
go listenToRPCRequests(responder, rater_listen, rater_rpc_encoding)
|
||||
if cfg.rater_enabled && !cfg.balancer_enabled && cfg.rater_listen != INTERNAL {
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS Rater on %s.", cfg.rater_listen))
|
||||
go listenToRPCRequests(responder, cfg.rater_listen, cfg.rater_rpc_encoding)
|
||||
}
|
||||
if balancer_enabled {
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS Balancer on %s.", balancer_listen))
|
||||
if cfg.balancer_enabled {
|
||||
rater.Logger.Info(fmt.Sprintf("Starting CGRateS Balancer on %s.", cfg.balancer_listen))
|
||||
go stopBalancerSingnalHandler()
|
||||
responder.Bal = bal
|
||||
go listenToRPCRequests(responder, balancer_listen, balancer_rpc_encoding)
|
||||
if rater_enabled {
|
||||
go listenToRPCRequests(responder, cfg.balancer_listen, cfg.balancer_rpc_encoding)
|
||||
if cfg.rater_enabled {
|
||||
rater.Logger.Info("Starting internal rater.")
|
||||
bal.AddClient("local", new(rater.ResponderWorker))
|
||||
}
|
||||
}
|
||||
|
||||
if scheduler_enabled {
|
||||
if cfg.scheduler_enabled {
|
||||
rater.Logger.Info("Starting CGRateS Scheduler.")
|
||||
go func() {
|
||||
sched := scheduler.NewScheduler()
|
||||
@@ -362,14 +309,14 @@ func main() {
|
||||
}()
|
||||
}
|
||||
|
||||
if sm_enabled {
|
||||
if cfg.sm_enabled {
|
||||
rater.Logger.Info("Starting CGRateS SessionManager.")
|
||||
go startSessionManager(responder, loggerDb)
|
||||
// close all sessions on shutdown
|
||||
go shutdownSessionmanagerSingnalHandler()
|
||||
}
|
||||
|
||||
if mediator_enabled {
|
||||
if cfg.mediator_enabled {
|
||||
rater.Logger.Info("Starting CGRateS Mediator.")
|
||||
go startMediator(responder, loggerDb)
|
||||
}
|
||||
|
||||
@@ -20,141 +20,258 @@ package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/goconf/conf"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// this function will overwrite default values with the ones present in the config file
|
||||
func readConfig(c *conf.ConfigFile) {
|
||||
var hasOpt bool
|
||||
if hasOpt = c.HasOption("global", "datadb_type"); hasOpt {
|
||||
data_db_type, _ = c.GetString("global", "datadb_type")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "datadb_host"); hasOpt {
|
||||
data_db_host, _ = c.GetString("global", "datadb_host")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "datadb_port"); hasOpt {
|
||||
data_db_port, _ = c.GetString("global", "datadb_port")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "datadb_name"); hasOpt {
|
||||
data_db_name, _ = c.GetString("global", "datadb_name")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "datadb_user"); hasOpt {
|
||||
data_db_user, _ = c.GetString("global", "datadb_user")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "datadb_passwd"); hasOpt {
|
||||
data_db_pass, _ = c.GetString("global", "datadb_passwd")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "logdb_type"); hasOpt {
|
||||
log_db_type, _ = c.GetString("global", "logdb_type")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "logdb_host"); hasOpt {
|
||||
log_db_host, _ = c.GetString("global", "logdb_host")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "logdb_port"); hasOpt {
|
||||
log_db_port, _ = c.GetString("global", "logdb_port")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "logdb_name"); hasOpt {
|
||||
log_db_name, _ = c.GetString("global", "logdb_name")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "logdb_user"); hasOpt {
|
||||
log_db_user, _ = c.GetString("global", "logdb_user")
|
||||
}
|
||||
if hasOpt = c.HasOption("global", "logdb_passwd"); hasOpt {
|
||||
log_db_pass, _ = c.GetString("global", "logdb_passwd")
|
||||
}
|
||||
if hasOpt = c.HasOption("rater", "enabled"); hasOpt {
|
||||
rater_enabled, _ = c.GetBool("rater", "enabled")
|
||||
}
|
||||
if hasOpt = c.HasOption("rater", "balancer"); hasOpt {
|
||||
rater_balancer, _ = c.GetString("rater", "balancer")
|
||||
}
|
||||
if hasOpt = c.HasOption("rater", "listen"); hasOpt {
|
||||
rater_listen, _ = c.GetString("rater", "listen")
|
||||
}
|
||||
if hasOpt = c.HasOption("rater", "rpc_encoding"); hasOpt {
|
||||
rater_rpc_encoding, _ = c.GetString("rater", "rpc_encoding")
|
||||
}
|
||||
if hasOpt = c.HasOption("balancer", "enabled"); hasOpt {
|
||||
balancer_enabled, _ = c.GetBool("balancer", "enabled")
|
||||
}
|
||||
if hasOpt = c.HasOption("balancer", "listen"); hasOpt {
|
||||
balancer_listen, _ = c.GetString("balancer", "listen")
|
||||
}
|
||||
if hasOpt = c.HasOption("balancer", "rpc_encoding"); hasOpt {
|
||||
balancer_rpc_encoding, _ = c.GetString("balancer", "rpc_encoding")
|
||||
}
|
||||
if hasOpt = c.HasOption("scheduler", "enabled"); hasOpt {
|
||||
scheduler_enabled, _ = c.GetBool("scheduler", "enabled")
|
||||
}
|
||||
if hasOpt = c.HasOption("session_manager", "enabled"); hasOpt {
|
||||
sm_enabled, _ = c.GetBool("session_manager", "enabled")
|
||||
}
|
||||
if hasOpt = c.HasOption("session_manager", "switch_type"); hasOpt {
|
||||
sm_switch_type, _ = c.GetString("session_manager", "switch_type")
|
||||
}
|
||||
if hasOpt = c.HasOption("session_manager", "rater"); hasOpt {
|
||||
sm_rater, _ = c.GetString("session_manager", "rater")
|
||||
}
|
||||
if hasOpt = c.HasOption("session_manager", "debit_period"); hasOpt {
|
||||
sm_debit_period, _ = c.GetInt("session_manager", "debit_period")
|
||||
}
|
||||
if hasOpt = c.HasOption("session_manager", "rpc_encoding"); hasOpt {
|
||||
sm_rpc_encoding, _ = c.GetString("session_manager", "rpc_encoding")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "enabled"); hasOpt {
|
||||
mediator_enabled, _ = c.GetBool("mediator", "enabled")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "cdr_path"); hasOpt {
|
||||
mediator_cdr_path, _ = c.GetString("mediator", "cdr_path")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "cdr_out_path"); hasOpt {
|
||||
mediator_cdr_out_path, _ = c.GetString("mediator", "cdr_out_path")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "rater"); hasOpt {
|
||||
mediator_rater, _ = c.GetString("mediator", "rater")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "rpc_encoding"); hasOpt {
|
||||
mediator_rpc_encoding, _ = c.GetString("mediator", "rpc_encoding")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "skipdb"); hasOpt {
|
||||
mediator_skipdb, _ = c.GetBool("mediator", "skipdb")
|
||||
}
|
||||
if hasOpt = c.HasOption("mediator", "pseudo_prepaid"); hasOpt {
|
||||
mediator_pseudo_prepaid, _ = c.GetBool("mediator", "pseudo_prepaid")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "server"); hasOpt {
|
||||
freeswitch_server, _ = c.GetString("freeswitch", "server")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "pass"); hasOpt {
|
||||
freeswitch_pass, _ = c.GetString("freeswitch", "pass")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "tor_index"); hasOpt {
|
||||
freeswitch_tor, _ = c.GetString("freeswitch", "tor_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "tenant_index"); hasOpt {
|
||||
freeswitch_tenant, _ = c.GetString("freeswitch", "tenant_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "direction_index"); hasOpt {
|
||||
freeswitch_direction, _ = c.GetString("freeswitch", "direction_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "subject_index"); hasOpt {
|
||||
freeswitch_subject, _ = c.GetString("freeswitch", "subject_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "account_index"); hasOpt {
|
||||
freeswitch_account, _ = c.GetString("freeswitch", "account_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "destination_index"); hasOpt {
|
||||
freeswitch_destination, _ = c.GetString("freeswitch", "destination_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "time_start_index"); hasOpt {
|
||||
freeswitch_time_start, _ = c.GetString("freeswitch", "time_start_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "duration_index"); hasOpt {
|
||||
freeswitch_duration, _ = c.GetString("freeswitch", "duration_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "uuid_index"); hasOpt {
|
||||
freeswitch_uuid, _ = c.GetString("freeswitch", "uuid_index")
|
||||
}
|
||||
if hasOpt = c.HasOption("freeswitch", "reconnects"); hasOpt {
|
||||
freeswitch_reconnects, _ = c.GetInt("freeswitch", "reconnects")
|
||||
}
|
||||
// Holds system configuration, defaults are overwritten with values from config file if found
|
||||
type CGRConfig struct {
|
||||
data_db_type string
|
||||
data_db_host string // The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
data_db_port string // The port to bind to.
|
||||
data_db_name string // The name of the database to connect to.
|
||||
data_db_user string // The user to sign in as.
|
||||
data_db_pass string // The user's password.
|
||||
log_db_type string // Should reflect the database type used to store logs
|
||||
log_db_host string // The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
log_db_port string // The port to bind to.
|
||||
log_db_name string // The name of the database to connect to.
|
||||
log_db_user string // The user to sign in as.
|
||||
log_db_pass string // The user's password.
|
||||
rater_enabled bool // start standalone server (no balancer)
|
||||
rater_balancer string // balancer address host:port
|
||||
rater_listen string // listening address host:port
|
||||
rater_rpc_encoding string // use JSON for RPC encoding
|
||||
balancer_enabled bool
|
||||
balancer_listen string // Json RPC server address
|
||||
balancer_rpc_encoding string // use JSON for RPC encoding
|
||||
scheduler_enabled bool
|
||||
sm_enabled bool
|
||||
sm_switch_type string
|
||||
sm_rater string // address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
sm_debit_period int // the period to be debited in advanced during a call (in seconds)
|
||||
sm_rpc_encoding string // use JSON for RPC encoding
|
||||
sm_default_tor string // set default type of record label to 0
|
||||
sm_default_tenant string // set default tenant to 0
|
||||
sm_default_subject string // set default rating subject to 0
|
||||
mediator_enabled bool
|
||||
mediator_cdr_path string // Freeswitch Master CSV CDR path.
|
||||
mediator_cdr_out_path string // Freeswitch Master CSV CDR output path.
|
||||
mediator_rater string // address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
mediator_rpc_encoding string // use JSON for RPC encoding
|
||||
mediator_skipdb bool
|
||||
mediator_pseudo_prepaid bool
|
||||
freeswitch_server string // freeswitch address host:port
|
||||
freeswitch_pass string // reeswitch address host:port
|
||||
freeswitch_direction string
|
||||
freeswitch_tor string
|
||||
freeswitch_tenant string
|
||||
freeswitch_subject string
|
||||
freeswitch_account string
|
||||
freeswitch_destination string
|
||||
freeswitch_time_start string
|
||||
freeswitch_duration string
|
||||
freeswitch_uuid string
|
||||
freeswitch_reconnects int
|
||||
}
|
||||
|
||||
// Instantiate a new CGRConfig setting defaults or reading from file
|
||||
func NewCGRConfig(cfgPath *string) (*CGRConfig, error) {
|
||||
c, err := conf.ReadConfigFile(*cfgPath)
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Could not open the configuration file: %s", err))
|
||||
}
|
||||
cfg := &CGRConfig{}
|
||||
var hasOpt bool
|
||||
cfg.data_db_type = REDIS
|
||||
if hasOpt = c.HasOption("global", "datadb_type"); hasOpt {
|
||||
cfg.data_db_type, _ = c.GetString("global", "datadb_type")
|
||||
}
|
||||
cfg.data_db_host = "localhost"
|
||||
if hasOpt = c.HasOption("global", "datadb_host"); hasOpt {
|
||||
cfg.data_db_host, _ = c.GetString("global", "datadb_host")
|
||||
}
|
||||
cfg.data_db_port = ""
|
||||
if hasOpt = c.HasOption("global", "datadb_port"); hasOpt {
|
||||
cfg.data_db_port, _ = c.GetString("global", "datadb_port")
|
||||
}
|
||||
cfg.data_db_name = "10"
|
||||
if hasOpt = c.HasOption("global", "datadb_name"); hasOpt {
|
||||
cfg.data_db_name, _ = c.GetString("global", "datadb_name")
|
||||
}
|
||||
cfg.data_db_user = ""
|
||||
if hasOpt = c.HasOption("global", "datadb_user"); hasOpt {
|
||||
cfg.data_db_user, _ = c.GetString("global", "datadb_user")
|
||||
}
|
||||
cfg.data_db_pass = ""
|
||||
if hasOpt = c.HasOption("global", "datadb_passwd"); hasOpt {
|
||||
cfg.data_db_pass, _ = c.GetString("global", "datadb_passwd")
|
||||
}
|
||||
cfg.log_db_type = MONGO
|
||||
if hasOpt = c.HasOption("global", "logdb_type"); hasOpt {
|
||||
cfg.log_db_type, _ = c.GetString("global", "logdb_type")
|
||||
}
|
||||
cfg.log_db_host = "localhost"
|
||||
if hasOpt = c.HasOption("global", "logdb_host"); hasOpt {
|
||||
cfg.log_db_host, _ = c.GetString("global", "logdb_host")
|
||||
}
|
||||
cfg.log_db_port = ""
|
||||
if hasOpt = c.HasOption("global", "logdb_port"); hasOpt {
|
||||
cfg.log_db_port, _ = c.GetString("global", "logdb_port")
|
||||
}
|
||||
cfg.log_db_name = "cgrates"
|
||||
if hasOpt = c.HasOption("global", "logdb_name"); hasOpt {
|
||||
cfg.log_db_name, _ = c.GetString("global", "logdb_name")
|
||||
}
|
||||
cfg.log_db_user = ""
|
||||
if hasOpt = c.HasOption("global", "logdb_user"); hasOpt {
|
||||
cfg.log_db_user, _ = c.GetString("global", "logdb_user")
|
||||
}
|
||||
cfg.log_db_pass = ""
|
||||
if hasOpt = c.HasOption("global", "logdb_passwd"); hasOpt {
|
||||
cfg.log_db_pass, _ = c.GetString("global", "logdb_passwd")
|
||||
}
|
||||
cfg.rater_enabled = false
|
||||
if hasOpt = c.HasOption("rater", "enabled"); hasOpt {
|
||||
cfg.rater_enabled, _ = c.GetBool("rater", "enabled")
|
||||
}
|
||||
cfg.rater_balancer = DISABLED
|
||||
if hasOpt = c.HasOption("rater", "balancer"); hasOpt {
|
||||
cfg.rater_balancer, _ = c.GetString("rater", "balancer")
|
||||
}
|
||||
cfg.rater_listen = "127.0.0.1:1234"
|
||||
if hasOpt = c.HasOption("rater", "listen"); hasOpt {
|
||||
cfg.rater_listen, _ = c.GetString("rater", "listen")
|
||||
}
|
||||
cfg.rater_rpc_encoding = GOB
|
||||
if hasOpt = c.HasOption("rater", "rpc_encoding"); hasOpt {
|
||||
cfg.rater_rpc_encoding, _ = c.GetString("rater", "rpc_encoding")
|
||||
}
|
||||
cfg.balancer_enabled = false
|
||||
if hasOpt = c.HasOption("balancer", "enabled"); hasOpt {
|
||||
cfg.balancer_enabled, _ = c.GetBool("balancer", "enabled")
|
||||
}
|
||||
cfg.balancer_listen = "127.0.0.1:2001"
|
||||
if hasOpt = c.HasOption("balancer", "listen"); hasOpt {
|
||||
cfg.balancer_listen, _ = c.GetString("balancer", "listen")
|
||||
}
|
||||
cfg.balancer_rpc_encoding = GOB
|
||||
if hasOpt = c.HasOption("balancer", "rpc_encoding"); hasOpt {
|
||||
cfg.balancer_rpc_encoding, _ = c.GetString("balancer", "rpc_encoding")
|
||||
}
|
||||
cfg.scheduler_enabled = false
|
||||
if hasOpt = c.HasOption("scheduler", "enabled"); hasOpt {
|
||||
cfg.scheduler_enabled, _ = c.GetBool("scheduler", "enabled")
|
||||
}
|
||||
cfg.mediator_enabled = false
|
||||
if hasOpt = c.HasOption("mediator", "enabled"); hasOpt {
|
||||
cfg.mediator_enabled, _ = c.GetBool("mediator", "enabled")
|
||||
}
|
||||
cfg.mediator_cdr_path = ""
|
||||
if hasOpt = c.HasOption("mediator", "cdr_path"); hasOpt {
|
||||
cfg.mediator_cdr_path, _ = c.GetString("mediator", "cdr_path")
|
||||
}
|
||||
cfg.mediator_cdr_out_path = ""
|
||||
if hasOpt = c.HasOption("mediator", "cdr_out_path"); hasOpt {
|
||||
cfg.mediator_cdr_out_path, _ = c.GetString("mediator", "cdr_out_path")
|
||||
}
|
||||
cfg.mediator_rater = INTERNAL
|
||||
if hasOpt = c.HasOption("mediator", "rater"); hasOpt {
|
||||
cfg.mediator_rater, _ = c.GetString("mediator", "rater")
|
||||
}
|
||||
cfg.mediator_rpc_encoding = GOB
|
||||
if hasOpt = c.HasOption("mediator", "rpc_encoding"); hasOpt {
|
||||
cfg.mediator_rpc_encoding, _ = c.GetString("mediator", "rpc_encoding")
|
||||
}
|
||||
cfg.mediator_skipdb = false
|
||||
if hasOpt = c.HasOption("mediator", "skipdb"); hasOpt {
|
||||
cfg.mediator_skipdb, _ = c.GetBool("mediator", "skipdb")
|
||||
}
|
||||
cfg.mediator_pseudo_prepaid = false
|
||||
if hasOpt = c.HasOption("mediator", "pseudo_prepaid"); hasOpt {
|
||||
cfg.mediator_pseudo_prepaid, _ = c.GetBool("mediator", "pseudo_prepaid")
|
||||
}
|
||||
cfg.sm_enabled = false
|
||||
if hasOpt = c.HasOption("session_manager", "enabled"); hasOpt {
|
||||
cfg.sm_enabled, _ = c.GetBool("session_manager", "enabled")
|
||||
}
|
||||
cfg.sm_switch_type = FS
|
||||
if hasOpt = c.HasOption("session_manager", "switch_type"); hasOpt {
|
||||
cfg.sm_switch_type, _ = c.GetString("session_manager", "switch_type")
|
||||
}
|
||||
cfg.sm_rater = INTERNAL
|
||||
if hasOpt = c.HasOption("session_manager", "rater"); hasOpt {
|
||||
cfg.sm_rater, _ = c.GetString("session_manager", "rater")
|
||||
}
|
||||
cfg.sm_debit_period = 10
|
||||
if hasOpt = c.HasOption("session_manager", "debit_period"); hasOpt {
|
||||
cfg.sm_debit_period, _ = c.GetInt("session_manager", "debit_period")
|
||||
}
|
||||
cfg.sm_rpc_encoding = GOB
|
||||
if hasOpt = c.HasOption("session_manager", "rpc_encoding"); hasOpt {
|
||||
cfg.sm_rpc_encoding, _ = c.GetString("session_manager", "rpc_encoding")
|
||||
}
|
||||
cfg.sm_default_tor = "0"
|
||||
if hasOpt = c.HasOption("session_manager", "default_tor"); hasOpt {
|
||||
cfg.sm_default_tor, _ = c.GetString("session_manager", "default_tor")
|
||||
}
|
||||
cfg.sm_default_tenant = "0"
|
||||
if hasOpt = c.HasOption("session_manager", "default_tenant"); hasOpt {
|
||||
cfg.sm_default_tenant, _ = c.GetString("session_manager", "default_tenant")
|
||||
}
|
||||
cfg.sm_default_subject = "0"
|
||||
if hasOpt = c.HasOption("session_manager", "default_subject"); hasOpt {
|
||||
cfg.sm_default_subject, _ = c.GetString("session_manager", "default_subject")
|
||||
}
|
||||
cfg.freeswitch_server = "localhost:8021"
|
||||
if hasOpt = c.HasOption("freeswitch", "server"); hasOpt {
|
||||
cfg.freeswitch_server, _ = c.GetString("freeswitch", "server")
|
||||
}
|
||||
cfg.freeswitch_pass = "ClueCon"
|
||||
if hasOpt = c.HasOption("freeswitch", "pass"); hasOpt {
|
||||
cfg.freeswitch_pass, _ = c.GetString("freeswitch", "pass")
|
||||
}
|
||||
cfg.freeswitch_reconnects = 5
|
||||
if hasOpt = c.HasOption("freeswitch", "reconnects"); hasOpt {
|
||||
cfg.freeswitch_reconnects, _ = c.GetInt("freeswitch", "reconnects")
|
||||
}
|
||||
cfg.freeswitch_tor = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "tor_index"); hasOpt {
|
||||
cfg.freeswitch_tor, _ = c.GetString("freeswitch", "tor_index")
|
||||
}
|
||||
cfg.freeswitch_tenant = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "tenant_index"); hasOpt {
|
||||
cfg.freeswitch_tenant, _ = c.GetString("freeswitch", "tenant_index")
|
||||
}
|
||||
cfg.freeswitch_direction = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "direction_index"); hasOpt {
|
||||
cfg.freeswitch_direction, _ = c.GetString("freeswitch", "direction_index")
|
||||
}
|
||||
cfg.freeswitch_subject = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "subject_index"); hasOpt {
|
||||
cfg.freeswitch_subject, _ = c.GetString("freeswitch", "subject_index")
|
||||
}
|
||||
cfg.freeswitch_account = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "account_index"); hasOpt {
|
||||
cfg.freeswitch_account, _ = c.GetString("freeswitch", "account_index")
|
||||
}
|
||||
cfg.freeswitch_destination = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "destination_index"); hasOpt {
|
||||
cfg.freeswitch_destination, _ = c.GetString("freeswitch", "destination_index")
|
||||
}
|
||||
cfg.freeswitch_time_start = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "time_start_index"); hasOpt {
|
||||
cfg.freeswitch_time_start, _ = c.GetString("freeswitch", "time_start_index")
|
||||
}
|
||||
cfg.freeswitch_duration = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "duration_index"); hasOpt {
|
||||
cfg.freeswitch_duration, _ = c.GetString("freeswitch", "duration_index")
|
||||
}
|
||||
cfg.freeswitch_uuid = ""
|
||||
if hasOpt = c.HasOption("freeswitch", "uuid_index"); hasOpt {
|
||||
cfg.freeswitch_uuid, _ = c.GetString("freeswitch", "uuid_index")
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -19,170 +19,103 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/goconf/conf"
|
||||
"net/rpc"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const (
|
||||
configText = `
|
||||
[global]
|
||||
datadb_type = test #
|
||||
datadb_host = test # The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
datadb_port = test # The port to bind to.
|
||||
datadb_name = test # The name of the database to connect to.
|
||||
datadb_user = test # The user to sign in as.
|
||||
datadb_passwd = test # The user's password.root
|
||||
logdb_type = test #
|
||||
logdb_host = test # The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
logdb_port = test # The port to bind to.
|
||||
logdb_name = test # The name of the database to connect to.
|
||||
logdb_user = test # The user to sign in as.
|
||||
logdb_passwd = test # The user's password.root
|
||||
|
||||
[balancer]
|
||||
enabled = true # Start balancer server
|
||||
listen = test # Balancer listen interface
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[rater]
|
||||
enabled = true
|
||||
listen = test # listening address host:port, internal for internal communication only
|
||||
balancer = test # if defined it will register to balancer as worker
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[mediator]
|
||||
enabled = true
|
||||
cdr_path = test # Freeswitch Master CSV CDR path.
|
||||
cdr_out_path = test
|
||||
rater = test #address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
skipdb = true
|
||||
pseudo_prepaid = true
|
||||
|
||||
[scheduler]
|
||||
enabled = true
|
||||
|
||||
[session_manager]
|
||||
enabled = true
|
||||
switch_type = test
|
||||
rater = test #address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
debit_period = 11
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[freeswitch]
|
||||
server = test # freeswitch address host:port
|
||||
pass = test # freeswitch address host:port
|
||||
direction_index = test
|
||||
tor_index = test
|
||||
tenant_index = test
|
||||
subject_index = test
|
||||
account_index = test
|
||||
destination_index = test
|
||||
time_start_index = test
|
||||
duration_index = test
|
||||
uuid_index = test
|
||||
`
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
c, err := conf.ReadConfigBytes([]byte(configText))
|
||||
cfgPth := "test_data.txt"
|
||||
cfg, err = NewCGRConfig( &cfgPth )
|
||||
if err != nil {
|
||||
t.Log("Could not parse configuration!")
|
||||
t.Log(fmt.Sprintf("Could not parse config: %s!", err))
|
||||
t.FailNow()
|
||||
}
|
||||
readConfig(c)
|
||||
if data_db_type != "test" ||
|
||||
data_db_host != "test" ||
|
||||
data_db_port != "test" ||
|
||||
data_db_name != "test" ||
|
||||
data_db_user != "test" ||
|
||||
data_db_pass != "test" ||
|
||||
log_db_type != "test" ||
|
||||
log_db_host != "test" ||
|
||||
log_db_port != "test" ||
|
||||
log_db_name != "test" ||
|
||||
log_db_user != "test" ||
|
||||
log_db_pass != "test" ||
|
||||
|
||||
rater_enabled != true ||
|
||||
rater_balancer != "test" ||
|
||||
rater_listen != "test" ||
|
||||
rater_rpc_encoding != "test" ||
|
||||
|
||||
balancer_enabled != true ||
|
||||
balancer_listen != "test" ||
|
||||
balancer_rpc_encoding != "test" ||
|
||||
|
||||
scheduler_enabled != true ||
|
||||
|
||||
sm_enabled != true ||
|
||||
sm_switch_type != "test" ||
|
||||
sm_rater != "test" ||
|
||||
sm_debit_period != 11 ||
|
||||
sm_rpc_encoding != "test" ||
|
||||
|
||||
mediator_enabled != true ||
|
||||
mediator_cdr_path != "test" ||
|
||||
mediator_cdr_out_path != "test" ||
|
||||
mediator_rater != "test" ||
|
||||
mediator_rpc_encoding != "test" ||
|
||||
mediator_skipdb != true ||
|
||||
mediator_pseudo_prepaid != true ||
|
||||
|
||||
freeswitch_server != "test" ||
|
||||
freeswitch_pass != "test" ||
|
||||
freeswitch_direction != "test" ||
|
||||
freeswitch_tor != "test" ||
|
||||
freeswitch_tenant != "test" ||
|
||||
freeswitch_subject != "test" ||
|
||||
freeswitch_account != "test" ||
|
||||
freeswitch_destination != "test" ||
|
||||
freeswitch_time_start != "test" ||
|
||||
freeswitch_duration != "test" ||
|
||||
freeswitch_uuid != "test" {
|
||||
t.Log(data_db_type)
|
||||
t.Log(data_db_host)
|
||||
t.Log(data_db_port)
|
||||
t.Log(data_db_name)
|
||||
t.Log(data_db_user)
|
||||
t.Log(data_db_pass)
|
||||
t.Log(log_db_type)
|
||||
t.Log(log_db_host)
|
||||
t.Log(log_db_port)
|
||||
t.Log(log_db_name)
|
||||
t.Log(log_db_user)
|
||||
t.Log(log_db_pass)
|
||||
t.Log(rater_enabled)
|
||||
t.Log(rater_balancer)
|
||||
t.Log(rater_listen)
|
||||
t.Log(rater_rpc_encoding)
|
||||
t.Log(balancer_enabled)
|
||||
t.Log(balancer_listen)
|
||||
t.Log(balancer_rpc_encoding)
|
||||
t.Log(scheduler_enabled)
|
||||
t.Log(sm_enabled)
|
||||
t.Log(sm_switch_type)
|
||||
t.Log(sm_rater)
|
||||
t.Log(sm_debit_period)
|
||||
t.Log(sm_rpc_encoding)
|
||||
t.Log(mediator_enabled)
|
||||
t.Log(mediator_cdr_path)
|
||||
t.Log(mediator_cdr_out_path)
|
||||
t.Log(mediator_rater)
|
||||
t.Log(mediator_skipdb)
|
||||
t.Log(mediator_pseudo_prepaid)
|
||||
t.Log(freeswitch_server)
|
||||
t.Log(freeswitch_pass)
|
||||
t.Log(freeswitch_direction)
|
||||
t.Log(freeswitch_tor)
|
||||
t.Log(freeswitch_tenant)
|
||||
t.Log(freeswitch_subject)
|
||||
t.Log(freeswitch_account)
|
||||
t.Log(freeswitch_destination)
|
||||
t.Log(freeswitch_time_start)
|
||||
t.Log(freeswitch_duration)
|
||||
t.Log(freeswitch_uuid)
|
||||
if cfg.data_db_type != "test" ||
|
||||
cfg.data_db_host != "test" ||
|
||||
cfg.data_db_port != "test" ||
|
||||
cfg.data_db_name != "test" ||
|
||||
cfg.data_db_user != "test" ||
|
||||
cfg.data_db_pass != "test" ||
|
||||
cfg.log_db_type != "test" ||
|
||||
cfg.log_db_host != "test" ||
|
||||
cfg.log_db_port != "test" ||
|
||||
cfg.log_db_name != "test" ||
|
||||
cfg.log_db_user != "test" ||
|
||||
cfg.log_db_pass != "test" ||
|
||||
cfg.rater_enabled != true ||
|
||||
cfg.rater_balancer != "test" ||
|
||||
cfg.rater_listen != "test" ||
|
||||
cfg.rater_rpc_encoding != "test" ||
|
||||
cfg.balancer_enabled != true ||
|
||||
cfg.balancer_listen != "test" ||
|
||||
cfg.balancer_rpc_encoding != "test" ||
|
||||
cfg.scheduler_enabled != true ||
|
||||
cfg.sm_enabled != true ||
|
||||
cfg.sm_switch_type != "test" ||
|
||||
cfg.sm_rater != "test" ||
|
||||
cfg.sm_debit_period != 11 ||
|
||||
cfg.sm_rpc_encoding != "test" ||
|
||||
cfg.mediator_enabled != true ||
|
||||
cfg.mediator_cdr_path != "test" ||
|
||||
cfg.mediator_cdr_out_path != "test" ||
|
||||
cfg.mediator_rater != "test" ||
|
||||
cfg.mediator_rpc_encoding != "test" ||
|
||||
cfg.mediator_skipdb != true ||
|
||||
cfg.mediator_pseudo_prepaid != true ||
|
||||
cfg.freeswitch_server != "test" ||
|
||||
cfg.freeswitch_pass != "test" ||
|
||||
cfg.freeswitch_direction != "test" ||
|
||||
cfg.freeswitch_tor != "test" ||
|
||||
cfg.freeswitch_tenant != "test" ||
|
||||
cfg.freeswitch_subject != "test" ||
|
||||
cfg.freeswitch_account != "test" ||
|
||||
cfg.freeswitch_destination != "test" ||
|
||||
cfg.freeswitch_time_start != "test" ||
|
||||
cfg.freeswitch_duration != "test" ||
|
||||
cfg.freeswitch_uuid != "test" {
|
||||
t.Log(cfg.data_db_type)
|
||||
t.Log(cfg.data_db_host)
|
||||
t.Log(cfg.data_db_port)
|
||||
t.Log(cfg.data_db_name)
|
||||
t.Log(cfg.data_db_user)
|
||||
t.Log(cfg.data_db_pass)
|
||||
t.Log(cfg.log_db_type)
|
||||
t.Log(cfg.log_db_host)
|
||||
t.Log(cfg.log_db_port)
|
||||
t.Log(cfg.log_db_name)
|
||||
t.Log(cfg.log_db_user)
|
||||
t.Log(cfg.log_db_pass)
|
||||
t.Log(cfg.rater_enabled)
|
||||
t.Log(cfg.rater_balancer)
|
||||
t.Log(cfg.rater_listen)
|
||||
t.Log(cfg.rater_rpc_encoding)
|
||||
t.Log(cfg.balancer_enabled)
|
||||
t.Log(cfg.balancer_listen)
|
||||
t.Log(cfg.balancer_rpc_encoding)
|
||||
t.Log(cfg.scheduler_enabled)
|
||||
t.Log(cfg.sm_enabled)
|
||||
t.Log(cfg.sm_switch_type)
|
||||
t.Log(cfg.sm_rater)
|
||||
t.Log(cfg.sm_debit_period)
|
||||
t.Log(cfg.sm_rpc_encoding)
|
||||
t.Log(cfg.mediator_enabled)
|
||||
t.Log(cfg.mediator_cdr_path)
|
||||
t.Log(cfg.mediator_cdr_out_path)
|
||||
t.Log(cfg.mediator_rater)
|
||||
t.Log(cfg.mediator_skipdb)
|
||||
t.Log(cfg.mediator_pseudo_prepaid)
|
||||
t.Log(cfg.freeswitch_server)
|
||||
t.Log(cfg.freeswitch_pass)
|
||||
t.Log(cfg.freeswitch_direction)
|
||||
t.Log(cfg.freeswitch_tor)
|
||||
t.Log(cfg.freeswitch_tenant)
|
||||
t.Log(cfg.freeswitch_subject)
|
||||
t.Log(cfg.freeswitch_account)
|
||||
t.Log(cfg.freeswitch_destination)
|
||||
t.Log(cfg.freeswitch_time_start)
|
||||
t.Log(cfg.freeswitch_duration)
|
||||
t.Log(cfg.freeswitch_uuid)
|
||||
t.Error("Config file read failed!")
|
||||
}
|
||||
}
|
||||
@@ -201,27 +134,17 @@ func TestConfig(t *testing.T) {
|
||||
}
|
||||
}*/
|
||||
|
||||
func TestVarReset(t *testing.T) {
|
||||
c, err := conf.ReadConfigBytes([]byte(configText))
|
||||
func TestParamOverwrite(t *testing.T) {
|
||||
cfgPth := "test_data.txt"
|
||||
cfg, err = NewCGRConfig( &cfgPth )
|
||||
if err != nil {
|
||||
t.Log("Could not parse configuration!")
|
||||
t.Log(fmt.Sprintf("Could not parse config: %s!", err))
|
||||
t.FailNow()
|
||||
}
|
||||
myString := "default"
|
||||
myString, err = c.GetString("default", "non_existing")
|
||||
if err == nil {
|
||||
t.Error("Reding non exitsing variable did not issue error!")
|
||||
}
|
||||
if myString != "" {
|
||||
t.Error("Variable has not been reseted")
|
||||
}
|
||||
myBool := true
|
||||
myBool, err = c.GetBool("default", "non_existing")
|
||||
if err == nil {
|
||||
t.Error("Reding non exitsing variable did not issue error!")
|
||||
}
|
||||
if myBool {
|
||||
t.Error("Variable has not been reseted")
|
||||
if cfg.freeswitch_reconnects != 5 { // one default which is not overwritten in test data
|
||||
t.Errorf("freeswitch_reconnects set == %d, expect 5",cfg.freeswitch_reconnects)
|
||||
} else if cfg.scheduler_enabled != true { // one parameter which should be overwritten in test data
|
||||
t.Errorf("scheduler_enabled set == %d, expect true",cfg.freeswitch_reconnects)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,15 +58,15 @@ func stopRaterSingnalHandler() {
|
||||
Connects to the balancer and calls unregister RPC method.
|
||||
*/
|
||||
func unregisterFromBalancer() {
|
||||
client, err := rpc.Dial("tcp", rater_balancer)
|
||||
client, err := rpc.Dial("tcp", cfg.rater_balancer)
|
||||
if err != nil {
|
||||
rater.Logger.Crit("Cannot contact the balancer!")
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
var reply int
|
||||
rater.Logger.Info(fmt.Sprintf("Unregistering from balancer %s", rater_balancer))
|
||||
client.Call("Responder.UnRegisterRater", rater_listen, &reply)
|
||||
rater.Logger.Info(fmt.Sprintf("Unregistering from balancer %s", cfg.rater_balancer))
|
||||
client.Call("Responder.UnRegisterRater", cfg.rater_listen, &reply)
|
||||
if err := client.Close(); err != nil {
|
||||
rater.Logger.Crit("Could not close balancer unregistration!")
|
||||
exitChan <- true
|
||||
@@ -77,15 +77,15 @@ func unregisterFromBalancer() {
|
||||
Connects to the balancer and rehisters the rater to the server.
|
||||
*/
|
||||
func registerToBalancer() {
|
||||
client, err := rpc.Dial("tcp", rater_balancer)
|
||||
client, err := rpc.Dial("tcp", cfg.rater_balancer)
|
||||
if err != nil {
|
||||
rater.Logger.Crit(fmt.Sprintf("Cannot contact the balancer: %v", err))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
var reply int
|
||||
rater.Logger.Info(fmt.Sprintf("Registering to balancer %s", rater_balancer))
|
||||
client.Call("Responder.RegisterRater", rater_listen, &reply)
|
||||
rater.Logger.Info(fmt.Sprintf("Registering to balancer %s", cfg.rater_balancer))
|
||||
client.Call("Responder.RegisterRater", cfg.rater_listen, &reply)
|
||||
if err := client.Close(); err != nil {
|
||||
rater.Logger.Crit("Could not close balancer registration!")
|
||||
exitChan <- true
|
||||
@@ -115,7 +115,7 @@ func shutdownSessionmanagerSingnalHandler() {
|
||||
signal.Notify(c, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT)
|
||||
<-c
|
||||
|
||||
if err := sm.Shutdown(); err!=nil {
|
||||
if err := sm.Shutdown(); err != nil {
|
||||
rater.Logger.Warning(fmt.Sprintf("<SessionManager> %s", err))
|
||||
}
|
||||
exitChan <- true
|
||||
|
||||
60
cmd/cgr-rater/test_data.txt
Normal file
60
cmd/cgr-rater/test_data.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
### Test data, not for production usage
|
||||
|
||||
[global]
|
||||
datadb_type = test #
|
||||
datadb_host = test # The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
datadb_port = test # The port to bind to.
|
||||
datadb_name = test # The name of the database to connect to.
|
||||
datadb_user = test # The user to sign in as.
|
||||
datadb_passwd = test # The user's password.root
|
||||
logdb_type = test #
|
||||
logdb_host = test # The host to connect to. Values that start with / are for UNIX domain sockets.
|
||||
logdb_port = test # The port to bind to.
|
||||
logdb_name = test # The name of the database to connect to.
|
||||
logdb_user = test # The user to sign in as.
|
||||
logdb_passwd = test # The user's password.root
|
||||
|
||||
[balancer]
|
||||
enabled = true # Start balancer server
|
||||
listen = test # Balancer listen interface
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[rater]
|
||||
enabled = true
|
||||
listen = test # listening address host:port, internal for internal communication only
|
||||
balancer = test # if defined it will register to balancer as worker
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[mediator]
|
||||
enabled = true
|
||||
cdr_path = test # Freeswitch Master CSV CDR path.
|
||||
cdr_out_path = test
|
||||
rater = test #address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
skipdb = true
|
||||
pseudo_prepaid = true
|
||||
|
||||
[scheduler]
|
||||
enabled = true
|
||||
|
||||
[session_manager]
|
||||
enabled = true
|
||||
switch_type = test
|
||||
rater = test #address where to access rater. Can be internal, direct rater address or the address of a balancer
|
||||
debit_period = 11
|
||||
rpc_encoding = test # use JSON for RPC encoding
|
||||
|
||||
[freeswitch]
|
||||
server = test # freeswitch address host:port
|
||||
pass = test # freeswitch address host:port
|
||||
direction_index = test
|
||||
tor_index = test
|
||||
tenant_index = test
|
||||
subject_index = test
|
||||
account_index = test
|
||||
destination_index = test
|
||||
time_start_index = test
|
||||
duration_index = test
|
||||
uuid_index = test
|
||||
|
||||
Reference in New Issue
Block a user