mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
Update RouteS to consider minutes from balances
This commit is contained in:
committed by
Dan Christian Bogos
parent
51b4b7f6d1
commit
9256e9065e
@@ -315,6 +315,7 @@ func (rs *Responder) GetMaxSessionTime(arg *CallDescriptorWithArgDispatcher, rep
|
||||
|
||||
func (rs *Responder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs,
|
||||
reply *map[string]interface{}) (err error) {
|
||||
var maxDur time.Duration
|
||||
for _, anctID := range arg.AccountIDs {
|
||||
cd := &CallDescriptor{
|
||||
Category: utils.MetaRoutes,
|
||||
@@ -326,11 +327,11 @@ func (rs *Responder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnA
|
||||
TimeEnd: arg.SetupTime.Add(arg.Usage),
|
||||
DurationIndex: arg.Usage,
|
||||
}
|
||||
if maxDur, err := cd.GetMaxSessionDuration(); err != nil {
|
||||
if maxDur, err = cd.GetMaxSessionDuration(); err != nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> ignoring cost for account: %s, err: %s",
|
||||
utils.Responder, anctID, err.Error()))
|
||||
} else if maxDur >= arg.Usage {
|
||||
} else {
|
||||
*reply = map[string]interface{}{
|
||||
utils.CapMaxUsage: maxDur,
|
||||
utils.Cost: 0.0,
|
||||
|
||||
@@ -41,11 +41,11 @@ func (hcs *HightCostSorter) SortRoutes(prflID string, routes []*Route,
|
||||
Sorting: hcs.sorting,
|
||||
SortedRoutes: make([]*SortedRoute, 0)}
|
||||
for _, route := range routes {
|
||||
if len(route.RatingPlanIDs) == 0 {
|
||||
if len(route.RatingPlanIDs) == 0 && len(route.AccountIDs) == 0 {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> supplier: <%s> - empty RatingPlanIDs",
|
||||
fmt.Sprintf("<%s> supplier: <%s> - empty RatingPlanIDs or AccountIDs",
|
||||
utils.RouteS, route.ID))
|
||||
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs")
|
||||
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs or AccountIDs")
|
||||
}
|
||||
if srtSpl, pass, err := hcs.rS.populateSortingData(ev, route, extraOpts); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -41,11 +41,11 @@ func (lcs *LeastCostSorter) SortRoutes(prflID string, routes []*Route,
|
||||
Sorting: lcs.sorting,
|
||||
SortedRoutes: make([]*SortedRoute, 0)}
|
||||
for _, s := range routes {
|
||||
if len(s.RatingPlanIDs) == 0 {
|
||||
if len(s.RatingPlanIDs) == 0 && len(s.AccountIDs) == 0 {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> supplier: <%s> - empty RatingPlanIDs",
|
||||
fmt.Sprintf("<%s> supplier: <%s> - empty RatingPlanIDs or AccountIDs",
|
||||
utils.RouteS, s.ID))
|
||||
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs")
|
||||
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs or AccountIDs")
|
||||
}
|
||||
if srtSpl, pass, err := lcs.rS.populateSortingData(ev, s, extraOpts); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -244,7 +244,9 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent,
|
||||
usage = time.Duration(1 * time.Minute)
|
||||
err = nil
|
||||
}
|
||||
var rplyVals map[string]interface{}
|
||||
var accountMaxUsage time.Duration
|
||||
var acntCost map[string]interface{}
|
||||
var initialUsage time.Duration
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().RALsConns, nil, utils.ResponderGetMaxSessionTimeOnAccounts,
|
||||
&utils.GetMaxSessionTimeOnAccountsArgs{
|
||||
Tenant: ev.Tenant,
|
||||
@@ -253,28 +255,47 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent,
|
||||
SetupTime: sTime,
|
||||
Usage: usage,
|
||||
AccountIDs: acntIDs,
|
||||
}, &rplyVals); err != nil {
|
||||
}, &acntCost); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range rplyVals { // do not overwrite the return map
|
||||
costData[k] = v
|
||||
if ifaceMaxUsage, has := acntCost[utils.CapMaxUsage]; has {
|
||||
if accountMaxUsage, err = utils.IfaceAsDuration(ifaceMaxUsage); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if usage > accountMaxUsage {
|
||||
// remain usage needs to be covered by rating plans
|
||||
if len(rpIDs) == 0 {
|
||||
return nil, fmt.Errorf("no rating plans defined for remaining usage")
|
||||
}
|
||||
// update the setup time and the usage
|
||||
sTime = sTime.Add(accountMaxUsage)
|
||||
initialUsage = usage
|
||||
usage = usage - accountMaxUsage
|
||||
}
|
||||
for k, v := range acntCost { // update the costData with the infos from AccountS
|
||||
costData[k] = v
|
||||
}
|
||||
}
|
||||
rplyVals = make(map[string]interface{}) // reset the map
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().RALsConns, nil, utils.ResponderGetCostOnRatingPlans,
|
||||
&utils.GetCostOnRatingPlansArgs{
|
||||
Tenant: ev.Tenant,
|
||||
Account: acnt,
|
||||
Subject: subj,
|
||||
Destination: dst,
|
||||
SetupTime: sTime,
|
||||
Usage: usage,
|
||||
RatingPlanIDs: rpIDs,
|
||||
}, &rplyVals); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range rplyVals {
|
||||
costData[k] = v
|
||||
|
||||
if accountMaxUsage == 0 || accountMaxUsage < initialUsage {
|
||||
var rpCost map[string]interface{}
|
||||
if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().RALsConns, nil, utils.ResponderGetCostOnRatingPlans,
|
||||
&utils.GetCostOnRatingPlansArgs{
|
||||
Tenant: ev.Tenant,
|
||||
Account: acnt,
|
||||
Subject: subj,
|
||||
Destination: dst,
|
||||
SetupTime: sTime,
|
||||
Usage: usage,
|
||||
RatingPlanIDs: rpIDs,
|
||||
}, &rpCost); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range rpCost { // do not overwrite the return map
|
||||
costData[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -396,6 +417,7 @@ func (rpS *RouteService) populateSortingData(ev *utils.CGREvent, route *Route,
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> ignoring route with ID: %s, missing cost information",
|
||||
utils.RouteS, route.ID))
|
||||
return nil, false, nil
|
||||
} else {
|
||||
if extraOpts.maxCost != 0 &&
|
||||
costData[utils.Cost].(float64) > extraOpts.maxCost {
|
||||
|
||||
Reference in New Issue
Block a user