mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added Guardian as service in ServiceManager
This commit is contained in:
committed by
Dan Christian Bogos
parent
9464478cf7
commit
63723711e3
@@ -282,14 +282,6 @@ func startAnalyzerService(internalAnalyzerSChan chan rpcclient.RpcClientConnecti
|
||||
internalAnalyzerSChan <- aSv1
|
||||
}
|
||||
|
||||
func initGuardianSv1(internalGuardianSChan chan rpcclient.RpcClientConnection, server *utils.Server) {
|
||||
grdSv1 := v1.NewGuardianSv1()
|
||||
if !cfg.DispatcherSCfg().Enabled {
|
||||
server.RpcRegister(grdSv1)
|
||||
}
|
||||
internalGuardianSChan <- grdSv1
|
||||
}
|
||||
|
||||
func initCoreSv1(internalCoreSv1Chan chan rpcclient.RpcClientConnection, server *utils.Server) {
|
||||
cSv1 := v1.NewCoreSv1(engine.NewCoreService())
|
||||
if !cfg.DispatcherSCfg().Enabled {
|
||||
@@ -639,15 +631,12 @@ func main() {
|
||||
filterSChan := make(chan *engine.FilterS, 1)
|
||||
internalDispatcherSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalAnalyzerSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalGuardianSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
|
||||
internalLoaderSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalServeManagerChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalConfigChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalCoreSv1Chan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
|
||||
// init GuardianSv1
|
||||
initGuardianSv1(internalGuardianSChan, server)
|
||||
|
||||
// init CoreSv1
|
||||
initCoreSv1(internalCoreSv1Chan, server)
|
||||
|
||||
@@ -668,7 +657,8 @@ func main() {
|
||||
apiv2, _ := srvManager.GetService(utils.ApierV2)
|
||||
resp, _ := srvManager.GetService(utils.ResponderS)
|
||||
smg := services.NewSessionService()
|
||||
srvManager.AddService(chS, attrS, chrS, tS, stS, reS, supS, schS, cdrS, rals, smg,
|
||||
grd := services.NewGuardianService()
|
||||
srvManager.AddService(chS, attrS, chrS, tS, stS, reS, supS, schS, cdrS, rals, smg, grd,
|
||||
services.NewEventReaderService(),
|
||||
services.NewDNSAgent(),
|
||||
services.NewFreeswitchAgent(),
|
||||
@@ -692,6 +682,7 @@ func main() {
|
||||
internalRaterChan := resp.GetIntenternalChan()
|
||||
internalRALsv1Chan := rals.GetIntenternalChan()
|
||||
internalSMGChan := smg.GetIntenternalChan()
|
||||
internalGuardianSChan := grd.GetIntenternalChan()
|
||||
srvManager.StartServices()
|
||||
|
||||
cacheS := srvManager.GetCacheS()
|
||||
|
||||
94
services/guardian.go
Normal file
94
services/guardian.go
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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 services
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// NewGuardianService returns the Guardian Service
|
||||
func NewGuardianService() servmanager.Service {
|
||||
return &GuardianService{
|
||||
connChan: make(chan rpcclient.RpcClientConnection, 1),
|
||||
}
|
||||
}
|
||||
|
||||
// GuardianService implements Service interface
|
||||
type GuardianService struct {
|
||||
sync.RWMutex
|
||||
rpc *v1.GuardianSv1
|
||||
connChan chan rpcclient.RpcClientConnection
|
||||
}
|
||||
|
||||
// Start should handle the sercive start
|
||||
// populates internal channel for RPC conns
|
||||
func (grd *GuardianService) Start(sp servmanager.ServiceProvider, waitGuardian bool) (err error) {
|
||||
// safe to not check GuardianS should never be stoped and then started again
|
||||
// if grd.IsRunning() {
|
||||
// return fmt.Errorf("service aleady running")
|
||||
// }
|
||||
|
||||
grd.Lock()
|
||||
defer grd.Unlock()
|
||||
|
||||
grd.rpc = v1.NewGuardianSv1()
|
||||
if !sp.GetConfig().DispatcherSCfg().Enabled {
|
||||
sp.GetServer().RpcRegister(grd.rpc)
|
||||
}
|
||||
grd.connChan <- grd.rpc
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetIntenternalChan returns the internal connection chanel
|
||||
func (grd *GuardianService) GetIntenternalChan() (conn chan rpcclient.RpcClientConnection) {
|
||||
return grd.connChan
|
||||
}
|
||||
|
||||
// Reload handles the change of config
|
||||
func (grd *GuardianService) Reload(sp servmanager.ServiceProvider) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown stops the service
|
||||
func (grd *GuardianService) Shutdown() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetRPCInterface returns the interface to register for server
|
||||
func (grd *GuardianService) GetRPCInterface() interface{} {
|
||||
return grd.rpc
|
||||
}
|
||||
|
||||
// IsRunning returns if the service is running
|
||||
func (grd *GuardianService) IsRunning() bool {
|
||||
grd.RLock()
|
||||
defer grd.RUnlock()
|
||||
return grd != nil && grd.rpc != nil
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
func (grd *GuardianService) ServiceName() string {
|
||||
return utils.GuardianS
|
||||
}
|
||||
@@ -245,6 +245,7 @@ func (srvMngr *ServiceManager) StartServices() (err error) {
|
||||
}
|
||||
chS.Start(srvMngr, true)
|
||||
}
|
||||
go srvMngr.startService(utils.GuardianS)
|
||||
|
||||
go srvMngr.handleReload()
|
||||
if srvMngr.GetConfig().AttributeSCfg().Enabled {
|
||||
|
||||
@@ -602,6 +602,7 @@ const (
|
||||
AnalyzerS = "AnalyzerS"
|
||||
CDRServer = "CDRServer"
|
||||
ResponderS = "ResponderS"
|
||||
GuardianS = "GuardianS"
|
||||
)
|
||||
|
||||
// Lower service names
|
||||
|
||||
Reference in New Issue
Block a user