Suppliers *least_cost ignoring suppliers with empty cost information

This commit is contained in:
DanB
2017-12-02 09:42:40 +01:00
parent 693247fde7
commit 5395581bb5
3 changed files with 14 additions and 8 deletions

View File

@@ -44,10 +44,10 @@ var sTestsSupplierSV1 = []func(t *testing.T){
testV1SplSLoadConfig,
testV1SplSInitDataDb,
testV1SplSResetStorDb,
//testV1SplSStartEngine,
testV1SplSStartEngine,
testV1SplSRpcConn,
testV1SplSFromFolder,
//testV1SplSGetWeightSuppliers,
testV1SplSGetWeightSuppliers,
testV1SplSGetLeastCostSuppliers,
testV1SplSStopEngine,
}

View File

@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"fmt"
"github.com/cgrates/cgrates/utils"
)
@@ -37,17 +39,22 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string,
suppls []*Supplier, ev *SupplierEvent) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: lcs.sorting,
SortedSuppliers: make([]*SortedSupplier, len(suppls))}
for i, s := range suppls {
SortedSuppliers: make([]*SortedSupplier, 0)}
for _, s := range suppls {
ec, err := lcs.spS.costForEvent(ev, s.AccountIDs, s.RatingPlanIDs)
if err != nil {
return nil, err
} else if ec == nil {
utils.Logger.Warning(
fmt.Sprintf("<%s> profile: %s ignoring supplier with ID: %s, missing cost information",
utils.SupplierS, prflID, s.ID))
continue
}
sortedSuppls.SortedSuppliers[i] = &SortedSupplier{
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{
SupplierID: s.ID,
SortingData: map[string]interface{}{
utils.Weight: s.Weight,
utils.Cost: ec.GetCost()}}
utils.Cost: ec.GetCost()}})
}
sortedSuppls.SortCost()
return

View File

@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"errors"
"fmt"
"sort"
"time"
@@ -229,7 +228,7 @@ func (spS *SupplierService) costForEvent(ev *SupplierEvent,
}
return NewEventCostFromCallCost(cc, "", ""), nil
}
return nil, errors.New("no cost found")
return
}
// statMetrics will query a list of statIDs and return composed metric values