Merging master, fixing conflicts

This commit is contained in:
DanB
2016-01-06 14:52:29 +01:00
26 changed files with 618 additions and 88 deletions

View File

@@ -257,7 +257,6 @@ func cdrLogAction(acc *Account, sq *StatsQueueTriggered, a *Action, acs Actions)
return err
}
}
b, _ := json.Marshal(cdrs)
a.ExpirationString = string(b) // testing purpose only
return

View File

@@ -172,6 +172,7 @@ type AttrAddAlias struct {
Overwrite bool
}
// SetAlias will set/overwrite specified alias
func (am *AliasHandler) SetAlias(attr *AttrAddAlias, reply *string) error {
am.mu.Lock()
defer am.mu.Unlock()

View File

@@ -743,19 +743,39 @@ func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) {
func (cd *CallDescriptor) RefundIncrements() (left float64, err error) {
cd.account = nil // make sure it's not cached
accountsCache := make(map[string]*Account)
// get account list for locking
// all must be locked in order to use cache
accMap := make(map[string]struct{})
var accountIDs []string
for _, increment := range cd.Increments {
account, found := accountsCache[increment.BalanceInfo.AccountId]
if !found {
if acc, err := accountingStorage.GetAccount(increment.BalanceInfo.AccountId); err == nil && acc != nil {
account = acc
accountsCache[increment.BalanceInfo.AccountId] = account
defer accountingStorage.SetAccount(account)
}
}
account.refundIncrement(increment, cd, true)
accMap[increment.BalanceInfo.AccountId] = struct{}{}
}
return 0.0, err
for key := range accMap {
accountIDs = append(accountIDs, key)
}
// start increment refunding loop
Guardian.Guard(func() (interface{}, error) {
accountsCache := make(map[string]*Account)
for _, increment := range cd.Increments {
account, found := accountsCache[increment.BalanceInfo.AccountId]
if !found {
if acc, err := accountingStorage.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
defer accountingStorage.SetAccount(account)
}
}
if account == nil {
utils.Logger.Warning(fmt.Sprintf("Could not get the account to be refunded: %s", increment.BalanceInfo.AccountId))
continue
}
//utils.Logger.Info(fmt.Sprintf("Refunding increment %+v", increment))
account.refundIncrement(increment, cd, true)
}
return 0, err
}, 0, accountIDs...)
return 0, err
}
func (cd *CallDescriptor) FlushCache() (err error) {

View File

@@ -220,10 +220,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err
if rs.Bal != nil {
*reply, err = rs.callMethod(arg, "Responder.RefundIncrements")
} else {
r, e := Guardian.Guard(func() (interface{}, error) {
return arg.RefundIncrements()
}, 0, arg.GetAccountKey())
*reply, err = r.(float64), e
*reply, err = arg.RefundIncrements()
}
rs.getCache().Cache(cacheKey, &cache2go.CacheItem{Value: reply, Err: err})
return

View File

@@ -246,47 +246,46 @@ func TestUnitCountersCountAllVoiceDestinationEvent(t *testing.T) {
}
}
/*
func TestUnitCountersResetCounterById(t *testing.T) {
a := &Account{
ActionTriggers: ActionTriggers{
&ActionTrigger{
ID: "TestTR1",
UniqueID: "TestTR1",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
ID: "TestTR11",
UniqueID: "TestTR11",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.MONETARY,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
ID: "TestTR2",
UniqueID: "TestTR2",
ThresholdType: utils.TRIGGER_MAX_EVENT_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
ID: "TestTR3",
UniqueID: "TestTR3",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.VOICE,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
ID: "TestTR4",
UniqueID: "TestTR4",
ThresholdType: utils.TRIGGER_MAX_BALANCE_COUNTER,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
BalanceWeight: 10,
},
&ActionTrigger{
ID: "TestTR5",
UniqueID: "TestTR5",
ThresholdType: utils.TRIGGER_MAX_BALANCE,
BalanceType: utils.SMS,
BalanceDirections: utils.NewStringMap(utils.OUT, utils.IN),
@@ -328,4 +327,3 @@ func TestUnitCountersResetCounterById(t *testing.T) {
t.Errorf("Error Initializing adding unit counters: %v", len(a.UnitCounters))
}
}
*/