mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 05:09:54 +05:00
Updated mongoDB driver constructor
This commit is contained in:
committed by
Dan Christian Bogos
parent
4fe3b8e257
commit
6eb4be05c2
@@ -1078,6 +1078,7 @@ func testDspRplActions(t *testing.T) {
|
||||
ActionType: utils.LOG,
|
||||
},
|
||||
},
|
||||
Key: "KeyActions",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
@@ -1143,6 +1144,7 @@ func testDspRplActionPlan(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Key: "KeyActionPlan",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
@@ -1197,6 +1199,7 @@ func testDspRplAccountActionPlans(t *testing.T) {
|
||||
setAccountActionPlans := &engine.SetAccountActionPlansArgWithOpts{
|
||||
AplIDs: []string{"KeyAccountActionPlans"},
|
||||
Overwrite: true,
|
||||
AcntID: "KeyAccountActionPlans",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
@@ -1269,6 +1272,7 @@ func testDspRplRatingPlan(t *testing.T) {
|
||||
// Get RatingPlan
|
||||
var reply engine.RatingPlan
|
||||
argsRatingPlan := &utils.StringWithOpts{
|
||||
Arg: "id",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
@@ -1325,6 +1329,7 @@ func testDspRplRatingProfile(t *testing.T) {
|
||||
// Get RatingProfile
|
||||
var reply engine.RatingProfile
|
||||
argsRatingProfile := &utils.StringWithOpts{
|
||||
Arg: "idRatingProfile",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
@@ -1379,6 +1384,7 @@ func testDspRplDestination(t *testing.T) {
|
||||
// Get Destination
|
||||
var reply engine.Destination
|
||||
argsDestination := &utils.StringWithOpts{
|
||||
Arg: "idDestination",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
@@ -1433,6 +1439,7 @@ func testDspRplLoadIDs(t *testing.T) {
|
||||
// Get LoadIDs
|
||||
var reply map[string]int64
|
||||
argsLoadIDs := &utils.StringWithOpts{
|
||||
Arg: "idLoadIDs",
|
||||
Tenant: "cgrates.org",
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
|
||||
@@ -126,7 +126,7 @@ func TimeDecodeValue1(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val ref
|
||||
|
||||
// NewMongoStorage givese new mongo driver
|
||||
func NewMongoStorage(host, port, db, user, pass, mrshlerStr, storageType string,
|
||||
cdrsIndexes []string, isDataDB bool, ttl time.Duration) (ms *MongoStorage, err error) {
|
||||
cdrsIndexes []string, ttl time.Duration) (ms *MongoStorage, err error) {
|
||||
url := host
|
||||
if port != "" {
|
||||
url += ":" + port
|
||||
@@ -171,7 +171,6 @@ func NewMongoStorage(host, port, db, user, pass, mrshlerStr, storageType string,
|
||||
storageType: storageType,
|
||||
ms: mrshler,
|
||||
cdrsIndexes: cdrsIndexes,
|
||||
isDataDB: isDataDB,
|
||||
}
|
||||
|
||||
if err = ms.query(func(sctx mongo.SessionContext) error {
|
||||
@@ -208,7 +207,6 @@ type MongoStorage struct {
|
||||
ms Marshaler
|
||||
cdrsIndexes []string
|
||||
cnter *utils.Counter
|
||||
isDataDB bool
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) query(argfunc func(ctx mongo.SessionContext) error) (err error) {
|
||||
@@ -221,7 +219,7 @@ func (ms *MongoStorage) query(argfunc func(ctx mongo.SessionContext) error) (err
|
||||
|
||||
// IsDataDB returns if the storeage is used for DataDb
|
||||
func (ms *MongoStorage) IsDataDB() bool {
|
||||
return ms.isDataDB
|
||||
return ms.storageType == utils.DataDB
|
||||
}
|
||||
|
||||
// SetTTL set the context TTL used for queries (is thread safe)
|
||||
|
||||
@@ -62,7 +62,7 @@ func NewDataDBConn(dbType, host, port, name, user,
|
||||
if ttl, err = utils.IfaceAsDuration(opts[utils.QueryTimeoutCfg]); err != nil {
|
||||
return
|
||||
}
|
||||
d, err = NewMongoStorage(host, port, name, user, pass, marshaler, utils.DataDB, nil, true, ttl)
|
||||
d, err = NewMongoStorage(host, port, name, user, pass, marshaler, utils.DataDB, nil, ttl)
|
||||
case utils.INTERNAL:
|
||||
d = NewInternalDB(nil, nil, true)
|
||||
default:
|
||||
@@ -81,7 +81,7 @@ func NewStorDBConn(dbType, host, port, name, user, pass, marshaler string,
|
||||
if ttl, err = utils.IfaceAsDuration(opts[utils.QueryTimeoutCfg]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db, err = NewMongoStorage(host, port, name, user, pass, marshaler, utils.StorDB, stringIndexedFields, false, ttl)
|
||||
db, err = NewMongoStorage(host, port, name, user, pass, marshaler, utils.StorDB, stringIndexedFields, ttl)
|
||||
case utils.POSTGRES:
|
||||
var maxConn, maxIdleConn, connMaxLifetime int64
|
||||
if maxConn, err = utils.IfaceAsTInt64(opts[utils.MaxOpenConnsCfg]); err != nil {
|
||||
|
||||
@@ -98,7 +98,7 @@ func testActionsInitCdrsStore(t *testing.T) {
|
||||
actsCfg.StorDbCfg().Port, actsCfg.StorDbCfg().Name,
|
||||
actsCfg.StorDbCfg().User, actsCfg.StorDbCfg().Password,
|
||||
actsCfg.GeneralCfg().DBDataEncoding,
|
||||
utils.StorDB, nil, false, 10*time.Second); err != nil {
|
||||
utils.StorDB, nil, 10*time.Second); err != nil {
|
||||
t.Fatal("Could not connect to mongo", err.Error())
|
||||
}
|
||||
case utils.MetaPostgres:
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestDMitinitDB(t *testing.T) {
|
||||
mgoITCfg.StorDbCfg().Port, mgoITCfg.StorDbCfg().Name,
|
||||
mgoITCfg.StorDbCfg().User, mgoITCfg.StorDbCfg().Password,
|
||||
mgoITCfg.GeneralCfg().DBDataEncoding,
|
||||
utils.StorDB, nil, false, 10*time.Second)
|
||||
utils.StorDB, nil, 10*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal("Could not connect to Mongo", err.Error())
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ func TestFilterIndexerIT(t *testing.T) {
|
||||
mgoITCfg.StorDbCfg().Port, mgoITCfg.StorDbCfg().Name,
|
||||
mgoITCfg.StorDbCfg().User, mgoITCfg.StorDbCfg().Password,
|
||||
mgoITCfg.GeneralCfg().DBDataEncoding,
|
||||
utils.StorDB, nil, false, 10*time.Second)
|
||||
utils.StorDB, nil, 10*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ func TestOnStorIT(t *testing.T) {
|
||||
mgoITCfg.StorDbCfg().Port, mgoITCfg.StorDbCfg().Name,
|
||||
mgoITCfg.StorDbCfg().User, mgoITCfg.StorDbCfg().Password,
|
||||
mgoITCfg.GeneralCfg().DBDataEncoding,
|
||||
utils.StorDB, nil, false, 10*time.Second); err != nil {
|
||||
utils.StorDB, nil, 10*time.Second); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
onStorCfg = mgoITCfg.StorDbCfg().Name
|
||||
|
||||
@@ -87,7 +87,7 @@ func TestStorDBit(t *testing.T) {
|
||||
cfg.StorDbCfg().Port, cfg.StorDbCfg().Name,
|
||||
cfg.StorDbCfg().User, cfg.StorDbCfg().Password,
|
||||
cfg.GeneralCfg().DBDataEncoding,
|
||||
utils.StorDB, cfg.StorDbCfg().StringIndexedFields, false, 10*time.Second); err != nil {
|
||||
utils.StorDB, cfg.StorDbCfg().StringIndexedFields, 10*time.Second); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case utils.MetaPostgres:
|
||||
|
||||
Reference in New Issue
Block a user