mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add implementation of CDRsV2 in Dispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
cf6d6455ad
commit
ad832ff4e8
42
apier/v2/dispatcher.go
Normal file
42
apier/v2/dispatcher.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package v2
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/dispatchers"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewDispatcherSCDRsV2(dps *dispatchers.DispatcherService) *DispatcherSCDRsV2 {
|
||||
return &DispatcherSCDRsV2{dS: dps}
|
||||
}
|
||||
|
||||
// Exports RPC from CDRsV2
|
||||
type DispatcherSCDRsV2 struct {
|
||||
dS *dispatchers.DispatcherService
|
||||
}
|
||||
|
||||
func (dS *DispatcherSCDRsV2) StoreSessionCost(args *engine.ArgsV2CDRSStoreSMCost, reply *string) error {
|
||||
return dS.dS.CDRsV2StoreSessionCost(args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherSCDRsV2) ProcessEvent(args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) error {
|
||||
return dS.dS.CDRsV2ProcessEvent(args, reply)
|
||||
}
|
||||
@@ -205,3 +205,47 @@ func (dS *DispatcherService) CDRsV1ProcessCDR(args *engine.CDRWithArgDispatcher,
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaCDRs, routeID,
|
||||
utils.CDRsV1ProcessCDR, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) CDRsV2ProcessEvent(args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args.CGREvent.Tenant != utils.EmptyString {
|
||||
tnt = args.CGREvent.Tenant
|
||||
}
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if args.ArgDispatcher == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
|
||||
}
|
||||
if err = dS.authorize(utils.CDRsV2ProcessEvent, tnt,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var routeID *string
|
||||
if args.ArgDispatcher != nil {
|
||||
routeID = args.ArgDispatcher.RouteID
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaCDRs, routeID,
|
||||
utils.CDRsV2ProcessEvent, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) CDRsV2StoreSessionCost(args *engine.ArgsV2CDRSStoreSMCost, reply *string) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args.TenantArg != nil && args.TenantArg.Tenant != utils.EmptyString {
|
||||
tnt = args.TenantArg.Tenant
|
||||
}
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if args.ArgDispatcher == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
|
||||
}
|
||||
if err = dS.authorize(utils.CDRsV2StoreSessionCost, 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.MetaCDRs, routeID,
|
||||
utils.CDRsV2StoreSessionCost, args, reply)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
v2 "github.com/cgrates/cgrates/apier/v2"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/dispatchers"
|
||||
@@ -138,6 +140,9 @@ func (dspS *DispatcherService) Start() (err error) {
|
||||
dspS.server.RpcRegisterName(utils.ReplicatorSv1,
|
||||
v1.NewDispatcherReplicatorSv1(dspS.dspS))
|
||||
|
||||
dspS.server.RpcRegisterName(utils.CDRsV2,
|
||||
v2.NewDispatcherSCDRsV2(dspS.dspS))
|
||||
|
||||
dspS.connChan <- dspS.dspS
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user