EventExporterSv1 API skel

This commit is contained in:
DanB
2020-05-10 14:21:51 +02:00
parent 5c0599d0ec
commit 75b9433ccc
5 changed files with 67 additions and 14 deletions

43
apier/v1/ees.go Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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)
}

View File

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

View File

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

View File

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

View File

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