mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added tests for loadercgrcfg, migratorcfg,supplierscfg and thresholdscfg
This commit is contained in:
committed by
Dan Christian Bogos
parent
9b17e5024a
commit
917710642b
@@ -69,9 +69,9 @@ var (
|
||||
|
||||
flush = flag.Bool("flushdb", false,
|
||||
"Flush the database before importing")
|
||||
tpid = flag.String("tpid", dfltCfg.LoaderCgrConfig.TpID,
|
||||
tpid = flag.String("tpid", dfltCfg.LoaderCgrCfg().TpID,
|
||||
"The tariff plan ID from the database")
|
||||
dataPath = flag.String("path", dfltCfg.LoaderCgrConfig.DataPath,
|
||||
dataPath = flag.String("path", dfltCfg.LoaderCgrCfg().DataPath,
|
||||
"The path to folder containing the data files")
|
||||
version = flag.Bool("version", false,
|
||||
"Prints the application version.")
|
||||
@@ -83,9 +83,9 @@ var (
|
||||
fromStorDB = flag.Bool("from_stordb", false, "Load the tariff plan from storDb to dataDb")
|
||||
toStorDB = flag.Bool("to_stordb", false, "Import the tariff plan from files to storDb")
|
||||
rpcEncoding = flag.String("rpc_encoding", utils.MetaJSONrpc, "RPC encoding used <gob|json>")
|
||||
cacheSAddress = flag.String("caches_address", dfltCfg.LoaderCgrConfig.CachesConns[0].Address,
|
||||
cacheSAddress = flag.String("caches_address", dfltCfg.LoaderCgrCfg().CachesConns[0].Address,
|
||||
"CacheS component to contact for cache reloads, empty to disable automatic cache reloads")
|
||||
schedulerAddress = flag.String("scheduler_address", dfltCfg.LoaderCgrConfig.SchedulerConns[0].Address, "")
|
||||
schedulerAddress = flag.String("scheduler_address", dfltCfg.LoaderCgrCfg().SchedulerConns[0].Address, "")
|
||||
|
||||
importID = flag.String("import_id", "", "Uniquely identify an import/load, postpended to some automatic fields")
|
||||
timezone = flag.String("timezone", "", `Timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB>`)
|
||||
@@ -173,32 +173,32 @@ func main() {
|
||||
}
|
||||
|
||||
if *tpid != "" {
|
||||
ldrCfg.LoaderCgrConfig.TpID = *tpid
|
||||
ldrCfg.LoaderCgrCfg().TpID = *tpid
|
||||
}
|
||||
|
||||
if *dataPath != "" {
|
||||
ldrCfg.LoaderCgrConfig.DataPath = *dataPath
|
||||
ldrCfg.LoaderCgrCfg().DataPath = *dataPath
|
||||
}
|
||||
|
||||
if *cacheSAddress != dfltCfg.LoaderCgrConfig.CachesConns[0].Address {
|
||||
ldrCfg.LoaderCgrConfig.CachesConns = make([]*config.HaPoolConfig, 0)
|
||||
if *cacheSAddress != dfltCfg.LoaderCgrCfg().CachesConns[0].Address {
|
||||
ldrCfg.LoaderCgrCfg().CachesConns = make([]*config.HaPoolConfig, 0)
|
||||
if *cacheSAddress != "" {
|
||||
ldrCfg.LoaderCgrConfig.CachesConns = append(ldrCfg.LoaderCgrConfig.CachesConns,
|
||||
ldrCfg.LoaderCgrCfg().CachesConns = append(ldrCfg.LoaderCgrCfg().CachesConns,
|
||||
&config.HaPoolConfig{Address: *cacheSAddress})
|
||||
}
|
||||
}
|
||||
|
||||
if *schedulerAddress != dfltCfg.LoaderCgrConfig.SchedulerConns[0].Address {
|
||||
ldrCfg.LoaderCgrConfig.SchedulerConns = make([]*config.HaPoolConfig, 0)
|
||||
if *schedulerAddress != dfltCfg.LoaderCgrCfg().SchedulerConns[0].Address {
|
||||
ldrCfg.LoaderCgrCfg().SchedulerConns = make([]*config.HaPoolConfig, 0)
|
||||
if *schedulerAddress != "" {
|
||||
ldrCfg.LoaderCgrConfig.SchedulerConns = append(ldrCfg.LoaderCgrConfig.SchedulerConns,
|
||||
ldrCfg.LoaderCgrCfg().SchedulerConns = append(ldrCfg.LoaderCgrCfg().SchedulerConns,
|
||||
&config.HaPoolConfig{Address: *schedulerAddress})
|
||||
}
|
||||
}
|
||||
|
||||
if *rpcEncoding != dfltCfg.LoaderCgrConfig.CachesConns[0].Transport &&
|
||||
len(ldrCfg.LoaderCgrConfig.CachesConns) != 0 {
|
||||
ldrCfg.LoaderCgrConfig.CachesConns[0].Transport = *rpcEncoding
|
||||
if *rpcEncoding != dfltCfg.LoaderCgrCfg().CachesConns[0].Transport &&
|
||||
len(ldrCfg.LoaderCgrCfg().CachesConns) != 0 {
|
||||
ldrCfg.LoaderCgrCfg().CachesConns[0].Transport = *rpcEncoding
|
||||
}
|
||||
|
||||
if *importID == "" {
|
||||
@@ -209,8 +209,8 @@ func main() {
|
||||
ldrCfg.GeneralCfg().DefaultTimezone = *timezone
|
||||
}
|
||||
|
||||
if *disableReverse != dfltCfg.LoaderCgrConfig.DisableReverse {
|
||||
ldrCfg.LoaderCgrConfig.DisableReverse = *disableReverse
|
||||
if *disableReverse != dfltCfg.LoaderCgrCfg().DisableReverse {
|
||||
ldrCfg.LoaderCgrCfg().DisableReverse = *disableReverse
|
||||
}
|
||||
|
||||
if !*toStorDB {
|
||||
@@ -241,16 +241,16 @@ func main() {
|
||||
if !*dryRun {
|
||||
//tpid_remove
|
||||
if *toStorDB { // Import files from a directory into storDb
|
||||
if ldrCfg.LoaderCgrConfig.TpID == "" {
|
||||
if ldrCfg.LoaderCgrCfg().TpID == "" {
|
||||
log.Fatal("TPid required.")
|
||||
}
|
||||
if *flushStorDB {
|
||||
if err = storDb.RemTpData("", ldrCfg.LoaderCgrConfig.TpID, map[string]string{}); err != nil {
|
||||
if err = storDb.RemTpData("", ldrCfg.LoaderCgrCfg().TpID, map[string]string{}); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
csvImporter := engine.TPCSVImporter{
|
||||
TPid: ldrCfg.LoaderCgrConfig.TpID,
|
||||
TPid: ldrCfg.LoaderCgrCfg().TpID,
|
||||
StorDb: storDb,
|
||||
DirPath: *dataPath,
|
||||
Sep: ',',
|
||||
@@ -295,7 +295,7 @@ func main() {
|
||||
}
|
||||
|
||||
tpReader := engine.NewTpReader(dm.DataDB(), loader,
|
||||
ldrCfg.LoaderCgrConfig.TpID, ldrCfg.GeneralCfg().DefaultTimezone)
|
||||
ldrCfg.LoaderCgrCfg().TpID, ldrCfg.GeneralCfg().DefaultTimezone)
|
||||
|
||||
if err = tpReader.LoadAll(); err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -304,13 +304,13 @@ func main() {
|
||||
if *dryRun { // We were just asked to parse the data, not saving it
|
||||
return
|
||||
}
|
||||
if len(ldrCfg.LoaderCgrConfig.CachesConns) != 0 { // Init connection to CacheS so we can reload it's data
|
||||
if len(ldrCfg.LoaderCgrCfg().CachesConns) != 0 { // Init connection to CacheS so we can reload it's data
|
||||
if cacheS, err = rpcclient.NewRpcClient("tcp",
|
||||
ldrCfg.LoaderCgrConfig.CachesConns[0].Address,
|
||||
ldrCfg.LoaderCgrConfig.CachesConns[0].Tls, ldrCfg.TlsCfg().ClientKey,
|
||||
ldrCfg.LoaderCgrCfg().CachesConns[0].Address,
|
||||
ldrCfg.LoaderCgrCfg().CachesConns[0].Tls, ldrCfg.TlsCfg().ClientKey,
|
||||
ldrCfg.TlsCfg().ClientCerificate, ldrCfg.TlsCfg().CaCertificate, 3, 3,
|
||||
time.Duration(1*time.Second), time.Duration(5*time.Minute),
|
||||
strings.TrimPrefix(ldrCfg.LoaderCgrConfig.CachesConns[0].Transport, utils.Meta),
|
||||
strings.TrimPrefix(ldrCfg.LoaderCgrCfg().CachesConns[0].Transport, utils.Meta),
|
||||
nil, false); err != nil {
|
||||
log.Fatalf("Could not connect to CacheS: %s", err.Error())
|
||||
return
|
||||
@@ -321,12 +321,12 @@ func main() {
|
||||
|
||||
// FixMe: remove users reloading as soon as not longer supported
|
||||
if *usersAddress != "" { // Init connection to rater so we can reload it's data
|
||||
if len(ldrCfg.LoaderCgrConfig.CachesConns) != 0 &&
|
||||
*usersAddress == ldrCfg.LoaderCgrConfig.CachesConns[0].Address {
|
||||
if len(ldrCfg.LoaderCgrCfg().CachesConns) != 0 &&
|
||||
*usersAddress == ldrCfg.LoaderCgrCfg().CachesConns[0].Address {
|
||||
userS = cacheS
|
||||
} else {
|
||||
if userS, err = rpcclient.NewRpcClient("tcp", *usersAddress,
|
||||
ldrCfg.LoaderCgrConfig.CachesConns[0].Tls,
|
||||
ldrCfg.LoaderCgrCfg().CachesConns[0].Tls,
|
||||
ldrCfg.TlsCfg().ClientKey, ldrCfg.TlsCfg().ClientCerificate,
|
||||
ldrCfg.TlsCfg().CaCertificate, 3, 3,
|
||||
time.Duration(1*time.Second), time.Duration(5*time.Minute),
|
||||
|
||||
@@ -149,68 +149,68 @@ func main() {
|
||||
|
||||
// outDataDB
|
||||
if *outDataDBType == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBType == mgrCfg.MigratorCgrConfig.OutDataDBType {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBType = mgrCfg.DataDbCfg().DataDbType
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBType == mgrCfg.MigratorCgrCfg().OutDataDBType {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBType = mgrCfg.DataDbCfg().DataDbType
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBType = strings.TrimPrefix(*outDataDBType, "*")
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBType = strings.TrimPrefix(*outDataDBType, "*")
|
||||
}
|
||||
|
||||
if *outDataDBHost == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBHost == mgrCfg.MigratorCgrConfig.OutDataDBHost {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBHost = mgrCfg.DataDbCfg().DataDbHost
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBHost == mgrCfg.MigratorCgrCfg().OutDataDBHost {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBHost = mgrCfg.DataDbCfg().DataDbHost
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBHost = *outDataDBHost
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBHost = *outDataDBHost
|
||||
}
|
||||
if *outDataDBPort == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBPort == mgrCfg.MigratorCgrConfig.OutDataDBPort {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBPort = mgrCfg.DataDbCfg().DataDbPort
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBPort == mgrCfg.MigratorCgrCfg().OutDataDBPort {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBPort = mgrCfg.DataDbCfg().DataDbPort
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBPort = *outDataDBPort
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBPort = *outDataDBPort
|
||||
}
|
||||
if *outDataDBName == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBName == mgrCfg.MigratorCgrConfig.OutDataDBName {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBName = mgrCfg.DataDbCfg().DataDbName
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBName == mgrCfg.MigratorCgrCfg().OutDataDBName {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBName = mgrCfg.DataDbCfg().DataDbName
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBName = *outDataDBName
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBName = *outDataDBName
|
||||
}
|
||||
if *outDataDBUser == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBUser == mgrCfg.MigratorCgrConfig.OutDataDBUser {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBUser = mgrCfg.DataDbCfg().DataDbUser
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBUser == mgrCfg.MigratorCgrCfg().OutDataDBUser {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBUser = mgrCfg.DataDbCfg().DataDbUser
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBUser = *outDataDBUser
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBUser = *outDataDBUser
|
||||
}
|
||||
if *outDataDBPass == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBPassword == mgrCfg.MigratorCgrConfig.OutDataDBPassword {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBPassword = mgrCfg.DataDbCfg().DataDbPass
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBPassword == mgrCfg.MigratorCgrCfg().OutDataDBPassword {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBPassword = mgrCfg.DataDbCfg().DataDbPass
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBPassword = *outDataDBPass
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBPassword = *outDataDBPass
|
||||
}
|
||||
if *outDBDataEncoding == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBEncoding == mgrCfg.MigratorCgrConfig.OutDataDBEncoding {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBEncoding = mgrCfg.GeneralCfg().DBDataEncoding
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBEncoding == mgrCfg.MigratorCgrCfg().OutDataDBEncoding {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBEncoding = mgrCfg.GeneralCfg().DBDataEncoding
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBEncoding = *outDBDataEncoding
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBEncoding = *outDBDataEncoding
|
||||
}
|
||||
if *outDataDBRedisSentinel == utils.MetaDataDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutDataDBRedisSentinel == mgrCfg.MigratorCgrConfig.OutDataDBRedisSentinel {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBRedisSentinel = mgrCfg.DataDbCfg().DataDbSentinelName
|
||||
if dfltCfg.MigratorCgrCfg().OutDataDBRedisSentinel == mgrCfg.MigratorCgrCfg().OutDataDBRedisSentinel {
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBRedisSentinel = mgrCfg.DataDbCfg().DataDbSentinelName
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBRedisSentinel = *outDataDBRedisSentinel
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBRedisSentinel = *outDataDBRedisSentinel
|
||||
}
|
||||
|
||||
sameDataDB = mgrCfg.MigratorCgrConfig.OutDataDBType == mgrCfg.DataDbCfg().DataDbType &&
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBHost == mgrCfg.DataDbCfg().DataDbHost &&
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBPort == mgrCfg.DataDbCfg().DataDbPort &&
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBName == mgrCfg.DataDbCfg().DataDbName &&
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBEncoding == mgrCfg.GeneralCfg().DBDataEncoding
|
||||
sameDataDB = mgrCfg.MigratorCgrCfg().OutDataDBType == mgrCfg.DataDbCfg().DataDbType &&
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBHost == mgrCfg.DataDbCfg().DataDbHost &&
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBPort == mgrCfg.DataDbCfg().DataDbPort &&
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBName == mgrCfg.DataDbCfg().DataDbName &&
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBEncoding == mgrCfg.GeneralCfg().DBDataEncoding
|
||||
|
||||
if dmIN, err = migrator.NewMigratorDataDB(mgrCfg.DataDbCfg().DataDbType,
|
||||
mgrCfg.DataDbCfg().DataDbHost, mgrCfg.DataDbCfg().DataDbPort,
|
||||
@@ -222,11 +222,11 @@ func main() {
|
||||
|
||||
if sameDataDB {
|
||||
dmOUT = dmIN
|
||||
} else if dmOUT, err = migrator.NewMigratorDataDB(mgrCfg.MigratorCgrConfig.OutDataDBType,
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBHost, mgrCfg.MigratorCgrConfig.OutDataDBPort,
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBName, mgrCfg.MigratorCgrConfig.OutDataDBUser,
|
||||
mgrCfg.MigratorCgrConfig.OutDataDBPassword, mgrCfg.MigratorCgrConfig.OutDataDBEncoding,
|
||||
mgrCfg.CacheCfg(), mgrCfg.MigratorCgrConfig.OutDataDBRedisSentinel); err != nil {
|
||||
} else if dmOUT, err = migrator.NewMigratorDataDB(mgrCfg.MigratorCgrCfg().OutDataDBType,
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBHost, mgrCfg.MigratorCgrCfg().OutDataDBPort,
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBName, mgrCfg.MigratorCgrCfg().OutDataDBUser,
|
||||
mgrCfg.MigratorCgrCfg().OutDataDBPassword, mgrCfg.MigratorCgrCfg().OutDataDBEncoding,
|
||||
mgrCfg.CacheCfg(), mgrCfg.MigratorCgrCfg().OutDataDBRedisSentinel); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -252,52 +252,52 @@ func main() {
|
||||
|
||||
// outStorDB
|
||||
if *outStorDBType == utils.MetaStorDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutStorDBType == mgrCfg.MigratorCgrConfig.OutStorDBType {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBType = mgrCfg.StorDbCfg().StorDBType
|
||||
if dfltCfg.MigratorCgrCfg().OutStorDBType == mgrCfg.MigratorCgrCfg().OutStorDBType {
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBType = mgrCfg.StorDbCfg().StorDBType
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBType = strings.TrimPrefix(*outStorDBType, "*")
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBType = strings.TrimPrefix(*outStorDBType, "*")
|
||||
}
|
||||
if *outStorDBHost == utils.MetaStorDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutStorDBHost == mgrCfg.MigratorCgrConfig.OutStorDBHost {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBHost = mgrCfg.StorDbCfg().StorDBHost
|
||||
if dfltCfg.MigratorCgrCfg().OutStorDBHost == mgrCfg.MigratorCgrCfg().OutStorDBHost {
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBHost = mgrCfg.StorDbCfg().StorDBHost
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBHost = *outStorDBHost
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBHost = *outStorDBHost
|
||||
}
|
||||
if *outStorDBPort == utils.MetaStorDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutStorDBPort == mgrCfg.MigratorCgrConfig.OutStorDBPort {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBPort = mgrCfg.StorDbCfg().StorDBPort
|
||||
if dfltCfg.MigratorCgrCfg().OutStorDBPort == mgrCfg.MigratorCgrCfg().OutStorDBPort {
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBPort = mgrCfg.StorDbCfg().StorDBPort
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBPort = *outStorDBPort
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBPort = *outStorDBPort
|
||||
}
|
||||
if *outStorDBName == utils.MetaStorDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutStorDBName == mgrCfg.MigratorCgrConfig.OutStorDBName {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBName = mgrCfg.StorDbCfg().StorDBName
|
||||
if dfltCfg.MigratorCgrCfg().OutStorDBName == mgrCfg.MigratorCgrCfg().OutStorDBName {
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBName = mgrCfg.StorDbCfg().StorDBName
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBName = *outStorDBName
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBName = *outStorDBName
|
||||
}
|
||||
if *outStorDBUser == utils.MetaStorDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutStorDBUser == mgrCfg.MigratorCgrConfig.OutStorDBUser {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBUser = mgrCfg.StorDbCfg().StorDBUser
|
||||
if dfltCfg.MigratorCgrCfg().OutStorDBUser == mgrCfg.MigratorCgrCfg().OutStorDBUser {
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBUser = mgrCfg.StorDbCfg().StorDBUser
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBUser = *outStorDBUser
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBUser = *outStorDBUser
|
||||
}
|
||||
if *outStorDBPass == utils.MetaStorDB {
|
||||
if dfltCfg.MigratorCgrConfig.OutStorDBPassword == mgrCfg.MigratorCgrConfig.OutStorDBPassword {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBPassword = mgrCfg.StorDbCfg().StorDBPass
|
||||
if dfltCfg.MigratorCgrCfg().OutStorDBPassword == mgrCfg.MigratorCgrCfg().OutStorDBPassword {
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBPassword = mgrCfg.StorDbCfg().StorDBPass
|
||||
}
|
||||
} else {
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBPassword = *outStorDBPass
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBPassword = *outStorDBPass
|
||||
}
|
||||
|
||||
sameStorDB = mgrCfg.MigratorCgrConfig.OutStorDBType == mgrCfg.StorDbCfg().StorDBType &&
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBHost == mgrCfg.StorDbCfg().StorDBHost &&
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBPort == mgrCfg.StorDbCfg().StorDBPort &&
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBName == mgrCfg.StorDbCfg().StorDBName
|
||||
sameStorDB = mgrCfg.MigratorCgrCfg().OutStorDBType == mgrCfg.StorDbCfg().StorDBType &&
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBHost == mgrCfg.StorDbCfg().StorDBHost &&
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBPort == mgrCfg.StorDbCfg().StorDBPort &&
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBName == mgrCfg.StorDbCfg().StorDBName
|
||||
|
||||
if storDBIn, err = migrator.NewMigratorStorDB(mgrCfg.StorDbCfg().StorDBType,
|
||||
mgrCfg.StorDbCfg().StorDBHost, mgrCfg.StorDbCfg().StorDBPort,
|
||||
@@ -312,10 +312,10 @@ func main() {
|
||||
|
||||
if sameStorDB {
|
||||
storDBOut = storDBIn
|
||||
} else if storDBOut, err = migrator.NewMigratorStorDB(mgrCfg.MigratorCgrConfig.OutStorDBType,
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBHost, mgrCfg.MigratorCgrConfig.OutStorDBPort,
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBName, mgrCfg.MigratorCgrConfig.OutStorDBUser,
|
||||
mgrCfg.MigratorCgrConfig.OutStorDBPassword, mgrCfg.StorDbCfg().StorDBMaxOpenConns,
|
||||
} else if storDBOut, err = migrator.NewMigratorStorDB(mgrCfg.MigratorCgrCfg().OutStorDBType,
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBHost, mgrCfg.MigratorCgrCfg().OutStorDBPort,
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBName, mgrCfg.MigratorCgrCfg().OutStorDBUser,
|
||||
mgrCfg.MigratorCgrCfg().OutStorDBPassword, mgrCfg.StorDbCfg().StorDBMaxOpenConns,
|
||||
mgrCfg.StorDbCfg().StorDBMaxIdleConns, mgrCfg.StorDbCfg().StorDBConnMaxLifetime,
|
||||
mgrCfg.StorDbCfg().StorDBCDRSIndexes); err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
119
config/config.go
119
config/config.go
@@ -127,6 +127,7 @@ func SetCgrConfig(cfg *CGRConfig) {
|
||||
func NewDefaultCGRConfig() (*CGRConfig, error) {
|
||||
cfg := new(CGRConfig)
|
||||
cfg.DataFolderPath = "/usr/share/cgrates/"
|
||||
cfg.MaxCallDuration = time.Duration(3) * time.Hour // Hardcoded for now
|
||||
|
||||
cfg.generalCfg = new(GeneralCfg)
|
||||
cfg.generalCfg.NodeID = utils.UUIDSha1Prefix()
|
||||
@@ -154,12 +155,17 @@ func NewDefaultCGRConfig() (*CGRConfig, error) {
|
||||
cfg.chargerSCfg = new(ChargerSCfg)
|
||||
cfg.resourceSCfg = new(ResourceSConfig)
|
||||
cfg.statsCfg = new(StatSCfg)
|
||||
cfg.thresholdSCfg = new(ThresholdSCfg)
|
||||
cfg.supplierSCfg = new(SupplierSCfg)
|
||||
cfg.sureTaxCfg = new(SureTaxCfg)
|
||||
cfg.dispatcherSCfg = new(DispatcherSCfg)
|
||||
cfg.loaderCgrCfg = new(LoaderCgrCfg)
|
||||
cfg.migratorCgrCfg = new(MigratorCgrCfg)
|
||||
|
||||
//Depricated
|
||||
cfg.cdrStatsCfg = new(CdrStatsCfg)
|
||||
cfg.SmOsipsConfig = new(SmOsipsConfig)
|
||||
|
||||
cfg.dispatcherSCfg = new(DispatcherSCfg)
|
||||
cfg.ConfigReloads = make(map[string]chan struct{})
|
||||
cfg.ConfigReloads[utils.CDRC] = make(chan struct{}, 1)
|
||||
cfg.ConfigReloads[utils.CDRC] <- struct{}{} // Unlock the channel
|
||||
@@ -171,16 +177,15 @@ func NewDefaultCGRConfig() (*CGRConfig, error) {
|
||||
cfg.ConfigReloads[utils.DIAMETER_AGENT] <- struct{}{} // Unlock the channel
|
||||
cfg.ConfigReloads[utils.SMAsterisk] = make(chan struct{}, 1)
|
||||
cfg.ConfigReloads[utils.SMAsterisk] <- struct{}{} // Unlock the channel
|
||||
|
||||
cgrJsonCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.MaxCallDuration = time.Duration(3) * time.Hour // Hardcoded for now
|
||||
|
||||
if err := cfg.loadFromJsonCfg(cgrJsonCfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.dfltCdreProfile = cfg.CdreProfiles[utils.META_DEFAULT].Clone() // So default will stay unique, will have nil pointer in case of no defaults loaded which is an extra check
|
||||
cfg.dfltCdrcProfile = cfg.CdrcProfiles["/var/spool/cgrates/cdrc/in"][0].Clone()
|
||||
dfltFsConnConfig = cfg.fsAgentCfg.EventSocketConns[0] // We leave it crashing here on purpose if no Connection defaults defined
|
||||
@@ -261,6 +266,10 @@ func NewCGRConfigFromFolder(cfgDir string) (*CGRConfig, error) {
|
||||
// Holds system configuration, defaults are overwritten with values from config file if found
|
||||
type CGRConfig struct {
|
||||
MaxCallDuration time.Duration // The maximum call duration (used by responder when querying DerivedCharging) // ToDo: export it in configuration file
|
||||
DataFolderPath string // Path towards data folder, for tests internal usage, not loading out of .json options
|
||||
// Cache defaults loaded from json and needing clones
|
||||
dfltCdreProfile *CdreCfg // Default cdreConfig profile
|
||||
dfltCdrcProfile *CdrcCfg // Default cdrcConfig profile
|
||||
|
||||
CdreProfiles map[string]*CdreCfg // Cdre config profiles
|
||||
CdrcProfiles map[string][]*CdrcCfg // Number of CDRC instances running imports, format map[dirPath][]{Configs}
|
||||
@@ -268,22 +277,12 @@ type CGRConfig struct {
|
||||
|
||||
httpAgentCfg []*HttpAgentCfg // HttpAgent configuration
|
||||
|
||||
thresholdSCfg *ThresholdSCfg // configuration for ThresholdS
|
||||
supplierSCfg *SupplierSCfg // configuration for SupplierS
|
||||
dispatcherSCfg *DispatcherSCfg // configuration for Dispatcher
|
||||
MailerServer string // The server to use when sending emails out
|
||||
MailerAuthUser string // Authenticate to email server using this user
|
||||
MailerAuthPass string // Authenticate to email server with this password
|
||||
MailerFromAddr string // From address used when sending emails out
|
||||
DataFolderPath string // Path towards data folder, for tests internal usage, not loading out of .json options
|
||||
sureTaxCfg *SureTaxCfg // Load here SureTax configuration, as pointer so we can have runtime reloads in the future
|
||||
ConfigReloads map[string]chan struct{} // Signals to specific entities that a config reload should occur
|
||||
LoaderCgrConfig *LoaderCgrCfg
|
||||
MigratorCgrConfig *MigratorCgrCfg
|
||||
MailerServer string // The server to use when sending emails out
|
||||
MailerAuthUser string // Authenticate to email server using this user
|
||||
MailerAuthPass string // Authenticate to email server with this password
|
||||
MailerFromAddr string // From address used when sending emails out
|
||||
|
||||
// Cache defaults loaded from json and needing clones
|
||||
dfltCdreProfile *CdreCfg // Default cdreConfig profile
|
||||
dfltCdrcProfile *CdrcCfg // Default cdrcConfig profile
|
||||
ConfigReloads map[string]chan struct{} // Signals to specific entities that a config reload should occur
|
||||
|
||||
generalCfg *GeneralCfg // General config
|
||||
dataDbCfg *DataDbCfg // Database config
|
||||
@@ -306,6 +305,12 @@ type CGRConfig struct {
|
||||
chargerSCfg *ChargerSCfg // ChargerS config
|
||||
resourceSCfg *ResourceSConfig // ResourceS config
|
||||
statsCfg *StatSCfg // StatS config
|
||||
thresholdSCfg *ThresholdSCfg // ThresholdS config
|
||||
supplierSCfg *SupplierSCfg // SupplierS config
|
||||
sureTaxCfg *SureTaxCfg // SureTax config
|
||||
dispatcherSCfg *DispatcherSCfg // DispatcherS config
|
||||
loaderCgrCfg *LoaderCgrCfg // LoaderCgr config
|
||||
migratorCgrCfg *MigratorCgrCfg // MigratorCgr config
|
||||
analyzerSCfg *AnalyzerSCfg
|
||||
|
||||
// Deprecated
|
||||
@@ -905,11 +910,17 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if self.thresholdSCfg.loadFromJsonCfg(jsnThresholdSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnSupplierSCfg, err := jsnCfg.SupplierSJsonCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if self.supplierSCfg.loadFromJsonCfg(jsnSupplierSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnLoaderCfg, err := jsnCfg.LoaderJsonCfg()
|
||||
if err != nil {
|
||||
@@ -925,21 +936,33 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.sureTaxCfg.loadFromJsonCfg(jsnSureTaxCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnDispatcherCfg, err := jsnCfg.DispatcherSJsonCfg()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if self.dispatcherSCfg.loadFromJsonCfg(jsnDispatcherCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnLoaderCgrCfg, err := jsnCfg.LoaderCfgJson()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if self.loaderCgrCfg.loadFromJsonCfg(jsnLoaderCgrCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnMigratorCgrCfg, err := jsnCfg.MigratorCfgJson()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if self.migratorCgrCfg.loadFromJsonCfg(jsnMigratorCgrCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
jsnTlsCgrCfg, err := jsnCfg.TlsCfgJson()
|
||||
if err != nil {
|
||||
@@ -1074,24 +1097,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
}
|
||||
///depricated^^^
|
||||
|
||||
if jsnThresholdSCfg != nil {
|
||||
if self.thresholdSCfg == nil {
|
||||
self.thresholdSCfg = new(ThresholdSCfg)
|
||||
}
|
||||
if self.thresholdSCfg.loadFromJsonCfg(jsnThresholdSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnSupplierSCfg != nil {
|
||||
if self.supplierSCfg == nil {
|
||||
self.supplierSCfg = new(SupplierSCfg)
|
||||
}
|
||||
if self.supplierSCfg.loadFromJsonCfg(jsnSupplierSCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnMailerCfg != nil {
|
||||
if jsnMailerCfg.Server != nil {
|
||||
self.MailerServer = *jsnMailerCfg.Server
|
||||
@@ -1106,42 +1111,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) {
|
||||
self.MailerFromAddr = *jsnMailerCfg.From_address
|
||||
}
|
||||
}
|
||||
|
||||
if jsnSureTaxCfg != nil { // New config for SureTax
|
||||
if self.sureTaxCfg, err = NewSureTaxCfgWithDefaults(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := self.sureTaxCfg.loadFromJsonCfg(jsnSureTaxCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnDispatcherCfg != nil {
|
||||
if self.dispatcherSCfg == nil {
|
||||
self.dispatcherSCfg = new(DispatcherSCfg)
|
||||
}
|
||||
if self.dispatcherSCfg.loadFromJsonCfg(jsnDispatcherCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnLoaderCgrCfg != nil {
|
||||
if self.LoaderCgrConfig == nil {
|
||||
self.LoaderCgrConfig = new(LoaderCgrCfg)
|
||||
}
|
||||
if self.LoaderCgrConfig.loadFromJsonCfg(jsnLoaderCgrCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if jsnMigratorCgrCfg != nil {
|
||||
if self.MigratorCgrConfig == nil {
|
||||
self.MigratorCgrConfig = new(MigratorCgrCfg)
|
||||
}
|
||||
if self.MigratorCgrConfig.loadFromJsonCfg(jsnMigratorCgrCfg); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1226,11 +1195,11 @@ func (cfg *CGRConfig) DispatcherSCfg() *DispatcherSCfg {
|
||||
}
|
||||
|
||||
func (cfg *CGRConfig) LoaderCgrCfg() *LoaderCgrCfg {
|
||||
return cfg.LoaderCgrConfig
|
||||
return cfg.loaderCgrCfg
|
||||
}
|
||||
|
||||
func (cfg *CGRConfig) MigratorCgrCfg() *MigratorCgrCfg {
|
||||
return cfg.MigratorCgrConfig
|
||||
return cfg.migratorCgrCfg
|
||||
}
|
||||
|
||||
func (cfg *CGRConfig) SchedulerCfg() *SchedulerCfg {
|
||||
|
||||
@@ -1496,8 +1496,8 @@ func TestCgrLoaderCfgDefault(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.LoaderCgrConfig, eLdrCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.LoaderCgrConfig), utils.ToJSON(eLdrCfg))
|
||||
if !reflect.DeepEqual(cgrCfg.LoaderCgrCfg(), eLdrCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.LoaderCgrCfg()), utils.ToJSON(eLdrCfg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1517,8 +1517,8 @@ func TestCgrMigratorCfgDefault(t *testing.T) {
|
||||
OutStorDBUser: "cgrates",
|
||||
OutStorDBPassword: "",
|
||||
}
|
||||
if !reflect.DeepEqual(cgrCfg.MigratorCgrConfig, eMgrCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.MigratorCgrConfig), utils.ToJSON(eMgrCfg))
|
||||
if !reflect.DeepEqual(cgrCfg.MigratorCgrCfg(), eMgrCfg) {
|
||||
t.Errorf("received: %+v, expecting: %+v", utils.ToJSON(cgrCfg.MigratorCgrCfg()), utils.ToJSON(eMgrCfg))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1635,10 +1635,10 @@ func TestCgrMigratorCfg2(t *testing.T) {
|
||||
|
||||
if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(JSN_CFG); err != nil {
|
||||
t.Error(err)
|
||||
} else if cgrCfg.MigratorCgrConfig.OutDataDBHost != "0.0.0.0" {
|
||||
t.Errorf("Expected: 0.0.0.0 , received: %+v", cgrCfg.MigratorCgrConfig.OutDataDBHost)
|
||||
} else if cgrCfg.MigratorCgrConfig.OutDataDBPort != "9999" {
|
||||
t.Errorf("Expected: 9999, received: %+v", cgrCfg.MigratorCgrConfig.OutDataDBPassword)
|
||||
} else if cgrCfg.MigratorCgrCfg().OutDataDBHost != "0.0.0.0" {
|
||||
t.Errorf("Expected: 0.0.0.0 , received: %+v", cgrCfg.MigratorCgrCfg().OutDataDBHost)
|
||||
} else if cgrCfg.MigratorCgrCfg().OutDataDBPort != "9999" {
|
||||
t.Errorf("Expected: 9999, received: %+v", cgrCfg.MigratorCgrCfg().OutDataDBPassword)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,9 @@ type LoaderCgrCfg struct {
|
||||
}
|
||||
|
||||
func (ld *LoaderCgrCfg) loadFromJsonCfg(jsnCfg *LoaderCfgJson) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
if jsnCfg.Tpid != nil {
|
||||
ld.TpID = *jsnCfg.Tpid
|
||||
}
|
||||
|
||||
66
config/loadercgrcfg_test.go
Normal file
66
config/loadercgrcfg_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func TestLoaderCgrCfgloadFromJsonCfg(t *testing.T) {
|
||||
var loadscfg, expected LoaderCgrCfg
|
||||
if err := loadscfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(loadscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, loadscfg)
|
||||
}
|
||||
if err := loadscfg.loadFromJsonCfg(new(LoaderCfgJson)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(loadscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, loadscfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"loader": { // loader for tariff plans out of .csv files
|
||||
"tpid": "", // tariff plan identificator
|
||||
"data_path": "", // path towards tariff plan files
|
||||
"disable_reverse": false, // disable reverse computing
|
||||
"caches_conns":[ // addresses towards cacheS components for reloads
|
||||
{"address": "127.0.0.1:2012", "transport": "*json"}
|
||||
],
|
||||
"scheduler_conns": [
|
||||
{"address": "127.0.0.1:2012"}
|
||||
],
|
||||
},
|
||||
}`
|
||||
expected = LoaderCgrCfg{
|
||||
CachesConns: []*HaPoolConfig{{Address: "127.0.0.1:2012", Transport: "*json"}},
|
||||
SchedulerConns: []*HaPoolConfig{{Address: "127.0.0.1:2012"}},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnLoadersCfg, err := jsnCfg.LoaderCfgJson(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = loadscfg.loadFromJsonCfg(jsnLoadersCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, loadscfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", utils.ToJSON(expected), utils.ToJSON(loadscfg))
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,9 @@ type MigratorCgrCfg struct {
|
||||
}
|
||||
|
||||
func (mg *MigratorCgrCfg) loadFromJsonCfg(jsnCfg *MigratorCfgJson) (err error) {
|
||||
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
if jsnCfg.Out_dataDB_type != nil {
|
||||
mg.OutDataDBType = *jsnCfg.Out_dataDB_type
|
||||
}
|
||||
@@ -61,7 +63,6 @@ func (mg *MigratorCgrCfg) loadFromJsonCfg(jsnCfg *MigratorCfgJson) (err error) {
|
||||
if jsnCfg.Out_dataDB_redis_sentinel != nil {
|
||||
mg.OutDataDBRedisSentinel = *jsnCfg.Out_dataDB_redis_sentinel
|
||||
}
|
||||
|
||||
if jsnCfg.Out_storDB_type != nil {
|
||||
mg.OutStorDBType = *jsnCfg.Out_storDB_type
|
||||
}
|
||||
|
||||
79
config/migratorcfg_test.go
Normal file
79
config/migratorcfg_test.go
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMigratorCgrCfgloadFromJsonCfg(t *testing.T) {
|
||||
var migcfg, expected MigratorCgrCfg
|
||||
if err := migcfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(migcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, migcfg)
|
||||
}
|
||||
if err := migcfg.loadFromJsonCfg(new(MigratorCfgJson)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(migcfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, migcfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"migrator": {
|
||||
"out_datadb_type": "redis",
|
||||
"out_datadb_host": "127.0.0.1",
|
||||
"out_datadb_port": "6379",
|
||||
"out_datadb_name": "10",
|
||||
"out_datadb_user": "cgrates",
|
||||
"out_datadb_password": "",
|
||||
"out_datadb_encoding" : "msgpack",
|
||||
"out_stordb_type": "mysql",
|
||||
"out_stordb_host": "127.0.0.1",
|
||||
"out_stordb_port": "3306",
|
||||
"out_stordb_name": "cgrates",
|
||||
"out_stordb_user": "cgrates",
|
||||
"out_stordb_password": "",
|
||||
},
|
||||
}`
|
||||
expected = MigratorCgrCfg{
|
||||
OutDataDBType: "redis",
|
||||
OutDataDBHost: "127.0.0.1",
|
||||
OutDataDBPort: "6379",
|
||||
OutDataDBName: "10",
|
||||
OutDataDBUser: "cgrates",
|
||||
OutDataDBPassword: "",
|
||||
OutDataDBEncoding: "msgpack",
|
||||
OutStorDBType: "mysql",
|
||||
OutStorDBHost: "127.0.0.1",
|
||||
OutStorDBPort: "3306",
|
||||
OutStorDBName: "cgrates",
|
||||
OutStorDBUser: "cgrates",
|
||||
OutStorDBPassword: "",
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnThSCfg, err := jsnCfg.MigratorCfgJson(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = migcfg.loadFromJsonCfg(jsnThSCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, migcfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", expected, migcfg)
|
||||
}
|
||||
}
|
||||
67
config/supplierscfg_test.go
Normal file
67
config/supplierscfg_test.go
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSupplierSCfgloadFromJsonCfg(t *testing.T) {
|
||||
var supscfg, expected SupplierSCfg
|
||||
if err := supscfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(supscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, supscfg)
|
||||
}
|
||||
if err := supscfg.loadFromJsonCfg(new(SupplierSJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(supscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, supscfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"suppliers": { // Supplier service (*new)
|
||||
"enabled": false, // starts SupplierS service: <true|false>.
|
||||
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"prefix_indexed_fields": ["index1", "index2"], // query indexes based on these fields for faster processing
|
||||
"attributes_conns": [], // address where to reach the AttributeS <""|127.0.0.1:2013>
|
||||
"rals_conns": [
|
||||
{"address": "*internal"}, // address where to reach the RALs for cost/accounting <*internal>
|
||||
],
|
||||
"resources_conns": [], // address where to reach the Resource service, empty to disable functionality: <""|*internal|x.y.z.y:1234>
|
||||
"stats_conns": [], // address where to reach the Stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234>
|
||||
},
|
||||
}`
|
||||
expected = SupplierSCfg{
|
||||
PrefixIndexedFields: &[]string{"index1", "index2"},
|
||||
AttributeSConns: []*HaPoolConfig{},
|
||||
RALsConns: []*HaPoolConfig{{Address: "*internal"}},
|
||||
ResourceSConns: []*HaPoolConfig{},
|
||||
StatSConns: []*HaPoolConfig{},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnSupSCfg, err := jsnCfg.SupplierSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = supscfg.loadFromJsonCfg(jsnSupSCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, supscfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", expected, supscfg)
|
||||
}
|
||||
}
|
||||
@@ -19,27 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Creates a new SureTaxCfg with defaults pre-populated out of config_defaults.json
|
||||
func NewSureTaxCfgWithDefaults() (*SureTaxCfg, error) {
|
||||
jsnCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(CGRATES_CFG_JSON))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jsnSureTaxCfg, err := jsnCfg.SureTaxJsonCfg()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
st := new(SureTaxCfg)
|
||||
if err := st.loadFromJsonCfg(jsnSureTaxCfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return st, nil
|
||||
}
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// SureTax configuration object
|
||||
type SureTaxCfg struct {
|
||||
@@ -72,8 +55,10 @@ type SureTaxCfg struct {
|
||||
}
|
||||
|
||||
// Loads/re-loads data from json config object
|
||||
func (self *SureTaxCfg) loadFromJsonCfg(jsnCfg *SureTaxJsonCfg) error {
|
||||
var err error
|
||||
func (self *SureTaxCfg) loadFromJsonCfg(jsnCfg *SureTaxJsonCfg) (err error) {
|
||||
if jsnCfg == nil {
|
||||
return
|
||||
}
|
||||
if jsnCfg.Url != nil {
|
||||
self.Url = *jsnCfg.Url
|
||||
}
|
||||
60
config/thresholdscfg_test.go
Normal file
60
config/thresholdscfg_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package config
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestThresholdSCfgloadFromJsonCfg(t *testing.T) {
|
||||
var thscfg, expected ThresholdSCfg
|
||||
if err := thscfg.loadFromJsonCfg(nil); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(thscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, thscfg)
|
||||
}
|
||||
if err := thscfg.loadFromJsonCfg(new(ThresholdSJsonCfg)); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(thscfg, expected) {
|
||||
t.Errorf("Expected: %+v ,recived: %+v", expected, thscfg)
|
||||
}
|
||||
cfgJSONStr := `{
|
||||
"thresholds": { // Threshold service (*new)
|
||||
"enabled": false, // starts ThresholdS service: <true|false>.
|
||||
"store_interval": "2h", // dump cache regularly to dataDB, 0 - dump at start/shutdown: <""|$dur>
|
||||
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"prefix_indexed_fields": ["index1", "index2"], // query indexes based on these fields for faster processing
|
||||
},
|
||||
}`
|
||||
expected = ThresholdSCfg{
|
||||
StoreInterval: time.Duration(time.Hour * 2),
|
||||
PrefixIndexedFields: &[]string{"index1", "index2"},
|
||||
}
|
||||
if jsnCfg, err := NewCgrJsonCfgFromReader(strings.NewReader(cfgJSONStr)); err != nil {
|
||||
t.Error(err)
|
||||
} else if jsnThSCfg, err := jsnCfg.ThresholdSJsonCfg(); err != nil {
|
||||
t.Error(err)
|
||||
} else if err = thscfg.loadFromJsonCfg(jsnThSCfg); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(expected, thscfg) {
|
||||
t.Errorf("Expected: %+v , recived: %+v", expected, thscfg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user