Added DB reload for RalS

This commit is contained in:
Trial97
2019-10-08 15:32:32 +03:00
committed by Dan Christian Bogos
parent 29dfbc8b90
commit 29b9a878b1
7 changed files with 41 additions and 16 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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(),

View File

@@ -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

View File

@@ -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,

View File

@@ -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)

View File

@@ -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,