Updated dispatcher for responder API

This commit is contained in:
Trial97
2019-03-06 14:00:25 +02:00
committed by Dan Christian Bogos
parent 9b2bb3cb31
commit 16603a8c30
4 changed files with 145 additions and 1 deletions

View File

@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
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)
}

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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