diff --git a/engine/suppliers.go b/engine/suppliers.go index a875e2cb7..111051f3b 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -633,3 +633,21 @@ func (spS *SupplierService) V1GetSupplierProfilesForEvent(args *utils.CGREventWi *reply = sPs return } + +// SetAttributeSConnection sets the new conection to the attribute service +// only used on reload +func (spS *SupplierService) SetAttributeSConnection(attrS rpcclient.RpcClientConnection) { + spS.attributeS = attrS +} + +// SetStatSConnection sets the new conection to the stat service +// only used on reload +func (spS *SupplierService) SetStatSConnection(stS rpcclient.RpcClientConnection) { + spS.statS = stS +} + +// SetResourceSConnection sets the new conection to the resource service +// only used on reload +func (spS *SupplierService) SetResourceSConnection(rS rpcclient.RpcClientConnection) { + spS.resourceS = rS +} diff --git a/services/suppliers.go b/services/suppliers.go index db41e6d45..c3e2e912b 100644 --- a/services/suppliers.go +++ b/services/suppliers.go @@ -74,6 +74,8 @@ func (splS *SupplierService) Start(sp servmanager.ServiceProvider, waitCache boo utils.SupplierS, err.Error())) return } + splS.Lock() + defer splS.Unlock() splS.splS, err = engine.NewSupplierService(sp.GetDM(), sp.GetFilterS(), sp.GetConfig(), resourceSConn, statSConn, attrSConn) if err != nil { @@ -81,8 +83,7 @@ func (splS *SupplierService) Start(sp servmanager.ServiceProvider, waitCache boo utils.SupplierS, err.Error())) return } - splS.Lock() - defer splS.Unlock() + utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.SupplierS)) splS.rpc = v1.NewSupplierSv1(splS.splS) if !sp.GetConfig().DispatcherSCfg().Enabled { @@ -99,6 +100,30 @@ func (splS *SupplierService) GetIntenternalChan() (conn chan rpcclient.RpcClient // Reload handles the change of config func (splS *SupplierService) Reload(sp servmanager.ServiceProvider) (err error) { + var attrSConn, resourceSConn, statSConn rpcclient.RpcClientConnection + attrSConn, err = sp.GetConnection(utils.AttributeS, sp.GetConfig().SupplierSCfg().AttributeSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to %s: %s", + utils.SupplierS, utils.SupplierS, err.Error())) + return + } + statSConn, err = sp.GetConnection(utils.StatS, sp.GetConfig().SupplierSCfg().StatSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to StatS: %s", + utils.SupplierS, err.Error())) + return + } + resourceSConn, err = sp.GetConnection(utils.ResourceS, sp.GetConfig().SupplierSCfg().ResourceSConns) + if err != nil { + utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to StatS: %s", + utils.SupplierS, err.Error())) + return + } + splS.Lock() + splS.splS.SetAttributeSConnection(attrSConn) + splS.splS.SetStatSConnection(statSConn) + splS.splS.SetResourceSConnection(resourceSConn) + splS.Unlock() return }