From 1e584f5297dba95d89d799214ca71c8bd06e81a2 Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 25 Jul 2018 03:21:24 -0400 Subject: [PATCH] Remove supplier connection from AttributeS and update check config sanity --- cmd/cgr-engine/cgr-engine.go | 19 +++---------------- config/attributescfg.go | 8 -------- config/config.go | 5 +++++ config/config_defaults.go | 1 - config/config_json_test.go | 1 - config/config_test.go | 1 - config/libconfig_json.go | 1 - engine/attributes.go | 11 ++--------- engine/attributes_test.go | 2 +- 9 files changed, 11 insertions(+), 38 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index b0d003adf..4edb338d1 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -576,20 +576,7 @@ func startUsersServer(internalUserSChan chan rpcclient.RpcClientConnection, dm * // startAttributeService fires up the AttributeS func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnection, cacheS *engine.CacheS, cfg *config.CGRConfig, dm *engine.DataManager, - server *utils.Server, exitChan chan bool, filterSChan chan *engine.FilterS, - internalSupplierSChan chan rpcclient.RpcClientConnection) { - var err error - var sppSConn *rpcclient.RpcClientPool - if len(cfg.AttributeSCfg().SupplierSConns) != 0 { // Stats connection init - sppSConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST, cfg.TLSClientKey, cfg.TLSClientCerificate, - cfg.ConnectAttempts, cfg.Reconnects, cfg.ConnectTimeout, cfg.ReplyTimeout, - cfg.AttributeSCfg().SupplierSConns, internalSupplierSChan, cfg.InternalTtl) - if err != nil { - utils.Logger.Crit(fmt.Sprintf(" Could not connect to SupplierS: %s", err.Error())) - exitChan <- true - return - } - } + server *utils.Server, exitChan chan bool, filterSChan chan *engine.FilterS) { filterS := <-filterSChan filterSChan <- filterS <-cacheS.GetPrecacheChannel(utils.CacheAttributeProfiles) @@ -597,7 +584,7 @@ func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnec aS, err := engine.NewAttributeService(dm, filterS, cfg.AttributeSCfg().StringIndexedFields, cfg.AttributeSCfg().PrefixIndexedFields, - cfg.AttributeSCfg().ProcessRuns, sppSConn) + cfg.AttributeSCfg().ProcessRuns) if err != nil { utils.Logger.Crit( fmt.Sprintf("<%s> Could not init, error: %s", @@ -1311,7 +1298,7 @@ func main() { if cfg.AttributeSCfg().Enabled { go startAttributeService(internalAttributeSChan, cacheS, - cfg, dm, server, exitChan, filterSChan, internalSupplierSChan) + cfg, dm, server, exitChan, filterSChan) } if cfg.ChargerSCfg().Enabled { go startChargerService(internalChargerSChan, cacheS, internalAttributeSChan, diff --git a/config/attributescfg.go b/config/attributescfg.go index aebdccd0b..477d26b46 100644 --- a/config/attributescfg.go +++ b/config/attributescfg.go @@ -24,7 +24,6 @@ type AttributeSCfg struct { StringIndexedFields *[]string PrefixIndexedFields *[]string ProcessRuns int - SupplierSConns []*HaPoolConfig } func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) { @@ -51,12 +50,5 @@ func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) if jsnCfg.Process_runs != nil { alS.ProcessRuns = *jsnCfg.Process_runs } - if jsnCfg.Suppliers_conns != nil { - alS.SupplierSConns = make([]*HaPoolConfig, len(*jsnCfg.Suppliers_conns)) - for idx, jsnHaCfg := range *jsnCfg.Suppliers_conns { - alS.SupplierSConns[idx] = NewDfltHaPoolConfig() - alS.SupplierSConns[idx].loadFromJsonCfg(jsnHaCfg) - } - } return } diff --git a/config/config.go b/config/config.go index b63acd075..59f5f328d 100755 --- a/config/config.go +++ b/config/config.go @@ -700,6 +700,11 @@ func (self *CGRConfig) checkConfigSanity() error { return errors.New("StatS not enabled but requested by SupplierS component.") } } + for _, connCfg := range self.supplierSCfg.AttributeSConns { + if connCfg.Address == utils.MetaInternal && !self.attributeSCfg.Enabled { + return errors.New("AttributeS not enabled but requested by SupplierS component.") + } + } } // DispaterS checks if self.dispatcherSCfg != nil && self.dispatcherSCfg.Enabled { diff --git a/config/config_defaults.go b/config/config_defaults.go index b200d8a2f..36d45ea70 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -430,7 +430,6 @@ const CGRATES_CFG_JSON = ` //"string_indexed_fields": [], // query indexes based on these fields for faster processing "prefix_indexed_fields": [], // query indexes based on these fields for faster processing "process_runs": 1, // number of run loops when processing event - "suppliers_conns": [], // address where to reach the SupplierS <""|*internal|127.0.0.1:2013> }, diff --git a/config/config_json_test.go b/config/config_json_test.go index 152eda1ee..5205d3e88 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -705,7 +705,6 @@ func TestDfAttributeServJsonCfg(t *testing.T) { String_indexed_fields: nil, Prefix_indexed_fields: &[]string{}, Process_runs: utils.IntPointer(1), - Suppliers_conns: &[]*HaPoolJsonCfg{}, } if cfg, err := dfCgrJsonCfg.AttributeServJsonCfg(); err != nil { t.Error(err) diff --git a/config/config_test.go b/config/config_test.go index 8d07a425c..07b1c6a5f 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -803,7 +803,6 @@ func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) { StringIndexedFields: nil, PrefixIndexedFields: &[]string{}, ProcessRuns: 1, - SupplierSConns: []*HaPoolConfig{}, } if !reflect.DeepEqual(eAliasSCfg, cgrCfg.attributeSCfg) { t.Errorf("received: %+v, expecting: %+v", eAliasSCfg, cgrCfg.attributeSCfg) diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 4e115ff9a..4c78c3ac4 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -427,7 +427,6 @@ type AttributeSJsonCfg struct { String_indexed_fields *[]string Prefix_indexed_fields *[]string Process_runs *int - Suppliers_conns *[]*HaPoolJsonCfg } // ChargerSJsonCfg service config section diff --git a/engine/attributes.go b/engine/attributes.go index e7a6019d2..0c4e8684d 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -20,23 +20,17 @@ package engine import ( "fmt" - "reflect" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func NewAttributeService(dm *DataManager, filterS *FilterS, stringIndexedFields, prefixIndexedFields *[]string, - processRuns int, sppS rpcclient.RpcClientConnection) (*AttributeService, error) { - if sppS != nil && reflect.ValueOf(sppS).IsNil() { // fix nil value in interface - sppS = nil - } + processRuns int) (*AttributeService, error) { return &AttributeService{dm: dm, filterS: filterS, stringIndexedFields: stringIndexedFields, prefixIndexedFields: prefixIndexedFields, - processRuns: processRuns, - sppS: sppS}, nil + processRuns: processRuns}, nil } type AttributeService struct { @@ -45,7 +39,6 @@ type AttributeService struct { stringIndexedFields *[]string prefixIndexedFields *[]string processRuns int - sppS rpcclient.RpcClientConnection // rpc connection towards SupplierS } // ListenAndServe will initialize the service diff --git a/engine/attributes_test.go b/engine/attributes_test.go index 8175c8df6..b7b27e9de 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -181,7 +181,7 @@ func TestAttributePopulateAttrService(t *testing.T) { if err != nil { t.Errorf("Error: %+v", err) } - attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1, nil) + attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1) if err != nil { t.Errorf("Error: %+v", err) }