From 29b9a878b1ad8eca752e203b6825faf880ff55d4 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 8 Oct 2019 15:32:32 +0300 Subject: [PATCH] Added DB reload for RalS --- cmd/cgr-engine/cgr-engine.go | 2 +- config/config.go | 35 +++++++++++++++++++++++++++-------- services/apierv1.go | 6 +++--- services/datadb.go | 2 +- services/rals.go | 2 +- services/rals_it_test.go | 8 +++++++- services/sessions_it_test.go | 2 +- 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 65e5f3130..54e803a6a 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -532,7 +532,7 @@ func main() { attrS.GetIntenternalChan(), stS.GetIntenternalChan(), reS.GetIntenternalChan(), dspS.GetIntenternalChan()) schS := services.NewSchedulerService(cfg, dmService, cacheS, server, internalCDRServerChan, dspS.GetIntenternalChan()) - rals := services.NewRalService(cfg, dmService.GetDM(), cdrDb, loadDb, cacheS, filterSChan, server, + rals := services.NewRalService(cfg, dmService, cdrDb, loadDb, cacheS, filterSChan, server, tS.GetIntenternalChan(), stS.GetIntenternalChan(), internalCacheSChan, schS.GetIntenternalChan(), attrS.GetIntenternalChan(), dspS.GetIntenternalChan(), schS, exitChan) diff --git a/config/config.go b/config/config.go index 5fe889917..3460abe6b 100755 --- a/config/config.go +++ b/config/config.go @@ -1542,13 +1542,18 @@ func (cfg *CGRConfig) reloadSection(section string) (err error) { } fallthrough case SCHEDULER_JSN: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[SCHEDULER_JSN] <- struct{}{} if !fall { break } fallthrough case RALS_JSN: + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[RALS_JSN] <- struct{}{} if !fall { break @@ -1620,42 +1625,54 @@ func (cfg *CGRConfig) reloadSection(section string) (err error) { } fallthrough case ATTRIBUTE_JSN: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[ATTRIBUTE_JSN] <- struct{}{} if !fall { break } fallthrough case ChargerSCfgJson: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[ChargerSCfgJson] <- struct{}{} if !fall { break } fallthrough case RESOURCES_JSON: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[RESOURCES_JSON] <- struct{}{} if !fall { break } fallthrough case STATS_JSON: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[STATS_JSON] <- struct{}{} if !fall { break } fallthrough case THRESHOLDS_JSON: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[THRESHOLDS_JSON] <- struct{}{} if !fall { break } fallthrough case SupplierSJson: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[SupplierSJson] <- struct{}{} if !fall { break @@ -1668,7 +1685,9 @@ func (cfg *CGRConfig) reloadSection(section string) (err error) { } fallthrough case DispatcherSJson: - cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + if !fall { + cfg.rldChans[DATADB_JSN] <- struct{}{} // reload datadb before + } cfg.rldChans[DispatcherSJson] <- struct{}{} if !fall { break diff --git a/services/apierv1.go b/services/apierv1.go index feff14ea4..381573b3a 100644 --- a/services/apierv1.go +++ b/services/apierv1.go @@ -30,7 +30,7 @@ import ( ) // NewApierV1Service returns the ApierV1 Service -func NewApierV1Service(cfg *config.CGRConfig, dm *engine.DataManager, +func NewApierV1Service(cfg *config.CGRConfig, dm *DataDBService, cdrStorage engine.CdrStorage, loadStorage engine.LoadStorage, filterSChan chan *engine.FilterS, server *utils.Server, cacheSChan, schedChan, attrsChan, @@ -58,7 +58,7 @@ func NewApierV1Service(cfg *config.CGRConfig, dm *engine.DataManager, type ApierV1Service struct { sync.RWMutex cfg *config.CGRConfig - dm *engine.DataManager + dm *DataDBService cdrStorage engine.CdrStorage loadStorage engine.LoadStorage filterSChan chan *engine.FilterS @@ -111,7 +111,7 @@ func (api *ApierV1Service) Start() (err error) { api.api = &v1.ApierV1{ StorDb: api.loadStorage, - DataManager: api.dm, + DataManager: api.dm.GetDM(), CdrDb: api.cdrStorage, Config: api.cfg, Responder: api.responderService.GetResponder(), diff --git a/services/datadb.go b/services/datadb.go index 9842f19d2..aa3fbb123 100644 --- a/services/datadb.go +++ b/services/datadb.go @@ -113,7 +113,7 @@ func (db *DataDBService) Shutdown() (err error) { func (db *DataDBService) IsRunning() bool { db.RLock() defer db.RUnlock() - return db != nil && db.db != nil + return db != nil && db.db != nil && db.db.DataDB() != nil } // ServiceName returns the service name diff --git a/services/rals.go b/services/rals.go index c410f5e4c..35e203faa 100644 --- a/services/rals.go +++ b/services/rals.go @@ -31,7 +31,7 @@ import ( ) // NewRalService returns the Ral Service -func NewRalService(cfg *config.CGRConfig, dm *engine.DataManager, +func NewRalService(cfg *config.CGRConfig, dm *DataDBService, cdrStorage engine.CdrStorage, loadStorage engine.LoadStorage, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, server *utils.Server, thsChan, stsChan, cacheSChan, schedChan, attrsChan, dispatcherChan chan rpcclient.RpcClientConnection, diff --git a/services/rals_it_test.go b/services/rals_it_test.go index 78cdcee9e..65a6dd6a2 100644 --- a/services/rals_it_test.go +++ b/services/rals_it_test.go @@ -67,7 +67,7 @@ func TestRalsReload(t *testing.T) { db := NewDataDBService(cfg) schS := NewSchedulerService(cfg, nil, chS, server, make(chan rpcclient.RpcClientConnection, 1), nil) tS := NewThresholdService(cfg, db, chS, filterSChan, server) - ralS := NewRalService(cfg, nil, nil, nil, chS, filterSChan, server, + ralS := NewRalService(cfg, db, nil, nil, chS, filterSChan, server, tS.GetIntenternalChan(), internalChan, cacheSChan, internalChan, internalChan, internalChan, schS, engineShutdown) srvMngr.AddServices(ralS, schS, tS, NewLoaderService(cfg, nil, filterSChan, server, cacheSChan, nil, engineShutdown), db) @@ -77,6 +77,9 @@ func TestRalsReload(t *testing.T) { if ralS.IsRunning() { t.Errorf("Expected service to be down") } + if db.IsRunning() { + t.Errorf("Expected service to be down") + } var reply string if err := cfg.V1ReloadConfig(&config.ConfigReloadWithArgDispatcher{ Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), @@ -103,6 +106,9 @@ func TestRalsReload(t *testing.T) { t.Errorf("Expected service to be running") } + if !db.IsRunning() { + t.Errorf("Expected service to be running") + } cfg.RalsCfg().Enabled = false cfg.GetReloadChan(config.RALS_JSN) <- struct{}{} time.Sleep(10 * time.Millisecond) diff --git a/services/sessions_it_test.go b/services/sessions_it_test.go index f4f164b64..f65e7a0d2 100644 --- a/services/sessions_it_test.go +++ b/services/sessions_it_test.go @@ -70,7 +70,7 @@ func TestSessionSReload(t *testing.T) { db := NewDataDBService(cfg) chrS := NewChargerService(cfg, db, chS, filterSChan, server, nil, nil) schS := NewSchedulerService(cfg, nil, chS, server, make(chan rpcclient.RpcClientConnection, 1), nil) - ralS := NewRalService(cfg, nil, nil, nil, chS, filterSChan, server, + ralS := NewRalService(cfg, db, nil, nil, chS, filterSChan, server, /*tS*/ internalChan, internalChan, cacheSChan, internalChan, internalChan, internalChan, schS, engineShutdown) cdrS := NewCDRServer(cfg, nil, nil, filterSChan, server,