本文整理汇总了Golang中github.com/cgrates/cgrates/config.SetCgrConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang SetCgrConfig函数的具体用法?Golang SetCgrConfig怎么用?Golang SetCgrConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetCgrConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestParseFsHangup
func TestParseFsHangup(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(hangupEv)
setupTime, _ := ev.GetSetupTime(utils.META_DEFAULT, "")
answerTime, _ := ev.GetAnswerTime(utils.META_DEFAULT, "")
dur, _ := ev.GetDuration(utils.META_DEFAULT)
if ev.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID ||
ev.GetDirection(utils.META_DEFAULT) != "*out" ||
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org" ||
ev.GetCategory(utils.META_DEFAULT) != "call" ||
ev.GetAccount(utils.META_DEFAULT) != "1001" ||
ev.GetSubject(utils.META_DEFAULT) != "1001" ||
ev.GetDestination(utils.META_DEFAULT) != "1003" ||
setupTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC) ||
answerTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC) ||
dur != time.Duration(66)*time.Second ||
ev.GetSupplier(utils.META_DEFAULT) != "supplier1" ||
ev.GetDisconnectCause(utils.META_DEFAULT) != "NORMAL_CLEARING" {
t.Error("Default values not matching",
ev.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID,
ev.GetDirection(utils.META_DEFAULT) != "*out",
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org",
ev.GetCategory(utils.META_DEFAULT) != "call",
ev.GetAccount(utils.META_DEFAULT) != "1001",
ev.GetSubject(utils.META_DEFAULT) != "1001",
ev.GetDestination(utils.META_DEFAULT) != "1003",
setupTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC),
answerTime.UTC() != time.Date(2015, 7, 7, 14, 52, 8, 0, time.UTC),
dur != time.Duration(66)*time.Second,
ev.GetSupplier(utils.META_DEFAULT) != "supplier1",
ev.GetDisconnectCause(utils.META_DEFAULT) != "NORMAL_CLEARING")
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:34,代码来源:fsevent_test.go
示例2: TestParseFsHangup
func TestParseFsHangup(t *testing.T) {
cfg, _ = config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).New(hangupEv)
setupTime, _ := ev.GetSetupTime(utils.META_DEFAULT)
answerTime, _ := ev.GetAnswerTime(utils.META_DEFAULT)
dur, _ := ev.GetDuration(utils.META_DEFAULT)
if ev.GetReqType(utils.META_DEFAULT) != utils.PSEUDOPREPAID ||
ev.GetDirection(utils.META_DEFAULT) != "*out" ||
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org" ||
ev.GetCategory(utils.META_DEFAULT) != "call" ||
ev.GetAccount(utils.META_DEFAULT) != "1003" ||
ev.GetSubject(utils.META_DEFAULT) != "1003" ||
ev.GetDestination(utils.META_DEFAULT) != "1002" ||
setupTime.UTC() != time.Date(2014, 4, 25, 16, 8, 27, 0, time.UTC) ||
answerTime.UTC() != time.Date(2014, 4, 25, 16, 8, 40, 0, time.UTC) ||
dur != time.Duration(5)*time.Second {
t.Error("Default values not matching",
ev.GetReqType(utils.META_DEFAULT) != utils.PSEUDOPREPAID,
ev.GetDirection(utils.META_DEFAULT) != "*out",
ev.GetTenant(utils.META_DEFAULT) != "cgrates.org",
ev.GetCategory(utils.META_DEFAULT) != "call",
ev.GetAccount(utils.META_DEFAULT) != "1003",
ev.GetSubject(utils.META_DEFAULT) != "1003",
ev.GetDestination(utils.META_DEFAULT) != "1002",
setupTime.UTC() != time.Date(2014, 4, 25, 17, 8, 27, 0, time.UTC),
answerTime.UTC() != time.Date(2014, 4, 25, 17, 8, 40, 0, time.UTC),
dur != time.Duration(5)*time.Second)
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:30,代码来源:fsevent_test.go
示例3: TestFsEvGetExtraFields
func TestFsEvGetExtraFields(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
cfg.SmFsConfig.ExtraFields = []*utils.RSRField{&utils.RSRField{Id: "Channel-Read-Codec-Name"}, &utils.RSRField{Id: "Channel-Write-Codec-Name"}, &utils.RSRField{Id: "NonExistingHeader"}}
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(hangupEv)
expectedExtraFields := map[string]string{"Channel-Read-Codec-Name": "SPEEX", "Channel-Write-Codec-Name": "SPEEX", "NonExistingHeader": ""}
if extraFields := ev.GetExtraFields(); !reflect.DeepEqual(expectedExtraFields, extraFields) {
t.Errorf("Expecting: %+v, received: %+v", expectedExtraFields, extraFields)
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:10,代码来源:fsevent_test.go
示例4: TestAuthSetStorage
func TestAuthSetStorage(t *testing.T) {
ratingDbAuth, _ = engine.NewMapStorageJson()
engine.SetRatingStorage(ratingDbAuth)
acntDbAuth, _ = engine.NewMapStorageJson()
engine.SetAccountingStorage(acntDbAuth)
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
rsponder = new(engine.Responder)
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:10,代码来源:auth_test.go
示例5: TestTutOsipsCallsInitCfg
func TestTutOsipsCallsInitCfg(t *testing.T) {
// Init config first
var err error
tutOsipsCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "tutorials", "osips_async", "cgrates", "etc", "cgrates"))
if err != nil {
t.Error(err)
}
tutOsipsCallsCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(tutOsipsCallsCfg)
}
开发者ID:cgrates,项目名称:cgrates,代码行数:10,代码来源:tutorial_osips_calls_test.go
示例6: TestTutSMGInitCfg
func TestTutSMGInitCfg(t *testing.T) {
tutSMGCfgPath = path.Join(*dataDir, "conf", "samples", "smgeneric")
// Init config first
var err error
tutSMGCfg, err = config.NewCGRConfigFromFolder(tutSMGCfgPath)
if err != nil {
t.Error(err)
}
tutSMGCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(tutSMGCfg)
}
开发者ID:cgrates,项目名称:cgrates,代码行数:11,代码来源:tut_smgeneric_it_test.go
示例7: TestActionsitInitCfg
func TestActionsitInitCfg(t *testing.T) {
// Init config first
var err error
actsLclCfg, err = config.NewCGRConfigFromFolder(actsLclCfgPath)
if err != nil {
t.Error(err)
}
actsLclCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(actsLclCfg)
}
开发者ID:cgrates,项目名称:cgrates,代码行数:11,代码来源:actions_it_test.go
示例8: TestDmtAgentInitCfg
func TestDmtAgentInitCfg(t *testing.T) {
daCfgPath = path.Join(*dataDir, "conf", "samples", "dmtagent")
// Init config first
var err error
daCfg, err = config.NewCGRConfigFromFolder(daCfgPath)
if err != nil {
t.Error(err)
}
daCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(daCfg)
rplyTimeout, _ = utils.ParseDurationWithSecs(*replyTimeout)
}
开发者ID:cgrates,项目名称:cgrates,代码行数:12,代码来源:dmtagent_it_test.go
示例9: TestTutAstCallsInitCfg
func TestTutAstCallsInitCfg(t *testing.T) {
if !*testCalls {
return
}
// Init config first
var err error
tutAstCallsCfg, err = config.NewCGRConfigFromFolder(path.Join(*dataDir, "tutorials", "asterisk_events", "cgrates", "etc", "cgrates"))
if err != nil {
t.Error(err)
}
tutAstCallsCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(tutAstCallsCfg)
}
开发者ID:eloycoto,项目名称:cgrates,代码行数:13,代码来源:tutorial_astevents_calls_test.go
示例10: TestSMGRplcInitCfg
func TestSMGRplcInitCfg(t *testing.T) {
smgRplcMasterCfgPath = path.Join(*dataDir, "conf", "samples", "smgreplcmaster")
if smgRplcMasterCfg, err = config.NewCGRConfigFromFolder(smgRplcMasterCfgPath); err != nil {
t.Fatal(err)
}
smgRplcMasterCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(smgRplcMasterCfg)
smgRplcSlaveCfgPath = path.Join(*dataDir, "conf", "samples", "smgreplcslave")
if smgRplcSlaveCfg, err = config.NewCGRConfigFromFolder(smgRplcSlaveCfgPath); err != nil {
t.Fatal(err)
}
}
开发者ID:cgrates,项目名称:cgrates,代码行数:13,代码来源:smgreplc_it_test.go
示例11: init
func init() {
if !*testLocal {
return
}
tutCfgPath = path.Join(*dataDir, "conf", "samples", "tutorial_local_test.cfg")
var err error
tutCfg, err = config.NewCGRConfigFromFile(&tutCfgPath)
if err != nil {
log.Print("ERROR: ", err)
}
tutCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(tutCfg)
}
开发者ID:intralanman,项目名称:cgrates,代码行数:13,代码来源:tutorial_local_test.go
示例12: TestOsipsEventGetValues
func TestOsipsEventGetValues(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
setupTime, _ := osipsEv.GetSetupTime(utils.META_DEFAULT, "")
eSetupTime, _ := utils.ParseTimeDetectLayout("1406370492", "")
answerTime, _ := osipsEv.GetAnswerTime(utils.META_DEFAULT, "")
eAnswerTime, _ := utils.ParseTimeDetectLayout("1406370499", "")
dur, _ := osipsEv.GetDuration(utils.META_DEFAULT)
pdd, _ := osipsEv.GetPdd(utils.META_DEFAULT)
endTime, _ := osipsEv.GetEndTime(utils.META_DEFAULT, "")
if osipsEv.GetName() != "E_ACC_CDR" ||
osipsEv.GetCgrId("") != utils.Sha1("ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ", setupTime.UTC().String()) ||
osipsEv.GetUUID() != "ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ" ||
osipsEv.GetDirection(utils.META_DEFAULT) != utils.OUT ||
osipsEv.GetSubject(utils.META_DEFAULT) != "dan" ||
osipsEv.GetAccount(utils.META_DEFAULT) != "dan" ||
osipsEv.GetDestination(utils.META_DEFAULT) != "+4986517174963" ||
osipsEv.GetCallDestNr(utils.META_DEFAULT) != "+4986517174963" ||
osipsEv.GetCategory(utils.META_DEFAULT) != cfg.DefaultCategory ||
osipsEv.GetTenant(utils.META_DEFAULT) != "itsyscom.com" ||
osipsEv.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID ||
!setupTime.Equal(eSetupTime) ||
!answerTime.Equal(eAnswerTime) ||
!endTime.Equal(eAnswerTime.Add(dur)) ||
dur != time.Duration(20*time.Second) ||
pdd != time.Duration(3)*time.Second ||
osipsEv.GetSupplier(utils.META_DEFAULT) != "supplier3" ||
osipsEv.GetDisconnectCause(utils.META_DEFAULT) != "200" ||
osipsEv.GetOriginatorIP(utils.META_DEFAULT) != "172.16.254.77" {
t.Error("GetValues not matching: ", osipsEv.GetName() != "E_ACC_CDR",
osipsEv.GetCgrId("") != utils.Sha1("ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ", setupTime.UTC().String()),
osipsEv.GetUUID() != "ODVkMDI2Mzc2MDY5N2EzODhjNTAzNTdlODhiZjRlYWQ",
osipsEv.GetDirection(utils.META_DEFAULT) != utils.OUT,
osipsEv.GetSubject(utils.META_DEFAULT) != "dan",
osipsEv.GetAccount(utils.META_DEFAULT) != "dan",
osipsEv.GetDestination(utils.META_DEFAULT) != "+4986517174963",
osipsEv.GetCallDestNr(utils.META_DEFAULT) != "+4986517174963",
osipsEv.GetCategory(utils.META_DEFAULT) != cfg.DefaultCategory,
osipsEv.GetTenant(utils.META_DEFAULT) != "itsyscom.com",
osipsEv.GetReqType(utils.META_DEFAULT) != utils.META_PREPAID,
!setupTime.Equal(time.Date(2014, 7, 26, 12, 28, 12, 0, time.UTC)),
!answerTime.Equal(time.Date(2014, 7, 26, 12, 28, 19, 0, time.Local)),
!endTime.Equal(time.Date(2014, 7, 26, 12, 28, 39, 0, time.Local)),
dur != time.Duration(20*time.Second),
pdd != time.Duration(3)*time.Second,
osipsEv.GetSupplier(utils.META_DEFAULT) != "supplier3",
osipsEv.GetDisconnectCause(utils.META_DEFAULT) != "200",
osipsEv.GetOriginatorIP(utils.META_DEFAULT) != "172.16.254.77",
)
}
}
开发者ID:kevinlovesing,项目名称:cgrates,代码行数:51,代码来源:osipsevent_test.go
示例13: TestEventSelectiveHeaders
// Test here if the answer is selected out of headers we specify, even if not default defined
func TestEventSelectiveHeaders(t *testing.T) {
body := `Event-Name: RE_SCHEDULE
Core-UUID: 792e181c-b6e6-499c-82a1-52a778e7d82d
FreeSWITCH-Hostname: h1.ip-switch.net
FreeSWITCH-Switchname: h1.ip-switch.net
FreeSWITCH-IPv4: 88.198.12.156
FreeSWITCH-IPv6: %3A%3A1
Event-Date-Local: 2012-10-05%2013%3A41%3A38
Event-Date-GMT: Fri,%2005%20Oct%202012%2011%3A41%3A38%20GMT
Event-Date-Timestamp: 1349437298012866
Event-Calling-File: switch_scheduler.c
Event-Calling-Function: switch_scheduler_execute
Event-Calling-Line-Number: 65
Event-Sequence: 34263
Task-ID: 2
Task-Desc: heartbeat
Task-Group: core
Task-Runtime: 1349437318`
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(body)
setupTime, _ := ev.GetSetupTime("Event-Date-Local", "")
answerTime, _ := ev.GetAnswerTime("Event-Date-Local", "")
dur, _ := ev.GetDuration("Event-Calling-Line-Number")
if ev.GetReqType("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetDirection("FreeSWITCH-Hostname") != "*out" ||
ev.GetTenant("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetCategory("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetAccount("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetSubject("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetDestination("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
setupTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC) ||
answerTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC) ||
dur != time.Duration(65)*time.Second ||
ev.GetSupplier("FreeSWITCH-Hostname") != "h1.ip-switch.net" ||
ev.GetDisconnectCause("FreeSWITCH-Hostname") != "h1.ip-switch.net" {
t.Error("Values out of static not matching",
ev.GetReqType("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetDirection("FreeSWITCH-Hostname") != "*out",
ev.GetTenant("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetCategory("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetAccount("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetSubject("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetDestination("FreeSWITCH-Hostname") != "h1.ip-switch.net",
setupTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC),
answerTime != time.Date(2012, 10, 5, 13, 41, 38, 0, time.UTC),
dur != time.Duration(65)*time.Second,
ev.GetSupplier("FreeSWITCH-Hostname") != "h1.ip-switch.net",
ev.GetDisconnectCause("FreeSWITCH-Hostname") != "h1.ip-switch.net")
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:52,代码来源:fsevent_test.go
示例14: TestSMGInitCfg
func TestSMGInitCfg(t *testing.T) {
if !*testIntegration {
return
}
daCfgPath = path.Join(*dataDir, "conf", "samples", "smg")
// Init config first
var err error
daCfg, err = config.NewCGRConfigFromFolder(daCfgPath)
if err != nil {
t.Error(err)
}
daCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(daCfg)
}
开发者ID:bhepp,项目名称:cgrates,代码行数:14,代码来源:smg_it_test.go
示例15: TestTutLocalInitCfg
func TestTutLocalInitCfg(t *testing.T) {
if !*testLocal {
return
}
tutLocalCfgPath = path.Join(*dataDir, "conf", "samples", "tutlocal")
// Init config first
var err error
tutFsLocalCfg, err = config.NewCGRConfigFromFolder(tutLocalCfgPath)
if err != nil {
t.Error(err)
}
tutFsLocalCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
config.SetCgrConfig(tutFsLocalCfg)
}
开发者ID:nikbyte,项目名称:cgrates,代码行数:14,代码来源:tutorial_local_test.go
示例16: TestFsEvAsStoredCdr
func TestFsEvAsStoredCdr(t *testing.T) {
cfg, _ = config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).New(hangupEv)
setupTime, _ := utils.ParseTimeDetectLayout("1398442107")
aTime, _ := utils.ParseTimeDetectLayout("1398442120")
eStoredCdr := &utils.StoredCdr{CgrId: utils.Sha1("37e9b766-5256-4e4b-b1ed-3767b930fec8", setupTime.UTC().String()),
TOR: utils.VOICE, AccId: "37e9b766-5256-4e4b-b1ed-3767b930fec8", CdrHost: "10.0.2.15", CdrSource: "FS_CHANNEL_HANGUP_COMPLETE", ReqType: utils.PSEUDOPREPAID,
Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003",
Destination: "1002", SetupTime: setupTime, AnswerTime: aTime,
Usage: time.Duration(5) * time.Second, ExtraFields: make(map[string]string), Cost: -1}
if storedCdr := ev.AsStoredCdr(); !reflect.DeepEqual(eStoredCdr, storedCdr) {
t.Errorf("Expecting: %+v, received: %+v", eStoredCdr, storedCdr)
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:15,代码来源:fsevent_test.go
示例17: TestFsEvAsStoredCdr
func TestFsEvAsStoredCdr(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(hangupEv)
setupTime, _ := utils.ParseTimeDetectLayout("1436280728", "")
aTime, _ := utils.ParseTimeDetectLayout("1436280728", "")
eStoredCdr := &engine.StoredCdr{CgrId: "164b0422fdc6a5117031b427439482c6a4f90e41",
TOR: utils.VOICE, AccId: "e3133bf7-dcde-4daf-9663-9a79ffcef5ad", CdrHost: "10.0.3.15", CdrSource: "FS_CHANNEL_HANGUP_COMPLETE", ReqType: utils.META_PREPAID,
Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001",
Destination: "1003", SetupTime: setupTime, AnswerTime: aTime,
Usage: time.Duration(66) * time.Second, Pdd: time.Duration(28) * time.Millisecond, Supplier: "supplier1", DisconnectCause: "NORMAL_CLEARING", ExtraFields: make(map[string]string), Cost: -1}
if storedCdr := ev.AsStoredCdr(""); !reflect.DeepEqual(eStoredCdr, storedCdr) {
t.Errorf("Expecting: %+v, received: %+v", eStoredCdr, storedCdr)
}
}
开发者ID:gale320,项目名称:cgrates,代码行数:15,代码来源:fsevent_test.go
示例18: TestResponderGetDerivedChargers
// Test internal abilites of GetDerivedChargers
func TestResponderGetDerivedChargers(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
cfgedDC := utils.DerivedChargers{&utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", UsageField: "test"}}
cfg.DerivedChargers = cfgedDC
config.SetCgrConfig(cfg)
r := Responder{}
attrs := utils.AttrDerivedChargers{Tenant: "cgrates.org", Category: "call", Direction: "*out", Account: "responder_test", Subject: "responder_test"}
var dcs utils.DerivedChargers
if err := r.GetDerivedChargers(attrs, &dcs); err != nil {
t.Error("Unexpected error", err.Error())
} else if !reflect.DeepEqual(dcs, cfgedDC) {
t.Errorf("Expecting: %v, received: %v ", cfgedDC, dcs)
}
}
开发者ID:intralanman,项目名称:cgrates,代码行数:16,代码来源:responder_test.go
示例19: main
func main() {
flag.Parse()
if *version {
fmt.Println("CGRateS " + utils.VERSION)
return
}
if *pidFile != "" {
writePid()
}
if *singlecpu {
runtime.GOMAXPROCS(1) // Having multiple cpus slows down computing due to CPU management, to be reviewed in future Go releases
}
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
cfg, err = config.NewCGRConfigFromFolder(*cfgDir)
if err != nil {
utils.Logger.Crit(fmt.Sprintf("Could not parse config: %s exiting!", err))
return
}
config.SetCgrConfig(cfg) // Share the config object
if *raterEnabled {
cfg.RaterEnabled = *raterEnabled
}
if *schedEnabled {
cfg.SchedulerEnabled = *schedEnabled
}
if *cdrsEnabled {
cfg.CDRSEnabled = *cdrsEnabled
}
var ratingDb engine.RatingStorage
var accountDb engine.AccountingStorage
var logDb engine.LogStorage
var loadDb engine.LoadStorage
var cdrDb engine.CdrStorage
if cfg.RaterEnabled || cfg.SchedulerEnabled { // Only connect to dataDb if necessary
ratingDb, err = engine.ConfigureRatingStorage(cfg.TpDbType, cfg.TpDbHost, cfg.TpDbPort,
cfg.TpDbName, cfg.TpDbUser, cfg.TpDbPass, cfg.DBDataEncoding)
if err != nil { // Cannot configure getter database, show stopper
utils.Logger.Crit(fmt.Sprintf("Could not configure dataDb: %s exiting!", err))
return
}
defer ratingDb.Close()
engine.SetRatingStorage(ratingDb)
accountDb, err = engine.ConfigureAccountingStorage(cfg.DataDbType, cfg.DataDbHost, cfg.DataDbPort,
cfg.DataDbName, cfg.DataDbUser, cfg.DataDbPass, cfg.DBDataEncoding)
if err != nil { // Cannot configure getter database, show stopper
utils.Logger.Crit(fmt.Sprintf("Could not configure dataDb: %s exiting!", err))
return
}
defer accountDb.Close()
engine.SetAccountingStorage(accountDb)
}
if cfg.RaterEnabled || cfg.CDRSEnabled || cfg.SchedulerEnabled { // Only connect to storDb if necessary
logDb, err = engine.ConfigureLogStorage(cfg.StorDBType, cfg.StorDBHost, cfg.StorDBPort,
cfg.StorDBName, cfg.StorDBUser, cfg.StorDBPass, cfg.DBDataEncoding, cfg.StorDBMaxOpenConns, cfg.StorDBMaxIdleConns)
if err != nil { // Cannot configure logger database, show stopper
utils.Logger.Crit(fmt.Sprintf("Could not configure logger database: %s exiting!", err))
return
}
defer logDb.Close()
engine.SetStorageLogger(logDb)
// loadDb,cdrDb and logDb are all mapped on the same stordb storage
loadDb = logDb.(engine.LoadStorage)
cdrDb = logDb.(engine.CdrStorage)
engine.SetCdrStorage(cdrDb)
}
engine.SetRoundingDecimals(cfg.RoundingDecimals)
stopHandled := false
// Rpc/http server
server := new(engine.Server)
// Async starts here, will follow cgrates.json start order
exitChan := make(chan bool)
// Define internal connections via channels
internalBalancerChan := make(chan *balancer2go.Balancer, 1)
internalRaterChan := make(chan *engine.Responder, 1)
internalSchedulerChan := make(chan *scheduler.Scheduler, 1)
internalCdrSChan := make(chan *engine.CdrServer, 1)
internalCdrStatSChan := make(chan engine.StatsInterface, 1)
internalHistorySChan := make(chan history.Scribe, 1)
internalPubSubSChan := make(chan engine.PublisherSubscriber, 1)
internalUserSChan := make(chan engine.UserService, 1)
internalAliaseSChan := make(chan engine.AliasService, 1)
// Start balancer service
if cfg.BalancerEnabled {
go startBalancer(internalBalancerChan, &stopHandled, exitChan) // Not really needed async here but to cope with uniformity
}
// Start rater service
if cfg.RaterEnabled {
//.........这里部分代码省略.........
开发者ID:henrylee2cn,项目名称:cgrates,代码行数:101,代码来源:cgr-engine.go
示例20: TestParseEventValue
func TestParseEventValue(t *testing.T) {
cfg, _ := config.NewDefaultCGRConfig()
config.SetCgrConfig(cfg)
ev := new(FSEvent).AsEvent(hangupEv)
if cgrid := ev.ParseEventValue(&utils.RSRField{Id: utils.CGRID}, ""); cgrid != "164b0422fdc6a5117031b427439482c6a4f90e41" {
t.Error("Unexpected cgrid parsed", cgrid)
}
if tor := ev.ParseEventValue(&utils.RSRField{Id: utils.TOR}, ""); tor != utils.VOICE {
t.Error("Unexpected tor parsed", tor)
}
if accid := ev.ParseEventValue(&utils.RSRField{Id: utils.ACCID}, ""); accid != "e3133bf7-dcde-4daf-9663-9a79ffcef5ad" {
t.Error("Unexpected result parsed", accid)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.CDRHOST}, ""); parsed != "10.0.3.15" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.CDRSOURCE}, ""); parsed != "FS_EVENT" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.REQTYPE}, ""); parsed != utils.META_PREPAID {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.DIRECTION}, ""); parsed != utils.OUT {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.TENANT}, ""); parsed != "cgrates.org" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.CATEGORY}, ""); parsed != "call" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.ACCOUNT}, ""); parsed != "1001" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.SUBJECT}, ""); parsed != "1001" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.DESTINATION}, ""); parsed != "1003" {
t.Error("Unexpected result parsed", parsed)
}
sTime, _ := utils.ParseTimeDetectLayout("1436280728471153"[:len("1436280728471153")-6], "") // We discard nanoseconds information so we can correlate csv
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.SETUP_TIME}, ""); parsed != sTime.String() {
t.Errorf("Expecting: %s, parsed: %s", sTime.String(), parsed)
}
aTime, _ := utils.ParseTimeDetectLayout("1436280728971147"[:len("1436280728971147")-6], "")
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.ANSWER_TIME}, ""); parsed != aTime.String() {
t.Errorf("Expecting: %s, parsed: %s", aTime.String(), parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.USAGE}, ""); parsed != "66000000000" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.PDD}, ""); parsed != "0.028" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.SUPPLIER}, ""); parsed != "supplier1" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.MEDI_RUNID}, ""); parsed != utils.DEFAULT_RUNID {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: utils.COST}, ""); parsed != "-1" {
t.Error("Unexpected result parsed", parsed)
}
if parsed := ev.ParseEventValue(&utils.RSRField{Id: "Hangup-Cause"}, ""); parsed != "NORMAL_CLEARING" {
t.Error("Unexpected result parsed", parsed)
}
}
开发者ID:bhepp,项目名称:cgrates,代码行数:67,代码来源:fsevent_test.go
注:本文中的github.com/cgrates/cgrates/config.SetCgrConfig函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论