Added all Responder Methods to DispatacherS.Fixes #2954

This commit is contained in:
Trial97
2021-05-19 10:49:44 +03:00
committed by Dan Christian Bogos
parent 380f4ef44e
commit fd5b8774ab
13 changed files with 77 additions and 27 deletions

View File

@@ -101,6 +101,8 @@ type ResponderInterface interface {
RefundRounding(arg *engine.CallDescriptorWithArgDispatcher, reply *float64) (err error)
GetMaxSessionTime(arg *engine.CallDescriptorWithArgDispatcher, reply *time.Duration) (err error)
Shutdown(arg *utils.TenantWithArgDispatcher, reply *string) (err error)
GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]interface{}) (err error)
GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]interface{}) (err error)
Ping(ign *utils.CGREventWithArgDispatcher, reply *string) error
}

View File

@@ -535,6 +535,13 @@ func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithArgDispatcher, rep
return dS.dS.ResponderShutdown(args, reply)
}
func (dS *DispatcherResponder) GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]interface{}) (err error) {
return dS.dS.ResponderGetCostOnRatingPlans(arg, reply)
}
func (dS *DispatcherResponder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]interface{}) (err error) {
return dS.dS.ResponderGetMaxSessionTimeOnAccounts(arg, reply)
}
// Ping used to determinate if component is active
func (dS *DispatcherResponder) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.ResponderPing(args, reply)

View File

@@ -186,3 +186,40 @@ func (dS *DispatcherService) ResponderShutdown(args *utils.TenantWithArgDispatch
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaResponder,
routeID, utils.ResponderShutdown, args, reply)
}
func (dS *DispatcherService) ResponderGetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]interface{}) (err error) {
tnt := utils.FirstNonEmpty(arg.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if arg.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
}
if err = dS.authorize(utils.ResponderShutdown, tnt,
arg.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
var routeID *string
if arg.ArgDispatcher != nil {
routeID = arg.ArgDispatcher.RouteID
}
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaResponder,
routeID, utils.ResponderShutdown, arg, reply)
}
func (dS *DispatcherService) ResponderGetMaxSessionTimeOnAccounts(args *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]interface{}) (err error) {
tnt := utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
}
if err = dS.authorize(utils.ResponderShutdown, tnt,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
var routeID *string
if args.ArgDispatcher != nil {
routeID = args.ArgDispatcher.RouteID
}
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaResponder,
routeID, utils.ResponderShutdown, args, reply)
}

View File

@@ -194,7 +194,7 @@ type SupplierWithParams struct {
// SuppliersSorter is the interface which needs to be implemented by supplier sorters
type SuppliersSorter interface {
SortSuppliers(string, []*Supplier, *utils.CGREvent, *optsGetSuppliers) (*SortedSuppliers, error)
SortSuppliers(string, []*Supplier, *utils.CGREvent, *optsGetSuppliers, *utils.ArgDispatcher) (*SortedSuppliers, error)
}
// NewSupplierSortDispatcher constructs SupplierSortDispatcher
@@ -215,10 +215,10 @@ func NewSupplierSortDispatcher(lcrS *SupplierService) (ssd SupplierSortDispatche
type SupplierSortDispatcher map[string]SuppliersSorter
func (ssd SupplierSortDispatcher) SortSuppliers(prflID, strategy string,
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sd, has := ssd[strategy]
if !has {
return nil, fmt.Errorf("unsupported sorting strategy: %s", strategy)
}
return sd.SortSuppliers(prflID, suppls, suplEv, extraOpts)
return sd.SortSuppliers(prflID, suppls, suplEv, extraOpts, argDsp)
}

View File

@@ -36,7 +36,7 @@ type HightCostSorter struct {
}
func (hcs *HightCostSorter) SortSuppliers(prflID string, suppls []*Supplier,
ev *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
ev *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: hcs.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
@@ -47,7 +47,7 @@ func (hcs *HightCostSorter) SortSuppliers(prflID string, suppls []*Supplier,
utils.SupplierS, s.ID))
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs")
}
if srtSpl, pass, err := hcs.spS.populateSortingData(ev, s, extraOpts); err != nil {
if srtSpl, pass, err := hcs.spS.populateSortingData(ev, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, srtSpl)

View File

@@ -36,7 +36,7 @@ type LeastCostSorter struct {
}
func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier,
ev *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
ev *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: lcs.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
@@ -47,7 +47,7 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier,
utils.SupplierS, s.ID))
return nil, utils.NewErrMandatoryIeMissing("RatingPlanIDs")
}
if srtSpl, pass, err := lcs.spS.populateSortingData(ev, s, extraOpts); err != nil {
if srtSpl, pass, err := lcs.spS.populateSortingData(ev, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, srtSpl)

View File

@@ -36,7 +36,7 @@ type LoadDistributionSorter struct {
}
func (ws *LoadDistributionSorter) SortSuppliers(prflID string,
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: ws.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
@@ -48,7 +48,7 @@ func (ws *LoadDistributionSorter) SortSuppliers(prflID string,
utils.SupplierS, s.ID))
return nil, utils.NewErrMandatoryIeMissing("StatIDs")
}
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts); err != nil {
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
// Add the ratio in SortingData so we can used it later in SortLoadDistribution

View File

@@ -34,12 +34,12 @@ type QOSSupplierSorter struct {
}
func (qos *QOSSupplierSorter) SortSuppliers(prflID string, suppls []*Supplier,
ev *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
ev *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: qos.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
for _, s := range suppls {
if srtSpl, pass, err := qos.spS.populateSortingData(ev, s, extraOpts); err != nil {
if srtSpl, pass, err := qos.spS.populateSortingData(ev, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, srtSpl)

View File

@@ -36,7 +36,7 @@ type ResourceAscendentSorter struct {
}
func (ws *ResourceAscendentSorter) SortSuppliers(prflID string,
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: ws.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
@@ -47,7 +47,7 @@ func (ws *ResourceAscendentSorter) SortSuppliers(prflID string,
utils.SupplierS, s.ID))
return nil, utils.NewErrMandatoryIeMissing("ResourceIDs")
}
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts); err != nil {
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, srtSpl)

View File

@@ -36,7 +36,7 @@ type ResourceDescendentSorter struct {
}
func (ws *ResourceDescendentSorter) SortSuppliers(prflID string,
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: ws.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
@@ -47,7 +47,7 @@ func (ws *ResourceDescendentSorter) SortSuppliers(prflID string,
utils.SupplierS, s.ID))
return nil, utils.NewErrMandatoryIeMissing("ResourceIDs")
}
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts); err != nil {
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, srtSpl)

View File

@@ -34,12 +34,12 @@ type WeightSorter struct {
}
func (ws *WeightSorter) SortSuppliers(prflID string,
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers) (sortedSuppls *SortedSuppliers, err error) {
suppls []*Supplier, suplEv *utils.CGREvent, extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (sortedSuppls *SortedSuppliers, err error) {
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
Sorting: ws.sorting,
SortedSuppliers: make([]*SortedSupplier, 0)}
for _, s := range suppls {
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts); err != nil {
if srtSpl, pass, err := ws.spS.populateSortingData(suplEv, s, extraOpts, argDsp); err != nil {
return nil, err
} else if pass && srtSpl != nil {
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, srtSpl)

View File

@@ -203,7 +203,7 @@ func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *utils.CGREvent,
// costForEvent will compute cost out of accounts and rating plans for event
// returns map[string]interface{} with cost and relevant matching information inside
func (spS *SupplierService) costForEvent(ev *utils.CGREvent,
acntIDs, rpIDs []string) (costData map[string]interface{}, err error) {
acntIDs, rpIDs []string, argDsp *utils.ArgDispatcher) (costData map[string]interface{}, err error) {
costData = make(map[string]interface{})
if err = ev.CheckMandatoryFields([]string{utils.Account,
utils.Destination, utils.SetupTime}); err != nil {
@@ -241,12 +241,13 @@ func (spS *SupplierService) costForEvent(ev *utils.CGREvent,
if len(acntIDs) != 0 {
if err := spS.connMgr.Call(spS.cgrcfg.SupplierSCfg().RALsConns, nil, utils.ResponderGetMaxSessionTimeOnAccounts,
&utils.GetMaxSessionTimeOnAccountsArgs{
Tenant: ev.Tenant,
Subject: subj,
Destination: dst,
SetupTime: sTime,
Usage: usage,
AccountIDs: acntIDs,
Tenant: ev.Tenant,
Subject: subj,
Destination: dst,
SetupTime: sTime,
Usage: usage,
AccountIDs: acntIDs,
ArgDispatcher: argDsp,
}, &acntCost); err != nil {
return nil, err
}
@@ -281,6 +282,7 @@ func (spS *SupplierService) costForEvent(ev *utils.CGREvent,
SetupTime: sTime,
Usage: usage,
RatingPlanIDs: rpIDs,
ArgDispatcher: argDsp,
}, &rpCost); err != nil {
return nil, err
}
@@ -388,7 +390,7 @@ func (spS *SupplierService) resourceUsage(resIDs []string, tenant string) (tUsag
}
func (spS *SupplierService) populateSortingData(ev *utils.CGREvent, spl *Supplier,
extraOpts *optsGetSuppliers) (srtSpl *SortedSupplier, pass bool, err error) {
extraOpts *optsGetSuppliers, argDsp *utils.ArgDispatcher) (srtSpl *SortedSupplier, pass bool, err error) {
sortedSpl := &SortedSupplier{
SupplierID: spl.ID,
SortingData: map[string]interface{}{
@@ -398,7 +400,7 @@ func (spS *SupplierService) populateSortingData(ev *utils.CGREvent, spl *Supplie
}
//calculate costData if we have fields
if len(spl.AccountIDs) != 0 || len(spl.RatingPlanIDs) != 0 {
costData, err := spS.costForEvent(ev, spl.AccountIDs, spl.RatingPlanIDs)
costData, err := spS.costForEvent(ev, spl.AccountIDs, spl.RatingPlanIDs, argDsp)
if err != nil {
if extraOpts.ignoreErrors {
utils.Logger.Warning(
@@ -520,7 +522,7 @@ func (spS *SupplierService) sortedSuppliersForEvent(args *ArgsGetSuppliers) (sor
extraOpts.sortingParameters = splPrfl.SortingParameters // populate sortingParameters in extraOpts
extraOpts.sortingStragety = splPrfl.Sorting // populate sortinStrategy in extraOpts
sortedSuppliers, err := spS.sorter.SortSuppliers(splPrfl.ID, splPrfl.Sorting,
splPrfl.Suppliers, args.CGREvent, extraOpts)
splPrfl.Suppliers, args.CGREvent, extraOpts, args.ArgDispatcher)
if err != nil {
return nil, err
}

View File

@@ -1423,6 +1423,7 @@ type GetCostOnRatingPlansArgs struct {
SetupTime time.Time
Usage time.Duration
RatingPlanIDs []string
*ArgDispatcher
}
type GetMaxSessionTimeOnAccountsArgs struct {
@@ -1432,4 +1433,5 @@ type GetMaxSessionTimeOnAccountsArgs struct {
SetupTime time.Time
Usage time.Duration
AccountIDs []string
*ArgDispatcher
}