From 5a25443e174d8f0e24faacc2d90338bc74b51234 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 5 Feb 2021 17:07:42 +0200 Subject: [PATCH] Updated the syntax for inline filters and attributes values --- actions/actions_test.go | 12 +++--- apier/v1/libapier_test.go | 10 ++--- console/command_executer_test.go | 3 +- data/conf/samples/ees_internal/cgrates.json | 2 +- data/conf/samples/ees_mongo/cgrates.json | 2 +- data/conf/samples/ees_mysql/cgrates.json | 2 +- .../filtered_scheduler2_internal/cgrates.json | 2 +- .../filtered_scheduler2_mongo/cgrates.json | 2 +- .../filtered_scheduler2_mysql/cgrates.json | 2 +- engine/filters.go | 10 ++--- engine/filters_test.go | 14 +++---- engine/libattributes.go | 2 +- engine/libattributes_test.go | 19 ++++++--- engine/libengine.go | 1 - engine/libstats_test.go | 2 +- engine/model_helpers.go | 2 +- engine/z_attributes_test.go | 2 +- general_tests/filters_it_test.go | 2 +- migrator/derived_chargers.go | 2 +- migrator/derived_chargers_it_test.go | 4 +- migrator/derived_chargers_test.go | 2 +- migrator/filters.go | 2 +- migrator/storage_redis.go | 2 +- migrator/thresholds_test.go | 40 +++++++++++++------ rates/rates_test.go | 8 ++-- sessions/sessions_test.go | 8 ++-- 26 files changed, 90 insertions(+), 69 deletions(-) diff --git a/actions/actions_test.go b/actions/actions_test.go index c9f37b42c..a481421e4 100644 --- a/actions/actions_test.go +++ b/actions/actions_test.go @@ -56,7 +56,7 @@ func TestMatchingActionProfilesForEvent(t *testing.T) { actPrf := &engine.ActionProfile{ Tenant: "cgrates.org", ID: "test_id1", - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, Actions: []*engine.APAction{ { ID: "TOPUP", @@ -163,7 +163,7 @@ func TestScheduledActions(t *testing.T) { actPrf := &engine.ActionProfile{ Tenant: "cgrates.org", ID: "test_id1", - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, Actions: []*engine.APAction{ { ID: "TOPUP", @@ -238,7 +238,7 @@ func TestScheduleAction(t *testing.T) { actPrf := &engine.ActionProfile{ Tenant: "cgrates.org", ID: "test_id1", - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, Schedule: "* * * * *", Actions: []*engine.APAction{ { @@ -362,7 +362,7 @@ func TestV1ScheduleActions(t *testing.T) { actPrf := &engine.ActionProfile{ Tenant: "cgrates.org", ID: "test_id1", - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, Schedule: utils.MetaASAP, Actions: []*engine.APAction{ { @@ -418,7 +418,7 @@ func TestV1ExecuteActions(t *testing.T) { actPrf := &engine.ActionProfile{ Tenant: "cgrates.org", ID: "test_id1", - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, Schedule: utils.MetaASAP, Actions: []*engine.APAction{ { @@ -486,7 +486,7 @@ func (dbM *dataDBMockError) GetActionProfileDrv(string, string) (*engine.ActionP return &engine.ActionProfile{ Tenant: "cgrates.org", ID: "test_id1", - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, Actions: []*engine.APAction{ { ID: "TOPUP", diff --git a/apier/v1/libapier_test.go b/apier/v1/libapier_test.go index d839a6390..ca045578a 100644 --- a/apier/v1/libapier_test.go +++ b/apier/v1/libapier_test.go @@ -60,7 +60,7 @@ func TestComposeArgsReload(t *testing.T) { } if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles, - "cgrates.org:ATTR1", &[]string{"*string:~*req.Account:1001;~req.Subject", "*prefix:1001:~*req.Destination", "*gt:~req.Usage:0"}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil { + "cgrates.org:ATTR1", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination", "*gt:~req.Usage:0"}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expArgs, rply) { t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply)) @@ -79,7 +79,7 @@ func TestComposeArgsReload(t *testing.T) { } if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheStatQueueProfiles, - "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001;~req.Subject", "*prefix:1001:~*req.Destination"}, nil, make(map[string]interface{})); err != nil { + "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"}, nil, make(map[string]interface{})); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expArgs, rply) { t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply)) @@ -162,7 +162,7 @@ func TestCallCache(t *testing.T) { } if err := apv1.CallCache(utils.StringPointer(utils.MetaReload), "cgrates.org", utils.CacheStatQueueProfiles, - "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001;~req.Subject", "*prefix:1001:~*req.Destination"}, + "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"}, nil, make(map[string]interface{})); err != nil { t.Fatal(err) } else if len(cache) != 1 { @@ -172,7 +172,7 @@ func TestCallCache(t *testing.T) { } exp.Method = utils.CacheSv1LoadCache if err := apv1.CallCache(utils.StringPointer(utils.MetaLoad), "cgrates.org", utils.CacheStatQueueProfiles, - "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001;~req.Subject", "*prefix:1001:~*req.Destination"}, + "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"}, nil, make(map[string]interface{})); err != nil { t.Fatal(err) } else if len(cache) != 1 { @@ -182,7 +182,7 @@ func TestCallCache(t *testing.T) { } exp.Method = utils.CacheSv1RemoveItems if err := apv1.CallCache(utils.StringPointer(utils.MetaRemove), "cgrates.org", utils.CacheStatQueueProfiles, - "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001;~req.Subject", "*prefix:1001:~*req.Destination"}, + "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"}, nil, make(map[string]interface{})); err != nil { t.Fatal(err) } else if len(cache) != 1 { diff --git a/console/command_executer_test.go b/console/command_executer_test.go index e43f419a8..5917b0238 100644 --- a/console/command_executer_test.go +++ b/console/command_executer_test.go @@ -19,7 +19,6 @@ package console import ( "encoding/json" - "fmt" "os" "reflect" "sort" @@ -345,7 +344,7 @@ func TestCommandExecuterLocalFromArgsCase2(t *testing.T) { err := testStruct.FromArgs(cmdArgs, true) expected := "json: Unmarshal(non-pointer struct {})" if err == nil || err.Error() != expected { - fmt.Errorf("\nExpected <%+v>, \nRecevied <%+v>", expected, err) + t.Errorf("\nExpected <%+v>, \nRecevied <%+v>", expected, err) } } diff --git a/data/conf/samples/ees_internal/cgrates.json b/data/conf/samples/ees_internal/cgrates.json index e8d8a9516..aece68ee5 100644 --- a/data/conf/samples/ees_internal/cgrates.json +++ b/data/conf/samples/ees_internal/cgrates.json @@ -122,7 +122,7 @@ "synchronous": false, "attempts": 1, "field_separator": ",", - "filters": ["*string:~*req.CGRID:Cdr1;Cdr2"], + "filters": ["*string:~*req.CGRID:Cdr1|Cdr2"], "fields":[ {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"}, {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"}, diff --git a/data/conf/samples/ees_mongo/cgrates.json b/data/conf/samples/ees_mongo/cgrates.json index 39e90cce6..1f9461669 100644 --- a/data/conf/samples/ees_mongo/cgrates.json +++ b/data/conf/samples/ees_mongo/cgrates.json @@ -126,7 +126,7 @@ "synchronous": false, "attempts": 1, "field_separator": ",", - "filters": ["*string:~*req.CGRID:Cdr1;Cdr2"], + "filters": ["*string:~*req.CGRID:Cdr1|Cdr2"], "fields":[ {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"}, {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"}, diff --git a/data/conf/samples/ees_mysql/cgrates.json b/data/conf/samples/ees_mysql/cgrates.json index 2abf340b1..4dd815444 100644 --- a/data/conf/samples/ees_mysql/cgrates.json +++ b/data/conf/samples/ees_mysql/cgrates.json @@ -124,7 +124,7 @@ "synchronous": false, "attempts": 1, "field_separator": ",", - "filters": ["*string:~*req.CGRID:Cdr1;Cdr2"], + "filters": ["*string:~*req.CGRID:Cdr1|Cdr2"], "fields":[ {"tag": "CGRID", "path": "*exp.CGRID", "type": "*variable", "value": "~*req.CGRID"}, {"tag": "RunID", "path": "*exp.RunID", "type": "*variable", "value": "~*req.RunID"}, diff --git a/data/conf/samples/filtered_scheduler2_internal/cgrates.json b/data/conf/samples/filtered_scheduler2_internal/cgrates.json index 28a42828a..dbd2b3ac6 100644 --- a/data/conf/samples/filtered_scheduler2_internal/cgrates.json +++ b/data/conf/samples/filtered_scheduler2_internal/cgrates.json @@ -33,7 +33,7 @@ "schedulers": { "enabled": true, - "filters": ["*suffix:~*act.AccountID:1002;1003"], + "filters": ["*suffix:~*act.AccountID:1002|1003"], }, diff --git a/data/conf/samples/filtered_scheduler2_mongo/cgrates.json b/data/conf/samples/filtered_scheduler2_mongo/cgrates.json index 080a9c84d..5fc653cc7 100644 --- a/data/conf/samples/filtered_scheduler2_mongo/cgrates.json +++ b/data/conf/samples/filtered_scheduler2_mongo/cgrates.json @@ -37,7 +37,7 @@ "schedulers": { "enabled": true, - "filters": ["*suffix:~*act.AccountID:1002;1003"], + "filters": ["*suffix:~*act.AccountID:1002|1003"], }, diff --git a/data/conf/samples/filtered_scheduler2_mysql/cgrates.json b/data/conf/samples/filtered_scheduler2_mysql/cgrates.json index 6cdbb3d41..984fe3655 100644 --- a/data/conf/samples/filtered_scheduler2_mysql/cgrates.json +++ b/data/conf/samples/filtered_scheduler2_mysql/cgrates.json @@ -35,7 +35,7 @@ "schedulers": { "enabled": true, - "filters": ["*suffix:~*act.AccountID:1002;1003"], + "filters": ["*suffix:~*act.AccountID:1002|1003"], }, diff --git a/engine/filters.go b/engine/filters.go index 7fdd8255d..38513c987 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -147,20 +147,20 @@ func (fS *FilterS) LazyPass(tenant string, filterIDs []string, return } -func splitDynFltrValues(val string) (vals []string) { +func splitDynFltrValues(val, sep string) (vals []string) { startIdx := strings.IndexByte(val, utils.RSRDynStartChar) endIdx := strings.IndexByte(val, utils.RSRDynEndChar) if startIdx == -1 || endIdx == -1 { - return strings.Split(val, utils.InfieldSep) + return strings.Split(val, sep) } - vals = strings.Split(val[:startIdx], utils.InfieldSep) + vals = strings.Split(val[:startIdx], sep) vals[len(vals)-1] += val[startIdx : endIdx+1] val = val[endIdx+1:] if len(val) == 0 { return } - valsEnd := splitDynFltrValues(val) + valsEnd := splitDynFltrValues(val, sep) vals[len(vals)-1] += valsEnd[0] return append(vals, valsEnd[1:]...) } @@ -173,7 +173,7 @@ func NewFilterFromInline(tenant, inlnRule string) (f *Filter, err error) { } var vals []string if ruleSplt[2] != utils.EmptyString { - vals = splitDynFltrValues(ruleSplt[2]) + vals = splitDynFltrValues(ruleSplt[2], utils.PipeSep) } f = &Filter{ Tenant: tenant, diff --git a/engine/filters_test.go b/engine/filters_test.go index 21bef94c6..c48be1479 100644 --- a/engine/filters_test.go +++ b/engine/filters_test.go @@ -1337,7 +1337,7 @@ func TestPassPartial(t *testing.T) { func TestNewFilterFromInline(t *testing.T) { exp := &Filter{ Tenant: "cgrates.org", - ID: "*string:~*req.Account:~*uhc.<~*req.CGRID;-Account>;1001", + ID: "*string:~*req.Account:~*uhc.<~*req.CGRID;-Account>|1001", Rules: []*FilterRule{ { Type: utils.MetaString, @@ -1349,7 +1349,7 @@ func TestNewFilterFromInline(t *testing.T) { if err := exp.Compile(); err != nil { t.Fatal(err) } - if rcv, err := NewFilterFromInline("cgrates.org", "*string:~*req.Account:~*uhc.<~*req.CGRID;-Account>;1001"); err != nil { + if rcv, err := NewFilterFromInline("cgrates.org", "*string:~*req.Account:~*uhc.<~*req.CGRID;-Account>|1001"); err != nil { t.Error(err) } else if !reflect.DeepEqual(exp, rcv) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(exp), utils.ToJSON(rcv)) @@ -1359,7 +1359,7 @@ func TestNewFilterFromInline(t *testing.T) { t.Error("Expected error received nil") } - if _, err := NewFilterFromInline("cgrates.org", "*string:~*req.Account:~*req.CGRID{*;1001"); err == nil { + if _, err := NewFilterFromInline("cgrates.org", "*string:~*req.Account:~*req.CGRID{*|1001"); err == nil { t.Error("Expected error received nil") } } @@ -1401,28 +1401,28 @@ func TestActivationIntervalPass(t *testing.T) { } if pass, err := filterS.Pass("cgrates.org", - []string{"*ai:~*req.CustomTime:;2013-09-01T00:00:00Z"}, fEv); err != nil { + []string{"*ai:~*req.CustomTime:|2013-09-01T00:00:00Z"}, fEv); err != nil { t.Error(err) } else if !pass { t.Errorf("Expecting: %+v, received: %+v", true, pass) } if pass, err := filterS.Pass("cgrates.org", - []string{"*ai:~*req.CustomTime:;2013-06-01T00:00:00Z"}, fEv); err != nil { + []string{"*ai:~*req.CustomTime:|2013-06-01T00:00:00Z"}, fEv); err != nil { t.Error(err) } else if pass { t.Errorf("Expecting: %+v, received: %+v", false, pass) } if pass, err := filterS.Pass("cgrates.org", - []string{"*ai:~*req.CustomTime:2013-06-01T00:00:00Z;2013-09-01T00:00:00Z"}, fEv); err != nil { + []string{"*ai:~*req.CustomTime:2013-06-01T00:00:00Z|2013-09-01T00:00:00Z"}, fEv); err != nil { t.Error(err) } else if !pass { t.Errorf("Expecting: %+v, received: %+v", true, pass) } if pass, err := filterS.Pass("cgrates.org", - []string{"*ai:~*req.CustomTime:2013-08-01T00:00:00Z;2013-09-01T00:00:00Z"}, fEv); err != nil { + []string{"*ai:~*req.CustomTime:2013-08-01T00:00:00Z|2013-09-01T00:00:00Z"}, fEv); err != nil { t.Error(err) } else if pass { t.Errorf("Expecting: %+v, received: %+v", false, pass) diff --git a/engine/libattributes.go b/engine/libattributes.go index 77333366f..b338fb92a 100644 --- a/engine/libattributes.go +++ b/engine/libattributes.go @@ -145,7 +145,7 @@ func NewAttributeFromInline(tenant, inlnRule string) (attr *AttributeProfile, er return nil, fmt.Errorf("inline parse error for string: <%s>", rule) } var vals config.RSRParsers - if vals, err = config.NewRSRParsers(ruleSplt[2], utils.PipeSep); err != nil { + if vals, err = config.NewRSRParsers(ruleSplt[2], utils.ANDSep); err != nil { return nil, err } if len(ruleSplt[1]) == 0 { diff --git a/engine/libattributes_test.go b/engine/libattributes_test.go index a1644c304..1d0702e7b 100644 --- a/engine/libattributes_test.go +++ b/engine/libattributes_test.go @@ -123,16 +123,23 @@ func TestConvertExternalToProfileMissing2(t *testing.T) { } func TestNewAttributeFromInline(t *testing.T) { - attrID := "*sum:*req.Field2:10|~*req.NumField|20" + attrID := "*sum:*req.Field2:10&~*req.NumField&20;*sum:*req.Field3:10&~*req.NumField4&20" expAttrPrf1 := &AttributeProfile{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: attrID, Contexts: []string{utils.MetaAny}, - Attributes: []*Attribute{{ - Path: utils.MetaReq + utils.NestingSep + "Field2", - Type: utils.MetaSum, - Value: config.NewRSRParsersMustCompile("10;~*req.NumField;20", utils.InfieldSep), - }}, + Attributes: []*Attribute{ + { + Path: utils.MetaReq + utils.NestingSep + "Field2", + Type: utils.MetaSum, + Value: config.NewRSRParsersMustCompile("10;~*req.NumField;20", utils.InfieldSep), + }, + { + Path: utils.MetaReq + utils.NestingSep + "Field3", + Type: utils.MetaSum, + Value: config.NewRSRParsersMustCompile("10;~*req.NumField4;20", utils.InfieldSep), + }, + }, } attr, err := NewAttributeFromInline(config.CgrConfig().GeneralCfg().DefaultTenant, attrID) if err != nil { diff --git a/engine/libengine.go b/engine/libengine.go index df69bad7d..175ebc685 100644 --- a/engine/libengine.go +++ b/engine/libengine.go @@ -62,7 +62,6 @@ func NewRPCConnection(cfg *config.RemoteHost, keyPath, certPath, caPath string, return rpcclient.NewRPCClient(utils.TCP, cfg.Address, cfg.TLS, keyPath, certPath, caPath, connAttempts, reconnects, connectTimeout, replyTimeout, utils.FirstNonEmpty(cfg.Transport, rpcclient.GOBrpc), nil, lazyConnect) - return } // IntRPC is the global variable that is used to comunicate with all the subsystems internally diff --git a/engine/libstats_test.go b/engine/libstats_test.go index 872fa366a..c261e7291 100644 --- a/engine/libstats_test.go +++ b/engine/libstats_test.go @@ -241,7 +241,7 @@ func TestStatRemOnQueueLength2(t *testing.T) { sq = &StatQueue{ sqPrfl: &StatQueueProfile{ QueueLength: 2, - FilterIDs: []string{"*string:~Account:1001;1002"}, + FilterIDs: []string{"*string:~Account:1001|1002"}, }, SQItems: []SQItem{ {"cgrates.org:TestStatRemExpired_1", nil}, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index f0f296e5b..733b7d722 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1734,7 +1734,7 @@ func (tps FilterMdls) AsTPFilter() (result []*utils.TPFilterProfile) { if tp.Type != utils.EmptyString { var vals []string if tp.Values != utils.EmptyString { - vals = splitDynFltrValues(tp.Values) + vals = splitDynFltrValues(tp.Values, utils.InfieldSep) } th.Filters = append(th.Filters, &utils.TPFilter{ Type: tp.Type, diff --git a/engine/z_attributes_test.go b/engine/z_attributes_test.go index cd51c6031..c5e2055b9 100644 --- a/engine/z_attributes_test.go +++ b/engine/z_attributes_test.go @@ -1878,7 +1878,7 @@ func TestGetAttributeProfileFromInline(t *testing.T) { } else if test != true { t.Errorf("Expecting: true got :%+v", test) } - attrID := "*sum:*req.Field2:10|~*req.NumField|20" + attrID := "*sum:*req.Field2:10&~*req.NumField&20" expAttrPrf1 := &AttributeProfile{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, ID: attrID, diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index 67724ce45..ed3106eaf 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -852,7 +852,7 @@ func testV1FltrAttributesPrefix(t *testing.T) { AttributeProfile: &engine.AttributeProfile{ Tenant: "cgrates.new", ID: "ATTR_1001", - FilterIDs: []string{"*prefix:~*req.CustomField:2007;+2007", "*prefix:~*req.CustomField2:2007;+2007", "FLTR_1"}, + FilterIDs: []string{"*prefix:~*req.CustomField:2007|+2007", "*prefix:~*req.CustomField2:2007|+2007", "FLTR_1"}, Contexts: []string{"prefix"}, Attributes: []*engine.Attribute{ { diff --git a/migrator/derived_chargers.go b/migrator/derived_chargers.go index 441f6275d..96e7ef107 100644 --- a/migrator/derived_chargers.go +++ b/migrator/derived_chargers.go @@ -158,7 +158,7 @@ func (m *Migrator) derivedChargers2Chargers(dck *v1DerivedChargersWithKey) (err if len(dck.Value.DestinationIDs) != 0 { destination = fmt.Sprintf("%s:~%s:", utils.MetaDestinations, utils.MetaReq+utils.NestingSep+utils.Destination) keys := dcGetMapKeys(dck.Value.DestinationIDs) - destination += strings.Join(keys, utils.InfieldSep) + destination += strings.Join(keys, utils.PipeSep) } filter := make([]string, 0) diff --git a/migrator/derived_chargers_it_test.go b/migrator/derived_chargers_it_test.go index 2529a1662..02595f90c 100644 --- a/migrator/derived_chargers_it_test.go +++ b/migrator/derived_chargers_it_test.go @@ -150,7 +150,7 @@ func testDCITMigrateAndMove(t *testing.T) { ID: fmt.Sprintf("%s_%v", derivch.Key, 0), Contexts: []string{utils.MetaChargers}, FilterIDs: []string{ - "*destinations:~*req.Destination:1001;1002;1003", + "*destinations:~*req.Destination:1001|1002|1003", "*string:~*req.Account:1003", }, ActivationInterval: nil, @@ -174,7 +174,7 @@ func testDCITMigrateAndMove(t *testing.T) { Tenant: defaultTenant, ID: fmt.Sprintf("%s_%v", derivch.Key, 0), FilterIDs: []string{ - "*destinations:~*req.Destination:1001;1002;1003", + "*destinations:~*req.Destination:1001|1002|1003", "*string:~*req.Account:1003", "*rsr:~*req.filterhdr1:.+", }, diff --git a/migrator/derived_chargers_test.go b/migrator/derived_chargers_test.go index 2cd21be8c..931bae270 100644 --- a/migrator/derived_chargers_test.go +++ b/migrator/derived_chargers_test.go @@ -222,7 +222,7 @@ func TestDerivedChargers2Charger(t *testing.T) { FilterIDs: []string{ "*string:~*req.Category:*voice1", "*string:~*req.Account:1001", - "*rsr:~*req.Header4:b;c", + "*rsr:~*req.Header4:b|c", }, ActivationInterval: nil, RunID: "runID", diff --git a/migrator/filters.go b/migrator/filters.go index 9358a5d47..e59d2bba7 100644 --- a/migrator/filters.go +++ b/migrator/filters.go @@ -906,7 +906,7 @@ func migrateInlineFilterV4(v4fltIDs []string) (fltrIDs []string, err error) { } fltrIDs = append(fltrIDs, fltr+el+utils.InInFieldSep+ - strings.Join(vals, utils.InfieldSep)) + strings.Join(vals, utils.PipeSep)) } } return diff --git a/migrator/storage_redis.go b/migrator/storage_redis.go index 162044c14..0ee3eb0d7 100644 --- a/migrator/storage_redis.go +++ b/migrator/storage_redis.go @@ -677,7 +677,7 @@ func (v1rs *redisMigrator) remV1Alias(key string) (err error) { } return - return v1rs.rds.Cmd(nil, "DEL", key) + // return v1rs.rds.Cmd(nil, "DEL", key) } // User methods diff --git a/migrator/thresholds_test.go b/migrator/thresholds_test.go index 77336903b..0c64e5d8c 100644 --- a/migrator/thresholds_test.go +++ b/migrator/thresholds_test.go @@ -27,18 +27,33 @@ import ( "github.com/cgrates/cgrates/utils" ) -func Testv2ActionTriggerAsThreshold(t *testing.T) { +func TestV2ActionTriggerAsThreshold(t *testing.T) { var filters []*engine.FilterRule v2ATR := &v2ActionTrigger{ - ID: "test2", // original csv tag - UniqueID: "testUUID", // individual id - ThresholdType: "*min_event_counter", //*min_event_counter, *max_event_counter, *min_balance_counter, *max_balance_counter, *min_balance, *max_balance, *balance_expired - ThresholdValue: 5.32, - Recurrent: false, // reset excuted flag each run - MinSleep: 5 * time.Second, // Minimum duration between two executions in case of recurrent triggers - ExpirationDate: time.Now(), - ActivationDate: time.Now(), - Balance: new(engine.BalanceFilter), + ID: "test2", // original csv tag + UniqueID: "testUUID", // individual id + ThresholdType: "*min_event_counter", //*min_event_counter, *max_event_counter, *min_balance_counter, *max_balance_counter, *min_balance, *max_balance, *balance_expired + ThresholdValue: 5.32, + Recurrent: false, // reset excuted flag each run + MinSleep: 5 * time.Second, // Minimum duration between two executions in case of recurrent triggers + ExpirationDate: time.Now(), + ActivationDate: time.Now(), + Balance: &engine.BalanceFilter{ + ID: utils.StringPointer(utils.MetaMonetary), + DestinationIDs: &utils.StringMap{ + "1002": true, + }, + RatingSubject: utils.StringPointer("1001"), + Categories: &utils.StringMap{ + utils.MetaVoice: true, + }, + SharedGroups: &utils.StringMap{ + "SHG1": true, + }, + TimingIDs: &utils.StringMap{ + "TIMINGID": true, + }, + }, Weight: 0, ActionsID: "Action1", MinQueuedItems: 10, // Trigger actions only if this number is hit (stats only) @@ -63,6 +78,7 @@ func Testv2ActionTriggerAsThreshold(t *testing.T) { thp := &engine.ThresholdProfile{ ID: v2ATR.ID, + FilterIDs: make([]string, 0), Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, Blocker: false, Weight: v2ATR.Weight, @@ -76,10 +92,10 @@ func Testv2ActionTriggerAsThreshold(t *testing.T) { newthp, newth, fltr, err := v2ATR.AsThreshold() if err != nil { - t.Errorf("err") + t.Error(err) } if !reflect.DeepEqual(thp, newthp) { - t.Errorf("Expecting: %+v, received: %+v", thp, newthp) + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(thp), utils.ToJSON(newthp)) } if !reflect.DeepEqual(th, newth) { t.Errorf("Expecting: %+v, received: %+v", th, newth) diff --git a/rates/rates_test.go b/rates/rates_test.go index 1ba5ae1b2..de2cc2845 100644 --- a/rates/rates_test.go +++ b/rates/rates_test.go @@ -82,7 +82,7 @@ func TestMatchingRateProfileForEventActivationInterval(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", Weight: 10, - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2020, 7, 21, 0, 0, 0, 0, time.UTC), ExpiryTime: time.Date(2020, 7, 21, 10, 0, 0, 0, time.UTC), @@ -311,7 +311,7 @@ func TestMatchingRateProfileEvent(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", Weight: 7, - FilterIDs: []string{"*string:~*req.Account:1001;1002;1003", "*prefix:~*req.Destination:10"}, + FilterIDs: []string{"*string:~*req.Account:1001|1002|1003", "*prefix:~*req.Destination:10"}, ActivationInterval: &utils.ActivationInterval{ ExpiryTime: t1, }, @@ -400,7 +400,7 @@ func TestMatchingRateProfileEvent(t *testing.T) { }); err != utils.ErrNotFound { t.Error(err) } - rpp.FilterIDs = []string{"*string:~*req.Account:1001;1002;1003", "*gt:~*req.Cost{*:10"} + rpp.FilterIDs = []string{"*string:~*req.Account:1001|1002|1003", "*gt:~*req.Cost{*:10"} if _, err := rate.matchingRateProfileForEvent("cgrates.org", []string{}, &utils.ArgsCostForEvent{ @@ -416,7 +416,7 @@ func TestMatchingRateProfileEvent(t *testing.T) { }); err.Error() != "invalid converter terminator in rule: <~*req.Cost{*>" { t.Error(err) } - rpp.FilterIDs = []string{"*string:~*req.Account:1001;1002;1003"} + rpp.FilterIDs = []string{"*string:~*req.Account:1001|1002|1003"} rate.dm = nil if _, err := rate.matchingRateProfileForEvent("cgrates.org", []string{"rp3"}, diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index 14ee8d98a..489569877 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -2108,7 +2108,7 @@ func TestSessionSfilterSessions(t *testing.T) { expSess := []*ExternalSession{ eses1, } - fltrs := &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s;%s", utils.MetaVoice, utils.MetaData)}} + fltrs := &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s|%s", utils.MetaVoice, utils.MetaData)}} if sess := sS.filterSessions(fltrs, true); len(sess) != 0 { t.Errorf("Expected no session, received: %s", utils.ToJSON(sess)) } @@ -2163,7 +2163,7 @@ func TestSessionSfilterSessions(t *testing.T) { } else if !reflect.DeepEqual(expSess[0], eses1) && !reflect.DeepEqual(expSess[0], eses2) { t.Errorf("Expected %s or %s, received: %s", utils.ToJSON(eses1), utils.ToJSON(eses2), utils.ToJSON(sess[0])) } - fltrs = &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s;%s", utils.MetaVoice, utils.MetaSMS)}, Limit: utils.IntPointer(1)} + fltrs = &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s|%s", utils.MetaVoice, utils.MetaSMS)}, Limit: utils.IntPointer(1)} if sess := sS.filterSessions(fltrs, false); len(sess) != 1 { t.Errorf("Expected one session, received: %s", utils.ToJSON(sess)) } else if !reflect.DeepEqual(expSess[0], eses1) && !reflect.DeepEqual(expSess[0], eses2) { @@ -2222,7 +2222,7 @@ func TestSessionSfilterSessionsCount(t *testing.T) { sEv[utils.ToR] = utils.MetaData sr2[utils.CGRID] = GetSetCGRID(sEv) sS.registerSession(session, false) - fltrs := &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s;%s", utils.MetaVoice, utils.MetaData)}} + fltrs := &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s|%s", utils.MetaVoice, utils.MetaData)}} if noSess := sS.filterSessionsCount(fltrs, false); noSess != 2 { t.Errorf("Expected %v , received: %s", 2, utils.ToJSON(noSess)) @@ -2263,7 +2263,7 @@ func TestSessionSfilterSessionsCount(t *testing.T) { } sS = NewSessionS(sSCfg, nil, nil) sS.registerSession(session, true) - fltrs = &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s;%s", utils.MetaVoice, utils.MetaData)}} + fltrs = &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s|%s", utils.MetaVoice, utils.MetaData)}} if noSess := sS.filterSessionsCount(fltrs, true); noSess != 2 { t.Errorf("Expected %v , received: %s", 2, utils.ToJSON(noSess)) }