diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 82790fd58..eea2c42bb 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -74,7 +74,6 @@ var ( func startCdrcs(internalCdrSChan, internalRaterChan chan rpcclient.RpcClientConnection, exitChan chan bool, filterSChan chan *engine.FilterS) { - // Not sure here if FilterS is passed correct at line 103 in fo start cdrc filterS := <-filterSChan filterSChan <- filterS cdrcInitialized := false // Control whether the cdrc was already initialized (so we don't reload in that case) @@ -840,8 +839,10 @@ func startFilterService(filterSChan chan *engine.FilterS, cacheS *engine.CacheS, // loaderService will start and register APIs for LoaderService if enabled func loaderService(cacheS *engine.CacheS, cfg *config.CGRConfig, - dm *engine.DataManager, server *utils.Server, exitChan chan bool) { - ldrS := loaders.NewLoaderService(dm, cfg.LoaderCfg(), cfg.DefaultTimezone) + dm *engine.DataManager, server *utils.Server, exitChan chan bool, filterSChan chan *engine.FilterS) { + filterS := <-filterSChan + filterSChan <- filterS + ldrS := loaders.NewLoaderService(dm, cfg.LoaderCfg(), cfg.DefaultTimezone, filterS) if !ldrS.Enabled() { return } @@ -1341,7 +1342,7 @@ func main() { internalRaterChan, cacheS, dm, server, exitChan) } - go loaderService(cacheS, cfg, dm, server, exitChan) + go loaderService(cacheS, cfg, dm, server, exitChan, filterSChan) // Serve rpc connections go startRpc(server, internalRaterChan, internalCdrSChan, internalCdrStatSChan, diff --git a/config/config.go b/config/config.go index a111c9a1b..408d27d04 100755 --- a/config/config.go +++ b/config/config.go @@ -516,7 +516,7 @@ func (self *CGRConfig) checkConfigSanity() error { for _, field := range data.Fields { if field.Type != utils.META_COMPOSED && field.Type != utils.MetaString { - return fmt.Errorf("<%s> invalid field type %s for %s at %s", utils.LoaderS, field.Type, data.Type, field.Tag) + return fmt.Errorf("<%s> invalid field type %s for %s at %s", utils.LoaderS, field.Type, data.Type, field.ID) } } } diff --git a/config/config_defaults.go b/config/config_defaults.go index 9d59bb844..b2d73b334 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -482,6 +482,7 @@ const CGRATES_CFG_JSON = ` { "id": "*default", // identifier of the Loader "enabled": false, // starts as service: . + "tenant": "cgrates.org", // tenant used in filterS.Pass "dry_run": false, // do not send the CDRs to CDRS, just parse them "run_delay": 0, // sleep interval in seconds between consecutive runs, 0 to use automation via inotify "lock_filename": ".cgr.lck", // Filename containing concurrency lock in case of delayed processing @@ -496,116 +497,116 @@ const CGRATES_CFG_JSON = ` "type": "*attributes", // data source type "file_name": "Attributes.csv", // file name in the tp_in_dir "fields": [ - {"tag": "TenantID", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ProfileID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "Contexts", "field_id": "Contexts", "type": "*composed", "value": "2"}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "3"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "4"}, - {"tag": "FieldName", "field_id": "FieldName", "type": "*composed", "value": "5"}, - {"tag": "Initial", "field_id": "Initial", "type": "*composed", "value": "6"}, - {"tag": "Substitute", "field_id": "Substitute", "type": "*composed", "value": "7"}, - {"tag": "Append", "field_id": "Append", "type": "*composed", "value": "8"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "9"}, + {"id": "TenantID", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ProfileID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "Contexts", "field_id": "Contexts", "type": "*composed", "value": "~2"}, + {"id": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~3"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~4"}, + {"id": "FieldName", "field_id": "FieldName", "type": "*composed", "value": "~5"}, + {"id": "Initial", "field_id": "Initial", "type": "*composed", "value": "~6"}, + {"id": "Substitute", "field_id": "Substitute", "type": "*composed", "value": "~7"}, + {"id": "Append", "field_id": "Append", "type": "*composed", "value": "~8"}, + {"id": "Weight", "field_id": "Weight", "type": "*composed", "value": "~9"}, ], }, { "type": "*filters", // data source type "file_name": "Filters.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterType", "field_id": "FilterType", "type": "*composed", "value": "2"}, - {"tag": "FilterFieldName", "field_id": "FilterFieldName", "type": "*composed", "value": "3"}, - {"tag": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*composed", "value": "4"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "5"}, + {"id": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "FilterType", "field_id": "FilterType", "type": "*composed", "value": "~2"}, + {"id": "FilterFieldName", "field_id": "FilterFieldName", "type": "*composed", "value": "~3"}, + {"id": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*composed", "value": "~4"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~5"}, ], }, { "type": "*resources", // data source type "file_name": "Resources.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "TTL", "field_id": "UsageTTL", "type": "*composed", "value": "4"}, - {"tag": "Limit", "field_id": "Limit", "type": "*composed", "value": "5"}, - {"tag": "AllocationMessage", "field_id": "AllocationMessage", "type": "*composed", "value": "6"}, - {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "7"}, - {"tag": "Stored", "field_id": "Stored", "type": "*composed", "value": "8"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "9"}, - {"tag": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "10"}, + {"id": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"id": "TTL", "field_id": "UsageTTL", "type": "*composed", "value": "~4"}, + {"id": "Limit", "field_id": "Limit", "type": "*composed", "value": "~5"}, + {"id": "AllocationMessage", "field_id": "AllocationMessage", "type": "*composed", "value": "~6"}, + {"id": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "~7"}, + {"id": "Stored", "field_id": "Stored", "type": "*composed", "value": "~8"}, + {"id": "Weight", "field_id": "Weight", "type": "*composed", "value": "~9"}, + {"id": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "~10"}, ], }, { "type": "*stats", // data source type "file_name": "Stats.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "QueueLength", "field_id": "QueueLength", "type": "*composed", "value": "4"}, - {"tag": "TTL", "field_id": "TTL", "type": "*composed", "value": "5"}, - {"tag": "Metrics", "field_id": "Metrics", "type": "*composed", "value": "6"}, - {"tag": "MetricParams", "field_id": "Parameters", "type": "*composed", "value": "7"}, - {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "8"}, - {"tag": "Stored", "field_id": "Stored", "type": "*composed", "value": "9"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "10"}, - {"tag": "MinItems", "field_id": "MinItems", "type": "*composed", "value": "11"}, - {"tag": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "12"}, + {"id": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"id": "QueueLength", "field_id": "QueueLength", "type": "*composed", "value": "~4"}, + {"id": "TTL", "field_id": "TTL", "type": "*composed", "value": "~5"}, + {"id": "Metrics", "field_id": "Metrics", "type": "*composed", "value": "~6"}, + {"id": "MetricParams", "field_id": "Parameters", "type": "*composed", "value": "~7"}, + {"id": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "~8"}, + {"id": "Stored", "field_id": "Stored", "type": "*composed", "value": "~9"}, + {"id": "Weight", "field_id": "Weight", "type": "*composed", "value": "~10"}, + {"id": "MinItems", "field_id": "MinItems", "type": "*composed", "value": "~11"}, + {"id": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "~12"}, ], }, { "type": "*thresholds", // data source type "file_name": "Thresholds.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "MaxHits", "field_id": "MaxHits", "type": "*composed", "value": "4"}, - {"tag": "MinHits", "field_id": "MinHits", "type": "*composed", "value": "5"}, - {"tag": "MinSleep", "field_id": "MinSleep", "type": "*composed", "value": "6"}, - {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "7"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "8"}, - {"tag": "ActionIDs", "field_id": "ActionIDs", "type": "*composed", "value": "9"}, - {"tag": "Async", "field_id": "Async", "type": "*composed", "value": "10"}, + {"id": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"id": "MaxHits", "field_id": "MaxHits", "type": "*composed", "value": "~4"}, + {"id": "MinHits", "field_id": "MinHits", "type": "*composed", "value": "~5"}, + {"id": "MinSleep", "field_id": "MinSleep", "type": "*composed", "value": "~6"}, + {"id": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "~7"}, + {"id": "Weight", "field_id": "Weight", "type": "*composed", "value": "~8"}, + {"id": "ActionIDs", "field_id": "ActionIDs", "type": "*composed", "value": "~9"}, + {"id": "Async", "field_id": "Async", "type": "*composed", "value": "~10"}, ], }, { "type": "*suppliers", // data source type "file_name": "Suppliers.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "Sorting", "field_id": "Sorting", "type": "*composed", "value": "4"}, - {"tag": "SortingParamameters", "field_id": "SortingParamameters", "type": "*composed", "value": "5"}, - {"tag": "SupplierID", "field_id": "SupplierID", "type": "*composed", "value": "6"}, - {"tag": "SupplierFilterIDs", "field_id": "SupplierFilterIDs", "type": "*composed", "value": "7"}, - {"tag": "SupplierAccountIDs", "field_id": "SupplierAccountIDs", "type": "*composed", "value": "8"}, - {"tag": "SupplierRatingPlanIDs", "field_id": "SupplierRatingPlanIDs", "type": "*composed", "value": "9"}, - {"tag": "SupplierResourceIDs", "field_id": "SupplierResourceIDs", "type": "*composed", "value": "10"}, - {"tag": "SupplierStatIDs", "field_id": "SupplierStatIDs", "type": "*composed", "value": "11"}, - {"tag": "SupplierWeight", "field_id": "SupplierWeight", "type": "*composed", "value": "12"}, - {"tag": "SupplierBlocker", "field_id": "SupplierBlocker", "type": "*composed", "value": "13"}, - {"tag": "SupplierParameters", "field_id": "SupplierParameters", "type": "*composed", "value": "14"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "15"}, + {"id": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"id": "Sorting", "field_id": "Sorting", "type": "*composed", "value": "~4"}, + {"id": "SortingParamameters", "field_id": "SortingParamameters", "type": "*composed", "value": "~5"}, + {"id": "SupplierID", "field_id": "SupplierID", "type": "*composed", "value": "~6"}, + {"id": "SupplierFilterIDs", "field_id": "SupplierFilterIDs", "type": "*composed", "value": "~7"}, + {"id": "SupplierAccountIDs", "field_id": "SupplierAccountIDs", "type": "*composed", "value": "~8"}, + {"id": "SupplierRatingPlanIDs", "field_id": "SupplierRatingPlanIDs", "type": "*composed", "value": "~9"}, + {"id": "SupplierResourceIDs", "field_id": "SupplierResourceIDs", "type": "*composed", "value": "~10"}, + {"id": "SupplierStatIDs", "field_id": "SupplierStatIDs", "type": "*composed", "value": "~11"}, + {"id": "SupplierWeight", "field_id": "SupplierWeight", "type": "*composed", "value": "~12"}, + {"id": "SupplierBlocker", "field_id": "SupplierBlocker", "type": "*composed", "value": "~13"}, + {"id": "SupplierParameters", "field_id": "SupplierParameters", "type": "*composed", "value": "~14"}, + {"id": "Weight", "field_id": "Weight", "type": "*composed", "value": "~15"}, ], }, { "type": "*chargers", // data source type "file_name": "Chargers.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "RunID", "field_id": "RunID", "type": "*composed", "value": "4"}, - {"tag": "AttributeIDs", "field_id": "AttributeIDs", "type": "*composed", "value": "5"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "6"}, + {"id": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"id": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"id": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"id": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"id": "RunID", "field_id": "RunID", "type": "*composed", "value": "~4"}, + {"id": "AttributeIDs", "field_id": "AttributeIDs", "type": "*composed", "value": "~5"}, + {"id": "Weight", "field_id": "Weight", "type": "*composed", "value": "~6"}, ], }, ], diff --git a/config/config_json_test.go b/config/config_json_test.go index 7018e834e..cea06b6dd 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -801,6 +801,7 @@ func TestDfLoaderJsonCfg(t *testing.T) { &LoaderJsonCfg{ ID: utils.StringPointer(utils.META_DEFAULT), Enabled: utils.BoolPointer(false), + Tenant: utils.StringPointer("cgrates.org"), Dry_run: utils.BoolPointer(false), Run_delay: utils.IntPointer(0), Lock_filename: utils.StringPointer(".cgr.lck"), @@ -814,353 +815,353 @@ func TestDfLoaderJsonCfg(t *testing.T) { &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaAttributes), File_name: utils.StringPointer(utils.AttributesCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer("TenantID"), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer("TenantID"), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ProfileID"), + &FcTemplateJsonCfg{Id: utils.StringPointer("ProfileID"), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Contexts"), + &FcTemplateJsonCfg{Id: utils.StringPointer("Contexts"), Field_id: utils.StringPointer(utils.Contexts), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterIDs"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterIDs"), Field_id: utils.StringPointer(utils.FilterIDs), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FieldName"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("FieldName"), Field_id: utils.StringPointer(utils.FieldName), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Initial"), + Value: utils.StringPointer("~5")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Initial"), Field_id: utils.StringPointer(utils.Initial), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("6")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Substitute"), + Value: utils.StringPointer("~6")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Substitute"), Field_id: utils.StringPointer(utils.Substitute), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("7")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Append"), + Value: utils.StringPointer("~7")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Append"), Field_id: utils.StringPointer(utils.Append), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("8")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Weight"), + Value: utils.StringPointer("~8")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Weight"), Field_id: utils.StringPointer(utils.Weight), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("9")}, + Value: utils.StringPointer("~9")}, }, }, &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaFilters), File_name: utils.StringPointer(utils.FiltersCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.Tenant), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.ID), + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.ID), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterType"), + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterType"), Field_id: utils.StringPointer("FilterType"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterFieldName"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterFieldName"), Field_id: utils.StringPointer("FilterFieldName"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterFieldValues"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterFieldValues"), Field_id: utils.StringPointer("FilterFieldValues"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, + Value: utils.StringPointer("~5")}, }, }, &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaResources), File_name: utils.StringPointer(utils.ResourcesCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.Tenant), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.ID), + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.ID), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterIDs"), + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterIDs"), Field_id: utils.StringPointer("FilterIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("TTL"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("TTL"), Field_id: utils.StringPointer("UsageTTL"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Limit"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Limit"), Field_id: utils.StringPointer("Limit"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("AllocationMessage"), + Value: utils.StringPointer("~5")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("AllocationMessage"), Field_id: utils.StringPointer("AllocationMessage"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("6")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Blocker"), + Value: utils.StringPointer("~6")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Blocker"), Field_id: utils.StringPointer("Blocker"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("7")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Stored"), + Value: utils.StringPointer("~7")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Stored"), Field_id: utils.StringPointer("Stored"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("8")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Weight"), + Value: utils.StringPointer("~8")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Weight"), Field_id: utils.StringPointer("Weight"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("9")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ThresholdIDs"), + Value: utils.StringPointer("~9")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ThresholdIDs"), Field_id: utils.StringPointer("ThresholdIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("10")}, + Value: utils.StringPointer("~10")}, }, }, &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaStats), File_name: utils.StringPointer(utils.StatsCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.Tenant), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.ID), + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.ID), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterIDs"), + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterIDs"), Field_id: utils.StringPointer("FilterIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("QueueLength"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("QueueLength"), Field_id: utils.StringPointer("QueueLength"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("TTL"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("TTL"), Field_id: utils.StringPointer("TTL"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Metrics"), + Value: utils.StringPointer("~5")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Metrics"), Field_id: utils.StringPointer("Metrics"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("6")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("MetricParams"), + Value: utils.StringPointer("~6")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("MetricParams"), Field_id: utils.StringPointer("Parameters"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("7")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Blocker"), + Value: utils.StringPointer("~7")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Blocker"), Field_id: utils.StringPointer("Blocker"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("8")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Stored"), + Value: utils.StringPointer("~8")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Stored"), Field_id: utils.StringPointer("Stored"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("9")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Weight"), + Value: utils.StringPointer("~9")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Weight"), Field_id: utils.StringPointer("Weight"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("10")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("MinItems"), + Value: utils.StringPointer("~10")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("MinItems"), Field_id: utils.StringPointer("MinItems"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("11")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ThresholdIDs"), + Value: utils.StringPointer("~11")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ThresholdIDs"), Field_id: utils.StringPointer("ThresholdIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("12")}, + Value: utils.StringPointer("~12")}, }, }, &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaThresholds), File_name: utils.StringPointer(utils.ThresholdsCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.Tenant), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.ID), + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.ID), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterIDs"), + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterIDs"), Field_id: utils.StringPointer("FilterIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("MaxHits"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("MaxHits"), Field_id: utils.StringPointer("MaxHits"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("MinHits"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("MinHits"), Field_id: utils.StringPointer("MinHits"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("MinSleep"), + Value: utils.StringPointer("~5")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("MinSleep"), Field_id: utils.StringPointer("MinSleep"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("6")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Blocker"), + Value: utils.StringPointer("~6")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Blocker"), Field_id: utils.StringPointer("Blocker"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("7")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Weight"), + Value: utils.StringPointer("~7")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Weight"), Field_id: utils.StringPointer("Weight"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("8")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActionIDs"), + Value: utils.StringPointer("~8")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActionIDs"), Field_id: utils.StringPointer("ActionIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("9")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Async"), + Value: utils.StringPointer("~9")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Async"), Field_id: utils.StringPointer("Async"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("10")}, + Value: utils.StringPointer("~10")}, }, }, &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaSuppliers), File_name: utils.StringPointer(utils.SuppliersCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.Tenant), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.ID), + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.ID), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterIDs"), + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterIDs"), Field_id: utils.StringPointer("FilterIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Sorting"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Sorting"), Field_id: utils.StringPointer("Sorting"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SortingParamameters"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SortingParamameters"), Field_id: utils.StringPointer("SortingParamameters"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierID"), + Value: utils.StringPointer("~5")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierID"), Field_id: utils.StringPointer("SupplierID"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("6")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierFilterIDs"), + Value: utils.StringPointer("~6")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierFilterIDs"), Field_id: utils.StringPointer("SupplierFilterIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("7")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierAccountIDs"), + Value: utils.StringPointer("~7")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierAccountIDs"), Field_id: utils.StringPointer("SupplierAccountIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("8")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierRatingPlanIDs"), + Value: utils.StringPointer("~8")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierRatingPlanIDs"), Field_id: utils.StringPointer("SupplierRatingPlanIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("9")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierResourceIDs"), + Value: utils.StringPointer("~9")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierResourceIDs"), Field_id: utils.StringPointer("SupplierResourceIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("10")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierStatIDs"), + Value: utils.StringPointer("~10")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierStatIDs"), Field_id: utils.StringPointer("SupplierStatIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("11")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierWeight"), + Value: utils.StringPointer("~11")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierWeight"), Field_id: utils.StringPointer("SupplierWeight"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("12")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierBlocker"), + Value: utils.StringPointer("~12")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierBlocker"), Field_id: utils.StringPointer("SupplierBlocker"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("13")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("SupplierParameters"), + Value: utils.StringPointer("~13")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("SupplierParameters"), Field_id: utils.StringPointer("SupplierParameters"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("14")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Weight"), + Value: utils.StringPointer("~14")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Weight"), Field_id: utils.StringPointer("Weight"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("15")}, + Value: utils.StringPointer("~15")}, }, }, &LoaderJsonDataType{ Type: utils.StringPointer(utils.MetaChargers), File_name: utils.StringPointer(utils.ChargersCsv), - Fields: &[]*CdrFieldJsonCfg{ - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.Tenant), + Fields: &[]*FcTemplateJsonCfg{ + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.Tenant), Field_id: utils.StringPointer(utils.Tenant), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("0"), + Value: utils.StringPointer("~0"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer(utils.ID), + &FcTemplateJsonCfg{Id: utils.StringPointer(utils.ID), Field_id: utils.StringPointer(utils.ID), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("1"), + Value: utils.StringPointer("~1"), Mandatory: utils.BoolPointer(true)}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("FilterIDs"), + &FcTemplateJsonCfg{Id: utils.StringPointer("FilterIDs"), Field_id: utils.StringPointer("FilterIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("2")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("ActivationInterval"), + Value: utils.StringPointer("~2")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("ActivationInterval"), Field_id: utils.StringPointer("ActivationInterval"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("3")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("RunID"), + Value: utils.StringPointer("~3")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("RunID"), Field_id: utils.StringPointer("RunID"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("4")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("AttributeIDs"), + Value: utils.StringPointer("~4")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("AttributeIDs"), Field_id: utils.StringPointer("AttributeIDs"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("5")}, - &CdrFieldJsonCfg{Tag: utils.StringPointer("Weight"), + Value: utils.StringPointer("~5")}, + &FcTemplateJsonCfg{Id: utils.StringPointer("Weight"), Field_id: utils.StringPointer("Weight"), Type: utils.StringPointer(utils.META_COMPOSED), - Value: utils.StringPointer("6")}, + Value: utils.StringPointer("~6")}, }, }, }, diff --git a/config/config_test.go b/config/config_test.go index d0fb4f400..9ea79b3a5 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -1114,6 +1114,7 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) { &LoaderSConfig{ Id: utils.META_DEFAULT, Enabled: false, + Tenant: NewRSRParsersMustCompile("cgrates.org", true), DryRun: false, RunDelay: 0, LockFileName: ".cgr.lck", @@ -1129,360 +1130,360 @@ func TestCgrLoaderCfgITDefaults(t *testing.T) { &LoaderDataType{ Type: utils.MetaAttributes, Filename: utils.AttributesCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "TenantID", + Fields: []*FCTemplate{ + &FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ProfileID", + &FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "Contexts", + &FCTemplate{ID: "Contexts", FieldId: "Contexts", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "FilterIDs", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "FieldName", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "FieldName", FieldId: "FieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Initial", + Value: NewRSRParsersMustCompile("~5", true)}, + &FCTemplate{ID: "Initial", FieldId: "Initial", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Substitute", + Value: NewRSRParsersMustCompile("~6", true)}, + &FCTemplate{ID: "Substitute", FieldId: "Substitute", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Append", + Value: NewRSRParsersMustCompile("~7", true)}, + &FCTemplate{ID: "Append", FieldId: "Append", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Weight", + Value: NewRSRParsersMustCompile("~8", true)}, + &FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~9", true)}, }, }, &LoaderDataType{ Type: utils.MetaFilters, Filename: utils.FiltersCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "Tenant", + Fields: []*FCTemplate{ + &FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ID", + &FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "FilterType", + &FCTemplate{ID: "FilterType", FieldId: "FilterType", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "FilterFieldName", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "FilterFieldName", FieldId: "FilterFieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "FilterFieldValues", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "FilterFieldValues", FieldId: "FilterFieldValues", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~5", true)}, }, }, &LoaderDataType{ Type: utils.MetaResources, Filename: utils.ResourcesCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "Tenant", + Fields: []*FCTemplate{ + &FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ID", + &FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "FilterIDs", + &FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "TTL", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "TTL", FieldId: "UsageTTL", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Limit", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "Limit", FieldId: "Limit", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "AllocationMessage", + Value: NewRSRParsersMustCompile("~5", true)}, + &FCTemplate{ID: "AllocationMessage", FieldId: "AllocationMessage", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Blocker", + Value: NewRSRParsersMustCompile("~6", true)}, + &FCTemplate{ID: "Blocker", FieldId: "Blocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Stored", + Value: NewRSRParsersMustCompile("~7", true)}, + &FCTemplate{ID: "Stored", FieldId: "Stored", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Weight", + Value: NewRSRParsersMustCompile("~8", true)}, + &FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ThresholdIDs", + Value: NewRSRParsersMustCompile("~9", true)}, + &FCTemplate{ID: "ThresholdIDs", FieldId: "ThresholdIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~10", true)}, }, }, &LoaderDataType{ Type: utils.MetaStats, Filename: utils.StatsCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "Tenant", + Fields: []*FCTemplate{ + &FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ID", + &FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "FilterIDs", + &FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "QueueLength", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "QueueLength", FieldId: "QueueLength", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "TTL", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "TTL", FieldId: "TTL", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Metrics", + Value: NewRSRParsersMustCompile("~5", true)}, + &FCTemplate{ID: "Metrics", FieldId: "Metrics", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "MetricParams", + Value: NewRSRParsersMustCompile("~6", true)}, + &FCTemplate{ID: "MetricParams", FieldId: "Parameters", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Blocker", + Value: NewRSRParsersMustCompile("~7", true)}, + &FCTemplate{ID: "Blocker", FieldId: "Blocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Stored", + Value: NewRSRParsersMustCompile("~8", true)}, + &FCTemplate{ID: "Stored", FieldId: "Stored", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Weight", + Value: NewRSRParsersMustCompile("~9", true)}, + &FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "MinItems", + Value: NewRSRParsersMustCompile("~10", true)}, + &FCTemplate{ID: "MinItems", FieldId: "MinItems", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("11", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ThresholdIDs", + Value: NewRSRParsersMustCompile("~11", true)}, + &FCTemplate{ID: "ThresholdIDs", FieldId: "ThresholdIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("12", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~12", true)}, }, }, &LoaderDataType{ Type: utils.MetaThresholds, Filename: utils.ThresholdsCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "Tenant", + Fields: []*FCTemplate{ + &FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ID", + &FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "FilterIDs", + &FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "MaxHits", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "MaxHits", FieldId: "MaxHits", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "MinHits", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "MinHits", FieldId: "MinHits", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "MinSleep", + Value: NewRSRParsersMustCompile("~5", true)}, + &FCTemplate{ID: "MinSleep", FieldId: "MinSleep", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Blocker", + Value: NewRSRParsersMustCompile("~6", true)}, + &FCTemplate{ID: "Blocker", FieldId: "Blocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Weight", + Value: NewRSRParsersMustCompile("~7", true)}, + &FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActionIDs", + Value: NewRSRParsersMustCompile("~8", true)}, + &FCTemplate{ID: "ActionIDs", FieldId: "ActionIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Async", + Value: NewRSRParsersMustCompile("~9", true)}, + &FCTemplate{ID: "Async", FieldId: "Async", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~10", true)}, }, }, &LoaderDataType{ Type: utils.MetaSuppliers, Filename: utils.SuppliersCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "Tenant", + Fields: []*FCTemplate{ + &FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ID", + &FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "FilterIDs", + &FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Sorting", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "Sorting", FieldId: "Sorting", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SortingParamameters", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "SortingParamameters", FieldId: "SortingParamameters", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierID", + Value: NewRSRParsersMustCompile("~5", true)}, + &FCTemplate{ID: "SupplierID", FieldId: "SupplierID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierFilterIDs", + Value: NewRSRParsersMustCompile("~6", true)}, + &FCTemplate{ID: "SupplierFilterIDs", FieldId: "SupplierFilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierAccountIDs", + Value: NewRSRParsersMustCompile("~7", true)}, + &FCTemplate{ID: "SupplierAccountIDs", FieldId: "SupplierAccountIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierRatingPlanIDs", + Value: NewRSRParsersMustCompile("~8", true)}, + &FCTemplate{ID: "SupplierRatingPlanIDs", FieldId: "SupplierRatingPlanIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierResourceIDs", + Value: NewRSRParsersMustCompile("~9", true)}, + &FCTemplate{ID: "SupplierResourceIDs", FieldId: "SupplierResourceIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierStatIDs", + Value: NewRSRParsersMustCompile("~10", true)}, + &FCTemplate{ID: "SupplierStatIDs", FieldId: "SupplierStatIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("11", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierWeight", + Value: NewRSRParsersMustCompile("~11", true)}, + &FCTemplate{ID: "SupplierWeight", FieldId: "SupplierWeight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("12", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierBlocker", + Value: NewRSRParsersMustCompile("~12", true)}, + &FCTemplate{ID: "SupplierBlocker", FieldId: "SupplierBlocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("13", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "SupplierParameters", + Value: NewRSRParsersMustCompile("~13", true)}, + &FCTemplate{ID: "SupplierParameters", FieldId: "SupplierParameters", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("14", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Weight", + Value: NewRSRParsersMustCompile("~14", true)}, + &FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("15", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~15", true)}, }, }, &LoaderDataType{ Type: utils.MetaChargers, Filename: utils.ChargersCsv, - Fields: []*CfgCdrField{ - &CfgCdrField{Tag: "Tenant", + Fields: []*FCTemplate{ + &FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &CfgCdrField{Tag: "ID", + &FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &CfgCdrField{Tag: "FilterIDs", + &FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "ActivationInterval", + Value: NewRSRParsersMustCompile("~2", true)}, + &FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "RunID", + Value: NewRSRParsersMustCompile("~3", true)}, + &FCTemplate{ID: "RunID", FieldId: "RunID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "AttributeIDs", + Value: NewRSRParsersMustCompile("~4", true)}, + &FCTemplate{ID: "AttributeIDs", FieldId: "AttributeIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &CfgCdrField{Tag: "Weight", + Value: NewRSRParsersMustCompile("~5", true)}, + &FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, + Value: NewRSRParsersMustCompile("~6", true)}, }, }, }, }, } if !reflect.DeepEqual(eCfg, cgrCfg.loaderCfg) { - t.Errorf("received: %+v, expecting: %+v", + t.Errorf("received: %+v, \n expecting: %+v", utils.ToJSON(eCfg), utils.ToJSON(cgrCfg.loaderCfg)) } } diff --git a/config/libconfig_json.go b/config/libconfig_json.go index c46c18e08..5e32f2f81 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -481,12 +481,13 @@ type SupplierSJsonCfg struct { type LoaderJsonDataType struct { Type *string File_name *string - Fields *[]*CdrFieldJsonCfg + Fields *[]*FcTemplateJsonCfg } type LoaderJsonCfg struct { ID *string Enabled *bool + Tenant *string Dry_run *bool Run_delay *int Lock_filename *string diff --git a/config/loadersconfig.go b/config/loadersconfig.go index 4919c2c68..7cad19bdc 100644 --- a/config/loadersconfig.go +++ b/config/loadersconfig.go @@ -33,6 +33,7 @@ func NewDfltLoaderSConfig() *LoaderSConfig { type LoaderSConfig struct { // rename to LoaderSConfig Id string Enabled bool + Tenant RSRParsers DryRun bool RunDelay time.Duration LockFileName string @@ -54,11 +55,10 @@ func NewDfltLoaderDataTypeConfig() *LoaderDataType { type LoaderDataType struct { //rename to LoaderDataType Type string Filename string - Fields []*CfgCdrField + Fields []*FCTemplate } func (self *LoaderDataType) loadFromJsonCfg(jsnCfg *LoaderJsonDataType) error { - if jsnCfg == nil { return nil } @@ -69,11 +69,7 @@ func (self *LoaderDataType) loadFromJsonCfg(jsnCfg *LoaderJsonDataType) error { self.Filename = *jsnCfg.File_name } if jsnCfg.Fields != nil { - if fields, err := CfgCdrFieldsFromCdrFieldsJsonCfg(*jsnCfg.Fields); err != nil { - return err - } else { - self.Fields = fields - } + self.Fields = FCTemplatesFromFCTemapltesJsonCfg(*jsnCfg.Fields) } return nil } @@ -88,6 +84,9 @@ func (self *LoaderSConfig) loadFromJsonCfg(jsnCfg *LoaderJsonCfg) error { if jsnCfg.Enabled != nil { self.Enabled = *jsnCfg.Enabled } + if jsnCfg.Tenant != nil { + self.Tenant = NewRSRParsersMustCompile(*jsnCfg.Tenant, true) + } if jsnCfg.Dry_run != nil { self.DryRun = *jsnCfg.Dry_run } @@ -131,6 +130,7 @@ func (self *LoaderSConfig) Clone() *LoaderSConfig { clnLoader := new(LoaderSConfig) clnLoader.Id = self.Id clnLoader.Enabled = self.Enabled + clnLoader.Tenant = self.Tenant clnLoader.DryRun = self.DryRun clnLoader.RunDelay = self.RunDelay clnLoader.LockFileName = self.LockFileName diff --git a/config/rsrparser.go b/config/rsrparser.go index b53dc18fd..a7af9117e 100644 --- a/config/rsrparser.go +++ b/config/rsrparser.go @@ -113,6 +113,17 @@ func (prsrs RSRParsers) ParseCDR(dP DataProvider) (out string, err error) { return } +func (prsrs RSRParsers) ParseLoaderSDP(dP DataProvider) (out string, err error) { + for _, prsr := range prsrs { + if outPrsr, err := prsr.ParseLoaderSDP(dP); err != nil { + return "", err + } else { + out += outPrsr + } + } + return +} + func NewRSRParser(parserRules string, allFiltersMatch bool) (rsrParser *RSRParser, err error) { if len(parserRules) == 0 { return @@ -285,3 +296,16 @@ func (prsr *RSRParser) ParseCDR(dP DataProvider) (out string, err error) { } return prsr.ParseValue(outStr) } + +// ParseLoaderSDP Parse a DataProvider from LoaderS +// data there can be FileName:ColNumber and need to be splitted by ":" +func (prsr *RSRParser) ParseLoaderSDP(dP DataProvider) (out string, err error) { + var outStr string + if prsr.attrValue == "" { + if outStr, err = dP.FieldAsString( + strings.Split(prsr.attrName, utils.InInFieldSep)); err != nil { + return + } + } + return prsr.ParseValue(outStr) +} diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json index 3daa370fc..54c2961c4 100644 --- a/data/conf/samples/tutmysql/cgrates.json +++ b/data/conf/samples/tutmysql/cgrates.json @@ -117,75 +117,75 @@ "type": "*resources", // data source type "file_name": "Resources.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "TTL", "field_id": "UsageTTL", "type": "*composed", "value": "4"}, - {"tag": "Limit", "field_id": "Limit", "type": "*composed", "value": "5"}, - {"tag": "AllocationMessage", "field_id": "AllocationMessage", "type": "*composed", "value": "6"}, - {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "7"}, - {"tag": "Stored", "field_id": "Stored", "type": "*composed", "value": "8"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "9"}, - {"tag": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "10"}, + {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"tag": "TTL", "field_id": "UsageTTL", "type": "*composed", "value": "~4"}, + {"tag": "Limit", "field_id": "Limit", "type": "*composed", "value": "~5"}, + {"tag": "AllocationMessage", "field_id": "AllocationMessage", "type": "*composed", "value": "~6"}, + {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "~7"}, + {"tag": "Stored", "field_id": "Stored", "type": "*composed", "value": "~8"}, + {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "~9"}, + {"tag": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "~10"}, ], }, { "type": "*stats", // data source type "file_name": "Stats.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "QueueLength", "field_id": "QueueLength", "type": "*composed", "value": "4"}, - {"tag": "TTL", "field_id": "TTL", "type": "*composed", "value": "5"}, - {"tag": "Metrics", "field_id": "Metrics", "type": "*composed", "value": "6"}, - {"tag": "MetricParams", "field_id": "Parameters", "type": "*composed", "value": "7"}, - {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "8"}, - {"tag": "Stored", "field_id": "Stored", "type": "*composed", "value": "9"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "10"}, - {"tag": "MinItems", "field_id": "MinItems", "type": "*composed", "value": "11"}, - {"tag": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "12"}, + {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"tag": "QueueLength", "field_id": "QueueLength", "type": "*composed", "value": "~4"}, + {"tag": "TTL", "field_id": "TTL", "type": "*composed", "value": "~5"}, + {"tag": "Metrics", "field_id": "Metrics", "type": "*composed", "value": "~6"}, + {"tag": "MetricParams", "field_id": "Parameters", "type": "*composed", "value": "~7"}, + {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "~8"}, + {"tag": "Stored", "field_id": "Stored", "type": "*composed", "value": "~9"}, + {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "~10"}, + {"tag": "MinItems", "field_id": "MinItems", "type": "*composed", "value": "~11"}, + {"tag": "ThresholdIDs", "field_id": "ThresholdIDs", "type": "*composed", "value": "~12"}, ], }, { "type": "*thresholds", // data source type "file_name": "Thresholds.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "MaxHits", "field_id": "MaxHits", "type": "*composed", "value": "4"}, - {"tag": "MinHits", "field_id": "MinHits", "type": "*composed", "value": "5"}, - {"tag": "MinSleep", "field_id": "MinSleep", "type": "*composed", "value": "6"}, - {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "7"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "8"}, - {"tag": "ActionIDs", "field_id": "ActionIDs", "type": "*composed", "value": "9"}, - {"tag": "Async", "field_id": "Async", "type": "*composed", "value": "10"}, + {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"tag": "MaxHits", "field_id": "MaxHits", "type": "*composed", "value": "~4"}, + {"tag": "MinHits", "field_id": "MinHits", "type": "*composed", "value": "~5"}, + {"tag": "MinSleep", "field_id": "MinSleep", "type": "*composed", "value": "~6"}, + {"tag": "Blocker", "field_id": "Blocker", "type": "*composed", "value": "~7"}, + {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "~8"}, + {"tag": "ActionIDs", "field_id": "ActionIDs", "type": "*composed", "value": "~9"}, + {"tag": "Async", "field_id": "Async", "type": "*composed", "value": "~10"}, ], }, { "type": "*suppliers", // data source type "file_name": "Suppliers.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "2"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "3"}, - {"tag": "Sorting", "field_id": "Sorting", "type": "*composed", "value": "4"}, - {"tag": "SortingParamameters", "field_id": "SortingParamameters", "type": "*composed", "value": "5"}, - {"tag": "SupplierID", "field_id": "SupplierID", "type": "*composed", "value": "6"}, - {"tag": "SupplierFilterIDs", "field_id": "SupplierFilterIDs", "type": "*composed", "value": "7"}, - {"tag": "SupplierAccountIDs", "field_id": "SupplierAccountIDs", "type": "*composed", "value": "8"}, - {"tag": "SupplierRatingPlanIDs", "field_id": "SupplierRatingPlanIDs", "type": "*composed", "value": "9"}, - {"tag": "SupplierResourceIDs", "field_id": "SupplierResourceIDs", "type": "*composed", "value": "10"}, - {"tag": "SupplierStatIDs", "field_id": "SupplierStatIDs", "type": "*composed", "value": "11"}, - {"tag": "SupplierWeight", "field_id": "SupplierWeight", "type": "*composed", "value": "12"}, - {"tag": "SupplierBlocker", "field_id": "SupplierBlocker", "type": "*composed", "value": "13"}, - {"tag": "SupplierParameters", "field_id": "SupplierParameters", "type": "*composed", "value": "14"}, - {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "15"}, + {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"tag": "FilterIDs", "field_id": "FilterIDs", "type": "*composed", "value": "~2"}, + {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~3"}, + {"tag": "Sorting", "field_id": "Sorting", "type": "*composed", "value": "~4"}, + {"tag": "SortingParamameters", "field_id": "SortingParamameters", "type": "*composed", "value": "~5"}, + {"tag": "SupplierID", "field_id": "SupplierID", "type": "*composed", "value": "~6"}, + {"tag": "SupplierFilterIDs", "field_id": "SupplierFilterIDs", "type": "*composed", "value": "~7"}, + {"tag": "SupplierAccountIDs", "field_id": "SupplierAccountIDs", "type": "*composed", "value": "~8"}, + {"tag": "SupplierRatingPlanIDs", "field_id": "SupplierRatingPlanIDs", "type": "*composed", "value": "~9"}, + {"tag": "SupplierResourceIDs", "field_id": "SupplierResourceIDs", "type": "*composed", "value": "~10"}, + {"tag": "SupplierStatIDs", "field_id": "SupplierStatIDs", "type": "*composed", "value": "~11"}, + {"tag": "SupplierWeight", "field_id": "SupplierWeight", "type": "*composed", "value": "~12"}, + {"tag": "SupplierBlocker", "field_id": "SupplierBlocker", "type": "*composed", "value": "~13"}, + {"tag": "SupplierParameters", "field_id": "SupplierParameters", "type": "*composed", "value": "~14"}, + {"tag": "Weight", "field_id": "Weight", "type": "*composed", "value": "~15"}, ], }, ], @@ -207,12 +207,12 @@ "type": "*filters", // data source type "file_name": "Filters.csv", // file name in the tp_in_dir "fields": [ - {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "0", "mandatory": true}, - {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "1", "mandatory": true}, - {"tag": "FilterType", "field_id": "FilterType", "type": "*composed", "value": "2"}, - {"tag": "FilterFieldName", "field_id": "FilterFieldName", "type": "*composed", "value": "3"}, - {"tag": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*composed", "value": "4"}, - {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "5"}, + {"tag": "Tenant", "field_id": "Tenant", "type": "*composed", "value": "~0", "mandatory": true}, + {"tag": "ID", "field_id": "ID", "type": "*composed", "value": "~1", "mandatory": true}, + {"tag": "FilterType", "field_id": "FilterType", "type": "*composed", "value": "~2"}, + {"tag": "FilterFieldName", "field_id": "FilterFieldName", "type": "*composed", "value": "~3"}, + {"tag": "FilterFieldValues", "field_id": "FilterFieldValues", "type": "*composed", "value": "~4"}, + {"tag": "ActivationInterval", "field_id": "ActivationInterval", "type": "*composed", "value": "~5"}, ], }, ], diff --git a/loaders/libloader.go b/loaders/libloader.go index 068629911..29bfea201 100644 --- a/loaders/libloader.go +++ b/loaders/libloader.go @@ -21,9 +21,9 @@ package loaders import ( "fmt" "strconv" - "strings" "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -38,52 +38,100 @@ func (ld LoaderData) TenantID() string { // UpdateFromCSV will update LoaderData with data received from fileName, // contained in record and processed with cfgTpl func (ld LoaderData) UpdateFromCSV(fileName string, record []string, - cfgTpl []*config.CfgCdrField) (err error) { + cfgTpl []*config.FCTemplate, tnt config.RSRParsers, filterS *engine.FilterS) (err error) { + csvProvider := newCsvProvider(record, fileName) for _, cfgFld := range cfgTpl { - var valStr string - for _, rsrFld := range cfgFld.Value { - if rsrFld.IsStatic() { - var val string - if val, err = rsrFld.Parse(""); err != nil { - return err - } - valStr += val - continue - } - idxStr := rsrFld.Id // default to Id in the rsrField - spltSrc := strings.Split(rsrFld.Id, utils.InInFieldSep) - if len(spltSrc) == 2 { // having field name inside definition, compare here with our source - if spltSrc[0] != fileName { - continue - } - idxStr = spltSrc[1] // will have index at second position in the rule definition - } - var cfgFieldIdx int - if cfgFieldIdx, err = strconv.Atoi(idxStr); err != nil { - return - } else if len(record) <= cfgFieldIdx { - return fmt.Errorf("Ignoring record: %v - cannot extract field %s", record, cfgFld.Tag) - } - if parsed, err := rsrFld.Parse(record[cfgFieldIdx]); err != nil { + // Make sure filters are matching + if len(cfgFld.Filters) != 0 { + tenant, err := tnt.ParseValue("") + if err != nil { return err - } else { - valStr += parsed } - + if pass, err := filterS.Pass(tenant, + cfgFld.Filters, csvProvider); err != nil || !pass { + continue // Not passes filters, ignore this CDR + } + } + out, err := cfgFld.Value.ParseLoaderSDP(csvProvider) + if err != nil { + return err } switch cfgFld.Type { case utils.META_COMPOSED: if _, has := ld[cfgFld.FieldId]; !has { - ld[cfgFld.FieldId] = valStr + ld[cfgFld.FieldId] = out } else if valOrig, canCast := ld[cfgFld.FieldId].(string); canCast { - valOrig += valStr + valOrig += out ld[cfgFld.FieldId] = valOrig } case utils.MetaString: if _, has := ld[cfgFld.FieldId]; !has { - ld[cfgFld.FieldId] = valStr + ld[cfgFld.FieldId] = out } } } return } + +// newCsvProvider constructs a DataProvider +func newCsvProvider(record []string, fileName string) (dP config.DataProvider) { + dP = &csvProvider{req: record, fileName: fileName, cache: config.NewNavigableMap(nil)} + return +} + +// csvProvider implements engine.DataProvider so we can pass it to filters +type csvProvider struct { + req []string + fileName string + cache *config.NavigableMap +} + +// String is part of engine.DataProvider interface +// when called, it will display the already parsed values out of cache +func (cP *csvProvider) String() string { + return utils.ToJSON(cP) +} + +// FieldAsInterface is part of engine.DataProvider interface +func (cP *csvProvider) FieldAsInterface(fldPath []string) (data interface{}, err error) { + if data, err = cP.cache.FieldAsInterface(fldPath); err == nil || + err != utils.ErrNotFound { // item found in cache + return + } + err = nil // cancel previous err + idx := fldPath[0] + var fileName string + if len(fldPath) == 2 { + fileName = fldPath[0] + idx = fldPath[1] + } + if fileName != "" && cP.fileName != fileName { + cP.cache.Set(fldPath, nil, false) + return + } + if cfgFieldIdx, err := strconv.Atoi(idx); err != nil || len(cP.req) <= cfgFieldIdx { + return nil, fmt.Errorf("Ignoring record: %v with error : %+v", cP.req, err) + } else { + data = cP.req[cfgFieldIdx] + } + + cP.cache.Set(fldPath, data, false) + return +} + +// FieldAsString is part of engine.DataProvider interface +func (cP *csvProvider) FieldAsString(fldPath []string) (data string, err error) { + var valIface interface{} + valIface, err = cP.FieldAsInterface(fldPath) + if err != nil { + return + } + data, _ = utils.CastFieldIfToString(valIface) + return +} + +// AsNavigableMap is part of engine.DataProvider interface +func (cP *csvProvider) AsNavigableMap([]*config.FCTemplate) ( + nm *config.NavigableMap, err error) { + return nil, utils.ErrNotImplemented +} diff --git a/loaders/libloader_test.go b/loaders/libloader_test.go index aaabc28dd..ae1f8455f 100644 --- a/loaders/libloader_test.go +++ b/loaders/libloader_test.go @@ -27,49 +27,49 @@ import ( ) func TestDataUpdateFromCSVOneFile(t *testing.T) { - attrSFlds := []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + attrSFlds := []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "Contexts", + &config.FCTemplate{ID: "Contexts", FieldId: "Contexts", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FilterIDs", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FieldName", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "FieldName", FieldId: "FieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Initial", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "Initial", FieldId: "Initial", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Substitute", + Value: config.NewRSRParsersMustCompile("~6", true)}, + &config.FCTemplate{ID: "Substitute", FieldId: "Substitute", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Append", + Value: config.NewRSRParsersMustCompile("~7", true)}, + &config.FCTemplate{ID: "Append", FieldId: "Append", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~8", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~9", true)}, } rows := [][]string{ @@ -77,7 +77,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { []string{"cgrates.org", "ATTR_1", "", "", "", "Subject", "*any", "1001", "true", ""}, } lData := make(LoaderData) - if err := lData.UpdateFromCSV("Attributes.csv", rows[0], attrSFlds); err != nil { + if err := lData.UpdateFromCSV("Attributes.csv", rows[0], attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", true), nil); err != nil { t.Error(err) } eLData := LoaderData{"Tenant": "cgrates.org", @@ -95,7 +95,7 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { t.Errorf("expecting: %+v, received: %+v", eLData, lData) } lData = make(LoaderData) - if err := lData.UpdateFromCSV("Attributes.csv", rows[1], attrSFlds); err != nil { + if err := lData.UpdateFromCSV("Attributes.csv", rows[1], attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", true), nil); err != nil { t.Error(err) } eLData = LoaderData{"Tenant": "cgrates.org", @@ -115,41 +115,41 @@ func TestDataUpdateFromCSVOneFile(t *testing.T) { } func TestDataUpdateFromCSVMultiFiles(t *testing.T) { - attrSFlds := []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + attrSFlds := []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^cgrates.org", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("cgrates.org", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File2.csv:1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~File2.csv:1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "Contexts", + &config.FCTemplate{ID: "Contexts", FieldId: "Contexts", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^*any", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FieldName", + Value: config.NewRSRParsersMustCompile("*any", true)}, + &config.FCTemplate{ID: "FieldName", FieldId: "FieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File1.csv:5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Initial", + Value: config.NewRSRParsersMustCompile("~File1.csv:5", true)}, + &config.FCTemplate{ID: "Initial", FieldId: "Initial", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File1.csv:6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Substitute", + Value: config.NewRSRParsersMustCompile("~File1.csv:6", true)}, + &config.FCTemplate{ID: "Substitute", FieldId: "Substitute", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File1.csv:7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Append", + Value: config.NewRSRParsersMustCompile("~File1.csv:7", true)}, + &config.FCTemplate{ID: "Append", FieldId: "Append", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^true", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("true", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^10", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("10", true)}, } loadRun1 := map[string][]string{ @@ -158,7 +158,7 @@ func TestDataUpdateFromCSVMultiFiles(t *testing.T) { } lData := make(LoaderData) for fName, record := range loadRun1 { - if err := lData.UpdateFromCSV(fName, record, attrSFlds); err != nil { + if err := lData.UpdateFromCSV(fName, record, attrSFlds, config.NewRSRParsersMustCompile("cgrates.org", true), nil); err != nil { t.Error(err) } } diff --git a/loaders/loader.go b/loaders/loader.go index 1f44e464e..a84cceef5 100644 --- a/loaders/loader.go +++ b/loaders/loader.go @@ -39,20 +39,22 @@ type openedCSVFile struct { } func NewLoader(dm *engine.DataManager, cfg *config.LoaderSConfig, - timezone string) (ldr *Loader) { + timezone string, filterS *engine.FilterS) (ldr *Loader) { ldr = &Loader{ enabled: cfg.Enabled, + tenant: cfg.Tenant, dryRun: cfg.DryRun, ldrID: cfg.Id, tpInDir: cfg.TpInDir, tpOutDir: cfg.TpOutDir, lockFilename: cfg.LockFileName, fieldSep: cfg.FieldSeparator, - dataTpls: make(map[string][]*config.CfgCdrField), + dataTpls: make(map[string][]*config.FCTemplate), rdrs: make(map[string]map[string]*openedCSVFile), bufLoaderData: make(map[string][]LoaderData), dm: dm, timezone: timezone, + filterS: filterS, } for _, ldrData := range cfg.Data { ldr.dataTpls[ldrData.Type] = ldrData.Fields @@ -62,8 +64,8 @@ func NewLoader(dm *engine.DataManager, cfg *config.LoaderSConfig, } for _, cfgFld := range ldrData.Fields { // add all possible files to be opened for _, cfgFldVal := range cfgFld.Value { - if idx := strings.Index(cfgFldVal.Id, utils.InInFieldSep); idx != -1 { - ldr.rdrs[ldrData.Type][cfgFldVal.Id[:idx]] = nil + if idx := strings.Index(cfgFldVal.Rules, utils.InInFieldSep); idx != -1 { + ldr.rdrs[ldrData.Type][cfgFldVal.Rules[:idx]] = nil } } } @@ -74,6 +76,7 @@ func NewLoader(dm *engine.DataManager, cfg *config.LoaderSConfig, // Loader is one instance loading from a folder type Loader struct { enabled bool + tenant config.RSRParsers dryRun bool ldrID string tpInDir string @@ -81,12 +84,13 @@ type Loader struct { lockFilename string cacheSConns []*config.HaPoolConfig fieldSep string - dataTpls map[string][]*config.CfgCdrField // map[loaderType]*config.CfgCdrField + dataTpls map[string][]*config.FCTemplate // map[loaderType]*config.FCTemplate rdrs map[string]map[string]*openedCSVFile // map[loaderType]map[fileName]*openedCSVFile for common incremental read procRows int // keep here the last processed row in the file/-s bufLoaderData map[string][]LoaderData // cache of data read, indexed on tenantID dm *engine.DataManager timezone string + filterS *engine.FilterS } func (ldr *Loader) ListenAndServe(exitChan chan struct{}) (err error) { @@ -201,7 +205,7 @@ func (ldr *Loader) processContent(loaderType string) (err error) { } if err := lData.UpdateFromCSV(fName, record, - ldr.dataTpls[loaderType]); err != nil { + ldr.dataTpls[loaderType], ldr.tenant, ldr.filterS); err != nil { fmt.Sprintf("<%s> <%s> line: %d, error: %s", utils.LoaderS, ldr.ldrID, lineNr, err.Error()) hasErrors = true @@ -293,6 +297,12 @@ func (ldr *Loader) storeLoadedData(loaderType string, if err := ldr.dm.SetResourceProfile(res, true); err != nil { return err } + if err := ldr.dm.SetResource( + &engine.Resource{Tenant: res.Tenant, + ID: res.ID, + Usages: make(map[string]*engine.ResourceUsage)}); err != nil { + return err + } } } case utils.MetaFilters: @@ -344,6 +354,17 @@ func (ldr *Loader) storeLoadedData(loaderType string, if err := ldr.dm.SetStatQueueProfile(stsPrf, true); err != nil { return err } + metrics := make(map[string]engine.StatMetric) + for _, metricwithparam := range stsPrf.Metrics { + if metric, err := engine.NewStatMetric(metricwithparam.MetricID, stsPrf.MinItems, metricwithparam.Parameters); err != nil { + return utils.APIErrorHandler(err) + } else { + metrics[metricwithparam.MetricID] = metric + } + } + if err := ldr.dm.SetStatQueue(&engine.StatQueue{Tenant: stsPrf.Tenant, ID: stsPrf.ID, SQMetrics: metrics}); err != nil { + return err + } } } case utils.MetaThresholds: @@ -370,6 +391,9 @@ func (ldr *Loader) storeLoadedData(loaderType string, if err := ldr.dm.SetThresholdProfile(thPrf, true); err != nil { return err } + if err := ldr.dm.SetThreshold(&engine.Threshold{Tenant: thPrf.Tenant, ID: thPrf.ID}); err != nil { + return err + } } } case utils.MetaSuppliers: diff --git a/loaders/loader_test.go b/loaders/loader_test.go index fb9509740..1afc2f64d 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -43,50 +43,50 @@ cgrates.org,TestLoader1,lcr,*string:Account:1008;*string:Account:1009,,Subject,* dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaAttributes: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaAttributes: []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "Contexts", + &config.FCTemplate{ID: "Contexts", FieldId: "Contexts", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FilterIDs", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FieldName", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "FieldName", FieldId: "FieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Initial", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "Initial", FieldId: "Initial", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Substitute", + Value: config.NewRSRParsersMustCompile("~6", true)}, + &config.FCTemplate{ID: "Substitute", FieldId: "Substitute", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Append", + Value: config.NewRSRParsersMustCompile("~7", true)}, + &config.FCTemplate{ID: "Append", FieldId: "Append", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~8", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~9", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(attrsCSV)) @@ -145,42 +145,42 @@ func TestLoaderProcessContentMultiFiles(t *testing.T) { dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaAttributes: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaAttributes: []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^cgrates.org", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("cgrates.org", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File2.csv:1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~File2.csv:1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "Contexts", + &config.FCTemplate{ID: "Contexts", FieldId: "Contexts", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^*any", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FieldName", + Value: config.NewRSRParsersMustCompile("*any", true)}, + &config.FCTemplate{ID: "FieldName", FieldId: "FieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File1.csv:5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Initial", + Value: config.NewRSRParsersMustCompile("~File1.csv:5", true)}, + &config.FCTemplate{ID: "Initial", FieldId: "Initial", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File1.csv:6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Substitute", + Value: config.NewRSRParsersMustCompile("~File1.csv:6", true)}, + &config.FCTemplate{ID: "Substitute", FieldId: "Substitute", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("File1.csv:7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Append", + Value: config.NewRSRParsersMustCompile("~File1.csv:7", true)}, + &config.FCTemplate{ID: "Append", FieldId: "Append", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^true", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("true", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.MetaString, - Value: utils.ParseRSRFieldsMustCompile("^10", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("10", true)}, }, } rdr1 := ioutil.NopCloser(strings.NewReader(file1CSV)) @@ -237,54 +237,54 @@ cgrates.org,ResGroup2,*string:Account:1002,2014-07-29T15:00:00Z,3600s,2,premium_ dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaResources: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "Tenant", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaResources: []*config.FCTemplate{ + &config.FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ID", + &config.FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "FilterIDs", + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "TTL", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "TTL", FieldId: "UsageTTL", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Limit", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "Limit", FieldId: "Limit", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "AllocationMessage", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "AllocationMessage", FieldId: "AllocationMessage", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Blocker", + Value: config.NewRSRParsersMustCompile("~6", true)}, + &config.FCTemplate{ID: "Blocker", FieldId: "Blocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Stored", + Value: config.NewRSRParsersMustCompile("~7", true)}, + &config.FCTemplate{ID: "Stored", FieldId: "Stored", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~8", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Thresholds", + Value: config.NewRSRParsersMustCompile("~9", true)}, + &config.FCTemplate{ID: "Thresholds", FieldId: "Thresholds", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~10", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(resProfiles)) @@ -366,34 +366,34 @@ cgrates.org,FLTR_ACNT_1002,*string,Account,1002,2014-07-29T15:00:00Z dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaFilters: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "Tenant", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaFilters: []*config.FCTemplate{ + &config.FCTemplate{ID: "Tenant", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ID", + &config.FCTemplate{ID: "ID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "FilterType", + &config.FCTemplate{ID: "FilterType", FieldId: "FilterType", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FilterFieldName", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "FilterFieldName", FieldId: "FilterFieldName", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "FilterFieldValues", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "FilterFieldValues", FieldId: "FilterFieldValues", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~5", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(filters)) @@ -482,54 +482,54 @@ cgrates.org,THD_ACNT_1002,*string:Account:1002,2014-07-29T15:00:00Z,-1,1,1s,true dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaThresholds: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaThresholds: []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "FilterIDs", + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "MaxHits", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "MaxHits", FieldId: "MaxHits", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "MinHits", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "MinHits", FieldId: "MinHits", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "MinSleep", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "MinSleep", FieldId: "MinSleep", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Blocker", + Value: config.NewRSRParsersMustCompile("~6", true)}, + &config.FCTemplate{ID: "Blocker", FieldId: "Blocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~7", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActionIDs", + Value: config.NewRSRParsersMustCompile("~8", true)}, + &config.FCTemplate{ID: "ActionIDs", FieldId: "ActionIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Async", + Value: config.NewRSRParsersMustCompile("~9", true)}, + &config.FCTemplate{ID: "Async", FieldId: "Async", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~10", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(thresholdCSV)) @@ -603,62 +603,62 @@ cgrates.org,Stats1,*string:Account:1003,2014-07-29T15:00:00Z,100,1s,*sum;*averag dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaStats: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaStats: []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "FilterIDs", + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "QueueLength", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "QueueLength", FieldId: "QueueLength", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "TTL", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "TTL", FieldId: "TTL", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Metrics", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "Metrics", FieldId: "Metrics", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "MetricParams", + Value: config.NewRSRParsersMustCompile("~6", true)}, + &config.FCTemplate{ID: "MetricParams", FieldId: "Parameters", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Blocker", + Value: config.NewRSRParsersMustCompile("~7", true)}, + &config.FCTemplate{ID: "Blocker", FieldId: "Blocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Stored", + Value: config.NewRSRParsersMustCompile("~8", true)}, + &config.FCTemplate{ID: "Stored", FieldId: "Stored", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~9", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "MinItems", + Value: config.NewRSRParsersMustCompile("~10", true)}, + &config.FCTemplate{ID: "MinItems", FieldId: "MinItems", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("11", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ThresholdIDs", + Value: config.NewRSRParsersMustCompile("~11", true)}, + &config.FCTemplate{ID: "ThresholdIDs", FieldId: "ThresholdIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("12", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~12", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(statsCSV)) @@ -765,74 +765,74 @@ cgrates.org,SPL_LEASTCOST_1,,,,,supplier2,,,RP_RETAIL1,resource_spl2,,20,,, dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaSuppliers: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaSuppliers: []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "FilterIDs", + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Sorting", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "Sorting", FieldId: "Sorting", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SortingParamameters", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "SortingParamameters", FieldId: "SortingParamameters", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierID", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "SupplierID", FieldId: "SupplierID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierFilterIDs", + Value: config.NewRSRParsersMustCompile("~6", true)}, + &config.FCTemplate{ID: "SupplierFilterIDs", FieldId: "SupplierFilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("7", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierAccountIDs", + Value: config.NewRSRParsersMustCompile("~7", true)}, + &config.FCTemplate{ID: "SupplierAccountIDs", FieldId: "SupplierAccountIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("8", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierRatingPlanIDs", + Value: config.NewRSRParsersMustCompile("~8", true)}, + &config.FCTemplate{ID: "SupplierRatingPlanIDs", FieldId: "SupplierRatingplanIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("9", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierResourceIDs", + Value: config.NewRSRParsersMustCompile("~9", true)}, + &config.FCTemplate{ID: "SupplierResourceIDs", FieldId: "SupplierResourceIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("10", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierStatIDs", + Value: config.NewRSRParsersMustCompile("~10", true)}, + &config.FCTemplate{ID: "SupplierStatIDs", FieldId: "SupplierStatIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("11", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierWeight", + Value: config.NewRSRParsersMustCompile("~11", true)}, + &config.FCTemplate{ID: "SupplierWeight", FieldId: "SupplierWeight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("12", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierBlocker", + Value: config.NewRSRParsersMustCompile("~12", true)}, + &config.FCTemplate{ID: "SupplierBlocker", FieldId: "SupplierBlocker", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("13", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "SupplierParameters", + Value: config.NewRSRParsersMustCompile("~13", true)}, + &config.FCTemplate{ID: "SupplierParameters", FieldId: "SupplierParameters", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("14", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~14", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("15", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~15", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(supplierCSV)) @@ -948,38 +948,38 @@ cgrates.org,Charge2,*string:Account:1003,2014-07-29T15:00:00Z,*default,Attr3,10 dm: engine.NewDataManager(data), timezone: "UTC", } - ldr.dataTpls = map[string][]*config.CfgCdrField{ - utils.MetaChargers: []*config.CfgCdrField{ - &config.CfgCdrField{Tag: "TenantID", + ldr.dataTpls = map[string][]*config.FCTemplate{ + utils.MetaChargers: []*config.FCTemplate{ + &config.FCTemplate{ID: "TenantID", FieldId: "Tenant", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("0", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~0", true), Mandatory: true}, - &config.CfgCdrField{Tag: "ProfileID", + &config.FCTemplate{ID: "ProfileID", FieldId: "ID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("1", utils.INFIELD_SEP), + Value: config.NewRSRParsersMustCompile("~1", true), Mandatory: true}, - &config.CfgCdrField{Tag: "FilterIDs", + &config.FCTemplate{ID: "FilterIDs", FieldId: "FilterIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("2", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "ActivationInterval", + Value: config.NewRSRParsersMustCompile("~2", true)}, + &config.FCTemplate{ID: "ActivationInterval", FieldId: "ActivationInterval", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("3", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "RunID", + Value: config.NewRSRParsersMustCompile("~3", true)}, + &config.FCTemplate{ID: "RunID", FieldId: "RunID", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("4", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "AttributeIDs", + Value: config.NewRSRParsersMustCompile("~4", true)}, + &config.FCTemplate{ID: "AttributeIDs", FieldId: "AttributeIDs", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("5", utils.INFIELD_SEP)}, - &config.CfgCdrField{Tag: "Weight", + Value: config.NewRSRParsersMustCompile("~5", true)}, + &config.FCTemplate{ID: "Weight", FieldId: "Weight", Type: utils.META_COMPOSED, - Value: utils.ParseRSRFieldsMustCompile("6", utils.INFIELD_SEP)}, + Value: config.NewRSRParsersMustCompile("~6", true)}, }, } rdr := ioutil.NopCloser(strings.NewReader(chargerCSV)) diff --git a/loaders/loaders.go b/loaders/loaders.go index 568f36367..b98263a08 100644 --- a/loaders/loaders.go +++ b/loaders/loaders.go @@ -28,13 +28,13 @@ import ( ) func NewLoaderService(dm *engine.DataManager, ldrsCfg []*config.LoaderSConfig, - timezone string) (ldrS *LoaderService) { + timezone string, filterS *engine.FilterS) (ldrS *LoaderService) { ldrS = &LoaderService{ldrs: make(map[string]*Loader)} for _, ldrCfg := range ldrsCfg { if !ldrCfg.Enabled { continue } - ldrS.ldrs[ldrCfg.Id] = NewLoader(dm, ldrCfg, timezone) + ldrS.ldrs[ldrCfg.Id] = NewLoader(dm, ldrCfg, timezone, filterS) } return }