mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated guardian and cache
This commit is contained in:
committed by
Dan Christian Bogos
parent
f0dddcea09
commit
718a9a992b
@@ -301,6 +301,14 @@ func initCacheS(internalCacheSChan chan rpcclient.RpcClientConnection,
|
||||
return
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -656,12 +664,14 @@ func main() {
|
||||
internalConfigChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalCoreSv1Chan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalCacheSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
|
||||
// internalSMGChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalGuardianSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
|
||||
// init CacheS
|
||||
cacheS := initCacheS(internalCacheSChan, server, dm, exitChan)
|
||||
|
||||
// init GuardianSv1
|
||||
initGuardianSv1(internalGuardianSChan, server)
|
||||
|
||||
// init CoreSv1
|
||||
initCoreSv1(internalCoreSv1Chan, server)
|
||||
|
||||
@@ -669,7 +679,6 @@ func main() {
|
||||
srvManager := servmanager.NewServiceManager(cfg, dm, cdrDb,
|
||||
loadDb, filterSChan, server, internalDispatcherSChan, exitChan)
|
||||
|
||||
// chS := services.NewCacheService()
|
||||
attrS := services.NewAttributeService(cfg, dm, cacheS, filterSChan, server)
|
||||
chrS := services.NewChargerService(cfg, dm, cacheS, filterSChan, server,
|
||||
attrS.GetIntenternalChan(), internalDispatcherSChan)
|
||||
@@ -692,11 +701,10 @@ func main() {
|
||||
stS.GetIntenternalChan(), internalDispatcherSChan)
|
||||
schS.SetCdrsConns(cdrS.GetIntenternalChan())
|
||||
/*
|
||||
|
||||
smg := services.NewSessionService()
|
||||
grd := services.NewGuardianService()*/
|
||||
srvManager.AddServices( /*chS, */ attrS, chrS, tS, stS, reS, supS, schS, rals,
|
||||
rals.GetResponder(), rals.GetAPIv1(), rals.GetAPIv2(), cdrS) /* smg, grd,
|
||||
*/
|
||||
srvManager.AddServices(attrS, chrS, tS, stS, reS, supS, schS, rals,
|
||||
rals.GetResponder(), rals.GetAPIv1(), rals.GetAPIv2(), cdrS) /* smg,
|
||||
services.NewEventReaderService(),
|
||||
services.NewDNSAgent(),
|
||||
services.NewFreeswitchAgent(),
|
||||
@@ -708,9 +716,7 @@ func main() {
|
||||
*/
|
||||
|
||||
/*
|
||||
internalCacheSChan := chS.GetIntenternalChan()
|
||||
internalSMGChan := smg.GetIntenternalChan()
|
||||
internalGuardianSChan := grd.GetIntenternalChan()
|
||||
*/
|
||||
srvManager.StartServices()
|
||||
|
||||
@@ -719,8 +725,6 @@ func main() {
|
||||
reS.GetIntenternalChan(), rals.GetResponder().GetIntenternalChan(),
|
||||
cfg, dm, exitChan)
|
||||
|
||||
// cacheS := srvManager.GetCacheS()
|
||||
|
||||
initServiceManagerV1(internalServeManagerChan, srvManager, server)
|
||||
|
||||
// init internalRPCSet
|
||||
@@ -734,7 +738,7 @@ func main() {
|
||||
engine.IntRPC.AddInternalRPCClient(utils.CDRsV1, cdrS.GetIntenternalChan())
|
||||
engine.IntRPC.AddInternalRPCClient(utils.CDRsV2, cdrS.GetIntenternalChan())
|
||||
engine.IntRPC.AddInternalRPCClient(utils.ChargerSv1, chrS.GetIntenternalChan())
|
||||
// engine.IntRPC.AddInternalRPCClient(utils.GuardianSv1, internalGuardianSChan)
|
||||
engine.IntRPC.AddInternalRPCClient(utils.GuardianSv1, internalGuardianSChan)
|
||||
engine.IntRPC.AddInternalRPCClient(utils.LoaderSv1, internalLoaderSChan)
|
||||
engine.IntRPC.AddInternalRPCClient(utils.ResourceSv1, reS.GetIntenternalChan())
|
||||
engine.IntRPC.AddInternalRPCClient(utils.Responder, rals.GetResponder().GetIntenternalChan())
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
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 (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// NewCacheService returns the Cache Service
|
||||
func NewCacheService() servmanager.Service {
|
||||
return &CacheService{
|
||||
connChan: make(chan rpcclient.RpcClientConnection, 1),
|
||||
}
|
||||
}
|
||||
|
||||
// CacheService implements Service interface
|
||||
type CacheService struct {
|
||||
sync.RWMutex
|
||||
chS *engine.CacheS
|
||||
rpc *v1.CacheSv1
|
||||
connChan chan rpcclient.RpcClientConnection
|
||||
}
|
||||
|
||||
// Start should handle the sercive start
|
||||
// inits the CacheS and starts precaching as well as populating internal channel for RPC conns
|
||||
func (chS *CacheService) Start(sp servmanager.ServiceProvider, waitCache bool) (err error) {
|
||||
// safe to not check CacheS should never be stoped and then started again
|
||||
// if chS.IsRunning() {
|
||||
// return fmt.Errorf("service aleady running")
|
||||
// }
|
||||
|
||||
chS.Lock()
|
||||
defer chS.Unlock()
|
||||
chS.chS = engine.NewCacheS(sp.GetConfig(), sp.GetDM())
|
||||
go func() {
|
||||
if err := chS.chS.Precache(); err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<%s> could not init, error: %s", utils.CacheS, err.Error()))
|
||||
sp.GetExitChan() <- true
|
||||
}
|
||||
}()
|
||||
|
||||
chS.rpc = v1.NewCacheSv1(chS.chS)
|
||||
if !sp.GetConfig().DispatcherSCfg().Enabled {
|
||||
sp.GetServer().RpcRegister(chS.rpc)
|
||||
}
|
||||
chS.connChan <- chS.rpc
|
||||
|
||||
// set the cache in ServiceManager
|
||||
sp.SetCacheS(chS.chS)
|
||||
return
|
||||
}
|
||||
|
||||
// GetIntenternalChan returns the internal connection chanel
|
||||
func (chS *CacheService) GetIntenternalChan() (conn chan rpcclient.RpcClientConnection) {
|
||||
return chS.connChan
|
||||
}
|
||||
|
||||
// Reload handles the change of config
|
||||
func (chS *CacheService) Reload(sp servmanager.ServiceProvider) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown stops the service
|
||||
func (chS *CacheService) Shutdown() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetRPCInterface returns the interface to register for server
|
||||
func (chS *CacheService) GetRPCInterface() interface{} {
|
||||
return chS.rpc
|
||||
}
|
||||
|
||||
// IsRunning returns if the service is running
|
||||
func (chS *CacheService) IsRunning() bool {
|
||||
chS.RLock()
|
||||
defer chS.RUnlock()
|
||||
return chS != nil && chS.chS != nil
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
func (chS *CacheService) ServiceName() string {
|
||||
return utils.CacheS
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user