Add MaxCost for SupplierSv1.GetSuppliers

This commit is contained in:
TeoV
2018-03-29 07:55:22 -04:00
committed by Dan Christian Bogos
parent fe9a9c5de4
commit e6abae9fd4
3 changed files with 19 additions and 0 deletions

View File

@@ -165,6 +165,7 @@ func testV1SplSGetWeightSuppliers(t *testing.T) {
func testV1SplSGetLeastCostSuppliers(t *testing.T) {
ev := &engine.ArgsGetSuppliers{
//MaxCost: 0.020,
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testV1SplSGetLeastCostSuppliers",

View File

@@ -41,6 +41,7 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string,
Sorting: lcs.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
for _, s := range suppls {
utils.Logger.Debug(fmt.Sprintf("s : %+v \n", s))
costData, err := lcs.spS.costForEvent(ev, s.AccountIDs, s.RatingPlanIDs)
if err != nil {
return nil, err
@@ -50,6 +51,14 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string,
utils.SupplierS, prflID, s.ID))
continue
}
cost, err := utils.IfaceAsFloat64(costData[utils.Cost])
if err != nil {
return nil, err
}
utils.Logger.Debug(fmt.Sprintf("maxCost : %+v and cost costData[utils.Cost] %+v", float64(*lcs.spS.maxCost), cost))
if cost > float64(*lcs.spS.maxCost) {
continue
}
srtData := map[string]interface{}{
utils.Weight: s.Weight,
}
@@ -61,6 +70,10 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string,
SortingData: srtData,
SupplierParameters: s.SupplierParameters})
}
utils.Logger.Debug(fmt.Sprintf("sortedSuppls : %+v \n", sortedSuppls))
if len(sortedSuppls.SortedSuppliers) == 0 {
return nil, utils.ErrNotFound
}
sortedSuppls.SortCost()
return
}

View File

@@ -92,6 +92,7 @@ type SupplierService struct {
filterS *FilterS
stringIndexedFields *[]string
prefixIndexedFields *[]string
maxCost *float64
resourceS,
statS rpcclient.RpcClientConnection
sorter SupplierSortDispatcher
@@ -265,6 +266,8 @@ func (spS *SupplierService) resourceUsage(resIDs []string) (tUsage float64, err
// for event based on filters and sorting algorithms
func (spS *SupplierService) sortedSuppliersForEvent(args *ArgsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
var suppPrfls SupplierProfiles
utils.Logger.Debug(fmt.Sprintf("args.maxcost %+v", args.MaxCost))
spS.maxCost = utils.Float64Pointer(args.MaxCost)
if suppPrfls, err = spS.matchingSupplierProfilesForEvent(&args.CGREvent); err != nil {
return
} else if len(suppPrfls) == 0 {
@@ -301,6 +304,8 @@ func (spS *SupplierService) sortedSuppliersForEvent(args *ArgsGetSuppliers) (sor
}
type ArgsGetSuppliers struct {
IgnoreError bool
MaxCost float64
utils.CGREvent
utils.Paginator
}