mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added RalS as service in ServiceManager
This commit is contained in:
committed by
Dan Christian Bogos
parent
a92348a905
commit
e4abc4ea07
@@ -1181,17 +1181,13 @@ func main() {
|
||||
// Define internal connections via channels
|
||||
filterSChan := make(chan *engine.FilterS, 1)
|
||||
internalDispatcherSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalRaterChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalSMGChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalAnalyzerSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalGuardianSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalLoaderSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalApierV1Chan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalApierV2Chan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalServeManagerChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalConfigChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalCoreSv1Chan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
internalRALsv1Chan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
|
||||
// init GuardianSv1
|
||||
initGuardianSv1(internalGuardianSChan, server)
|
||||
@@ -1211,7 +1207,11 @@ func main() {
|
||||
supS := services.NewSupplierService()
|
||||
schS := services.NewSchedulerService()
|
||||
cdrS := services.NewCDRServer()
|
||||
srvManager.AddService(chS, attrS, chrS, tS, stS, reS, supS, schS, cdrS, services.NewResponderService(internalRaterChan))
|
||||
rals := services.NewRalService(srvManager)
|
||||
apiv1, _ := srvManager.GetService(utils.ApierV1)
|
||||
apiv2, _ := srvManager.GetService(utils.ApierV2)
|
||||
resp, _ := srvManager.GetService(utils.ResponderS)
|
||||
srvManager.AddService(chS, attrS, chrS, tS, stS, reS, supS, schS, cdrS, rals)
|
||||
internalAttributeSChan := attrS.GetIntenternalChan()
|
||||
internalChargerSChan := chrS.GetIntenternalChan()
|
||||
internalThresholdSChan := tS.GetIntenternalChan()
|
||||
@@ -1221,6 +1221,10 @@ func main() {
|
||||
internalSchedSChan := schS.GetIntenternalChan()
|
||||
internalCdrSChan := cdrS.GetIntenternalChan()
|
||||
internalCacheSChan := chS.GetIntenternalChan()
|
||||
internalApierV1Chan := apiv1.GetIntenternalChan()
|
||||
internalApierV2Chan := apiv2.GetIntenternalChan()
|
||||
internalRaterChan := resp.GetIntenternalChan()
|
||||
internalRALsv1Chan := rals.GetIntenternalChan()
|
||||
srvManager.StartServices()
|
||||
|
||||
cacheS := srvManager.GetCacheS()
|
||||
@@ -1255,14 +1259,6 @@ func main() {
|
||||
|
||||
initConfigSv1(internalConfigChan, server)
|
||||
|
||||
// Start RALs
|
||||
if cfg.RalsCfg().Enabled {
|
||||
go startRater(internalRaterChan, internalApierV1Chan, internalApierV2Chan,
|
||||
internalThresholdSChan, internalStatSChan, internalCacheSChan, internalSchedSChan,
|
||||
internalAttributeSChan, internalDispatcherSChan, internalRALsv1Chan,
|
||||
/*srvManager*/ schS, server, dm, loadDb, cdrDb, cacheS, filterSChan, exitChan)
|
||||
}
|
||||
|
||||
// Start CDRC components if necessary
|
||||
go startCdrcs(internalCdrSChan, internalRaterChan, internalDispatcherSChan, filterSChan, exitChan)
|
||||
|
||||
|
||||
@@ -1,248 +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 main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
v2 "github.com/cgrates/cgrates/apier/v2"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/services"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// Starts rater and reports on chan
|
||||
func startRater(internalRaterChan, internalApierv1, internalApierv2, internalThdSChan,
|
||||
internalStatSChan, internalCacheSChan, internalSchedulerSChan, internalAttributeSChan,
|
||||
internalDispatcherSChan, internalRALsChan chan rpcclient.RpcClientConnection,
|
||||
/*serviceManager *servmanager.ServiceManager*/ schS *services.SchedulerService, server *utils.Server,
|
||||
dm *engine.DataManager, loadDb engine.LoadStorage, cdrDb engine.CdrStorage,
|
||||
chS *engine.CacheS, // separate from channel for optimization
|
||||
filterSChan chan *engine.FilterS, exitChan chan bool) {
|
||||
filterS := <-filterSChan
|
||||
filterSChan <- filterS
|
||||
var waitTasks []chan struct{}
|
||||
cacheTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, cacheTaskChan)
|
||||
go func() { //Wait for cache load
|
||||
defer close(cacheTaskChan)
|
||||
<-chS.GetPrecacheChannel(utils.CacheDestinations)
|
||||
<-chS.GetPrecacheChannel(utils.CacheReverseDestinations)
|
||||
<-chS.GetPrecacheChannel(utils.CacheRatingPlans)
|
||||
<-chS.GetPrecacheChannel(utils.CacheRatingProfiles)
|
||||
<-chS.GetPrecacheChannel(utils.CacheActions)
|
||||
<-chS.GetPrecacheChannel(utils.CacheActionPlans)
|
||||
<-chS.GetPrecacheChannel(utils.CacheAccountActionPlans)
|
||||
<-chS.GetPrecacheChannel(utils.CacheActionTriggers)
|
||||
<-chS.GetPrecacheChannel(utils.CacheSharedGroups)
|
||||
<-chS.GetPrecacheChannel(utils.CacheTimings)
|
||||
}()
|
||||
|
||||
intThdSChan := internalThdSChan
|
||||
intStatSChan := internalStatSChan
|
||||
intCacheSChan := internalCacheSChan
|
||||
intSchedulerSChanL := internalSchedulerSChan
|
||||
intAttributeSChan := internalAttributeSChan
|
||||
if cfg.DispatcherSCfg().Enabled {
|
||||
intThdSChan = internalDispatcherSChan
|
||||
intStatSChan = internalDispatcherSChan
|
||||
intCacheSChan = internalDispatcherSChan
|
||||
intSchedulerSChanL = internalDispatcherSChan
|
||||
intAttributeSChan = internalDispatcherSChan
|
||||
}
|
||||
|
||||
var thdS rpcclient.RpcClientConnection
|
||||
if len(cfg.RalsCfg().ThresholdSConns) != 0 { // Connections to ThresholdS
|
||||
thdsTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, thdsTaskChan)
|
||||
go func() {
|
||||
defer close(thdsTaskChan)
|
||||
var err error
|
||||
thdS, err = engine.NewRPCPool(rpcclient.POOL_FIRST,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
cfg.RalsCfg().ThresholdSConns, intThdSChan, false)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<RALs> Could not connect to ThresholdS, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
var stats rpcclient.RpcClientConnection
|
||||
if len(cfg.RalsCfg().StatSConns) != 0 { // Connections to StatS
|
||||
statsTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, statsTaskChan)
|
||||
go func() {
|
||||
defer close(statsTaskChan)
|
||||
var err error
|
||||
stats, err = engine.NewRPCPool(rpcclient.POOL_FIRST,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
cfg.RalsCfg().StatSConns, intStatSChan, false)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<RALs> Could not connect to StatS, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//create cache connection
|
||||
var cacheSrpc rpcclient.RpcClientConnection
|
||||
if len(cfg.ApierCfg().CachesConns) != 0 {
|
||||
cachesTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, cachesTaskChan)
|
||||
go func() {
|
||||
defer close(cachesTaskChan)
|
||||
var err error
|
||||
cacheSrpc, err = engine.NewRPCPool(rpcclient.POOL_FIRST,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
cfg.ApierCfg().CachesConns, intCacheSChan, false)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<APIer> Could not connect to CacheS, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//create scheduler connection
|
||||
var schedulerSrpc rpcclient.RpcClientConnection
|
||||
if len(cfg.ApierCfg().SchedulerConns) != 0 {
|
||||
schedulerSTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, schedulerSTaskChan)
|
||||
go func() {
|
||||
defer close(schedulerSTaskChan)
|
||||
var err error
|
||||
schedulerSrpc, err = engine.NewRPCPool(rpcclient.POOL_FIRST,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
cfg.ApierCfg().SchedulerConns, intSchedulerSChanL, false)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<APIer> Could not connect to SchedulerS, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
//create scheduler connection
|
||||
var attributeSrpc rpcclient.RpcClientConnection
|
||||
if len(cfg.ApierCfg().AttributeSConns) != 0 {
|
||||
attributeSTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, attributeSTaskChan)
|
||||
go func() {
|
||||
defer close(attributeSTaskChan)
|
||||
var err error
|
||||
attributeSrpc, err = engine.NewRPCPool(rpcclient.POOL_FIRST,
|
||||
cfg.TlsCfg().ClientKey,
|
||||
cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate,
|
||||
cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects,
|
||||
cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout,
|
||||
cfg.ApierCfg().AttributeSConns, intAttributeSChan, false)
|
||||
if err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<APIer> Could not connect to AttributeS, error: %s", err.Error()))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Wait for all connections to complete before going further
|
||||
for _, chn := range waitTasks {
|
||||
<-chn
|
||||
}
|
||||
|
||||
responder := &engine.Responder{
|
||||
ExitChan: exitChan,
|
||||
MaxComputedUsage: cfg.RalsCfg().MaxComputedUsage}
|
||||
|
||||
// correct reflect on cacheS since there is no APIer init
|
||||
if cacheSrpc != nil && reflect.ValueOf(cacheSrpc).IsNil() {
|
||||
cacheSrpc = nil
|
||||
}
|
||||
// correct reflect on schedulerS since there is no APIer init
|
||||
if schedulerSrpc != nil && reflect.ValueOf(schedulerSrpc).IsNil() {
|
||||
schedulerSrpc = nil
|
||||
}
|
||||
// correct reflect on schedulerS since there is no APIer init
|
||||
if attributeSrpc != nil && reflect.ValueOf(attributeSrpc).IsNil() {
|
||||
attributeSrpc = nil
|
||||
}
|
||||
apierRpcV1 := &v1.ApierV1{
|
||||
StorDb: loadDb,
|
||||
DataManager: dm,
|
||||
CdrDb: cdrDb,
|
||||
Config: cfg,
|
||||
Responder: responder,
|
||||
Scheduler: schS,
|
||||
HTTPPoster: engine.NewHTTPPoster(cfg.GeneralCfg().HttpSkipTlsVerify,
|
||||
cfg.GeneralCfg().ReplyTimeout),
|
||||
FilterS: filterS,
|
||||
CacheS: cacheSrpc,
|
||||
SchedulerS: schedulerSrpc,
|
||||
AttributeS: attributeSrpc}
|
||||
|
||||
if thdS != nil {
|
||||
engine.SetThresholdS(thdS) // temporary architectural fix until we will have separate AccountS
|
||||
}
|
||||
if stats != nil {
|
||||
engine.SetStatS(stats)
|
||||
}
|
||||
|
||||
apierRpcV2 := &v2.ApierV2{
|
||||
ApierV1: *apierRpcV1}
|
||||
|
||||
ralSv1 := v1.NewRALsV1()
|
||||
|
||||
if !cfg.DispatcherSCfg().Enabled {
|
||||
server.RpcRegister(responder)
|
||||
server.RpcRegister(apierRpcV1)
|
||||
server.RpcRegister(apierRpcV2)
|
||||
server.RpcRegister(ralSv1)
|
||||
}
|
||||
|
||||
utils.RegisterRpcParams("", &v1.CDRsV1{})
|
||||
utils.RegisterRpcParams("", &v2.CDRsV2{})
|
||||
utils.RegisterRpcParams("", &v1.SMGenericV1{})
|
||||
utils.RegisterRpcParams("", responder)
|
||||
utils.RegisterRpcParams("", apierRpcV1)
|
||||
utils.RegisterRpcParams("", apierRpcV2)
|
||||
utils.RegisterRpcParams(utils.RALsV1, ralSv1)
|
||||
utils.GetRpcParams("")
|
||||
|
||||
internalApierv1 <- apierRpcV1
|
||||
internalApierv2 <- apierRpcV2
|
||||
internalRALsChan <- ralSv1
|
||||
internalRaterChan <- responder // Rater done
|
||||
}
|
||||
|
||||
@@ -1261,7 +1261,10 @@ func (cfg *CGRConfig) HTTPCfg() *HTTPCfg {
|
||||
return cfg.httpCfg
|
||||
}
|
||||
|
||||
// RalsCfg returns the config for Ral Service
|
||||
func (cfg *CGRConfig) RalsCfg() *RalsCfg {
|
||||
cfg.lks[RALS_JSN].Lock()
|
||||
defer cfg.lks[RALS_JSN].Unlock()
|
||||
return cfg.ralsCfg
|
||||
}
|
||||
|
||||
@@ -1497,6 +1500,7 @@ func (cfg *CGRConfig) reloadSection(section string) (err error) {
|
||||
}
|
||||
fallthrough
|
||||
case RALS_JSN:
|
||||
cfg.rldChans[RALS_JSN] <- struct{}{}
|
||||
if !fall {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
@@ -46,10 +45,22 @@ func TestCdrsReload(t *testing.T) {
|
||||
|
||||
close(chS.GetPrecacheChannel(utils.CacheChargerProfiles))
|
||||
close(chS.GetPrecacheChannel(utils.CacheChargerFilterIndexes))
|
||||
|
||||
close(chS.GetPrecacheChannel(utils.CacheDestinations))
|
||||
close(chS.GetPrecacheChannel(utils.CacheReverseDestinations))
|
||||
close(chS.GetPrecacheChannel(utils.CacheRatingPlans))
|
||||
close(chS.GetPrecacheChannel(utils.CacheRatingProfiles))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActions))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActionPlans))
|
||||
close(chS.GetPrecacheChannel(utils.CacheAccountActionPlans))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActionTriggers))
|
||||
close(chS.GetPrecacheChannel(utils.CacheSharedGroups))
|
||||
close(chS.GetPrecacheChannel(utils.CacheTimings))
|
||||
|
||||
cfg.ChargerSCfg().Enabled = true
|
||||
cfg.RalsCfg().RALsEnabled = true
|
||||
responderChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
responderChan <- v1.NewResourceSv1(nil)
|
||||
cacheSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
cacheSChan <- chS
|
||||
server := utils.NewServer()
|
||||
srvMngr := servmanager.NewServiceManager(cfg /*dm*/, nil,
|
||||
/*cdrStorage*/ nil,
|
||||
@@ -57,7 +68,7 @@ func TestCdrsReload(t *testing.T) {
|
||||
server, nil, engineShutdown)
|
||||
srvMngr.SetCacheS(chS)
|
||||
cdrS := NewCDRServer()
|
||||
srvMngr.AddService(cdrS, NewResponderService(responderChan), NewChargerService())
|
||||
srvMngr.AddService(cdrS, NewRalService(srvMngr), NewChargerService(), &CacheService{connChan: cacheSChan}, NewSchedulerService())
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
152
services/rals.go
Normal file
152
services/rals.go
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
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/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// NewRalService returns the Ral Service
|
||||
func NewRalService(sp servmanager.ServiceProvider) servmanager.Service {
|
||||
apiv1 := NewApierV1Service()
|
||||
apiv2 := NewApierV2Service(apiv1)
|
||||
resp := NewResponderService()
|
||||
sp.AddService(apiv1, apiv2, resp)
|
||||
return &RalService{
|
||||
apiv1: apiv1,
|
||||
apiv2: apiv2,
|
||||
responder: resp,
|
||||
connChan: make(chan rpcclient.RpcClientConnection, 1),
|
||||
}
|
||||
}
|
||||
|
||||
// RalService implements Service interface
|
||||
type RalService struct {
|
||||
sync.RWMutex
|
||||
rals *v1.RALsV1
|
||||
apiv1 *ApierV1Service
|
||||
apiv2 *ApierV2Service
|
||||
responder *ResponderService
|
||||
connChan chan rpcclient.RpcClientConnection
|
||||
}
|
||||
|
||||
// Start should handle the sercive start
|
||||
// For this service the start should be called from RAL Service
|
||||
func (rals *RalService) Start(sp servmanager.ServiceProvider, waitCache bool) (err error) {
|
||||
if rals.IsRunning() {
|
||||
return fmt.Errorf("service aleady running")
|
||||
}
|
||||
|
||||
rals.Lock()
|
||||
defer rals.Unlock()
|
||||
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheDestinations)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheReverseDestinations)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheRatingPlans)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheRatingProfiles)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheActions)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheActionPlans)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheAccountActionPlans)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheActionTriggers)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheSharedGroups)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheTimings)
|
||||
|
||||
if err = rals.responder.Start(sp, waitCache); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = rals.apiv1.Start(sp, waitCache); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = rals.apiv2.Start(sp, waitCache); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rals.rals = v1.NewRALsV1()
|
||||
|
||||
if !sp.GetConfig().DispatcherSCfg().Enabled {
|
||||
sp.GetServer().RpcRegister(rals.rals)
|
||||
}
|
||||
|
||||
utils.RegisterRpcParams(utils.RALsV1, rals.rals)
|
||||
|
||||
rals.connChan <- rals.rals
|
||||
return
|
||||
}
|
||||
|
||||
// GetIntenternalChan returns the internal connection chanel
|
||||
func (rals *RalService) GetIntenternalChan() (conn chan rpcclient.RpcClientConnection) {
|
||||
return rals.connChan
|
||||
}
|
||||
|
||||
// Reload handles the change of config
|
||||
func (rals *RalService) Reload(sp servmanager.ServiceProvider) (err error) {
|
||||
if err = rals.apiv1.Reload(sp); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.apiv2.Reload(sp); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.responder.Reload(sp); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown stops the service
|
||||
func (rals *RalService) Shutdown() (err error) {
|
||||
rals.Lock()
|
||||
defer rals.Unlock()
|
||||
if err = rals.apiv1.Shutdown(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.apiv2.Shutdown(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.responder.Shutdown(); err != nil {
|
||||
return
|
||||
}
|
||||
rals.rals = nil
|
||||
<-rals.connChan
|
||||
return
|
||||
}
|
||||
|
||||
// GetRPCInterface returns the interface to register for server
|
||||
func (rals *RalService) GetRPCInterface() interface{} {
|
||||
return rals.rals
|
||||
}
|
||||
|
||||
// IsRunning returns if the service is running
|
||||
func (rals *RalService) IsRunning() bool {
|
||||
rals.RLock()
|
||||
defer rals.RUnlock()
|
||||
return rals != nil && rals.rals != nil
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
func (rals *RalService) ServiceName() string {
|
||||
return utils.RALService
|
||||
}
|
||||
@@ -29,9 +29,9 @@ import (
|
||||
)
|
||||
|
||||
// NewResponderService returns the Resonder Service
|
||||
func NewResponderService(connChan chan rpcclient.RpcClientConnection) *ResponderService {
|
||||
func NewResponderService() *ResponderService {
|
||||
return &ResponderService{
|
||||
connChan: connChan,
|
||||
connChan: make(chan rpcclient.RpcClientConnection, 1),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,6 @@ func (resp *ResponderService) Start(sp servmanager.ServiceProvider, waitCache bo
|
||||
if resp.IsRunning() {
|
||||
return fmt.Errorf("service aleady running")
|
||||
}
|
||||
var waitTasks []chan struct{}
|
||||
cacheTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, cacheTaskChan)
|
||||
|
||||
var thdS, stats rpcclient.RpcClientConnection
|
||||
if thdS, err = sp.GetConnection(utils.ThresholdS, sp.GetConfig().RalsCfg().RALsThresholdSConns); err != nil {
|
||||
|
||||
@@ -271,6 +271,9 @@ func (srvMngr *ServiceManager) StartServices() (err error) {
|
||||
if srvMngr.GetConfig().CdrsCfg().Enabled {
|
||||
go srvMngr.startService(utils.CDRServer)
|
||||
}
|
||||
if srvMngr.GetConfig().RalsCfg().RALsEnabled {
|
||||
go srvMngr.startService(utils.RALService)
|
||||
}
|
||||
// startServer()
|
||||
return
|
||||
}
|
||||
@@ -294,36 +297,40 @@ func (srvMngr *ServiceManager) handleReload() {
|
||||
case ext := <-srvMngr.engineShutdown:
|
||||
srvMngr.engineShutdown <- ext
|
||||
return
|
||||
case <-srvMngr.cfg.GetReloadChan(config.ATTRIBUTE_JSN):
|
||||
if err = srvMngr.reloadService(utils.AttributeS, srvMngr.cfg.AttributeSCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.ATTRIBUTE_JSN):
|
||||
if err = srvMngr.reloadService(utils.AttributeS, srvMngr.GetConfig().AttributeSCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.ChargerSCfgJson):
|
||||
if err = srvMngr.reloadService(utils.ChargerS, srvMngr.cfg.ChargerSCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.ChargerSCfgJson):
|
||||
if err = srvMngr.reloadService(utils.ChargerS, srvMngr.GetConfig().ChargerSCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.THRESHOLDS_JSON):
|
||||
if err = srvMngr.reloadService(utils.ThresholdS, srvMngr.cfg.ThresholdSCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.THRESHOLDS_JSON):
|
||||
if err = srvMngr.reloadService(utils.ThresholdS, srvMngr.GetConfig().ThresholdSCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.STATS_JSON):
|
||||
if err = srvMngr.reloadService(utils.StatS, srvMngr.cfg.StatSCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.STATS_JSON):
|
||||
if err = srvMngr.reloadService(utils.StatS, srvMngr.GetConfig().StatSCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.RESOURCES_JSON):
|
||||
if err = srvMngr.reloadService(utils.ResourceS, srvMngr.cfg.ResourceSCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.RESOURCES_JSON):
|
||||
if err = srvMngr.reloadService(utils.ResourceS, srvMngr.GetConfig().ResourceSCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.SupplierSJson):
|
||||
if err = srvMngr.reloadService(utils.SupplierS, srvMngr.cfg.SupplierSCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.SupplierSJson):
|
||||
if err = srvMngr.reloadService(utils.SupplierS, srvMngr.GetConfig().SupplierSCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.SCHEDULER_JSN):
|
||||
if err = srvMngr.reloadService(utils.SchedulerS, srvMngr.cfg.SchedulerCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.SCHEDULER_JSN):
|
||||
if err = srvMngr.reloadService(utils.SchedulerS, srvMngr.GetConfig().SchedulerCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.cfg.GetReloadChan(config.CDRS_JSN):
|
||||
if err = srvMngr.reloadService(utils.CDRServer, srvMngr.cfg.CdrsCfg().Enabled); err != nil {
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.CDRS_JSN):
|
||||
if err = srvMngr.reloadService(utils.CDRServer, srvMngr.GetConfig().CdrsCfg().Enabled); err != nil {
|
||||
return
|
||||
}
|
||||
case <-srvMngr.GetConfig().GetReloadChan(config.RALS_JSN):
|
||||
if err = srvMngr.reloadService(utils.RALService, srvMngr.GetConfig().RalsCfg().RALsEnabled); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user