mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 11:06:25 +05:00
Supplier.Strategy -> Sorting
This commit is contained in:
@@ -77,8 +77,8 @@ type LCRProfile struct {
|
||||
ID string // LCR Profile ID
|
||||
FilterIDs []string
|
||||
ActivationInterval *utils.ActivationInterval // Activation interval
|
||||
Strategy string // LCR Strategy used when computing
|
||||
StrategyParams []string
|
||||
Sorting string // Sorting strategy
|
||||
SortingParams []string
|
||||
Suppliers LCRSuppliers
|
||||
Blocker bool // do not process further profiles after this one
|
||||
Weight float64
|
||||
@@ -109,7 +109,7 @@ func NewLCRService(dm *DataManager, timezone string,
|
||||
statS: statS,
|
||||
indexedFields: indexedFields}
|
||||
|
||||
if lcrS.strategyDispatcher, err = NewSupplierStrategyDispatcher(lcrS); err != nil {
|
||||
if lcrS.sortDispatcher, err = NewSupplierSortDispatcher(lcrS); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
@@ -123,7 +123,7 @@ type LCRService struct {
|
||||
indexedFields []string
|
||||
resourceS,
|
||||
statS rpcclient.RpcClientConnection
|
||||
strategyDispatcher SupplierStrategyDispatcher
|
||||
sortDispatcher SupplierSortDispatcher
|
||||
}
|
||||
|
||||
// ListenAndServe will initialize the service
|
||||
@@ -229,7 +229,7 @@ func (lcrS *LCRService) supliersForEvent(ev *LCREvent) (lss LCRSuppliers, err er
|
||||
}
|
||||
lss = append(lss, s)
|
||||
}
|
||||
if err = lcrS.strategyDispatcher.OrderSuppliers(lcrPrfl.Strategy,
|
||||
if err = lcrS.sortDispatcher.SortSuppliers(lcrPrfl.Sorting,
|
||||
lcrPrfl.Suppliers); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ import (
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// NewSupplierStrategyDispatcher constructs SupplierStrategyDispatcher
|
||||
func NewSupplierStrategyDispatcher(lcrS *LCRService) (ssd SupplierStrategyDispatcher, err error) {
|
||||
ssd = make(map[string]SuppliersStrategy)
|
||||
// NewSupplierSortDispatcher constructs SupplierSortDispatcher
|
||||
func NewSupplierSortDispatcher(lcrS *LCRService) (ssd SupplierSortDispatcher, err error) {
|
||||
ssd = make(map[string]SuppliersSorting)
|
||||
ssd[utils.MetaStatic] = new(StaticStrategy)
|
||||
ssd[utils.MetaLeastCost] = NewLeastCostStrategy(lcrS)
|
||||
return
|
||||
@@ -34,18 +34,18 @@ func NewSupplierStrategyDispatcher(lcrS *LCRService) (ssd SupplierStrategyDispat
|
||||
|
||||
// SupplierStrategyHandler will initialize strategies
|
||||
// and dispatch requests to them
|
||||
type SupplierStrategyDispatcher map[string]SuppliersStrategy
|
||||
type SupplierSortDispatcher map[string]SuppliersSorting
|
||||
|
||||
func (ssd SupplierStrategyDispatcher) OrderSuppliers(strategy string, suppls LCRSuppliers) (err error) {
|
||||
func (ssd SupplierSortDispatcher) SortSuppliers(strategy string, suppls LCRSuppliers) (err error) {
|
||||
sd, has := ssd[strategy]
|
||||
if !has {
|
||||
return fmt.Errorf("unsupported sort strategy: %s", strategy)
|
||||
}
|
||||
return sd.OrderSuppliers(suppls)
|
||||
return sd.SortSuppliers(suppls)
|
||||
}
|
||||
|
||||
type SuppliersStrategy interface {
|
||||
OrderSuppliers(LCRSuppliers) error
|
||||
type SuppliersSorting interface {
|
||||
SortSuppliers(LCRSuppliers) error
|
||||
}
|
||||
|
||||
// NewLeastCostStrategy constructs LeastCostStrategy
|
||||
@@ -58,7 +58,7 @@ type LeastCostStrategy struct {
|
||||
lcrS *LCRService
|
||||
}
|
||||
|
||||
func (lcs *LeastCostStrategy) OrderSuppliers(suppls LCRSuppliers) (err error) {
|
||||
func (lcs *LeastCostStrategy) SortSuppliers(suppls LCRSuppliers) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ func (lcs *LeastCostStrategy) OrderSuppliers(suppls LCRSuppliers) (err error) {
|
||||
type StaticStrategy struct {
|
||||
}
|
||||
|
||||
func (ss *StaticStrategy) OrderSuppliers(suppls LCRSuppliers) (err error) {
|
||||
func (ss *StaticStrategy) SortSuppliers(suppls LCRSuppliers) (err error) {
|
||||
suppls.Sort()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2530,12 +2530,12 @@ func APItoLCRProfile(tpTH *utils.TPLCR, timezone string) (th *LCRProfile, err er
|
||||
th = &LCRProfile{
|
||||
Tenant: tpTH.Tenant,
|
||||
ID: tpTH.ID,
|
||||
Strategy: tpTH.Strategy,
|
||||
Sorting: tpTH.Strategy,
|
||||
Weight: tpTH.Weight,
|
||||
Suppliers: make([]*LCRSupplier, len(tpTH.Suppliers)),
|
||||
}
|
||||
for _, stp := range tpTH.StrategyParams {
|
||||
th.StrategyParams = append(th.StrategyParams, stp)
|
||||
th.SortingParams = append(th.SortingParams, stp)
|
||||
}
|
||||
for _, fli := range tpTH.FilterIDs {
|
||||
th.FilterIDs = append(th.FilterIDs, fli)
|
||||
|
||||
Reference in New Issue
Block a user