From cc0855ce834b8dffe3c3564f1693341ee364f047 Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 7 Nov 2019 07:24:43 -0500 Subject: [PATCH] Rename GetAccount with GetAccountDrv and add GetAccount in DataManager --- apier/v1/accounts.go | 12 ++++---- apier/v1/debit_test.go | 2 +- apier/v1/triggers.go | 12 ++++---- apier/v2/accounts.go | 6 ++-- apier/v2/triggers.go | 2 +- engine/account_test.go | 8 ++--- engine/action_plan.go | 2 +- engine/actions_test.go | 50 +++++++++++++++---------------- engine/calldesc.go | 6 ++-- engine/calldesc_test.go | 28 ++++++++--------- engine/datamanager.go | 19 ++++++++++++ engine/loader_csv_test.go | 4 +-- engine/loader_it_test.go | 2 +- engine/onstor_it_test.go | 6 ++-- engine/sharedgroup.go | 2 +- engine/storage_interface.go | 2 +- engine/storage_internal_datadb.go | 4 +-- engine/storage_map_datadb.go | 4 +-- engine/storage_mongo_datadb.go | 4 +-- engine/storage_redis.go | 4 +-- engine/storage_test.go | 6 ++-- engine/tpreader.go | 2 +- general_tests/acntacts_test.go | 6 ++-- general_tests/auth_test.go | 2 +- general_tests/ddazmbl1_test.go | 6 ++-- general_tests/ddazmbl2_test.go | 6 ++-- general_tests/ddazmbl3_test.go | 6 ++-- migrator/accounts.go | 2 +- migrator/accounts2_it_test.go | 2 +- migrator/accounts_it_test.go | 6 ++-- 30 files changed, 121 insertions(+), 102 deletions(-) diff --git a/apier/v1/accounts.go b/apier/v1/accounts.go index c90971565..94b68b397 100644 --- a/apier/v1/accounts.go +++ b/apier/v1/accounts.go @@ -174,7 +174,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) (err e dirtyActionPlans := make(map[string]*engine.ActionPlan) _, err = guardian.Guardian.Guard(func() (interface{}, error) { var ub *engine.Account - if bal, _ := self.DataManager.DataDB().GetAccount(accID); bal != nil { + if bal, _ := self.DataManager.GetAccount(accID); bal != nil { ub = bal } else { // Not found in db, create it here ub = &engine.Account{ @@ -374,7 +374,7 @@ func (self *ApierV1) GetAccounts(attr utils.AttrGetAccounts, reply *[]interface{ } retAccounts := make([]interface{}, 0) for _, acntKey := range limitedAccounts { - if acnt, err := self.DataManager.DataDB().GetAccount(acntKey[len(utils.ACCOUNT_PREFIX):]); err != nil && err != utils.ErrNotFound { // Not found is not an error here + if acnt, err := self.DataManager.GetAccount(acntKey[len(utils.ACCOUNT_PREFIX):]); err != nil && err != utils.ErrNotFound { // Not found is not an error here return err } else if acnt != nil { if attr.Disabled != nil && *attr.Disabled != acnt.Disabled { @@ -390,7 +390,7 @@ func (self *ApierV1) GetAccounts(attr utils.AttrGetAccounts, reply *[]interface{ // Get balance func (self *ApierV1) GetAccount(attr *utils.AttrGetAccount, reply *interface{}) error { tag := utils.ConcatenatedKey(attr.Tenant, attr.Account) - userBalance, err := self.DataManager.DataDB().GetAccount(tag) + userBalance, err := self.DataManager.GetAccount(tag) if err != nil { return err } @@ -443,7 +443,7 @@ func (self *ApierV1) modifyBalance(aType string, attr *AttrAddBalance, reply *st expTime = &expTimeVal } accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) - if _, err := self.DataManager.DataDB().GetAccount(accID); err != nil { + if _, err := self.DataManager.GetAccount(accID); err != nil { // create account if does not exist account := &engine.Account{ ID: accID, @@ -526,7 +526,7 @@ func (self *ApierV1) SetBalance(attr *utils.AttrSetBalance, reply *string) error expTime = &expTimeVal } accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) - if _, err := self.DataManager.DataDB().GetAccount(accID); err != nil { + if _, err := self.DataManager.GetAccount(accID); err != nil { // create account if not exists account := &engine.Account{ ID: accID, @@ -603,7 +603,7 @@ func (self *ApierV1) RemoveBalances(attr *utils.AttrSetBalance, reply *string) e expTime = &expTimeVal } accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) - if _, err := self.DataManager.DataDB().GetAccount(accID); err != nil { + if _, err := self.DataManager.GetAccount(accID); err != nil { return utils.ErrNotFound } diff --git a/apier/v1/debit_test.go b/apier/v1/debit_test.go index 4016112b3..001bc723a 100644 --- a/apier/v1/debit_test.go +++ b/apier/v1/debit_test.go @@ -137,7 +137,7 @@ func TestDebitUsageWithOptions(t *testing.T) { } // Reload the account and verify that the usage of $1 was removed from the monetary balance - resolvedAccount, err := apierDebitStorage.GetAccount(cgrAcnt1.ID) + resolvedAccount, err := apierDebitStorage.GetAccountDrv(cgrAcnt1.ID) if err != nil { t.Error(err) } diff --git a/apier/v1/triggers.go b/apier/v1/triggers.go index a58fb99e6..711c0b6de 100644 --- a/apier/v1/triggers.go +++ b/apier/v1/triggers.go @@ -32,7 +32,7 @@ func (self *ApierV1) GetAccountActionTriggers(attrs utils.TenantAccount, reply * if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Account"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } - if account, err := self.DataManager.DataDB().GetAccount(utils.ConcatenatedKey(attrs.Tenant, attrs.Account)); err != nil { + if account, err := self.DataManager.GetAccount(utils.ConcatenatedKey(attrs.Tenant, attrs.Account)); err != nil { return utils.NewErrServerError(err) } else { ats := account.ActionTriggers @@ -66,7 +66,7 @@ func (self *ApierV1) AddAccountActionTriggers(attr AttrAddAccountActionTriggers, accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) var account *engine.Account _, err = guardian.Guardian.Guard(func() (interface{}, error) { - if acc, err := self.DataManager.DataDB().GetAccount(accID); err == nil { + if acc, err := self.DataManager.GetAccount(accID); err == nil { account = acc } else { return 0, err @@ -121,7 +121,7 @@ func (self *ApierV1) RemoveAccountActionTriggers(attr AttrRemoveAccountActionTri accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) _, err := guardian.Guardian.Guard(func() (interface{}, error) { var account *engine.Account - if acc, err := self.DataManager.DataDB().GetAccount(accID); err == nil { + if acc, err := self.DataManager.GetAccount(accID); err == nil { account = acc } else { return 0, err @@ -163,7 +163,7 @@ func (self *ApierV1) ResetAccountActionTriggers(attr AttrResetAccountActionTrigg accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) var account *engine.Account _, err := guardian.Guardian.Guard(func() (interface{}, error) { - if acc, err := self.DataManager.DataDB().GetAccount(accID); err == nil { + if acc, err := self.DataManager.GetAccount(accID); err == nil { account = acc } else { return 0, err @@ -225,7 +225,7 @@ func (self *ApierV1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers, accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) var account *engine.Account _, err := guardian.Guardian.Guard(func() (interface{}, error) { - if acc, err := self.DataManager.DataDB().GetAccount(accID); err == nil { + if acc, err := self.DataManager.GetAccount(accID); err == nil { account = acc } else { return 0, err @@ -602,7 +602,7 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string } acntID := utils.ConcatenatedKey(attr.Tenant, attr.Account) _, err := guardian.Guardian.Guard(func() (interface{}, error) { - acnt, err := self.DataManager.DataDB().GetAccount(acntID) + acnt, err := self.DataManager.GetAccount(acntID) if err != nil { return 0, err } diff --git a/apier/v2/accounts.go b/apier/v2/accounts.go index c9e8d297b..287c369bd 100644 --- a/apier/v2/accounts.go +++ b/apier/v2/accounts.go @@ -64,7 +64,7 @@ func (self *ApierV2) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine.Ac } retAccounts := make([]*engine.Account, 0) for _, acntKey := range limitedAccounts { - if acnt, err := self.DataManager.DataDB().GetAccount(acntKey[len(utils.ACCOUNT_PREFIX):]); err != nil && err != utils.ErrNotFound { // Not found is not an error here + if acnt, err := self.DataManager.GetAccount(acntKey[len(utils.ACCOUNT_PREFIX):]); err != nil && err != utils.ErrNotFound { // Not found is not an error here return err } else if acnt != nil { if attr.Disabled != nil && *attr.Disabled != acnt.Disabled { @@ -80,7 +80,7 @@ func (self *ApierV2) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine.Ac // Get balance func (self *ApierV2) GetAccount(attr *utils.AttrGetAccount, reply *engine.Account) error { tag := utils.ConcatenatedKey(attr.Tenant, attr.Account) - account, err := self.DataManager.DataDB().GetAccount(tag) + account, err := self.DataManager.GetAccount(tag) if err != nil { return err } @@ -110,7 +110,7 @@ func (self *ApierV2) SetAccount(attr AttrSetAccount, reply *string) error { var ub *engine.Account var schedNeedsReload bool _, err := guardian.Guardian.Guard(func() (interface{}, error) { - if bal, _ := self.DataManager.DataDB().GetAccount(accID); bal != nil { + if bal, _ := self.DataManager.GetAccount(accID); bal != nil { ub = bal } else { // Not found in db, create it here ub = &engine.Account{ diff --git a/apier/v2/triggers.go b/apier/v2/triggers.go index 3d97ec73a..4f22a21b9 100644 --- a/apier/v2/triggers.go +++ b/apier/v2/triggers.go @@ -160,7 +160,7 @@ func (self *ApierV2) SetAccountActionTriggers(attr AttrSetAccountActionTriggers, accID := utils.ConcatenatedKey(attr.Tenant, attr.Account) var account *engine.Account _, err := guardian.Guardian.Guard(func() (interface{}, error) { - if acc, err := self.DataManager.DataDB().GetAccount(accID); err == nil { + if acc, err := self.DataManager.GetAccount(accID); err == nil { account = acc } else { return 0, err diff --git a/engine/account_test.go b/engine/account_test.go index 75313478a..760a21a1a 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -95,7 +95,7 @@ func TestAccountStorageStoreRestore(t *testing.T) { BalanceMap: map[string]Balances{utils.VOICE: Balances{b1, b2}, utils.MONETARY: Balances{&Balance{Value: 21}}}} dm.DataDB().SetAccount(rifsBalance) - ub1, err := dm.DataDB().GetAccount("other") + ub1, err := dm.GetAccount("other") if err != nil || !ub1.BalanceMap[utils.MONETARY].Equal(rifsBalance.BalanceMap[utils.MONETARY]) { t.Log("UB: ", ub1) @@ -172,7 +172,7 @@ func TestAccountStorageStore(t *testing.T) { utils.VOICE: Balances{b1, b2}, utils.MONETARY: Balances{&Balance{Value: 21}}}} dm.DataDB().SetAccount(rifsBalance) - result, err := dm.DataDB().GetAccount(rifsBalance.ID) + result, err := dm.GetAccount(rifsBalance.ID) if err != nil || rifsBalance.ID != result.ID || len(rifsBalance.BalanceMap[utils.VOICE]) < 2 || len(result.BalanceMap[utils.VOICE]) < 2 || @@ -1484,7 +1484,7 @@ func TestDebitShared(t *testing.T) { if rif.BalanceMap[utils.MONETARY][0].GetValue() != 0 { t.Errorf("Error debiting from shared group: %+v", rif.BalanceMap[utils.MONETARY][0]) } - groupie, _ = dm.DataDB().GetAccount("groupie") + groupie, _ = dm.GetAccount("groupie") if groupie.BalanceMap[utils.MONETARY][0].GetValue() != 10 { t.Errorf("Error debiting from shared group: %+v", groupie.BalanceMap[utils.MONETARY][0]) } @@ -2350,7 +2350,7 @@ func BenchmarkAccountStorageStoreRestore(b *testing.B) { rifsBalance := &Account{ID: "other", BalanceMap: map[string]Balances{utils.VOICE: Balances{b1, b2}, utils.MONETARY: Balances{&Balance{Value: 21}}}} for i := 0; i < b.N; i++ { dm.DataDB().SetAccount(rifsBalance) - dm.DataDB().GetAccount(rifsBalance.ID) + dm.GetAccount(rifsBalance.ID) } } diff --git a/engine/action_plan.go b/engine/action_plan.go index a2756e66c..bfa789bae 100644 --- a/engine/action_plan.go +++ b/engine/action_plan.go @@ -312,7 +312,7 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err var partialyExecuted bool for accID := range at.accountIDs { _, err = guardian.Guardian.Guard(func() (interface{}, error) { - acc, err := dm.DataDB().GetAccount(accID) + acc, err := dm.GetAccount(accID) if err != nil { utils.Logger.Warning(fmt.Sprintf("Could not get account id: %s. Skipping!", accID)) return 0, err diff --git a/engine/actions_test.go b/engine/actions_test.go index eaf6c33cd..c4d4de586 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -1411,7 +1411,7 @@ func TestActionMakeNegative(t *testing.T) { } func TestRemoveAction(t *testing.T) { - if _, err := dm.DataDB().GetAccount("cgrates.org:remo"); err != nil { + if _, err := dm.GetAccount("cgrates.org:remo"); err != nil { t.Errorf("account to be removed not found: %v", err) } a := &Action{ @@ -1423,14 +1423,14 @@ func TestRemoveAction(t *testing.T) { actions: Actions{a}, } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:remo") + afterUb, err := dm.GetAccount("cgrates.org:remo") if err == nil || afterUb != nil { t.Error("error removing account: ", err, afterUb) } } func TestTopupAction(t *testing.T) { - initialUb, _ := dm.DataDB().GetAccount("vdf:minu") + initialUb, _ := dm.GetAccount("vdf:minu") a := &Action{ ActionType: utils.TOPUP, Balance: &BalanceFilter{Type: utils.StringPointer(utils.MONETARY), Value: &utils.ValueFormula{Static: 25}, @@ -1444,7 +1444,7 @@ func TestTopupAction(t *testing.T) { } at.Execute(nil, nil) - afterUb, _ := dm.DataDB().GetAccount("vdf:minu") + afterUb, _ := dm.GetAccount("vdf:minu") initialValue := initialUb.BalanceMap[utils.MONETARY].GetTotalValue() afterValue := afterUb.BalanceMap[utils.MONETARY].GetTotalValue() if afterValue != initialValue+25 { @@ -1453,7 +1453,7 @@ func TestTopupAction(t *testing.T) { } func TestTopupActionLoaded(t *testing.T) { - initialUb, _ := dm.DataDB().GetAccount("vdf:minitsboy") + initialUb, _ := dm.GetAccount("vdf:minitsboy") a := &Action{ ActionType: utils.TOPUP, Balance: &BalanceFilter{Type: utils.StringPointer(utils.MONETARY), @@ -1468,7 +1468,7 @@ func TestTopupActionLoaded(t *testing.T) { } at.Execute(nil, nil) - afterUb, _ := dm.DataDB().GetAccount("vdf:minitsboy") + afterUb, _ := dm.GetAccount("vdf:minitsboy") initialValue := initialUb.BalanceMap[utils.MONETARY].GetTotalValue() afterValue := afterUb.BalanceMap[utils.MONETARY].GetTotalValue() if afterValue != initialValue+25 { @@ -1561,7 +1561,7 @@ func TestActionTransactionFuncType(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:trans") + acc, err := dm.GetAccount("cgrates.org:trans") if err != nil || acc == nil { t.Error("Error getting account: ", acc, err) } @@ -1598,7 +1598,7 @@ func TestActionTransactionBalanceType(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:trans") + acc, err := dm.GetAccount("cgrates.org:trans") if err != nil || acc == nil { t.Error("Error getting account: ", acc, err) } @@ -1635,7 +1635,7 @@ func TestActionTransactionBalanceNotType(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:trans") + acc, err := dm.GetAccount("cgrates.org:trans") if err != nil || acc == nil { t.Error("Error getting account: ", acc, err) } @@ -1678,7 +1678,7 @@ func TestActionWithExpireWithoutExpire(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:exp") + acc, err := dm.GetAccount("cgrates.org:exp") if err != nil || acc == nil { t.Errorf("Error getting account: %+v: %v", acc, err) } @@ -1725,7 +1725,7 @@ func TestActionRemoveBalance(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:rembal") + acc, err := dm.GetAccount("cgrates.org:rembal") if err != nil || acc == nil { t.Errorf("Error getting account: %+v: %v", acc, err) } @@ -1778,7 +1778,7 @@ func TestActionRemoveExpiredBalance(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:rembal2") + acc, err := dm.GetAccount("cgrates.org:rembal2") if err != nil || acc == nil { t.Errorf("Error getting account: %+v: %v", acc, err) } @@ -1828,7 +1828,7 @@ func TestActionTransferMonetaryDefault(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:trans") + afterUb, err := dm.GetAccount("cgrates.org:trans") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -1889,7 +1889,7 @@ func TestActionTransferMonetaryDefaultFilter(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:trans") + afterUb, err := dm.GetAccount("cgrates.org:trans") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -1955,7 +1955,7 @@ func TestActionConditionalTopup(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:cond") + afterUb, err := dm.GetAccount("cgrates.org:cond") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -2019,7 +2019,7 @@ func TestActionConditionalTopupNoMatch(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:cond") + afterUb, err := dm.GetAccount("cgrates.org:cond") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -2083,7 +2083,7 @@ func TestActionConditionalTopupExistingBalance(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:cond") + afterUb, err := dm.GetAccount("cgrates.org:cond") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -2233,7 +2233,7 @@ func TestActionConditionalDisabledIfNegative(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:af") + afterUb, err := dm.GetAccount("cgrates.org:af") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -2304,7 +2304,7 @@ func TestActionSetBalance(t *testing.T) { } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:setb") + afterUb, err := dm.GetAccount("cgrates.org:setb") if err != nil { t.Error("account not found: ", err, afterUb) } @@ -2340,7 +2340,7 @@ func TestActionExpirationTime(t *testing.T) { } for rep := 0; rep < 5; rep++ { at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:expo") + afterUb, err := dm.GetAccount("cgrates.org:expo") if err != nil || len(afterUb.BalanceMap[utils.VOICE]) != rep+1 { t.Error("error topuping expiration balance: ", utils.ToIJSON(afterUb)) @@ -2363,7 +2363,7 @@ func TestActionExpNoExp(t *testing.T) { actions: exp, } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:expnoexp") + afterUb, err := dm.GetAccount("cgrates.org:expnoexp") if err != nil || len(afterUb.BalanceMap[utils.VOICE]) != 2 { t.Error("error topuping expiration balance: ", utils.ToIJSON(afterUb)) @@ -2404,7 +2404,7 @@ func TestActionTopUpZeroNegative(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:zeroNegative") + acc, err := dm.GetAccount("cgrates.org:zeroNegative") if err != nil || acc == nil { t.Error("Error getting account: ", acc, err) } @@ -2460,7 +2460,7 @@ func TestActionSetExpiry(t *testing.T) { }, } err = at.Execute(nil, nil) - acc, err := dm.DataDB().GetAccount("cgrates.org:zeroNegative") + acc, err := dm.GetAccount("cgrates.org:zeroNegative") if err != nil || acc == nil { t.Error("Error getting account: ", acc, err) } @@ -2533,7 +2533,7 @@ func TestCgrRpcAction(t *testing.T) { } func TestValueFormulaDebit(t *testing.T) { - if _, err := dm.DataDB().GetAccount("cgrates.org:vf"); err != nil { + if _, err := dm.GetAccount("cgrates.org:vf"); err != nil { t.Errorf("account to be removed not found: %v", err) } @@ -2542,7 +2542,7 @@ func TestValueFormulaDebit(t *testing.T) { ActionsID: "VF", } at.Execute(nil, nil) - afterUb, err := dm.DataDB().GetAccount("cgrates.org:vf") + afterUb, err := dm.GetAccount("cgrates.org:vf") // not an exact value, depends of month v := afterUb.BalanceMap[utils.MONETARY].GetTotalValue() if err != nil || v > -0.30 || v < -0.36 { diff --git a/engine/calldesc.go b/engine/calldesc.go index 25a7ed92f..4a8bc47e3 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -264,7 +264,7 @@ func (cd *CallDescriptor) AddRatingInfo(ris ...*RatingInfo) { // Gets and caches the user balance information. func (cd *CallDescriptor) getAccount() (ub *Account, err error) { if cd.account == nil { - cd.account, err = dm.DataDB().GetAccount(cd.GetAccountKey()) + cd.account, err = dm.GetAccount(cd.GetAccountKey()) } if cd.account != nil && cd.account.Disabled { return nil, utils.ErrAccountDisabled @@ -884,7 +884,7 @@ func (cd *CallDescriptor) refundIncrements() (acnt *Account, err error) { for _, increment := range cd.Increments { account, found := accountsCache[increment.BalanceInfo.AccountID] if !found { - if acc, err := dm.DataDB().GetAccount(increment.BalanceInfo.AccountID); err == nil && acc != nil { + if acc, err := dm.GetAccount(increment.BalanceInfo.AccountID); err == nil && acc != nil { account = acc accountsCache[increment.BalanceInfo.AccountID] = account // will save the account only once at the end of the function @@ -947,7 +947,7 @@ func (cd *CallDescriptor) refundRounding() (err error) { for _, increment := range cd.Increments { account, found := accountsCache[increment.BalanceInfo.AccountID] if !found { - if acc, err := dm.DataDB().GetAccount(increment.BalanceInfo.AccountID); err == nil && acc != nil { + if acc, err := dm.GetAccount(increment.BalanceInfo.AccountID); err == nil && acc != nil { account = acc accountsCache[increment.BalanceInfo.AccountID] = account // will save the account only once at the end of the function diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index 661ab614d..4f450e585 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -741,7 +741,7 @@ func TestGetMaxSessiontWithBlocker(t *testing.T) { at.accountIDs = ap.AccountIDs at.Execute(nil, nil) } - acc, err := dm.DataDB().GetAccount("cgrates.org:block") + acc, err := dm.GetAccount("cgrates.org:block") if err != nil { t.Error("error getting account: ", err) } @@ -790,7 +790,7 @@ func TestGetMaxSessiontWithBlockerEmpty(t *testing.T) { at.accountIDs = ap.AccountIDs at.Execute(nil, nil) } - acc, err := dm.DataDB().GetAccount("cgrates.org:block_empty") + acc, err := dm.GetAccount("cgrates.org:block_empty") if err != nil { t.Error("error getting account: ", err) } @@ -1001,7 +1001,7 @@ func TestMaxDebitRoundingIssue(t *testing.T) { MaxCostSoFar: 0, PerformRounding: true, } - acc, err := dm.DataDB().GetAccount("cgrates.org:dy") + acc, err := dm.GetAccount("cgrates.org:dy") if err != nil || acc.BalanceMap[utils.MONETARY][0].Value != 1 { t.Errorf("Error getting account: %+v (%v)", utils.ToIJSON(acc), err) } @@ -1012,7 +1012,7 @@ func TestMaxDebitRoundingIssue(t *testing.T) { t.Log(utils.ToIJSON(cc)) t.Errorf("Expected %v was %+v (%v)", expected, cc, err) } - acc, err = dm.DataDB().GetAccount("cgrates.org:dy") + acc, err = dm.GetAccount("cgrates.org:dy") if err != nil || acc.BalanceMap[utils.MONETARY][0].Value != 1-expected { t.Errorf("Error getting account: %+v (%v)", utils.ToIJSON(acc), err) } @@ -1035,7 +1035,7 @@ func TestDebitRoundingRefund(t *testing.T) { MaxCostSoFar: 0, PerformRounding: true, } - acc, err := dm.DataDB().GetAccount("cgrates.org:dy") + acc, err := dm.GetAccount("cgrates.org:dy") if err != nil || acc.BalanceMap[utils.MONETARY][0].Value != 1 { t.Errorf("Error getting account: %+v (%v)", utils.ToIJSON(acc), err) } @@ -1046,7 +1046,7 @@ func TestDebitRoundingRefund(t *testing.T) { t.Log(utils.ToIJSON(cc)) t.Errorf("Expected %v was %+v (%v)", expected, cc, err) } - acc, err = dm.DataDB().GetAccount("cgrates.org:dy") + acc, err = dm.GetAccount("cgrates.org:dy") if err != nil || acc.BalanceMap[utils.MONETARY][0].Value != 1-expected { t.Errorf("Error getting account: %+v (%v)", utils.ToIJSON(acc), err) } @@ -1192,7 +1192,7 @@ func TestMaxDebitWithAccountShared(t *testing.T) { if len(balanceMap) != 1 || balanceMap[0].GetValue() != 0 { t.Errorf("Wrong shared balance debited: %+v", balanceMap[0]) } - other, err := dm.DataDB().GetAccount("vdf:empty10") + other, err := dm.GetAccount("vdf:empty10") if err != nil || other.BalanceMap[utils.MONETARY][0].GetValue() != 7.5 { t.Errorf("Error debiting shared balance: %+v", other.BalanceMap[utils.MONETARY][0]) } @@ -1319,7 +1319,7 @@ func TestMaxSesionTimeEmptyBalance(t *testing.T) { Account: "luna", Destination: "0723", } - acc, _ := dm.DataDB().GetAccount("vdf:luna") + acc, _ := dm.GetAccount("vdf:luna") allowedTime, err := cd.getMaxSessionDuration(acc) if err != nil || allowedTime != 0 { t.Error("Error get max session for 0 acount", err) @@ -1336,7 +1336,7 @@ func TestMaxSesionTimeEmptyBalanceAndNoCost(t *testing.T) { Account: "luna", Destination: "112", } - acc, _ := dm.DataDB().GetAccount("vdf:luna") + acc, _ := dm.GetAccount("vdf:luna") allowedTime, err := cd.getMaxSessionDuration(acc) if err != nil || allowedTime == 0 { t.Error("Error get max session for 0 acount", err) @@ -1352,7 +1352,7 @@ func TestMaxSesionTimeLong(t *testing.T) { Subject: "money", Destination: "0723", } - acc, _ := dm.DataDB().GetAccount("cgrates.org:money") + acc, _ := dm.GetAccount("cgrates.org:money") allowedTime, err := cd.getMaxSessionDuration(acc) if err != nil || allowedTime != cd.TimeEnd.Sub(cd.TimeStart) { t.Error("Error get max session for acount:", allowedTime, err) @@ -1368,7 +1368,7 @@ func TestMaxSesionTimeLongerThanMoney(t *testing.T) { Subject: "money", Destination: "0723", } - acc, _ := dm.DataDB().GetAccount("cgrates.org:money") + acc, _ := dm.GetAccount("cgrates.org:money") allowedTime, err := cd.getMaxSessionDuration(acc) expected, err := time.ParseDuration("9999s") // 1 is the connect fee if err != nil || allowedTime != expected { @@ -1657,7 +1657,7 @@ func TestCDRefundIncrements(t *testing.T) { } cd := &CallDescriptor{TOR: utils.VOICE, Increments: increments} cd.RefundIncrements() - ub, _ = dm.DataDB().GetAccount(ub.ID) + ub, _ = dm.GetAccount(ub.ID) if ub.BalanceMap[utils.MONETARY][0].GetValue() != 104 || ub.BalanceMap[utils.VOICE][0].GetValue() != 13*float64(time.Second) || ub.BalanceMap[utils.VOICE][1].GetValue() != 14*float64(time.Second) { @@ -1686,7 +1686,7 @@ func TestCDRefundIncrementsZeroValue(t *testing.T) { } cd := &CallDescriptor{TOR: utils.VOICE, Increments: increments} cd.RefundIncrements() - ub, _ = dm.DataDB().GetAccount(ub.ID) + ub, _ = dm.GetAccount(ub.ID) if ub.BalanceMap[utils.MONETARY][0].GetValue() != 100 || ub.BalanceMap[utils.VOICE][0].GetValue() != 10 || ub.BalanceMap[utils.VOICE][1].GetValue() != 10 { @@ -1835,7 +1835,7 @@ func TestCDDebitBalanceSubjectWithFallback(t *testing.T) { } else if cc.Cost != 0.6 { t.Errorf("CallCost: %v", cc) } - if resAcnt, err := dm.DataDB().GetAccount(acnt.ID); err != nil { + if resAcnt, err := dm.GetAccount(acnt.ID); err != nil { t.Error(err) } else if resAcnt.BalanceMap[utils.VOICE][0].ID != "voice1" || resAcnt.BalanceMap[utils.VOICE][0].Value != 0 { diff --git a/engine/datamanager.go b/engine/datamanager.go index 7eacd01f9..999c8d961 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -317,6 +317,25 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b return } +func (dm *DataManager) GetAccount(id string) (acc *Account, err error) { + acc, err = dm.dataDB.GetAccountDrv(id) + if err != nil { + if len(dm.rmtDataDBs) != 0 { + var rmtErr error + for _, rmtDM := range dm.rmtDataDBs { + if acc, rmtErr = rmtDM.dataDB.GetAccountDrv(id); rmtErr == nil { + break + } + } + err = rmtErr + } + if err != nil { + return nil, err + } + } + return +} + // GetStatQueue retrieves a StatQueue from dataDB // handles caching and deserialization of metrics func (dm *DataManager) GetStatQueue(tenant, id string, diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 6f5854776..0744a5c2b 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -942,12 +942,12 @@ func TestLoadAccountActions(t *testing.T) { t.Errorf("Error loading account action: %+v", utils.ToIJSON(aa.UnitCounters[utils.VOICE][0].Counters[0].Filter)) } // test that it does not overwrite balances - existing, err := dm.DataDB().GetAccount(aa.ID) + existing, err := dm.GetAccount(aa.ID) if err != nil || len(existing.BalanceMap) != 2 { t.Errorf("The account was not set before load: %+v", existing) } dm.DataDB().SetAccount(aa) - existing, err = dm.DataDB().GetAccount(aa.ID) + existing, err = dm.GetAccount(aa.ID) if err != nil || len(existing.BalanceMap) != 2 { t.Errorf("The set account altered the balances: %+v", existing) } diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go index 251d77d8b..adb2c24f6 100644 --- a/engine/loader_it_test.go +++ b/engine/loader_it_test.go @@ -276,7 +276,7 @@ func TestLoaderITWriteToDatabase(t *testing.T) { } for k, ub := range loader.accountActions { - rcv, err := loader.dm.DataDB().GetAccount(k) + rcv, err := loader.dm.GetAccount(k) if err != nil { t.Error("Failed GetAccount: ", err.Error()) } diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index d3edb2d23..b002ecaf2 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -1116,13 +1116,13 @@ func testOnStorITCRUDAccount(t *testing.T) { ID: utils.ConcatenatedKey("cgrates.org", "account2"), BalanceMap: map[string]Balances{utils.MONETARY: {&Balance{Value: 10, Weight: 10}}}, } - if _, rcvErr := onStor.DataDB().GetAccount(acc.ID); rcvErr != utils.ErrNotFound { + if _, rcvErr := onStor.GetAccount(acc.ID); rcvErr != utils.ErrNotFound { t.Error(rcvErr) } if err := onStor.DataDB().SetAccount(acc); err != nil { t.Error(err) } - if rcv, err := onStor.DataDB().GetAccount(acc.ID); err != nil { + if rcv, err := onStor.GetAccount(acc.ID); err != nil { t.Error(err) } else if !reflect.DeepEqual(acc.ID, rcv.ID) { t.Errorf("Expecting: %v, received: %v", acc.ID, rcv.ID) @@ -1134,7 +1134,7 @@ func testOnStorITCRUDAccount(t *testing.T) { if err := onStor.DataDB().RemoveAccount(acc.ID); err != nil { t.Error(err) } - if _, rcvErr := onStor.DataDB().GetAccount(acc.ID); rcvErr != utils.ErrNotFound { + if _, rcvErr := onStor.GetAccount(acc.ID); rcvErr != utils.ErrNotFound { t.Error(rcvErr) } } diff --git a/engine/sharedgroup.go b/engine/sharedgroup.go index 359f63c2f..bc26aed2b 100644 --- a/engine/sharedgroup.go +++ b/engine/sharedgroup.go @@ -97,7 +97,7 @@ func (sg *SharedGroup) GetBalances(destination, category, balanceType string, ub if ubId == ub.ID { // skip the initiating user nUb = ub } else { - nUb, _ = dm.DataDB().GetAccount(ubId) + nUb, _ = dm.GetAccount(ubId) if nUb == nil || nUb.Disabled { continue } diff --git a/engine/storage_interface.go b/engine/storage_interface.go index bc845ed95..215e06a16 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -80,7 +80,7 @@ type DataDB interface { RemAccountActionPlans(acntID string, apIDs []string) (err error) PushTask(*Task) error PopTask() (*Task, error) - GetAccount(string) (*Account, error) + GetAccountDrv(string) (*Account, error) SetAccount(*Account) error RemoveAccount(string) error GetResourceProfileDrv(string, string) (*ResourceProfile, error) diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go index 779a047dd..c2793f418 100644 --- a/engine/storage_internal_datadb.go +++ b/engine/storage_internal_datadb.go @@ -646,7 +646,7 @@ func (iDB *InternalDB) PopTask() (t *Task, err error) { return } -func (iDB *InternalDB) GetAccount(id string) (acc *Account, err error) { +func (iDB *InternalDB) GetAccountDrv(id string) (acc *Account, err error) { x, ok := iDB.db.Get(utils.CacheAccounts, utils.ACCOUNT_PREFIX+id) if !ok || x == nil { return nil, utils.ErrNotFound @@ -659,7 +659,7 @@ func (iDB *InternalDB) SetAccount(acc *Account) (err error) { // UPDATE: if all balances expired and were cleaned it makes // sense to write empty balance map if len(acc.BalanceMap) == 0 { - if ac, err := iDB.GetAccount(acc.ID); err == nil && !ac.allBalancesExpired() { + if ac, err := iDB.GetAccountDrv(acc.ID); err == nil && !ac.allBalancesExpired() { ac.ActionTriggers = acc.ActionTriggers ac.UnitCounters = acc.UnitCounters ac.AllowNegative = acc.AllowNegative diff --git a/engine/storage_map_datadb.go b/engine/storage_map_datadb.go index dad222ae2..3e4f3a342 100644 --- a/engine/storage_map_datadb.go +++ b/engine/storage_map_datadb.go @@ -491,7 +491,7 @@ func (ms *MapStorage) RemoveSharedGroupDrv(id string) (err error) { return } -func (ms *MapStorage) GetAccount(key string) (ub *Account, err error) { +func (ms *MapStorage) GetAccountDrv(key string) (ub *Account, err error) { ms.mu.RLock() defer ms.mu.RUnlock() values, ok := ms.dict[utils.ACCOUNT_PREFIX+key] @@ -515,7 +515,7 @@ func (ms *MapStorage) SetAccount(ub *Account) (err error) { // UPDATE: if all balances expired and were cleaned it makes // sense to write empty balance map if len(ub.BalanceMap) == 0 { - if ac, err := ms.GetAccount(ub.ID); err == nil && !ac.allBalancesExpired() { + if ac, err := ms.GetAccountDrv(ub.ID); err == nil && !ac.allBalancesExpired() { ac.ActionTriggers = ub.ActionTriggers ac.UnitCounters = ub.UnitCounters ac.AllowNegative = ub.AllowNegative diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 6d5484db0..075df4b93 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -1143,7 +1143,7 @@ func (ms *MongoStorage) RemoveSharedGroupDrv(id string) (err error) { }) } -func (ms *MongoStorage) GetAccount(key string) (result *Account, err error) { +func (ms *MongoStorage) GetAccountDrv(key string) (result *Account, err error) { result = new(Account) err = ms.query(func(sctx mongo.SessionContext) (err error) { cur := ms.getCol(ColAcc).FindOne(sctx, bson.M{"id": key}) @@ -1164,7 +1164,7 @@ func (ms *MongoStorage) SetAccount(acc *Account) error { // UPDATE: if all balances expired and were cleaned it makes // sense to write empty balance map if len(acc.BalanceMap) == 0 { - if ac, err := ms.GetAccount(acc.ID); err == nil && !ac.allBalancesExpired() { + if ac, err := ms.GetAccountDrv(acc.ID); err == nil && !ac.allBalancesExpired() { ac.ActionTriggers = acc.ActionTriggers ac.UnitCounters = acc.UnitCounters ac.AllowNegative = acc.AllowNegative diff --git a/engine/storage_redis.go b/engine/storage_redis.go index 4b7e3a73b..0f1660925 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -735,7 +735,7 @@ func (rs *RedisStorage) RemoveSharedGroupDrv(id string) (err error) { return rs.Cmd(redis_DEL, utils.SHARED_GROUP_PREFIX+id).Err } -func (rs *RedisStorage) GetAccount(key string) (*Account, error) { +func (rs *RedisStorage) GetAccountDrv(key string) (*Account, error) { rpl := rs.Cmd(redis_GET, utils.ACCOUNT_PREFIX+key) if rpl.Err != nil { return nil, rpl.Err @@ -758,7 +758,7 @@ func (rs *RedisStorage) SetAccount(ub *Account) (err error) { // UPDATE: if all balances expired and were cleaned it makes // sense to write empty balance map if len(ub.BalanceMap) == 0 { - if ac, err := rs.GetAccount(ub.ID); err == nil && !ac.allBalancesExpired() { + if ac, err := rs.GetAccountDrv(ub.ID); err == nil && !ac.allBalancesExpired() { ac.ActionTriggers = ub.ActionTriggers ac.UnitCounters = ub.UnitCounters ac.AllowNegative = ub.AllowNegative diff --git a/engine/storage_test.go b/engine/storage_test.go index d517ad919..1c96e6c03 100644 --- a/engine/storage_test.go +++ b/engine/storage_test.go @@ -115,7 +115,7 @@ func TestStorageCacheRefresh(t *testing.T) { */ func TestStorageDisabledAccount(t *testing.T) { - acc, err := dm.DataDB().GetAccount("cgrates.org:alodis") + acc, err := dm.GetAccount("cgrates.org:alodis") if err != nil || acc == nil { t.Error("Error loading disabled user account: ", err, acc) } @@ -133,11 +133,11 @@ func TestStoreInterfaces(t *testing.T) { } func TestDifferentUuid(t *testing.T) { - a1, err := dm.DataDB().GetAccount("cgrates.org:12345") + a1, err := dm.GetAccount("cgrates.org:12345") if err != nil { t.Error("Error getting account: ", err) } - a2, err := dm.DataDB().GetAccount("cgrates.org:123456") + a2, err := dm.GetAccount("cgrates.org:123456") if err != nil { t.Error("Error getting account: ", err) } diff --git a/engine/tpreader.go b/engine/tpreader.go index a89eec8e6..63a6ebe60 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -1068,7 +1068,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions) return err } } - ub, err := tpr.dm.DataDB().GetAccount(id) + ub, err := tpr.dm.GetAccount(id) if err != nil { ub = &Account{ ID: id, diff --git a/general_tests/acntacts_test.go b/general_tests/acntacts_test.go index 73bff05e0..5d49cf616 100644 --- a/general_tests/acntacts_test.go +++ b/general_tests/acntacts_test.go @@ -72,7 +72,7 @@ ENABLE_ACNT,*enable_account,,,,,,,,,,,,,false,false,10` nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil) expectAcnt := &engine.Account{ID: "cgrates.org:1"} - if acnt, err := dbAcntActs.DataDB().GetAccount("cgrates.org:1"); err != nil { + if acnt, err := dbAcntActs.GetAccount("cgrates.org:1"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account created") @@ -91,7 +91,7 @@ func TestAcntActsDisableAcnt(t *testing.T) { t.Error(err) } expectAcnt := &engine.Account{ID: "cgrates.org:1", Disabled: true} - if acnt, err := dbAcntActs.DataDB().GetAccount(acnt1Tag); err != nil { + if acnt, err := dbAcntActs.GetAccount(acnt1Tag); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectAcnt, acnt) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectAcnt), utils.ToJSON(acnt)) @@ -108,7 +108,7 @@ func TestAcntActsEnableAcnt(t *testing.T) { t.Error(err) } expectAcnt := &engine.Account{ID: "cgrates.org:1", Disabled: false} - if acnt, err := dbAcntActs.DataDB().GetAccount(acnt1Tag); err != nil { + if acnt, err := dbAcntActs.GetAccount(acnt1Tag); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectAcnt, acnt) { t.Errorf("Expecting: %+v, received: %+v", expectAcnt, acnt) diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index e84c58e88..93ae5996e 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -72,7 +72,7 @@ cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_ANY,` t.Fatal(err) } csvr.WriteToDatabase(false, false) - if acnt, err := dbAuth.DataDB().GetAccount("cgrates.org:testauthpostpaid1"); err != nil { + if acnt, err := dbAuth.GetAccount("cgrates.org:testauthpostpaid1"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account saved") diff --git a/general_tests/ddazmbl1_test.go b/general_tests/ddazmbl1_test.go index 4d937c6bc..b1237560f 100644 --- a/general_tests/ddazmbl1_test.go +++ b/general_tests/ddazmbl1_test.go @@ -105,7 +105,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` t.Fatal(err) } csvr.WriteToDatabase(false, false) - if acnt, err := dataDB.DataDB().GetAccount("cgrates.org:12344"); err != nil { + if acnt, err := dataDB.GetAccount("cgrates.org:12344"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account saved") @@ -133,7 +133,7 @@ func TestDZ1ExecuteActions(t *testing.T) { scheduler.NewScheduler(dataDB, config.CgrConfig(), engine.NewFilterS(config.CgrConfig(), nil, nil, nil, dataDB)).Reload() time.Sleep(10 * time.Millisecond) // Give time to scheduler to topup the account - if acnt, err := dataDB.DataDB().GetAccount("cgrates.org:12344"); err != nil { + if acnt, err := dataDB.GetAccount("cgrates.org:12344"); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 2 { t.Error("Account does not have enough balances: ", acnt.BalanceMap) @@ -161,7 +161,7 @@ func TestDZ1Debit(t *testing.T) { } else if cc.Cost != 0.01 { t.Error("Wrong cost returned: ", cc.Cost) } - acnt, err := dataDB.DataDB().GetAccount("cgrates.org:12344") + acnt, err := dataDB.GetAccount("cgrates.org:12344") if err != nil { t.Fatal(err) } diff --git a/general_tests/ddazmbl2_test.go b/general_tests/ddazmbl2_test.go index 51c8adb69..bc83a10b2 100644 --- a/general_tests/ddazmbl2_test.go +++ b/general_tests/ddazmbl2_test.go @@ -103,7 +103,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` t.Fatal(err) } csvr.WriteToDatabase(false, false) - if acnt, err := dataDB2.DataDB().GetAccount("cgrates.org:12345"); err != nil { + if acnt, err := dataDB2.GetAccount("cgrates.org:12345"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account saved") @@ -130,7 +130,7 @@ func TestExecuteActions2(t *testing.T) { scheduler.NewScheduler(dataDB2, config.CgrConfig(), engine.NewFilterS(config.CgrConfig(), nil, nil, nil, dataDB)).Reload() time.Sleep(10 * time.Millisecond) // Give time to scheduler to topup the account - if acnt, err := dataDB2.DataDB().GetAccount("cgrates.org:12345"); err != nil { + if acnt, err := dataDB2.GetAccount("cgrates.org:12345"); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 2 { t.Error("Account does not have enough balances: ", acnt.BalanceMap) @@ -156,7 +156,7 @@ func TestDebit2(t *testing.T) { } else if cc.Cost != 0.01 { t.Error("Wrong cost returned: ", cc.Cost) } - acnt, err := dataDB2.DataDB().GetAccount("cgrates.org:12345") + acnt, err := dataDB2.GetAccount("cgrates.org:12345") if err != nil { t.Error(err) } diff --git a/general_tests/ddazmbl3_test.go b/general_tests/ddazmbl3_test.go index 0586c2f1c..d84795f7c 100644 --- a/general_tests/ddazmbl3_test.go +++ b/general_tests/ddazmbl3_test.go @@ -102,7 +102,7 @@ cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,` } csvr.WriteToDatabase(false, false) - if acnt, err := dataDB3.DataDB().GetAccount("cgrates.org:12346"); err != nil { + if acnt, err := dataDB3.GetAccount("cgrates.org:12346"); err != nil { t.Error(err) } else if acnt == nil { t.Error("No account saved") @@ -129,7 +129,7 @@ func TestExecuteActions3(t *testing.T) { scheduler.NewScheduler(dataDB3, config.CgrConfig(), engine.NewFilterS(config.CgrConfig(), nil, nil, nil, dataDB)).Reload() time.Sleep(10 * time.Millisecond) // Give time to scheduler to topup the account - if acnt, err := dataDB3.DataDB().GetAccount("cgrates.org:12346"); err != nil { + if acnt, err := dataDB3.GetAccount("cgrates.org:12346"); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 { t.Error("Account does not have enough balances: ", acnt.BalanceMap) @@ -153,7 +153,7 @@ func TestDebit3(t *testing.T) { } else if cc.Cost != 0.01 { t.Error("Wrong cost returned: ", cc.Cost) } - acnt, err := dataDB3.DataDB().GetAccount("cgrates.org:12346") + acnt, err := dataDB3.GetAccount("cgrates.org:12346") if err != nil { t.Error(err) } diff --git a/migrator/accounts.go b/migrator/accounts.go index ebc5a2d35..607cdda6a 100755 --- a/migrator/accounts.go +++ b/migrator/accounts.go @@ -42,7 +42,7 @@ func (m *Migrator) migrateCurrentAccounts() (err error) { } for _, id := range ids { idg := strings.TrimPrefix(id, utils.ACCOUNT_PREFIX) - acc, err := m.dmIN.DataManager().DataDB().GetAccount(idg) + acc, err := m.dmIN.DataManager().GetAccount(idg) if err != nil { return err } diff --git a/migrator/accounts2_it_test.go b/migrator/accounts2_it_test.go index 95537700e..d0420d043 100755 --- a/migrator/accounts2_it_test.go +++ b/migrator/accounts2_it_test.go @@ -237,7 +237,7 @@ func testAcc2ITMigrate(t *testing.T) { t.Errorf("Unexpected version returned: %d", vrs[utils.Accounts]) } //check if account was migrate correctly - result, err := acc2Migrator.dmOut.DataManager().DataDB().GetAccount(testAccount.ID) + result, err := acc2Migrator.dmOut.DataManager().GetAccount(testAccount.ID) if err != nil { t.Error("Error when getting Accounts ", err.Error()) } diff --git a/migrator/accounts_it_test.go b/migrator/accounts_it_test.go index ee65908d2..b17a05fb2 100755 --- a/migrator/accounts_it_test.go +++ b/migrator/accounts_it_test.go @@ -307,7 +307,7 @@ func testAccITMigrateAndMove(t *testing.T) { t.Errorf("Unexpected version returned: %d", vrs[utils.Accounts]) } //check if account was migrate correctly - result, err := accMigrator.dmOut.DataManager().DataDB().GetAccount(testAccount.ID) + result, err := accMigrator.dmOut.DataManager().GetAccount(testAccount.ID) if err != nil { t.Error("Error when getting Accounts ", err.Error()) } @@ -335,7 +335,7 @@ func testAccITMigrateAndMove(t *testing.T) { t.Error("Error when accMigratorrating Accounts ", err.Error()) } //check if account was migrate correctly - result, err := accMigrator.dmOut.DataManager().DataDB().GetAccount(testAccount.ID) + result, err := accMigrator.dmOut.DataManager().GetAccount(testAccount.ID) if err != nil { t.Error(err) } @@ -343,7 +343,7 @@ func testAccITMigrateAndMove(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", testAccount, result) } //check if old account was deleted - result, err = accMigrator.dmIN.DataManager().DataDB().GetAccount(testAccount.ID) + result, err = accMigrator.dmIN.DataManager().GetAccount(testAccount.ID) if err != utils.ErrNotFound { t.Error(err) }