mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Fixes for the new mongo driver
This commit is contained in:
committed by
Dan Christian Bogos
parent
6690f72f00
commit
092f2c6da8
@@ -576,7 +576,7 @@ func testV1RsDBStore(t *testing.T) {
|
||||
}
|
||||
case "ResGroup2":
|
||||
if len(r.Usages) != 3 || len(r.TTLIdx) != 3 {
|
||||
t.Errorf("Unexpected resource: %+v", r)
|
||||
t.Errorf("Unexpected resource: %s", utils.ToJSON(r))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
"stor_db": {
|
||||
"db_type": "mongo",
|
||||
"db_name": "cgrates2",
|
||||
"db_port": 27017,
|
||||
},
|
||||
|
||||
|
||||
@@ -664,6 +664,7 @@ func (ms *MongoStorage) GetRatingProfileDrv(key string) (rp *RatingProfile, err
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colRpf).FindOne(sctx, bson.M{"id": key})
|
||||
if err := cur.Decode(rp); err != nil {
|
||||
rp = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -959,6 +960,7 @@ func (ms *MongoStorage) GetSharedGroupDrv(key string) (sg *SharedGroup, err erro
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colShg).FindOne(sctx, bson.M{"id": key})
|
||||
if err := cur.Decode(sg); err != nil {
|
||||
sg = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -994,8 +996,8 @@ func (ms *MongoStorage) GetAccount(key string) (result *Account, err error) {
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colAcc).FindOne(sctx, bson.M{"id": key})
|
||||
if err := cur.Decode(result); err != nil {
|
||||
result = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
result = nil
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
return err
|
||||
@@ -1771,6 +1773,7 @@ func (ms *MongoStorage) GetResourceProfileDrv(tenant, id string) (rp *ResourcePr
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colRsP).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(rp); err != nil {
|
||||
rp = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -1806,6 +1809,7 @@ func (ms *MongoStorage) GetResourceDrv(tenant, id string) (r *Resource, err erro
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colRes).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(r); err != nil {
|
||||
r = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -1841,6 +1845,7 @@ func (ms *MongoStorage) GetTimingDrv(id string) (t *utils.TPTiming, err error) {
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colTmg).FindOne(sctx, bson.M{"id": id})
|
||||
if err := cur.Decode(t); err != nil {
|
||||
t = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2058,6 +2063,7 @@ func (ms *MongoStorage) GetStatQueueProfileDrv(tenant string, id string) (sq *St
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colSqp).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(sq); err != nil {
|
||||
sq = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2096,6 +2102,7 @@ func (ms *MongoStorage) GetStoredStatQueueDrv(tenant, id string) (sq *StoredStat
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colSqs).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(sq); err != nil {
|
||||
sq = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2134,6 +2141,7 @@ func (ms *MongoStorage) GetThresholdProfileDrv(tenant, ID string) (tp *Threshold
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colTps).FindOne(sctx, bson.M{"tenant": tenant, "id": ID})
|
||||
if err := cur.Decode(tp); err != nil {
|
||||
tp = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2170,6 +2178,7 @@ func (ms *MongoStorage) GetThresholdDrv(tenant, id string) (r *Threshold, err er
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colThs).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(r); err != nil {
|
||||
r = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2247,6 +2256,7 @@ func (ms *MongoStorage) GetSupplierProfileDrv(tenant, id string) (r *SupplierPro
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colSpp).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(r); err != nil {
|
||||
r = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2282,6 +2292,7 @@ func (ms *MongoStorage) GetAttributeProfileDrv(tenant, id string) (r *AttributeP
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colAttr).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(r); err != nil {
|
||||
r = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
@@ -2317,6 +2328,7 @@ func (ms *MongoStorage) GetChargerProfileDrv(tenant, id string) (r *ChargerProfi
|
||||
err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) {
|
||||
cur := ms.getCol(colCpp).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
|
||||
if err := cur.Decode(r); err != nil {
|
||||
r = nil
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return utils.ErrNotFound
|
||||
}
|
||||
|
||||
@@ -26,13 +26,92 @@ import (
|
||||
)
|
||||
|
||||
func TestV1AccountAsAccount(t *testing.T) {
|
||||
d1b := &v1Balance{Value: 100000, Weight: 10, DestinationIds: "NAT", Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}}}
|
||||
v1b := &v1Balance{Value: 100000, Weight: 10, DestinationIds: "NAT", Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}}}
|
||||
v1Acc := &v1Account{Id: "*OUT:CUSTOMER_1:rif", BalanceMap: map[string]v1BalanceChain{utils.DATA: v1BalanceChain{d1b}, utils.VOICE: v1BalanceChain{v1b}, utils.MONETARY: v1BalanceChain{&v1Balance{Value: 21, Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}}}}}}
|
||||
d2 := &engine.Balance{Uuid: "", ID: "", Value: 100000, Directions: utils.StringMap{"*OUT": true}, Weight: 10, DestinationIDs: utils.StringMap{"NAT": true}, RatingSubject: "", Categories: utils.NewStringMap(""), SharedGroups: utils.NewStringMap(""), Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}}, TimingIDs: utils.NewStringMap(""), Factor: engine.ValueFactor{}}
|
||||
v2 := &engine.Balance{Uuid: "", ID: "", Value: 0.0001, Directions: utils.StringMap{"*OUT": true}, Weight: 10, DestinationIDs: utils.StringMap{"NAT": true}, RatingSubject: "", Categories: utils.NewStringMap(""), SharedGroups: utils.NewStringMap(""), Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}}, TimingIDs: utils.NewStringMap(""), Factor: engine.ValueFactor{}}
|
||||
m2 := &engine.Balance{Uuid: "", ID: "", Value: 21, Directions: utils.StringMap{"*OUT": true}, DestinationIDs: utils.NewStringMap(""), RatingSubject: "", Categories: utils.NewStringMap(""), SharedGroups: utils.NewStringMap(""), Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}}, TimingIDs: utils.NewStringMap(""), Factor: engine.ValueFactor{}}
|
||||
testAccount := &engine.Account{ID: "CUSTOMER_1:rif", BalanceMap: map[string]engine.Balances{utils.DATA: engine.Balances{d2}, utils.VOICE: engine.Balances{v2}, utils.MONETARY: engine.Balances{m2}}, UnitCounters: engine.UnitCounters{}, ActionTriggers: engine.ActionTriggers{}}
|
||||
d1b := &v1Balance{
|
||||
Value: 100000,
|
||||
Weight: 10,
|
||||
DestinationIds: "NAT",
|
||||
Timings: []*engine.RITiming{
|
||||
&engine.RITiming{
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
}
|
||||
v1b := &v1Balance{
|
||||
Value: 100000,
|
||||
Weight: 10,
|
||||
DestinationIds: "NAT",
|
||||
Timings: []*engine.RITiming{
|
||||
&engine.RITiming{
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
}
|
||||
v1Acc := &v1Account{
|
||||
Id: "*OUT:CUSTOMER_1:rif",
|
||||
BalanceMap: map[string]v1BalanceChain{
|
||||
utils.DATA: v1BalanceChain{d1b},
|
||||
utils.VOICE: v1BalanceChain{v1b},
|
||||
utils.MONETARY: v1BalanceChain{&v1Balance{
|
||||
Value: 21,
|
||||
Timings: []*engine.RITiming{
|
||||
&engine.RITiming{
|
||||
StartTime: "00:00:00",
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
}
|
||||
d2 := &engine.Balance{
|
||||
Uuid: "",
|
||||
ID: "",
|
||||
Value: 100000,
|
||||
Directions: utils.StringMap{"*OUT": true},
|
||||
Weight: 10,
|
||||
DestinationIDs: utils.StringMap{"NAT": true},
|
||||
RatingSubject: "",
|
||||
Categories: utils.NewStringMap(""),
|
||||
SharedGroups: utils.NewStringMap(""),
|
||||
Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}},
|
||||
TimingIDs: utils.NewStringMap(""),
|
||||
Factor: engine.ValueFactor{},
|
||||
}
|
||||
v2 := &engine.Balance{
|
||||
Uuid: "",
|
||||
ID: "",
|
||||
Value: 0.0001,
|
||||
Directions: utils.StringMap{"*OUT": true},
|
||||
Weight: 10,
|
||||
DestinationIDs: utils.StringMap{"NAT": true},
|
||||
RatingSubject: "",
|
||||
Categories: utils.NewStringMap(""),
|
||||
SharedGroups: utils.NewStringMap(""),
|
||||
Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}},
|
||||
TimingIDs: utils.NewStringMap(""),
|
||||
Factor: engine.ValueFactor{},
|
||||
}
|
||||
m2 := &engine.Balance{
|
||||
Uuid: "",
|
||||
ID: "",
|
||||
Value: 21,
|
||||
Directions: utils.StringMap{"*OUT": true},
|
||||
DestinationIDs: utils.NewStringMap(""),
|
||||
RatingSubject: "",
|
||||
Categories: utils.NewStringMap(""),
|
||||
SharedGroups: utils.NewStringMap(""),
|
||||
Timings: []*engine.RITiming{&engine.RITiming{StartTime: "00:00:00"}},
|
||||
TimingIDs: utils.NewStringMap(""),
|
||||
Factor: engine.ValueFactor{},
|
||||
}
|
||||
testAccount := &engine.Account{
|
||||
ID: "CUSTOMER_1:rif",
|
||||
BalanceMap: map[string]engine.Balances{
|
||||
utils.DATA: engine.Balances{d2},
|
||||
utils.VOICE: engine.Balances{v2},
|
||||
utils.MONETARY: engine.Balances{m2},
|
||||
},
|
||||
UnitCounters: engine.UnitCounters{},
|
||||
ActionTriggers: engine.ActionTriggers{},
|
||||
}
|
||||
if def := v1b.IsDefault(); def != false {
|
||||
t.Errorf("Expecting: false, received: true")
|
||||
}
|
||||
|
||||
@@ -162,7 +162,8 @@ func testActITConnect(t *testing.T) {
|
||||
|
||||
func testActITFlush(t *testing.T) {
|
||||
actMigrator.dmOut.DataManager().DataDB().Flush("")
|
||||
if err := engine.SetDBVersions(actMigrator.dmOut.DataManager().DataDB()); err != nil {
|
||||
actMigrator.dmIN.DataManager().DataDB().Flush("")
|
||||
if err := engine.SetDBVersions(actMigrator.dmIN.DataManager().DataDB()); err != nil {
|
||||
t.Error("Error ", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,12 @@ var sTestssCostIT = []func(t *testing.T){
|
||||
func TestSessionCostITMongo(t *testing.T) {
|
||||
var err error
|
||||
sCostPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo")
|
||||
sCostPathOut = path.Join(*dataDir, "conf", "samples", "tutmongojson")
|
||||
sCostCfgIn, err = config.NewCGRConfigFromFolder(sCostPathIn)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
sCostCfgOut, err = config.NewCGRConfigFromFolder(sCostPathIn)
|
||||
sCostCfgOut, err = config.NewCGRConfigFromFolder(sCostPathOut)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ func (v1ms *mongoMigrator) getv1Account() (v1Acnt *v1Account, err error) {
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v1Acnt = new(v1Account)
|
||||
if err := (*v1ms.cursor).Decode(v1Acnt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -114,6 +115,7 @@ func (v1ms *mongoMigrator) getv2Account() (v2Acnt *v2Account, err error) {
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v2Acnt = new(v2Account)
|
||||
if err := (*v1ms.cursor).Decode(v2Acnt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,7 +137,7 @@ func (v1ms *mongoMigrator) remV2Account(id string) (err error) {
|
||||
//Action methods
|
||||
//get
|
||||
func (v1ms *mongoMigrator) getV1ActionPlans() (v1aps *v1ActionPlans, err error) {
|
||||
var strct *AtKeyValue
|
||||
strct := new(AtKeyValue)
|
||||
if v1ms.cursor == nil {
|
||||
var cursor mongo.Cursor
|
||||
cursor, err = v1ms.mgoDB.DB().Collection("actiontimings").Find(v1ms.mgoDB.GetContext(), nil)
|
||||
@@ -165,7 +167,7 @@ func (v1ms *mongoMigrator) setV1ActionPlans(x *v1ActionPlans) (err error) {
|
||||
//Actions methods
|
||||
//get
|
||||
func (v1ms *mongoMigrator) getV1Actions() (v1acs *v1Actions, err error) {
|
||||
var strct *AcKeyValue
|
||||
strct := new(AcKeyValue)
|
||||
if v1ms.cursor == nil {
|
||||
var cursor mongo.Cursor
|
||||
cursor, err = v1ms.mgoDB.DB().Collection("actions").Find(v1ms.mgoDB.GetContext(), nil)
|
||||
@@ -219,6 +221,7 @@ func (v1ms *mongoMigrator) getV1SharedGroup() (v1sg *v1SharedGroup, err error) {
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v1sg = new(v1SharedGroup)
|
||||
if err := (*v1ms.cursor).Decode(v1sg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -247,6 +250,7 @@ func (v1ms *mongoMigrator) getV1Stats() (v1st *v1Stat, err error) {
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v1st = new(v1Stat)
|
||||
if err := (*v1ms.cursor).Decode(v1st); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -275,6 +279,7 @@ func (v1ms *mongoMigrator) getV2ActionTrigger() (v2at *v2ActionTrigger, err erro
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v2at = new(v2ActionTrigger)
|
||||
if err := (*v1ms.cursor).Decode(v2at); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -303,6 +308,7 @@ func (v1ms *mongoMigrator) getV1AttributeProfile() (v1attrPrf *v1AttributeProfil
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v1attrPrf = new(v1AttributeProfile)
|
||||
if err := (*v1ms.cursor).Decode(v1attrPrf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -331,6 +337,7 @@ func (v1ms *mongoMigrator) getV2ThresholdProfile() (v2T *v2Threshold, err error)
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v2T = new(v2Threshold)
|
||||
if err := (*v1ms.cursor).Decode(v2T); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ func (v1ms *mongoStorDBMigrator) getV1CDR() (v1Cdr *v1Cdrs, err error) {
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v1Cdr = new(v1Cdrs)
|
||||
if err := (*v1ms.cursor).Decode(v1Cdr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -106,6 +107,7 @@ func (v1ms *mongoStorDBMigrator) getV2SMCost() (v2Cost *v2SessionsCost, err erro
|
||||
v1ms.cursor = nil
|
||||
return nil, utils.ErrNoMoreData
|
||||
}
|
||||
v2Cost = new(v2SessionsCost)
|
||||
if err := (*v1ms.cursor).Decode(v2Cost); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -120,6 +122,6 @@ func (v1ms *mongoStorDBMigrator) setV2SMCost(v2Cost *v2SessionsCost) (err error)
|
||||
|
||||
//remove
|
||||
func (v1ms *mongoStorDBMigrator) remV2SMCost(v2Cost *v2SessionsCost) (err error) {
|
||||
_, err = v1ms.mgoDB.DB().Collection(v1AccountDBPrefix).DeleteMany(v1ms.mgoDB.GetContext(), nil)
|
||||
_, err = v1ms.mgoDB.DB().Collection(utils.SessionsCostsTBL).DeleteMany(v1ms.mgoDB.GetContext(), nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -673,7 +673,7 @@ func TestSMGVoiceSessionTTL(t *testing.T) {
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
time.Sleep(time.Duration(100 * time.Millisecond))
|
||||
time.Sleep(time.Duration(200 * time.Millisecond))
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}, DestinationPrefixes: []string{"1008"}}
|
||||
if err := smgRPC.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user