diff --git a/cmd/cgr-migrator/cgr-migrator.go b/cmd/cgr-migrator/cgr-migrator.go index 7ba662be7..7f4c5634e 100755 --- a/cmd/cgr-migrator/cgr-migrator.go +++ b/cmd/cgr-migrator/cgr-migrator.go @@ -46,7 +46,7 @@ var ( "Configuration directory path.") exec = cgrMigratorFlags.String("exec", "", "fire up automatic migration "+ - "<*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups|*stordb|*datadb>") + "<*set_versions|*cost_details|*accounts|*actions|*action_triggers|*action_plans|*shared_groups|*filters|*stordb|*datadb>") version = cgrMigratorFlags.Bool("version", false, "prints the application version") inDataDBType = cgrMigratorFlags.String("datadb_type", dfltCfg.DataDbCfg().DataDbType, diff --git a/config/config.go b/config/config.go index 17fb570a6..52b53c34a 100755 --- a/config/config.go +++ b/config/config.go @@ -134,6 +134,7 @@ func NewDefaultCGRConfig() (cfg *CGRConfig, err error) { cfg.DataFolderPath = "/usr/share/cgrates/" cfg.MaxCallDuration = time.Duration(3) * time.Hour // Hardcoded for now + cfg.rpcConns = make(map[string]*RpcConn) cfg.generalCfg = new(GeneralCfg) cfg.generalCfg.NodeID = utils.UUIDSha1Prefix() cfg.dataDbCfg = new(DataDbCfg) @@ -256,6 +257,8 @@ type CGRConfig struct { ConfigReloads map[string]chan struct{} // Signals to specific entities that a config reload should occur rldChans map[string]chan struct{} // index here the channels used for reloads + rpcConns map[string]*RpcConn + generalCfg *GeneralCfg // General config dataDbCfg *DataDbCfg // Database config storDbCfg *StorDbCfg // StroreDb config @@ -735,6 +738,7 @@ func (cfg *CGRConfig) LazySanityCheck() { func (cfg *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { // Load sections out of JSON config, stop on error for _, loadFunc := range []func(*CgrJsonCfg) error{ + cfg.loadRpcConns, cfg.loadGeneralCfg, cfg.loadCacheCfg, cfg.loadListenCfg, cfg.loadHttpCfg, cfg.loadDataDBCfg, cfg.loadStorDBCfg, cfg.loadFilterSCfg, cfg.loadRalSCfg, cfg.loadSchedulerCfg, @@ -754,6 +758,14 @@ func (cfg *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { return } +// loadRpcConns loads the RPCConns section of the configuration +func (cfg *CGRConfig) loadRpcConns(jsnCfg *CgrJsonCfg) (err error) { + var jsnRpcConns map[string]*RpcConn + if jsnRpcConns, err = jsnCfg.RpcConnJsonCfg(); err != nil { + return + } +} + // loadGeneralCfg loads the General section of the configuration func (cfg *CGRConfig) loadGeneralCfg(jsnCfg *CgrJsonCfg) (err error) { var jsnGeneralCfg *GeneralJsonCfg diff --git a/config/config_json.go b/config/config_json.go index 04454cfb1..184656813 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -60,6 +60,7 @@ const ( Apier = "apier" DNSAgentJson = "dns_agent" ERsJson = "ers" + RpcConnsJsonName = "rpc_conns" ) // Loads the json config out of io.Reader, eg other sources than file, maybe over http @@ -84,6 +85,18 @@ func (self CgrJsonCfg) GeneralJsonCfg() (*GeneralJsonCfg, error) { return cfg, nil } +func (self CgrJsonCfg) RpcConnJsonCfg() (map[string]*RpcConnsJson, error) { + rawCfg, hasKey := self[RpcConnsJsonName] + if !hasKey { + return nil, nil + } + cfg := make(map[string]*RpcConnsJson) + if err := json.Unmarshal(*rawCfg, cfg); err != nil { + return nil, err + } + return cfg, nil +} + func (self CgrJsonCfg) CacheJsonCfg() (*CacheJsonCfg, error) { rawCfg, hasKey := self[CACHE_JSN] if !hasKey { diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 8edf30127..9b7bf33c5 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -256,6 +256,12 @@ type FsConnJsonCfg struct { Alias *string } +type RpcConnsJson struct { + Strategy *string + PoolSize *int + Conns *[]*RemoteHostJson +} + // Represents one connection instance towards a rater/cdrs server type RemoteHostJson struct { Address *string diff --git a/config/smconfig.go b/config/smconfig.go index 46aa32507..67bb866ba 100644 --- a/config/smconfig.go +++ b/config/smconfig.go @@ -33,6 +33,32 @@ func NewDfltRemoteHost() *RemoteHost { return &dfltVal } +type RpcConn struct { + Strategy string + PoolSize int + Conns []*RemoteHost +} + +func (rC *RpcConn) loadFromJsonCfg(jsnCfg *RpcConnsJson) (err error) { + if jsnCfg == nil { + return + } + if jsnCfg.Strategy != nil { + rC.Strategy = *jsnCfg.Strategy + } + if jsnCfg.PoolSize != nil { + rC.PoolSize = *jsnCfg.PoolSize + } + if jsnCfg.Conns != nil { + rC.Conns = make([]*RemoteHost, len(*jsnCfg.Conns)) + for idx, jsnHaCfg := range *jsnCfg.Conns { + rC.Conns[idx] = NewDfltRemoteHost() + rC.Conns[idx].loadFromJsonCfg(jsnHaCfg) + } + } + return +} + // One connection to Rater type RemoteHost struct { Address string diff --git a/engine/version.go b/engine/version.go index 8974e2d32..6bd0bf447 100644 --- a/engine/version.go +++ b/engine/version.go @@ -34,6 +34,7 @@ var ( utils.SharedGroups: "cgr-migrator -exec=*shared_groups", utils.Thresholds: "cgr-migrator -exec=*thresholds", utils.LoadIDsVrs: "cgr-migrator -exec=*load_ids", + utils.Filters: "cgr-migrator -exec=*filters", } storDBVers = map[string]string{ utils.CostDetails: "cgr-migrator -exec=*cost_details", diff --git a/migrator/migrator.go b/migrator/migrator.go index 3b7610420..d9f4b6af3 100755 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -125,6 +125,8 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateThresholds() case utils.MetaAttributes: err = m.migrateAttributeProfile() + case utils.MetaFilters: + err = m.migrateFilters() //only Move case utils.MetaRatingPlans: err = m.migrateRatingPlans() @@ -136,8 +138,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateReverseDestinations() case utils.MetaTimings: err = m.migrateTimings() - case utils.MetaFilters: - err = m.migrateFilters() case utils.MetaResources: err = m.migrateResources() case MetaAliases: