From 82ecd234f986d7dc891c7d8fbd473bf3d35bdb1d Mon Sep 17 00:00:00 2001 From: porosnicuadrian Date: Fri, 18 Sep 2020 18:13:47 +0300 Subject: [PATCH] Updated eescfg AsMapInterface method and uploaded tests for AsMapInterface and load methods --- config/cachecfg.go | 16 +- config/config.go | 2 +- config/eescfg.go | 63 ++++--- config/eescfg_test.go | 396 ++++++++++++++++++++++++++++++++++++++++++ config/erscfg.go | 97 ++++++----- config/erscfg_test.go | 2 +- utils/consts.go | 3 +- 7 files changed, 499 insertions(+), 80 deletions(-) diff --git a/config/cachecfg.go b/config/cachecfg.go index e1cd72a43..9bdbc4c89 100755 --- a/config/cachecfg.go +++ b/config/cachecfg.go @@ -60,18 +60,20 @@ func (cParam *CacheParamCfg) loadFromJsonCfg(jsnCfg *CacheParamJsonCfg) error { return nil } -func (cParam *CacheParamCfg) AsMapInterface() map[string]interface{} { - var TTL string = "" - if cParam.TTL != 0 { - TTL = cParam.TTL.String() - } - return map[string]interface{}{ +func (cParam *CacheParamCfg) AsMapInterface() (initialMP map[string]interface{}) { + initialMP = map[string]interface{}{ utils.LimitCfg: cParam.Limit, - utils.TTLCfg: TTL, utils.StaticTTLCfg: cParam.StaticTTL, utils.PrecacheCfg: cParam.Precache, utils.ReplicateCfg: cParam.Replicate, } + + var TTL string = utils.EmptyString + if cParam.TTL != 0 { + TTL = cParam.TTL.String() + } + initialMP[utils.TTLCfg] = TTL + return } // CacheCfg used to store the cache config diff --git a/config/config.go b/config/config.go index be054bbbd..b35e75d6a 100755 --- a/config/config.go +++ b/config/config.go @@ -743,7 +743,7 @@ func (cfg *CGRConfig) loadEesCfg(jsnCfg *CgrJsonCfg) (err error) { if jsnEEsCfg, err = jsnCfg.EEsJsonCfg(); err != nil { return } - return cfg.eesCfg.loadFromJsonCfg(jsnEEsCfg, cfg.templates, cfg.generalCfg.RSRSep, cfg.dfltEvExp, cfg.generalCfg.RSRSep) + return cfg.eesCfg.loadFromJsonCfg(jsnEEsCfg, cfg.templates, cfg.generalCfg.RSRSep, cfg.dfltEvExp) } // loadRateSCfg loads the rates section of the configuration diff --git a/config/eescfg.go b/config/eescfg.go index 702f4c429..fffd55ae3 100644 --- a/config/eescfg.go +++ b/config/eescfg.go @@ -31,7 +31,7 @@ type EEsCfg struct { Exporters []*EventExporterCfg } -func (eeS *EEsCfg) loadFromJsonCfg(jsnCfg *EEsJsonCfg, msgTemplates map[string][]*FCTemplate, sep string, dfltExpCfg *EventExporterCfg, separator string) (err error) { +func (eeS *EEsCfg) loadFromJsonCfg(jsnCfg *EEsJsonCfg, msgTemplates map[string][]*FCTemplate, sep string, dfltExpCfg *EventExporterCfg) (err error) { if jsnCfg == nil { return } @@ -106,16 +106,26 @@ func (eeS *EEsCfg) Clone() (cln *EEsCfg) { return } -func (eeS *EEsCfg) AsMapInterface(separator string) map[string]interface{} { - exporters := make([]map[string]interface{}, len(eeS.Exporters)) - for i, item := range eeS.Exporters { - exporters[i] = item.AsMapInterface(separator) - } - return map[string]interface{}{ +func (eeS *EEsCfg) AsMapInterface(separator string) (initialMP map[string]interface{}) { + initialMP = map[string]interface{}{ utils.EnabledCfg: eeS.Enabled, utils.AttributeSConnsCfg: eeS.AttributeSConns, - utils.ExportersCfg: exporters, } + if eeS.Cache != nil { + cache := make(map[string]interface{}, len(eeS.Cache)) + for key, value := range eeS.Cache { + cache[key] = value.AsMapInterface() + } + initialMP[utils.CacheCfg] = cache + } + if eeS.Exporters != nil { + exporters := make([]map[string]interface{}, len(eeS.Exporters)) + for i, item := range eeS.Exporters { + exporters[i] = item.AsMapInterface(separator) + } + initialMP[utils.ExportersCfg] = exporters + } + return } type EventExporterCfg struct { @@ -287,27 +297,12 @@ func (eeC *EventExporterCfg) Clone() (cln *EventExporterCfg) { return } -func (eeC *EventExporterCfg) AsMapInterface(separator string) map[string]interface{} { - var tenant string - if eeC.Tenant != nil { - values := make([]string, len(eeC.Tenant)) - for i, item := range eeC.Tenant { - values[i] = item.Rules - } - tenant = strings.Join(values, separator) - } - - fields := make([]map[string]interface{}, 0, len(eeC.Fields)) - for _, fld := range eeC.Fields { - fields = append(fields, fld.AsMapInterface(separator)) - } - - return map[string]interface{}{ +func (eeC *EventExporterCfg) AsMapInterface(separator string) (initialMP map[string]interface{}) { + initialMP = map[string]interface{}{ utils.IDCfg: eeC.ID, utils.TypeCfg: eeC.Type, utils.ExportPath: eeC.ExportPath, utils.ExportPathCfg: eeC.FieldSep, - utils.TenantCfg: tenant, utils.TimezoneCfg: eeC.Timezone, utils.FiltersCfg: eeC.Filters, utils.FlagsCfg: eeC.Flags.SliceFlags(), @@ -316,7 +311,23 @@ func (eeC *EventExporterCfg) AsMapInterface(separator string) map[string]interfa utils.SynchronousCfg: eeC.Synchronous, utils.AttemptsCfg: eeC.Attempts, utils.FieldSeparatorCfg: eeC.FieldSep, - utils.FieldsCfg: fields, utils.OptsCfg: eeC.Opts, } + if eeC.Tenant != nil { + var tenant string + values := make([]string, len(eeC.Tenant)) + for i, item := range eeC.Tenant { + values[i] = item.Rules + } + tenant = strings.Join(values, separator) + initialMP[utils.TenantCfg] = tenant + } + if eeC.Fields != nil { + fields := make([]map[string]interface{}, 0, len(eeC.Fields)) + for _, fld := range eeC.Fields { + fields = append(fields, fld.AsMapInterface(separator)) + } + initialMP[utils.FieldsCfg] = fields + } + return } diff --git a/config/eescfg_test.go b/config/eescfg_test.go index 17df19253..b7d07a81c 100644 --- a/config/eescfg_test.go +++ b/config/eescfg_test.go @@ -430,3 +430,399 @@ func TestEventExporterSameID(t *testing.T) { t.Errorf("Expected: %+v ,\n recived: %+v", utils.ToJSON(expectedEEsCfg), utils.ToJSON(cfg.eesCfg)) } } + +func TestEEsCfgloadFromJsonCfg(t *testing.T) { + jsonCfg := &EEsJsonCfg{ + Enabled: utils.BoolPointer(true), + Attributes_conns: &[]string{"*conn1", "*conn2"}, + Cache: &map[string]*CacheParamJsonCfg{ + utils.MetaFileCSV: { + Limit: utils.IntPointer(-2), + Ttl: utils.StringPointer("1s"), + Static_ttl: utils.BoolPointer(false), + }, + }, + Exporters: &[]*EventExporterJsonCfg{ + { + Id: utils.StringPointer("CSVExporter"), + Type: utils.StringPointer("*file_csv"), + Filters: &[]string{}, + Attribute_ids: &[]string{}, + Flags: &[]string{"*dryrun"}, + Export_path: utils.StringPointer("/tmp/testCSV"), + Tenant: nil, + Timezone: utils.StringPointer("UTC"), + Synchronous: utils.BoolPointer(true), + Attempts: utils.IntPointer(1), + Field_separator: utils.StringPointer(","), + Fields: &[]*FcTemplateJsonCfg{ + { + Tag: utils.StringPointer(utils.CGRID), + Path: utils.StringPointer("*exp.CGRID"), + Type: utils.StringPointer(utils.MetaVariable), + Value: utils.StringPointer("~*req.CGRID"), + }, + }, + }, + }, + } + expectedCfg := &EEsCfg{ + Enabled: true, + AttributeSConns: []string{"*conn1", "*conn2"}, + Cache: map[string]*CacheParamCfg{ + utils.MetaFileCSV: { + Limit: -2, + TTL: 1 * time.Second, + StaticTTL: false, + }, + }, + Exporters: []*EventExporterCfg{ + { + ID: utils.MetaDefault, + Type: utils.META_NONE, + FieldSep: ",", + Tenant: nil, + ExportPath: "/var/spool/cgrates/ees", + Attempts: 1, + Timezone: utils.EmptyString, + Filters: []string{}, + AttributeSIDs: []string{}, + Flags: utils.FlagsWithParams{}, + contentFields: []*FCTemplate{ + { + Tag: utils.CGRID, + Path: "*exp.CGRID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.CGRID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.RunID, + Path: "*exp.RunID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.RunID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.ToR, + Path: "*exp.ToR", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.ToR", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.OriginID, + Path: "*exp.OriginID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.OriginID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.RequestType, + Path: "*exp.RequestType", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.RequestType", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Tenant, + Path: "*exp.Tenant", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Tenant", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Category, + Path: "*exp.Category", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Category", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Account, + Path: "*exp.Account", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Account", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Subject, + Path: "*exp.Subject", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Subject", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Destination, + Path: "*exp.Destination", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Destination", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.SetupTime, + Path: "*exp.SetupTime", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.SetupTime", utils.INFIELD_SEP), + Layout: "2006-01-02T15:04:05Z07:00", + }, + { + Tag: utils.AnswerTime, + Path: "*exp.AnswerTime", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.AnswerTime", utils.INFIELD_SEP), + Layout: "2006-01-02T15:04:05Z07:00", + }, + { + Tag: utils.Usage, + Path: "*exp.Usage", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Usage", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Cost, + Path: "*exp.Cost", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Cost{*round:4}", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + }, + Fields: []*FCTemplate{ + { + Tag: utils.CGRID, + Path: "*exp.CGRID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.CGRID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.RunID, + Path: "*exp.RunID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.RunID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.ToR, + Path: "*exp.ToR", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.ToR", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.OriginID, + Path: "*exp.OriginID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.OriginID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.RequestType, + Path: "*exp.RequestType", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.RequestType", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Tenant, + Path: "*exp.Tenant", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Tenant", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Category, + Path: "*exp.Category", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Category", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Account, + Path: "*exp.Account", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Account", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Subject, + Path: "*exp.Subject", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Subject", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Destination, + Path: "*exp.Destination", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Destination", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.SetupTime, + Path: "*exp.SetupTime", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.SetupTime", utils.INFIELD_SEP), + Layout: "2006-01-02T15:04:05Z07:00", + }, + { + Tag: utils.AnswerTime, + Path: "*exp.AnswerTime", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.AnswerTime", utils.INFIELD_SEP), + Layout: "2006-01-02T15:04:05Z07:00", + }, + { + Tag: utils.Usage, + Path: "*exp.Usage", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Usage", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + { + Tag: utils.Cost, + Path: "*exp.Cost", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.Cost{*round:4}", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + }, + headerFields: []*FCTemplate{}, + trailerFields: []*FCTemplate{}, + Opts: make(map[string]interface{}), + }, + { + ID: "CSVExporter", + Type: "*file_csv", + Filters: []string{}, + AttributeSIDs: []string{}, + Flags: utils.FlagsWithParamsFromSlice([]string{utils.MetaDryRun}), + ExportPath: "/tmp/testCSV", + Tenant: nil, + Timezone: "UTC", + Synchronous: true, + Attempts: 1, + FieldSep: ",", + headerFields: []*FCTemplate{}, + trailerFields: []*FCTemplate{}, + contentFields: []*FCTemplate{ + { + Tag: utils.CGRID, + Path: "*exp.CGRID", + Type: utils.MetaVariable, + Value: NewRSRParsersMustCompile("~*req.CGRID", utils.INFIELD_SEP), + Layout: time.RFC3339, + }, + }, + Opts: make(map[string]interface{}), + Fields: []*FCTemplate{ + {Tag: utils.CGRID, Path: "*exp.CGRID", Type: utils.MetaVariable, Value: NewRSRParsersMustCompile("~*req.CGRID", utils.INFIELD_SEP), Layout: time.RFC3339}, + }, + }, + }, + } + for _, profile := range expectedCfg.Exporters { + for _, v := range profile.Fields { + v.ComputePath() + } + for _, v := range profile.contentFields { + v.ComputePath() + } + } + if cgrCfg, err := NewDefaultCGRConfig(); err != nil { + t.Error(err) + } else if err := cgrCfg.eesCfg.loadFromJsonCfg(jsonCfg, cgrCfg.templates, cgrCfg.generalCfg.RSRSep, cgrCfg.dfltEvExp); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(expectedCfg, cgrCfg.eesCfg) { + + t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedCfg), utils.ToJSON(cgrCfg.eesCfg)) + } +} + +func TestEEsCfgAsMapInterface(t *testing.T) { + cfgJSONStr := `{ + "ees": { + "enabled": true, + "attributes_conns":["*conn1","*conn2"], + "cache": { + "*file_csv": {"limit": -2, "precache": false, "replicate": false, "ttl": "1s", "static_ttl": false} + }, + "exporters": [ + { + "id": "CSVExporter", + "type": "*file_csv", + "export_path": "/tmp/testCSV", + "opts": {}, + "tenant": "", + "timezone": "UTC", + "filters": [], + "flags": [], + "attribute_ids": [], + "attribute_context": "", + "synchronous": false, + "attempts": 1, + "field_separator": ",", + "fields":[ + {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"} + ] + }] + } + }` + eMap := map[string]interface{}{ + utils.EnabledCfg: true, + utils.AttributeSConnsCfg: []string{"*conn1", "*conn2"}, + utils.CacheCfg: map[string]interface{}{ + utils.MetaFileCSV: map[string]interface{}{ + utils.LimitCfg: -2, + utils.PrecacheCfg: false, + utils.ReplicateCfg: false, + utils.TTLCfg: "1s", + utils.StaticTTLCfg: false, + }, + }, + utils.ExportersCfg: []map[string]interface{}{ + { + utils.IdCfg: "CSVExporter", + utils.TypeCfg: "*file_csv", + utils.ExportPathCfg: "/tmp/testCSV", + utils.OptsCfg: map[string]interface{}{}, + utils.TenantCfg: nil, + utils.TimezoneCfg: "UTC", + utils.FiltersCfg: []string{}, + utils.FlagsCfg: utils.FlagsWithParams{}, + utils.AttributeIDsCfg: []string{}, + utils.AttributeContextCfg: nil, + utils.SynchronousCfg: false, + utils.AttemptsCfg: 1, + utils.FieldSepCfg: ",", + utils.FieldsCfg: []map[string]interface{}{ + { + utils.TagCfg: utils.CGRID, + utils.PathCfg: "*exp.CGRID", + utils.TypeCfg: utils.MetaVariable, + utils.ValueCfg: "~*req.CGRID", + }, + }, + }, + }, + } + if cgrCfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil { + t.Error(err) + } else { + rcv := cgrCfg.eesCfg.AsMapInterface(cgrCfg.generalCfg.RSRSep) + if !reflect.DeepEqual(eMap[utils.ExportersCfg].([]map[string]interface{})[0][utils.Flags], + rcv[utils.ExportersCfg].([]map[string]interface{})[0][utils.Flags]) { + t.Errorf("Expecetd %+v, received %+v", eMap[utils.ExportersCfg].([]map[string]interface{})[0][utils.Flags], + rcv[utils.ExportersCfg].([]map[string]interface{})[0][utils.Flags]) + } else if !reflect.DeepEqual(eMap[utils.ExportersCfg].([]map[string]interface{})[0][utils.FieldsCfg].([]map[string]interface{})[0][utils.ValueCfg], + rcv[utils.ExportersCfg].([]map[string]interface{})[0][utils.FieldsCfg].([]map[string]interface{})[0][utils.ValueCfg]) { + t.Errorf("Expected %+v, received %+v", eMap[utils.ExportersCfg].([]map[string]interface{})[0][utils.FieldsCfg].([]map[string]interface{})[0][utils.ValueCfg], + rcv[utils.ExportersCfg].([]map[string]interface{})[0][utils.FieldsCfg].([]map[string]interface{})[0][utils.ValueCfg]) + } else if !reflect.DeepEqual(eMap[utils.AttributeSConnsCfg], rcv[utils.AttributeSConnsCfg]) { + t.Errorf("Expected %+v, received %+v", eMap[utils.AttributeSConnsCfg], rcv[utils.AttributeSConnsCfg]) + } else if !reflect.DeepEqual(eMap[utils.CacheCfg].(map[string]interface{})[utils.MetaFileCSV], rcv[utils.CacheCfg].(map[string]interface{})[utils.MetaFileCSV]) { + t.Errorf("Expected %+v \n, received %+v", eMap[utils.CacheCfg].(map[string]interface{})[utils.MetaFileCSV], rcv[utils.CacheCfg].(map[string]interface{})[utils.MetaFileCSV]) + } + } +} diff --git a/config/erscfg.go b/config/erscfg.go index 652d8a6a2..8dbd78553 100644 --- a/config/erscfg.go +++ b/config/erscfg.go @@ -99,16 +99,19 @@ func (erS *ERsCfg) Clone() (cln *ERsCfg) { return } -func (erS *ERsCfg) AsMapInterface(separator string) map[string]interface{} { - readers := make([]map[string]interface{}, len(erS.Readers)) - for i, item := range erS.Readers { - readers[i] = item.AsMapInterface(separator) - } - return map[string]interface{}{ +func (erS *ERsCfg) AsMapInterface(separator string) (initialMP map[string]interface{}) { + initialMP = map[string]interface{}{ utils.EnabledCfg: erS.Enabled, utils.SessionSConnsCfg: erS.SessionSConns, - utils.ReadersCfg: readers, } + if erS.Readers != nil { + readers := make([]map[string]interface{}, len(erS.Readers)) + for i, item := range erS.Readers { + readers[i] = item.AsMapInterface(separator) + } + initialMP[utils.ReadersCfg] = readers + } + return } type EventReaderCfg struct { @@ -270,10 +273,29 @@ func (er *EventReaderCfg) Clone() (cln *EventReaderCfg) { return } -func (er *EventReaderCfg) AsMapInterface(separator string) map[string]interface{} { - xmlRootPath := make([]string, len(er.XmlRootPath)) - for i, item := range er.XmlRootPath { - xmlRootPath[i] = item +func (er *EventReaderCfg) AsMapInterface(separator string) (initialMP map[string]interface{}) { + initialMP = map[string]interface{}{ + utils.IDCfg: er.ID, + utils.TypeCfg: er.Type, + utils.RowLengthCfg: er.RowLength, + utils.FieldSepCfg: er.FieldSep, + utils.HeaderDefCharCfg: er.HeaderDefineChar, + utils.ConcurrentReqsCfg: er.ConcurrentReqs, + utils.SourcePathCfg: er.SourcePath, + utils.ProcessedPathCfg: er.ProcessedPath, + utils.TimezoneCfg: er.Timezone, + utils.FiltersCfg: er.Filters, + utils.FlagsCfg: er.Flags.SliceFlags(), + utils.FailedCallsPrefixCfg: er.FailedCallsPrefix, + utils.PartialCacheExpiryActionCfg: er.PartialCacheExpiryAction, + utils.OptsCfg: er.Opts, + } + if er.XmlRootPath != nil { + xmlRootPath := make([]string, len(er.XmlRootPath)) + for i, item := range er.XmlRootPath { + xmlRootPath[i] = item + } + initialMP[utils.XmlRootPathCfg] = xmlRootPath } var tenant string if er.Tenant != nil { @@ -282,16 +304,23 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]interface{ values[i] = item.Rules } tenant = strings.Join(values, separator) + initialMP[utils.TenantCfg] = tenant + } + if er.Fields != nil { + fields := make([]map[string]interface{}, len(er.Fields)) + for i, item := range er.Fields { + fields[i] = item.AsMapInterface(separator) + } + initialMP[utils.FieldsCfg] = fields + } + if er.CacheDumpFields != nil { + cacheDumpFields := make([]map[string]interface{}, len(er.CacheDumpFields)) + for i, item := range er.CacheDumpFields { + cacheDumpFields[i] = item.AsMapInterface(separator) + } + initialMP[utils.CacheDumpFieldsCfg] = cacheDumpFields } - fields := make([]map[string]interface{}, len(er.Fields)) - for i, item := range er.Fields { - fields[i] = item.AsMapInterface(separator) - } - cacheDumpFields := make([]map[string]interface{}, len(er.CacheDumpFields)) - for i, item := range er.CacheDumpFields { - cacheDumpFields[i] = item.AsMapInterface(separator) - } var runDelay string if er.RunDelay > 0 { runDelay = er.RunDelay.String() @@ -300,32 +329,12 @@ func (er *EventReaderCfg) AsMapInterface(separator string) map[string]interface{ } else { runDelay = "-1" } + initialMP[utils.RunDelayCfg] = runDelay - var partialRecordCache string = "0" if er.PartialRecordCache != 0 { - partialRecordCache = er.PartialRecordCache.String() - } - - return map[string]interface{}{ - utils.IDCfg: er.ID, - utils.TypeCfg: er.Type, - utils.RowLengthCfg: er.RowLength, - utils.FieldSepCfg: er.FieldSep, - utils.HeaderDefCharCfg: er.HeaderDefineChar, - utils.RunDelayCfg: runDelay, - utils.ConcurrentReqsCfg: er.ConcurrentReqs, - utils.SourcePathCfg: er.SourcePath, - utils.ProcessedPathCfg: er.ProcessedPath, - utils.XmlRootPathCfg: xmlRootPath, - utils.TenantCfg: tenant, - utils.TimezoneCfg: er.Timezone, - utils.FiltersCfg: er.Filters, - utils.FlagsCfg: er.Flags.SliceFlags(), - utils.FailedCallsPrefixCfg: er.FailedCallsPrefix, - utils.PartialRecordCacheCfg: partialRecordCache, - utils.PartialCacheExpiryActionCfg: er.PartialCacheExpiryAction, - utils.FieldsCfg: fields, - utils.CacheDumpFieldsCfg: cacheDumpFields, - utils.OptsCfg: er.Opts, + initialMP[utils.PartialRecordCacheCfg] = er.PartialRecordCache.String() + } else { + initialMP[utils.PartialRecordCacheCfg] = "0" } + return } diff --git a/config/erscfg_test.go b/config/erscfg_test.go index 01f74519a..4257eef52 100644 --- a/config/erscfg_test.go +++ b/config/erscfg_test.go @@ -451,6 +451,6 @@ func TestERsCfgAsMapInterface(t *testing.T) { if cfg, err := NewCGRConfigFromJsonStringWithDefaults(cfgJSONStr); err != nil { t.Error(err) } else if rcv := cfg.ersCfg.AsMapInterface(utils.EmptyString); !reflect.DeepEqual(eMap, rcv) { - t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToJSON(eMap), utils.ToJSON(rcv)) + t.Errorf("\nExpected: %+v\nRecived: %+v", utils.ToIJSON(eMap), utils.ToIJSON(rcv)) } } diff --git a/utils/consts.go b/utils/consts.go index 8ec38aadc..d7f3815b5 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -2260,7 +2260,8 @@ const ( DataDbCfg = "data_db" // from JSON StorDbCfg = "stor_db" // from JSON TlsCfg = "tls" // from JSON - CacheCfg = "caches" // from JSON + CacheCfg = "cache" //from JSON + CachesCfg = "caches" // from JSON HttpCfg = "http" // from JSON FilterSCfg = "filters" // from JSON RalsCfg = "rals" // from JSON