From 16603a8c30aaeb4d34ede64d4b63affaf85573b2 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 6 Mar 2019 14:00:25 +0200 Subject: [PATCH] Updated dispatcher for responder API --- apier/v1/dispatcher.go | 34 +++++++++++++ dispatchers/responder.go | 103 ++++++++++++++++++++++++++++++++++++++- dispatchers/utils.go | 5 ++ utils/consts.go | 4 ++ 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index a8efd64ac..616ef252c 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -19,6 +19,8 @@ along with this program. If not, see package v1 import ( + "time" + "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -375,3 +377,35 @@ type DispatcherResponder struct { func (dS *DispatcherResponder) Status(args *dispatchers.TntWithApiKey, reply *map[string]interface{}) error { return dS.dS.ResponderStatus(args, reply) } + +func (dS *DispatcherResponder) GetCost(args *dispatchers.CallDescriptorWithApiKey, reply *engine.CallCost) error { + return dS.dS.ResponderGetCost(args, reply) +} + +func (dS *DispatcherResponder) Debit(args *dispatchers.CallDescriptorWithApiKey, reply *engine.CallCost) error { + return dS.dS.ResponderDebit(args, reply) +} + +func (dS *DispatcherResponder) MaxDebit(args *dispatchers.CallDescriptorWithApiKey, reply *engine.CallCost) error { + return dS.dS.ResponderMaxDebit(args, reply) +} + +func (dS *DispatcherResponder) RefundIncrements(args *dispatchers.CallDescriptorWithApiKey, reply *engine.Account) error { + return dS.dS.ResponderRefundIncrements(args, reply) +} + +func (dS *DispatcherResponder) RefundRounding(args *dispatchers.CallDescriptorWithApiKey, reply *float64) error { + return dS.dS.ResponderRefundRounding(args, reply) +} + +func (dS *DispatcherResponder) GetMaxSessionTime(args *dispatchers.CallDescriptorWithApiKey, reply *time.Duration) error { + return dS.dS.ResponderGetMaxSessionTime(args, reply) +} + +func (dS *DispatcherResponder) Shutdown(args *dispatchers.TntWithApiKey, reply *string) error { + return dS.dS.ResponderShutdown(args, reply) +} + +func (dS *DispatcherResponder) GetTimeout(args *dispatchers.TntWithApiKey, reply *time.Duration) error { + return dS.dS.ResponderGetTimeout(args, reply) +} diff --git a/dispatchers/responder.go b/dispatchers/responder.go index a19fdd60e..ac0586d91 100644 --- a/dispatchers/responder.go +++ b/dispatchers/responder.go @@ -21,6 +21,7 @@ package dispatchers import ( "time" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -34,6 +35,106 @@ func (dS *DispatcherService) ResponderStatus(args *TntWithApiKey, } return dS.Dispatch(&utils.CGREvent{ Tenant: args.Tenant, - }, utils.MetaStats, args.RouteID, utils.ResponderStatus, + }, utils.MetaResponder, args.RouteID, utils.ResponderStatus, "", reply) } + +func (dS *DispatcherService) ResponderGetCost(args *CallDescriptorWithApiKey, + reply *engine.CallCost) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderGetCost, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder, + args.RouteID, utils.ResponderGetCost, args.CallDescriptor, reply) +} + +func (dS *DispatcherService) ResponderDebit(args *CallDescriptorWithApiKey, + reply *engine.CallCost) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderDebit, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder, + args.RouteID, utils.ResponderDebit, args.CallDescriptor, reply) +} + +func (dS *DispatcherService) ResponderMaxDebit(args *CallDescriptorWithApiKey, + reply *engine.CallCost) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderMaxDebit, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder, + args.RouteID, utils.ResponderMaxDebit, args.CallDescriptor, reply) +} + +func (dS *DispatcherService) ResponderRefundIncrements(args *CallDescriptorWithApiKey, + reply *engine.Account) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderRefundIncrements, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder, + args.RouteID, utils.ResponderRefundIncrements, args.CallDescriptor, reply) +} + +func (dS *DispatcherService) ResponderRefundRounding(args *CallDescriptorWithApiKey, + reply *float64) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderRefundRounding, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder, + args.RouteID, utils.ResponderRefundRounding, args.CallDescriptor, reply) +} + +func (dS *DispatcherService) ResponderGetMaxSessionTime(args *CallDescriptorWithApiKey, + reply *time.Duration) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderGetMaxSessionTime, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(args.CallDescriptor.AsCGREvent(), utils.MetaResponder, + args.RouteID, utils.ResponderGetMaxSessionTime, args.CallDescriptor, reply) +} + +func (dS *DispatcherService) ResponderShutdown(args *TntWithApiKey, + reply *string) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderShutdown, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{ + Tenant: args.Tenant, + }, utils.MetaResponder, args.RouteID, utils.ResponderShutdown, + "", reply) +} + +func (dS *DispatcherService) ResponderGetTimeout(args *TntWithApiKey, + reply *time.Duration) (err error) { + if dS.attrS != nil { + if err = dS.authorize(utils.ResponderGetTimeout, args.Tenant, + args.APIKey, utils.TimePointer(time.Now())); err != nil { + return + } + } + return dS.Dispatch(&utils.CGREvent{ + Tenant: args.Tenant, + }, utils.MetaResponder, args.RouteID, utils.ResponderGetTimeout, + 0, reply) +} diff --git a/dispatchers/utils.go b/dispatchers/utils.go index 52329ff92..b2beaf3d5 100755 --- a/dispatchers/utils.go +++ b/dispatchers/utils.go @@ -120,6 +120,11 @@ type SessionWithApiKey struct { sessions.Session } +type CallDescriptorWithApiKey struct { + DispatcherResource + engine.CallDescriptor +} + func ParseStringMap(s string) utils.StringMap { if s == utils.ZERO { return make(utils.StringMap) diff --git a/utils/consts.go b/utils/consts.go index 779b6d2e0..45172ddfc 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -380,6 +380,7 @@ const ( MetaSharedGroups = "*shared_groups" MetaRALs = "*rals" MetaStats = "*stats" + MetaResponder = "*responder" MetaThresholds = "*thresholds" MetaSuppliers = "*suppliers" MetaAttributes = "*attributes" @@ -786,6 +787,9 @@ const ( ResponderStatus = "Responder.Status" ResponderMaxDebit = "Responder.MaxDebit" ResponderRefundRounding = "Responder.RefundRounding" + ResponderGetCost = "Responder.GetCost" + ResponderShutdown = "Responder.Shutdown" + ResponderGetTimeout = "Responder.GetTimeout" ) // DispatcherS APIs