diff --git a/apis/attributes_it_test.go b/apis/attributes_it_test.go index 7234a0a5c..f77c44b56 100644 --- a/apis/attributes_it_test.go +++ b/apis/attributes_it_test.go @@ -178,7 +178,11 @@ func testAttributeSetAttributeProfile(t *testing.T) { Value: "cgrates.itsyscom", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } var reply string @@ -205,7 +209,11 @@ func testAttributeSetAttributeProfile(t *testing.T) { Value: "cgrates.itsyscom", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } var result engine.APIAttributeProfile if err := attrSRPC.Call(context.Background(), utils.AdminSv1GetAttributeProfile, @@ -255,7 +263,11 @@ func testAttributeGetAttributes(t *testing.T) { Value: "cgrates.itsyscom", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } if err := attrSRPC.Call(context.Background(), utils.AdminSv1GetAttributeProfiles, @@ -363,7 +375,11 @@ func testAttributeGetAttributes2(t *testing.T) { Value: "cgrates.itsyscom", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, { Tenant: utils.CGRateSorg, @@ -467,7 +483,11 @@ func testAttributeGetAttributesAfterRemove(t *testing.T) { Value: "cgrates.itsyscom", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } if err := attrSRPC.Call(context.Background(), utils.AdminSv1GetAttributeProfiles, @@ -542,7 +562,11 @@ func testAttributeSGetAttributesWithPrefix(t *testing.T) { Value: "cgrates.itsyscom", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } if err := attrSRPC.Call(context.Background(), utils.AdminSv1GetAttributeProfiles, @@ -615,7 +639,11 @@ func testAttributeSGetAttributeForEventAnyContext(t *testing.T) { Value: "1001", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } var result string @@ -650,7 +678,11 @@ func testAttributeSGetAttributeForEventAnyContext(t *testing.T) { Value: "1001", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if !reflect.DeepEqual(expAttrFromEv, attrReply) { t.Errorf("Expecting: %s, received: %s", utils.ToJSON(expAttrFromEv), utils.ToJSON(attrReply)) @@ -686,7 +718,11 @@ func testAttributeSGetAttributeForEventSameAnyContext(t *testing.T) { Value: "1001", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if !reflect.DeepEqual(expAttrFromEv, attrReply) { t.Errorf("Expecting: %s, received: %s", utils.ToJSON(expAttrFromEv), utils.ToJSON(attrReply)) @@ -744,7 +780,11 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { FilterIDs: []string{}, }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if *encoding == utils.MetaGOB { eAttrPrf.Attributes[0].FilterIDs = nil @@ -770,7 +810,11 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { FilterIDs: []string{}, }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } if err := attrSRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, @@ -860,7 +904,11 @@ func testAttributeProcessEventWithSearchAndReplace(t *testing.T) { }, }, Blocker: true, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } var result string @@ -918,7 +966,11 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { Value: "Value1", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } attrPrf2 := &engine.APIAttributeProfileWithAPIOpts{ @@ -932,7 +984,11 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { Value: "Value2", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } attrPrf3 := &engine.APIAttributeProfileWithAPIOpts{ @@ -946,7 +1002,11 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { Value: "Value3", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } // Add attribute in DM @@ -1022,7 +1082,11 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { Value: "Value1", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } attrPrf2 := &engine.APIAttributeProfileWithAPIOpts{ @@ -1036,7 +1100,11 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { Value: "Value2", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } attrPrf3 := &engine.APIAttributeProfileWithAPIOpts{ @@ -1050,7 +1118,11 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { Value: "Value3", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } // Add attributeProfiles diff --git a/apis/cache_it_test.go b/apis/cache_it_test.go index 50841593b..e14974d6a 100644 --- a/apis/cache_it_test.go +++ b/apis/cache_it_test.go @@ -449,7 +449,11 @@ func testCacheSSetMoreAttributeProfiles(t *testing.T) { Value: "Value1", }, }, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } attrPrf2 := &engine.APIAttributeProfileWithAPIOpts{ @@ -463,7 +467,11 @@ func testCacheSSetMoreAttributeProfiles(t *testing.T) { Value: "Value2", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } attrPrf3 := &engine.APIAttributeProfileWithAPIOpts{ @@ -477,7 +485,11 @@ func testCacheSSetMoreAttributeProfiles(t *testing.T) { Value: "Value3", }, }, - Weights: ";30", + Weights: utils.DynamicWeights{ + { + Weight: 30, + }, + }, }, } // Add attributeProfiles diff --git a/apis/filters_test.go b/apis/filters_test.go index 8b2575f48..1eef4e8f6 100644 --- a/apis/filters_test.go +++ b/apis/filters_test.go @@ -811,7 +811,11 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { APIAttributeProfile: &engine.APIAttributeProfile{ FilterIDs: []string{"FLTR_ID"}, ID: "ATTR_ID", - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Attributes: []*engine.ExternalAttribute{ { Path: "*req.Account", @@ -979,7 +983,11 @@ func TestFiltersSetFilterClearCache(t *testing.T) { APIAttributeProfile: &engine.APIAttributeProfile{ FilterIDs: []string{"FLTR_ID"}, ID: "ATTR_ID", - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Attributes: []*engine.ExternalAttribute{ { Path: "*req.Account", diff --git a/apis/loaders_it_test.go b/apis/loaders_it_test.go index 86f5579ac..96631170a 100644 --- a/apis/loaders_it_test.go +++ b/apis/loaders_it_test.go @@ -614,7 +614,11 @@ func testLoadersGetAttributeProfiles(t *testing.T) { }, }, Blocker: true, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, { Tenant: "cgrates.org", @@ -634,7 +638,11 @@ func testLoadersGetAttributeProfiles(t *testing.T) { }, }, Blocker: true, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } var attrs []*engine.APIAttributeProfile diff --git a/cmd/cgr-loader/cgr-loader_remove_it_test.go b/cmd/cgr-loader/cgr-loader_remove_it_test.go index 105f0e190..f35975549 100644 --- a/cmd/cgr-loader/cgr-loader_remove_it_test.go +++ b/cmd/cgr-loader/cgr-loader_remove_it_test.go @@ -401,7 +401,11 @@ func testCgrLdrGetAttributeProfileAfterLoad(t *testing.T) { Tenant: utils.CGRateSorg, ID: "ATTR_ACNT_1001", FilterIDs: []string{"*string:~*opts.*context:*sessions", "FLTR_ACCOUNT_1001"}, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Attributes: []*engine.ExternalAttribute{ { FilterIDs: []string{}, diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index 35c93f493..3e473787d 100644 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -233,7 +233,11 @@ func testDspAttrGetAttrFailover(t *testing.T) { Type: utils.MetaConstant, Value: "CGRateS.org", }}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if *encoding == utils.MetaGOB { eAttrPrf.Attributes[0].FilterIDs = nil // empty slice are nil in gob @@ -412,7 +416,11 @@ func testDspAttrTestAuthKey2(t *testing.T) { Type: utils.MetaConstant, Value: "CGRateS.org", }}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if *encoding == utils.MetaGOB { eAttrPrf.Attributes[0].FilterIDs = nil // empty slice are nil in gob @@ -499,7 +507,11 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { Type: utils.MetaConstant, Value: "CGRateS.org", }}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if *encoding == utils.MetaGOB { eAttrPrf.Attributes[0].FilterIDs = nil // empty slice are nil in gob diff --git a/engine/libattributes.go b/engine/libattributes.go index 9fb417bc8..51a969e55 100644 --- a/engine/libattributes.go +++ b/engine/libattributes.go @@ -100,7 +100,7 @@ type APIAttributeProfile struct { FilterIDs []string Attributes []*ExternalAttribute Blocker bool // blocker flag to stop processing on multiple runs - Weights string + Weights utils.DynamicWeights } type APIAttributeProfileWithAPIOpts struct { @@ -115,7 +115,7 @@ func NewAPIAttributeProfile(attr *AttributeProfile) (ext *APIAttributeProfile) { FilterIDs: attr.FilterIDs, Attributes: make([]*ExternalAttribute, len(attr.Attributes)), Blocker: attr.Blocker, - Weights: attr.Weights.String(utils.InfieldSep, utils.ANDSep), + Weights: attr.Weights, } for i, at := range attr.Attributes { ext.Attributes[i] = &ExternalAttribute{ @@ -134,11 +134,6 @@ func (ext *APIAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, er if len(ext.Attributes) == 0 { return nil, utils.NewErrMandatoryIeMissing("Attributes") } - if ext.Weights != utils.EmptyString { - if attr.Weights, err = utils.NewDynamicWeightsFromString(ext.Weights, utils.InfieldSep, utils.ANDSep); err != nil { - return - } - } attr.Attributes = make([]*Attribute, len(ext.Attributes)) for i, extAttr := range ext.Attributes { if extAttr.Path == utils.EmptyString { @@ -158,6 +153,7 @@ func (ext *APIAttributeProfile) AsAttributeProfile() (attr *AttributeProfile, er attr.Tenant = ext.Tenant attr.ID = ext.ID attr.FilterIDs = ext.FilterIDs + attr.Weights = ext.Weights return } diff --git a/engine/libattributes_test.go b/engine/libattributes_test.go index 4e150d8f2..d528af2fc 100644 --- a/engine/libattributes_test.go +++ b/engine/libattributes_test.go @@ -38,7 +38,11 @@ func TestConvertExternalToProfile(t *testing.T) { Value: "1001", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } expAttr := &AttributeProfile{ @@ -73,7 +77,11 @@ func TestConvertExternalToProfileMissing(t *testing.T) { ID: "ATTR_ID", FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE", "*ai:~*req.AnswerTime:2014-07-14T14:35:00Z|2014-07-14T14:36:00Z", "*string:~*opts.*context:*sessions|*cdrs"}, Attributes: []*ExternalAttribute{}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } _, err := external.AsAttributeProfile() @@ -93,7 +101,11 @@ func TestConvertExternalToProfileMissing2(t *testing.T) { Path: utils.MetaReq + utils.NestingSep + "Account", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } _, err := external.AsAttributeProfile() diff --git a/engine/z_attributes_test.go b/engine/z_attributes_test.go index 3939c35be..3e042f193 100644 --- a/engine/z_attributes_test.go +++ b/engine/z_attributes_test.go @@ -186,10 +186,14 @@ func TestAttributesV1GetAttributeForEventProfileIgnoreOpts(t *testing.T) { } rply := &APIAttributeProfile{} expected := &APIAttributeProfile{ - Tenant: "cgrates.org", - ID: "AC1", - FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"}, - Weights: ";20", + Tenant: "cgrates.org", + ID: "AC1", + FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"}, + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, Attributes: []*ExternalAttribute{}, } @@ -219,7 +223,11 @@ func TestAttributesV1GetAttributeForEventProfileIgnoreOpts(t *testing.T) { ID: "AC1", FilterIDs: []string{"*string:~*req.Attribute:testAttrValue"}, Attributes: []*ExternalAttribute{}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } // with ignore filters on true and with bad filter err = aA.V1GetAttributeForEvent(context.Background(), ev2, rply2) @@ -4414,7 +4422,11 @@ func TestAttributesV1GetAttributeForEvent(t *testing.T) { Value: ".co.uk", }, }, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } err = alS.V1GetAttributeForEvent(context.Background(), ev, rply) diff --git a/general_tests/attributes_filters_index_it_test.go b/general_tests/attributes_filters_index_it_test.go index 90a011551..e83aa7ef5 100644 --- a/general_tests/attributes_filters_index_it_test.go +++ b/general_tests/attributes_filters_index_it_test.go @@ -148,7 +148,11 @@ func testAttributeSetProfile(t *testing.T) { Path: "*req.FL1", Value: "Al1", }}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, }, } if err := attrFltrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { diff --git a/general_tests/attributes_it_test.go b/general_tests/attributes_it_test.go index a0e02bf84..2a4213b31 100644 --- a/general_tests/attributes_it_test.go +++ b/general_tests/attributes_it_test.go @@ -196,7 +196,11 @@ func testAttributeSProcessEventWithAccount(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { @@ -263,7 +267,11 @@ func testAttributeSProcessEventWithAccountFull(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { @@ -370,7 +378,11 @@ func testAttributeSProcessEventWithStat(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } var result string @@ -438,7 +450,11 @@ func testAttributeSProcessEventWithStatFull(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } var result string @@ -573,7 +589,11 @@ func testAttributeSProcessEventWithResource(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { @@ -645,7 +665,11 @@ func testAttributeSProcessEventWithResourceFull(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { @@ -725,7 +749,11 @@ func testAttributeSProcessEventWithLibPhoneNumber(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { @@ -809,7 +837,11 @@ func testAttributeSProcessEventWithLibPhoneNumberComposed(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { @@ -883,7 +915,11 @@ func testAttributeSProcessEventWithLibPhoneNumberFull(t *testing.T) { }, }, Blocker: false, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } if err := attrRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, alsPrf, &result); err != nil { diff --git a/general_tests/filtered_replication_it_test.go b/general_tests/filtered_replication_it_test.go index 04662e9f9..f27960d2c 100644 --- a/general_tests/filtered_replication_it_test.go +++ b/general_tests/filtered_replication_it_test.go @@ -169,7 +169,11 @@ func testFltrRplAttributeProfile(t *testing.T) { Value: utils.InfieldSep, }, }, - Weights: ";10", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, }, } var result string @@ -218,7 +222,11 @@ func testFltrRplAttributeProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(attrPrf.APIAttributeProfile), utils.ToJSON(replyPrfl)) } replyPrfl = nil - attrPrf.Weights = ";15" + attrPrf.Weights = utils.DynamicWeights{ + { + Weight: 10, + }, + } if err := fltrRplInternalRPC.Call(context.Background(), utils.AdminSv1SetAttributeProfile, attrPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { diff --git a/general_tests/loaders_internal_indexes_it_test.go b/general_tests/loaders_internal_indexes_it_test.go index 90163fc1c..c6ef63a5d 100644 --- a/general_tests/loaders_internal_indexes_it_test.go +++ b/general_tests/loaders_internal_indexes_it_test.go @@ -137,7 +137,11 @@ func testLoadersIDBIdxCheckAttributes(t *testing.T) { Type: utils.MetaConstant, Value: "CGRateS.org", }}, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } var reply *engine.APIAttributeProfile diff --git a/loaders/loader_it_test.go b/loaders/loader_it_test.go index c451945f9..6b9298409 100644 --- a/loaders/loader_it_test.go +++ b/loaders/loader_it_test.go @@ -243,7 +243,11 @@ func testLoaderCheckAttributes(t *testing.T) { Value: "Sub2", }}, Blocker: true, - Weights: ";20", + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, } if *encoding == utils.MetaGOB { // gob threats empty slices as nil values eAttrPrf.Attributes[1].FilterIDs = nil