diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index f32d932f6..e636ea189 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -59,13 +59,11 @@ var sTestsOnStorIT = []func(t *testing.T){ testOnStorITRatingProfile, testOnStorITCRUDDestinations, testOnStorITCRUDReverseDestinations, - testOnStorITLCR, testOnStorITActions, testOnStorITSharedGroup, testOnStorITCRUDActionPlan, testOnStorITCRUDAccountActionPlans, testOnStorITCRUDAccount, - testOnStorITCRUDCdrStatsQueue, testOnStorITCRUDSubscribers, testOnStorITResource, testOnStorITResourceProfile, @@ -109,25 +107,25 @@ func TestOnStorITRedis(t *testing.T) { } } -func TestOnStorITMongo(t *testing.T) { - sleepDelay = 500 * time.Millisecond - cdrsMongoCfgPath := path.Join(*dataDir, "conf", "samples", "cdrsv2mongo") - mgoITCfg, err := config.NewCGRConfigFromFolder(cdrsMongoCfgPath) - if err != nil { - t.Fatal(err) - } - if mgoITdb, err = NewMongoStorageOld(mgoITCfg.StorDbCfg().StorDBHost, - mgoITCfg.StorDbCfg().StorDBPort, mgoITCfg.StorDbCfg().StorDBName, - mgoITCfg.StorDbCfg().StorDBUser, mgoITCfg.StorDbCfg().StorDBPass, - utils.StorDB, nil, mgoITCfg.CacheCfg()); err != nil { - t.Fatal(err) - } - onStorCfg = mgoITCfg.StorDbCfg().StorDBName - onStor = NewDataManager(mgoITdb) - for _, stest := range sTestsOnStorIT { - t.Run("TestOnStorITMongo", stest) - } -} +// func TestOnStorITMongo(t *testing.T) { +// sleepDelay = 500 * time.Millisecond +// cdrsMongoCfgPath := path.Join(*dataDir, "conf", "samples", "cdrsv2mongo") +// mgoITCfg, err := config.NewCGRConfigFromFolder(cdrsMongoCfgPath) +// if err != nil { +// t.Fatal(err) +// } +// if mgoITdb, err = NewMongoStorage(mgoITCfg.StorDbCfg().StorDBHost, +// mgoITCfg.StorDbCfg().StorDBPort, mgoITCfg.StorDbCfg().StorDBName, +// mgoITCfg.StorDbCfg().StorDBUser, mgoITCfg.StorDbCfg().StorDBPass, +// utils.StorDB, nil, mgoITCfg.CacheCfg()); err != nil { +// t.Fatal(err) +// } +// onStorCfg = mgoITCfg.StorDbCfg().StorDBName +// onStor = NewDataManager(mgoITdb) +// for _, stest := range sTestsOnStorIT { +// t.Run("TestOnStorITMongo", stest) +// } +// } func TestOnStorITMongo2(t *testing.T) { sleepDelay = 500 * time.Millisecond @@ -717,24 +715,18 @@ func testOnStorITRatingProfile(t *testing.T) { if rcv, err := onStor.GetRatingProfile(rpf.Id, false, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() - if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) } + //get from database if rcv, err := onStor.GetRatingProfile(rpf.Id, true, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() - if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) } + expectedCRPl := []string{"rpf_*out:test:1:trp"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.RATING_PROFILE_PREFIX); err != nil { t.Error(err) @@ -758,23 +750,15 @@ func testOnStorITRatingProfile(t *testing.T) { if rcv, err := onStor.GetRatingProfile(rpf.Id, false, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() - if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetRatingProfile(rpf.Id, true, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.RatingPlanActivations[0].ActivationTime = rcv.RatingPlanActivations[0].ActivationTime.UTC() - if !reflect.DeepEqual(rpf, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(rpf, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rpf), utils.ToJSON(rcv)) } if err = onStor.RemoveRatingProfile(rpf.Id, utils.NonTransactional); err != nil { t.Error(err) @@ -1563,14 +1547,15 @@ func testOnStorITResourceProfile(t *testing.T) { true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(rL, rcv) { - t.Errorf("Expecting: %v, received: %v", rL, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rL), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetResourceProfile(rL.Tenant, rL.ID, false, true, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(rL, rcv) { - t.Errorf("Expecting: %v, received: %v", rL, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rL), utils.ToJSON(rcv)) + } expectedR := []string{"rsp_cgrates.org:RL_TEST2"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.ResourceProfilesPrefix); err != nil { @@ -1589,15 +1574,16 @@ func testOnStorITResourceProfile(t *testing.T) { true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(rL, rcv) { - t.Errorf("Expecting: %v, received: %v", rL, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rL), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetResourceProfile(rL.Tenant, rL.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(rL, rcv) { - t.Errorf("Expecting: %v, received: %v", rL, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(rL), utils.ToJSON(rcv)) } + if err := onStor.RemoveResourceProfile(rL.Tenant, rL.ID, utils.NonTransactional, false); err != nil { t.Error(err) @@ -1639,14 +1625,15 @@ func testOnStorITResource(t *testing.T) { true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(res, rcv)) { - t.Errorf("Expecting: %v, received: %v", res, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(res), utils.ToJSON(rcv)) } + //get from database if rcv, err := onStor.GetResource("cgrates.org", "RL1", false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(res, rcv)) { - t.Errorf("Expecting: %v, received: %v", res, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(res), utils.ToJSON(rcv)) } expectedT := []string{"res_cgrates.org:RL1"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.ResourcesPrefix); err != nil { @@ -1665,15 +1652,16 @@ func testOnStorITResource(t *testing.T) { true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(res, rcv)) { - t.Errorf("Expecting: %v, received: %v", res, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(res), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetResource("cgrates.org", "RL1", false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(res, rcv)) { - t.Errorf("Expecting: %v, received: %v", res, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(res), utils.ToJSON(rcv)) } + if err := onStor.RemoveResource(res.Tenant, res.ID, utils.NonTransactional); err != nil { t.Error(err) } @@ -1766,7 +1754,7 @@ func testOnStorITCRUDHistory(t *testing.T) { if rcv, err := onStor.DataDB().GetLoadHistory(1, true, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(ist, rcv[0]) { - t.Errorf("Expecting: %v, received: %v", ist, rcv[0]) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(ist), utils.ToJSON(rcv[0])) } } @@ -1774,8 +1762,14 @@ func testOnStorITCRUDStructVersion(t *testing.T) { if _, err := onStor.DataDB().GetVersions(utils.Accounts); err != utils.ErrNotFound { t.Error(err) } - vrs := Versions{utils.Accounts: 3, utils.Actions: 2, utils.ActionTriggers: 2, - utils.ActionPlans: 2, utils.SharedGroups: 2, utils.CostDetails: 1} + vrs := Versions{ + utils.Accounts: 3, + utils.Actions: 2, + utils.ActionTriggers: 2, + utils.ActionPlans: 2, + utils.SharedGroups: 2, + utils.CostDetails: 1, + } if err := onStor.DataDB().SetVersions(vrs, false); err != nil { t.Error(err) } @@ -1855,14 +1849,14 @@ func testOnStorITStatQueueProfile(t *testing.T) { sq.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(sq, rcv) { - t.Errorf("Expecting: %v, received: %v", sq, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(sq), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetStatQueueProfile(sq.Tenant, sq.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(sq, rcv) { - t.Errorf("Expecting: %v, received: %v", sq, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(sq), utils.ToJSON(rcv)) } expectedR := []string{"sqp_cgrates.org:test"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.StatQueueProfilePrefix); err != nil { @@ -1941,14 +1935,14 @@ func testOnStorITStatQueue(t *testing.T) { sq.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(sq, rcv) { - t.Errorf("Expecting: %v, received: %v", sq, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(sq), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetStatQueue(sq.Tenant, sq.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(sq, rcv) { - t.Errorf("Expecting: %v, received: %v", sq, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(sq), utils.ToJSON(rcv)) } expectedT := []string{"stq_cgrates.org:Test_StatQueue"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.StatQueuePrefix); err != nil { @@ -1977,14 +1971,14 @@ func testOnStorITStatQueue(t *testing.T) { sq.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(sq, rcv) { - t.Errorf("Expecting: %v, received: %v", sq, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(sq), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetStatQueue(sq.Tenant, sq.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !reflect.DeepEqual(sq, rcv) { - t.Errorf("Expecting: %v, received: %v", sq, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(sq), utils.ToJSON(rcv)) } if err := onStor.RemoveStatQueue(sq.Tenant, sq.ID, utils.NonTransactional); err != nil { @@ -2043,25 +2037,15 @@ func testOnStorITThresholdProfile(t *testing.T) { if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() - rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() - if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() - rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() - if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } expectedR := []string{"thp_cgrates.org:test"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.ThresholdProfilePrefix); err != nil { @@ -2079,25 +2063,15 @@ func testOnStorITThresholdProfile(t *testing.T) { if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, true, false, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() - rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() - if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetThresholdProfile(th.Tenant, th.ID, false, false, utils.NonTransactional); err != nil { t.Error(err) - } else { - //convert to UTC for mongo that stores the Date as ISODate - rcv.ActivationInterval.ActivationTime = rcv.ActivationInterval.ActivationTime.UTC() - rcv.ActivationInterval.ExpiryTime = rcv.ActivationInterval.ExpiryTime.UTC() - if !reflect.DeepEqual(th, rcv) { - t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) - } + } else if !reflect.DeepEqual(th, rcv) { + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } if err := onStor.RemoveThresholdProfile(th.Tenant, th.ID, utils.NonTransactional, false); err != nil { @@ -2134,14 +2108,14 @@ func testOnStorITThreshold(t *testing.T) { true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(th, rcv)) { - t.Errorf("Expecting: %v, received: %v", th, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetThreshold("cgrates.org", "TH1", false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(th, rcv)) { - t.Errorf("Expecting: %v, received: %v", th, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } expectedT := []string{"thd_cgrates.org:TH1"} if itm, err := onStor.DataDB().GetKeysForPrefix(utils.ThresholdPrefix); err != nil { @@ -2160,14 +2134,14 @@ func testOnStorITThreshold(t *testing.T) { true, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(th, rcv)) { - t.Errorf("Expecting: %v, received: %v", th, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } //get from database if rcv, err := onStor.GetThreshold("cgrates.org", "TH1", false, false, utils.NonTransactional); err != nil { t.Error(err) } else if !(reflect.DeepEqual(th, rcv)) { - t.Errorf("Expecting: %v, received: %v", th, rcv) + t.Errorf("Expecting: %v, received: %v", utils.ToJSON(th), utils.ToJSON(rcv)) } if err := onStor.RemoveThreshold(th.Tenant, th.ID, utils.NonTransactional); err != nil { t.Error(err) diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 3cee1203a..eba585903 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -97,7 +97,7 @@ var ( ) func NewMongoStorageOld(host, port, db, user, pass, storageType string, - cdrsIndexes []string, cacheCfg config.CacheCfg) (ms *MongoStorage, err error) { + cdrsIndexes []string, cacheCfg config.CacheCfg) (ms *MongoStorageOld, err error) { url := host if port != "" { url += ":" + port @@ -115,13 +115,22 @@ func NewMongoStorageOld(host, port, db, user, pass, storageType string, return nil, err } session.SetMode(mgo.Strong, true) - ms = &MongoStorage{db: dbName, session: session, storageType: storageType, ms: NewCodecMsgpackMarshaler(), + ms = &MongoStorageOld{db: dbName, session: session, storageType: storageType, ms: NewCodecMsgpackMarshaler(), cacheCfg: cacheCfg, cdrsIndexes: cdrsIndexes} + + if cNames, err := session.DB(ms.db).CollectionNames(); err != nil { + return nil, err + } else if len(cNames) == 0 { // create indexes only if database is empty + if err = ms.EnsureIndexes(); err != nil { + return nil, err + } + } + ms.cnter = utils.NewCounter(time.Now().UnixNano(), 0) return } -type MongoStorage struct { +type MongoStorageOld struct { session *mgo.Session db string storageType string // datadb, stordb @@ -131,14 +140,13 @@ type MongoStorage struct { cnter *utils.Counter } -func (ms *MongoStorage) conn(col string) (*mgo.Session, *mgo.Collection) { +func (ms *MongoStorageOld) conn(col string) (*mgo.Session, *mgo.Collection) { sessionCopy := ms.session.Copy() return sessionCopy, sessionCopy.DB(ms.db).C(col) } -/* // EnsureIndexes creates db indexes -func (ms *MongoStorage) EnsureIndexes() (err error) { +func (ms *MongoStorageOld) EnsureIndexes() (err error) { dbSession := ms.session.Copy() defer dbSession.Close() db := dbSession.DB(ms.db) @@ -153,7 +161,6 @@ func (ms *MongoStorage) EnsureIndexes() (err error) { for _, col := range []string{colAct, colApl, colAAp, colAtr, colDcs, colRpl, colDst, colRds, colAls, colUsr, colLht} { if err = db.C(col).EnsureIndex(idx); err != nil { - return } } @@ -295,9 +302,9 @@ func (ms *MongoStorage) EnsureIndexes() (err error) { } } return -}//*/ +} -func (ms *MongoStorage) getColNameForPrefix(prefix string) (name string, ok bool) { +func (ms *MongoStorageOld) getColNameForPrefix(prefix string) (name string, ok bool) { colMap := map[string]string{ utils.DESTINATION_PREFIX: colDst, utils.REVERSE_DESTINATION_PREFIX: colRds, @@ -332,31 +339,31 @@ func (ms *MongoStorage) getColNameForPrefix(prefix string) (name string, ok bool return } -func (ms *MongoStorage) Close() { +func (ms *MongoStorageOld) Close() { ms.session.Close() } -func (ms *MongoStorage) Flush(ignore string) (err error) { +func (ms *MongoStorageOld) Flush(ignore string) (err error) { dbSession := ms.session.Copy() defer dbSession.Close() return dbSession.DB(ms.db).DropDatabase() } -func (ms *MongoStorage) Marshaler() Marshaler { +func (ms *MongoStorageOld) Marshaler() Marshaler { return ms.ms } // DB returnes a database object with cloned session inside -func (ms *MongoStorage) DB() *mgo.Database { +func (ms *MongoStorageOld) DB() *mgo.Database { return ms.session.Copy().DB(ms.db) } -func (ms *MongoStorage) SelectDatabase(dbName string) (err error) { +func (ms *MongoStorageOld) SelectDatabase(dbName string) (err error) { ms.db = dbName return } -func (ms *MongoStorage) RebuildReverseForPrefix(prefix string) (err error) { +func (ms *MongoStorageOld) RebuildReverseForPrefix(prefix string) (err error) { if !utils.IsSliceMember([]string{utils.REVERSE_DESTINATION_PREFIX, utils.REVERSE_ALIASES_PREFIX, utils.AccountActionPlansPrefix}, prefix) { return utils.ErrInvalidKey @@ -417,7 +424,7 @@ func (ms *MongoStorage) RebuildReverseForPrefix(prefix string) (err error) { return nil } -func (ms *MongoStorage) RemoveReverseForPrefix(prefix string) (err error) { +func (ms *MongoStorageOld) RemoveReverseForPrefix(prefix string) (err error) { if !utils.IsSliceMember([]string{utils.REVERSE_DESTINATION_PREFIX, utils.REVERSE_ALIASES_PREFIX, utils.AccountActionPlansPrefix}, prefix) { return utils.ErrInvalidKey @@ -478,7 +485,7 @@ func (ms *MongoStorage) RemoveReverseForPrefix(prefix string) (err error) { return nil } -func (ms *MongoStorage) IsDBEmpty() (resp bool, err error) { +func (ms *MongoStorageOld) IsDBEmpty() (resp bool, err error) { session := ms.session.Copy() defer session.Close() db := session.DB(ms.db) @@ -489,7 +496,7 @@ func (ms *MongoStorage) IsDBEmpty() (resp bool, err error) { return len(cols) == 0 || cols[0] == "cdrs", nil } -func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err error) { +func (ms *MongoStorageOld) GetKeysForPrefix(prefix string) (result []string, err error) { var category, subject string keyLen := len(utils.DESTINATION_PREFIX) if len(prefix) < keyLen { @@ -700,7 +707,7 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err er return } -func (ms *MongoStorage) HasDataDrv(category, subject, tenant string) (has bool, err error) { +func (ms *MongoStorageOld) HasDataDrv(category, subject, tenant string) (has bool, err error) { session := ms.session.Copy() defer session.Close() db := session.DB(ms.db) @@ -757,7 +764,7 @@ func (ms *MongoStorage) HasDataDrv(category, subject, tenant string) (has bool, return } -func (ms *MongoStorage) GetRatingPlanDrv(key string) (rp *RatingPlan, err error) { +func (ms *MongoStorageOld) GetRatingPlanDrv(key string) (rp *RatingPlan, err error) { var kv struct { Key string Value []byte @@ -786,7 +793,7 @@ func (ms *MongoStorage) GetRatingPlanDrv(key string) (rp *RatingPlan, err error) return } -func (ms *MongoStorage) SetRatingPlanDrv(rp *RatingPlan) error { +func (ms *MongoStorageOld) SetRatingPlanDrv(rp *RatingPlan) error { result, err := ms.ms.Marshal(rp) if err != nil { return err @@ -804,7 +811,7 @@ func (ms *MongoStorage) SetRatingPlanDrv(rp *RatingPlan) error { return err } -func (ms *MongoStorage) RemoveRatingPlanDrv(key string) error { +func (ms *MongoStorageOld) RemoveRatingPlanDrv(key string) error { session, col := ms.conn(colRpl) defer session.Close() var kv struct { @@ -833,7 +840,7 @@ func (ms *MongoStorage) RemoveRatingPlanDrv(key string) error { return iter.Close() } -func (ms *MongoStorage) GetRatingProfileDrv(key string) (rp *RatingProfile, err error) { +func (ms *MongoStorageOld) GetRatingProfileDrv(key string) (rp *RatingProfile, err error) { session, col := ms.conn(colRpf) defer session.Close() if err = col.Find(bson.M{"id": key}).One(&rp); err != nil { @@ -845,7 +852,7 @@ func (ms *MongoStorage) GetRatingProfileDrv(key string) (rp *RatingProfile, err return } -func (ms *MongoStorage) SetRatingProfileDrv(rp *RatingProfile) (err error) { +func (ms *MongoStorageOld) SetRatingProfileDrv(rp *RatingProfile) (err error) { session, col := ms.conn(colRpf) defer session.Close() if _, err = col.Upsert(bson.M{"id": rp.Id}, rp); err != nil { @@ -854,7 +861,7 @@ func (ms *MongoStorage) SetRatingProfileDrv(rp *RatingProfile) (err error) { return } -func (ms *MongoStorage) RemoveRatingProfileDrv(key string) error { +func (ms *MongoStorageOld) RemoveRatingProfileDrv(key string) error { session, col := ms.conn(colRpf) defer session.Close() iter := col.Find(bson.M{"id": key}).Select(bson.M{"id": 1}).Iter() @@ -867,7 +874,7 @@ func (ms *MongoStorage) RemoveRatingProfileDrv(key string) error { return iter.Close() } -func (ms *MongoStorage) GetDestination(key string, skipCache bool, +func (ms *MongoStorageOld) GetDestination(key string, skipCache bool, transactionID string) (result *Destination, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheDestinations, key); ok { @@ -910,7 +917,7 @@ func (ms *MongoStorage) GetDestination(key string, skipCache bool, return } -func (ms *MongoStorage) SetDestination(dest *Destination, transactionID string) (err error) { +func (ms *MongoStorageOld) SetDestination(dest *Destination, transactionID string) (err error) { result, err := ms.ms.Marshal(dest) if err != nil { return err @@ -930,7 +937,7 @@ func (ms *MongoStorage) SetDestination(dest *Destination, transactionID string) return } -func (ms *MongoStorage) GetReverseDestination(prefix string, skipCache bool, +func (ms *MongoStorageOld) GetReverseDestination(prefix string, skipCache bool, transactionID string) (ids []string, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheReverseDestinations, prefix); ok { @@ -960,7 +967,7 @@ func (ms *MongoStorage) GetReverseDestination(prefix string, skipCache bool, return } -func (ms *MongoStorage) SetReverseDestination(dest *Destination, +func (ms *MongoStorageOld) SetReverseDestination(dest *Destination, transactionID string) (err error) { session, col := ms.conn(colRds) defer session.Close() @@ -973,7 +980,7 @@ func (ms *MongoStorage) SetReverseDestination(dest *Destination, return } -func (ms *MongoStorage) RemoveDestination(destID string, +func (ms *MongoStorageOld) RemoveDestination(destID string, transactionID string) (err error) { session, col := ms.conn(colDst) // get destination for prefix list @@ -1004,7 +1011,7 @@ func (ms *MongoStorage) RemoveDestination(destID string, return } -func (ms *MongoStorage) UpdateReverseDestination(oldDest, newDest *Destination, +func (ms *MongoStorageOld) UpdateReverseDestination(oldDest, newDest *Destination, transactionID string) error { session, col := ms.conn(colRds) defer session.Close() @@ -1065,7 +1072,7 @@ func (ms *MongoStorage) UpdateReverseDestination(oldDest, newDest *Destination, return nil } -func (ms *MongoStorage) GetActionsDrv(key string) (as Actions, err error) { +func (ms *MongoStorageOld) GetActionsDrv(key string) (as Actions, err error) { var result struct { Key string Value Actions @@ -1082,7 +1089,7 @@ func (ms *MongoStorage) GetActionsDrv(key string) (as Actions, err error) { return } -func (ms *MongoStorage) SetActionsDrv(key string, as Actions) error { +func (ms *MongoStorageOld) SetActionsDrv(key string, as Actions) error { session, col := ms.conn(colAct) defer session.Close() _, err := col.Upsert(bson.M{"key": key}, &struct { @@ -1092,14 +1099,14 @@ func (ms *MongoStorage) SetActionsDrv(key string, as Actions) error { return err } -func (ms *MongoStorage) RemoveActionsDrv(key string) error { +func (ms *MongoStorageOld) RemoveActionsDrv(key string) error { session, col := ms.conn(colAct) defer session.Close() err := col.Remove(bson.M{"key": key}) return err } -func (ms *MongoStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err error) { +func (ms *MongoStorageOld) GetSharedGroupDrv(key string) (sg *SharedGroup, err error) { session, col := ms.conn(colShg) defer session.Close() if err = col.Find(bson.M{"id": key}).One(&sg); err != nil { @@ -1111,7 +1118,7 @@ func (ms *MongoStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err erro return } -func (ms *MongoStorage) SetSharedGroupDrv(sg *SharedGroup) (err error) { +func (ms *MongoStorageOld) SetSharedGroupDrv(sg *SharedGroup) (err error) { session, col := ms.conn(colShg) defer session.Close() if _, err = col.Upsert(bson.M{"id": sg.Id}, sg); err != nil { @@ -1120,14 +1127,14 @@ func (ms *MongoStorage) SetSharedGroupDrv(sg *SharedGroup) (err error) { return } -func (ms *MongoStorage) RemoveSharedGroupDrv(id, transactionID string) (err error) { +func (ms *MongoStorageOld) RemoveSharedGroupDrv(id, transactionID string) (err error) { session, col := ms.conn(colShg) defer session.Close() err = col.Remove(bson.M{"id": id}) return err } -func (ms *MongoStorage) GetAccount(key string) (result *Account, err error) { +func (ms *MongoStorageOld) GetAccount(key string) (result *Account, err error) { result = new(Account) session, col := ms.conn(colAcc) defer session.Close() @@ -1139,7 +1146,7 @@ func (ms *MongoStorage) GetAccount(key string) (result *Account, err error) { return } -func (ms *MongoStorage) SetAccount(acc *Account) error { +func (ms *MongoStorageOld) SetAccount(acc *Account) error { // never override existing account with an empty one // UPDATE: if all balances expired and were cleaned it makes // sense to write empty balance map @@ -1158,7 +1165,7 @@ func (ms *MongoStorage) SetAccount(acc *Account) error { return err } -func (ms *MongoStorage) RemoveAccount(key string) (err error) { +func (ms *MongoStorageOld) RemoveAccount(key string) (err error) { session, col := ms.conn(colAcc) defer session.Close() if err = col.Remove(bson.M{"id": key}); err == mgo.ErrNotFound { @@ -1167,7 +1174,7 @@ func (ms *MongoStorage) RemoveAccount(key string) (err error) { return } -func (ms *MongoStorage) GetSubscribersDrv() (result map[string]*SubscriberData, err error) { +func (ms *MongoStorageOld) GetSubscribersDrv() (result map[string]*SubscriberData, err error) { session, col := ms.conn(colPbs) defer session.Close() iter := col.Find(nil).Iter() @@ -1183,7 +1190,7 @@ func (ms *MongoStorage) GetSubscribersDrv() (result map[string]*SubscriberData, return } -func (ms *MongoStorage) SetSubscriberDrv(key string, sub *SubscriberData) (err error) { +func (ms *MongoStorageOld) SetSubscriberDrv(key string, sub *SubscriberData) (err error) { session, col := ms.conn(colPbs) defer session.Close() _, err = col.Upsert(bson.M{"key": key}, &struct { @@ -1193,13 +1200,13 @@ func (ms *MongoStorage) SetSubscriberDrv(key string, sub *SubscriberData) (err e return err } -func (ms *MongoStorage) RemoveSubscriberDrv(key string) (err error) { +func (ms *MongoStorageOld) RemoveSubscriberDrv(key string) (err error) { session, col := ms.conn(colPbs) defer session.Close() return col.Remove(bson.M{"key": key}) } -func (ms *MongoStorage) SetUserDrv(up *UserProfile) (err error) { +func (ms *MongoStorageOld) SetUserDrv(up *UserProfile) (err error) { session, col := ms.conn(colUsr) defer session.Close() _, err = col.Upsert(bson.M{"key": up.GetId()}, &struct { @@ -1209,7 +1216,7 @@ func (ms *MongoStorage) SetUserDrv(up *UserProfile) (err error) { return err } -func (ms *MongoStorage) GetUserDrv(key string) (up *UserProfile, err error) { +func (ms *MongoStorageOld) GetUserDrv(key string) (up *UserProfile, err error) { var kv struct { Key string Value *UserProfile @@ -1226,7 +1233,7 @@ func (ms *MongoStorage) GetUserDrv(key string) (up *UserProfile, err error) { return } -func (ms *MongoStorage) GetUsersDrv() (result []*UserProfile, err error) { +func (ms *MongoStorageOld) GetUsersDrv() (result []*UserProfile, err error) { session, col := ms.conn(colUsr) defer session.Close() iter := col.Find(nil).Iter() @@ -1241,13 +1248,13 @@ func (ms *MongoStorage) GetUsersDrv() (result []*UserProfile, err error) { return } -func (ms *MongoStorage) RemoveUserDrv(key string) (err error) { +func (ms *MongoStorageOld) RemoveUserDrv(key string) (err error) { session, col := ms.conn(colUsr) defer session.Close() return col.Remove(bson.M{"key": key}) } -func (ms *MongoStorage) GetAlias(key string, skipCache bool, +func (ms *MongoStorageOld) GetAlias(key string, skipCache bool, transactionID string) (al *Alias, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheAliases, key); ok { @@ -1280,7 +1287,7 @@ func (ms *MongoStorage) GetAlias(key string, skipCache bool, return } -func (ms *MongoStorage) SetAlias(al *Alias, transactionID string) (err error) { +func (ms *MongoStorageOld) SetAlias(al *Alias, transactionID string) (err error) { session, col := ms.conn(colAls) defer session.Close() if _, err = col.Upsert(bson.M{"key": al.GetId()}, &struct { @@ -1292,7 +1299,7 @@ func (ms *MongoStorage) SetAlias(al *Alias, transactionID string) (err error) { return err } -func (ms *MongoStorage) GetReverseAlias(reverseID string, skipCache bool, +func (ms *MongoStorageOld) GetReverseAlias(reverseID string, skipCache bool, transactionID string) (ids []string, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheReverseAliases, reverseID); ok { @@ -1322,7 +1329,7 @@ func (ms *MongoStorage) GetReverseAlias(reverseID string, skipCache bool, return } -func (ms *MongoStorage) SetReverseAlias(al *Alias, transactionID string) (err error) { +func (ms *MongoStorageOld) SetReverseAlias(al *Alias, transactionID string) (err error) { session, col := ms.conn(colRCfgs) defer session.Close() for _, value := range al.Values { @@ -1339,7 +1346,7 @@ func (ms *MongoStorage) SetReverseAlias(al *Alias, transactionID string) (err er return } -func (ms *MongoStorage) RemoveAlias(key, transactionID string) (err error) { +func (ms *MongoStorageOld) RemoveAlias(key, transactionID string) (err error) { al := &Alias{} al.SetId(key) origKey := key @@ -1385,7 +1392,7 @@ func (ms *MongoStorage) RemoveAlias(key, transactionID string) (err error) { } // Limit will only retrieve the last n items out of history, newest first -func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool, +func (ms *MongoStorageOld) GetLoadHistory(limit int, skipCache bool, transactionID string) (loadInsts []*utils.LoadInstance, err error) { if limit == 0 { return nil, nil @@ -1422,7 +1429,7 @@ func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool, } // Adds a single load instance to load history -func (ms *MongoStorage) AddLoadHistory(ldInst *utils.LoadInstance, +func (ms *MongoStorageOld) AddLoadHistory(ldInst *utils.LoadInstance, loadHistSize int, transactionID string) error { if loadHistSize == 0 { // Load history disabled return nil @@ -1470,7 +1477,7 @@ func (ms *MongoStorage) AddLoadHistory(ldInst *utils.LoadInstance, return err } -func (ms *MongoStorage) GetActionTriggersDrv(key string) (atrs ActionTriggers, err error) { +func (ms *MongoStorageOld) GetActionTriggersDrv(key string) (atrs ActionTriggers, err error) { var kv struct { Key string Value ActionTriggers @@ -1487,7 +1494,7 @@ func (ms *MongoStorage) GetActionTriggersDrv(key string) (atrs ActionTriggers, e return } -func (ms *MongoStorage) SetActionTriggersDrv(key string, atrs ActionTriggers) (err error) { +func (ms *MongoStorageOld) SetActionTriggersDrv(key string, atrs ActionTriggers) (err error) { session, col := ms.conn(colAtr) defer session.Close() if len(atrs) == 0 { @@ -1504,14 +1511,14 @@ func (ms *MongoStorage) SetActionTriggersDrv(key string, atrs ActionTriggers) (e return err } -func (ms *MongoStorage) RemoveActionTriggersDrv(key string) error { +func (ms *MongoStorageOld) RemoveActionTriggersDrv(key string) error { session, col := ms.conn(colAtr) defer session.Close() err := col.Remove(bson.M{"key": key}) return err } -func (ms *MongoStorage) GetActionPlan(key string, skipCache bool, +func (ms *MongoStorageOld) GetActionPlan(key string, skipCache bool, transactionID string) (ats *ActionPlan, err error) { if !skipCache { if x, err := Cache.GetCloned(utils.CacheActionPlans, key); err != nil { @@ -1556,7 +1563,7 @@ func (ms *MongoStorage) GetActionPlan(key string, skipCache bool, return } -func (ms *MongoStorage) SetActionPlan(key string, ats *ActionPlan, +func (ms *MongoStorageOld) SetActionPlan(key string, ats *ActionPlan, overwrite bool, transactionID string) (err error) { session, col := ms.conn(colApl) defer session.Close() @@ -1598,7 +1605,7 @@ func (ms *MongoStorage) SetActionPlan(key string, ats *ActionPlan, return err } -func (ms *MongoStorage) RemoveActionPlan(key string, transactionID string) error { +func (ms *MongoStorageOld) RemoveActionPlan(key string, transactionID string) error { session, col := ms.conn(colApl) defer session.Close() cCommit := cacheCommit(transactionID) @@ -1610,7 +1617,7 @@ func (ms *MongoStorage) RemoveActionPlan(key string, transactionID string) error return err } -func (ms *MongoStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) { +func (ms *MongoStorageOld) GetAllActionPlans() (ats map[string]*ActionPlan, err error) { keys, err := ms.GetKeysForPrefix(utils.ACTION_PLAN_PREFIX) if err != nil { return nil, err @@ -1628,7 +1635,7 @@ func (ms *MongoStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err err return } -func (ms *MongoStorage) GetAccountActionPlans(acntID string, skipCache bool, transactionID string) (aPlIDs []string, err error) { +func (ms *MongoStorageOld) GetAccountActionPlans(acntID string, skipCache bool, transactionID string) (aPlIDs []string, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheAccountActionPlans, acntID); ok { if x == nil { @@ -1657,7 +1664,7 @@ func (ms *MongoStorage) GetAccountActionPlans(acntID string, skipCache bool, tra return } -func (ms *MongoStorage) SetAccountActionPlans(acntID string, aPlIDs []string, overwrite bool) (err error) { +func (ms *MongoStorageOld) SetAccountActionPlans(acntID string, aPlIDs []string, overwrite bool) (err error) { session, col := ms.conn(colAAp) defer session.Close() if !overwrite { @@ -1678,7 +1685,7 @@ func (ms *MongoStorage) SetAccountActionPlans(acntID string, aPlIDs []string, ov return } -func (ms *MongoStorage) RemAccountActionPlans(acntID string, aPlIDs []string) (err error) { +func (ms *MongoStorageOld) RemAccountActionPlans(acntID string, aPlIDs []string) (err error) { session, col := ms.conn(colAAp) defer session.Close() if len(aPlIDs) == 0 { @@ -1709,13 +1716,13 @@ func (ms *MongoStorage) RemAccountActionPlans(acntID string, aPlIDs []string) (e return } -func (ms *MongoStorage) PushTask(t *Task) error { +func (ms *MongoStorageOld) PushTask(t *Task) error { session, col := ms.conn(colTsk) defer session.Close() return col.Insert(bson.M{"_id": bson.NewObjectId(), "task": t}) } -func (ms *MongoStorage) PopTask() (t *Task, err error) { +func (ms *MongoStorageOld) PopTask() (t *Task, err error) { v := struct { ID bson.ObjectId `bson:"_id"` Task *Task @@ -1732,7 +1739,7 @@ func (ms *MongoStorage) PopTask() (t *Task, err error) { return } -func (ms *MongoStorage) GetDerivedChargersDrv(key string) (dcs *utils.DerivedChargers, err error) { +func (ms *MongoStorageOld) GetDerivedChargersDrv(key string) (dcs *utils.DerivedChargers, err error) { var kv struct { Key string Value *utils.DerivedChargers @@ -1749,7 +1756,7 @@ func (ms *MongoStorage) GetDerivedChargersDrv(key string) (dcs *utils.DerivedCha return } -func (ms *MongoStorage) SetDerivedChargers(key string, +func (ms *MongoStorageOld) SetDerivedChargers(key string, dcs *utils.DerivedChargers, transactionID string) (err error) { cCommit := cacheCommit(transactionID) if dcs == nil || len(dcs.Chargers) == 0 { @@ -1772,7 +1779,7 @@ func (ms *MongoStorage) SetDerivedChargers(key string, return err } -func (ms *MongoStorage) RemoveDerivedChargersDrv(id, transactionID string) (err error) { +func (ms *MongoStorageOld) RemoveDerivedChargersDrv(id, transactionID string) (err error) { cCommit := cacheCommit(transactionID) session, col := ms.conn(colDcs) defer session.Close() @@ -1783,7 +1790,7 @@ func (ms *MongoStorage) RemoveDerivedChargersDrv(id, transactionID string) (err return nil } -func (ms *MongoStorage) GetResourceProfileDrv(tenant, id string) (rp *ResourceProfile, err error) { +func (ms *MongoStorageOld) GetResourceProfileDrv(tenant, id string) (rp *ResourceProfile, err error) { session, col := ms.conn(colRsP) defer session.Close() rp = new(ResourceProfile) @@ -1796,14 +1803,14 @@ func (ms *MongoStorage) GetResourceProfileDrv(tenant, id string) (rp *ResourcePr return } -func (ms *MongoStorage) SetResourceProfileDrv(rp *ResourceProfile) (err error) { +func (ms *MongoStorageOld) SetResourceProfileDrv(rp *ResourceProfile) (err error) { session, col := ms.conn(colRsP) defer session.Close() _, err = col.Upsert(bson.M{"tenant": rp.Tenant, "id": rp.ID}, rp) return } -func (ms *MongoStorage) RemoveResourceProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveResourceProfileDrv(tenant, id string) (err error) { session, col := ms.conn(colRsP) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { @@ -1812,7 +1819,7 @@ func (ms *MongoStorage) RemoveResourceProfileDrv(tenant, id string) (err error) return nil } -func (ms *MongoStorage) GetResourceDrv(tenant, id string) (r *Resource, err error) { +func (ms *MongoStorageOld) GetResourceDrv(tenant, id string) (r *Resource, err error) { session, col := ms.conn(colRes) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&r); err != nil { @@ -1824,14 +1831,14 @@ func (ms *MongoStorage) GetResourceDrv(tenant, id string) (r *Resource, err erro return } -func (ms *MongoStorage) SetResourceDrv(r *Resource) (err error) { +func (ms *MongoStorageOld) SetResourceDrv(r *Resource) (err error) { session, col := ms.conn(colRes) defer session.Close() _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) return } -func (ms *MongoStorage) RemoveResourceDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveResourceDrv(tenant, id string) (err error) { session, col := ms.conn(colRes) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { @@ -1840,7 +1847,7 @@ func (ms *MongoStorage) RemoveResourceDrv(tenant, id string) (err error) { return nil } -func (ms *MongoStorage) GetTimingDrv(id string) (t *utils.TPTiming, err error) { +func (ms *MongoStorageOld) GetTimingDrv(id string) (t *utils.TPTiming, err error) { session, col := ms.conn(colTmg) defer session.Close() if err = col.Find(bson.M{"id": id}).One(&t); err != nil { @@ -1852,14 +1859,14 @@ func (ms *MongoStorage) GetTimingDrv(id string) (t *utils.TPTiming, err error) { return } -func (ms *MongoStorage) SetTimingDrv(t *utils.TPTiming) (err error) { +func (ms *MongoStorageOld) SetTimingDrv(t *utils.TPTiming) (err error) { session, col := ms.conn(colTmg) defer session.Close() _, err = col.Upsert(bson.M{"id": t.ID}, t) return } -func (ms *MongoStorage) RemoveTimingDrv(id string) (err error) { +func (ms *MongoStorageOld) RemoveTimingDrv(id string) (err error) { session, col := ms.conn(colTmg) defer session.Close() if err = col.Remove(bson.M{"id": id}); err != nil { @@ -1870,7 +1877,7 @@ func (ms *MongoStorage) RemoveTimingDrv(id string) (err error) { // GetFilterIndexesDrv retrieves Indexes from dataDB //filterType is used togheter with fieldName:Val -func (ms *MongoStorage) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType string, +func (ms *MongoStorageOld) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType string, fldNameVal map[string]string) (indexes map[string]utils.StringMap, err error) { session, col := ms.conn(colRFI) defer session.Close() @@ -1924,7 +1931,7 @@ func (ms *MongoStorage) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType st } // SetFilterIndexesDrv stores Indexes into DataDB -func (ms *MongoStorage) SetFilterIndexesDrv(cacheID, itemIDPrefix string, +func (ms *MongoStorageOld) SetFilterIndexesDrv(cacheID, itemIDPrefix string, indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { session, col := ms.conn(colRFI) defer session.Close() @@ -1986,7 +1993,7 @@ func (ms *MongoStorage) SetFilterIndexesDrv(cacheID, itemIDPrefix string, return } -func (ms *MongoStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (err error) { +func (ms *MongoStorageOld) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (err error) { session, col := ms.conn(colRFI) defer session.Close() regexKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix @@ -2002,7 +2009,7 @@ func (ms *MongoStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (er return } -func (ms *MongoStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix, +func (ms *MongoStorageOld) MatchFilterIndexDrv(cacheID, itemIDPrefix, filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) { session, col := ms.conn(colRFI) defer session.Close() @@ -2023,7 +2030,7 @@ func (ms *MongoStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix, } // GetStatQueueProfileDrv retrieves a StatQueueProfile from dataDB -func (ms *MongoStorage) GetStatQueueProfileDrv(tenant string, id string) (sq *StatQueueProfile, err error) { +func (ms *MongoStorageOld) GetStatQueueProfileDrv(tenant string, id string) (sq *StatQueueProfile, err error) { session, col := ms.conn(colSqp) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&sq); err != nil { @@ -2036,7 +2043,7 @@ func (ms *MongoStorage) GetStatQueueProfileDrv(tenant string, id string) (sq *St } // SetStatQueueProfileDrv stores a StatsQueue into DataDB -func (ms *MongoStorage) SetStatQueueProfileDrv(sq *StatQueueProfile) (err error) { +func (ms *MongoStorageOld) SetStatQueueProfileDrv(sq *StatQueueProfile) (err error) { session, col := ms.conn(colSqp) defer session.Close() _, err = col.UpsertId(bson.M{"tenant": sq.Tenant, "id": sq.ID}, sq) @@ -2044,7 +2051,7 @@ func (ms *MongoStorage) SetStatQueueProfileDrv(sq *StatQueueProfile) (err error) } // RemStatQueueProfileDrv removes a StatsQueue from dataDB -func (ms *MongoStorage) RemStatQueueProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemStatQueueProfileDrv(tenant, id string) (err error) { session, col := ms.conn(colSqp) err = col.Remove(bson.M{"tenant": tenant, "id": id}) if err != nil { @@ -2055,7 +2062,7 @@ func (ms *MongoStorage) RemStatQueueProfileDrv(tenant, id string) (err error) { } // GetStoredStatQueueDrv retrieves a StoredStatQueue -func (ms *MongoStorage) GetStoredStatQueueDrv(tenant, id string) (sq *StoredStatQueue, err error) { +func (ms *MongoStorageOld) GetStoredStatQueueDrv(tenant, id string) (sq *StoredStatQueue, err error) { session, col := ms.conn(colSqs) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&sq); err != nil { @@ -2068,7 +2075,7 @@ func (ms *MongoStorage) GetStoredStatQueueDrv(tenant, id string) (sq *StoredStat } // SetStoredStatQueueDrv stores the metrics for a StoredStatQueue -func (ms *MongoStorage) SetStoredStatQueueDrv(sq *StoredStatQueue) (err error) { +func (ms *MongoStorageOld) SetStoredStatQueueDrv(sq *StoredStatQueue) (err error) { session, col := ms.conn(colSqs) defer session.Close() _, err = col.Upsert(bson.M{"tenant": sq.Tenant, "id": sq.ID}, sq) @@ -2076,7 +2083,7 @@ func (ms *MongoStorage) SetStoredStatQueueDrv(sq *StoredStatQueue) (err error) { } // RemStoredStatQueueDrv removes stored metrics for a StoredStatQueue -func (ms *MongoStorage) RemStoredStatQueueDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemStoredStatQueueDrv(tenant, id string) (err error) { session, col := ms.conn(colSqs) defer session.Close() err = col.Remove(bson.M{"tenant": tenant, "id": id}) @@ -2087,7 +2094,7 @@ func (ms *MongoStorage) RemStoredStatQueueDrv(tenant, id string) (err error) { } // GetThresholdProfileDrv retrieves a ThresholdProfile from dataDB -func (ms *MongoStorage) GetThresholdProfileDrv(tenant, ID string) (tp *ThresholdProfile, err error) { +func (ms *MongoStorageOld) GetThresholdProfileDrv(tenant, ID string) (tp *ThresholdProfile, err error) { session, col := ms.conn(colTps) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": ID}).One(&tp); err != nil { @@ -2100,7 +2107,7 @@ func (ms *MongoStorage) GetThresholdProfileDrv(tenant, ID string) (tp *Threshold } // SetThresholdProfileDrv stores a ThresholdProfile into DataDB -func (ms *MongoStorage) SetThresholdProfileDrv(tp *ThresholdProfile) (err error) { +func (ms *MongoStorageOld) SetThresholdProfileDrv(tp *ThresholdProfile) (err error) { session, col := ms.conn(colTps) defer session.Close() _, err = col.UpsertId(bson.M{"tenant": tp.Tenant, "id": tp.ID}, tp) @@ -2108,7 +2115,7 @@ func (ms *MongoStorage) SetThresholdProfileDrv(tp *ThresholdProfile) (err error) } // RemoveThresholdProfile removes a ThresholdProfile from dataDB/cache -func (ms *MongoStorage) RemThresholdProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemThresholdProfileDrv(tenant, id string) (err error) { session, col := ms.conn(colTps) defer session.Close() err = col.Remove(bson.M{"tenant": tenant, "id": id}) @@ -2118,7 +2125,7 @@ func (ms *MongoStorage) RemThresholdProfileDrv(tenant, id string) (err error) { return } -func (ms *MongoStorage) GetThresholdDrv(tenant, id string) (r *Threshold, err error) { +func (ms *MongoStorageOld) GetThresholdDrv(tenant, id string) (r *Threshold, err error) { session, col := ms.conn(colThs) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&r); err != nil { @@ -2130,14 +2137,14 @@ func (ms *MongoStorage) GetThresholdDrv(tenant, id string) (r *Threshold, err er return } -func (ms *MongoStorage) SetThresholdDrv(r *Threshold) (err error) { +func (ms *MongoStorageOld) SetThresholdDrv(r *Threshold) (err error) { session, col := ms.conn(colThs) defer session.Close() _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) return } -func (ms *MongoStorage) RemoveThresholdDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveThresholdDrv(tenant, id string) (err error) { session, col := ms.conn(colThs) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { @@ -2146,7 +2153,7 @@ func (ms *MongoStorage) RemoveThresholdDrv(tenant, id string) (err error) { return nil } -func (ms *MongoStorage) GetFilterDrv(tenant, id string) (r *Filter, err error) { +func (ms *MongoStorageOld) GetFilterDrv(tenant, id string) (r *Filter, err error) { session, col := ms.conn(colFlt) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&r); err != nil { @@ -2163,14 +2170,14 @@ func (ms *MongoStorage) GetFilterDrv(tenant, id string) (r *Filter, err error) { return } -func (ms *MongoStorage) SetFilterDrv(r *Filter) (err error) { +func (ms *MongoStorageOld) SetFilterDrv(r *Filter) (err error) { session, col := ms.conn(colFlt) defer session.Close() _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) return } -func (ms *MongoStorage) RemoveFilterDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveFilterDrv(tenant, id string) (err error) { session, col := ms.conn(colFlt) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { @@ -2179,7 +2186,7 @@ func (ms *MongoStorage) RemoveFilterDrv(tenant, id string) (err error) { return nil } -func (ms *MongoStorage) GetSupplierProfileDrv(tenant, id string) (r *SupplierProfile, err error) { +func (ms *MongoStorageOld) GetSupplierProfileDrv(tenant, id string) (r *SupplierProfile, err error) { session, col := ms.conn(colSpp) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&r); err != nil { @@ -2191,14 +2198,14 @@ func (ms *MongoStorage) GetSupplierProfileDrv(tenant, id string) (r *SupplierPro return } -func (ms *MongoStorage) SetSupplierProfileDrv(r *SupplierProfile) (err error) { +func (ms *MongoStorageOld) SetSupplierProfileDrv(r *SupplierProfile) (err error) { session, col := ms.conn(colSpp) defer session.Close() _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) return } -func (ms *MongoStorage) RemoveSupplierProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveSupplierProfileDrv(tenant, id string) (err error) { session, col := ms.conn(colSpp) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { @@ -2207,7 +2214,7 @@ func (ms *MongoStorage) RemoveSupplierProfileDrv(tenant, id string) (err error) return nil } -func (ms *MongoStorage) GetAttributeProfileDrv(tenant, id string) (r *AttributeProfile, err error) { +func (ms *MongoStorageOld) GetAttributeProfileDrv(tenant, id string) (r *AttributeProfile, err error) { session, col := ms.conn(colAttr) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&r); err != nil { @@ -2219,14 +2226,14 @@ func (ms *MongoStorage) GetAttributeProfileDrv(tenant, id string) (r *AttributeP return } -func (ms *MongoStorage) SetAttributeProfileDrv(r *AttributeProfile) (err error) { +func (ms *MongoStorageOld) SetAttributeProfileDrv(r *AttributeProfile) (err error) { session, col := ms.conn(colAttr) defer session.Close() _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) return } -func (ms *MongoStorage) RemoveAttributeProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveAttributeProfileDrv(tenant, id string) (err error) { session, col := ms.conn(colAttr) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { @@ -2235,7 +2242,7 @@ func (ms *MongoStorage) RemoveAttributeProfileDrv(tenant, id string) (err error) return nil } -func (ms *MongoStorage) GetChargerProfileDrv(tenant, id string) (r *ChargerProfile, err error) { +func (ms *MongoStorageOld) GetChargerProfileDrv(tenant, id string) (r *ChargerProfile, err error) { session, col := ms.conn(colCpp) defer session.Close() if err = col.Find(bson.M{"tenant": tenant, "id": id}).One(&r); err != nil { @@ -2247,14 +2254,14 @@ func (ms *MongoStorage) GetChargerProfileDrv(tenant, id string) (r *ChargerProfi return } -func (ms *MongoStorage) SetChargerProfileDrv(r *ChargerProfile) (err error) { +func (ms *MongoStorageOld) SetChargerProfileDrv(r *ChargerProfile) (err error) { session, col := ms.conn(colCpp) defer session.Close() _, err = col.Upsert(bson.M{"tenant": r.Tenant, "id": r.ID}, r) return } -func (ms *MongoStorage) RemoveChargerProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorageOld) RemoveChargerProfileDrv(tenant, id string) (err error) { session, col := ms.conn(colCpp) defer session.Close() if err = col.Remove(bson.M{"tenant": tenant, "id": id}); err != nil { diff --git a/engine/storage_mongo_datadb_new.go b/engine/storage_mongo_datadb_new.go index 8e500c347..6a8d4e200 100644 --- a/engine/storage_mongo_datadb_new.go +++ b/engine/storage_mongo_datadb_new.go @@ -33,15 +33,15 @@ import ( "github.com/cgrates/ltcache" "github.com/mongodb/mongo-go-driver/bson" - "github.com/mongodb/mongo-go-driver/bson/objectid" + "github.com/mongodb/mongo-go-driver/bson/primitive" "github.com/mongodb/mongo-go-driver/mongo" - "github.com/mongodb/mongo-go-driver/options" + "github.com/mongodb/mongo-go-driver/mongo/options" "github.com/mongodb/mongo-go-driver/x/bsonx" ) -// NewMongoStorageNew givese new mongo driver +// NewMongoStorage givese new mongo driver func NewMongoStorage(host, port, db, user, pass, storageType string, - cdrsIndexes []string, cacheCfg config.CacheCfg) (ms *MongoStorageNew, err error) { + cdrsIndexes []string, cacheCfg config.CacheCfg) (ms *MongoStorage, err error) { url := "mongodb://" + host if port != "" { url += ":" + port @@ -64,7 +64,7 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, if err != nil { return nil, err } - ms = &MongoStorageNew{ + ms = &MongoStorage{ client: client, ctx: ctx, db: dbName, @@ -73,12 +73,19 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, cacheCfg: cacheCfg, cdrsIndexes: cdrsIndexes, } + if col, err := ms.client.Database(db).ListCollections(ms.ctx, nil); err != nil { + return nil, err + } else if !col.Next(ctx) { // create indexes only if database is empty + if err = ms.EnsureIndexes(); err != nil { + return nil, err + } + } ms.cnter = utils.NewCounter(time.Now().UnixNano(), 0) return } -// MongoStorageNew struct for new mongo driver -type MongoStorageNew struct { +// MongoStorage struct for new mongo driver +type MongoStorage struct { client *mongo.Client ctx context.Context db string @@ -90,11 +97,110 @@ type MongoStorageNew struct { cnter *utils.Counter } -func (ms *MongoStorageNew) getCol(col string) *mongo.Collection { +func (ms *MongoStorage) EnusureIndex(colName string, uniq bool, keys ...string) error { + return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { + col := ms.getCol(colName) + io := mongo.NewIndexOptionsBuilder().Unique(uniq) + var doc bsonx.Doc + // elem := make([]bson.M, len(keys)) + for _, k := range keys { + // elem[i] = bson.M{k: 1} + doc = doc.Append(k, bsonx.Int32(1)) + } + _, err := col.Indexes().CreateOne(sctx, mongo.IndexModel{ + Keys: doc, + Options: io.Build(), + }) + return err + }) +} + +func (ms *MongoStorage) getCol(col string) *mongo.Collection { return ms.client.Database(ms.db).Collection(col) } -func (ms *MongoStorageNew) getColNameForPrefix(prefix string) (string, bool) { +// EnsureIndexes creates db indexes +func (ms *MongoStorage) EnsureIndexes() (err error) { + if ms.storageType == utils.DataDB { + for _, col := range []string{colAct, colApl, colAAp, colAtr, + colDcs, colRpl, colDst, colRds, colAls, colUsr, colLht} { + if err = ms.EnusureIndex(col, true, "key"); err != nil { + return + } + } + for _, col := range []string{colRsP, colRes, colSqs, colSqp, + colTps, colThs, colSpp, colAttr, colFlt, colCpp} { + if err = ms.EnusureIndex(col, true, "tenant", "id"); err != nil { + return + } + } + for _, col := range []string{colRpf, colShg, colAcc} { + if err = ms.EnusureIndex(col, true, "id"); err != nil { + return + } + } + } + if ms.storageType == utils.StorDB { + for _, col := range []string{utils.TBLTPTimings, utils.TBLTPDestinations, + utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, + utils.TBLTPSharedGroups, utils.TBLTPActions, + utils.TBLTPActionPlans, utils.TBLTPActionTriggers, + utils.TBLTPStats, utils.TBLTPResources} { + if err = ms.EnusureIndex(col, true, "tpid", "id"); err != nil { + return + } + } + + if err = ms.EnusureIndex(utils.TBLTPRateProfiles, true, "tpid", "direction", + "tenant", "category", "subject", "loadid"); err != nil { + return + } + + if err = ms.EnusureIndex(utils.TBLTPUsers, true, "tpid", "tenant", + "username"); err != nil { + return + } + + if err = ms.EnusureIndex(utils.TBLTPDerivedChargers, true, "tpid", "tenant", + "category", "subject", "account", "loadid"); err != nil { + return + } + + if err = ms.EnusureIndex(utils.TBLTPDerivedChargers, true, "tpid", "direction", + "tenant", "account", "loadid"); err != nil { + return + } + + if err = ms.EnusureIndex(utils.CDRsTBL, true, CGRIDLow, RunIDLow, + OriginIDLow); err != nil { + return + } + + for _, idxKey := range ms.cdrsIndexes { + if err = ms.EnusureIndex(utils.CDRsTBL, false, idxKey); err != nil { + return + } + } + + if err = ms.EnusureIndex(utils.SessionsCostsTBL, true, CGRIDLow, + RunIDLow); err != nil { + return + } + + if err = ms.EnusureIndex(utils.SessionsCostsTBL, false, OriginHostLow, + OriginIDLow); err != nil { + return + } + + if err = ms.EnusureIndex(utils.SessionsCostsTBL, false, RunIDLow, + OriginIDLow); err != nil { + return + } + } + return +} + +func (ms *MongoStorage) getColNameForPrefix(prefix string) (string, bool) { res, ok := map[string]string{ utils.DESTINATION_PREFIX: colDst, utils.REVERSE_DESTINATION_PREFIX: colRds, @@ -107,61 +213,58 @@ func (ms *MongoStorageNew) getColNameForPrefix(prefix string) (string, bool) { utils.RATING_PROFILE_PREFIX: colRpf, utils.ACCOUNT_PREFIX: colAcc, utils.SHARED_GROUP_PREFIX: colShg, - utils.LCR_PREFIX: colLcr, utils.DERIVEDCHARGERS_PREFIX: colDcs, utils.ALIASES_PREFIX: colAls, utils.REVERSE_ALIASES_PREFIX: colRCfgs, utils.PUBSUB_SUBSCRIBERS_PREFIX: colPbs, utils.USERS_PREFIX: colUsr, - utils.CDR_STATS_PREFIX: colCrs, utils.LOADINST_KEY: colLht, utils.VERSION_PREFIX: colVer, - //utils.CDR_STATS_QUEUE_PREFIX: colStq, - utils.TimingsPrefix: colTmg, - utils.ResourcesPrefix: colRes, - utils.ResourceProfilesPrefix: colRsP, - utils.ThresholdProfilePrefix: colTps, - utils.StatQueueProfilePrefix: colSqp, - utils.ThresholdPrefix: colThs, - utils.FilterPrefix: colFlt, - utils.SupplierProfilePrefix: colSpp, - utils.AttributeProfilePrefix: colAttr, + utils.TimingsPrefix: colTmg, + utils.ResourcesPrefix: colRes, + utils.ResourceProfilesPrefix: colRsP, + utils.ThresholdProfilePrefix: colTps, + utils.StatQueueProfilePrefix: colSqp, + utils.ThresholdPrefix: colThs, + utils.FilterPrefix: colFlt, + utils.SupplierProfilePrefix: colSpp, + utils.AttributeProfilePrefix: colAttr, }[prefix] return res, ok } // Close disconects the client -func (ms *MongoStorageNew) Close() { +func (ms *MongoStorage) Close() { if err := ms.client.Disconnect(ms.ctx); err != nil { utils.Logger.Err(fmt.Sprintf(" Error on disconect:%s", err)) } } // Flush drops the datatable -func (ms *MongoStorageNew) Flush(ignore string) (err error) { +func (ms *MongoStorage) Flush(ignore string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { return ms.client.Database(ms.db).Drop(sctx) }) } // Marshaler returns the marshall -func (ms *MongoStorageNew) Marshaler() Marshaler { +func (ms *MongoStorage) Marshaler() Marshaler { return ms.ms } // DB returnes a database object -func (ms *MongoStorageNew) DB() *mongo.Database { +func (ms *MongoStorage) DB() *mongo.Database { return ms.client.Database(ms.db) } // SelectDatabase selects the database -func (ms *MongoStorageNew) SelectDatabase(dbName string) (err error) { +func (ms *MongoStorage) SelectDatabase(dbName string) (err error) { ms.db = dbName return } // RebuildReverseForPrefix implementation -func (ms *MongoStorageNew) RebuildReverseForPrefix(prefix string) (err error) { +func (ms *MongoStorage) RebuildReverseForPrefix(prefix string) (err error) { if !utils.IsSliceMember([]string{utils.REVERSE_DESTINATION_PREFIX, utils.REVERSE_ALIASES_PREFIX, utils.AccountActionPlansPrefix}, prefix) { return utils.ErrInvalidKey @@ -224,7 +327,7 @@ func (ms *MongoStorageNew) RebuildReverseForPrefix(prefix string) (err error) { } // RemoveReverseForPrefix implementation -func (ms *MongoStorageNew) RemoveReverseForPrefix(prefix string) (err error) { +func (ms *MongoStorage) RemoveReverseForPrefix(prefix string) (err error) { if !utils.IsSliceMember([]string{utils.REVERSE_DESTINATION_PREFIX, utils.REVERSE_ALIASES_PREFIX, utils.AccountActionPlansPrefix}, prefix) { return utils.ErrInvalidKey @@ -291,7 +394,7 @@ func (ms *MongoStorageNew) RemoveReverseForPrefix(prefix string) (err error) { } // IsDBEmpty implementation -func (ms *MongoStorageNew) IsDBEmpty() (resp bool, err error) { +func (ms *MongoStorage) IsDBEmpty() (resp bool, err error) { err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { col, err := ms.DB().ListCollections(sctx, nil) if err != nil { @@ -312,7 +415,7 @@ func (ms *MongoStorageNew) IsDBEmpty() (resp bool, err error) { return resp, err } -func (ms *MongoStorageNew) getField(sctx mongo.SessionContext, col, prefix, subject, field string) (result []string, err error) { +func (ms *MongoStorage) getField(sctx mongo.SessionContext, col, prefix, subject, field string) (result []string, err error) { fieldResult := bson.D{} iter, err := ms.getCol(col).Find(sctx, bson.M{field: bsonx.Regex(subject, "")}, @@ -332,7 +435,7 @@ func (ms *MongoStorageNew) getField(sctx mongo.SessionContext, col, prefix, subj } return result, iter.Close(sctx) } -func (ms *MongoStorageNew) getField2(sctx mongo.SessionContext, col, prefix, subject string, tntID *utils.TenantID) (result []string, err error) { +func (ms *MongoStorage) getField2(sctx mongo.SessionContext, col, prefix, subject string, tntID *utils.TenantID) (result []string, err error) { idResult := struct{ Tenant, Id string }{} elem := bson.M{} if tntID.Tenant != "" { @@ -358,7 +461,7 @@ func (ms *MongoStorageNew) getField2(sctx mongo.SessionContext, col, prefix, sub } // GetKeysForPrefix implementation -func (ms *MongoStorageNew) GetKeysForPrefix(prefix string) (result []string, err error) { +func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err error) { var category, subject string keyLen := len(utils.DESTINATION_PREFIX) if len(prefix) < keyLen { @@ -388,8 +491,6 @@ func (ms *MongoStorageNew) GetKeysForPrefix(prefix string) (result []string, err result, err = ms.getField(sctx, colShg, utils.SHARED_GROUP_PREFIX, subject, "id") case utils.DERIVEDCHARGERS_PREFIX: result, err = ms.getField(sctx, colDcs, utils.DERIVEDCHARGERS_PREFIX, subject, "key") - case utils.LCR_PREFIX: - result, err = ms.getField(sctx, colLcr, utils.LCR_PREFIX, subject, "key") case utils.ACCOUNT_PREFIX: result, err = ms.getField(sctx, colAcc, utils.ACCOUNT_PREFIX, subject, "id") case utils.ALIASES_PREFIX: @@ -428,7 +529,7 @@ func (ms *MongoStorageNew) GetKeysForPrefix(prefix string) (result []string, err return } -func (ms *MongoStorageNew) HasDataDrv(category, subject, tenant string) (has bool, err error) { +func (ms *MongoStorage) HasDataDrv(category, subject, tenant string) (has bool, err error) { err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { var count int64 switch category { @@ -471,7 +572,7 @@ func (ms *MongoStorageNew) HasDataDrv(category, subject, tenant string) (has boo return has, err } -func (ms *MongoStorageNew) GetRatingPlanDrv(key string) (rp *RatingPlan, err error) { +func (ms *MongoStorage) GetRatingPlanDrv(key string) (rp *RatingPlan, err error) { var kv struct { Key string Value []byte @@ -505,7 +606,7 @@ func (ms *MongoStorageNew) GetRatingPlanDrv(key string) (rp *RatingPlan, err err return } -func (ms *MongoStorageNew) SetRatingPlanDrv(rp *RatingPlan) error { +func (ms *MongoStorage) SetRatingPlanDrv(rp *RatingPlan) error { result, err := ms.ms.Marshal(rp) if err != nil { return err @@ -526,7 +627,7 @@ func (ms *MongoStorageNew) SetRatingPlanDrv(rp *RatingPlan) error { }) } -func (ms *MongoStorageNew) RemoveRatingPlanDrv(key string) error { +func (ms *MongoStorage) RemoveRatingPlanDrv(key string) error { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colRpl).DeleteMany(sctx, bson.M{"key": key}) if dr.DeletedCount == 0 { @@ -536,7 +637,7 @@ func (ms *MongoStorageNew) RemoveRatingPlanDrv(key string) error { }) } -func (ms *MongoStorageNew) GetRatingProfileDrv(key string) (rp *RatingProfile, err error) { +func (ms *MongoStorage) GetRatingProfileDrv(key string) (rp *RatingProfile, err error) { rp = new(RatingProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colRpf).FindOne(sctx, bson.M{"id": key}) @@ -551,7 +652,7 @@ func (ms *MongoStorageNew) GetRatingProfileDrv(key string) (rp *RatingProfile, e return } -func (ms *MongoStorageNew) SetRatingProfileDrv(rp *RatingProfile) (err error) { +func (ms *MongoStorage) SetRatingProfileDrv(rp *RatingProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colRpf).UpdateOne(sctx, bson.M{"id": rp.Id}, bson.M{"$set": rp}, @@ -561,7 +662,7 @@ func (ms *MongoStorageNew) SetRatingProfileDrv(rp *RatingProfile) (err error) { }) } -func (ms *MongoStorageNew) RemoveRatingProfileDrv(key string) error { +func (ms *MongoStorage) RemoveRatingProfileDrv(key string) error { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colRpf).DeleteMany(sctx, bson.M{"id": key}) if dr.DeletedCount == 0 { @@ -571,48 +672,7 @@ func (ms *MongoStorageNew) RemoveRatingProfileDrv(key string) error { }) } -func (ms *MongoStorageNew) GetLCRDrv(key string) (lcr *LCR, err error) { - var result struct { - Key string - Value *LCR - } - err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur := ms.getCol(colLcr).FindOne(sctx, bson.M{"key": key}) - if err := cur.Decode(&result); err != nil { - if err == mongo.ErrNoDocuments { - return utils.ErrNotFound - } - return err - } - return nil - }) - return result.Value, err -} - -func (ms *MongoStorageNew) SetLCRDrv(lcr *LCR) (err error) { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - _, err = ms.getCol(colLcr).UpdateOne(sctx, bson.M{"key": lcr.GetId()}, - bson.M{"$set": struct { - Key string - Value *LCR - }{lcr.GetId(), lcr}}, - options.Update().SetUpsert(true), - ) - return err - }) -} - -func (ms *MongoStorageNew) RemoveLCRDrv(key, transactionID string) (err error) { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - dr, err := ms.getCol(colLcr).DeleteOne(sctx, bson.M{"key": key}) - if dr.DeletedCount == 0 { - return utils.ErrNotFound - } - return err - }) -} - -func (ms *MongoStorageNew) GetDestination(key string, skipCache bool, +func (ms *MongoStorage) GetDestination(key string, skipCache bool, transactionID string) (result *Destination, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheDestinations, key); ok { @@ -659,7 +719,7 @@ func (ms *MongoStorageNew) GetDestination(key string, skipCache bool, return } -func (ms *MongoStorageNew) SetDestination(dest *Destination, transactionID string) (err error) { +func (ms *MongoStorage) SetDestination(dest *Destination, transactionID string) (err error) { result, err := ms.ms.Marshal(dest) if err != nil { return err @@ -681,7 +741,7 @@ func (ms *MongoStorageNew) SetDestination(dest *Destination, transactionID strin }) } -func (ms *MongoStorageNew) RemoveDestination(destID string, +func (ms *MongoStorage) RemoveDestination(destID string, transactionID string) (err error) { // get destination for prefix list d, err := ms.GetDestination(destID, false, transactionID) @@ -713,7 +773,7 @@ func (ms *MongoStorageNew) RemoveDestination(destID string, return } -func (ms *MongoStorageNew) GetReverseDestination(prefix string, skipCache bool, +func (ms *MongoStorage) GetReverseDestination(prefix string, skipCache bool, transactionID string) (ids []string, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheReverseDestinations, prefix); ok { @@ -747,7 +807,7 @@ func (ms *MongoStorageNew) GetReverseDestination(prefix string, skipCache bool, return } -func (ms *MongoStorageNew) SetReverseDestination(dest *Destination, +func (ms *MongoStorage) SetReverseDestination(dest *Destination, transactionID string) (err error) { for _, p := range dest.Prefixes { if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { @@ -763,7 +823,7 @@ func (ms *MongoStorageNew) SetReverseDestination(dest *Destination, return nil } -func (ms *MongoStorageNew) UpdateReverseDestination(oldDest, newDest *Destination, +func (ms *MongoStorage) UpdateReverseDestination(oldDest, newDest *Destination, transactionID string) error { //log.Printf("Old: %+v, New: %+v", oldDest, newDest) var obsoletePrefixes []string @@ -828,7 +888,7 @@ func (ms *MongoStorageNew) UpdateReverseDestination(oldDest, newDest *Destinatio return nil } -func (ms *MongoStorageNew) GetActionsDrv(key string) (as Actions, err error) { +func (ms *MongoStorage) GetActionsDrv(key string) (as Actions, err error) { var result struct { Key string Value Actions @@ -849,7 +909,7 @@ func (ms *MongoStorageNew) GetActionsDrv(key string) (as Actions, err error) { return } -func (ms *MongoStorageNew) SetActionsDrv(key string, as Actions) error { +func (ms *MongoStorage) SetActionsDrv(key string, as Actions) error { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colAct).UpdateOne(sctx, bson.M{"key": key}, bson.M{"$set": struct { @@ -862,7 +922,7 @@ func (ms *MongoStorageNew) SetActionsDrv(key string, as Actions) error { }) } -func (ms *MongoStorageNew) RemoveActionsDrv(key string) error { +func (ms *MongoStorage) RemoveActionsDrv(key string) error { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colAct).DeleteOne(sctx, bson.M{"key": key}) if dr.DeletedCount == 0 { @@ -872,7 +932,7 @@ func (ms *MongoStorageNew) RemoveActionsDrv(key string) error { }) } -func (ms *MongoStorageNew) GetSharedGroupDrv(key string) (sg *SharedGroup, err error) { +func (ms *MongoStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err error) { sg = new(SharedGroup) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colShg).FindOne(sctx, bson.M{"id": key}) @@ -887,7 +947,7 @@ func (ms *MongoStorageNew) GetSharedGroupDrv(key string) (sg *SharedGroup, err e return } -func (ms *MongoStorageNew) SetSharedGroupDrv(sg *SharedGroup) (err error) { +func (ms *MongoStorage) SetSharedGroupDrv(sg *SharedGroup) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colShg).UpdateOne(sctx, bson.M{"id": sg.Id}, bson.M{"$set": sg}, @@ -897,7 +957,7 @@ func (ms *MongoStorageNew) SetSharedGroupDrv(sg *SharedGroup) (err error) { }) } -func (ms *MongoStorageNew) RemoveSharedGroupDrv(id, transactionID string) (err error) { +func (ms *MongoStorage) RemoveSharedGroupDrv(id, transactionID string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colShg).DeleteOne(sctx, bson.M{"id": id}) if dr.DeletedCount == 0 { @@ -907,7 +967,7 @@ func (ms *MongoStorageNew) RemoveSharedGroupDrv(id, transactionID string) (err e }) } -func (ms *MongoStorageNew) GetAccount(key string) (result *Account, err error) { +func (ms *MongoStorage) GetAccount(key string) (result *Account, err error) { result = new(Account) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colAcc).FindOne(sctx, bson.M{"id": key}) @@ -922,7 +982,7 @@ func (ms *MongoStorageNew) GetAccount(key string) (result *Account, err error) { return } -func (ms *MongoStorageNew) SetAccount(acc *Account) error { +func (ms *MongoStorage) SetAccount(acc *Account) error { // never override existing account with an empty one // UPDATE: if all balances expired and were cleaned it makes // sense to write empty balance map @@ -944,7 +1004,7 @@ func (ms *MongoStorageNew) SetAccount(acc *Account) error { }) } -func (ms *MongoStorageNew) RemoveAccount(key string) (err error) { +func (ms *MongoStorage) RemoveAccount(key string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colAcc).DeleteOne(sctx, bson.M{"id": key}) if dr.DeletedCount == 0 { @@ -954,50 +1014,7 @@ func (ms *MongoStorageNew) RemoveAccount(key string) (err error) { }) } -func (ms *MongoStorageNew) GetCdrStatsQueueDrv(key string) (sq *CDRStatsQueue, err error) { - var result struct { - Key string - Value *CDRStatsQueue - } - if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur := ms.getCol(colStq).FindOne(sctx, bson.M{"key": key}) - if err := cur.Decode(&result); err != nil { - if err == mongo.ErrNoDocuments { - return utils.ErrNotFound - } - return err - } - return nil - }); err != nil { - return nil, err - } - return result.Value, nil -} - -func (ms *MongoStorageNew) SetCdrStatsQueueDrv(sq *CDRStatsQueue) (err error) { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - _, err = ms.getCol(colStq).UpdateOne(sctx, bson.M{"key": sq.GetId()}, - bson.M{"$set": struct { - Key string - Value *CDRStatsQueue - }{Key: sq.GetId(), Value: sq}}, - options.Update().SetUpsert(true), - ) - return err - }) -} - -func (ms *MongoStorageNew) RemoveCdrStatsQueueDrv(id string) (err error) { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - dr, err := ms.getCol(colStq).DeleteOne(sctx, bson.M{"key": id}) - if dr.DeletedCount == 0 { - return utils.ErrNotFound - } - return err - }) -} - -func (ms *MongoStorageNew) GetSubscribersDrv() (result map[string]*SubscriberData, err error) { +func (ms *MongoStorage) GetSubscribersDrv() (result map[string]*SubscriberData, err error) { result = make(map[string]*SubscriberData) var kv struct { Key string @@ -1022,7 +1039,7 @@ func (ms *MongoStorageNew) GetSubscribersDrv() (result map[string]*SubscriberDat return } -func (ms *MongoStorageNew) SetSubscriberDrv(key string, sub *SubscriberData) (err error) { +func (ms *MongoStorage) SetSubscriberDrv(key string, sub *SubscriberData) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colPbs).UpdateOne(sctx, bson.M{"key": key}, bson.M{"$set": struct { @@ -1035,7 +1052,7 @@ func (ms *MongoStorageNew) SetSubscriberDrv(key string, sub *SubscriberData) (er }) } -func (ms *MongoStorageNew) RemoveSubscriberDrv(key string) (err error) { +func (ms *MongoStorage) RemoveSubscriberDrv(key string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colPbs).DeleteOne(sctx, bson.M{"key": key}) if dr.DeletedCount == 0 { @@ -1045,7 +1062,7 @@ func (ms *MongoStorageNew) RemoveSubscriberDrv(key string) (err error) { }) } -func (ms *MongoStorageNew) GetUserDrv(key string) (up *UserProfile, err error) { +func (ms *MongoStorage) GetUserDrv(key string) (up *UserProfile, err error) { var kv struct { Key string Value *UserProfile @@ -1065,7 +1082,7 @@ func (ms *MongoStorageNew) GetUserDrv(key string) (up *UserProfile, err error) { return kv.Value, nil } -func (ms *MongoStorageNew) GetUsersDrv() (result []*UserProfile, err error) { +func (ms *MongoStorage) GetUsersDrv() (result []*UserProfile, err error) { err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur, err := ms.getCol(colUsr).Find(sctx, nil) if err != nil { @@ -1087,7 +1104,7 @@ func (ms *MongoStorageNew) GetUsersDrv() (result []*UserProfile, err error) { return } -func (ms *MongoStorageNew) SetUserDrv(up *UserProfile) (err error) { +func (ms *MongoStorage) SetUserDrv(up *UserProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colUsr).UpdateOne(sctx, bson.M{"key": up.GetId()}, bson.M{"$set": struct { @@ -1100,7 +1117,7 @@ func (ms *MongoStorageNew) SetUserDrv(up *UserProfile) (err error) { }) } -func (ms *MongoStorageNew) RemoveUserDrv(key string) (err error) { +func (ms *MongoStorage) RemoveUserDrv(key string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colUsr).DeleteOne(sctx, bson.M{"key": key}) if dr.DeletedCount == 0 { @@ -1110,7 +1127,7 @@ func (ms *MongoStorageNew) RemoveUserDrv(key string) (err error) { }) } -func (ms *MongoStorageNew) GetAlias(key string, skipCache bool, +func (ms *MongoStorage) GetAlias(key string, skipCache bool, transactionID string) (al *Alias, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheAliases, key); ok { @@ -1148,7 +1165,7 @@ func (ms *MongoStorageNew) GetAlias(key string, skipCache bool, return } -func (ms *MongoStorageNew) SetAlias(al *Alias, transactionID string) (err error) { +func (ms *MongoStorage) SetAlias(al *Alias, transactionID string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colAls).UpdateOne(sctx, bson.M{"key": al.GetId()}, bson.M{"$set": struct { @@ -1161,7 +1178,7 @@ func (ms *MongoStorageNew) SetAlias(al *Alias, transactionID string) (err error) }) } -func (ms *MongoStorageNew) RemoveAlias(key, transactionID string) (err error) { +func (ms *MongoStorage) RemoveAlias(key, transactionID string) (err error) { al := new(Alias) al.SetId(key) origKey := key @@ -1214,7 +1231,7 @@ func (ms *MongoStorageNew) RemoveAlias(key, transactionID string) (err error) { return } -func (ms *MongoStorageNew) GetReverseAlias(reverseID string, skipCache bool, +func (ms *MongoStorage) GetReverseAlias(reverseID string, skipCache bool, transactionID string) (ids []string, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheReverseAliases, reverseID); ok { @@ -1248,7 +1265,7 @@ func (ms *MongoStorageNew) GetReverseAlias(reverseID string, skipCache bool, return } -func (ms *MongoStorageNew) SetReverseAlias(al *Alias, transactionID string) (err error) { +func (ms *MongoStorage) SetReverseAlias(al *Alias, transactionID string) (err error) { for _, value := range al.Values { for target, pairs := range value.Pairs { for _, alias := range pairs { @@ -1270,7 +1287,7 @@ func (ms *MongoStorageNew) SetReverseAlias(al *Alias, transactionID string) (err } // Limit will only retrieve the last n items out of history, newest first -func (ms *MongoStorageNew) GetLoadHistory(limit int, skipCache bool, +func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool, transactionID string) (loadInsts []*utils.LoadInstance, err error) { if limit == 0 { return nil, nil @@ -1316,7 +1333,7 @@ func (ms *MongoStorageNew) GetLoadHistory(limit int, skipCache bool, } // Adds a single load instance to load history -func (ms *MongoStorageNew) AddLoadHistory(ldInst *utils.LoadInstance, +func (ms *MongoStorage) AddLoadHistory(ldInst *utils.LoadInstance, loadHistSize int, transactionID string) error { if loadHistSize == 0 { // Load history disabled return nil @@ -1331,7 +1348,7 @@ func (ms *MongoStorageNew) AddLoadHistory(ldInst *utils.LoadInstance, cur := ms.getCol(colLht).FindOne(sctx, bson.M{"key": utils.LOADINST_KEY}) if err := cur.Decode(&kv); err != nil { if err == mongo.ErrNoDocuments { - return utils.ErrNotFound + return nil // utils.ErrNotFound } return err } @@ -1372,7 +1389,7 @@ func (ms *MongoStorageNew) AddLoadHistory(ldInst *utils.LoadInstance, return err } -func (ms *MongoStorageNew) GetActionTriggersDrv(key string) (atrs ActionTriggers, err error) { +func (ms *MongoStorage) GetActionTriggersDrv(key string) (atrs ActionTriggers, err error) { var kv struct { Key string Value ActionTriggers @@ -1393,10 +1410,10 @@ func (ms *MongoStorageNew) GetActionTriggersDrv(key string) (atrs ActionTriggers return } -func (ms *MongoStorageNew) SetActionTriggersDrv(key string, atrs ActionTriggers) (err error) { +func (ms *MongoStorage) SetActionTriggersDrv(key string, atrs ActionTriggers) (err error) { if len(atrs) == 0 { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - _, err = ms.getCol(colStq).DeleteOne(sctx, bson.M{"key": key}) + _, err = ms.getCol(colAtr).DeleteOne(sctx, bson.M{"key": key}) return err }) } @@ -1412,9 +1429,9 @@ func (ms *MongoStorageNew) SetActionTriggersDrv(key string, atrs ActionTriggers) }) } -func (ms *MongoStorageNew) RemoveActionTriggersDrv(key string) error { +func (ms *MongoStorage) RemoveActionTriggersDrv(key string) error { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - dr, err := ms.getCol(colStq).DeleteOne(sctx, bson.M{"key": key}) + dr, err := ms.getCol(colAtr).DeleteOne(sctx, bson.M{"key": key}) if dr.DeletedCount == 0 { return utils.ErrNotFound } @@ -1422,7 +1439,7 @@ func (ms *MongoStorageNew) RemoveActionTriggersDrv(key string) error { }) } -func (ms *MongoStorageNew) GetActionPlan(key string, skipCache bool, +func (ms *MongoStorage) GetActionPlan(key string, skipCache bool, transactionID string) (ats *ActionPlan, err error) { if !skipCache { if x, err := Cache.GetCloned(utils.CacheActionPlans, key); err != nil { @@ -1471,7 +1488,7 @@ func (ms *MongoStorageNew) GetActionPlan(key string, skipCache bool, return } -func (ms *MongoStorageNew) SetActionPlan(key string, ats *ActionPlan, +func (ms *MongoStorage) SetActionPlan(key string, ats *ActionPlan, overwrite bool, transactionID string) (err error) { // clean dots from account ids map cCommit := cacheCommit(transactionID) @@ -1516,7 +1533,7 @@ func (ms *MongoStorageNew) SetActionPlan(key string, ats *ActionPlan, }) } -func (ms *MongoStorageNew) RemoveActionPlan(key string, transactionID string) error { +func (ms *MongoStorage) RemoveActionPlan(key string, transactionID string) error { cCommit := cacheCommit(transactionID) Cache.Remove(utils.CacheActionPlans, key, cCommit, transactionID) return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { @@ -1525,7 +1542,7 @@ func (ms *MongoStorageNew) RemoveActionPlan(key string, transactionID string) er }) } -func (ms *MongoStorageNew) GetAllActionPlans() (ats map[string]*ActionPlan, err error) { +func (ms *MongoStorage) GetAllActionPlans() (ats map[string]*ActionPlan, err error) { keys, err := ms.GetKeysForPrefix(utils.ACTION_PLAN_PREFIX) if err != nil { return nil, err @@ -1542,7 +1559,7 @@ func (ms *MongoStorageNew) GetAllActionPlans() (ats map[string]*ActionPlan, err return } -func (ms *MongoStorageNew) GetAccountActionPlans(acntID string, skipCache bool, transactionID string) (aPlIDs []string, err error) { +func (ms *MongoStorage) GetAccountActionPlans(acntID string, skipCache bool, transactionID string) (aPlIDs []string, err error) { if !skipCache { if x, ok := Cache.Get(utils.CacheAccountActionPlans, acntID); ok { if x == nil { @@ -1575,7 +1592,7 @@ func (ms *MongoStorageNew) GetAccountActionPlans(acntID string, skipCache bool, return } -func (ms *MongoStorageNew) SetAccountActionPlans(acntID string, aPlIDs []string, overwrite bool) (err error) { +func (ms *MongoStorage) SetAccountActionPlans(acntID string, aPlIDs []string, overwrite bool) (err error) { if !overwrite { if oldaPlIDs, err := ms.GetAccountActionPlans(acntID, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound { return err @@ -1601,7 +1618,7 @@ func (ms *MongoStorageNew) SetAccountActionPlans(acntID string, aPlIDs []string, } // ToDo: check return len(aPlIDs) == 0 -func (ms *MongoStorageNew) RemAccountActionPlans(acntID string, aPlIDs []string) (err error) { +func (ms *MongoStorage) RemAccountActionPlans(acntID string, aPlIDs []string) (err error) { if len(aPlIDs) == 0 { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colAAp).DeleteOne(sctx, bson.M{"key": acntID}) @@ -1644,16 +1661,16 @@ func (ms *MongoStorageNew) RemAccountActionPlans(acntID string, aPlIDs []string) }) } -func (ms *MongoStorageNew) PushTask(t *Task) error { +func (ms *MongoStorage) PushTask(t *Task) error { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { - _, err := ms.getCol(colTsk).InsertOne(sctx, bson.M{"_id": objectid.New(), "task": t}) + _, err := ms.getCol(colTsk).InsertOne(sctx, bson.M{"_id": primitive.NewObjectID(), "task": t}) return err }) } -func (ms *MongoStorageNew) PopTask() (t *Task, err error) { +func (ms *MongoStorage) PopTask() (t *Task, err error) { v := struct { - ID objectid.ObjectID `bson:"_id"` + ID primitive.ObjectID `bson:"_id"` Task *Task }{} if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { @@ -1671,7 +1688,7 @@ func (ms *MongoStorageNew) PopTask() (t *Task, err error) { return v.Task, nil } -func (ms *MongoStorageNew) GetDerivedChargersDrv(key string) (dcs *utils.DerivedChargers, err error) { +func (ms *MongoStorage) GetDerivedChargersDrv(key string) (dcs *utils.DerivedChargers, err error) { var kv struct { Key string Value *utils.DerivedChargers @@ -1691,7 +1708,7 @@ func (ms *MongoStorageNew) GetDerivedChargersDrv(key string) (dcs *utils.Derived return kv.Value, nil } -func (ms *MongoStorageNew) SetDerivedChargers(key string, +func (ms *MongoStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers, transactionID string) (err error) { cCommit := cacheCommit(transactionID) if dcs == nil || len(dcs.Chargers) == 0 { @@ -1716,7 +1733,7 @@ func (ms *MongoStorageNew) SetDerivedChargers(key string, }) } -func (ms *MongoStorageNew) RemoveDerivedChargersDrv(id, transactionID string) (err error) { +func (ms *MongoStorage) RemoveDerivedChargersDrv(id, transactionID string) (err error) { cCommit := cacheCommit(transactionID) if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colDcs).DeleteOne(sctx, bson.M{"key": id}) @@ -1728,52 +1745,7 @@ func (ms *MongoStorageNew) RemoveDerivedChargersDrv(id, transactionID string) (e return nil } -func (ms *MongoStorageNew) GetCdrStatsDrv(key string) (cs *CdrStats, err error) { - cs = new(CdrStats) - err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur := ms.getCol(colCrs).FindOne(sctx, bson.M{"id": key}) - if err := cur.Decode(cs); err != nil { - if err == mongo.ErrNoDocuments { - return utils.ErrNotFound - } - return err - } - return nil - }) - return -} - -func (ms *MongoStorageNew) GetAllCdrStatsDrv() (css []*CdrStats, err error) { - err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur, err := ms.getCol(colCrs).Find(sctx, nil) - if err != nil { - return err - } - for cur.Next(sctx) { - var cs CdrStats - err := cur.Decode(&cs) - if err != nil { - return err - } - clone := cs // avoid using the same pointer in append - css = append(css, &clone) - } - return cur.Close(sctx) - }) - return -} - -func (ms *MongoStorageNew) SetCdrStatsDrv(cs *CdrStats) error { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - _, err = ms.getCol(colCrs).UpdateOne(sctx, bson.M{"id": cs.Id}, - bson.M{"$set": cs}, - options.Update().SetUpsert(true), - ) - return err - }) -} - -func (ms *MongoStorageNew) GetResourceProfileDrv(tenant, id string) (rp *ResourceProfile, err error) { +func (ms *MongoStorage) GetResourceProfileDrv(tenant, id string) (rp *ResourceProfile, err error) { rp = new(ResourceProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colRsP).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -1788,7 +1760,7 @@ func (ms *MongoStorageNew) GetResourceProfileDrv(tenant, id string) (rp *Resourc return } -func (ms *MongoStorageNew) SetResourceProfileDrv(rp *ResourceProfile) (err error) { +func (ms *MongoStorage) SetResourceProfileDrv(rp *ResourceProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colRsP).UpdateOne(sctx, bson.M{"tenant": rp.Tenant, "id": rp.ID}, bson.M{"$set": rp}, @@ -1798,9 +1770,9 @@ func (ms *MongoStorageNew) SetResourceProfileDrv(rp *ResourceProfile) (err error }) } -func (ms *MongoStorageNew) RemoveResourceProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveResourceProfileDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - dr, err := ms.getCol(colDcs).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) + dr, err := ms.getCol(colRsP).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { return utils.ErrNotFound } @@ -1808,7 +1780,7 @@ func (ms *MongoStorageNew) RemoveResourceProfileDrv(tenant, id string) (err erro }) } -func (ms *MongoStorageNew) GetResourceDrv(tenant, id string) (r *Resource, err error) { +func (ms *MongoStorage) GetResourceDrv(tenant, id string) (r *Resource, err error) { r = new(Resource) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colRes).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -1823,7 +1795,7 @@ func (ms *MongoStorageNew) GetResourceDrv(tenant, id string) (r *Resource, err e return } -func (ms *MongoStorageNew) SetResourceDrv(r *Resource) (err error) { +func (ms *MongoStorage) SetResourceDrv(r *Resource) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colRes).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID}, bson.M{"$set": r}, @@ -1833,7 +1805,7 @@ func (ms *MongoStorageNew) SetResourceDrv(r *Resource) (err error) { }) } -func (ms *MongoStorageNew) RemoveResourceDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveResourceDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colRes).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -1843,7 +1815,7 @@ func (ms *MongoStorageNew) RemoveResourceDrv(tenant, id string) (err error) { }) } -func (ms *MongoStorageNew) GetTimingDrv(id string) (t *utils.TPTiming, err error) { +func (ms *MongoStorage) GetTimingDrv(id string) (t *utils.TPTiming, err error) { t = new(utils.TPTiming) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colTmg).FindOne(sctx, bson.M{"id": id}) @@ -1858,7 +1830,7 @@ func (ms *MongoStorageNew) GetTimingDrv(id string) (t *utils.TPTiming, err error return } -func (ms *MongoStorageNew) SetTimingDrv(t *utils.TPTiming) (err error) { +func (ms *MongoStorage) SetTimingDrv(t *utils.TPTiming) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colTmg).UpdateOne(sctx, bson.M{"id": t.ID}, bson.M{"$set": t}, @@ -1868,7 +1840,7 @@ func (ms *MongoStorageNew) SetTimingDrv(t *utils.TPTiming) (err error) { }) } -func (ms *MongoStorageNew) RemoveTimingDrv(id string) (err error) { +func (ms *MongoStorage) RemoveTimingDrv(id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colTmg).DeleteOne(sctx, bson.M{"id": id}) if dr.DeletedCount == 0 { @@ -1880,7 +1852,7 @@ func (ms *MongoStorageNew) RemoveTimingDrv(id string) (err error) { // GetFilterIndexesDrv retrieves Indexes from dataDB //filterType is used togheter with fieldName:Val -func (ms *MongoStorageNew) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType string, +func (ms *MongoStorage) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType string, fldNameVal map[string]string) (indexes map[string]utils.StringMap, err error) { type result struct { Key string @@ -1959,7 +1931,7 @@ func (ms *MongoStorageNew) GetFilterIndexesDrv(cacheID, itemIDPrefix, filterType } // SetFilterIndexesDrv stores Indexes into DataDB -func (ms *MongoStorageNew) SetFilterIndexesDrv(cacheID, itemIDPrefix string, +func (ms *MongoStorage) SetFilterIndexesDrv(cacheID, itemIDPrefix string, indexes map[string]utils.StringMap, commit bool, transactionID string) (err error) { originKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix dbKey := originKey @@ -2025,7 +1997,7 @@ func (ms *MongoStorageNew) SetFilterIndexesDrv(cacheID, itemIDPrefix string, } } -func (ms *MongoStorageNew) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (err error) { +func (ms *MongoStorage) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) (err error) { regexKey := utils.CacheInstanceToPrefix[cacheID] + itemIDPrefix for _, character := range []string{".", "*"} { regexKey = strings.Replace(regexKey, character, `\`+character, strings.Count(regexKey, character)) @@ -2037,7 +2009,7 @@ func (ms *MongoStorageNew) RemoveFilterIndexesDrv(cacheID, itemIDPrefix string) }) } -func (ms *MongoStorageNew) MatchFilterIndexDrv(cacheID, itemIDPrefix, +func (ms *MongoStorage) MatchFilterIndexDrv(cacheID, itemIDPrefix, filterType, fldName, fldVal string) (itemIDs utils.StringMap, err error) { var result struct { Key string @@ -2060,7 +2032,7 @@ func (ms *MongoStorageNew) MatchFilterIndexDrv(cacheID, itemIDPrefix, } // GetStatQueueProfileDrv retrieves a StatQueueProfile from dataDB -func (ms *MongoStorageNew) GetStatQueueProfileDrv(tenant string, id string) (sq *StatQueueProfile, err error) { +func (ms *MongoStorage) GetStatQueueProfileDrv(tenant string, id string) (sq *StatQueueProfile, err error) { sq = new(StatQueueProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colSqp).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2076,7 +2048,7 @@ func (ms *MongoStorageNew) GetStatQueueProfileDrv(tenant string, id string) (sq } // SetStatQueueProfileDrv stores a StatsQueue into DataDB -func (ms *MongoStorageNew) SetStatQueueProfileDrv(sq *StatQueueProfile) (err error) { +func (ms *MongoStorage) SetStatQueueProfileDrv(sq *StatQueueProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colSqp).UpdateOne(sctx, bson.M{"tenant": sq.Tenant, "id": sq.ID}, bson.M{"$set": sq}, @@ -2087,7 +2059,7 @@ func (ms *MongoStorageNew) SetStatQueueProfileDrv(sq *StatQueueProfile) (err err } // RemStatQueueProfileDrv removes a StatsQueue from dataDB -func (ms *MongoStorageNew) RemStatQueueProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemStatQueueProfileDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colSqp).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2098,7 +2070,7 @@ func (ms *MongoStorageNew) RemStatQueueProfileDrv(tenant, id string) (err error) } // GetStoredStatQueueDrv retrieves a StoredStatQueue -func (ms *MongoStorageNew) GetStoredStatQueueDrv(tenant, id string) (sq *StoredStatQueue, err error) { +func (ms *MongoStorage) GetStoredStatQueueDrv(tenant, id string) (sq *StoredStatQueue, err error) { sq = new(StoredStatQueue) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colSqs).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2114,7 +2086,7 @@ func (ms *MongoStorageNew) GetStoredStatQueueDrv(tenant, id string) (sq *StoredS } // SetStoredStatQueueDrv stores the metrics for a StoredStatQueue -func (ms *MongoStorageNew) SetStoredStatQueueDrv(sq *StoredStatQueue) (err error) { +func (ms *MongoStorage) SetStoredStatQueueDrv(sq *StoredStatQueue) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colSqs).UpdateOne(sctx, bson.M{"tenant": sq.Tenant, "id": sq.ID}, bson.M{"$set": sq}, @@ -2125,7 +2097,7 @@ func (ms *MongoStorageNew) SetStoredStatQueueDrv(sq *StoredStatQueue) (err error } // RemStoredStatQueueDrv removes stored metrics for a StoredStatQueue -func (ms *MongoStorageNew) RemStoredStatQueueDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemStoredStatQueueDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colSqs).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2136,7 +2108,7 @@ func (ms *MongoStorageNew) RemStoredStatQueueDrv(tenant, id string) (err error) } // GetThresholdProfileDrv retrieves a ThresholdProfile from dataDB -func (ms *MongoStorageNew) GetThresholdProfileDrv(tenant, ID string) (tp *ThresholdProfile, err error) { +func (ms *MongoStorage) GetThresholdProfileDrv(tenant, ID string) (tp *ThresholdProfile, err error) { tp = new(ThresholdProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colTps).FindOne(sctx, bson.M{"tenant": tenant, "id": ID}) @@ -2152,7 +2124,7 @@ func (ms *MongoStorageNew) GetThresholdProfileDrv(tenant, ID string) (tp *Thresh } // SetThresholdProfileDrv stores a ThresholdProfile into DataDB -func (ms *MongoStorageNew) SetThresholdProfileDrv(tp *ThresholdProfile) (err error) { +func (ms *MongoStorage) SetThresholdProfileDrv(tp *ThresholdProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colTps).UpdateOne(sctx, bson.M{"tenant": tp.Tenant, "id": tp.ID}, bson.M{"$set": tp}, options.Update().SetUpsert(true), @@ -2162,7 +2134,7 @@ func (ms *MongoStorageNew) SetThresholdProfileDrv(tp *ThresholdProfile) (err err } // RemoveThresholdProfile removes a ThresholdProfile from dataDB/cache -func (ms *MongoStorageNew) RemThresholdProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemThresholdProfileDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colTps).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2172,7 +2144,7 @@ func (ms *MongoStorageNew) RemThresholdProfileDrv(tenant, id string) (err error) }) } -func (ms *MongoStorageNew) GetThresholdDrv(tenant, id string) (r *Threshold, err error) { +func (ms *MongoStorage) GetThresholdDrv(tenant, id string) (r *Threshold, err error) { r = new(Threshold) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colThs).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2187,7 +2159,7 @@ func (ms *MongoStorageNew) GetThresholdDrv(tenant, id string) (r *Threshold, err return } -func (ms *MongoStorageNew) SetThresholdDrv(r *Threshold) (err error) { +func (ms *MongoStorage) SetThresholdDrv(r *Threshold) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colThs).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID}, bson.M{"$set": r}, @@ -2197,7 +2169,7 @@ func (ms *MongoStorageNew) SetThresholdDrv(r *Threshold) (err error) { }) } -func (ms *MongoStorageNew) RemoveThresholdDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveThresholdDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colThs).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2207,7 +2179,7 @@ func (ms *MongoStorageNew) RemoveThresholdDrv(tenant, id string) (err error) { }) } -func (ms *MongoStorageNew) GetFilterDrv(tenant, id string) (r *Filter, err error) { +func (ms *MongoStorage) GetFilterDrv(tenant, id string) (r *Filter, err error) { r = new(Filter) if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colFlt).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2229,7 +2201,7 @@ func (ms *MongoStorageNew) GetFilterDrv(tenant, id string) (r *Filter, err error return } -func (ms *MongoStorageNew) SetFilterDrv(r *Filter) (err error) { +func (ms *MongoStorage) SetFilterDrv(r *Filter) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colFlt).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID}, bson.M{"$set": r}, @@ -2239,7 +2211,7 @@ func (ms *MongoStorageNew) SetFilterDrv(r *Filter) (err error) { }) } -func (ms *MongoStorageNew) RemoveFilterDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveFilterDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colFlt).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2249,7 +2221,7 @@ func (ms *MongoStorageNew) RemoveFilterDrv(tenant, id string) (err error) { }) } -func (ms *MongoStorageNew) GetSupplierProfileDrv(tenant, id string) (r *SupplierProfile, err error) { +func (ms *MongoStorage) GetSupplierProfileDrv(tenant, id string) (r *SupplierProfile, err error) { r = new(SupplierProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colSpp).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2264,7 +2236,7 @@ func (ms *MongoStorageNew) GetSupplierProfileDrv(tenant, id string) (r *Supplier return } -func (ms *MongoStorageNew) SetSupplierProfileDrv(r *SupplierProfile) (err error) { +func (ms *MongoStorage) SetSupplierProfileDrv(r *SupplierProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colSpp).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID}, bson.M{"$set": r}, @@ -2274,7 +2246,7 @@ func (ms *MongoStorageNew) SetSupplierProfileDrv(r *SupplierProfile) (err error) }) } -func (ms *MongoStorageNew) RemoveSupplierProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveSupplierProfileDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colSpp).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2284,7 +2256,7 @@ func (ms *MongoStorageNew) RemoveSupplierProfileDrv(tenant, id string) (err erro }) } -func (ms *MongoStorageNew) GetAttributeProfileDrv(tenant, id string) (r *AttributeProfile, err error) { +func (ms *MongoStorage) GetAttributeProfileDrv(tenant, id string) (r *AttributeProfile, err error) { r = new(AttributeProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colAttr).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2299,7 +2271,7 @@ func (ms *MongoStorageNew) GetAttributeProfileDrv(tenant, id string) (r *Attribu return } -func (ms *MongoStorageNew) SetAttributeProfileDrv(r *AttributeProfile) (err error) { +func (ms *MongoStorage) SetAttributeProfileDrv(r *AttributeProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colAttr).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID}, bson.M{"$set": r}, @@ -2309,7 +2281,7 @@ func (ms *MongoStorageNew) SetAttributeProfileDrv(r *AttributeProfile) (err erro }) } -func (ms *MongoStorageNew) RemoveAttributeProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveAttributeProfileDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colAttr).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { @@ -2319,7 +2291,7 @@ func (ms *MongoStorageNew) RemoveAttributeProfileDrv(tenant, id string) (err err }) } -func (ms *MongoStorageNew) GetChargerProfileDrv(tenant, id string) (r *ChargerProfile, err error) { +func (ms *MongoStorage) GetChargerProfileDrv(tenant, id string) (r *ChargerProfile, err error) { r = new(ChargerProfile) err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(colCpp).FindOne(sctx, bson.M{"tenant": tenant, "id": id}) @@ -2334,7 +2306,7 @@ func (ms *MongoStorageNew) GetChargerProfileDrv(tenant, id string) (r *ChargerPr return } -func (ms *MongoStorageNew) SetChargerProfileDrv(r *ChargerProfile) (err error) { +func (ms *MongoStorage) SetChargerProfileDrv(r *ChargerProfile) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { _, err = ms.getCol(colCpp).UpdateOne(sctx, bson.M{"tenant": r.Tenant, "id": r.ID}, bson.M{"$set": r}, @@ -2344,7 +2316,7 @@ func (ms *MongoStorageNew) SetChargerProfileDrv(r *ChargerProfile) (err error) { }) } -func (ms *MongoStorageNew) RemoveChargerProfileDrv(tenant, id string) (err error) { +func (ms *MongoStorage) RemoveChargerProfileDrv(tenant, id string) (err error) { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colCpp).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id}) if dr.DeletedCount == 0 { diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 997d9a310..caf6ec8ac 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -29,7 +29,7 @@ import ( "github.com/cgrates/mgo/bson" ) -func (ms *MongoStorage) GetTpIds(colName string) ([]string, error) { +func (ms *MongoStorageOld) GetTpIds(colName string) ([]string, error) { tpidMap := make(map[string]bool) session := ms.session.Copy() db := session.DB(ms.db) @@ -60,7 +60,7 @@ func (ms *MongoStorage) GetTpIds(colName string) ([]string, error) { return tpids, nil } -func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) { +func (ms *MongoStorageOld) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) { findMap := make(map[string]interface{}) if tpid != "" { findMap["tpid"] = tpid @@ -68,7 +68,7 @@ func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDisti for k, v := range filter { findMap[k] = v } - for k, v := range distinct { //fix for MongoStorage on TPUsers + for k, v := range distinct { //fix for MongoStorageOld on TPUsers if v == "user_name" { distinct[k] = "username" } @@ -129,7 +129,7 @@ func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDisti return distinctIds.Slice(), nil } -func (ms *MongoStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { +func (ms *MongoStorageOld) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { filter := bson.M{ "tpid": tpid, } @@ -146,7 +146,7 @@ func (ms *MongoStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e return results, err } -func (ms *MongoStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestination, error) { +func (ms *MongoStorageOld) GetTPDestinations(tpid, id string) ([]*utils.TPDestination, error) { filter := bson.M{ "tpid": tpid, } @@ -163,7 +163,7 @@ func (ms *MongoStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestinati return results, err } -func (ms *MongoStorage) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { +func (ms *MongoStorageOld) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { filter := bson.M{ "tpid": tpid, } @@ -185,7 +185,7 @@ func (ms *MongoStorage) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { return results, err } -func (ms *MongoStorage) GetTPDestinationRates(tpid, id string, pag *utils.Paginator) ([]*utils.TPDestinationRate, error) { +func (ms *MongoStorageOld) GetTPDestinationRates(tpid, id string, pag *utils.Paginator) ([]*utils.TPDestinationRate, error) { filter := bson.M{ "tpid": tpid, } @@ -211,7 +211,7 @@ func (ms *MongoStorage) GetTPDestinationRates(tpid, id string, pag *utils.Pagina return results, err } -func (ms *MongoStorage) GetTPRatingPlans(tpid, id string, pag *utils.Paginator) ([]*utils.TPRatingPlan, error) { +func (ms *MongoStorageOld) GetTPRatingPlans(tpid, id string, pag *utils.Paginator) ([]*utils.TPRatingPlan, error) { filter := bson.M{ "tpid": tpid, } @@ -237,7 +237,7 @@ func (ms *MongoStorage) GetTPRatingPlans(tpid, id string, pag *utils.Paginator) return results, err } -func (ms *MongoStorage) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { +func (ms *MongoStorageOld) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { filter := bson.M{"tpid": tp.TPid} if tp.Direction != "" { filter["direction"] = tp.Direction @@ -264,7 +264,7 @@ func (ms *MongoStorage) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*utils return results, err } -func (ms *MongoStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { +func (ms *MongoStorageOld) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { filter := bson.M{ "tpid": tpid, } @@ -281,7 +281,7 @@ func (ms *MongoStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro return results, err } -func (ms *MongoStorage) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, error) { +func (ms *MongoStorageOld) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, error) { filter := bson.M{"tpid": tp.TPid} if tp.Tenant != "" { filter["tenant"] = tp.Tenant @@ -299,7 +299,7 @@ func (ms *MongoStorage) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, error) return results, err } -func (ms *MongoStorage) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases, error) { +func (ms *MongoStorageOld) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases, error) { filter := bson.M{"tpid": tp.TPid} if tp.Direction != "" { filter["direction"] = tp.Direction @@ -329,7 +329,7 @@ func (ms *MongoStorage) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases, e return results, err } -func (ms *MongoStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { +func (ms *MongoStorageOld) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { filter := bson.M{ "tpid": tpid, } @@ -346,7 +346,7 @@ func (ms *MongoStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, er return results, err } -func (ms *MongoStorage) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { +func (ms *MongoStorageOld) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { filter := bson.M{ "tpid": tpid, } @@ -363,7 +363,7 @@ func (ms *MongoStorage) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { return results, err } -func (ms *MongoStorage) GetTPDerivedChargers(tp *utils.TPDerivedChargers) ([]*utils.TPDerivedChargers, error) { +func (ms *MongoStorageOld) GetTPDerivedChargers(tp *utils.TPDerivedChargers) ([]*utils.TPDerivedChargers, error) { filter := bson.M{"tpid": tp.TPid} if tp.Direction != "" { filter["direction"] = tp.Direction @@ -393,7 +393,7 @@ func (ms *MongoStorage) GetTPDerivedChargers(tp *utils.TPDerivedChargers) ([]*ut return results, err } -func (ms *MongoStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { +func (ms *MongoStorageOld) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { filter := bson.M{ "tpid": tpid, } @@ -410,7 +410,7 @@ func (ms *MongoStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error return results, err } -func (ms *MongoStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { +func (ms *MongoStorageOld) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { filter := bson.M{ "tpid": tpid, } @@ -427,7 +427,7 @@ func (ms *MongoStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan return results, err } -func (ms *MongoStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { +func (ms *MongoStorageOld) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { filter := bson.M{ "tpid": tpid, } @@ -444,7 +444,7 @@ func (ms *MongoStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionT return results, err } -func (ms *MongoStorage) GetTPAccountActions(tp *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { +func (ms *MongoStorageOld) GetTPAccountActions(tp *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { filter := bson.M{"tpid": tp.TPid} if tp.Tenant != "" { filter["tenant"] = tp.Tenant @@ -465,7 +465,7 @@ func (ms *MongoStorage) GetTPAccountActions(tp *utils.TPAccountActions) ([]*util return results, err } -func (ms *MongoStorage) RemTpData(table, tpid string, args map[string]string) error { +func (ms *MongoStorageOld) RemTpData(table, tpid string, args map[string]string) error { session := ms.session.Copy() db := session.DB(ms.db) defer session.Close() @@ -504,7 +504,7 @@ func (ms *MongoStorage) RemTpData(table, tpid string, args map[string]string) er return db.C(table).Remove(args) } -func (ms *MongoStorage) SetTPTimings(tps []*utils.ApierTPTiming) error { +func (ms *MongoStorageOld) SetTPTimings(tps []*utils.ApierTPTiming) error { if len(tps) == 0 { return nil } @@ -518,7 +518,7 @@ func (ms *MongoStorage) SetTPTimings(tps []*utils.ApierTPTiming) error { return err } -func (ms *MongoStorage) SetTPDestinations(tpDsts []*utils.TPDestination) (err error) { +func (ms *MongoStorageOld) SetTPDestinations(tpDsts []*utils.TPDestination) (err error) { if len(tpDsts) == 0 { return } @@ -532,7 +532,7 @@ func (ms *MongoStorage) SetTPDestinations(tpDsts []*utils.TPDestination) (err er return } -func (ms *MongoStorage) SetTPRates(tps []*utils.TPRate) error { +func (ms *MongoStorageOld) SetTPRates(tps []*utils.TPRate) error { if len(tps) == 0 { return nil } @@ -551,7 +551,7 @@ func (ms *MongoStorage) SetTPRates(tps []*utils.TPRate) error { return err } -func (ms *MongoStorage) SetTPDestinationRates(tps []*utils.TPDestinationRate) error { +func (ms *MongoStorageOld) SetTPDestinationRates(tps []*utils.TPDestinationRate) error { if len(tps) == 0 { return nil } @@ -570,7 +570,7 @@ func (ms *MongoStorage) SetTPDestinationRates(tps []*utils.TPDestinationRate) er return err } -func (ms *MongoStorage) SetTPRatingPlans(tps []*utils.TPRatingPlan) error { +func (ms *MongoStorageOld) SetTPRatingPlans(tps []*utils.TPRatingPlan) error { if len(tps) == 0 { return nil } @@ -589,7 +589,7 @@ func (ms *MongoStorage) SetTPRatingPlans(tps []*utils.TPRatingPlan) error { return err } -func (ms *MongoStorage) SetTPRatingProfiles(tps []*utils.TPRatingProfile) error { +func (ms *MongoStorageOld) SetTPRatingProfiles(tps []*utils.TPRatingProfile) error { if len(tps) == 0 { return nil } @@ -610,7 +610,7 @@ func (ms *MongoStorage) SetTPRatingProfiles(tps []*utils.TPRatingProfile) error return err } -func (ms *MongoStorage) SetTPSharedGroups(tps []*utils.TPSharedGroups) error { +func (ms *MongoStorageOld) SetTPSharedGroups(tps []*utils.TPSharedGroups) error { if len(tps) == 0 { return nil } @@ -629,7 +629,7 @@ func (ms *MongoStorage) SetTPSharedGroups(tps []*utils.TPSharedGroups) error { return err } -func (ms *MongoStorage) SetTPUsers(tps []*utils.TPUsers) error { +func (ms *MongoStorageOld) SetTPUsers(tps []*utils.TPUsers) error { if len(tps) == 0 { return nil } @@ -652,7 +652,7 @@ func (ms *MongoStorage) SetTPUsers(tps []*utils.TPUsers) error { return err } -func (ms *MongoStorage) SetTPAliases(tps []*utils.TPAliases) error { +func (ms *MongoStorageOld) SetTPAliases(tps []*utils.TPAliases) error { if len(tps) == 0 { return nil } @@ -678,7 +678,7 @@ func (ms *MongoStorage) SetTPAliases(tps []*utils.TPAliases) error { return err } -func (ms *MongoStorage) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) error { +func (ms *MongoStorageOld) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) error { if len(tps) == 0 { return nil } @@ -703,7 +703,7 @@ func (ms *MongoStorage) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) err return err } -func (ms *MongoStorage) SetTPActions(tps []*utils.TPActions) error { +func (ms *MongoStorageOld) SetTPActions(tps []*utils.TPActions) error { if len(tps) == 0 { return nil } @@ -722,7 +722,7 @@ func (ms *MongoStorage) SetTPActions(tps []*utils.TPActions) error { return err } -func (ms *MongoStorage) SetTPActionPlans(tps []*utils.TPActionPlan) error { +func (ms *MongoStorageOld) SetTPActionPlans(tps []*utils.TPActionPlan) error { if len(tps) == 0 { return nil } @@ -741,7 +741,7 @@ func (ms *MongoStorage) SetTPActionPlans(tps []*utils.TPActionPlan) error { return err } -func (ms *MongoStorage) SetTPActionTriggers(tps []*utils.TPActionTriggers) error { +func (ms *MongoStorageOld) SetTPActionTriggers(tps []*utils.TPActionTriggers) error { if len(tps) == 0 { return nil } @@ -760,7 +760,7 @@ func (ms *MongoStorage) SetTPActionTriggers(tps []*utils.TPActionTriggers) error return err } -func (ms *MongoStorage) SetTPAccountActions(tps []*utils.TPAccountActions) error { +func (ms *MongoStorageOld) SetTPAccountActions(tps []*utils.TPAccountActions) error { if len(tps) == 0 { return nil } @@ -778,7 +778,7 @@ func (ms *MongoStorage) SetTPAccountActions(tps []*utils.TPAccountActions) error return err } -func (ms *MongoStorage) SetTPResources(tpRLs []*utils.TPResource) (err error) { +func (ms *MongoStorageOld) SetTPResources(tpRLs []*utils.TPResource) (err error) { if len(tpRLs) == 0 { return } @@ -792,7 +792,7 @@ func (ms *MongoStorage) SetTPResources(tpRLs []*utils.TPResource) (err error) { return } -func (ms *MongoStorage) SetTPRStats(tpS []*utils.TPStats) (err error) { +func (ms *MongoStorageOld) SetTPRStats(tpS []*utils.TPStats) (err error) { if len(tpS) == 0 { return } @@ -806,7 +806,7 @@ func (ms *MongoStorage) SetTPRStats(tpS []*utils.TPStats) (err error) { return } -func (ms *MongoStorage) SetSMCost(smc *SMCost) error { +func (ms *MongoStorageOld) SetSMCost(smc *SMCost) error { if smc.CostDetails == nil { return nil } @@ -815,7 +815,7 @@ func (ms *MongoStorage) SetSMCost(smc *SMCost) error { return col.Insert(smc) } -func (ms *MongoStorage) RemoveSMCost(smc *SMCost) error { +func (ms *MongoStorageOld) RemoveSMCost(smc *SMCost) error { session, col := ms.conn(utils.SessionsCostsTBL) defer session.Close() remParams := bson.M{} @@ -828,7 +828,7 @@ func (ms *MongoStorage) RemoveSMCost(smc *SMCost) error { return err } -func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) (smcs []*SMCost, err error) { +func (ms *MongoStorageOld) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) (smcs []*SMCost, err error) { filter := bson.M{} if cgrid != "" { filter[CGRIDLow] = cgrid @@ -860,7 +860,7 @@ func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri return smcs, nil } -func (ms *MongoStorage) SetCDR(cdr *CDR, allowUpdate bool) (err error) { +func (ms *MongoStorageOld) SetCDR(cdr *CDR, allowUpdate bool) (err error) { if cdr.OrderID == 0 { cdr.OrderID = ms.cnter.Next() } @@ -874,7 +874,7 @@ func (ms *MongoStorage) SetCDR(cdr *CDR, allowUpdate bool) (err error) { return err } -func (ms *MongoStorage) cleanEmptyFilters(filters bson.M) { +func (ms *MongoStorageOld) cleanEmptyFilters(filters bson.M) { for k, v := range filters { switch value := v.(type) { case *int64: @@ -907,7 +907,7 @@ func (ms *MongoStorage) cleanEmptyFilters(filters bson.M) { } // _, err := col(ColCDRs).UpdateAll(bson.M{CGRIDLow: bson.M{"$in": cgrIds}}, bson.M{"$set": bson.M{"deleted_at": time.Now()}}) -func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, int64, error) { +func (ms *MongoStorageOld) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, int64, error) { var minUsage, maxUsage *time.Duration if len(qryFltr.MinUsage) != 0 { if parsed, err := utils.ParseDurationWithNanosecs(qryFltr.MinUsage); err != nil { @@ -1079,7 +1079,7 @@ func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, return cdrs, 0, nil } -func (ms *MongoStorage) GetTPStat(tpid, id string) ([]*utils.TPStats, error) { +func (ms *MongoStorageOld) GetTPStat(tpid, id string) ([]*utils.TPStats, error) { filter := bson.M{ "tpid": tpid, } @@ -1096,7 +1096,7 @@ func (ms *MongoStorage) GetTPStat(tpid, id string) ([]*utils.TPStats, error) { return results, err } -func (ms *MongoStorage) SetTPStats(tpSTs []*utils.TPStats) (err error) { +func (ms *MongoStorageOld) SetTPStats(tpSTs []*utils.TPStats) (err error) { if len(tpSTs) == 0 { return } @@ -1110,7 +1110,7 @@ func (ms *MongoStorage) SetTPStats(tpSTs []*utils.TPStats) (err error) { return } -func (ms *MongoStorage) GetTPThresholds(tpid, id string) ([]*utils.TPThreshold, error) { +func (ms *MongoStorageOld) GetTPThresholds(tpid, id string) ([]*utils.TPThreshold, error) { filter := bson.M{ "tpid": tpid, } @@ -1127,7 +1127,7 @@ func (ms *MongoStorage) GetTPThresholds(tpid, id string) ([]*utils.TPThreshold, return results, err } -func (ms *MongoStorage) SetTPThresholds(tpTHs []*utils.TPThreshold) (err error) { +func (ms *MongoStorageOld) SetTPThresholds(tpTHs []*utils.TPThreshold) (err error) { if len(tpTHs) == 0 { return } @@ -1141,7 +1141,7 @@ func (ms *MongoStorage) SetTPThresholds(tpTHs []*utils.TPThreshold) (err error) return } -func (ms *MongoStorage) GetTPFilters(tpid, id string) ([]*utils.TPFilterProfile, error) { +func (ms *MongoStorageOld) GetTPFilters(tpid, id string) ([]*utils.TPFilterProfile, error) { filter := bson.M{ "tpid": tpid, } @@ -1158,7 +1158,7 @@ func (ms *MongoStorage) GetTPFilters(tpid, id string) ([]*utils.TPFilterProfile, return results, err } -func (ms *MongoStorage) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err error) { +func (ms *MongoStorageOld) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err error) { if len(tpTHs) == 0 { return } @@ -1172,7 +1172,7 @@ func (ms *MongoStorage) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err error) return } -func (ms *MongoStorage) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) { +func (ms *MongoStorageOld) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) { filter := bson.M{ "tpid": tpid, } @@ -1189,7 +1189,7 @@ func (ms *MongoStorage) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProf return results, err } -func (ms *MongoStorage) SetTPSuppliers(tpSPs []*utils.TPSupplierProfile) (err error) { +func (ms *MongoStorageOld) SetTPSuppliers(tpSPs []*utils.TPSupplierProfile) (err error) { if len(tpSPs) == 0 { return } @@ -1203,7 +1203,7 @@ func (ms *MongoStorage) SetTPSuppliers(tpSPs []*utils.TPSupplierProfile) (err er return } -func (ms *MongoStorage) GetTPAttributes(tpid, id string) ([]*utils.TPAttributeProfile, error) { +func (ms *MongoStorageOld) GetTPAttributes(tpid, id string) ([]*utils.TPAttributeProfile, error) { filter := bson.M{ "tpid": tpid, } @@ -1220,7 +1220,7 @@ func (ms *MongoStorage) GetTPAttributes(tpid, id string) ([]*utils.TPAttributePr return results, err } -func (ms *MongoStorage) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (err error) { +func (ms *MongoStorageOld) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (err error) { if len(tpSPs) == 0 { return } @@ -1234,7 +1234,7 @@ func (ms *MongoStorage) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (err return } -func (ms *MongoStorage) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) { +func (ms *MongoStorageOld) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) { filter := bson.M{ "tpid": tpid, } @@ -1251,7 +1251,7 @@ func (ms *MongoStorage) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfil return results, err } -func (ms *MongoStorage) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err error) { +func (ms *MongoStorageOld) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err error) { if len(tpCPP) == 0 { return } @@ -1265,7 +1265,7 @@ func (ms *MongoStorage) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err erro return } -func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) { +func (ms *MongoStorageOld) GetVersions(itm string) (vrs Versions, err error) { session, col := ms.conn(colVer) defer session.Close() proj := bson.M{} // projection params @@ -1284,7 +1284,7 @@ func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) { return } -func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) { +func (ms *MongoStorageOld) SetVersions(vrs Versions, overwrite bool) (err error) { session, col := ms.conn(colVer) defer session.Close() if overwrite { @@ -1295,7 +1295,7 @@ func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) { return } -func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) { +func (ms *MongoStorageOld) RemoveVersions(vrs Versions) (err error) { session, col := ms.conn(colVer) defer session.Close() if len(vrs) != 0 { @@ -1317,6 +1317,6 @@ func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) { return } -func (ms *MongoStorage) GetStorageType() string { +func (ms *MongoStorageOld) GetStorageType() string { return utils.MONGO } diff --git a/engine/storage_mongo_stordb_new.go b/engine/storage_mongo_stordb_new.go index 1152bc47b..7d931d817 100644 --- a/engine/storage_mongo_stordb_new.go +++ b/engine/storage_mongo_stordb_new.go @@ -30,11 +30,11 @@ import ( "github.com/mongodb/mongo-go-driver/bson" // "github.com/mongodb/mongo-go-driver/bson/objectid" "github.com/mongodb/mongo-go-driver/mongo" - "github.com/mongodb/mongo-go-driver/options" + "github.com/mongodb/mongo-go-driver/mongo/options" "github.com/mongodb/mongo-go-driver/x/bsonx" ) -func (ms *MongoStorageNew) GetTpIds(colName string) (tpids []string, err error) { +func (ms *MongoStorage) GetTpIds(colName string) (tpids []string, err error) { getTpIDs := func(ctx context.Context, col string, tpMap map[string]struct{}) (map[string]struct{}, error) { if strings.HasPrefix(col, "tp_") { result, err := ms.getCol(col).Distinct(ctx, "tpid", nil) @@ -82,7 +82,7 @@ func (ms *MongoStorageNew) GetTpIds(colName string) (tpids []string, err error) return tpids, nil } -func (ms *MongoStorageNew) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) { +func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDistinctIds, filter map[string]string, pag *utils.Paginator) ([]string, error) { findMap := bson.M{} if tpid != "" { findMap["tpid"] = tpid @@ -156,7 +156,7 @@ func (ms *MongoStorageNew) GetTpTableIds(tpid, table string, distinct utils.TPDi return distinctIds.Slice(), nil } -func (ms *MongoStorageNew) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { +func (ms *MongoStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -183,7 +183,7 @@ func (ms *MongoStorageNew) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming return results, err } -func (ms *MongoStorageNew) GetTPDestinations(tpid, id string) ([]*utils.TPDestination, error) { +func (ms *MongoStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestination, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -210,7 +210,7 @@ func (ms *MongoStorageNew) GetTPDestinations(tpid, id string) ([]*utils.TPDestin return results, err } -func (ms *MongoStorageNew) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { +func (ms *MongoStorage) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -240,7 +240,7 @@ func (ms *MongoStorageNew) GetTPRates(tpid, id string) ([]*utils.TPRate, error) return results, err } -func (ms *MongoStorageNew) GetTPDestinationRates(tpid, id string, pag *utils.Paginator) ([]*utils.TPDestinationRate, error) { +func (ms *MongoStorage) GetTPDestinationRates(tpid, id string, pag *utils.Paginator) ([]*utils.TPDestinationRate, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -276,7 +276,7 @@ func (ms *MongoStorageNew) GetTPDestinationRates(tpid, id string, pag *utils.Pag return results, err } -func (ms *MongoStorageNew) GetTPRatingPlans(tpid, id string, pag *utils.Paginator) ([]*utils.TPRatingPlan, error) { +func (ms *MongoStorage) GetTPRatingPlans(tpid, id string, pag *utils.Paginator) ([]*utils.TPRatingPlan, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -312,7 +312,7 @@ func (ms *MongoStorageNew) GetTPRatingPlans(tpid, id string, pag *utils.Paginato return results, err } -func (ms *MongoStorageNew) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { +func (ms *MongoStorage) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { filter := bson.M{"tpid": tp.TPid} if tp.Direction != "" { filter["direction"] = tp.Direction @@ -351,7 +351,7 @@ func (ms *MongoStorageNew) GetTPRatingProfiles(tp *utils.TPRatingProfile) ([]*ut return results, err } -func (ms *MongoStorageNew) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { +func (ms *MongoStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -378,73 +378,7 @@ func (ms *MongoStorageNew) GetTPSharedGroups(tpid, id string) ([]*utils.TPShared return results, err } -func (ms *MongoStorageNew) GetTPCdrStats(tpid, id string) ([]*utils.TPCdrStats, error) { - filter := bson.M{"tpid": tpid} - if id != "" { - filter["id"] = id - } - var results []*utils.TPCdrStats - err := ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur, err := ms.getCol(utils.TBLTPCdrStats).Find(sctx, filter) - if err != nil { - return err - } - for cur.Next(sctx) { - var el utils.TPCdrStats - err := cur.Decode(&el) - if err != nil { - return err - } - results = append(results, &el) - } - if len(results) == 0 { - return utils.ErrNotFound - } - return cur.Close(sctx) - }) - return results, err -} - -func (ms *MongoStorageNew) GetTPLCRs(tp *utils.TPLcrRules) ([]*utils.TPLcrRules, error) { - filter := bson.M{"tpid": tp.TPid} - if tp.Direction != "" { - filter["direction"] = tp.Direction - } - if tp.Tenant != "" { - filter["tenant"] = tp.Tenant - } - if tp.Category != "" { - filter["category"] = tp.Category - } - if tp.Account != "" { - filter["account"] = tp.Account - } - if tp.Subject != "" { - filter["subject"] = tp.Subject - } - var results []*utils.TPLcrRules - err := ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur, err := ms.getCol(utils.TBLTPLcrs).Find(sctx, filter) - if err != nil { - return err - } - for cur.Next(sctx) { - var el utils.TPLcrRules - err := cur.Decode(&el) - if err != nil { - return err - } - results = append(results, &el) - } - if len(results) == 0 { - return utils.ErrNotFound - } - return cur.Close(sctx) - }) - return results, err -} - -func (ms *MongoStorageNew) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, error) { +func (ms *MongoStorage) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, error) { filter := bson.M{"tpid": tp.TPid} if tp.Tenant != "" { filter["tenant"] = tp.Tenant @@ -474,7 +408,7 @@ func (ms *MongoStorageNew) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, erro return results, err } -func (ms *MongoStorageNew) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases, error) { +func (ms *MongoStorage) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases, error) { filter := bson.M{"tpid": tp.TPid} if tp.Direction != "" { filter["direction"] = tp.Direction @@ -516,7 +450,7 @@ func (ms *MongoStorageNew) GetTPAliases(tp *utils.TPAliases) ([]*utils.TPAliases return results, err } -func (ms *MongoStorageNew) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { +func (ms *MongoStorage) GetTPResources(tpid, id string) ([]*utils.TPResource, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -543,7 +477,7 @@ func (ms *MongoStorageNew) GetTPResources(tpid, id string) ([]*utils.TPResource, return results, err } -func (ms *MongoStorageNew) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { +func (ms *MongoStorage) GetTPStats(tpid, id string) ([]*utils.TPStats, error) { filter := bson.M{ "tpid": tpid, } @@ -571,7 +505,7 @@ func (ms *MongoStorageNew) GetTPStats(tpid, id string) ([]*utils.TPStats, error) }) return results, err } -func (ms *MongoStorageNew) GetTPDerivedChargers(tp *utils.TPDerivedChargers) ([]*utils.TPDerivedChargers, error) { +func (ms *MongoStorage) GetTPDerivedChargers(tp *utils.TPDerivedChargers) ([]*utils.TPDerivedChargers, error) { filter := bson.M{"tpid": tp.TPid} if tp.Direction != "" { filter["direction"] = tp.Direction @@ -613,7 +547,7 @@ func (ms *MongoStorageNew) GetTPDerivedChargers(tp *utils.TPDerivedChargers) ([] return results, err } -func (ms *MongoStorageNew) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { +func (ms *MongoStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -640,7 +574,7 @@ func (ms *MongoStorageNew) GetTPActions(tpid, id string) ([]*utils.TPActions, er return results, err } -func (ms *MongoStorageNew) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { +func (ms *MongoStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -667,7 +601,7 @@ func (ms *MongoStorageNew) GetTPActionPlans(tpid, id string) ([]*utils.TPActionP return results, err } -func (ms *MongoStorageNew) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { +func (ms *MongoStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { filter := bson.M{ "tpid": tpid, } @@ -696,7 +630,7 @@ func (ms *MongoStorageNew) GetTPActionTriggers(tpid, id string) ([]*utils.TPActi return results, err } -func (ms *MongoStorageNew) GetTPAccountActions(tp *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { +func (ms *MongoStorage) GetTPAccountActions(tp *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { filter := bson.M{"tpid": tp.TPid} if tp.Tenant != "" { filter["tenant"] = tp.Tenant @@ -729,7 +663,7 @@ func (ms *MongoStorageNew) GetTPAccountActions(tp *utils.TPAccountActions) ([]*u return results, err } -func (ms *MongoStorageNew) RemTpData(table, tpid string, args map[string]string) error { +func (ms *MongoStorage) RemTpData(table, tpid string, args map[string]string) error { if len(table) == 0 { // Remove tpid out of all tables return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { col, err := ms.DB().ListCollections(sctx, nil, options.ListCollections().SetNameOnly(true)) @@ -778,7 +712,7 @@ func (ms *MongoStorageNew) RemTpData(table, tpid string, args map[string]string) }) } -func (ms *MongoStorageNew) SetTPTimings(tps []*utils.ApierTPTiming) error { +func (ms *MongoStorage) SetTPTimings(tps []*utils.ApierTPTiming) error { if len(tps) == 0 { return nil } @@ -796,7 +730,7 @@ func (ms *MongoStorageNew) SetTPTimings(tps []*utils.ApierTPTiming) error { }) } -func (ms *MongoStorageNew) SetTPDestinations(tpDsts []*utils.TPDestination) (err error) { +func (ms *MongoStorage) SetTPDestinations(tpDsts []*utils.TPDestination) (err error) { if len(tpDsts) == 0 { return nil } @@ -814,7 +748,7 @@ func (ms *MongoStorageNew) SetTPDestinations(tpDsts []*utils.TPDestination) (err }) } -func (ms *MongoStorageNew) SetTPRates(tps []*utils.TPRate) error { +func (ms *MongoStorage) SetTPRates(tps []*utils.TPRate) error { if len(tps) == 0 { return nil } @@ -837,7 +771,7 @@ func (ms *MongoStorageNew) SetTPRates(tps []*utils.TPRate) error { }) } -func (ms *MongoStorageNew) SetTPDestinationRates(tps []*utils.TPDestinationRate) error { +func (ms *MongoStorage) SetTPDestinationRates(tps []*utils.TPDestinationRate) error { if len(tps) == 0 { return nil } @@ -860,7 +794,7 @@ func (ms *MongoStorageNew) SetTPDestinationRates(tps []*utils.TPDestinationRate) }) } -func (ms *MongoStorageNew) SetTPRatingPlans(tps []*utils.TPRatingPlan) error { +func (ms *MongoStorage) SetTPRatingPlans(tps []*utils.TPRatingPlan) error { if len(tps) == 0 { return nil } @@ -883,7 +817,7 @@ func (ms *MongoStorageNew) SetTPRatingPlans(tps []*utils.TPRatingPlan) error { }) } -func (ms *MongoStorageNew) SetTPRatingProfiles(tps []*utils.TPRatingProfile) error { +func (ms *MongoStorage) SetTPRatingProfiles(tps []*utils.TPRatingProfile) error { if len(tps) == 0 { return nil } @@ -905,7 +839,7 @@ func (ms *MongoStorageNew) SetTPRatingProfiles(tps []*utils.TPRatingProfile) err }) } -func (ms *MongoStorageNew) SetTPSharedGroups(tps []*utils.TPSharedGroups) error { +func (ms *MongoStorage) SetTPSharedGroups(tps []*utils.TPSharedGroups) error { if len(tps) == 0 { return nil } @@ -928,30 +862,7 @@ func (ms *MongoStorageNew) SetTPSharedGroups(tps []*utils.TPSharedGroups) error }) } -func (ms *MongoStorageNew) SetTPCdrStats(tps []*utils.TPCdrStats) error { - if len(tps) == 0 { - return nil - } - m := make(map[string]bool) - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - for _, tp := range tps { - if found, _ := m[tp.ID]; !found { - m[tp.ID] = true - _, err := ms.getCol(utils.TBLTPCdrStats).DeleteMany(sctx, bson.M{"tpid": tp.TPid, "id": tp.ID}) - if err != nil { - return err - } - } - _, err := ms.getCol(utils.TBLTPCdrStats).InsertOne(sctx, tp) - if err != nil { - return err - } - } - return nil - }) -} - -func (ms *MongoStorageNew) SetTPUsers(tps []*utils.TPUsers) error { +func (ms *MongoStorage) SetTPUsers(tps []*utils.TPUsers) error { if len(tps) == 0 { return nil } @@ -976,7 +887,7 @@ func (ms *MongoStorageNew) SetTPUsers(tps []*utils.TPUsers) error { }) } -func (ms *MongoStorageNew) SetTPAliases(tps []*utils.TPAliases) error { +func (ms *MongoStorage) SetTPAliases(tps []*utils.TPAliases) error { if len(tps) == 0 { return nil } @@ -1004,7 +915,7 @@ func (ms *MongoStorageNew) SetTPAliases(tps []*utils.TPAliases) error { }) } -func (ms *MongoStorageNew) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) error { +func (ms *MongoStorage) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) error { if len(tps) == 0 { return nil } @@ -1031,29 +942,7 @@ func (ms *MongoStorageNew) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) }) } -func (ms *MongoStorageNew) SetTPLCRs(tps []*utils.TPLcrRules) error { - if len(tps) == 0 { - return nil - } - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - for _, tp := range tps { - _, err = ms.getCol(utils.TBLTPLcrs).UpdateOne(sctx, bson.M{ - "tpid": tp.TPid, - "direction": tp.Direction, - "tenant": tp.Tenant, - "category": tp.Category, - "account": tp.Account, - "subject": tp.Subject, - }, bson.M{"$set": tp}, options.Update().SetUpsert(true)) - if err != nil { - return err - } - } - return nil - }) -} - -func (ms *MongoStorageNew) SetTPActions(tps []*utils.TPActions) error { +func (ms *MongoStorage) SetTPActions(tps []*utils.TPActions) error { if len(tps) == 0 { return nil } @@ -1074,7 +963,7 @@ func (ms *MongoStorageNew) SetTPActions(tps []*utils.TPActions) error { }) } -func (ms *MongoStorageNew) SetTPActionPlans(tps []*utils.TPActionPlan) error { +func (ms *MongoStorage) SetTPActionPlans(tps []*utils.TPActionPlan) error { if len(tps) == 0 { return nil } @@ -1095,7 +984,7 @@ func (ms *MongoStorageNew) SetTPActionPlans(tps []*utils.TPActionPlan) error { }) } -func (ms *MongoStorageNew) SetTPActionTriggers(tps []*utils.TPActionTriggers) error { +func (ms *MongoStorage) SetTPActionTriggers(tps []*utils.TPActionTriggers) error { if len(tps) == 0 { return nil } @@ -1116,7 +1005,7 @@ func (ms *MongoStorageNew) SetTPActionTriggers(tps []*utils.TPActionTriggers) er }) } -func (ms *MongoStorageNew) SetTPAccountActions(tps []*utils.TPAccountActions) error { +func (ms *MongoStorage) SetTPAccountActions(tps []*utils.TPAccountActions) error { if len(tps) == 0 { return nil } @@ -1136,7 +1025,7 @@ func (ms *MongoStorageNew) SetTPAccountActions(tps []*utils.TPAccountActions) er }) } -func (ms *MongoStorageNew) SetTPResources(tpRLs []*utils.TPResource) (err error) { +func (ms *MongoStorage) SetTPResources(tpRLs []*utils.TPResource) (err error) { if len(tpRLs) == 0 { return } @@ -1152,7 +1041,7 @@ func (ms *MongoStorageNew) SetTPResources(tpRLs []*utils.TPResource) (err error) }) } -func (ms *MongoStorageNew) SetTPRStats(tps []*utils.TPStats) (err error) { +func (ms *MongoStorage) SetTPRStats(tps []*utils.TPStats) (err error) { if len(tps) == 0 { return } @@ -1168,7 +1057,7 @@ func (ms *MongoStorageNew) SetTPRStats(tps []*utils.TPStats) (err error) { }) } -func (ms *MongoStorageNew) SetSMCost(smc *SMCost) error { +func (ms *MongoStorage) SetSMCost(smc *SMCost) error { if smc.CostDetails == nil { return nil } @@ -1178,7 +1067,7 @@ func (ms *MongoStorageNew) SetSMCost(smc *SMCost) error { }) } -func (ms *MongoStorageNew) RemoveSMCost(smc *SMCost) error { +func (ms *MongoStorage) RemoveSMCost(smc *SMCost) error { remParams := bson.M{} if smc != nil { remParams = bson.M{"cgrid": smc.CGRID, "runid": smc.RunID} @@ -1189,7 +1078,7 @@ func (ms *MongoStorageNew) RemoveSMCost(smc *SMCost) error { }) } -func (ms *MongoStorageNew) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) (smcs []*SMCost, err error) { +func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix string) (smcs []*SMCost, err error) { filter := bson.M{} if cgrid != "" { filter[CGRIDLow] = cgrid @@ -1225,22 +1114,24 @@ func (ms *MongoStorageNew) GetSMCosts(cgrid, runid, originHost, originIDPrefix s return smcs, err } -func (ms *MongoStorageNew) SetCDR(cdr *CDR, allowUpdate bool) (err error) { +func (ms *MongoStorage) SetCDR(cdr *CDR, allowUpdate bool) (err error) { if cdr.OrderID == 0 { cdr.OrderID = ms.cnter.Next() } return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { if allowUpdate { - _, err = ms.getCol(ColCDRs).UpdateOne(sctx, bson.M{CGRIDLow: cdr.CGRID, RunIDLow: cdr.RunID}, + _, err = ms.getCol(ColCDRs).UpdateOne(sctx, + bson.M{CGRIDLow: cdr.CGRID, RunIDLow: cdr.RunID}, bson.M{"$set": cdr}, options.Update().SetUpsert(true)) - return err + // return err + } else { + _, err = ms.getCol(ColCDRs).InsertOne(sctx, cdr) } - _, err = ms.getCol(ColCDRs).InsertOne(sctx, cdr) return err }) } -func (ms *MongoStorageNew) cleanEmptyFilters(filters bson.M) { +func (ms *MongoStorage) cleanEmptyFilters(filters bson.M) { for k, v := range filters { switch value := v.(type) { case *int64: @@ -1273,7 +1164,7 @@ func (ms *MongoStorageNew) cleanEmptyFilters(filters bson.M) { } // _, err := col(ColCDRs).UpdateAll(bson.M{CGRIDLow: bson.M{"$in": cgrIds}}, bson.M{"$set": bson.M{"deleted_at": time.Now()}}) -func (ms *MongoStorageNew) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, int64, error) { +func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, int64, error) { var minUsage, maxUsage *time.Duration if len(qryFltr.MinUsage) != 0 { if parsed, err := utils.ParseDurationWithNanosecs(qryFltr.MinUsage); err != nil { @@ -1408,8 +1299,10 @@ func (ms *MongoStorageNew) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*C if qryFltr.OrderBy != "" { var orderVal string separateVals := strings.Split(qryFltr.OrderBy, utils.INFIELD_SEP) + ordVal := 1 if len(separateVals) == 2 && separateVals[1] == "desc" { - orderVal += "-" + ordVal = -1 + // orderVal += "-" } switch separateVals[0] { case utils.OrderID: @@ -1425,7 +1318,7 @@ func (ms *MongoStorageNew) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*C default: return nil, 0, fmt.Errorf("Invalid value : %s", separateVals[0]) } - fop = fop.SetSort(bson.M{orderVal: 1}) + fop = fop.SetSort(bson.M{orderVal: ordVal}) } if qryFltr.Count { var cnt int64 @@ -1459,7 +1352,7 @@ func (ms *MongoStorageNew) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*C return cdrs, 0, err } -func (ms *MongoStorageNew) GetTPStat(tpid, id string) ([]*utils.TPStats, error) { +func (ms *MongoStorage) GetTPStat(tpid, id string) ([]*utils.TPStats, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1486,7 +1379,7 @@ func (ms *MongoStorageNew) GetTPStat(tpid, id string) ([]*utils.TPStats, error) return results, err } -func (ms *MongoStorageNew) SetTPStats(tpSTs []*utils.TPStats) (err error) { +func (ms *MongoStorage) SetTPStats(tpSTs []*utils.TPStats) (err error) { if len(tpSTs) == 0 { return } @@ -1504,7 +1397,7 @@ func (ms *MongoStorageNew) SetTPStats(tpSTs []*utils.TPStats) (err error) { }) } -func (ms *MongoStorageNew) GetTPThresholds(tpid, id string) ([]*utils.TPThreshold, error) { +func (ms *MongoStorage) GetTPThresholds(tpid, id string) ([]*utils.TPThreshold, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1531,7 +1424,7 @@ func (ms *MongoStorageNew) GetTPThresholds(tpid, id string) ([]*utils.TPThreshol return results, err } -func (ms *MongoStorageNew) SetTPThresholds(tpTHs []*utils.TPThreshold) (err error) { +func (ms *MongoStorage) SetTPThresholds(tpTHs []*utils.TPThreshold) (err error) { if len(tpTHs) == 0 { return } @@ -1549,7 +1442,7 @@ func (ms *MongoStorageNew) SetTPThresholds(tpTHs []*utils.TPThreshold) (err erro }) } -func (ms *MongoStorageNew) GetTPFilters(tpid, id string) ([]*utils.TPFilterProfile, error) { +func (ms *MongoStorage) GetTPFilters(tpid, id string) ([]*utils.TPFilterProfile, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1576,7 +1469,7 @@ func (ms *MongoStorageNew) GetTPFilters(tpid, id string) ([]*utils.TPFilterProfi return results, err } -func (ms *MongoStorageNew) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err error) { +func (ms *MongoStorage) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err error) { if len(tpTHs) == 0 { return } @@ -1594,7 +1487,7 @@ func (ms *MongoStorageNew) SetTPFilters(tpTHs []*utils.TPFilterProfile) (err err }) } -func (ms *MongoStorageNew) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) { +func (ms *MongoStorage) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierProfile, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1621,7 +1514,7 @@ func (ms *MongoStorageNew) GetTPSuppliers(tpid, id string) ([]*utils.TPSupplierP return results, err } -func (ms *MongoStorageNew) SetTPSuppliers(tpSPs []*utils.TPSupplierProfile) (err error) { +func (ms *MongoStorage) SetTPSuppliers(tpSPs []*utils.TPSupplierProfile) (err error) { if len(tpSPs) == 0 { return } @@ -1639,7 +1532,7 @@ func (ms *MongoStorageNew) SetTPSuppliers(tpSPs []*utils.TPSupplierProfile) (err }) } -func (ms *MongoStorageNew) GetTPAttributes(tpid, id string) ([]*utils.TPAttributeProfile, error) { +func (ms *MongoStorage) GetTPAttributes(tpid, id string) ([]*utils.TPAttributeProfile, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1666,7 +1559,7 @@ func (ms *MongoStorageNew) GetTPAttributes(tpid, id string) ([]*utils.TPAttribut return results, err } -func (ms *MongoStorageNew) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (err error) { +func (ms *MongoStorage) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (err error) { if len(tpSPs) == 0 { return } @@ -1684,7 +1577,7 @@ func (ms *MongoStorageNew) SetTPAttributes(tpSPs []*utils.TPAttributeProfile) (e }) } -func (ms *MongoStorageNew) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) { +func (ms *MongoStorage) GetTPChargers(tpid, id string) ([]*utils.TPChargerProfile, error) { filter := bson.M{"tpid": tpid} if id != "" { filter["id"] = id @@ -1711,7 +1604,7 @@ func (ms *MongoStorageNew) GetTPChargers(tpid, id string) ([]*utils.TPChargerPro return results, err } -func (ms *MongoStorageNew) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err error) { +func (ms *MongoStorage) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err error) { if len(tpCPP) == 0 { return } @@ -1729,13 +1622,15 @@ func (ms *MongoStorageNew) SetTPChargers(tpCPP []*utils.TPChargerProfile) (err e }) } -func (ms *MongoStorageNew) GetVersions(itm string) (vrs Versions, err error) { +func (ms *MongoStorage) GetVersions(itm string) (vrs Versions, err error) { fop := options.FindOne() if itm != "" { - fop.SetProjection(bson.M{itm: 1}) + fop.SetProjection(bson.M{itm: 1, "_id": 0}) + } else { + fop.SetProjection(bson.M{"_id": 0}) } if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur := ms.getCol(colUsr).FindOne(sctx, nil, fop) + cur := ms.getCol(colVer).FindOne(sctx, nil, fop) if err := cur.Decode(&vrs); err != nil { if err == mongo.ErrNoDocuments { return utils.ErrNotFound @@ -1752,23 +1647,25 @@ func (ms *MongoStorageNew) GetVersions(itm string) (vrs Versions, err error) { return } -func (ms *MongoStorageNew) SetVersions(vrs Versions, overwrite bool) (err error) { +func (ms *MongoStorage) SetVersions(vrs Versions, overwrite bool) (err error) { if overwrite { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - _, err = ms.getCol(colVer).UpdateOne(sctx, nil, bson.M{"$set": vrs}, - options.Update().SetUpsert(true), - ) - return err - }) + ms.RemoveVersions(nil) } - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { - _, err := ms.getCol(colTsk).InsertOne(sctx, vrs) + return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { + _, err = ms.getCol(colVer).UpdateOne(sctx, nil, bson.M{"$set": vrs}, + options.Update().SetUpsert(true), + ) return err }) + // } + // return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) error { + // _, err := ms.getCol(colVer).InsertOne(sctx, vrs) + // return err + // }) // _, err = col.Upsert(bson.M{}, bson.M{"$set": &vrs}) } -func (ms *MongoStorageNew) RemoveVersions(vrs Versions) (err error) { +func (ms *MongoStorage) RemoveVersions(vrs Versions) (err error) { if len(vrs) == 0 { return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { dr, err := ms.getCol(colVer).DeleteOne(sctx, nil) @@ -1789,6 +1686,6 @@ func (ms *MongoStorageNew) RemoveVersions(vrs Versions) (err error) { }) } -func (ms *MongoStorageNew) GetStorageType() string { +func (ms *MongoStorage) GetStorageType() string { return utils.MONGO } diff --git a/glide.lock b/glide.lock index 2e7d527a3..f58a30f4a 100644 --- a/glide.lock +++ b/glide.lock @@ -145,7 +145,7 @@ imports: - name: github.com/Masterminds/semver version: c7af12943936e8c39859482e61f0574c2fd7fc75 - name: github.com/mongodb/mongo-go-driver - version: 03d16bbe636981a408ff359412697fa9ff16ec83 + version: 2bcd97a847884e8d7ecede81cf57bff44d6da7b8 subpackages: - bson - bson/bsoncodec diff --git a/migrator/storage_mongo_datadb.go b/migrator/storage_mongo_datadb.go index 51dd2964f..8f9edfd80 100644 --- a/migrator/storage_mongo_datadb.go +++ b/migrator/storage_mongo_datadb.go @@ -34,7 +34,7 @@ const ( type mongoMigrator struct { dm *engine.DataManager - mgoDB *engine.MongoStorage + mgoDB *engine.MongoStorageOld qryIter *mgo.Iter } @@ -50,7 +50,7 @@ type AtKeyValue struct { func newMongoMigrator(dm *engine.DataManager) (mgoMig *mongoMigrator) { return &mongoMigrator{ dm: dm, - mgoDB: dm.DataDB().(*engine.MongoStorage), + mgoDB: dm.DataDB().(*engine.MongoStorageOld), qryIter: nil, } } diff --git a/migrator/storage_mongo_stordb.go b/migrator/storage_mongo_stordb.go index d13c96412..c1cb72b51 100755 --- a/migrator/storage_mongo_stordb.go +++ b/migrator/storage_mongo_stordb.go @@ -28,14 +28,14 @@ import ( func newMongoStorDBMigrator(stor engine.StorDB) (mgoMig *mongoStorDBMigrator) { return &mongoStorDBMigrator{ storDB: &stor, - mgoDB: stor.(*engine.MongoStorage), + mgoDB: stor.(*engine.MongoStorageOld), qryIter: nil, } } type mongoStorDBMigrator struct { storDB *engine.StorDB - mgoDB *engine.MongoStorage + mgoDB *engine.MongoStorageOld qryIter *mgo.Iter }