Add ERs APIs to dispatchers

This commit is contained in:
ionutboangiu
2024-04-03 18:41:15 +03:00
committed by Dan Christian Bogos
parent e0ae593949
commit e56191e390
3 changed files with 105 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import (
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/ers"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
"github.com/cgrates/ltcache"
@@ -970,7 +971,7 @@ func (dS *DispatcherCoreSv1) Panic(ctx *context.Context, args *utils.PanicMessag
return dS.dS.CoreSv1Panic(ctx, args, reply)
}
// DispatcherCoreSv1 exports RPC from CoreSv1
// DispatcherEeSv1 exports RPC from EeSv1.
type DispatcherEeSv1 struct {
dS *dispatchers.DispatcherService
}
@@ -987,6 +988,23 @@ func (dS *DispatcherEeSv1) ProcessEvent(ctx *context.Context, args *engine.CGREv
return dS.dS.EeSv1ProcessEvent(ctx, args, reply)
}
// DispatcherErSv1 exports RPC from ErSv1.
type DispatcherErSv1 struct {
dS *dispatchers.DispatcherService
}
func NewDispatcherErSv1(dps *dispatchers.DispatcherService) *DispatcherErSv1 {
return &DispatcherErSv1{dS: dps}
}
func (dS *DispatcherErSv1) Ping(ctx *context.Context, cgrEv *utils.CGREvent, reply *string) error {
return dS.dS.ErSv1Ping(ctx, cgrEv, reply)
}
func (dS *DispatcherErSv1) ProcessEvent(ctx *context.Context, params ers.V1RunReaderParams, reply *string) error {
return dS.dS.ErSv1RunReader(ctx, params, reply)
}
type DispatcherReplicatorSv1 struct {
dS *dispatchers.DispatcherService
}

79
dispatchers/ers.go Normal file
View File

@@ -0,0 +1,79 @@
/*
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 dispatchers
import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/ers"
"github.com/cgrates/cgrates/utils"
)
func (dS *DispatcherService) ErSv1Ping(ctx *context.Context, cgrEv *utils.CGREvent, reply *string) error {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if cgrEv != nil && len(cgrEv.Tenant) != 0 {
tnt = cgrEv.Tenant
}
ev := make(map[string]any)
if cgrEv != nil {
ev = cgrEv.Event
}
opts := make(map[string]any)
if cgrEv != nil {
opts = cgrEv.APIOpts
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err := dS.authorize(utils.ErSv1Ping, tnt,
utils.IfaceAsString(opts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return err
}
}
return dS.Dispatch(
&utils.CGREvent{
Tenant: tnt,
Event: ev,
APIOpts: opts,
},
utils.MetaERs,
utils.ErSv1Ping, cgrEv, reply,
)
}
func (dS *DispatcherService) ErSv1RunReader(ctx *context.Context, params ers.V1RunReaderParams, reply *string) error {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if params.Tenant != "" {
tnt = params.Tenant
}
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if err := dS.authorize(utils.ErSv1RunReader, tnt,
utils.IfaceAsString(params.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
return err
}
}
return dS.Dispatch(
&utils.CGREvent{
Tenant: tnt,
ID: params.ID,
APIOpts: params.APIOpts,
},
utils.MetaERs,
utils.ErSv1RunReader, params, reply,
)
}

View File

@@ -201,6 +201,13 @@ func newDispatcherServiceMap(val *dispatchers.DispatcherService) (engine.IntServ
}
srvMap[srv.Name] = srv
srv, err = birpc.NewService(v1.NewDispatcherErSv1(val),
utils.ErSv1, true)
if err != nil {
return nil, err
}
srvMap[srv.Name] = srv
srv, err = birpc.NewService(v1.NewDispatcherGuardianSv1(val),
utils.GuardianSv1, true)
if err != nil {