From 42f2403693a38d5e29182144473046a0d21bc0c3 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 25 Sep 2019 10:50:14 +0300 Subject: [PATCH] Added connection reload for Resource service --- engine/resources.go | 6 ++++++ services/resources.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/engine/resources.go b/engine/resources.go index d9a391ca9..3bd6a632f 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -765,3 +765,9 @@ func (rS *ResourceService) Reload() { func (rS *ResourceService) StartLoop() { go rS.runBackup() } + +// SetThresholdConnection sets the new conection to the threshold service +// only used on reload +func (rS *ResourceService) SetThresholdConnection(thdS rpcclient.RpcClientConnection) { + rS.thdS = thdS +} diff --git a/services/resources.go b/services/resources.go index c0f4545ec..f11f34fc8 100644 --- a/services/resources.go +++ b/services/resources.go @@ -55,7 +55,7 @@ func (reS *ResourceService) Start(sp servmanager.ServiceProvider, waitCache bool <-sp.GetCacheS().GetPrecacheChannel(utils.CacheResourceFilterIndexes) } var thdSConn rpcclient.RpcClientConnection - if thdSConn, err = sp.GetConnection(utils.ThresholdS, sp.GetConfig().StatSCfg().ThresholdSConns); err != nil { + if thdSConn, err = sp.GetConnection(utils.ThresholdS, sp.GetConfig().ResourceSCfg().ThresholdSConns); err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to ThresholdS: %s", utils.ResourceS, err.Error())) return } @@ -84,9 +84,15 @@ func (reS *ResourceService) GetIntenternalChan() (conn chan rpcclient.RpcClientC // Reload handles the change of config func (reS *ResourceService) Reload(sp servmanager.ServiceProvider) (err error) { + var thdSConn rpcclient.RpcClientConnection + if thdSConn, err = sp.GetConnection(utils.ThresholdS, sp.GetConfig().ResourceSCfg().ThresholdSConns); err != nil { + utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to ThresholdS: %s", utils.ResourceS, err.Error())) + return + } reS.Lock() + reS.reS.SetThresholdConnection(thdSConn) reS.reS.Reload() - defer reS.Unlock() + reS.Unlock() return }