From 48feaf2bedf6e2142f7e6a6a5e69fef67b5ff359 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 2 Nov 2021 16:46:44 +0200 Subject: [PATCH] Add opts field for attributes cfg struct and fix compilation errors --- apier/v1/apier2_it_test.go | 8 +- apier/v1/attributes_it_test.go | 90 ++++-- apier/v1/cache_replication_it_test.go | 4 +- apier/v1/filterindexecache_it_test.go | 28 +- config/attributescfg.go | 63 +++- config/attributescfg_test.go | 20 +- config/config.go | 2 +- config/config_defaults.go | 5 + config/config_it_test.go | 4 +- config/config_test.go | 8 +- config/configsanity.go | 2 +- config/configsanity_test.go | 6 +- config/libconfig_json.go | 9 + dispatchers/attributes_it_test.go | 32 +- dispatchers/attributes_test.go | 49 +-- dispatchers/dispatchers.go | 2 +- ees/ees.go | 8 +- engine/attributes.go | 60 ++-- engine/attributes_test.go | 73 ++--- engine/cdrs.go | 10 +- engine/chargers.go | 12 +- engine/routes.go | 10 +- engine/z_attributes_test.go | 292 ++++++++++++------ .../attributes_filters_index_it_test.go | 10 +- general_tests/attributes_it_test.go | 51 +-- .../cacherpl_filter_update_it_test.go | 14 +- general_tests/filters_it_test.go | 11 +- sessions/sessions.go | 12 +- sessions/sessionscover_test.go | 6 +- utils/consts.go | 17 +- 30 files changed, 554 insertions(+), 364 deletions(-) diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index d014d261f..778bfa02b 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -155,13 +155,15 @@ func testAPIerLoadFromFolder(t *testing.T) { func testAPIerVerifyAttributesAfterLoad(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAPIerAfterDelete", Event: map[string]interface{}{ utils.AccountField: "1001", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: "simpleauth", + }, }, } @@ -231,13 +233,15 @@ func testAPIerAfterDelete(t *testing.T) { func testAPIerVerifyAttributesAfterDelete(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAPIerAfterDelete", Event: map[string]interface{}{ utils.AccountField: "1001", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: "simpleauth", + }, }, } var attrReply *engine.AttributeProfile diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index ccd262266..49c144ac9 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -183,7 +183,6 @@ func testAttributeSLoadFromFolder(t *testing.T) { func testAttributeSGetAttributeForEvent(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -191,6 +190,9 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { utils.AccountField: "1007", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -248,7 +250,6 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { func testAttributeSGetAttributeForEventNotFound(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaCDRs), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEventWihMetaAnyContext", @@ -256,6 +257,9 @@ func testAttributeSGetAttributeForEventNotFound(t *testing.T) { utils.AccountField: "dan", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaCDRs, + }, }, } eAttrPrf2 := &engine.AttributeProfileWithAPIOpts{ @@ -300,7 +304,6 @@ func testAttributeSGetAttributeForEventNotFound(t *testing.T) { func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaCDRs), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEventWihMetaAnyContext", @@ -308,6 +311,9 @@ func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) { utils.AccountField: "dan", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaCDRs, + }, }, } eAttrPrf2 := &engine.AttributeProfileWithAPIOpts{ @@ -356,7 +362,6 @@ func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) { func testAttributeSProcessEvent(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -364,6 +369,9 @@ func testAttributeSProcessEvent(t *testing.T) { utils.AccountField: "1007", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &engine.AttrSProcessEventReply{ @@ -412,7 +420,6 @@ func testAttributeSProcessEvent(t *testing.T) { func testAttributeSProcessEventNotFound(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventNotFound", @@ -420,7 +427,9 @@ func testAttributeSProcessEventNotFound(t *testing.T) { utils.AccountField: "Inexistent", utils.Destination: "+491511231234", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -433,7 +442,6 @@ func testAttributeSProcessEventNotFound(t *testing.T) { func testAttributeSProcessEventMissing(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -442,7 +450,9 @@ func testAttributeSProcessEventMissing(t *testing.T) { utils.Category: "*attributes", utils.Destination: "+491511231234", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -455,7 +465,6 @@ func testAttributeSProcessEventMissing(t *testing.T) { func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -463,6 +472,9 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { utils.AccountField: "1008", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } alsPrf = &engine.AttributeProfileWithAPIOpts{ @@ -525,7 +537,6 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -534,6 +545,9 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { utils.Subject: "1008", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } alsPrf = &engine.AttributeProfileWithAPIOpts{ @@ -606,7 +620,6 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSWithNoneSubstitute", @@ -615,6 +628,9 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { utils.Subject: "1001", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } alsPrf = &engine.AttributeProfileWithAPIOpts{ @@ -699,14 +715,16 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { t.Error("Unexpected reply returned", result) } attrArgs := &engine.AttrArgsProcessEvent{ - ProcessRuns: utils.IntPointer(1), - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "HeaderEventForAttribute", Event: map[string]interface{}{ "Field1": "Value1", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &engine.AttrSProcessEventReply{ @@ -719,7 +737,9 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { "Field1": "Value1", "Field2": "Value1", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1023,14 +1043,16 @@ func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) { t.Error("Unexpected reply returned", result) } attrArgs := &engine.AttrArgsProcessEvent{ - ProcessRuns: utils.IntPointer(1), - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "HeaderEventForAttribute", Event: map[string]interface{}{ "Category": "call", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &engine.AttrSProcessEventReply{ @@ -1042,7 +1064,9 @@ func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) { Event: map[string]interface{}{ "Category": "call_suffix", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1128,14 +1152,16 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { t.Error("Unexpected reply returned", result) } attrArgs := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &engine.AttrSProcessEventReply{ @@ -1149,6 +1175,9 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { "Field1": "Value1", "Field2": "Value2", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + }, }, } @@ -1240,14 +1269,16 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { t.Error("Unexpected reply returned", result) } attrArgs := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &engine.AttrSProcessEventReply{ @@ -1262,6 +1293,9 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { "Field2": "Value2", "Field3": "Value3", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + }, }, } @@ -1958,16 +1992,17 @@ func testAttributeSRmvAlsPrfWithoutTenant(t *testing.T) { func testAttributeSCacheTestProcessEventNotFound(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", Event: map[string]interface{}{ utils.AccountField: "1007", utils.Destination: "+491511231234", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + utils.OptsAttributesProfileIDs: []string{"ATTR_CACHE"}, + }, }, - AttributeIDs: []string{"ATTR_CACHE"}, } var rplyEv engine.AttrSProcessEventReply if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, @@ -1978,16 +2013,17 @@ func testAttributeSCacheTestProcessEventNotFound(t *testing.T) { func testAttributeSCacheTestProcessEventFound(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", Event: map[string]interface{}{ utils.AccountField: "1007", utils.Destination: "+491511231234", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + utils.OptsAttributesProfileIDs: []string{"ATTR_CACHE"}, + }, }, - AttributeIDs: []string{"ATTR_CACHE"}, } var rplyEv engine.AttrSProcessEventReply if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, diff --git a/apier/v1/cache_replication_it_test.go b/apier/v1/cache_replication_it_test.go index 4e1ac94ca..e17c685d0 100644 --- a/apier/v1/cache_replication_it_test.go +++ b/apier/v1/cache_replication_it_test.go @@ -125,13 +125,15 @@ func testCacheSReplicateLoadTariffPlanFromFolder(t *testing.T) { func testCacheSReplicateProcessAttributes(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testCacheSReplicateProcessAttributes", Event: map[string]interface{}{ utils.AccountField: "1001", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &engine.AttrSProcessEventReply{ diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 40dbc6962..b0edfcc8f 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -951,7 +951,6 @@ func testV1FIdxCaRemoveStatQueueProfile(t *testing.T) { //AttributeProfile func testV1FIdxCaProcessAttributeProfileEventWithNotFound(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -959,6 +958,9 @@ func testV1FIdxCaProcessAttributeProfileEventWithNotFound(t *testing.T) { utils.AccountField: "3009", utils.Destination: "+492511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1025,7 +1027,6 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { } //matches TEST_PROFILE1 ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -1033,6 +1034,9 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { utils.AccountField: "1009", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1045,7 +1049,6 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { func testV1FIdxCaGetAttributeProfileFromTP(t *testing.T) { //matches ATTR_1 ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -1053,6 +1056,9 @@ func testV1FIdxCaGetAttributeProfileFromTP(t *testing.T) { utils.AccountField: "1007", utils.Destination: "+491511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1118,7 +1124,6 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { } //matches TEST_PROFILE1 ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -1126,6 +1131,9 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { utils.AccountField: "2009", utils.Destination: "+492511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1176,7 +1184,6 @@ func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) { } //matches TEST_PROFILE1 ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -1184,6 +1191,9 @@ func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) { utils.AccountField: "3009", utils.Destination: "+492511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1195,7 +1205,6 @@ func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) { func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { var resp string ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -1203,6 +1212,9 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { utils.AccountField: "3009", utils.Destination: "+492511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -1211,7 +1223,6 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { } ev2 := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -1219,6 +1230,9 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { utils.AccountField: "2009", utils.Destination: "+492511231234", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err != nil { diff --git a/config/attributescfg.go b/config/attributescfg.go index f2b4184ee..a4569b23d 100644 --- a/config/attributescfg.go +++ b/config/attributescfg.go @@ -20,6 +20,14 @@ package config import "github.com/cgrates/cgrates/utils" +type AttributesOpts struct { + ProfileIDs []string + ProfileRuns int + ProfileIgnoreFilters bool + ProcessRuns int + Context *string +} + // AttributeSCfg is the configuration of attribute service type AttributeSCfg struct { Enabled bool @@ -30,10 +38,27 @@ type AttributeSCfg struct { StringIndexedFields *[]string PrefixIndexedFields *[]string SuffixIndexedFields *[]string - ProcessRuns int - ProfileRuns int NestedFields bool AnyContext bool + Opts *AttributesOpts +} + +func (attrOpts *AttributesOpts) loadFromJSONCfg(jsnCfg *AttributesOptsJson) { + if jsnCfg == nil { + return + } + if jsnCfg.ProfileIDs != nil { + attrOpts.ProfileIDs = *jsnCfg.ProfileIDs + } + if jsnCfg.ProfileRuns != nil { + attrOpts.ProfileRuns = *jsnCfg.ProfileRuns + } + if jsnCfg.ProcessRuns != nil { + attrOpts.ProcessRuns = *jsnCfg.ProcessRuns + } + if jsnCfg.Context != nil { + attrOpts.Context = jsnCfg.Context + } } func (alS *AttributeSCfg) loadFromJSONCfg(jsnCfg *AttributeSJsonCfg) (err error) { @@ -97,30 +122,35 @@ func (alS *AttributeSCfg) loadFromJSONCfg(jsnCfg *AttributeSJsonCfg) (err error) } alS.SuffixIndexedFields = &sif } - if jsnCfg.Process_runs != nil { - alS.ProcessRuns = *jsnCfg.Process_runs - } - if jsnCfg.Profile_runs != nil { - alS.ProfileRuns = *jsnCfg.Profile_runs - } if jsnCfg.Nested_fields != nil { alS.NestedFields = *jsnCfg.Nested_fields } if jsnCfg.Any_context != nil { alS.AnyContext = *jsnCfg.Any_context } + if jsnCfg.Opts != nil { + alS.Opts.loadFromJSONCfg(jsnCfg.Opts) + } return } // AsMapInterface returns the config as a map[string]interface{} func (alS *AttributeSCfg) AsMapInterface() (initialMP map[string]interface{}) { + opts := map[string]interface{}{ + utils.MetaProfileIDs: alS.Opts.ProfileIDs, + utils.MetaProfileRunsCfg: alS.Opts.ProfileRuns, + utils.MetaProfileIgnoreFiltersCfg: alS.Opts.ProfileIgnoreFilters, + utils.MetaProcessRunsCfg: alS.Opts.ProcessRuns, + } + if alS.Opts.Context != nil { + opts[utils.OptsContext] = *alS.Opts.Context + } initialMP = map[string]interface{}{ utils.EnabledCfg: alS.Enabled, utils.IndexedSelectsCfg: alS.IndexedSelects, - utils.ProcessRunsCfg: alS.ProcessRuns, - utils.ProfileRunsCfg: alS.ProfileRuns, utils.NestedFieldsCfg: alS.NestedFields, utils.AnyContextCfg: alS.AnyContext, + utils.OptsCfg: opts, } if alS.StringIndexedFields != nil { stringIndexedFields := make([]string, len(*alS.StringIndexedFields)) @@ -177,15 +207,24 @@ func (alS *AttributeSCfg) AsMapInterface() (initialMP map[string]interface{}) { return } +func (attrOpts AttributesOpts) Clone() *AttributesOpts { + return &AttributesOpts{ + ProfileIDs: utils.CloneStringSlice(attrOpts.ProfileIDs), + ProfileRuns: attrOpts.ProfileRuns, + ProfileIgnoreFilters: attrOpts.ProfileIgnoreFilters, + ProcessRuns: attrOpts.ProcessRuns, + Context: utils.StringPointer(*attrOpts.Context), + } +} + // Clone returns a deep copy of AttributeSCfg func (alS AttributeSCfg) Clone() (cln *AttributeSCfg) { cln = &AttributeSCfg{ Enabled: alS.Enabled, IndexedSelects: alS.IndexedSelects, NestedFields: alS.NestedFields, - ProcessRuns: alS.ProcessRuns, - ProfileRuns: alS.ProfileRuns, AnyContext: alS.AnyContext, + Opts: alS.Opts.Clone(), } if alS.ResourceSConns != nil { cln.ResourceSConns = make([]string, len(alS.ResourceSConns)) diff --git a/config/attributescfg_test.go b/config/attributescfg_test.go index bf06cb48c..5685873db 100644 --- a/config/attributescfg_test.go +++ b/config/attributescfg_test.go @@ -47,9 +47,11 @@ func TestAttributeSCfgloadFromJsonCfg(t *testing.T) { StringIndexedFields: &[]string{"*req.index1"}, PrefixIndexedFields: &[]string{"*req.index1", "*req.index2"}, SuffixIndexedFields: &[]string{"*req.index1"}, - ProcessRuns: 1, NestedFields: true, AnyContext: true, + Opts: &AttributesOpts{ + ProcessRuns: 1, + }, } jsnCfg := NewDefaultCGRConfig() if err = jsnCfg.attributeSCfg.loadFromJSONCfg(jsonCfg); err != nil { @@ -78,8 +80,8 @@ func TestAttributeSCfgAsMapInterface(t *testing.T) { utils.ApierSConnsCfg: []string{utils.MetaInternal}, utils.StringIndexedFieldsCfg: []string{"*req.index1"}, utils.PrefixIndexedFieldsCfg: []string{"*req.index1", "*req.index2"}, - utils.ProcessRunsCfg: 3, - utils.ProfileRunsCfg: 0, + utils.MetaProcessRunsCfg: 3, + utils.MetaProfileRunsCfg: 0, utils.IndexedSelectsCfg: true, utils.NestedFieldsCfg: false, utils.SuffixIndexedFieldsCfg: []string{}, @@ -110,9 +112,9 @@ func TestAttributeSCfgAsMapInterface2(t *testing.T) { utils.PrefixIndexedFieldsCfg: []string{}, utils.SuffixIndexedFieldsCfg: []string{"*req.index1", "*req.index2"}, utils.NestedFieldsCfg: true, - utils.ProcessRunsCfg: 7, + utils.MetaProcessRunsCfg: 7, utils.AnyContextCfg: true, - utils.ProfileRunsCfg: 0, + utils.MetaProfileRunsCfg: 0, } if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil { t.Error(err) @@ -136,9 +138,9 @@ func TestAttributeSCfgAsMapInterface3(t *testing.T) { utils.PrefixIndexedFieldsCfg: []string{}, utils.SuffixIndexedFieldsCfg: []string{}, utils.NestedFieldsCfg: false, - utils.ProcessRunsCfg: 1, + utils.MetaProcessRunsCfg: 1, utils.AnyContextCfg: true, - utils.ProfileRunsCfg: 0, + utils.MetaProfileRunsCfg: 0, } if conv, err := NewCGRConfigFromJSONStringWithDefaults(myJSONStr); err != nil { t.Error(err) @@ -157,9 +159,11 @@ func TestAttributeSCfgClone(t *testing.T) { StringIndexedFields: &[]string{"*req.index1"}, PrefixIndexedFields: &[]string{"*req.index1", "*req.index2"}, SuffixIndexedFields: &[]string{"*req.index1"}, - ProcessRuns: 1, NestedFields: true, AnyContext: true, + Opts: &AttributesOpts{ + ProcessRuns: 1, + }, } rcv := ban.Clone() if !reflect.DeepEqual(ban, rcv) { diff --git a/config/config.go b/config/config.go index cd1755e48..cc645970d 100644 --- a/config/config.go +++ b/config/config.go @@ -148,7 +148,7 @@ func newCGRConfig(config []byte) (cfg *CGRConfig, err error) { cfg.diameterAgentCfg = new(DiameterAgentCfg) cfg.radiusAgentCfg = new(RadiusAgentCfg) cfg.dnsAgentCfg = new(DNSAgentCfg) - cfg.attributeSCfg = new(AttributeSCfg) + cfg.attributeSCfg = &AttributeSCfg{Opts: &AttributesOpts{}} cfg.chargerSCfg = new(ChargerSCfg) cfg.resourceSCfg = new(ResourceSConfig) cfg.statsCfg = new(StatSCfg) diff --git a/config/config_defaults.go b/config/config_defaults.go index 3da434303..d7a28a067 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -709,6 +709,11 @@ const CGRATES_CFG_JSON = ` "process_runs": 1, // number of run loops when processing event "profile_runs": 0, // number of run a profile will process thes event "any_context": true, // if we match the *any context + "opts": { + "*profileIDs": [], + "*profileRuns": 0, + "*processRuns": 1, + }, }, diff --git a/config/config_it_test.go b/config/config_it_test.go index 6478a5fb2..7f25674e0 100644 --- a/config/config_it_test.go +++ b/config/config_it_test.go @@ -155,8 +155,10 @@ func testCGRConfigReloadAttributeS(t *testing.T) { PrefixIndexedFields: &[]string{}, SuffixIndexedFields: &[]string{}, IndexedSelects: true, - ProcessRuns: 1, AnyContext: true, + Opts: &AttributesOpts{ + ProcessRuns: 1, + }, } if !reflect.DeepEqual(expAttr, cfg.AttributeSCfg()) { t.Errorf("Expected %s , received: %s ", utils.ToJSON(expAttr), utils.ToJSON(cfg.AttributeSCfg())) diff --git a/config/config_test.go b/config/config_test.go index feb91c5a7..a46fa73bf 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -1937,9 +1937,11 @@ func TestAttributeSConfig(t *testing.T) { IndexedSelects: true, PrefixIndexedFields: &[]string{}, SuffixIndexedFields: &[]string{}, - ProcessRuns: 1, NestedFields: false, AnyContext: true, + Opts: &AttributesOpts{ + ProcessRuns: 1, + }, } cgrConfig := NewDefaultCGRConfig() if err != nil { @@ -4002,9 +4004,9 @@ func TestV1GetConfigAttribute(t *testing.T) { utils.PrefixIndexedFieldsCfg: []string{}, utils.SuffixIndexedFieldsCfg: []string{}, utils.NestedFieldsCfg: false, - utils.ProcessRunsCfg: 1, + utils.MetaProcessRunsCfg: 1, utils.AnyContextCfg: true, - utils.ProfileRunsCfg: 0, + utils.MetaProfileRunsCfg: 0, }, } cfgCgr := NewDefaultCGRConfig() diff --git a/config/configsanity.go b/config/configsanity.go index 7ac67ac95..e961fa943 100644 --- a/config/configsanity.go +++ b/config/configsanity.go @@ -584,7 +584,7 @@ func (cfg *CGRConfig) checkConfigSanity() error { } if cfg.attributeSCfg.Enabled { - if cfg.attributeSCfg.ProcessRuns < 1 { + if cfg.attributeSCfg.Opts.ProcessRuns < 1 { return fmt.Errorf("<%s> process_runs needs to be bigger than 0", utils.AttributeS) } } diff --git a/config/configsanity_test.go b/config/configsanity_test.go index 53c26ca7c..4a9ed85ad 100644 --- a/config/configsanity_test.go +++ b/config/configsanity_test.go @@ -1041,8 +1041,10 @@ func TestConfigSanityAttributesCfg(t *testing.T) { cfg := NewDefaultCGRConfig() cfg.attributeSCfg = &AttributeSCfg{ - Enabled: true, - ProcessRuns: -1, + Enabled: true, + Opts: &AttributesOpts{ + ProfileRuns: -1, + }, } expected := " process_runs needs to be bigger than 0" if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected { diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 0cdd1c0dc..dec02469d 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -397,6 +397,14 @@ type ReqProcessorJsnCfg struct { Reply_fields *[]*FcTemplateJsonCfg } +type AttributesOptsJson struct { + ProfileIDs *[]string `json:"*profileIDs"` + ProfileRuns *int `json:"*profileRuns"` + ProfileIgnoreFilters *bool `json:"*profileIgnoreFilters"` + ProcessRuns *int `json:"*processRuns"` + Context *string `json:"*context"` +} + // Attribute service config section type AttributeSJsonCfg struct { Enabled *bool @@ -411,6 +419,7 @@ type AttributeSJsonCfg struct { Process_runs *int Profile_runs *int Any_context *bool + Opts *AttributesOptsJson } // ChargerSJsonCfg service config section diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index 2210d335b..994cb921d 100644 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -212,7 +212,6 @@ func testDspAttrPingFailover2(t *testing.T) { func testDspAttrGetAttrFailover(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -221,7 +220,8 @@ func testDspAttrGetAttrFailover(t *testing.T) { utils.EventName: "Event1", }, APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "attr12345", + utils.OptsAPIKey: "attr12345", + utils.OptsContext: "simpleauth", }, }, } @@ -325,13 +325,15 @@ func testDspAttrPing(t *testing.T) { func testDspAttrTestMissingArgDispatcher(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", Event: map[string]interface{}{ utils.AccountField: "1001", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: "simpleauth", + }, }, } var attrReply *engine.AttributeProfile @@ -343,13 +345,15 @@ func testDspAttrTestMissingArgDispatcher(t *testing.T) { func testDspAttrTestMissingApiKey(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", Event: map[string]interface{}{ utils.AccountField: "1001", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: "simpleauth", + }, }, } var attrReply *engine.AttributeProfile @@ -381,7 +385,6 @@ func testDspAttrTestUnknownApiKey(t *testing.T) { func testDspAttrTestAuthKey(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -389,7 +392,8 @@ func testDspAttrTestAuthKey(t *testing.T) { utils.AccountField: "1001", }, APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "12345", + utils.OptsAPIKey: "12345", + utils.OptsContext: "simpleauth", }, }, } @@ -402,7 +406,6 @@ func testDspAttrTestAuthKey(t *testing.T) { func testDspAttrTestAuthKey2(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -410,7 +413,8 @@ func testDspAttrTestAuthKey2(t *testing.T) { utils.AccountField: "1001", }, APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "attr12345", + utils.OptsAPIKey: "attr12345", + utils.OptsContext: "simpleauth", }, }, } @@ -474,7 +478,6 @@ func testDspAttrTestAuthKey2(t *testing.T) { func testDspAttrTestAuthKey3(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -483,7 +486,8 @@ func testDspAttrTestAuthKey3(t *testing.T) { utils.EventName: "Event1", }, APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "attr12345", + utils.OptsAPIKey: "attr12345", + utils.OptsContext: "simpleauth", }, }, } @@ -496,7 +500,6 @@ func testDspAttrTestAuthKey3(t *testing.T) { func testDspAttrGetAttrRoundRobin(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -505,7 +508,8 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { utils.EventName: "RoundRobin", }, APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "attr12345", + utils.OptsAPIKey: "attr12345", + utils.OptsContext: "simpleauth", }, }, } @@ -587,7 +591,6 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { func testDspAttrGetAttrInternal(t *testing.T) { args := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer("simpleauth"), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSGetAttributeForEvent", @@ -596,7 +599,8 @@ func testDspAttrGetAttrInternal(t *testing.T) { utils.AccountField: "1003", }, APIOpts: map[string]interface{}{ - utils.OptsAPIKey: "attr12345", + utils.OptsAPIKey: "attr12345", + utils.OptsContext: "simpleauth", }, }, } diff --git a/dispatchers/attributes_test.go b/dispatchers/attributes_test.go index 5b0d114c9..4f7bcdbf5 100644 --- a/dispatchers/attributes_test.go +++ b/dispatchers/attributes_test.go @@ -92,15 +92,8 @@ func TestDspAttributeSv1GetAttributeForEventError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) processEvent := &engine.AttrArgsProcessEvent{ - AttributeIDs: nil, - Context: nil, - ProcessRuns: nil, CGREvent: &utils.CGREvent{ - Tenant: "", - ID: "", - Time: &time.Time{}, - Event: nil, - APIOpts: nil, + Time: &time.Time{}, }, } var reply *engine.AttributeProfile @@ -116,15 +109,9 @@ func TestDspAttributeSv1GetAttributeForEventErrorTenant(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) processEvent := &engine.AttrArgsProcessEvent{ - AttributeIDs: nil, - Context: nil, - ProcessRuns: nil, CGREvent: &utils.CGREvent{ - Tenant: "tenant", - ID: "", - Time: &time.Time{}, - Event: nil, - APIOpts: nil, + Tenant: "tenant", + Time: &time.Time{}, }, } var reply *engine.AttributeProfile @@ -139,15 +126,9 @@ func TestDspAttributeSv1GetAttributeForEventErrorAttributeS(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) processEvent := &engine.AttrArgsProcessEvent{ - AttributeIDs: nil, - Context: nil, - ProcessRuns: nil, CGREvent: &utils.CGREvent{ - Tenant: "tenant", - ID: "", - Time: &time.Time{}, - Event: nil, - APIOpts: nil, + Tenant: "tenant", + Time: &time.Time{}, }, } @@ -163,15 +144,9 @@ func TestDspAttributeSv1ProcessEventError(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) processEvent := &engine.AttrArgsProcessEvent{ - AttributeIDs: nil, - Context: nil, - ProcessRuns: nil, CGREvent: &utils.CGREvent{ - Tenant: "tenant", - ID: "", - Time: &time.Time{}, - Event: nil, - APIOpts: nil, + Tenant: "tenant", + Time: &time.Time{}, }, } @@ -188,15 +163,9 @@ func TestDspAttributeSv1ProcessEventErrorAttributeSConns(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) processEvent := &engine.AttrArgsProcessEvent{ - AttributeIDs: nil, - Context: nil, - ProcessRuns: nil, CGREvent: &utils.CGREvent{ - Tenant: "tenant", - ID: "", - Time: &time.Time{}, - Event: nil, - APIOpts: nil, + Tenant: "tenant", + Time: &time.Time{}, }, } diff --git a/dispatchers/dispatchers.go b/dispatchers/dispatchers.go index a2db8e44b..c8e8b9c6e 100644 --- a/dispatchers/dispatchers.go +++ b/dispatchers/dispatchers.go @@ -59,11 +59,11 @@ func (dS *DispatcherService) Shutdown() { func (dS *DispatcherService) authorizeEvent(ev *utils.CGREvent, reply *engine.AttrSProcessEventReply) (err error) { + ev.APIOpts[utils.OptsContext] = utils.MetaAuth if err = dS.connMgr.Call(dS.cfg.DispatcherSCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, &engine.AttrArgsProcessEvent{ CGREvent: ev, - Context: utils.StringPointer(utils.MetaAuth), }, reply); err != nil { if err.Error() == utils.ErrNotFound.Error() { err = utils.ErrUnknownApiKey diff --git a/ees/ees.go b/ees/ees.go index 37b2d1a22..2226b8d30 100644 --- a/ees/ees.go +++ b/ees/ees.go @@ -114,11 +114,11 @@ func (eeS *EventExporterS) attrSProcessEvent(cgrEv *utils.CGREvent, attrIDs []st } } attrArgs := &engine.AttrArgsProcessEvent{ - AttributeIDs: attrIDs, - Context: utils.StringPointer(ctx), - CGREvent: cgrEv, - ProcessRuns: processRuns, + CGREvent: cgrEv, } + attrArgs.CGREvent.APIOpts[utils.OptsAttributesProfileIDs] = attrIDs + attrArgs.CGREvent.APIOpts[utils.OptsContext] = ctx + attrArgs.CGREvent.APIOpts[utils.OptsAttributesProcessRuns] = processRuns if err = eeS.connMgr.Call( eeS.cfg.EEsNoLksCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, diff --git a/engine/attributes.go b/engine/attributes.go index fc7e189ca..0a93313a3 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -163,9 +163,6 @@ func (attrReply *AttrSProcessEventReply) Digest() (rplyDigest string) { // AttrArgsProcessEvent arguments used for proccess event type AttrArgsProcessEvent struct { - AttributeIDs []string - Context *string // attach the event to a context - ProcessRuns *int // number of loops for ProcessEvent *utils.CGREvent clnb bool //rpcclonable } @@ -185,27 +182,8 @@ func (attr *AttrArgsProcessEvent) RPCClone() (interface{}, error) { // Clone creates a clone of the object func (attr *AttrArgsProcessEvent) Clone() *AttrArgsProcessEvent { - var attrIDs []string - if attr.AttributeIDs != nil { - attrIDs = make([]string, len(attr.AttributeIDs)) - for i, id := range attr.AttributeIDs { - attrIDs[i] = id - } - } - var ctx *string - if attr.Context != nil { - ctx = utils.StringPointer(*attr.Context) - } - var procRuns *int - if attr.ProcessRuns != nil { - procRuns = new(int) - *procRuns = *attr.ProcessRuns - } return &AttrArgsProcessEvent{ - AttributeIDs: attrIDs, - Context: ctx, - ProcessRuns: procRuns, - CGREvent: attr.CGREvent.Clone(), + CGREvent: attr.CGREvent.Clone(), } } @@ -213,8 +191,18 @@ func (attr *AttrArgsProcessEvent) Clone() *AttrArgsProcessEvent { func (alS *AttributeService) processEvent(tnt string, args *AttrArgsProcessEvent, evNm utils.MapStorage, dynDP utils.DataProvider, lastID string, processedPrfNo map[string]int, profileRuns int) ( rply *AttrSProcessEventReply, err error) { + context := alS.cgrcfg.AttributeSCfg().Opts.Context + if opt, has := args.APIOpts[utils.OptsContext]; has { + context = utils.StringPointer(utils.IfaceAsString(opt)) + } + attrIDs := alS.cgrcfg.AttributeSCfg().Opts.ProfileIDs + if opt, has := args.APIOpts[utils.OptsAttributesProfileIDs]; has { + if attrIDs, err = utils.IfaceAsSliceString(opt); err != nil { + return + } + } var attrPrf *AttributeProfile - if attrPrf, err = alS.attributeProfileForEvent(tnt, args.Context, args.AttributeIDs, args.Time, evNm, lastID, processedPrfNo, profileRuns); err != nil { + if attrPrf, err = alS.attributeProfileForEvent(tnt, context, attrIDs, args.Time, evNm, lastID, processedPrfNo, profileRuns); err != nil { return } rply = &AttrSProcessEventReply{ @@ -283,7 +271,17 @@ func (alS *AttributeService) V1GetAttributeForEvent(args *AttrArgsProcessEvent, if tnt == utils.EmptyString { tnt = alS.cgrcfg.GeneralCfg().DefaultTenant } - attrPrf, err := alS.attributeProfileForEvent(tnt, args.Context, args.AttributeIDs, args.Time, utils.MapStorage{ + context := alS.cgrcfg.AttributeSCfg().Opts.Context + if opt, has := args.APIOpts[utils.OptsContext]; has { + context = utils.StringPointer(utils.IfaceAsString(opt)) + } + attrIDs := alS.cgrcfg.AttributeSCfg().Opts.ProfileIDs + if opt, has := args.APIOpts[utils.OptsAttributesProfileIDs]; has { + if attrIDs, err = utils.IfaceAsSliceString(opt); err != nil { + return + } + } + attrPrf, err := alS.attributeProfileForEvent(tnt, context, attrIDs, args.Time, utils.MapStorage{ utils.MetaReq: args.CGREvent.Event, utils.MetaOpts: args.APIOpts, utils.MetaVars: utils.MapStorage{ @@ -314,11 +312,15 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, tnt = alS.cgrcfg.GeneralCfg().DefaultTenant } - processRuns := alS.cgrcfg.AttributeSCfg().ProcessRuns - if args.ProcessRuns != nil && *args.ProcessRuns != 0 { - processRuns = *args.ProcessRuns + processRuns := alS.cgrcfg.AttributeSCfg().Opts.ProcessRuns + if opt, has := args.APIOpts[utils.OptsAttributesProcessRuns]; has { + var val int64 + if val, err = utils.IfaceAsTInt64(opt); err != nil { + return + } + processRuns = int(val) } - profileRuns := alS.cgrcfg.AttributeSCfg().ProfileRuns + profileRuns := alS.cgrcfg.AttributeSCfg().Opts.ProfileRuns if opt, has := args.APIOpts[utils.OptsAttributesProfileRuns]; has { var val int64 if val, err = utils.IfaceAsTInt64(opt); err != nil { diff --git a/engine/attributes_test.go b/engine/attributes_test.go index 1f03aa5dd..e0a56a88b 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -63,35 +63,15 @@ func TestAttributesShutdown(t *testing.T) { utils.Logger.SetLogLevel(0) } -func TestAttributesSetCloneable(t *testing.T) { - attr := &AttrArgsProcessEvent{ - AttributeIDs: []string{"ATTR_ID"}, - Context: utils.StringPointer(utils.MetaAny), - ProcessRuns: utils.IntPointer(1), - clnb: true, - } - - exp := &AttrArgsProcessEvent{ - AttributeIDs: []string{"ATTR_ID"}, - Context: utils.StringPointer(utils.MetaAny), - ProcessRuns: utils.IntPointer(1), - clnb: false, - } - attr.SetCloneable(false) - - if !reflect.DeepEqual(attr, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, attr) - } -} - func TestAttributesRPCClone(t *testing.T) { attr := &AttrArgsProcessEvent{ - AttributeIDs: []string{"ATTR_ID"}, - Context: utils.StringPointer(utils.MetaAny), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ - Event: make(map[string]interface{}), - APIOpts: make(map[string]interface{}), + Event: make(map[string]interface{}), + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaAny, + utils.OptsAttributesProfileIDs: []string{"ATTR_ID"}, + }, }, clnb: true, } @@ -99,12 +79,13 @@ func TestAttributesRPCClone(t *testing.T) { rcv, err := attr.RPCClone() exp := &AttrArgsProcessEvent{ - AttributeIDs: []string{"ATTR_ID"}, - Context: utils.StringPointer(utils.MetaAny), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ - Event: make(map[string]interface{}), - APIOpts: make(map[string]interface{}), + Event: make(map[string]interface{}), + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaAny, + utils.OptsAttributesProfileIDs: []string{"ATTR_ID"}, + }, }, clnb: false, } @@ -249,8 +230,10 @@ func TestAttributesV1ProcessEvent(t *testing.T) { Event: map[string]interface{}{ utils.AccountField: "adrian@itsyscom.com", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + }, }, - ProcessRuns: utils.IntPointer(2), }, &rply); err != nil { t.Errorf("Expected <%+v>, received <%+v>", nil, err) } else if sort.Strings(rply.AlteredFields); !reflect.DeepEqual(expected, rply) { @@ -292,8 +275,10 @@ func TestAttributesV1ProcessEventErrorMetaSum(t *testing.T) { Event: map[string]interface{}{ utils.AccountField: "adrian@itsyscom.com", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + }, }, - ProcessRuns: utils.IntPointer(2), }, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected <%+v>, received <%+v>", expErr, err) } @@ -335,8 +320,10 @@ func TestAttributesV1ProcessEventErrorMetaDifference(t *testing.T) { Event: map[string]interface{}{ utils.AccountField: "adrian@itsyscom.com", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + }, }, - ProcessRuns: utils.IntPointer(2), }, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected <%+v>, received <%+v>", expErr, err) } @@ -377,8 +364,10 @@ func TestAttributesV1ProcessEventErrorMetaValueExponent(t *testing.T) { Event: map[string]interface{}{ utils.AccountField: "adrian@itsyscom.com", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + }, }, - ProcessRuns: utils.IntPointer(2), }, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected <%+v>, received <%+v>", expErr, err) } @@ -1162,15 +1151,17 @@ func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) { } args := &AttrArgsProcessEvent{ - AttributeIDs: []string{"ATTR1", "ATTR2"}, - Context: utils.StringPointer(utils.MetaAny), - ProcessRuns: utils.IntPointer(3), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "AttrProcessEventMultipleRuns", Event: map[string]interface{}{ "Password": "passwd", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 3, + utils.OptsContext: utils.MetaAny, + utils.OptsAttributesProfileIDs: []string{"ATTR1", "ATTR2"}, + }, }, } reply := &AttrSProcessEventReply{} @@ -1268,12 +1259,14 @@ func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) { } args := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), - ProcessRuns: utils.IntPointer(3), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "AttrProcessEventMultipleRuns", Event: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 3, + utils.OptsContext: utils.MetaAny, + }, }, } diff --git a/engine/cdrs.go b/engine/cdrs.go index edcaa423d..ab87ae190 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -381,12 +381,12 @@ func (cdrS *CDRServer) attrSProcessEvent(cgrEv *utils.CGREvent) (err error) { } } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.FirstNonEmpty( - utils.IfaceAsString(cgrEv.APIOpts[utils.OptsContext]), - utils.MetaCDRs)), - CGREvent: cgrEv, - ProcessRuns: processRuns, + CGREvent: cgrEv, } + if attrArgs.CGREvent.APIOpts[utils.OptsContext] == utils.EmptyString { + attrArgs.CGREvent.APIOpts[utils.OptsContext] = utils.MetaCDRs + } + attrArgs.CGREvent.APIOpts[utils.OptsAttributesProcessRuns] = processRuns if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 { diff --git a/engine/chargers.go b/engine/chargers.go index fed88ba3b..e4ba57395 100644 --- a/engine/chargers.go +++ b/engine/chargers.go @@ -131,13 +131,13 @@ func (cS *ChargerService) processEvent(tnt string, cgrEv *utils.CGREvent) (rply } args := &AttrArgsProcessEvent{ - AttributeIDs: cP.AttributeIDs, - Context: utils.StringPointer(utils.FirstNonEmpty( - utils.IfaceAsString(clonedEv.APIOpts[utils.OptsContext]), - utils.MetaChargers)), - ProcessRuns: processRuns, - CGREvent: clonedEv, + CGREvent: clonedEv, } + args.CGREvent.APIOpts[utils.OptsAttributesProfileIDs] = cP.AttributeIDs + if args.CGREvent.APIOpts[utils.OptsContext] == utils.EmptyString { + args.CGREvent.APIOpts[utils.OptsContext] = utils.MetaChargers + } + args.CGREvent.APIOpts[utils.OptsAttributesProcessRuns] = processRuns var evReply AttrSProcessEventReply if err = cS.connMgr.Call(cS.cfg.ChargerSCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, args, &evReply); err != nil { diff --git a/engine/routes.go b/engine/routes.go index f23fd4155..87bd16aec 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -590,12 +590,12 @@ func (rpS *RouteService) V1GetRoutes(args *ArgsGetRoutes, reply *SortedRoutesLis } } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.FirstNonEmpty( - utils.IfaceAsString(args.CGREvent.Event[utils.OptsContext]), - utils.MetaRoutes)), - CGREvent: args.CGREvent, - ProcessRuns: processRuns, + CGREvent: args.CGREvent, } + if attrArgs.CGREvent.APIOpts[utils.OptsContext] == utils.EmptyString { + attrArgs.CGREvent.APIOpts[utils.OptsContext] = utils.MetaRoutes + } + attrArgs.CGREvent.APIOpts[utils.OptsAttributesProcessRuns] = processRuns var rplyEv AttrSProcessEventReply if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 { diff --git a/engine/z_attributes_test.go b/engine/z_attributes_test.go index 930c6495d..48e404b30 100644 --- a/engine/z_attributes_test.go +++ b/engine/z_attributes_test.go @@ -33,7 +33,6 @@ var ( dmAtr *DataManager attrEvs = []*AttrArgsProcessEvent{ { - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching AttributeProfile1 Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -43,36 +42,45 @@ var ( "UsageInterval": "1s", utils.Weight: "20.0", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, }, { - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching AttributeProfile2 Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Attribute": "AttributeProfile2", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, }, { - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching AttributeProfilePrefix Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Attribute": "AttributeProfilePrefix", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, }, { - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching AttributeProfilePrefix Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "DistinctMatch": 20, }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, }, } @@ -150,7 +158,7 @@ var ( func TestAttributePopulateAttrService(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 cfg.AttributeSCfg().StringIndexedFields = nil cfg.AttributeSCfg().PrefixIndexedFields = nil data := NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) @@ -238,8 +246,13 @@ func TestAttributeCache(t *testing.T) { } func TestAttributeProfileForEvent(t *testing.T) { - atrp, err := attrS.attributeProfileForEvent(attrEvs[0].Tenant, attrEvs[0].Context, - attrEvs[0].AttributeIDs, attrEvs[0].Time, utils.MapStorage{ + context := utils.StringPointer(utils.IfaceAsString(attrEvs[0].APIOpts[utils.OptsContext])) + var attrIDs []string + if attrIDs, err = utils.IfaceAsSliceString(attrEvs[0].APIOpts[utils.OptsAttributesProfileIDs]); err != nil { + t.Error(err) + } + atrp, err := attrS.attributeProfileForEvent(attrEvs[0].Tenant, context, + attrIDs, attrEvs[0].Time, utils.MapStorage{ utils.MetaReq: attrEvs[0].CGREvent.Event, utils.MetaOpts: attrEvs[0].APIOpts, utils.MetaVars: utils.MapStorage{ @@ -252,8 +265,12 @@ func TestAttributeProfileForEvent(t *testing.T) { if !reflect.DeepEqual(atrPs[0], atrp) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[0]), utils.ToJSON(atrp)) } - atrp, err = attrS.attributeProfileForEvent(attrEvs[1].Tenant, attrEvs[1].Context, - attrEvs[1].AttributeIDs, attrEvs[1].Time, utils.MapStorage{ + context = utils.StringPointer(utils.IfaceAsString(attrEvs[1].APIOpts[utils.OptsContext])) + if attrIDs, err = utils.IfaceAsSliceString(attrEvs[1].APIOpts[utils.OptsAttributesProfileIDs]); err != nil { + t.Error(err) + } + atrp, err = attrS.attributeProfileForEvent(attrEvs[1].Tenant, context, + attrIDs, attrEvs[1].Time, utils.MapStorage{ utils.MetaReq: attrEvs[1].CGREvent.Event, utils.MetaOpts: attrEvs[1].APIOpts, utils.MetaVars: utils.MapStorage{ @@ -266,9 +283,12 @@ func TestAttributeProfileForEvent(t *testing.T) { if !reflect.DeepEqual(atrPs[1], atrp) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(atrPs[1]), utils.ToJSON(atrp)) } - - atrp, err = attrS.attributeProfileForEvent(attrEvs[2].Tenant, attrEvs[2].Context, - attrEvs[2].AttributeIDs, attrEvs[2].Time, utils.MapStorage{ + context = utils.StringPointer(utils.IfaceAsString(attrEvs[2].APIOpts[utils.OptsContext])) + if attrIDs, err = utils.IfaceAsSliceString(attrEvs[2].APIOpts[utils.OptsAttributesProfileIDs]); err != nil { + t.Error(err) + } + atrp, err = attrS.attributeProfileForEvent(attrEvs[2].Tenant, context, + attrIDs, attrEvs[2].Time, utils.MapStorage{ utils.MetaReq: attrEvs[2].CGREvent.Event, utils.MetaOpts: attrEvs[2].APIOpts, utils.MetaVars: utils.MapStorage{ @@ -323,7 +343,7 @@ func TestAttributeProcessEventWithNotFound(t *testing.T) { func TestAttributeProcessEventWithIDs(t *testing.T) { attrEvs[3].CGREvent.Event["Account"] = "1010" //Field added in event after process - attrEvs[3].AttributeIDs = []string{"AttributeIDMatch"} + attrEvs[3].CGREvent.APIOpts[utils.OptsAttributesProfileIDs] = []string{"AttributeIDMatch"} eRply := &AttrSProcessEventReply{ MatchedProfiles: []string{"cgrates.org:AttributeIDMatch"}, AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Account"}, @@ -559,14 +579,16 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -672,14 +694,16 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -781,14 +805,16 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(2), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -871,14 +897,16 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -983,14 +1011,16 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1094,14 +1124,16 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1164,14 +1196,16 @@ func TestAttributeProcessValue(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Field1": "Value1", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1243,14 +1277,16 @@ func TestAttributeAttributeFilterIDs(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "PassField": "Test", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1316,14 +1352,16 @@ func TestAttributeProcessEventConstant(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Field1": "Value1", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1392,8 +1430,6 @@ func TestAttributeProcessEventVariable(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1401,6 +1437,10 @@ func TestAttributeProcessEventVariable(t *testing.T) { "Field1": "Value1", "TheField": "TheVal", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1475,8 +1515,6 @@ func TestAttributeProcessEventComposed(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1484,6 +1522,10 @@ func TestAttributeProcessEventComposed(t *testing.T) { "Field1": "Value1", "TheField": "TheVal", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1548,8 +1590,6 @@ func TestAttributeProcessEventSum(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1558,6 +1598,10 @@ func TestAttributeProcessEventSum(t *testing.T) { "TheField": "TheVal", "NumField": "20", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1623,8 +1667,6 @@ func TestAttributeProcessEventUsageDifference(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1634,6 +1676,10 @@ func TestAttributeProcessEventUsageDifference(t *testing.T) { "UnixTimeStamp": "1554364297", "UnixTimeStamp2": "1554364287", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1700,8 +1746,6 @@ func TestAttributeProcessEventValueExponent(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -1711,6 +1755,10 @@ func TestAttributeProcessEventValueExponent(t *testing.T) { "Multiplier": "2", "Pow": "3", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -1745,7 +1793,7 @@ func TestAttributeProcessEventValueExponent(t *testing.T) { func BenchmarkAttributeProcessEventConstant(b *testing.B) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: cfg}, cfg) @@ -1782,14 +1830,16 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) { b.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Field1": "Value1", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } var reply AttrSProcessEventReply @@ -1803,7 +1853,7 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) { func BenchmarkAttributeProcessEventVariable(b *testing.B) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: cfg}, cfg) @@ -1841,14 +1891,16 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) { b.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Field1": "Value1", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } var reply AttrSProcessEventReply @@ -1892,7 +1944,7 @@ func TestGetAttributeProfileFromInline(t *testing.T) { func TestProcessAttributeConstant(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) attrS = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: cfg}, cfg) @@ -1915,7 +1967,6 @@ func TestProcessAttributeConstant(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_CONSTANT Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeConstant", @@ -1923,6 +1974,9 @@ func TestProcessAttributeConstant(t *testing.T) { "Field1": "Val1", utils.Weight: "20.0", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -1949,7 +2003,7 @@ func TestProcessAttributeConstant(t *testing.T) { func TestProcessAttributeVariable(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -1973,7 +2027,6 @@ func TestProcessAttributeVariable(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_VARIABLE Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeVariable", @@ -1982,7 +2035,9 @@ func TestProcessAttributeVariable(t *testing.T) { "RandomField": "Val2", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2010,7 +2065,7 @@ func TestProcessAttributeVariable(t *testing.T) { func TestProcessAttributeComposed(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2039,7 +2094,6 @@ func TestProcessAttributeComposed(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_COMPOSED Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeComposed", @@ -2049,7 +2103,9 @@ func TestProcessAttributeComposed(t *testing.T) { "RandomField2": "Concatenated", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2077,7 +2133,7 @@ func TestProcessAttributeComposed(t *testing.T) { func TestProcessAttributeUsageDifference(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2101,7 +2157,6 @@ func TestProcessAttributeUsageDifference(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_USAGE_DIFF Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeUsageDifference", @@ -2111,7 +2166,9 @@ func TestProcessAttributeUsageDifference(t *testing.T) { "RandomField2": "1514804400", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2139,7 +2196,7 @@ func TestProcessAttributeUsageDifference(t *testing.T) { func TestProcessAttributeSum(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2163,7 +2220,6 @@ func TestProcessAttributeSum(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_SUM Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeSum", @@ -2173,7 +2229,9 @@ func TestProcessAttributeSum(t *testing.T) { "RandomField2": "5", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2201,7 +2259,7 @@ func TestProcessAttributeSum(t *testing.T) { func TestProcessAttributeDiff(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2225,7 +2283,6 @@ func TestProcessAttributeDiff(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_DIFF Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeDiff", @@ -2235,7 +2292,9 @@ func TestProcessAttributeDiff(t *testing.T) { "RandomField2": "5", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2263,7 +2322,7 @@ func TestProcessAttributeDiff(t *testing.T) { func TestProcessAttributeMultiply(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2287,7 +2346,6 @@ func TestProcessAttributeMultiply(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_MULTIPLY Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeMultiply", @@ -2297,7 +2355,9 @@ func TestProcessAttributeMultiply(t *testing.T) { "RandomField2": "5", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2325,7 +2385,7 @@ func TestProcessAttributeMultiply(t *testing.T) { func TestProcessAttributeDivide(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2349,7 +2409,6 @@ func TestProcessAttributeDivide(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_DIVIDE Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeDivide", @@ -2359,7 +2418,9 @@ func TestProcessAttributeDivide(t *testing.T) { "RandomField2": "5", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2387,7 +2448,7 @@ func TestProcessAttributeDivide(t *testing.T) { func TestProcessAttributeValueExponent(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2411,7 +2472,6 @@ func TestProcessAttributeValueExponent(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_VAL_EXP Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeValueExponent", @@ -2421,7 +2481,9 @@ func TestProcessAttributeValueExponent(t *testing.T) { "RandomField2": "5", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2449,7 +2511,7 @@ func TestProcessAttributeValueExponent(t *testing.T) { func TestProcessAttributeUnixTimeStamp(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2473,7 +2535,6 @@ func TestProcessAttributeUnixTimeStamp(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_UNIX_TIMESTAMP Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeUnixTimeStamp", @@ -2483,7 +2544,9 @@ func TestProcessAttributeUnixTimeStamp(t *testing.T) { "RandomField2": "2013-12-30T15:00:01Z", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2511,7 +2574,7 @@ func TestProcessAttributeUnixTimeStamp(t *testing.T) { func TestProcessAttributePrefix(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2535,7 +2598,6 @@ func TestProcessAttributePrefix(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_VAL_EXP Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeValueExponent", @@ -2544,7 +2606,9 @@ func TestProcessAttributePrefix(t *testing.T) { "Field2": "Val2", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2572,7 +2636,7 @@ func TestProcessAttributePrefix(t *testing.T) { func TestProcessAttributeSuffix(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2596,7 +2660,6 @@ func TestProcessAttributeSuffix(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_VAL_EXP Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeValueExponent", @@ -2605,7 +2668,9 @@ func TestProcessAttributeSuffix(t *testing.T) { "Field2": "Val2", utils.Weight: "20.0", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eNM := utils.MapStorage{ @@ -2634,7 +2699,7 @@ func TestProcessAttributeSuffix(t *testing.T) { func TestAttributeIndexSelectsFalse(t *testing.T) { // change the IndexedSelects to false cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 cfg.AttributeSCfg().StringIndexedFields = nil cfg.AttributeSCfg().PrefixIndexedFields = nil cfg.AttributeSCfg().IndexedSelects = false @@ -2673,14 +2738,16 @@ func TestAttributeIndexSelectsFalse(t *testing.T) { } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(1), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "Account": "1007", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 1, + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -2693,7 +2760,7 @@ func TestAttributeIndexSelectsFalse(t *testing.T) { func TestProcessAttributeWithSameWeight(t *testing.T) { cfg := config.NewDefaultCGRConfig() - cfg.AttributeSCfg().ProcessRuns = 1 + cfg.AttributeSCfg().Opts.ProcessRuns = 1 data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmAtr = NewDataManager(data, config.CgrConfig().CacheCfg(), nil) Cache.Clear(nil) @@ -2734,8 +2801,6 @@ func TestProcessAttributeWithSameWeight(t *testing.T) { t.Error(err) } ev := &AttrArgsProcessEvent{ - ProcessRuns: utils.IntPointer(2), - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ //matching ATTR_UNIX_TIMESTAMP Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: "TestProcessAttributeUnixTimeStamp", @@ -2744,6 +2809,10 @@ func TestProcessAttributeWithSameWeight(t *testing.T) { "RandomField": "1", utils.Weight: "20.0", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + utils.OptsContext: utils.MetaSessionS, + }, }, } var rcv AttrSProcessEventReply @@ -2819,14 +2888,16 @@ func TestAttributeMultipleProcessWithFiltersExists(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -2841,6 +2912,9 @@ func TestAttributeMultipleProcessWithFiltersExists(t *testing.T) { "Field1": "Value1", "Field2": "Value2", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + }, }, } var reply AttrSProcessEventReply @@ -2913,14 +2987,16 @@ func TestAttributeMultipleProcessWithFiltersNotEmpty(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(4), CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := &AttrSProcessEventReply{ @@ -2935,6 +3011,9 @@ func TestAttributeMultipleProcessWithFiltersNotEmpty(t *testing.T) { "Field1": "Value1", "Field2": "Value2", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 4, + }, }, } var reply AttrSProcessEventReply @@ -2980,11 +3059,12 @@ func TestAttributeMetaTenant(t *testing.T) { t.Error(err) } args := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - Event: map[string]interface{}{}, - APIOpts: map[string]interface{}{}, + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + Event: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := AttrSProcessEventReply{ @@ -3078,13 +3158,15 @@ func TestAttributesPorcessEventMatchingProcessRuns(t *testing.T) { attr := NewAttributeService(dm, fltrS, cfg) args := &AttrArgsProcessEvent{ - ProcessRuns: utils.IntPointer(2), - Context: utils.StringPointer(utils.MetaAny), CGREvent: &utils.CGREvent{ Event: map[string]interface{}{ "Account": "pc_test", "CompanyName": "MY_company_will_be_changed", }, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + utils.OptsContext: utils.MetaSessionS, + }, }, } reply := &AttrSProcessEventReply{} @@ -3098,7 +3180,9 @@ func TestAttributesPorcessEventMatchingProcessRuns(t *testing.T) { "CompanyName": "ITSYS COMMUNICATIONS SRL", "Password": "CGRateS.org", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsAttributesProcessRuns: 2, + }, }, } if err := attr.V1ProcessEvent(args, reply); err != nil { @@ -3151,8 +3235,6 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { t.Error(err) } args := &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(40), CGREvent: &utils.CGREvent{ Tenant: cfg.GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -3161,6 +3243,8 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { }, APIOpts: map[string]interface{}{ utils.OptsAttributesProfileRuns: 2, + utils.OptsAttributesProcessRuns: 40, + utils.OptsContext: utils.MetaSessionS, }, }, } @@ -3178,6 +3262,7 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { }, APIOpts: map[string]interface{}{ utils.OptsAttributesProfileRuns: 2, + utils.OptsAttributesProcessRuns: 40, }, }, } @@ -3191,8 +3276,6 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { } args = &AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - ProcessRuns: utils.IntPointer(40), CGREvent: &utils.CGREvent{ Tenant: cfg.GeneralCfg().DefaultTenant, ID: utils.GenUUID(), @@ -3201,6 +3284,8 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { }, APIOpts: map[string]interface{}{ utils.OptsAttributesProfileRuns: 1, + utils.OptsAttributesProcessRuns: 40, + utils.OptsContext: utils.MetaSessionS, }, }, } @@ -3218,6 +3303,7 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { }, APIOpts: map[string]interface{}{ utils.OptsAttributesProfileRuns: 1, + utils.OptsAttributesProcessRuns: 40, }, }, } diff --git a/general_tests/attributes_filters_index_it_test.go b/general_tests/attributes_filters_index_it_test.go index 72df1d182..351171d5f 100644 --- a/general_tests/attributes_filters_index_it_test.go +++ b/general_tests/attributes_filters_index_it_test.go @@ -162,13 +162,14 @@ func testAttributeSetProfile(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", Event: map[string]interface{}{ "Subject": "44", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } var rplyEv engine.AttrSProcessEventReply @@ -213,13 +214,14 @@ func testAttributeSetFltr2(t *testing.T) { //same event for process ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", Event: map[string]interface{}{ "Subject": "4444", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } exp := engine.AttrSProcessEventReply{ diff --git a/general_tests/attributes_it_test.go b/general_tests/attributes_it_test.go index c71b44f92..0a9690969 100644 --- a/general_tests/attributes_it_test.go +++ b/general_tests/attributes_it_test.go @@ -128,7 +128,6 @@ func testAttributeSLoadFromFolder(t *testing.T) { func testAttributeSProcessEvent(t *testing.T) { ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEvent", @@ -136,7 +135,9 @@ func testAttributeSProcessEvent(t *testing.T) { utils.EventName: "VariableTest", utils.ToR: utils.MetaVoice, }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } eRply := engine.AttrSProcessEventReply{ @@ -211,14 +212,15 @@ func testAttributeSProcessEventWithAccount(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithAccount", Event: map[string]interface{}{ "EventName": "AddAccountInfo", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -293,14 +295,15 @@ func testAttributeSProcessEventWithAccountFull(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithAccount2", Event: map[string]interface{}{ "EventName": "AddFullAccount", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -424,15 +427,15 @@ func testAttributeSProcessEventWithStat(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithStat", Event: map[string]interface{}{ "EventName": "AddStatEvent", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -507,14 +510,15 @@ func testAttributeSProcessEventWithStatFull(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithStat", Event: map[string]interface{}{ "EventName": "AddFullStats", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -652,15 +656,15 @@ func testAttributeSProcessEventWithResource(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), - CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithResource", Event: map[string]interface{}{ "EventName": "AddResourceUsages", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -735,13 +739,15 @@ func testAttributeSProcessEventWithResourceFull(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithResource2", Event: map[string]interface{}{ "EventName": "AddFullResource", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -826,7 +832,6 @@ func testAttributeSProcessEventWithLibPhoneNumber(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithLibPhoneNumber2", @@ -834,7 +839,9 @@ func testAttributeSProcessEventWithLibPhoneNumber(t *testing.T) { "EventName": "AddDestinationCarrier", "Destination": "+447779330921", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -928,7 +935,6 @@ func testAttributeSProcessEventWithLibPhoneNumberComposed(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithLibPhoneNumberComposed", @@ -936,7 +942,9 @@ func testAttributeSProcessEventWithLibPhoneNumberComposed(t *testing.T) { "EventName": "AddComposedInfo", "Destination": "+447779330921", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } @@ -1012,7 +1020,6 @@ func testAttributeSProcessEventWithLibPhoneNumberFull(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaSessionS), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testAttributeSProcessEventWithLibPhoneNumber", @@ -1020,7 +1027,9 @@ func testAttributeSProcessEventWithLibPhoneNumberFull(t *testing.T) { "EventName": "AddDestinationDetails", "Destination": "+447779330921", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaSessionS, + }, }, } diff --git a/general_tests/cacherpl_filter_update_it_test.go b/general_tests/cacherpl_filter_update_it_test.go index 8cbe8aa67..bcea53ee0 100644 --- a/general_tests/cacherpl_filter_update_it_test.go +++ b/general_tests/cacherpl_filter_update_it_test.go @@ -63,6 +63,9 @@ var ( Event: map[string]interface{}{ utils.AccountField: "1001", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaAny, + }, } ev2 = &utils.CGREvent{ Tenant: "cgrates.org", @@ -70,6 +73,9 @@ var ( Event: map[string]interface{}{ utils.AccountField: "1002", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaAny, + }, } ) @@ -218,7 +224,6 @@ func testFilterUpdateSetAttrProfileE1(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv1E1(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev1, } @@ -252,7 +257,6 @@ func testFilterUpdateGetAttrProfileForEventEv1E1(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv1E2(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev1, } @@ -286,7 +290,6 @@ func testFilterUpdateGetAttrProfileForEventEv1E2(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv2E1(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev2, } @@ -320,7 +323,6 @@ func testFilterUpdateGetAttrProfileForEventEv2E1(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv2E2(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev2, } @@ -388,7 +390,6 @@ func testFilterUpdateSetFilterAfterAttrE1(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv1E1NotMatching(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev1, } @@ -401,7 +402,6 @@ func testFilterUpdateGetAttrProfileForEventEv1E1NotMatching(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv1E2NotMatching(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev1, } @@ -414,7 +414,6 @@ func testFilterUpdateGetAttrProfileForEventEv1E2NotMatching(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv2E1NotMatching(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev2, } @@ -427,7 +426,6 @@ func testFilterUpdateGetAttrProfileForEventEv2E1NotMatching(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv2E2NotMatching(t *testing.T) { attrProcessEv := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.MetaAny), CGREvent: ev2, } diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index f47864558..395ca33f9 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -1061,9 +1061,10 @@ func testV1FltrAttributesPrefix(t *testing.T) { "CustomField2": "+2007", utils.Destination: "+1207", }, - APIOpts: map[string]interface{}{}, + APIOpts: map[string]interface{}{ + utils.OptsContext: "prefix", + }, }, - Context: utils.StringPointer("prefix"), } var result2 *engine.AttrSProcessEventReply if err := fltrRpc.Call(utils.AttributeSv1ProcessEvent, cgrEv, &result2); err != nil { @@ -1136,14 +1137,16 @@ func testV1FltrPopulateTimings(t *testing.T) { } ev := &engine.AttrArgsProcessEvent{ - AttributeIDs: []string{"FltrTest"}, - Context: utils.StringPointer(utils.MetaAny), CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testV1FltrPopulateTimings", Event: map[string]interface{}{ utils.AnswerTime: "2021-04-29T08:35:00Z", }, + APIOpts: map[string]interface{}{ + utils.OptsContext: utils.MetaAny, + utils.OptsAttributesProfileIDs: []string{"FltrTest"}, + }, }, } eRply := &engine.AttrSProcessEventReply{ diff --git a/sessions/sessions.go b/sessions/sessions.go index 736795e2d..bc9e4284e 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -3882,13 +3882,13 @@ func (sS *SessionS) processAttributes(cgrEv *utils.CGREvent, attrIDs []string, } } attrArgs := &engine.AttrArgsProcessEvent{ - Context: utils.StringPointer(utils.FirstNonEmpty( - utils.IfaceAsString(cgrEv.APIOpts[utils.OptsContext]), - utils.MetaSessionS)), - CGREvent: cgrEv, - AttributeIDs: attrIDs, - ProcessRuns: processRuns, + CGREvent: cgrEv, } + attrArgs.CGREvent.APIOpts[utils.OptsAttributesProfileIDs] = attrIDs + if attrArgs.CGREvent.APIOpts[utils.OptsContext] == utils.EmptyString { + attrArgs.CGREvent.APIOpts[utils.OptsContext] = utils.MetaSessionS + } + attrArgs.CGREvent.APIOpts[utils.OptsAttributesProcessRuns] = processRuns attrArgs.SetCloneable(clnb) err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().AttrSConns, nil, utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv) diff --git a/sessions/sessionscover_test.go b/sessions/sessionscover_test.go index 54bb7dc6e..2caeea888 100644 --- a/sessions/sessionscover_test.go +++ b/sessions/sessionscover_test.go @@ -2756,7 +2756,8 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { return nil }, utils.AttributeSv1ProcessEvent: func(args interface{}, reply interface{}) error { - if len(args.(*engine.AttrArgsProcessEvent).AttributeIDs) != 0 { + if attrIDs, err := utils.IfaceAsSliceString(args.(*engine.AttrArgsProcessEvent).APIOpts[utils.OptsAttributesProfileIDs]); err == nil && + len(attrIDs) != 0 { return utils.ErrNotImplemented } return nil @@ -3103,7 +3104,8 @@ func TestBiRPCv1UpdateSession1(t *testing.T) { clnt := &testMockClients{ calls: map[string]func(args interface{}, reply interface{}) error{ utils.AttributeSv1ProcessEvent: func(args interface{}, reply interface{}) error { - if len(args.(*engine.AttrArgsProcessEvent).AttributeIDs) == 1 { + if attrIDs, err := utils.IfaceAsSliceString(args.(*engine.AttrArgsProcessEvent).APIOpts[utils.OptsAttributesProfileIDs]); err == nil && + len(attrIDs) == 1 { return utils.ErrNotImplemented } return nil diff --git a/utils/consts.go b/utils/consts.go index f29f590d1..97799253c 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -2171,11 +2171,13 @@ const ( ClientDictionariesCfg = "client_dictionaries" // AttributeSCfg - IndexedSelectsCfg = "indexed_selects" - ProcessRunsCfg = "process_runs" - ProfileRunsCfg = "profile_runs" - NestedFieldsCfg = "nested_fields" - AnyContextCfg = "any_context" + IndexedSelectsCfg = "indexed_selects" + MetaProfileIDs = "*profileIDs" + MetaProcessRunsCfg = "*processRuns" + MetaProfileRunsCfg = "*profileRuns" + MetaProfileIgnoreFiltersCfg = "*profileIgnoreFilters" + NestedFieldsCfg = "nested_fields" + AnyContextCfg = "any_context" // ChargerSCfg StoreIntervalCfg = "store_interval" @@ -2450,8 +2452,9 @@ const ( OptsContext = "*context" Subsys = "*subsys" MetaMethod = "*reqMethod" - OptsAttributesProcessRuns = "*processRuns" - OptsAttributesProfileRuns = "*profileRuns" + OptsAttributesProfileIDs = "*attrProfileIDs" + OptsAttributesProcessRuns = "*attrProcessRuns" + OptsAttributesProfileRuns = "*attrProfileRuns" MetaEventType = "*eventType" EventType = "EventType" SchedulerInit = "SchedulerInit"