Added connection reload for Suppliers service

This commit is contained in:
Trial97
2019-09-25 10:57:50 +03:00
committed by Dan Christian Bogos
parent 42f2403693
commit 9cedb53fbe
2 changed files with 45 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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
}