mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 07:38:45 +05:00
Add Connection from Chargers to Attributes through ConnManager
This commit is contained in:
@@ -19,31 +19,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
func NewChargerService(dm *DataManager, filterS *FilterS,
|
||||
attrS rpcclient.ClientConnector,
|
||||
cfg *config.CGRConfig) (*ChargerService, error) {
|
||||
if attrS != nil && reflect.ValueOf(attrS).IsNil() {
|
||||
attrS = nil
|
||||
}
|
||||
cfg *config.CGRConfig, connMgr *ConnManager) (*ChargerService, error) {
|
||||
|
||||
return &ChargerService{dm: dm, filterS: filterS,
|
||||
attrS: attrS, cfg: cfg}, nil
|
||||
cfg: cfg, connMgr: connMgr}, nil
|
||||
}
|
||||
|
||||
// ChargerService is performing charging
|
||||
type ChargerService struct {
|
||||
dm *DataManager
|
||||
filterS *FilterS
|
||||
attrS rpcclient.ClientConnector
|
||||
cfg *config.CGRConfig
|
||||
connMgr *ConnManager
|
||||
}
|
||||
|
||||
// ListenAndServe will initialize the service
|
||||
@@ -126,9 +120,6 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREventWithArgDispatcher) (
|
||||
if len(cP.AttributeIDs) == 1 && cP.AttributeIDs[0] == utils.META_NONE {
|
||||
continue // AttributeS disabled
|
||||
}
|
||||
if cS.attrS == nil {
|
||||
return nil, errors.New("no connection to AttributeS")
|
||||
}
|
||||
|
||||
args := &AttrArgsProcessEvent{
|
||||
AttributeIDs: cP.AttributeIDs,
|
||||
@@ -138,7 +129,7 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREventWithArgDispatcher) (
|
||||
ArgDispatcher: clonedEv.ArgDispatcher,
|
||||
}
|
||||
var evReply AttrSProcessEventReply
|
||||
if err = cS.attrS.Call(utils.AttributeSv1ProcessEvent,
|
||||
if err = cS.connMgr.Call(cS.cfg.ChargerSCfg().AttributeSConns, utils.AttributeSv1ProcessEvent,
|
||||
args, &evReply); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -181,9 +172,3 @@ func (cS *ChargerService) V1GetChargersForEvent(args *utils.CGREventWithArgDispa
|
||||
*rply = cPs
|
||||
return
|
||||
}
|
||||
|
||||
// SetAttributeConnection sets the new connection to the attribute service
|
||||
// only used on reload
|
||||
func (cS *ChargerService) SetAttributeConnection(attrS rpcclient.ClientConnector) {
|
||||
cS.attrS = attrS
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ func TestChargerPopulateChargerService(t *testing.T) {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
chargerSrv, err = NewChargerService(dmCharger,
|
||||
&FilterS{dm: dmCharger, cfg: defaultCfg}, nil, defaultCfg)
|
||||
&FilterS{dm: dmCharger, cfg: defaultCfg}, defaultCfg, nil)
|
||||
if err != nil {
|
||||
t.Errorf("Error: %+v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user