From 0626b050c1e931e8a1fe3c945bd80e558869123a Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 2 Apr 2024 20:03:34 +0300 Subject: [PATCH] Add ERs apis to apier package Now the ErSv1 object methods are registered instead when starting the ERs service. --- apier/v1/ers.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ services/ers.go | 10 +++------- 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 apier/v1/ers.go diff --git a/apier/v1/ers.go b/apier/v1/ers.go new file mode 100644 index 000000000..7e9cbd5aa --- /dev/null +++ b/apier/v1/ers.go @@ -0,0 +1,49 @@ +/* +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 +*/ + +package v1 + +import ( + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/ers" + "github.com/cgrates/cgrates/utils" +) + +func NewErSv1(erS *ers.ERService) *ErSv1 { + return &ErSv1{erS: erS} +} + +type ErSv1 struct { + erS *ers.ERService +} + +func (eeSv1 *ErSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { + *reply = utils.Pong + return nil +} + +// V1RunReader processes files in the configured directory for the given reader. This function handles files +// based on the reader's type and configuration. Only available for readers that are not processing files +// automatically (RunDelay should equal 0). +// +// Note: This API is not safe to call concurrently for the same reader. Ensure the current files finish being +// processed before calling again. +func (eeSv1 *ErSv1) RunReader(ctx *context.Context, args utils.StringWithAPIOpts, + reply *string) error { + return eeSv1.erS.V1RunReader(ctx, args, reply) +} diff --git a/services/ers.go b/services/ers.go index acd9856d6..591142bb5 100644 --- a/services/ers.go +++ b/services/ers.go @@ -20,10 +20,10 @@ package services import ( "fmt" - "strings" "sync" "github.com/cgrates/birpc" + v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -94,15 +94,11 @@ func (erS *EventReaderService) Start() (err error) { erS.ers = ers.NewERService(erS.cfg, filterS, erS.connMgr) go erS.listenAndServe(erS.ers, erS.stopChan, erS.rldChan) - // Register ERs methods whose names start with "V1" under the "ErSv1" object name. - srv, err := birpc.NewServiceWithMethodsRename(erS.ers, utils.ErS, true, func(oldFn string) (newFn string) { - return strings.TrimPrefix(oldFn, "V1") - }) + // Register ERsV1 methods. + srv, err := birpc.NewService(v1.NewErSv1(erS.ers), "", false) if err != nil { return err } - engine.RegisterPingMethod(srv.Methods) - if !erS.cfg.DispatcherSCfg().Enabled { erS.server.RpcRegister(srv) }