From 4dcd47577e1f041caf2bbe5538d985e9d4363dbc Mon Sep 17 00:00:00 2001 From: DanB Date: Sun, 26 Nov 2017 18:33:44 +0100 Subject: [PATCH] Supplier.Strategy -> Sorting --- engine/lcrs.go | 10 +++++----- engine/liblcrs.go | 20 ++++++++++---------- engine/model_helpers.go | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/engine/lcrs.go b/engine/lcrs.go index 36e9f9828..13ea3da4a 100644 --- a/engine/lcrs.go +++ b/engine/lcrs.go @@ -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 } diff --git a/engine/liblcrs.go b/engine/liblcrs.go index 05bc6a2f9..5f1f76678 100644 --- a/engine/liblcrs.go +++ b/engine/liblcrs.go @@ -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 } diff --git a/engine/model_helpers.go b/engine/model_helpers.go index cddb0ab62..ee549bb81 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -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)