From d79b26419c941a25710c52f3826d70613f72c499 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 25 Sep 2019 11:11:50 +0300 Subject: [PATCH] Added connection reload for CDR server --- engine/cdrs.go | 32 ++++++++++++++++++++++++++++++++ engine/suppliers.go | 2 +- services/cdrs.go | 39 +++++++++++++++++++++++++++++++++++++++ services/schedulers.go | 2 +- 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/engine/cdrs.go b/engine/cdrs.go index 906a2d20d..efabd04d9 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -829,3 +829,35 @@ func (cdrS *CDRServer) V1CountCDRs(args *utils.RPCCDRsFilterWithArgDispatcher, c } return nil } + +// var ralConn, rpcclient.RpcClientConnection + +// SetAttributeSConnection sets the new conection to the attribute service +// only used on reload +func (cdrS *CDRServer) SetAttributeSConnection(attrS rpcclient.RpcClientConnection) { + cdrS.attrS = attrS +} + +// SetThresholSConnection sets the new conection to the threshold service +// only used on reload +func (cdrS *CDRServer) SetThresholSConnection(thdS rpcclient.RpcClientConnection) { + cdrS.thdS = thdS +} + +// SetStatSConnection sets the new conection to the stat service +// only used on reload +func (cdrS *CDRServer) SetStatSConnection(stS rpcclient.RpcClientConnection) { + cdrS.statS = stS +} + +// SetChargerSConnection sets the new conection to the charger service +// only used on reload +func (cdrS *CDRServer) SetChargerSConnection(chS rpcclient.RpcClientConnection) { + cdrS.chargerS = chS +} + +// SetRALsConnection sets the new conection to the RAL service +// only used on reload +func (cdrS *CDRServer) SetRALsConnection(rls rpcclient.RpcClientConnection) { + cdrS.rals = rls +} diff --git a/engine/suppliers.go b/engine/suppliers.go index 111051f3b..8dce4731e 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -616,7 +616,7 @@ func (spS *SupplierService) V1GetSuppliers(args *ArgsGetSuppliers, reply *Sorted return } -// V1GetSupplierProfiles returns the list of valid supplier profiles +// V1GetSupplierProfilesForEvent returns the list of valid supplier profiles func (spS *SupplierService) V1GetSupplierProfilesForEvent(args *utils.CGREventWithArgDispatcher, reply *[]*SupplierProfile) (err error) { if missing := utils.MissingStructFields(args.CGREvent, []string{utils.Tenant, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) diff --git a/services/cdrs.go b/services/cdrs.go index 29fbf26f8..51f9af26e 100644 --- a/services/cdrs.go +++ b/services/cdrs.go @@ -111,6 +111,45 @@ func (cdrS *CDRServer) GetIntenternalChan() (conn chan rpcclient.RpcClientConnec // Reload handles the change of config func (cdrS *CDRServer) Reload(sp servmanager.ServiceProvider) (err error) { + var ralConn, attrSConn, thresholdSConn, statsConn, chargerSConn rpcclient.RpcClientConnection + + chargerSConn, err = sp.GetConnection(utils.ChargerS, sp.GetConfig().CdrsCfg().ChargerSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf(" Could not connect to %s: %s", + utils.ChargerS, err.Error())) + return + } + ralConn, err = sp.GetConnection(utils.ResponderS, sp.GetConfig().CdrsCfg().RaterConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf(" Could not connect to %s: %s", + utils.RALService, err.Error())) + return + } + attrSConn, err = sp.GetConnection(utils.AttributeS, sp.GetConfig().CdrsCfg().AttributeSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf(" Could not connect to %s: %s", + utils.AttributeS, err.Error())) + return + } + thresholdSConn, err = sp.GetConnection(utils.ThresholdS, sp.GetConfig().CdrsCfg().ThresholdSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf(" Could not connect to %s: %s", + utils.ThresholdS, err.Error())) + return + } + statsConn, err = sp.GetConnection(utils.StatS, sp.GetConfig().CdrsCfg().StatSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf(" Could not connect to %s: %s", + utils.StatS, err.Error())) + return + } + cdrS.Lock() + cdrS.cdrS.SetRALsConnection(ralConn) + cdrS.cdrS.SetAttributeSConnection(attrSConn) + cdrS.cdrS.SetThresholSConnection(thresholdSConn) + cdrS.cdrS.SetStatSConnection(statsConn) + cdrS.cdrS.SetChargerSConnection(chargerSConn) + cdrS.Unlock() return } diff --git a/services/schedulers.go b/services/schedulers.go index 8f156ace4..98ba96bb1 100644 --- a/services/schedulers.go +++ b/services/schedulers.go @@ -90,7 +90,7 @@ func (schS *SchedulerService) GetIntenternalChan() (conn chan rpcclient.RpcClien func (schS *SchedulerService) Reload(sp servmanager.ServiceProvider) (err error) { schS.Lock() schS.schS.Reload() - defer schS.Unlock() + schS.Unlock() return }