diff --git a/apier/v1/ees.go b/apier/v1/ees.go new file mode 100644 index 000000000..cf77e73ed --- /dev/null +++ b/apier/v1/ees.go @@ -0,0 +1,43 @@ +/* +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/cgrates/ees" + "github.com/cgrates/cgrates/utils" +) + +func NewEventExporterSv1(eeS *ees.EventExporterS) *EventExporterSv1 { + return &EventExporterSv1{eeS: eeS} +} + +type EventExporterSv1 struct { + eeS *ees.EventExporterS +} + +func (eSv1 *EventExporterSv1) Ping(ign *utils.CGREventWithArgDispatcher, reply *string) error { + *reply = utils.Pong + return nil +} + +// ProcessEvent triggers exports on EEs side +func (eSv1 *EventExporterSv1) ProcessEvent(args *utils.CGREventWithOpts, + reply *string) error { + return eSv1.eeS.V1ProcessEvent(args, reply) +} diff --git a/console/ping.go b/console/ping.go index 70afba7cc..67be12af7 100644 --- a/console/ping.go +++ b/console/ping.go @@ -79,6 +79,8 @@ func (self *CmdApierPing) RpcMethod() string { return utils.ReplicatorSv1Ping case utils.ApierSLow: return utils.APIerSv1Ping + case utils.EEsLow: + return utils.EventExporterSv1Ping default: } return self.rpcMethod diff --git a/ees/ees.go b/ees/ees.go index 9624ad681..576b546b3 100644 --- a/ees/ees.go +++ b/ees/ees.go @@ -126,7 +126,7 @@ func (eeS *EventExporterS) attrSProcessEvent(cgrEv *utils.CGREventWithOpts, attr } // ProcessEvent will be called each time a new event is received from readers -func (eeS *EventExporterS) V1ProcessEvent(cgrEv *utils.CGREventWithOpts) (err error) { +func (eeS *EventExporterS) V1ProcessEvent(cgrEv *utils.CGREventWithOpts, rply *string) (err error) { eeS.cfg.RLocks(config.EEsJson) defer eeS.cfg.RUnlocks(config.EEsJson) diff --git a/services/ees.go b/services/ees.go index 2cf5704c0..5f907ba8f 100644 --- a/services/ees.go +++ b/services/ees.go @@ -27,6 +27,7 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" + "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/rpcclient" ) @@ -58,6 +59,7 @@ type EventExporterService struct { rldChan chan struct{} eeS *ees.EventExporterS + rpc *v1.EventExporterSv1 } // GetIntenternalChan is deprecated and it will be removed shortly @@ -65,12 +67,7 @@ func (es *EventExporterService) GetIntenternalChan() (conn chan rpcclient.Client panic("deprecated method") } -// IsRunning returns if the service is running -func (es *EventExporterService) IsRunning() bool { - es.RLock() - defer es.RUnlock() - return es != nil && es.eeS != nil -} + // ServiceName returns the service name func (es *EventExporterService) ServiceName() string { @@ -79,10 +76,14 @@ func (es *EventExporterService) ServiceName() string { // ShouldRun returns if the service should be running func (es *EventExporterService) ShouldRun() (should bool) { - es.cfg.RLocks(config.EEsJson) - should = es.cfg.EEsCfg().Enabled - es.cfg.RUnlocks(config.EEsJson) - return + return es.cfg.EEsCfg().Enabled +} + +// IsRunning returns if the service is running +func (es *EventExporterService) IsRunning() bool { + es.RLock() + defer es.RUnlock() + return es != nil && es.eeS != nil } // Reload handles the change of config @@ -115,9 +116,9 @@ func (es *EventExporterService) Start() (err error) { es.Lock() es.eeS = ees.NewEventExporterS(es.cfg, fltrS, es.connMgr) es.Unlock() - if err != nil { - - return + es.rpc = v1.NewEventExporterSv1(es.eeS) + if !es.cfg.DispatcherSCfg().Enabled { + es.server.RpcRegister(es.rpc) } es.intConnChan <- es.eeS return es.eeS.ListenAndServe(es.exitChan, es.rldChan) diff --git a/utils/consts.go b/utils/consts.go index 029a7d586..9da3ede6f 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -808,6 +808,7 @@ const ( RALsLow = "rals" ReplicatorLow = "replicator" ApierSLow = "apiers" + EEsLow = "ees" ) // Actions @@ -1472,6 +1473,12 @@ const ( SchedulerSv1ExecuteActionPlans = "SchedulerSv1.ExecuteActionPlans" ) +// EEs +const ( + EventExporterSv1 = "EventExporterSv1" + EventExporterSv1Ping = "EventExporterSv1.Ping" +) + //cgr_ variables const ( CGR_ACCOUNT = "cgr_account"