mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated mongodb driver
This commit is contained in:
committed by
Dan Christian Bogos
parent
9d18e8adbc
commit
4f8b4b2f45
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
2
glide.lock
generated
2
glide.lock
generated
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user