mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added DB reload for SessionS
This commit is contained in:
committed by
Dan Christian Bogos
parent
f6eea07115
commit
6d273d107c
@@ -541,7 +541,7 @@ func main() {
|
||||
attrS.GetIntenternalChan(), tS.GetIntenternalChan(),
|
||||
stS.GetIntenternalChan(), dspS.GetIntenternalChan())
|
||||
|
||||
smg := services.NewSessionService(cfg, dmService.GetDM(), server, chrS.GetIntenternalChan(),
|
||||
smg := services.NewSessionService(cfg, dmService, server, chrS.GetIntenternalChan(),
|
||||
rals.GetResponder().GetIntenternalChan(), reS.GetIntenternalChan(),
|
||||
tS.GetIntenternalChan(), stS.GetIntenternalChan(), supS.GetIntenternalChan(),
|
||||
attrS.GetIntenternalChan(), cdrS.GetIntenternalChan(), dspS.GetIntenternalChan(), exitChan)
|
||||
|
||||
@@ -1580,6 +1580,9 @@ func (cfg *CGRConfig) reloadSection(section string) (err error) {
|
||||
}
|
||||
fallthrough
|
||||
case SessionSJson:
|
||||
if !fall {
|
||||
cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before
|
||||
}
|
||||
cfg.rldChans[SessionSJson] <- struct{}{}
|
||||
if !fall {
|
||||
break
|
||||
|
||||
@@ -49,10 +49,11 @@ func TestDNSAgentReload(t *testing.T) {
|
||||
|
||||
server := utils.NewServer()
|
||||
srvMngr := servmanager.NewServiceManager(cfg, engineShutdown)
|
||||
sS := NewSessionService(cfg, nil, server, nil,
|
||||
db := NewDataDBService(cfg)
|
||||
sS := NewSessionService(cfg, db, server, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil, engineShutdown)
|
||||
srv := NewDNSAgent(cfg, filterSChan, sS.GetIntenternalChan(), nil, engineShutdown)
|
||||
srvMngr.AddServices(srv, sS, NewLoaderService(cfg, nil, filterSChan, server, cacheSChan, nil, engineShutdown))
|
||||
srvMngr.AddServices(srv, sS, NewLoaderService(cfg, nil, filterSChan, server, cacheSChan, nil, engineShutdown), db)
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -52,10 +52,11 @@ func TestEventReaderSReload(t *testing.T) {
|
||||
engineShutdown := make(chan bool, 1)
|
||||
server := utils.NewServer()
|
||||
srvMngr := servmanager.NewServiceManager(cfg, engineShutdown)
|
||||
sS := NewSessionService(cfg, nil, server, nil,
|
||||
db := NewDataDBService(cfg)
|
||||
sS := NewSessionService(cfg, db, server, nil,
|
||||
nil, nil, nil, nil, nil, nil, nil, nil, engineShutdown)
|
||||
attrS := NewEventReaderService(cfg, filterSChan, sS.GetIntenternalChan(), nil, engineShutdown)
|
||||
srvMngr.AddServices(attrS, sS, NewLoaderService(cfg, nil, filterSChan, server, nil, nil, engineShutdown))
|
||||
srvMngr.AddServices(attrS, sS, NewLoaderService(cfg, nil, filterSChan, server, nil, nil, engineShutdown), db)
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -32,7 +31,7 @@ import (
|
||||
)
|
||||
|
||||
// NewSessionService returns the Session Service
|
||||
func NewSessionService(cfg *config.CGRConfig, dm *engine.DataManager,
|
||||
func NewSessionService(cfg *config.CGRConfig, dm *DataDBService,
|
||||
server *utils.Server, chrsChan, respChan, resChan, thsChan, stsChan,
|
||||
supChan, attrsChan, cdrsChan, dispatcherChan chan rpcclient.RpcClientConnection,
|
||||
exitChan chan bool) servmanager.Service {
|
||||
@@ -58,7 +57,7 @@ func NewSessionService(cfg *config.CGRConfig, dm *engine.DataManager,
|
||||
type SessionService struct {
|
||||
sync.RWMutex
|
||||
cfg *config.CGRConfig
|
||||
dm *engine.DataManager
|
||||
dm *DataDBService
|
||||
server *utils.Server
|
||||
chrsChan chan rpcclient.RpcClientConnection
|
||||
respChan chan rpcclient.RpcClientConnection
|
||||
@@ -149,7 +148,7 @@ func (smg *SessionService) Start() (err error) {
|
||||
|
||||
smg.sm = sessions.NewSessionS(smg.cfg, ralsConns, resSConns, threshSConns,
|
||||
statSConns, suplSConns, attrConns, cdrsConn, chargerSConn,
|
||||
sReplConns, smg.dm, smg.cfg.GeneralCfg().DefaultTimezone)
|
||||
sReplConns, smg.dm.GetDM(), smg.cfg.GeneralCfg().DefaultTimezone)
|
||||
//start sync session in a separate gorutine
|
||||
go func(sm *sessions.SessionS) {
|
||||
if err = sm.ListenAndServe(smg.exitChan); err != nil {
|
||||
|
||||
@@ -77,13 +77,16 @@ func TestSessionSReload(t *testing.T) {
|
||||
make(chan rpcclient.RpcClientConnection, 1),
|
||||
chrS.GetIntenternalChan(), ralS.GetResponder().GetIntenternalChan(),
|
||||
nil, nil, nil, nil)
|
||||
attrS := NewSessionService(cfg, nil, server, chrS.GetIntenternalChan(),
|
||||
srv := NewSessionService(cfg, db, server, chrS.GetIntenternalChan(),
|
||||
ralS.GetResponder().GetIntenternalChan(), nil, nil, nil, nil, nil, cdrS.GetIntenternalChan(), nil, engineShutdown)
|
||||
srvMngr.AddServices(attrS, chrS, schS, ralS, cdrS, NewLoaderService(cfg, nil, filterSChan, server, cacheSChan, nil, engineShutdown), db)
|
||||
srvMngr.AddServices(srv, chrS, schS, ralS, cdrS, NewLoaderService(cfg, nil, filterSChan, server, cacheSChan, nil, engineShutdown), db)
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if attrS.IsRunning() {
|
||||
if srv.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
if db.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
var reply string
|
||||
@@ -96,13 +99,16 @@ func TestSessionSReload(t *testing.T) {
|
||||
t.Errorf("Expecting OK ,received %s", reply)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond) //need to switch to gorutine
|
||||
if !attrS.IsRunning() {
|
||||
if !srv.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
if !db.IsRunning() {
|
||||
t.Errorf("Expected service to be running")
|
||||
}
|
||||
cfg.SessionSCfg().Enabled = false
|
||||
cfg.GetReloadChan(config.SessionSJson) <- struct{}{}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if attrS.IsRunning() {
|
||||
if srv.IsRunning() {
|
||||
t.Errorf("Expected service to be down")
|
||||
}
|
||||
engineShutdown <- true
|
||||
|
||||
Reference in New Issue
Block a user