Updated sql ers config

This commit is contained in:
Trial97
2021-05-04 11:22:32 +03:00
committed by Dan Christian Bogos
parent 45a11aa91e
commit 15d89d5770
7 changed files with 37 additions and 70 deletions

View File

@@ -50,27 +50,22 @@ func newDbDefaults() dbDefaults {
utils.MySQL: map[string]string{
"DbName": "cgrates",
"DbPort": "3306",
"DbPass": "CGRateS.org",
},
utils.Postgres: map[string]string{
"DbName": "cgrates",
"DbPort": "5432",
"DbPass": "CGRateS.org",
},
utils.Mongo: map[string]string{
"DbName": "cgrates",
"DbPort": "27017",
"DbPass": "",
},
utils.Redis: map[string]string{
"DbName": "10",
"DbPort": "6379",
"DbPass": "",
},
utils.Internal: map[string]string{
"DbName": "internal",
"DbPort": "internal",
"DbPass": "internal",
},
}
return deflt
@@ -92,13 +87,6 @@ func (dbDflt dbDefaults) dbPort(dbType string, flagInput string) string {
return dbDflt[dbType]["DbPort"]
}
func (dbDflt dbDefaults) dbPass(dbType string, flagInput string) string {
if flagInput != utils.MetaDynamic {
return flagInput
}
return dbDflt[dbType]["DbPass"]
}
func init() {
cgrCfg = NewDefaultCGRConfig()
dbDefaultsCfg = newDbDefaults()

View File

@@ -360,12 +360,12 @@ const CGRATES_CFG_JSON = `
// "kafkaTopicProcessed": "", the topic were the events are sent after they are processed
// SQL
// "dbName": "cgrates", // the name of the database from were the events are read
// "tableName": "cdrs", // the name of the table from were the events are read
// "sqlDBName": "cgrates", // the name of the database from were the events are read
// "sqlTableName": "cdrs", // the name of the table from were the events are read
// "sslMode": "disable", // the ssl mode for postgres db
// "dbNameProcessed": "", // the name of the database were the events are sent after they are processed
// "tableNameProcessed": "", // the name of the table were the events are sent after they are processed
// "sqlDBNameProcessed": "", // the name of the database were the events are sent after they are processed
// "sqlTableNameProcessed": "", // the name of the table were the events are sent after they are processed
// "sslModeProcessed": "", // the ssl mode for postgres db
// SQS and S3

View File

@@ -878,14 +878,6 @@ func TestDbDefaultsMetaDynamic(t *testing.T) {
flagInput := utils.MetaDynamic
dbs := []string{utils.Mongo, utils.Redis, utils.MySQL, utils.Internal}
for _, dbtype := range dbs {
host := dbdf.dbHost(flagInput)
if host != utils.Localhost {
t.Errorf("received: %+v, expecting: %+v", host, utils.Localhost)
}
user := dbdf.dbUser(flagInput)
if user != utils.CGRateSLwr {
t.Errorf("received: %+v, expecting: %+v", user, utils.CGRateSLwr)
}
port := dbdf.dbPort(dbtype, flagInput)
if port != dbdf[dbtype]["DbPort"] {
t.Errorf("received: %+v, expecting: %+v", port, dbdf[dbtype]["DbPort"])
@@ -894,26 +886,13 @@ func TestDbDefaultsMetaDynamic(t *testing.T) {
if name != dbdf[dbtype]["DbName"] {
t.Errorf("received: %+v, expecting: %+v", name, dbdf[dbtype]["DbName"])
}
pass := dbdf.dbPass(dbtype, flagInput)
if pass != dbdf[dbtype]["DbPass"] {
t.Errorf("received: %+v, expecting: %+v", pass, dbdf[dbtype]["DbPass"])
}
}
}
func TestDbDefaults(t *testing.T) {
dbdf := newDbDefaults()
flagInput := "NonMetaDynamic"
dbs := []string{utils.Mongo, utils.Redis, utils.MySQL, utils.Internal, utils.Postgres}
for _, dbtype := range dbs {
host := dbdf.dbHost(flagInput)
if host != flagInput {
t.Errorf("Expected %+v, received %+v", flagInput, host)
}
user := dbdf.dbUser(flagInput)
if user != flagInput {
t.Errorf("Expected %+v, received %+v", flagInput, user)
}
port := dbdf.dbPort(dbtype, "1234")
if port != "1234" {
t.Errorf("Expected %+v, received %+v", "1234", port)
@@ -922,10 +901,6 @@ func TestDbDefaults(t *testing.T) {
if name != utils.CGRateSLwr {
t.Errorf("Expected %+v, received %+v", utils.CGRateSLwr, name)
}
pass := dbdf.dbPass(dbtype, utils.EmptyString)
if pass != utils.EmptyString {
t.Errorf("Expected %+v, received %+v", utils.EmptyString, pass)
}
}
}

View File

@@ -395,7 +395,7 @@
"attempts": 1,
"opts": {
"dbName": "exportedDatabase", // if dbName is not present "cgrates" will be used as default
"tableName": "expTable", // tableName is mandatory in opts for sql exporter
"sqlTableName": "expTable", // tableName is mandatory in opts for sql exporter
"sslMode": "disable",
"maxIdleConns": "10",
"maxOpenConns": "100",
@@ -415,8 +415,8 @@
"export_path": "mysql://cgrates:CGRateS.org@127.0.0.1:3306",
"attempts": 1,
"opts": {
"dbName": "exportedDatabase",
"tableName": "expTable",
"sqlDBName": "exportedDatabase",
"sqlTableName": "expTable",
"sslMode": "disable",
"maxIdleConns": "10",
"maxOpenConns": "100",

View File

@@ -96,9 +96,9 @@ func testSQLInitConfig(t *testing.T) {
"concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited
"source_path": "*mysql://cgrates:CGRateS.org@127.0.0.1:3306", // read data from this path
"opts": {
"dbName":"cgrates2",
"dbNameProcessed":"cgrates2",
"tableNameProcessed":"cdrs2",
"sqlDBName":"cgrates2",
"sqlDBNameProcessed":"cgrates2",
"sqlTableNameProcessed":"cdrs2",
},
"processed_path": "", // move processed data here
"tenant": "cgrates.org", // tenant used by import
@@ -373,9 +373,9 @@ func testSQLInitConfig2(t *testing.T) {
"concurrent_requests": 1024, // maximum simultaneous requests/files to process, 0 for unlimited
"source_path": "*mysql://cgrates:CGRateS.org@127.0.0.1:3306", // read data from this path
"opts": {
"dbName":"cgrates2",
"dbNameProcessed":"cgrates2",
"tableNameProcessed":"cdrs2",
"sqlDBName":"cgrates2",
"sqlDBNameProcessed":"cgrates2",
"sqlTableNameProcessed":"cdrs2",
},
"processed_path": "", // move processed data here
"tenant": "cgrates.org", // tenant used by import

View File

@@ -41,13 +41,13 @@ func TestSQLSetURL(t *testing.T) {
inURL := "*mysql://cgrates:CGRateS.org@127.0.0.1:3306"
outURL := "*mysql://cgrates:CGRateS.org@127.0.0.1:3306"
if err := sql.setURL(inURL, outURL, map[string]interface{}{
"dbName": "cgrates2",
"tableName": "cdrs2",
"sslMode": "enabled",
utils.SQLDBName: "cgrates2",
utils.SQLTableName: "cdrs2",
"sslMode": "enabled",
"dbNameProcessed": "cgrates3",
"tableNameProcessed": "cdrs3",
"sslModeProcessed": "enabled",
utils.SQLDBName + utils.ProcessedOpt: "cgrates3",
utils.SQLTableName + utils.ProcessedOpt: "cdrs3",
"sslModeProcessed": "enabled",
}); err != nil {
t.Fatal(err)
} else if expsql.connString != sql.connString {
@@ -76,13 +76,13 @@ func TestSQLSetURL(t *testing.T) {
inURL = "*postgres://cgrates:CGRateS.org@127.0.0.1:3306"
outURL = "*postgres://cgrates:CGRateS.org@127.0.0.1:3306"
if err := sql.setURL(inURL, outURL, map[string]interface{}{
"dbName": "cgrates2",
"tableName": "cdrs2",
"sslMode": "enabled",
utils.SQLDBName: "cgrates2",
utils.SQLTableName: "cdrs2",
"sslMode": "enabled",
"dbNameProcessed": "cgrates3",
"tableNameProcessed": "cdrs3",
"sslModeProcessed": "enabled",
utils.SQLDBName + utils.ProcessedOpt: "cgrates3",
utils.SQLTableName + utils.ProcessedOpt: "cdrs3",
"sslModeProcessed": "enabled",
}); err != nil {
t.Fatal(err)
} else if expsql.connString != sql.connString {
@@ -111,13 +111,13 @@ func TestSQLSetURL(t *testing.T) {
inURL = "*postgres://cgrates:CGRateS.org@127.0.0.1:3306"
outURL = ""
if err := sql.setURL(inURL, outURL, map[string]interface{}{
"dbName": "cgrates2",
"tableName": "cdrs2",
"sslMode": "enabled",
utils.SQLDBName: "cgrates2",
utils.SQLTableName: "cdrs2",
"sslMode": "enabled",
"dbNameProcessed": "cgrates2",
"tableNameProcessed": "cdrs2",
"sslModeProcessed": "enabled",
utils.SQLDBName + utils.ProcessedOpt: "cgrates2",
utils.SQLTableName + utils.ProcessedOpt: "cdrs2",
"sslModeProcessed": "enabled",
}); err != nil {
t.Fatal(err)
} else if expsql.connString != sql.connString {

View File

@@ -2331,9 +2331,13 @@ const (
// s3
S3Bucket = "s3BucketID"
S3FolderPath = "s3FolderPath"
SQLTableName = "tableName"
SQLDefaultSSLMode = "disable"
// sql
SQLDefaultDBName = "cgrates"
SQLDefaultSSLMode = "disable"
SQLDBName = "sqlDBName"
SQLTableName = "sqlTableName"
// fileCSV
RowLengthOpt = "RowLength"