mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Made DataDB connection for SessionS optional
This commit is contained in:
committed by
Dan Christian Bogos
parent
ae95d1b15c
commit
a98907bdff
@@ -1588,8 +1588,7 @@ func main() {
|
||||
var dm *engine.DataManager
|
||||
if cfg.RalsCfg().RALsEnabled || cfg.SchedulerCfg().Enabled || cfg.ChargerSCfg().Enabled ||
|
||||
cfg.AttributeSCfg().Enabled || cfg.ResourceSCfg().Enabled || cfg.StatSCfg().Enabled ||
|
||||
cfg.ThresholdSCfg().Enabled || cfg.SupplierSCfg().Enabled || cfg.DispatcherSCfg().Enabled ||
|
||||
cfg.SessionSCfg().Enabled { // Some services can run without db, ie: CDRC
|
||||
cfg.ThresholdSCfg().Enabled || cfg.SupplierSCfg().Enabled || cfg.DispatcherSCfg().Enabled { // Some services can run without db, ie: CDRC
|
||||
dm, err = engine.ConfigureDataStorage(cfg.DataDbCfg().DataDbType,
|
||||
cfg.DataDbCfg().DataDbHost, cfg.DataDbCfg().DataDbPort,
|
||||
cfg.DataDbCfg().DataDbName, cfg.DataDbCfg().DataDbUser,
|
||||
@@ -1605,6 +1604,22 @@ func main() {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
} else if cfg.SessionSCfg().Enabled {
|
||||
dm, err = engine.ConfigureDataStorage(cfg.DataDbCfg().DataDbType,
|
||||
cfg.DataDbCfg().DataDbHost, cfg.DataDbCfg().DataDbPort,
|
||||
cfg.DataDbCfg().DataDbName, cfg.DataDbCfg().DataDbUser,
|
||||
cfg.DataDbCfg().DataDbPass, cfg.GeneralCfg().DBDataEncoding,
|
||||
cfg.CacheCfg(), cfg.DataDbCfg().DataDbSentinelName)
|
||||
if err != nil { // Cannot configure getter database, show stopper
|
||||
utils.Logger.Warning(fmt.Sprintf("Could not configure dataDb: %s.Some SessionS API will not work", err))
|
||||
} else {
|
||||
defer dm.DataDB().Close()
|
||||
engine.SetDataStorage(dm)
|
||||
if err := engine.CheckVersions(dm.DataDB()); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
if cfg.RalsCfg().RALsEnabled || cfg.CdrsCfg().CDRSEnabled {
|
||||
storDb, err := engine.ConfigureStorStorage(cfg.StorDbCfg().StorDBType,
|
||||
|
||||
@@ -1551,6 +1551,9 @@ func (sS *SessionS) BiRPCv1GetActiveSessions(clnt rpcclient.RpcClientConnection,
|
||||
if args == nil { //protection in case on nil
|
||||
args = &utils.SessionFilter{}
|
||||
}
|
||||
if len(args.Filters) != 0 && sS.dm == nil {
|
||||
return utils.NoDataBaseConnection
|
||||
}
|
||||
aSs := sS.filterSessions(args, false)
|
||||
if len(aSs) == 0 {
|
||||
return utils.ErrNotFound
|
||||
@@ -1565,6 +1568,9 @@ func (sS *SessionS) BiRPCv1GetActiveSessionsCount(clnt rpcclient.RpcClientConnec
|
||||
if args == nil { //protection in case on nil
|
||||
args = &utils.SessionFilter{}
|
||||
}
|
||||
if len(args.Filters) != 0 && sS.dm == nil {
|
||||
return utils.NoDataBaseConnection
|
||||
}
|
||||
*reply = sS.filterSessionsCount(args, false)
|
||||
return nil
|
||||
}
|
||||
@@ -1575,6 +1581,9 @@ func (sS *SessionS) BiRPCv1GetPassiveSessions(clnt rpcclient.RpcClientConnection
|
||||
if args == nil { //protection in case on nil
|
||||
args = &utils.SessionFilter{}
|
||||
}
|
||||
if len(args.Filters) != 0 && sS.dm == nil {
|
||||
return utils.NoDataBaseConnection
|
||||
}
|
||||
pSs := sS.filterSessions(args, true)
|
||||
if len(pSs) == 0 {
|
||||
return utils.ErrNotFound
|
||||
@@ -1589,6 +1598,9 @@ func (sS *SessionS) BiRPCv1GetPassiveSessionsCount(clnt rpcclient.RpcClientConne
|
||||
if args == nil { //protection in case on nil
|
||||
args = &utils.SessionFilter{}
|
||||
}
|
||||
if len(args.Filters) != 0 && sS.dm == nil {
|
||||
return utils.NoDataBaseConnection
|
||||
}
|
||||
*reply = sS.filterSessionsCount(args, true)
|
||||
return nil
|
||||
}
|
||||
@@ -2769,6 +2781,9 @@ func (sS *SessionS) BiRPCv1ForceDisconnect(clnt rpcclient.RpcClientConnection,
|
||||
if args == nil { //protection in case on nil
|
||||
args = &utils.SessionFilter{}
|
||||
}
|
||||
if len(args.Filters) != 0 && sS.dm == nil {
|
||||
return utils.NoDataBaseConnection
|
||||
}
|
||||
aSs := sS.filterSessions(args, false)
|
||||
if len(aSs) == 0 {
|
||||
return utils.ErrNotFound
|
||||
|
||||
@@ -78,6 +78,7 @@ var (
|
||||
RalsErrorPrfx = "RALS_ERROR"
|
||||
DispatcherErrorPrefix = "DISPATCHER_ERROR"
|
||||
ErrUnsupportedFormat = errors.New("UNSUPPORTED_FORMAT")
|
||||
NoDataBaseConnection = errors.New("NO_DATA_BASE_CONNECTION")
|
||||
)
|
||||
|
||||
// NewCGRError initialises a new CGRError
|
||||
|
||||
Reference in New Issue
Block a user