From af924267e0c8da0ad1680e2e4d0319e9023d66eb Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 25 Sep 2019 10:39:10 +0300 Subject: [PATCH] Added connection reload for Charger service --- engine/chargers.go | 6 ++++++ services/attributes.go | 2 +- services/chargers.go | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/engine/chargers.go b/engine/chargers.go index a70f5a5ca..16fd6360f 100644 --- a/engine/chargers.go +++ b/engine/chargers.go @@ -179,3 +179,9 @@ func (cS *ChargerService) V1GetChargersForEvent(args *utils.CGREventWithArgDispa *rply = cPs return } + +// SetAttributeConnection sets the new conection to the attribute service +// only used on reload +func (cS *ChargerService) SetAttributeConnection(attrS rpcclient.RpcClientConnection) { + cS.attrS = attrS +} diff --git a/services/attributes.go b/services/attributes.go index 359d26785..3235bb5c0 100644 --- a/services/attributes.go +++ b/services/attributes.go @@ -81,7 +81,7 @@ func (attrS *AttributeService) GetIntenternalChan() (conn chan rpcclient.RpcClie // Reload handles the change of config func (attrS *AttributeService) Reload(sp servmanager.ServiceProvider) (err error) { - return + return // for the momment nothing to reload } // Shutdown stops the service diff --git a/services/chargers.go b/services/chargers.go index 1683603a7..2a8166ea9 100644 --- a/services/chargers.go +++ b/services/chargers.go @@ -53,15 +53,15 @@ func (chrS *ChargerService) Start(sp servmanager.ServiceProvider, waitCache bool <-sp.GetCacheS().GetPrecacheChannel(utils.CacheChargerProfiles) <-sp.GetCacheS().GetPrecacheChannel(utils.CacheChargerFilterIndexes) } - var chrSConn rpcclient.RpcClientConnection - if chrSConn, err = sp.GetConnection(utils.AttributeS, sp.GetConfig().ChargerSCfg().AttributeSConns); err != nil { + var attrSConn rpcclient.RpcClientConnection + if attrSConn, err = sp.GetConnection(utils.AttributeS, sp.GetConfig().ChargerSCfg().AttributeSConns); err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to %s: %s", utils.ChargerS, utils.AttributeS, err.Error())) return } chrS.Lock() defer chrS.Unlock() - if chrS.chrS, err = engine.NewChargerService(sp.GetDM(), sp.GetFilterS(), chrSConn, sp.GetConfig()); err != nil { + if chrS.chrS, err = engine.NewChargerService(sp.GetDM(), sp.GetFilterS(), attrSConn, sp.GetConfig()); err != nil { utils.Logger.Crit( fmt.Sprintf("<%s> Could not init, error: %s", utils.ChargerS, err.Error())) @@ -83,7 +83,15 @@ func (chrS *ChargerService) GetIntenternalChan() (conn chan rpcclient.RpcClientC // Reload handles the change of config func (chrS *ChargerService) Reload(sp servmanager.ServiceProvider) (err error) { - // need to reload the connection to the attributeS + var attrSConn rpcclient.RpcClientConnection + if attrSConn, err = sp.GetConnection(utils.AttributeS, sp.GetConfig().ChargerSCfg().AttributeSConns); err != nil { + utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to %s: %s", + utils.ChargerS, utils.AttributeS, err.Error())) + return + } + chrS.Lock() + chrS.chrS.SetAttributeConnection(attrSConn) + chrS.Unlock() return }