mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
fix build and test on lcr qos sorter
This commit is contained in:
@@ -80,7 +80,7 @@ func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) e
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
}
|
||||
_, err := engine.AccLock.Guard(engine.ACTION_TIMING_PREFIX, func() (float64, error) {
|
||||
_, err := engine.AccLock.Guard(func() (float64, error) {
|
||||
ats, err := self.AccountDb.GetActionTimings(attrs.ActionPlanId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -92,7 +92,7 @@ func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) e
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
})
|
||||
}, engine.ACTION_TIMING_PREFIX)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func (self *ApierV1) RemAccountActionTriggers(attrs AttrRemAcntActionTriggers, r
|
||||
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
|
||||
}
|
||||
balanceId := utils.AccountKey(attrs.Tenant, attrs.Account, attrs.Direction)
|
||||
_, err := engine.AccLock.Guard(balanceId, func() (float64, error) {
|
||||
_, err := engine.AccLock.Guard(func() (float64, error) {
|
||||
ub, err := self.AccountDb.GetAccount(balanceId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -150,7 +150,7 @@ func (self *ApierV1) RemAccountActionTriggers(attrs AttrRemAcntActionTriggers, r
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
})
|
||||
}, balanceId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func (self *ApierV1) SetAccount(attr AttrSetAccount, reply *string) error {
|
||||
balanceId := utils.AccountKey(attr.Tenant, attr.Account, attr.Direction)
|
||||
var ub *engine.Account
|
||||
var ats engine.ActionPlan
|
||||
_, err := engine.AccLock.Guard(balanceId, func() (float64, error) {
|
||||
_, err := engine.AccLock.Guard(func() (float64, error) {
|
||||
if bal, _ := self.AccountDb.GetAccount(balanceId); bal != nil {
|
||||
ub = bal
|
||||
} else { // Not found in db, create it here
|
||||
@@ -199,17 +199,17 @@ func (self *ApierV1) SetAccount(attr AttrSetAccount, reply *string) error {
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
})
|
||||
}, balanceId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
if len(ats) != 0 {
|
||||
_, err := engine.AccLock.Guard(engine.ACTION_TIMING_PREFIX, func() (float64, error) { // ToDo: Try locking it above on read somehow
|
||||
_, err := engine.AccLock.Guard(func() (float64, error) { // ToDo: Try locking it above on read somehow
|
||||
if err := self.AccountDb.SetActionTimings(attr.ActionPlanId, ats); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
})
|
||||
}, engine.ACTION_TIMING_PREFIX)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
|
||||
@@ -588,7 +588,7 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string
|
||||
}
|
||||
|
||||
tag := utils.AccountKey(attr.Tenant, attr.Account, attr.BalanceDirection)
|
||||
_, err = engine.AccLock.Guard(tag, func() (float64, error) {
|
||||
_, err = engine.AccLock.Guard(func() (float64, error) {
|
||||
userBalance, err := self.AccountDb.GetAccount(tag)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -600,7 +600,7 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
})
|
||||
}, tag)
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
@@ -658,7 +658,7 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply
|
||||
}
|
||||
}
|
||||
accID := utils.AccountKey(attr.Tenant, attr.Account, attr.Direction)
|
||||
_, err := engine.AccLock.Guard(accID, func() (float64, error) {
|
||||
_, err := engine.AccLock.Guard(func() (float64, error) {
|
||||
acc, err := self.AccountDb.GetAccount(accID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -670,7 +670,7 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
})
|
||||
}, accID)
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
@@ -685,12 +685,12 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str
|
||||
return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "TPid")
|
||||
}
|
||||
dbReader := engine.NewDbReader(self.StorDb, self.RatingDb, self.AccountDb, attrs.TPid)
|
||||
if _, err := engine.AccLock.Guard(attrs.KeyId(), func() (float64, error) {
|
||||
if _, err := engine.AccLock.Guard(func() (float64, error) {
|
||||
if err := dbReader.LoadAccountActionsFiltered(&attrs); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
}); err != nil {
|
||||
}, attrs.KeyId()); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
// ToDo: Get the action keys loaded by dbReader so we reload only these in cache
|
||||
|
||||
@@ -73,12 +73,12 @@ func (self *ApierV2) LoadAccountActions(attrs AttrLoadAccountActions, reply *str
|
||||
tpAa := &utils.TPAccountActions{TPid: attrs.TPid}
|
||||
tpAa.SetAccountActionsId(attrs.AccountActionsId)
|
||||
|
||||
if _, err := engine.AccLock.Guard(attrs.AccountActionsId, func() (float64, error) {
|
||||
if _, err := engine.AccLock.Guard(func() (float64, error) {
|
||||
if err := dbReader.LoadAccountActionsFiltered(tpAa); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 0, nil
|
||||
}); err != nil {
|
||||
}, attrs.AccountActionsId); err != nil {
|
||||
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
|
||||
}
|
||||
// ToDo: Get the action keys loaded by dbReader so we reload only these in cache
|
||||
|
||||
@@ -229,7 +229,13 @@ func (qoss QOSSorter) Swap(i, j int) {
|
||||
}
|
||||
|
||||
func (qoss QOSSorter) Less(i, j int) bool {
|
||||
//for _, param := range qoss[i].qosSortParams
|
||||
//qoss[i].Cost > qoss[j].Cost
|
||||
for _, param := range qoss[i].qosSortParams {
|
||||
if qoss[i].QOS[param] < qoss[j].QOS[param] {
|
||||
return true
|
||||
}
|
||||
if qoss[i].QOS[param] == qoss[j].QOS[param] {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -17,3 +17,72 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package engine
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLcrQOSSorter(t *testing.T) {
|
||||
s := QOSSorter{
|
||||
&LCRSupplierCost{
|
||||
QOS: map[string]float64{
|
||||
"ASR": 3,
|
||||
"ACD": 3,
|
||||
},
|
||||
qosSortParams: []string{ASR, ACD},
|
||||
},
|
||||
&LCRSupplierCost{
|
||||
QOS: map[string]float64{
|
||||
"ASR": 1,
|
||||
"ACD": 1,
|
||||
},
|
||||
qosSortParams: []string{ASR, ACD},
|
||||
},
|
||||
&LCRSupplierCost{
|
||||
QOS: map[string]float64{
|
||||
"ASR": 2,
|
||||
"ACD": 2,
|
||||
},
|
||||
qosSortParams: []string{ASR, ACD},
|
||||
},
|
||||
}
|
||||
sort.Sort(s)
|
||||
if s[0].QOS[ASR] != 1 ||
|
||||
s[1].QOS[ASR] != 2 ||
|
||||
s[2].QOS[ASR] != 3 {
|
||||
t.Error("Lcr qos sort failed: ", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLcrQOSSorterOACD(t *testing.T) {
|
||||
s := QOSSorter{
|
||||
&LCRSupplierCost{
|
||||
QOS: map[string]float64{
|
||||
"ASR": 1,
|
||||
"ACD": 3,
|
||||
},
|
||||
qosSortParams: []string{ASR, ACD},
|
||||
},
|
||||
&LCRSupplierCost{
|
||||
QOS: map[string]float64{
|
||||
"ASR": 1,
|
||||
"ACD": 1,
|
||||
},
|
||||
qosSortParams: []string{ASR, ACD},
|
||||
},
|
||||
&LCRSupplierCost{
|
||||
QOS: map[string]float64{
|
||||
"ASR": 1,
|
||||
"ACD": 2,
|
||||
},
|
||||
qosSortParams: []string{ASR, ACD},
|
||||
},
|
||||
}
|
||||
sort.Sort(s)
|
||||
if s[0].QOS[ACD] != 1 ||
|
||||
s[1].QOS[ACD] != 2 ||
|
||||
s[2].QOS[ACD] != 3 {
|
||||
t.Error("Lcr qos sort failed: ", s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,10 +108,10 @@ func (s *Scheduler) LoadActionTimings(storage engine.AccountingStorage) {
|
||||
newAts = append(newAts, at)
|
||||
}
|
||||
if toBeSaved {
|
||||
engine.AccLock.Guard(engine.ACTION_TIMING_PREFIX, func() (float64, error) {
|
||||
engine.AccLock.Guard(func() (float64, error) {
|
||||
storage.SetActionTimings(key, newAts)
|
||||
return 0, nil
|
||||
})
|
||||
}, engine.ACTION_TIMING_PREFIX)
|
||||
}
|
||||
}
|
||||
sort.Sort(s.queue)
|
||||
|
||||
Reference in New Issue
Block a user