From b35f6c34859bc3e888225ead44b1272c4d704850 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 19 May 2021 10:20:36 +0300 Subject: [PATCH] Added all Responder Methods to DispatacherS.Fixes #2954 --- apier/v1/api_interfaces.go | 2 ++ apier/v1/dispatcher.go | 7 +++++++ dispatchers/responder.go | 28 ++++++++++++++++++++++++++++ engine/routes.go | 2 ++ utils/apitpdata.go | 2 ++ 5 files changed, 41 insertions(+) diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index 5b5c892a7..6460920df 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -109,6 +109,8 @@ type ResponderInterface interface { RefundIncrements(arg *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) RefundRounding(arg *engine.CallDescriptorWithAPIOpts, reply *float64) (err error) GetMaxSessionTime(arg *engine.CallDescriptorWithAPIOpts, reply *time.Duration) (err error) + GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]interface{}) (err error) + GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]interface{}) (err error) Shutdown(arg *utils.TenantWithAPIOpts, reply *string) (err error) Ping(ign *utils.CGREvent, reply *string) error } diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 75dd36f00..249b7f3cb 100644 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -576,6 +576,13 @@ func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithAPIOpts, reply *st 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 detreminate if component is active func (dS *DispatcherResponder) Ping(args *utils.CGREvent, reply *string) error { return dS.dS.ResponderPing(args, reply) diff --git a/dispatchers/responder.go b/dispatchers/responder.go index bbefd8284..da150035c 100644 --- a/dispatchers/responder.go +++ b/dispatchers/responder.go @@ -121,3 +121,31 @@ func (dS *DispatcherService) ResponderShutdown(args *utils.TenantWithAPIOpts, APIOpts: args.APIOpts, }, utils.MetaResponder, 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 err = dS.authorize(utils.ResponderShutdown, tnt, + utils.IfaceAsString(arg.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{ + Tenant: tnt, + APIOpts: arg.APIOpts, + }, utils.MetaResponder, utils.ResponderGetCostOnRatingPlans, arg, reply) +} + +func (dS *DispatcherService) ResponderGetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]interface{}) (err error) { + tnt := utils.FirstNonEmpty(arg.Tenant, dS.cfg.GeneralCfg().DefaultTenant) + if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { + if err = dS.authorize(utils.ResponderShutdown, tnt, + utils.IfaceAsString(arg.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{ + Tenant: tnt, + APIOpts: arg.APIOpts, + }, utils.MetaResponder, utils.ResponderGetMaxSessionTimeOnAccounts, arg, reply) +} diff --git a/engine/routes.go b/engine/routes.go index dc8f3fb9c..927f8840e 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -231,6 +231,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, SetupTime: sTime, Usage: usage, AccountIDs: acntIDs, + APIOpts: ev.APIOpts, }, &acntCost); err != nil { return nil, err } @@ -265,6 +266,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, SetupTime: sTime, Usage: usage, RatingPlanIDs: rpIDs, + APIOpts: ev.APIOpts, }, &rpCost); err != nil { return nil, err } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 34e346c62..1970da87b 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1397,6 +1397,7 @@ type GetCostOnRatingPlansArgs struct { SetupTime time.Time Usage time.Duration RatingPlanIDs []string + APIOpts map[string]interface{} } type GetMaxSessionTimeOnAccountsArgs struct { @@ -1406,6 +1407,7 @@ type GetMaxSessionTimeOnAccountsArgs struct { SetupTime time.Time Usage time.Duration AccountIDs []string + APIOpts map[string]interface{} } type ArgExportToFolder struct {