mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"math"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -255,7 +256,8 @@ func (self *ApierV1) GetAccounts(attr utils.AttrGetAccounts, reply *[]*engine.Ac
|
||||
}
|
||||
var limitedAccounts []string
|
||||
if attr.Limit != 0 {
|
||||
limitedAccounts = accountKeys[attr.Offset : attr.Offset+attr.Limit]
|
||||
max := math.Min(float64(attr.Offset+attr.Limit), float64(len(accountKeys)))
|
||||
limitedAccounts = accountKeys[attr.Offset:int(max)]
|
||||
} else {
|
||||
limitedAccounts = accountKeys[attr.Offset:]
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (self *ApierV1) RemRatingSubjectAliases(tenantRatingSubject engine.TenantRa
|
||||
if missing := utils.MissingStructFields(&tenantRatingSubject, []string{"Tenant", "Subject"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.RatingDb.RemoveRpAliases([]*engine.TenantRatingSubject{&tenantRatingSubject}); err != nil {
|
||||
if err := self.RatingDb.RemoveRpAliases([]*engine.TenantRatingSubject{&tenantRatingSubject}, false); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
@@ -125,7 +125,7 @@ func (self *ApierV1) RemAccountAliases(tenantAccount engine.TenantAccount, reply
|
||||
if missing := utils.MissingStructFields(&tenantAccount, []string{"Tenant", "Account"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if err := self.RatingDb.RemoveAccAliases([]*engine.TenantAccount{&tenantAccount}); err != nil {
|
||||
if err := self.RatingDb.RemoveAccAliases([]*engine.TenantAccount{&tenantAccount}, false); err != nil {
|
||||
if err == utils.ErrNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ func (self *ApierV1) GetActions(actsId string, reply *[]*utils.TPAction) error {
|
||||
Weight: engAct.Weight,
|
||||
}
|
||||
if engAct.Balance != nil {
|
||||
act.Units = engAct.Balance.Value
|
||||
act.Units = engAct.Balance.GetValue()
|
||||
act.DestinationIds = engAct.Balance.DestinationIds
|
||||
act.RatingSubject = engAct.Balance.RatingSubject
|
||||
act.SharedGroup = engAct.Balance.SharedGroup
|
||||
|
||||
@@ -86,6 +86,8 @@ func executeCommand(command string) {
|
||||
param = param.(*console.StringWrapper).Item
|
||||
case *console.StringSliceWrapper:
|
||||
param = param.(*console.StringSliceWrapper).Items
|
||||
case *console.StringMapWrapper:
|
||||
param = param.(*console.StringMapWrapper).Items
|
||||
}
|
||||
//log.Printf("Param: %+v", param)
|
||||
|
||||
|
||||
@@ -89,4 +89,8 @@ type StringSliceWrapper struct {
|
||||
Items []string
|
||||
}
|
||||
|
||||
type StringMapWrapper struct {
|
||||
Items map[string]string
|
||||
}
|
||||
|
||||
type EmptyWrapper struct{}
|
||||
|
||||
@@ -18,8 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package console
|
||||
|
||||
import "github.com/cgrates/cgrates/engine"
|
||||
|
||||
func init() {
|
||||
c := &CmdPublish{
|
||||
name: "publish",
|
||||
@@ -32,7 +30,7 @@ func init() {
|
||||
type CmdPublish struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *engine.PublishInfo
|
||||
rpcParams *StringMapWrapper
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
@@ -46,7 +44,7 @@ func (self *CmdPublish) RpcMethod() string {
|
||||
|
||||
func (self *CmdPublish) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &engine.PublishInfo{}
|
||||
self.rpcParams = &StringMapWrapper{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
@@ -115,16 +115,16 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
|
||||
}
|
||||
if b.MatchFilter(a.Balance) {
|
||||
if reset {
|
||||
b.Value = 0
|
||||
b.SetValue(0)
|
||||
}
|
||||
b.SubstractAmount(bClone.Value)
|
||||
b.SubstractValue(bClone.GetValue())
|
||||
found = true
|
||||
}
|
||||
}
|
||||
// if it is not found then we add it to the list
|
||||
if !found {
|
||||
if bClone.Value != 0 {
|
||||
bClone.Value = -bClone.Value
|
||||
if bClone.GetValue() != 0 {
|
||||
bClone.SetValue(-bClone.GetValue())
|
||||
}
|
||||
bClone.dirty = true // Mark the balance as dirty since we have modified and it should be checked by action triggers
|
||||
ub.BalanceMap[id] = append(ub.BalanceMap[id], bClone)
|
||||
@@ -150,7 +150,7 @@ func (ub *Account) debitBalanceAction(a *Action, reset bool) error {
|
||||
func (ub *Account) getBalancesForPrefix(prefix, category string, balances BalanceChain, sharedGroup string) BalanceChain {
|
||||
var usefulBalances BalanceChain
|
||||
for _, b := range balances {
|
||||
if b.IsExpired() || (b.SharedGroup == "" && b.Value <= 0) {
|
||||
if b.IsExpired() || (b.SharedGroup == "" && b.GetValue() <= 0) {
|
||||
continue
|
||||
}
|
||||
if sharedGroup != "" && b.SharedGroup != sharedGroup {
|
||||
@@ -345,7 +345,7 @@ func (ub *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun boo
|
||||
for _, increment := range ts.Increments {
|
||||
cost := increment.Cost
|
||||
defaultBalance := ub.GetDefaultMoneyBalance(leftCC.Direction)
|
||||
defaultBalance.SubstractAmount(cost)
|
||||
defaultBalance.SubstractValue(cost)
|
||||
increment.BalanceInfo.MoneyBalanceUuid = defaultBalance.Uuid
|
||||
increment.BalanceInfo.AccountId = ub.Id
|
||||
increment.paid = true
|
||||
@@ -390,7 +390,7 @@ func (ub *Account) refundIncrement(increment *Increment, direction, unitType str
|
||||
if balance = ub.BalanceMap[unitType+direction].GetBalance(increment.BalanceInfo.UnitBalanceUuid); balance == nil {
|
||||
return
|
||||
}
|
||||
balance.Value += increment.Duration.Seconds()
|
||||
balance.AddValue(increment.Duration.Seconds())
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceType: unitType, Direction: direction, Balance: &Balance{Value: -increment.Duration.Seconds()}})
|
||||
}
|
||||
@@ -400,7 +400,7 @@ func (ub *Account) refundIncrement(increment *Increment, direction, unitType str
|
||||
if balance = ub.BalanceMap[utils.MONETARY+direction].GetBalance(increment.BalanceInfo.MoneyBalanceUuid); balance == nil {
|
||||
return
|
||||
}
|
||||
balance.Value += increment.Cost
|
||||
balance.AddValue(increment.Cost)
|
||||
if count {
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: direction, Balance: &Balance{Value: -increment.Cost}})
|
||||
}
|
||||
@@ -429,12 +429,12 @@ func (ub *Account) executeActionTriggers(a *Action) {
|
||||
if uc.BalanceType == at.BalanceType {
|
||||
for _, mb := range uc.Balances {
|
||||
if strings.Contains(at.ThresholdType, "*max") {
|
||||
if mb.MatchActionTrigger(at) && mb.Value >= at.ThresholdValue {
|
||||
if mb.MatchActionTrigger(at) && mb.GetValue() >= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
} else { //MIN
|
||||
if mb.MatchActionTrigger(at) && mb.Value <= at.ThresholdValue {
|
||||
if mb.MatchActionTrigger(at) && mb.GetValue() <= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
@@ -448,12 +448,12 @@ func (ub *Account) executeActionTriggers(a *Action) {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(at.ThresholdType, "*max") {
|
||||
if b.MatchActionTrigger(at) && b.Value >= at.ThresholdValue {
|
||||
if b.MatchActionTrigger(at) && b.GetValue() >= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
} else { //MIN
|
||||
if b.MatchActionTrigger(at) && b.Value <= at.ThresholdValue {
|
||||
if b.MatchActionTrigger(at) && b.GetValue() <= at.ThresholdValue {
|
||||
// run the actions
|
||||
at.Execute(ub, nil)
|
||||
}
|
||||
@@ -513,7 +513,7 @@ func (ub *Account) countUnits(a *Action) {
|
||||
ub.UnitCounters = append(ub.UnitCounters, unitsCounter)
|
||||
}
|
||||
|
||||
unitsCounter.addUnits(a.Balance.Value, a.Balance.DestinationIds) // DestinationIds is actually a destination (number or prefix)
|
||||
unitsCounter.addUnits(a.Balance.GetValue(), a.Balance.DestinationIds) // DestinationIds is actually a destination (number or prefix)
|
||||
ub.executeActionTriggers(nil)
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ func (ub *Account) initCounters() {
|
||||
ub.UnitCounters = append(ub.UnitCounters, uc)
|
||||
}
|
||||
b := a.Balance.Clone()
|
||||
b.Value = 0
|
||||
b.SetValue(0)
|
||||
uc.Balances = append(uc.Balances, b)
|
||||
uc.Balances.Sort()
|
||||
}
|
||||
@@ -634,8 +634,8 @@ func (acc *Account) DebitConnectionFee(cc *CallCost, usefulMoneyBalances Balance
|
||||
//log.Print("CONNECT FEE: %f", connectFee)
|
||||
connectFeePaid := false
|
||||
for _, b := range usefulMoneyBalances {
|
||||
if b.Value >= connectFee {
|
||||
b.SubstractAmount(connectFee)
|
||||
if b.GetValue() >= connectFee {
|
||||
b.SubstractValue(connectFee)
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
acc.countUnits(&Action{BalanceType: utils.MONETARY, Direction: cc.Direction, Balance: &Balance{Value: connectFee, DestinationIds: cc.Destination}})
|
||||
@@ -647,7 +647,7 @@ func (acc *Account) DebitConnectionFee(cc *CallCost, usefulMoneyBalances Balance
|
||||
// debit connect fee
|
||||
if connectFee > 0 && !connectFeePaid {
|
||||
// there are no money for the connect fee; go negative
|
||||
acc.GetDefaultMoneyBalance(cc.Direction).Value -= connectFee
|
||||
acc.GetDefaultMoneyBalance(cc.Direction).SubstractValue(connectFee)
|
||||
// the conect fee is not refundable!
|
||||
if count {
|
||||
acc.countUnits(&Action{BalanceType: utils.MONETARY, Direction: cc.Direction, Balance: &Balance{Value: connectFee, DestinationIds: cc.Destination}})
|
||||
|
||||
@@ -194,8 +194,8 @@ func TestDebitCreditZeroSecond(t *testing.T) {
|
||||
t.Logf("%+v", cc.Timespans[0])
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 21 {
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0])
|
||||
}
|
||||
}
|
||||
@@ -238,8 +238,8 @@ func TestDebitCreditZeroMinute(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Minute {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 10 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 10 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 21 {
|
||||
t.Error("Error extracting minutes from balance: ",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0])
|
||||
}
|
||||
@@ -284,9 +284,9 @@ func TestDebitCreditZeroMixedMinute(t *testing.T) {
|
||||
cc.Timespans[1].Increments[0].BalanceInfo.UnitBalanceUuid != "testm" {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans)
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][1].Value != 0 ||
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 10 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][1].GetValue() != 0 ||
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 10 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 21 {
|
||||
t.Logf("TS0: %+v", cc.Timespans[0])
|
||||
t.Logf("TS1: %+v", cc.Timespans[1])
|
||||
t.Errorf("Error extracting minutes from balance: %+v", rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][1])
|
||||
@@ -335,7 +335,7 @@ func TestDebitCreditNoCredit(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Minute {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 10 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 10 {
|
||||
t.Error("Error extracting minutes from balance: ",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0])
|
||||
}
|
||||
@@ -387,10 +387,10 @@ func TestDebitCreditHasCredit(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Minute {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 10 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 30 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 10 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 30 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
if len(cc.Timespans) != 3 || cc.Timespans[0].GetDuration() != time.Minute {
|
||||
t.Error("Error truncating extra timespans: ", cc.Timespans)
|
||||
@@ -435,10 +435,10 @@ func TestDebitCreditSplitMinutesMoney(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != 1*time.Second {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0].Duration)
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 30 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 30 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
if len(cc.Timespans) != 2 || cc.Timespans[0].GetDuration() != 10*time.Second || cc.Timespans[1].GetDuration() != 20*time.Second {
|
||||
t.Error("Error truncating extra timespans: ", cc.Timespans[1].GetDuration())
|
||||
@@ -487,7 +487,7 @@ func TestDebitCreditMoreTimespans(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Minute {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 30 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 30 {
|
||||
t.Error("Error extracting minutes from balance: ",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0])
|
||||
}
|
||||
@@ -536,8 +536,8 @@ func TestDebitCreditMoreTimespansMixed(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != time.Minute {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 10 ||
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][1].Value != 130 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 10 ||
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][1].GetValue() != 130 {
|
||||
t.Error("Error extracting minutes from balance: ",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][1], cc.Timespans[1])
|
||||
}
|
||||
@@ -631,7 +631,7 @@ func TestDebitCreditMoneyOnly(t *testing.T) {
|
||||
t.Logf("%+v", cc.Timespans[0].Increments)
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0].BalanceInfo)
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 0 {
|
||||
if rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 0 {
|
||||
t.Error("Error extracting minutes from balance: ",
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0])
|
||||
}
|
||||
@@ -685,10 +685,10 @@ func TestDebitCreditSubjectMinutes(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != 10*time.Second {
|
||||
t.Errorf("Error setting balance id to increment: %+v", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 180 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 280 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 180 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 280 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
if len(cc.Timespans) != 1 || cc.Timespans[0].GetDuration() != 70*time.Second {
|
||||
for _, ts := range cc.Timespans {
|
||||
@@ -738,9 +738,9 @@ func TestDebitCreditSubjectMoney(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != 10*time.Second {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 5 {
|
||||
if rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 5 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v",
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
if len(cc.Timespans) != 1 || cc.Timespans[0].GetDuration() != 70*time.Second {
|
||||
t.Error("Error truncating extra timespans: ", cc.Timespans)
|
||||
@@ -790,10 +790,10 @@ func TestDebitCreditSubjectMoney(t *testing.T) {
|
||||
cc.Timespans[0].Increments[0].Duration != 10*time.Second {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 7 {
|
||||
if rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 7 {
|
||||
t.Errorf("Error extracting minutes from balance: %+v, %+v",
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
rifsBalance.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
if len(cc.Timespans) != 2 || cc.Timespans[0].GetDuration() != 40*time.Second {
|
||||
for _, ts := range cc.Timespans {
|
||||
@@ -827,7 +827,7 @@ func TestAccountdebitBalanceExists(t *testing.T) {
|
||||
newMb := &Balance{Value: -10, Weight: 20, DestinationIds: "NAT"}
|
||||
a := &Action{BalanceType: utils.VOICE, Direction: OUTBOUND, Balance: newMb}
|
||||
ub.debitBalanceAction(a, false)
|
||||
if len(ub.BalanceMap[utils.VOICE+OUTBOUND]) != 2 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 25 {
|
||||
if len(ub.BalanceMap[utils.VOICE+OUTBOUND]) != 2 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 25 {
|
||||
t.Error("Error adding minute bucket!")
|
||||
}
|
||||
}
|
||||
@@ -856,7 +856,7 @@ func TestAccountAddMinutBucketEmpty(t *testing.T) {
|
||||
}
|
||||
a = &Action{BalanceType: utils.VOICE, Direction: OUTBOUND, Balance: mb2}
|
||||
ub.debitBalanceAction(a, false)
|
||||
if len(ub.BalanceMap[utils.VOICE+OUTBOUND]) != 1 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 20 {
|
||||
if len(ub.BalanceMap[utils.VOICE+OUTBOUND]) != 1 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 20 {
|
||||
t.Error("Error adding minute bucket: ", ub.BalanceMap[utils.VOICE+OUTBOUND])
|
||||
}
|
||||
a = &Action{BalanceType: utils.VOICE, Direction: OUTBOUND, Balance: mb3}
|
||||
@@ -874,19 +874,19 @@ func TestAccountExecuteTriggeredActions(t *testing.T) {
|
||||
ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirection: OUTBOUND, ThresholdValue: 2, ThresholdType: TRIGGER_MAX_COUNTER, ActionsId: "TEST_ACTIONS"}},
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Balance: &Balance{Value: 1}})
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 110 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 20 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value, ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 110 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 20 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue(), ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
// are set to executed
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 1}})
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 110 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 20 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value, ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 110 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 20 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue(), ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
// we can reset them
|
||||
ub.ResetActionTriggers(nil)
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 120 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 30 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value, ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 120 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 30 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue(), ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -898,8 +898,8 @@ func TestAccountExecuteTriggeredActionsBalance(t *testing.T) {
|
||||
ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirection: OUTBOUND, ThresholdValue: 100, ThresholdType: TRIGGER_MIN_COUNTER, ActionsId: "TEST_ACTIONS"}},
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Balance: &Balance{Value: 1}})
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 110 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 20 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value, ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 110 || ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 20 {
|
||||
t.Error("Error executing triggered actions", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue(), ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -911,8 +911,8 @@ func TestAccountExecuteTriggeredActionsOrder(t *testing.T) {
|
||||
ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: utils.MONETARY, BalanceDirection: OUTBOUND, ThresholdValue: 2, ThresholdType: TRIGGER_MAX_COUNTER, ActionsId: "TEST_ACTIONS_ORDER"}},
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 1}})
|
||||
if len(ub.BalanceMap[utils.MONETARY+OUTBOUND]) != 1 || ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 10 {
|
||||
t.Error("Error executing triggered actions in order", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
if len(ub.BalanceMap[utils.MONETARY+OUTBOUND]) != 1 || ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 10 {
|
||||
t.Error("Error executing triggered actions in order", ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,11 +939,11 @@ func TestCleanExpired(t *testing.T) {
|
||||
func TestAccountUnitCounting(t *testing.T) {
|
||||
ub := &Account{}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 10 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 10 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 20 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 20 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
}
|
||||
@@ -951,15 +951,15 @@ func TestAccountUnitCounting(t *testing.T) {
|
||||
func TestAccountUnitCountingOutbound(t *testing.T) {
|
||||
ub := &Account{}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 10 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 10 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 20 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 20 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 30 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 30 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
}
|
||||
@@ -967,15 +967,15 @@ func TestAccountUnitCountingOutbound(t *testing.T) {
|
||||
func TestAccountUnitCountingOutboundInbound(t *testing.T) {
|
||||
ub := &Account{}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 10 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 10 {
|
||||
t.Errorf("Error counting units: %+v", ub.UnitCounters[0])
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: OUTBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 20 {
|
||||
if len(ub.UnitCounters) != 1 && ub.UnitCounters[0].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 20 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
ub.countUnits(&Action{BalanceType: utils.MONETARY, Direction: INBOUND, Balance: &Balance{Value: 10}})
|
||||
if len(ub.UnitCounters) != 2 && ub.UnitCounters[1].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].Value != 20 || ub.UnitCounters[1].Balances[0].Value != 10 {
|
||||
if len(ub.UnitCounters) != 2 && ub.UnitCounters[1].BalanceType != utils.MONETARY || ub.UnitCounters[0].Balances[0].GetValue() != 20 || ub.UnitCounters[1].Balances[0].GetValue() != 10 {
|
||||
t.Error("Error counting units")
|
||||
}
|
||||
}
|
||||
@@ -1000,10 +1000,10 @@ func TestAccountRefund(t *testing.T) {
|
||||
for _, increment := range increments {
|
||||
ub.refundIncrement(increment, OUTBOUND, utils.VOICE, false)
|
||||
}
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 104 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 13 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][1].Value != 14 {
|
||||
t.Error("Error refounding money: ", ub.BalanceMap[utils.VOICE+OUTBOUND][1].Value)
|
||||
if ub.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 104 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 13 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][1].GetValue() != 14 {
|
||||
t.Error("Error refounding money: ", ub.BalanceMap[utils.VOICE+OUTBOUND][1].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1050,11 +1050,11 @@ func TestDebitShared(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error debiting balance: ", err)
|
||||
}
|
||||
if rif.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 0 {
|
||||
if rif.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 0 {
|
||||
t.Errorf("Error debiting from shared group: %+v", rif.BalanceMap[utils.MONETARY+OUTBOUND][0])
|
||||
}
|
||||
groupie, _ = accountingStorage.GetAccount("groupie")
|
||||
if groupie.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 10 {
|
||||
if groupie.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 10 {
|
||||
t.Errorf("Error debiting from shared group: %+v", groupie.BalanceMap[utils.MONETARY+OUTBOUND][0])
|
||||
}
|
||||
|
||||
@@ -1162,10 +1162,10 @@ func TestDebitSMS(t *testing.T) {
|
||||
if cc.Timespans[0].Increments[0].BalanceInfo.UnitBalanceUuid != "testm" {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.SMS+OUTBOUND][0].Value != 99 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
if rifsBalance.BalanceMap[utils.SMS+OUTBOUND][0].GetValue() != 99 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 21 {
|
||||
t.Log(cc.Timespans[0].Increments)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.SMS+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.SMS+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1205,10 +1205,10 @@ func TestDebitGeneric(t *testing.T) {
|
||||
if cc.Timespans[0].Increments[0].BalanceInfo.UnitBalanceUuid != "testm" {
|
||||
t.Error("Error setting balance id to increment: ", cc.Timespans[0].Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.GENERIC+OUTBOUND][0].Value != 99 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
if rifsBalance.BalanceMap[utils.GENERIC+OUTBOUND][0].GetValue() != 99 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 21 {
|
||||
t.Log(cc.Timespans[0].Increments)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.GENERIC+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.GENERIC+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1260,10 +1260,10 @@ func TestDebitDataUnits(t *testing.T) {
|
||||
if ts.Increments[0].BalanceInfo.UnitBalanceUuid != "testm" {
|
||||
t.Error("Error setting balance id to increment: ", ts.Increments[0])
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].Value != 20 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 21 {
|
||||
if rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].GetValue() != 20 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 21 {
|
||||
t.Log(ts.Increments)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1306,9 +1306,9 @@ func TestDebitDataMoney(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Error debiting balance: ", err)
|
||||
}
|
||||
if rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].Value != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 0 {
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].Value, rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].Value)
|
||||
if rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].GetValue() != 0 ||
|
||||
rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 0 {
|
||||
t.Error("Error extracting minutes from balance: ", rifsBalance.BalanceMap[utils.DATA+OUTBOUND][0].GetValue(), rifsBalance.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ func parseTemplateValue(rsrFlds utils.RSRFields, acnt *Account, action *Action)
|
||||
case "balance_id":
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.Id)
|
||||
case "balance_value":
|
||||
parsedValue += rsrFld.ParseValue(strconv.FormatFloat(action.Balance.Value, 'f', -1, 64))
|
||||
parsedValue += rsrFld.ParseValue(strconv.FormatFloat(action.Balance.GetValue(), 'f', -1, 64))
|
||||
case "destination_id":
|
||||
parsedValue += rsrFld.ParseValue(action.Balance.DestinationIds)
|
||||
case "extra_params":
|
||||
@@ -375,8 +375,8 @@ func resetCountersAction(ub *Account, sq *StatsQueueTriggered, a *Action, acs Ac
|
||||
}
|
||||
|
||||
func genericMakeNegative(a *Action) {
|
||||
if a.Balance != nil && a.Balance.Value >= 0 { // only apply if not allready negative
|
||||
a.Balance.Value = -a.Balance.Value
|
||||
if a.Balance != nil && a.Balance.GetValue() >= 0 { // only apply if not allready negative
|
||||
a.Balance.SetValue(-a.Balance.GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -666,7 +666,7 @@ func TestActionResetTriggresExecutesThem(t *testing.T) {
|
||||
ActionTriggers: ActionTriggerPriotityList{&ActionTrigger{BalanceType: utils.MONETARY, ThresholdValue: 2, ActionsId: "TEST_ACTIONS", Executed: true}},
|
||||
}
|
||||
resetTriggersAction(ub, nil, nil, nil)
|
||||
if ub.ActionTriggers[0].Executed == true || ub.BalanceMap[utils.MONETARY][0].Value == 12 {
|
||||
if ub.ActionTriggers[0].Executed == true || ub.BalanceMap[utils.MONETARY][0].GetValue() == 12 {
|
||||
t.Error("Reset triggers action failed!")
|
||||
}
|
||||
}
|
||||
@@ -723,7 +723,7 @@ func TestActionResetPrepaid(t *testing.T) {
|
||||
if !ub.AllowNegative ||
|
||||
ub.BalanceMap[utils.MONETARY].GetTotalValue() != 0 ||
|
||||
len(ub.UnitCounters) != 0 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 0 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 0 ||
|
||||
ub.ActionTriggers[0].Executed == true || ub.ActionTriggers[1].Executed == true {
|
||||
t.Log(ub.BalanceMap)
|
||||
t.Error("Reset prepaid action failed!")
|
||||
@@ -740,7 +740,7 @@ func TestActionResetPostpaid(t *testing.T) {
|
||||
resetAccountAction(ub, nil, nil, nil)
|
||||
if ub.BalanceMap[utils.MONETARY].GetTotalValue() != 0 ||
|
||||
len(ub.UnitCounters) != 0 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 0 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 0 ||
|
||||
ub.ActionTriggers[0].Executed == true || ub.ActionTriggers[1].Executed == true {
|
||||
t.Error("Reset postpaid action failed!")
|
||||
}
|
||||
@@ -888,7 +888,7 @@ func TestActionDebitMinutes(t *testing.T) {
|
||||
a := &Action{BalanceType: utils.VOICE, Direction: OUTBOUND, Balance: &Balance{Value: 5, Weight: 20, DestinationIds: "NAT"}}
|
||||
debitAction(ub, nil, a, nil)
|
||||
if ub.AllowNegative ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 5 ||
|
||||
ub.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 5 ||
|
||||
ub.BalanceMap[utils.MONETARY].GetTotalValue() != 100 ||
|
||||
len(ub.UnitCounters) != 1 ||
|
||||
len(ub.BalanceMap[utils.VOICE+OUTBOUND]) != 2 ||
|
||||
@@ -922,7 +922,7 @@ func TestActionResetAllCounters(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
mb := ub.UnitCounters[0].Balances[0]
|
||||
if mb.Weight != 20 || mb.Value != 0 || mb.DestinationIds != "NAT" {
|
||||
if mb.Weight != 20 || mb.GetValue() != 0 || mb.DestinationIds != "NAT" {
|
||||
t.Errorf("Balance cloned incorrectly: %v!", mb)
|
||||
}
|
||||
}
|
||||
@@ -954,7 +954,7 @@ func TestActionResetCounterMinutes(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
mb := ub.UnitCounters[1].Balances[0]
|
||||
if mb.Weight != 20 || mb.Value != 0 || mb.DestinationIds != "NAT" {
|
||||
if mb.Weight != 20 || mb.GetValue() != 0 || mb.DestinationIds != "NAT" {
|
||||
t.Errorf("Balance cloned incorrectly: %+v!", mb)
|
||||
}
|
||||
}
|
||||
@@ -1055,11 +1055,11 @@ func TestActionPlanLogging(t *testing.T) {
|
||||
func TestActionMakeNegative(t *testing.T) {
|
||||
a := &Action{Balance: &Balance{Value: 10}}
|
||||
genericMakeNegative(a)
|
||||
if a.Balance.Value > 0 {
|
||||
if a.Balance.GetValue() > 0 {
|
||||
t.Error("Failed to make negative: ", a)
|
||||
}
|
||||
genericMakeNegative(a)
|
||||
if a.Balance.Value > 0 {
|
||||
if a.Balance.GetValue() > 0 {
|
||||
t.Error("Failed to preserve negative: ", a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ func (b *Balance) getMatchingPrefixAndDestId(dest string) (prefix, destId string
|
||||
// Returns the available number of seconds for a specified credit
|
||||
func (b *Balance) GetMinutesForCredit(origCD *CallDescriptor, initialCredit float64) (duration time.Duration, credit float64) {
|
||||
cd := origCD.Clone()
|
||||
availableDuration := time.Duration(b.Value) * time.Second
|
||||
availableDuration := time.Duration(b.GetValue()) * time.Second
|
||||
duration = availableDuration
|
||||
credit = initialCredit
|
||||
cc, err := b.GetCost(cd, false)
|
||||
@@ -280,32 +280,52 @@ func (b *Balance) GetCost(cd *CallDescriptor, getStandardIfEmpty bool) (*CallCos
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Balance) SubstractAmount(amount float64) {
|
||||
func (b *Balance) GetValue() float64 {
|
||||
return b.Value
|
||||
}
|
||||
|
||||
func (b *Balance) AddValue(amount float64) {
|
||||
b.SetValue(b.GetValue() + amount)
|
||||
}
|
||||
|
||||
func (b *Balance) SubstractValue(amount float64) {
|
||||
b.SetValue(b.GetValue() - amount)
|
||||
}
|
||||
|
||||
func (b *Balance) SetValue(amount float64) {
|
||||
b.Value = amount
|
||||
b.Value = utils.Round(b.GetValue(), globalRoundingDecimals, utils.ROUNDING_MIDDLE)
|
||||
b.dirty = true
|
||||
|
||||
// publish event
|
||||
accountId := ""
|
||||
allowNegative := ""
|
||||
disabled := ""
|
||||
if b.account != nil {
|
||||
accountId = b.account.Id
|
||||
allowNegative = strconv.FormatBool(b.account.AllowNegative)
|
||||
disabled = strconv.FormatBool(b.account.Disabled)
|
||||
}
|
||||
Publish(CgrEvent{
|
||||
"EventName": utils.EVT_ACCOUNT_BALANCE_MODIFIED,
|
||||
"Uuid": b.Uuid,
|
||||
"Id": b.Id,
|
||||
"Value": strconv.FormatFloat(b.Value, 'f', -1, 64),
|
||||
"ExpirationDate": b.ExpirationDate.String(),
|
||||
"Weight": strconv.FormatFloat(b.Weight, 'f', -1, 64),
|
||||
"DestinationIds": b.DestinationIds,
|
||||
"RatingSubject": b.RatingSubject,
|
||||
"Category": b.Category,
|
||||
"SharedGroup": b.SharedGroup,
|
||||
"TimingIDs": b.TimingIDs,
|
||||
"Account": accountId,
|
||||
"EventName": utils.EVT_ACCOUNT_BALANCE_MODIFIED,
|
||||
"Uuid": b.Uuid,
|
||||
"Id": b.Id,
|
||||
"Value": strconv.FormatFloat(b.Value, 'f', -1, 64),
|
||||
"ExpirationDate": b.ExpirationDate.String(),
|
||||
"Weight": strconv.FormatFloat(b.Weight, 'f', -1, 64),
|
||||
"DestinationIds": b.DestinationIds,
|
||||
"RatingSubject": b.RatingSubject,
|
||||
"Category": b.Category,
|
||||
"SharedGroup": b.SharedGroup,
|
||||
"TimingIDs": b.TimingIDs,
|
||||
"Account": accountId,
|
||||
"AccountAllowNegative": allowNegative,
|
||||
"AccountDisabled": disabled,
|
||||
})
|
||||
b.Value -= amount
|
||||
b.Value = utils.Round(b.Value, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
|
||||
b.dirty = true
|
||||
}
|
||||
|
||||
func (b *Balance) DebitUnits(cd *CallDescriptor, ub *Account, moneyBalances BalanceChain, count bool, dryRun bool) (cc *CallCost, err error) {
|
||||
if !b.IsActiveAt(cd.TimeStart) || b.Value <= 0 {
|
||||
if !b.IsActiveAt(cd.TimeStart) || b.GetValue() <= 0 {
|
||||
return
|
||||
}
|
||||
if duration, err := utils.ParseZeroRatingSubject(b.RatingSubject); err == nil {
|
||||
@@ -352,8 +372,8 @@ func (b *Balance) DebitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
if seconds == 1 {
|
||||
amount = inc.Duration.Seconds()
|
||||
}
|
||||
if b.Value >= amount {
|
||||
b.SubstractAmount(amount)
|
||||
if b.GetValue() >= amount {
|
||||
b.SubstractValue(amount)
|
||||
inc.BalanceInfo.UnitBalanceUuid = b.Uuid
|
||||
inc.BalanceInfo.AccountId = ub.Id
|
||||
inc.UnitInfo = &UnitInfo{cc.Destination, amount, cc.TOR}
|
||||
@@ -429,19 +449,19 @@ func (b *Balance) DebitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
}
|
||||
var moneyBal *Balance
|
||||
for _, mb := range moneyBalances {
|
||||
if mb.Value >= cost {
|
||||
if mb.GetValue() >= cost {
|
||||
moneyBal = mb
|
||||
break
|
||||
}
|
||||
}
|
||||
if (cost == 0 || moneyBal != nil) && b.Value >= seconds {
|
||||
b.SubstractAmount(seconds)
|
||||
if (cost == 0 || moneyBal != nil) && b.GetValue() >= seconds {
|
||||
b.SubstractValue(seconds)
|
||||
inc.BalanceInfo.UnitBalanceUuid = b.Uuid
|
||||
inc.BalanceInfo.AccountId = ub.Id
|
||||
inc.UnitInfo = &UnitInfo{cc.Destination, seconds, cc.TOR}
|
||||
if cost != 0 {
|
||||
inc.BalanceInfo.MoneyBalanceUuid = moneyBal.Uuid
|
||||
moneyBal.SubstractAmount(cost)
|
||||
moneyBal.SubstractValue(cost)
|
||||
cd.MaxCostSoFar += cost
|
||||
}
|
||||
inc.paid = true
|
||||
@@ -473,7 +493,7 @@ func (b *Balance) DebitUnits(cd *CallDescriptor, ub *Account, moneyBalances Bala
|
||||
}
|
||||
|
||||
func (b *Balance) DebitMoney(cd *CallDescriptor, ub *Account, count bool, dryRun bool) (cc *CallCost, err error) {
|
||||
if !b.IsActiveAt(cd.TimeStart) || b.Value <= 0 {
|
||||
if !b.IsActiveAt(cd.TimeStart) || b.GetValue() <= 0 {
|
||||
return
|
||||
}
|
||||
//log.Printf("}}}}}}} %+v", cd.testCallcost)
|
||||
@@ -531,8 +551,8 @@ func (b *Balance) DebitMoney(cd *CallDescriptor, ub *Account, count bool, dryRun
|
||||
continue
|
||||
}
|
||||
|
||||
if b.Value >= amount {
|
||||
b.SubstractAmount(amount)
|
||||
if b.GetValue() >= amount {
|
||||
b.SubstractValue(amount)
|
||||
cd.MaxCostSoFar += amount
|
||||
inc.BalanceInfo.MoneyBalanceUuid = b.Uuid
|
||||
inc.BalanceInfo.AccountId = ub.Id
|
||||
@@ -591,7 +611,7 @@ func (bc BalanceChain) Sort() {
|
||||
func (bc BalanceChain) GetTotalValue() (total float64) {
|
||||
for _, b := range bc {
|
||||
if !b.IsExpired() && b.IsActive() {
|
||||
total += b.Value
|
||||
total += b.GetValue()
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -603,12 +623,12 @@ func (bc BalanceChain) Debit(amount float64) float64 {
|
||||
if b.IsExpired() {
|
||||
continue
|
||||
}
|
||||
if b.Value >= amount || i == len(bc)-1 { // if last one go negative
|
||||
b.SubstractAmount(amount)
|
||||
if b.GetValue() >= amount || i == len(bc)-1 { // if last one go negative
|
||||
b.SubstractValue(amount)
|
||||
break
|
||||
}
|
||||
b.Value = 0
|
||||
amount -= b.Value
|
||||
b.SetValue(0)
|
||||
amount -= b.GetValue()
|
||||
}
|
||||
return bc.GetTotalValue()
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func SetUserService(us UserService) {
|
||||
func Publish(event CgrEvent) {
|
||||
if pubSubServer != nil {
|
||||
var s string
|
||||
pubSubServer.Publish(PublishInfo{Event: event}, &s)
|
||||
pubSubServer.Publish(event, &s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ func (origCD *CallDescriptor) getMaxSessionDuration(origAcc *Account) (time.Dura
|
||||
defaultBalance := account.GetDefaultMoneyBalance(cd.Direction)
|
||||
|
||||
//use this to check what increment was payed with debt
|
||||
initialDefaultBalanceValue := defaultBalance.Value
|
||||
initialDefaultBalanceValue := defaultBalance.GetValue()
|
||||
|
||||
//Logger.Debug("ACCOUNT: " + utils.ToJSON(account))
|
||||
//Logger.Debug("DEFAULT_BALANCE: " + utils.ToJSON(defaultBalance))
|
||||
|
||||
@@ -699,11 +699,11 @@ func TestMaxDebitWithAccountShared(t *testing.T) {
|
||||
}
|
||||
acc, _ := cd.getAccount()
|
||||
balanceMap := acc.BalanceMap[utils.MONETARY+OUTBOUND]
|
||||
if len(balanceMap) != 1 || balanceMap[0].Value != 0 {
|
||||
if len(balanceMap) != 1 || balanceMap[0].GetValue() != 0 {
|
||||
t.Errorf("Wrong shared balance debited: %+v", balanceMap[0])
|
||||
}
|
||||
other, err := accountingStorage.GetAccount("*out:vdf:empty10")
|
||||
if err != nil || other.BalanceMap[utils.MONETARY+OUTBOUND][0].Value != 7.5 {
|
||||
if err != nil || other.BalanceMap[utils.MONETARY+OUTBOUND][0].GetValue() != 7.5 {
|
||||
t.Errorf("Error debiting shared balance: %+v", other.BalanceMap[utils.MONETARY+OUTBOUND][0])
|
||||
}
|
||||
}
|
||||
@@ -916,8 +916,8 @@ func TestDebitFromShareAndNormal(t *testing.T) {
|
||||
t.Errorf("Debit from share and normal error: %+v, %v", cc, err)
|
||||
}
|
||||
|
||||
if balanceMap[0].Value != 10 || balanceMap[1].Value != 27.5 {
|
||||
t.Errorf("Error debiting from right balance: %v %v", balanceMap[0].Value, balanceMap[1].Value)
|
||||
if balanceMap[0].GetValue() != 10 || balanceMap[1].GetValue() != 27.5 {
|
||||
t.Errorf("Error debiting from right balance: %v %v", balanceMap[0].GetValue(), balanceMap[1].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -944,8 +944,8 @@ func TestDebitFromEmptyShare(t *testing.T) {
|
||||
}
|
||||
acc, _ := cd.getAccount()
|
||||
balanceMap := acc.BalanceMap[utils.MONETARY+OUTBOUND]
|
||||
if len(balanceMap) != 2 || balanceMap[0].Value != 0 || balanceMap[1].Value != -2.5 {
|
||||
t.Errorf("Error debiting from empty share: %+v", balanceMap[1].Value)
|
||||
if len(balanceMap) != 2 || balanceMap[0].GetValue() != 0 || balanceMap[1].GetValue() != -2.5 {
|
||||
t.Errorf("Error debiting from empty share: %+v", balanceMap[1].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -973,16 +973,16 @@ func TestDebitNegatve(t *testing.T) {
|
||||
acc, _ := cd.getAccount()
|
||||
//utils.PrintFull(acc)
|
||||
balanceMap := acc.BalanceMap[utils.MONETARY+OUTBOUND]
|
||||
if len(balanceMap) != 1 || balanceMap[0].Value != -2.5 {
|
||||
t.Errorf("Error debiting from empty share: %+v", balanceMap[0].Value)
|
||||
if len(balanceMap) != 1 || balanceMap[0].GetValue() != -2.5 {
|
||||
t.Errorf("Error debiting from empty share: %+v", balanceMap[0].GetValue())
|
||||
}
|
||||
cc, err = cd.MaxDebit()
|
||||
//utils.PrintFull(cc)
|
||||
if err != nil || cc.Cost != 2.5 {
|
||||
t.Errorf("Debit from empty share error: %+v, %v", cc, err)
|
||||
}
|
||||
if len(balanceMap) != 1 || balanceMap[0].Value != -5 {
|
||||
t.Errorf("Error debiting from empty share: %+v", balanceMap[0].Value)
|
||||
if len(balanceMap) != 1 || balanceMap[0].GetValue() != -5 {
|
||||
t.Errorf("Error debiting from empty share: %+v", balanceMap[0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1059,8 +1059,8 @@ func TestMaxDebitConsumesMinutes(t *testing.T) {
|
||||
LoopIndex: 0,
|
||||
DurationIndex: 0}
|
||||
cd1.MaxDebit()
|
||||
if cd1.account.BalanceMap[utils.VOICE+OUTBOUND][0].Value != 20 {
|
||||
t.Error("Error using minutes: ", cd1.account.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
if cd1.account.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != 20 {
|
||||
t.Error("Error using minutes: ", cd1.account.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,10 @@ func (ce CgrEvent) PassFilters(rsrFields utils.RSRFields) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
type PublishInfo struct {
|
||||
Event CgrEvent
|
||||
}
|
||||
|
||||
type PublisherSubscriber interface {
|
||||
Subscribe(SubscribeInfo, *string) error
|
||||
Unsubscribe(SubscribeInfo, *string) error
|
||||
Publish(PublishInfo, *string) error
|
||||
Publish(CgrEvent, *string) error
|
||||
ShowSubscribers(string, *map[string]*SubscriberData) error
|
||||
}
|
||||
|
||||
@@ -123,16 +119,16 @@ func (ps *PubSub) Unsubscribe(si SubscribeInfo, reply *string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ps *PubSub) Publish(pi PublishInfo, reply *string) error {
|
||||
func (ps *PubSub) Publish(evt CgrEvent, reply *string) error {
|
||||
ps.mux.Lock()
|
||||
defer ps.mux.Unlock()
|
||||
for key, subData := range ps.subscribers {
|
||||
if !subData.ExpTime.IsZero() && subData.ExpTime.Before(time.Now()) {
|
||||
delete(ps.subscribers, key)
|
||||
ps.removeSubscriber(key)
|
||||
continue // subscription expired, do not send event
|
||||
continue // subscription exevtred, do not send event
|
||||
}
|
||||
if subData.Filters == nil || !pi.Event.PassFilters(subData.Filters) {
|
||||
if subData.Filters == nil || !evt.PassFilters(subData.Filters) {
|
||||
continue // the event does not match the filters
|
||||
}
|
||||
split := utils.InfieldSplit(key)
|
||||
@@ -148,10 +144,10 @@ func (ps *PubSub) Publish(pi PublishInfo, reply *string) error {
|
||||
go func() {
|
||||
delay := utils.Fib()
|
||||
for i := 0; i < 5; i++ { // Loop so we can increase the success rate on best effort
|
||||
if _, err := ps.pubFunc(address, ps.ttlVerify, pi.Event); err == nil {
|
||||
if _, err := ps.pubFunc(address, ps.ttlVerify, evt); err == nil {
|
||||
break // Success, no need to reinterate
|
||||
} else if i == 4 { // Last iteration, syslog the warning
|
||||
Logger.Warning(fmt.Sprintf("<PubSub> Failed calling url: [%s], error: [%s], event type: %s", address, err.Error(), pi.Event["EventName"]))
|
||||
Logger.Warning(fmt.Sprintf("<PubSub> Failed calling url: [%s], error: [%s], event type: %s", address, err.Error(), evt["EventName"]))
|
||||
break
|
||||
}
|
||||
time.Sleep(delay())
|
||||
@@ -186,8 +182,8 @@ func (ps *ProxyPubSub) Subscribe(si SubscribeInfo, reply *string) error {
|
||||
func (ps *ProxyPubSub) Unsubscribe(si SubscribeInfo, reply *string) error {
|
||||
return ps.Client.Call("PubSubV1.Unsubscribe", si, reply)
|
||||
}
|
||||
func (ps *ProxyPubSub) Publish(pi PublishInfo, reply *string) error {
|
||||
return ps.Client.Call("PubSubV1.Publish", pi, reply)
|
||||
func (ps *ProxyPubSub) Publish(evt CgrEvent, reply *string) error {
|
||||
return ps.Client.Call("PubSubV1.Publish", evt, reply)
|
||||
}
|
||||
|
||||
func (ps *ProxyPubSub) ShowSubscribers(in string, reply *map[string]*SubscriberData) error {
|
||||
|
||||
@@ -133,9 +133,7 @@ func TestPublish(t *testing.T) {
|
||||
}
|
||||
m := make(map[string]string)
|
||||
m["EventFilter"] = "test"
|
||||
if err := ps.Publish(PublishInfo{
|
||||
Event: m,
|
||||
}, &r); err != nil {
|
||||
if err := ps.Publish(m, &r); err != nil {
|
||||
t.Error("Error publishing: ", err)
|
||||
}
|
||||
for i := 0; i < 1000; i++ { // wait for the theread to populate map
|
||||
@@ -166,9 +164,7 @@ func TestPublishExpired(t *testing.T) {
|
||||
}, &r); err != nil {
|
||||
t.Error("Error subscribing: ", err)
|
||||
}
|
||||
if err := ps.Publish(PublishInfo{
|
||||
Event: map[string]string{"EventFilter": "test"},
|
||||
}, &r); err != nil {
|
||||
if err := ps.Publish(map[string]string{"EventFilter": "test"}, &r); err != nil {
|
||||
t.Error("Error publishing: ", err)
|
||||
}
|
||||
if len(ps.subscribers) != 0 {
|
||||
@@ -196,9 +192,7 @@ func TestPublishExpiredSave(t *testing.T) {
|
||||
if err != nil || len(subs) != 1 {
|
||||
t.Error("Error saving subscribers: ", err, subs)
|
||||
}
|
||||
if err := ps.Publish(PublishInfo{
|
||||
Event: map[string]string{"EventFilter": "test"},
|
||||
}, &r); err != nil {
|
||||
if err := ps.Publish(map[string]string{"EventFilter": "test"}, &r); err != nil {
|
||||
t.Error("Error publishing: ", err)
|
||||
}
|
||||
subs, err = accountingStorage.GetSubscribers()
|
||||
|
||||
@@ -99,13 +99,13 @@ func TestGetDerivedMaxSessionTime(t *testing.T) {
|
||||
t.Error(err)
|
||||
//} else if rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND].Equal(rifsAccount.BalanceMap[utils.VOICE+OUTBOUND]) {
|
||||
// t.Errorf("Expected: %+v, received: %+v", rifsAccount.BalanceMap[utils.VOICE+OUTBOUND][0], rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0])
|
||||
} else if rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].Value != rifsAccount.BalanceMap[utils.VOICE+OUTBOUND][0].Value {
|
||||
t.Error("BalanceValue: ", rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
} else if rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != rifsAccount.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() {
|
||||
t.Error("BalanceValue: ", rifStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
if danStoredAcnt, err := accountingStorage.GetAccount(utils.ConcatenatedKey(utils.OUT, testTenant, "dan")); err != nil {
|
||||
t.Error(err)
|
||||
} else if danStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].Value != dansAccount.BalanceMap[utils.VOICE+OUTBOUND][0].Value {
|
||||
t.Error("BalanceValue: ", danStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].Value)
|
||||
} else if danStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() != dansAccount.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue() {
|
||||
t.Error("BalanceValue: ", danStoredAcnt.BalanceMap[utils.VOICE+OUTBOUND][0].GetValue())
|
||||
}
|
||||
var dcs utils.DerivedChargers
|
||||
attrs := &utils.AttrDerivedChargers{Tenant: testTenant, Category: "call", Direction: "*out", Account: "dan", Subject: "dan"}
|
||||
|
||||
@@ -126,7 +126,7 @@ func (lbcs LowestBalanceChainSorter) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (lbcs LowestBalanceChainSorter) Less(i, j int) bool {
|
||||
return lbcs[i].Value < lbcs[j].Value
|
||||
return lbcs[i].GetValue() < lbcs[j].GetValue()
|
||||
}
|
||||
|
||||
type HighestBalanceChainSorter []*Balance
|
||||
@@ -140,7 +140,7 @@ func (hbcs HighestBalanceChainSorter) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (hbcs HighestBalanceChainSorter) Less(i, j int) bool {
|
||||
return hbcs[i].Value > hbcs[j].Value
|
||||
return hbcs[i].GetValue() > hbcs[j].GetValue()
|
||||
}
|
||||
|
||||
type RandomBalanceChainSorter []*Balance
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestSharedPopBalanceByStrategyLow(t *testing.T) {
|
||||
if len(sbc) != 3 ||
|
||||
sbc[0].Value != 1.0 ||
|
||||
sbc[1].Value != 2.0 {
|
||||
t.Error("Error sorting balance chain: ", sbc[0].Value)
|
||||
t.Error("Error sorting balance chain: ", sbc[0].GetValue())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ type RatingStorage interface {
|
||||
SetRatingProfile(*RatingProfile) error
|
||||
GetRpAlias(string, bool) (string, error)
|
||||
SetRpAlias(string, string) error
|
||||
RemoveRpAliases([]*TenantRatingSubject) error
|
||||
RemoveRpAliases([]*TenantRatingSubject, bool) error
|
||||
GetRPAliases(string, string, bool) ([]string, error)
|
||||
GetDestination(string) (*Destination, error)
|
||||
SetDestination(*Destination) error
|
||||
@@ -69,7 +69,7 @@ type RatingStorage interface {
|
||||
GetAllActionPlans() (map[string]ActionPlans, error)
|
||||
GetAccAlias(string, bool) (string, error)
|
||||
SetAccAlias(string, string) error
|
||||
RemoveAccAliases([]*TenantAccount) error
|
||||
RemoveAccAliases([]*TenantAccount, bool) error
|
||||
GetAccountAliases(string, string, bool) ([]string, error)
|
||||
SetUser(*UserProfile) error
|
||||
GetUser(string) (*UserProfile, error)
|
||||
|
||||
@@ -342,18 +342,30 @@ func (ms *MapStorage) SetRpAlias(key, alias string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (err error) {
|
||||
for key, _ := range ms.dict {
|
||||
for _, tntRtSubj := range tenantRtSubjects {
|
||||
tenantPrfx := utils.RP_ALIAS_PREFIX + tntRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.RP_ALIAS_PREFIX) {
|
||||
alsSubj, err := ms.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntRtSubj.Subject == alsSubj {
|
||||
cache2go.RemKey(key)
|
||||
func (ms *MapStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
for key, value := range ms.dict {
|
||||
for _, tenantRtSubj := range tenantRtSubjects {
|
||||
tenantPrfx := utils.RP_ALIAS_PREFIX + tenantRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.RP_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tenantRtSubj.Subject == string(value) {
|
||||
delete(ms.dict, key)
|
||||
cache2go.RemKey(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.RP_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tenantRtSubj := range tenantRtSubjects {
|
||||
tenantPrfx := tenantRtSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tenantRtSubj.Subject == alias {
|
||||
delete(ms.dict, utils.RP_ALIAS_PREFIX+key)
|
||||
cache2go.RemKey(utils.RP_ALIAS_PREFIX + key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -408,12 +420,31 @@ func (ms *MapStorage) SetAccAlias(key, alias string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err error) {
|
||||
for key, value := range ms.dict {
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == string(value) {
|
||||
delete(ms.dict, key)
|
||||
func (ms *MapStorage) RemoveAccAliases(tenantAccounts []*TenantAccount, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
for key, value := range ms.dict {
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if strings.HasPrefix(key, utils.ACC_ALIAS_PREFIX) && len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == string(value) {
|
||||
delete(ms.dict, key)
|
||||
cache2go.RemKey(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.ACC_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) >= len(tenantPrfx) && key[:len(tenantPrfx)] == tenantPrfx && tntAcnt.Account == alias {
|
||||
delete(ms.dict, utils.ACC_ALIAS_PREFIX+key)
|
||||
cache2go.RemKey(utils.ACC_ALIAS_PREFIX + key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,28 +411,56 @@ func (rs *RedisStorage) SetRpAlias(key, alias string) (err error) {
|
||||
}
|
||||
|
||||
// Removes the aliases of a specific account, on a tenant
|
||||
func (rs *RedisStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject) (err error) {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.RP_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntRSubj := range tenantRtSubjects {
|
||||
tenantPrfx := tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
if tntRSubj.Subject != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.RP_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.RP_ALIAS_PREFIX + key)
|
||||
break
|
||||
func (rs *RedisStorage) RemoveRpAliases(tenantRtSubjects []*TenantRatingSubject, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
alsKeys, err := rs.db.Keys(utils.RP_ALIAS_PREFIX + "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range alsKeys {
|
||||
for _, tntRSubj := range tenantRtSubjects {
|
||||
tenantPrfx := utils.RP_ALIAS_PREFIX + tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || tenantPrfx != key[:len(tenantPrfx)] { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
alias, err := rs.GetRpAlias(key[len(utils.RP_ALIAS_PREFIX):], true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tntRSubj.Subject != alias {
|
||||
continue
|
||||
}
|
||||
cache2go.RemKey(key)
|
||||
if _, err = rs.db.Del(key); err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.RP_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntRSubj := range tenantRtSubjects {
|
||||
tenantPrfx := tntRSubj.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
if tntRSubj.Subject != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.RP_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.RP_ALIAS_PREFIX + key)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -506,26 +534,53 @@ func (rs *RedisStorage) SetAccAlias(key, alias string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) RemoveAccAliases(tenantAccounts []*TenantAccount) (err error) {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.ACC_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (rs *RedisStorage) RemoveAccAliases(tenantAccounts []*TenantAccount, skipCache bool) (err error) {
|
||||
if skipCache {
|
||||
alsKeys, err := rs.db.Keys(utils.ACC_ALIAS_PREFIX + "*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, key := range alsKeys {
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := utils.ACC_ALIAS_PREFIX + tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || tenantPrfx != key[:len(tenantPrfx)] { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
alias, err := rs.GetAccAlias(key[len(utils.ACC_ALIAS_PREFIX):], true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tntAcnt.Account != alias {
|
||||
continue
|
||||
}
|
||||
cache2go.RemKey(key)
|
||||
if _, err = rs.db.Del(key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
} else {
|
||||
alsMap, err := cache2go.GetAllEntries(utils.ACC_ALIAS_PREFIX)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for key, aliasInterface := range alsMap {
|
||||
alias := aliasInterface.Value().(string)
|
||||
for _, tntAcnt := range tenantAccounts {
|
||||
tenantPrfx := tntAcnt.Tenant + utils.CONCATENATED_KEY_SEP
|
||||
if len(key) < len(tenantPrfx) || !strings.HasPrefix(key, tenantPrfx) { // filter out the tenant for accounts
|
||||
continue
|
||||
}
|
||||
if tntAcnt.Account != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.ACC_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.ACC_ALIAS_PREFIX + key)
|
||||
}
|
||||
if tntAcnt.Account != alias {
|
||||
continue
|
||||
}
|
||||
if _, err = rs.db.Del(utils.ACC_ALIAS_PREFIX + key); err != nil {
|
||||
return err
|
||||
}
|
||||
cache2go.RemKey(utils.ACC_ALIAS_PREFIX + key)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestRemRSubjAliases(t *testing.T) {
|
||||
if err := ratingStorage.SetRpAlias(utils.RatingSubjectAliasKey("itsyscom.com", "2003"), "1001"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1001"}}); err != nil {
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1001"}}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if cgrAliases, err := ratingStorage.GetRPAliases("cgrates.org", "1001", true); err != nil {
|
||||
@@ -184,7 +184,7 @@ func TestStorageRpAliases(t *testing.T) {
|
||||
if _, err := ratingStorage.GetRpAlias("cgrates.org:1991", true); err != nil {
|
||||
t.Error("Alias not found after setting")
|
||||
}
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1991"}}); err != nil {
|
||||
if err := ratingStorage.RemoveRpAliases([]*TenantRatingSubject{&TenantRatingSubject{Tenant: "cgrates.org", Subject: "1991"}}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := ratingStorage.GetRpAlias("cgrates.org:1991", true); err == nil {
|
||||
@@ -225,7 +225,7 @@ func TestStorageAccAliases(t *testing.T) {
|
||||
if _, err := ratingStorage.GetAccAlias("cgrates.org:1991", true); err != nil {
|
||||
t.Error("Alias not found after setting")
|
||||
}
|
||||
if err := ratingStorage.RemoveAccAliases([]*TenantAccount{&TenantAccount{Tenant: "cgrates.org", Account: "1991"}}); err != nil {
|
||||
if err := ratingStorage.RemoveAccAliases([]*TenantAccount{&TenantAccount{Tenant: "cgrates.org", Account: "1991"}}, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := ratingStorage.GetAccAlias("cgrates.org:1991", true); err == nil {
|
||||
|
||||
@@ -1251,7 +1251,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
if verbose {
|
||||
log.Print("Rating Profile Aliases:")
|
||||
}
|
||||
if err := tpr.ratingStorage.RemoveRpAliases(tpr.dirtyRpAliases); err != nil {
|
||||
if err := tpr.ratingStorage.RemoveRpAliases(tpr.dirtyRpAliases, true); err != nil {
|
||||
return err
|
||||
}
|
||||
for key, alias := range tpr.rpAliases {
|
||||
@@ -1266,7 +1266,7 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
if verbose {
|
||||
log.Print("Account Aliases:")
|
||||
}
|
||||
if err := tpr.ratingStorage.RemoveAccAliases(tpr.dirtyAccAliases); err != nil {
|
||||
if err := tpr.ratingStorage.RemoveAccAliases(tpr.dirtyAccAliases, true); err != nil {
|
||||
return err
|
||||
}
|
||||
for key, alias := range tpr.accAliases {
|
||||
|
||||
@@ -49,7 +49,7 @@ func (uc *UnitsCounter) initBalances(ats []*ActionTrigger) {
|
||||
for _, a := range acs {
|
||||
if a.Balance != nil {
|
||||
b := a.Balance.Clone()
|
||||
b.Value = 0
|
||||
b.SetValue(0)
|
||||
if !uc.Balances.HasBalance(b) {
|
||||
uc.Balances = append(uc.Balances, b)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
|
||||
if x, err := cache2go.GetCached(utils.DESTINATION_PREFIX + p); err == nil {
|
||||
destIds := x.(map[interface{}]struct{})
|
||||
if _, found := destIds[mb.DestinationIds]; found {
|
||||
mb.Value += amount
|
||||
mb.AddValue(amount)
|
||||
counted = true
|
||||
break
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (uc *UnitsCounter) addUnits(amount float64, prefix string) {
|
||||
if !counted {
|
||||
// use general balance
|
||||
b := uc.GetGeneralBalance()
|
||||
b.Value += amount
|
||||
b.AddValue(amount)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestUnitsCounterAddBalanceExists(t *testing.T) {
|
||||
Balances: BalanceChain{&Balance{Value: 1}, &Balance{Value: 10, Weight: 20, DestinationIds: "NAT"}, &Balance{Weight: 10, DestinationIds: "RET"}},
|
||||
}
|
||||
uc.addUnits(5, "0723")
|
||||
if len(uc.Balances) != 3 || uc.Balances[1].Value != 15 {
|
||||
if len(uc.Balances) != 3 || uc.Balances[1].GetValue() != 15 {
|
||||
t.Error("Error adding minute bucket!")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user