diff --git a/actions/actions.go b/actions/actions.go index ba656eaa0..23b487485 100644 --- a/actions/actions.go +++ b/actions/actions.go @@ -184,6 +184,9 @@ func (aS *ActionS) matchingActionProfilesForEvent(ctx *context.Context, tnt stri continue } } + if err = aPf.GetWeightFromDynamics(ctx, aS.fltrS, tnt, evNm); err != nil { + return + } aPfs = append(aPfs, aPf) } if len(aPfs) == 0 { diff --git a/apis/actions_test.go b/apis/actions_test.go index 340dd4ba1..7da7c97b2 100644 --- a/apis/actions_test.go +++ b/apis/actions_test.go @@ -53,9 +53,13 @@ func TestActionsSetGetRemActionProfile(t *testing.T) { actPrf := &engine.ActionProfileWithAPIOpts{ ActionProfile: &engine.ActionProfile{ - Tenant: "cgrates.org", - ID: "actID", - Weight: 10, + Tenant: "cgrates.org", + ID: "actID", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Actions: make([]*engine.APAction, 1), }, } @@ -227,9 +231,13 @@ func TestActionsRemoveActionProfileCheckErrors(t *testing.T) { actPrf := &engine.ActionProfileWithAPIOpts{ ActionProfile: &engine.ActionProfile{ - ID: "TestActionsRemoveActionProfileCheckErrors", - Tenant: "cgrates.org", - Weight: 10, + ID: "TestActionsRemoveActionProfileCheckErrors", + Tenant: "cgrates.org", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Actions: make([]*engine.APAction, 1), }, } diff --git a/apis/filter_indexes_it_test.go b/apis/filter_indexes_it_test.go index 7a466a904..aaf2844a6 100644 --- a/apis/filter_indexes_it_test.go +++ b/apis/filter_indexes_it_test.go @@ -1305,9 +1305,13 @@ func testV1FIdxSetActionProfileWithFltr(t *testing.T) { Tenant: "cgrates.org", ID: "REM_ACC", FilterIDs: []string{"fltr_for_attr", "*string:~*req.Account:1001"}, - Weight: 0, - Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, - Schedule: utils.MetaASAP, + Weights: utils.DynamicWeights{ + { + Weight: 0, + }, + }, + Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, + Schedule: utils.MetaASAP, Actions: []*engine.APAction{ { ID: "REM_BAL", @@ -1412,7 +1416,11 @@ func testV1FIdxSetActionProfileMoreFltrsMoreIndexing(t *testing.T) { ID: "REM_ACC", FilterIDs: []string{"fltr_for_attr", "*string:~*req.Account:1001", "fltr_for_attr3", "fltr_for_attr2"}, - Weight: 0, + Weights: utils.DynamicWeights{ + { + Weight: 0, + }, + }, Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, Schedule: utils.MetaASAP, Actions: []*engine.APAction{ @@ -1526,7 +1534,11 @@ func testV1FIdxActionMoreProfileForFilters(t *testing.T) { ID: "TOPUP_ACC", FilterIDs: []string{"fltr_for_attr3", "fltr_for_attr2", "*string:~*req.Account:1001"}, - Weight: 0, + Weights: utils.DynamicWeights{ + { + Weight: 0, + }, + }, Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, Schedule: utils.MetaASAP, Actions: []*engine.APAction{ @@ -1549,7 +1561,11 @@ func testV1FIdxActionMoreProfileForFilters(t *testing.T) { ID: "SET_BAL", FilterIDs: []string{"fltr_for_attr", "*string:~*req.Account:1001"}, - Weight: 0, + Weights: utils.DynamicWeights{ + { + Weight: 0, + }, + }, Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, Schedule: utils.MetaASAP, Actions: []*engine.APAction{ diff --git a/apis/loaders_it_test.go b/apis/loaders_it_test.go index 7f1a2034e..758377d02 100644 --- a/apis/loaders_it_test.go +++ b/apis/loaders_it_test.go @@ -477,9 +477,13 @@ func testLoadersGetAccounts(t *testing.T) { func testLoadersGetActionProfiles(t *testing.T) { expActs := []*engine.ActionProfile{ { - Tenant: "cgrates.org", - ID: "ONE_TIME_ACT", - Weight: 10, + Tenant: "cgrates.org", + ID: "ONE_TIME_ACT", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Schedule: utils.MetaASAP, Targets: map[string]utils.StringSet{ "*accounts": { diff --git a/apis/preload_it_test.go b/apis/preload_it_test.go index f2569eb8f..3dba203a0 100644 --- a/apis/preload_it_test.go +++ b/apis/preload_it_test.go @@ -290,9 +290,13 @@ func testPreloadITVerifyAccounts(t *testing.T) { func testPreloadITVerifyActionProfiles(t *testing.T) { var reply *engine.ActionProfile expected := &engine.ActionProfile{ - Tenant: "cgrates.org", - ID: "ONE_TIME_ACT", - Weight: 10, + Tenant: "cgrates.org", + ID: "ONE_TIME_ACT", + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Schedule: utils.MetaASAP, Targets: map[string]utils.StringSet{ "*accounts": { diff --git a/cmd/cgr-loader/cgr-loader_remove_it_test.go b/cmd/cgr-loader/cgr-loader_remove_it_test.go index 1e6e57481..ee846af07 100644 --- a/cmd/cgr-loader/cgr-loader_remove_it_test.go +++ b/cmd/cgr-loader/cgr-loader_remove_it_test.go @@ -302,8 +302,12 @@ func testCgrLdrGetActionProfileAfterLoad(t *testing.T) { Tenant: "cgrates.org", ID: "ONE_TIME_ACT", FilterIDs: []string{}, - Weight: 10, - Schedule: utils.MetaASAP, + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, + Schedule: utils.MetaASAP, Targets: map[string]utils.StringSet{ utils.MetaAccounts: { "1001": {}, diff --git a/config/config_defaults.go b/config/config_defaults.go index 05c851838..e4a650b9f 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -1396,7 +1396,7 @@ const CGRATES_CFG_JSON = ` {"tag": "Tenant", "path": "Tenant", "type": "*variable", "value": "~*req.0", "mandatory": true}, {"tag": "ID", "path": "ID", "type": "*variable", "value": "~*req.1", "mandatory": true}, {"tag": "FilterIDs", "path": "FilterIDs", "type": "*variable", "value": "~*req.2"}, - {"tag": "Weight", "path": "Weight", "type": "*variable", "value": "~*req.3"}, + {"tag": "Weights", "path": "Weights", "type": "*variable", "value": "~*req.3"}, {"tag": "Schedule", "path": "Schedule", "type": "*variable", "value": "~*req.4"}, // {"tag": "TargetType", "path": "TargetType", "type": "*variable", "value": "~*req.5"}, {"tag": "TargetIDs", "path": "Targets[<~*req.5>]", "type": "*variable", "value": "~*req.6"}, diff --git a/data/storage/docker_mysql/scripts/create_tariffplan_tables.sql b/data/storage/docker_mysql/scripts/create_tariffplan_tables.sql index 13bd3dcce..ac9aa3889 100644 --- a/data/storage/docker_mysql/scripts/create_tariffplan_tables.sql +++ b/data/storage/docker_mysql/scripts/create_tariffplan_tables.sql @@ -43,7 +43,7 @@ CREATE TABLE tp_stats ( `metric_filter_ids` varchar(64) NOT NULL, `stored` BOOLEAN NOT NULL, `blocker` BOOLEAN NOT NULL, - `weight` decimal(8,2) NOT NULL, + `weights` varchar(64) NOT NULL, `threshold_ids` varchar(64) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`pk`), @@ -67,7 +67,7 @@ CREATE TABLE tp_thresholds ( `min_hits` int(11) NOT NULL, `min_sleep` varchar(16) NOT NULL, `blocker` BOOLEAN NOT NULL, - `weight` decimal(8,2) NOT NULL, + `weights` varchar(64) NOT NULL, `action_profile_ids` varchar(64) NOT NULL, `async` BOOLEAN NOT NULL, `created_at` TIMESTAMP, @@ -146,7 +146,7 @@ CREATE TABLE tp_attributes ( `type` varchar(64) NOT NULL, `value` varchar(64) NOT NULL, `blocker` BOOLEAN NOT NULL, - `weight` decimal(8,2) NOT NULL, + `weights` varchar(64) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`pk`), KEY `tpid` (`tpid`), diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 9a0a6c115..279141080 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -278,7 +278,7 @@ CREATE TABLE tp_action_profiles ( `id` varchar(64) NOT NULL, `filter_ids` varchar(64) NOT NULL, `activation_interval` varchar(64) NOT NULL, - `weight` decimal(8,2) NOT NULL, + `weights` varchar(64) NOT NULL, `schedule` varchar(64) NOT NULL, `target_type` varchar(64) NOT NULL, `target_ids` varchar(64) NOT NULL, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 345f8bda6..50c16d8f7 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -266,7 +266,7 @@ CREATE TABLE tp_action_profiles ( "id" varchar(64) NOT NULL, "filter_ids" varchar(64) NOT NULL, "activation_interval" varchar(64) NOT NULL, - "weight" decimal(8,2) NOT NULL, + "weights" varchar(64) NOT NULL, "schedule" varchar(64) NOT NULL, "target_type" varchar(64) NOT NULL, "target_ids" varchar(64) NOT NULL, diff --git a/engine/actionprofile.go b/engine/actionprofile.go index b5964d7aa..f71855eb1 100644 --- a/engine/actionprofile.go +++ b/engine/actionprofile.go @@ -24,6 +24,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -33,11 +34,12 @@ type ActionProfile struct { Tenant string ID string FilterIDs []string - Weight float64 + Weights utils.DynamicWeights Schedule string Targets map[string]utils.StringSet Actions []*APAction + weight float64 } func (aP *ActionProfile) TenantID() string { @@ -49,7 +51,15 @@ type ActionProfiles []*ActionProfile // Sort is part of sort interface, sort based on Weight func (aps ActionProfiles) Sort() { - sort.Slice(aps, func(i, j int) bool { return aps[i].Weight > aps[j].Weight }) + sort.Slice(aps, func(i, j int) bool { return aps[i].weight > aps[j].weight }) +} + +func (ap *ActionProfile) GetWeightFromDynamics(ctx *context.Context, + fltrS *FilterS, tnt string, ev utils.DataProvider) (err error) { + if ap.weight, err = WeightFromDynamics(ctx, ap.Weights, fltrS, tnt, ev); err != nil { + return + } + return } // APAction defines action related information used within a ActionProfile @@ -111,7 +121,7 @@ func (aP *ActionProfile) Set(path []string, val interface{}, newBranch bool, _ s aP.FilterIDs = append(aP.FilterIDs, valA...) case utils.Weight: if val != utils.EmptyString { - aP.Weight, err = utils.IfaceAsFloat64(val) + aP.Weights, err = utils.NewDynamicWeightsFromString(utils.IfaceAsString(val), utils.InfieldSep, utils.ANDSep) } } return @@ -229,9 +239,7 @@ func (ap *ActionProfile) Merge(v2 interface{}) { equal = false } - if vi.Weight != 0 { - ap.Weight = vi.Weight - } + ap.Weights = append(ap.Weights, vi.Weights...) if len(vi.Schedule) != 0 { ap.Schedule = vi.Schedule } @@ -308,7 +316,7 @@ func (ap *ActionProfile) FieldAsInterface(fldPath []string) (_ interface{}, err case utils.FilterIDs: return ap.FilterIDs, nil case utils.Weight: - return ap.Weight, nil + return ap.Weights, nil case utils.Actions: return ap.Actions, nil case utils.Schedule: diff --git a/engine/actionprofile_test.go b/engine/actionprofile_test.go index 55fa7333a..4008d5049 100644 --- a/engine/actionprofile_test.go +++ b/engine/actionprofile_test.go @@ -31,35 +31,59 @@ func TestActionProfileSort(t *testing.T) { { Tenant: "test_tenantA", ID: "test_idA", - Weight: 1, + Weights: utils.DynamicWeights{ + { + Weight: 1, + }, + }, }, { Tenant: "test_tenantB", ID: "test_idB", - Weight: 2, + Weights: utils.DynamicWeights{ + { + Weight: 2, + }, + }, }, { Tenant: "test_tenantC", ID: "test_idC", - Weight: 3, + Weights: utils.DynamicWeights{ + { + Weight: 3, + }, + }, }, } expStruct := &ActionProfiles{ { Tenant: "test_tenantC", ID: "test_idC", - Weight: 3, + Weights: utils.DynamicWeights{ + { + Weight: 3, + }, + }, }, { Tenant: "test_tenantB", ID: "test_idB", - Weight: 2, + Weights: utils.DynamicWeights{ + { + Weight: 2, + }, + }, }, { Tenant: "test_tenantA", ID: "test_idA", - Weight: 1, + Weights: utils.DynamicWeights{ + { + Weight: 1, + }, + }, }, } testStruct.Sort() @@ -137,7 +161,11 @@ func TestActionProfileSet(t *testing.T) { ID: "ID", FilterIDs: []string{"fltr1", "*string:~*req.Account:1001"}, Schedule: utils.MetaNow, - Weight: 10, + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Targets: map[string]utils.StringSet{ utils.MetaAccounts: utils.NewStringSet([]string{"1001", "1002"}), utils.MetaThresholds: utils.NewStringSet([]string{"TH1", "TH2"}), @@ -253,7 +281,11 @@ func TestActionProfileFieldAsInterface(t *testing.T) { ID: "ID", FilterIDs: []string{"fltr1", "*string:~*req.Account:1001"}, Schedule: utils.MetaNow, - Weight: 10, + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, Targets: map[string]utils.StringSet{ utils.MetaAccounts: utils.NewStringSet([]string{"1001", "1002"}), utils.MetaThresholds: utils.NewStringSet([]string{"TH1", "TH2"}), @@ -307,7 +339,7 @@ func TestActionProfileFieldAsInterface(t *testing.T) { } if val, err := ap.FieldAsInterface([]string{utils.Weight}); err != nil { t.Fatal(err) - } else if exp := ap.Weight; !reflect.DeepEqual(exp, val) { + } else if exp := ap.Weights; !reflect.DeepEqual(exp, val) { t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(val)) } if val, err := ap.FieldAsInterface([]string{utils.Actions}); err != nil { @@ -501,19 +533,27 @@ func TestActionProfileMerge(t *testing.T) { Tenant: "cgrates.org", ID: "ID", FilterIDs: []string{"fltr1"}, - Weight: 65, - Schedule: "* * * * *", - Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, - Actions: []*APAction{{}}, + Weights: utils.DynamicWeights{ + { + Weight: 65, + }, + }, + Schedule: "* * * * *", + Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, + Actions: []*APAction{{}}, } if acc.Merge(&ActionProfile{ Tenant: "cgrates.org", ID: "ID", FilterIDs: []string{"fltr1"}, - Weight: 65, - Schedule: "* * * * *", - Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, - Actions: []*APAction{{}}, + Weights: utils.DynamicWeights{ + { + Weight: 65, + }, + }, + Schedule: "* * * * *", + Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, + Actions: []*APAction{{}}, }); !reflect.DeepEqual(exp, acc) { t.Errorf("Expected %v \n but received \n %v", utils.ToJSON(exp), utils.ToJSON(acc)) } diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index 477727a2c..582bed064 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -574,7 +574,7 @@ func TestLoadActionProfiles(t *testing.T) { TPid: testTPID, Tenant: "cgrates.org", ID: "ONE_TIME_ACT", - Weight: 10, + Weights: ";10", Schedule: utils.MetaASAP, Targets: []*utils.TPActionTarget{ { diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 900eaa904..c16d4e361 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2025,8 +2025,8 @@ func (apm ActionProfileMdls) AsTPActionProfile() (result []*utils.TPActionProfil } filterIDsMap[tenID].AddSlice(strings.Split(tp.FilterIDs, utils.InfieldSep)) } - if tp.Weight != 0 { - aPrf.Weight = tp.Weight + if tp.Weights != "" { + aPrf.Weights = tp.Weights } if tp.Schedule != utils.EmptyString { aPrf.Schedule = tp.Schedule @@ -2092,7 +2092,7 @@ func APItoModelTPActionProfile(tPrf *utils.TPActionProfile) (mdls ActionProfileM if i == 0 { mdl.FilterIDs = strings.Join(tPrf.FilterIDs, utils.InfieldSep) - mdl.Weight = tPrf.Weight + mdl.Weights = tPrf.Weights mdl.Schedule = tPrf.Schedule for _, target := range tPrf.Targets { mdl.TargetType = target.TargetType @@ -2129,11 +2129,15 @@ func APItoActionProfile(tpAp *utils.TPActionProfile, timezone string) (ap *Actio Tenant: tpAp.Tenant, ID: tpAp.ID, FilterIDs: make([]string, len(tpAp.FilterIDs)), - Weight: tpAp.Weight, Schedule: tpAp.Schedule, Targets: make(map[string]utils.StringSet), Actions: make([]*APAction, len(tpAp.Actions)), } + if tpAp.Weights != utils.EmptyString { + if ap.Weights, err = utils.NewDynamicWeightsFromString(tpAp.Weights, utils.InfieldSep, utils.ANDSep); err != nil { + return + } + } for i, stp := range tpAp.FilterIDs { ap.FilterIDs[i] = stp } @@ -2179,7 +2183,7 @@ func ActionProfileToAPI(ap *ActionProfile) (tpAp *utils.TPActionProfile) { Tenant: ap.Tenant, ID: ap.ID, FilterIDs: make([]string, len(ap.FilterIDs)), - Weight: ap.Weight, + Weights: ap.Weights.String(utils.InfieldSep, utils.ANDSep), Schedule: ap.Schedule, Targets: make([]*utils.TPActionTarget, 0, len(ap.Targets)), Actions: make([]*utils.TPAPAction, len(ap.Actions)), diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go index 2cd4f0d1b..f90ee3c06 100644 --- a/engine/model_helpers_test.go +++ b/engine/model_helpers_test.go @@ -3690,7 +3690,7 @@ func TestActionProfileMdlsAsTPActionProfileTimeLen1(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: "*string:~*req.Subject:1001;*ai:~*req.AnswerTime:2014-07-29T15:00:00Z", - Weight: 1, + Weights: ";1", Schedule: "test_schedule", ActionID: "test_action_id", ActionFilterIDs: "test_action_filter_ids", @@ -3702,7 +3702,7 @@ func TestActionProfileMdlsAsTPActionProfileTimeLen1(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*ai:~*req.AnswerTime:2014-07-29T15:00:00Z", "*string:~*req.Subject:1001"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Actions: []*utils.TPAPAction{ { @@ -3727,7 +3727,7 @@ func TestActionProfileMdlsAsTPActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: "*string:~*req.Subject:1001;*ai:~*req.AnswerTime:2014-07-29T15:00:00Z|2014-08-29T15:00:00Z", - Weight: 1, + Weights: ";1", Schedule: "test_schedule", TargetType: utils.MetaAccounts, TargetIDs: "test_account_id1;test_account_id2", @@ -3741,7 +3741,7 @@ func TestActionProfileMdlsAsTPActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*ai:~*req.AnswerTime:2014-07-29T15:00:00Z|2014-08-29T15:00:00Z", "*string:~*req.Subject:1001"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Targets: []*utils.TPActionTarget{ &utils.TPActionTarget{ @@ -3784,7 +3784,7 @@ func TestAPItoModelTPActionProfileTPActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002", "*ai:~*req.AnswerTime:2014-07-29T15:00:00Z|2014-08-29T15:00:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Targets: []*utils.TPActionTarget{{ TargetType: utils.MetaAccounts, @@ -3804,7 +3804,7 @@ func TestAPItoModelTPActionProfileTPActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: "*string:~*req.Subject:1001;*string:~*req.Subject:1002;*ai:~*req.AnswerTime:2014-07-29T15:00:00Z|2014-08-29T15:00:00Z", - Weight: 1, + Weights: ";1", Schedule: "test_schedule", TargetType: utils.MetaAccounts, TargetIDs: "test_account_id1;test_account_id2", @@ -3822,7 +3822,7 @@ func TestModelHelpersAPItoActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Targets: []*utils.TPActionTarget{ &utils.TPActionTarget{ @@ -3850,8 +3850,12 @@ func TestModelHelpersAPItoActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z", "*string:~*req.Subject:1001", "*string:~*req.Subject:1002"}, - Weight: 1, - Schedule: "test_schedule", + Weights: utils.DynamicWeights{ + { + Weight: 1, + }, + }, + Schedule: "test_schedule", Targets: map[string]utils.StringSet{ utils.MetaAccounts: utils.NewStringSet([]string{"test_account_id1", "test_account_id2"}), utils.MetaResources: utils.NewStringSet([]string{"test_ID1", "test_ID2"}), @@ -3883,7 +3887,7 @@ func TestModelHelpersAPItoActionProfileError3(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Actions: []*utils.TPAPAction{ { @@ -3908,7 +3912,7 @@ func TestModelHelpersAPItoActionProfileError4(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Actions: []*utils.TPAPAction{ { @@ -3933,8 +3937,12 @@ func TestModelHelpersActionProfileToAPI(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, - Schedule: "test_schedule", + Weights: utils.DynamicWeights{ + { + Weight: 1, + }, + }, + Schedule: "test_schedule", Actions: []*APAction{ { ID: "test_action_id", @@ -3953,7 +3961,7 @@ func TestModelHelpersActionProfileToAPI(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Targets: []*utils.TPActionTarget{}, Actions: []*utils.TPAPAction{ @@ -4936,7 +4944,7 @@ func TestModelHelpersActionProfileToAPICase2(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Targets: []*utils.TPActionTarget{ &utils.TPActionTarget{ @@ -4960,7 +4968,7 @@ func TestModelHelpersActionProfileToAPICase2(t *testing.T) { Tenant: "cgrates.org", ID: "RP1", FilterIDs: []string{"*string:~*req.Subject:1001", "*ai:~*req.AnswerTime:2014-07-14T14:25:00Z|2014-07-15T14:25:00Z"}, - Weight: 1, + Weights: ";1", Schedule: "test_schedule", Targets: []*utils.TPActionTarget{ &utils.TPActionTarget{ diff --git a/engine/models.go b/engine/models.go index 1843a5aed..5035373ae 100644 --- a/engine/models.go +++ b/engine/models.go @@ -324,21 +324,21 @@ func (RateProfileMdl) TableName() string { type ActionProfileMdl struct { PK uint `gorm:"primary_key"` Tpid string - Tenant string `index:"0" re:""` - ID string `index:"1" re:""` - FilterIDs string `index:"2" re:""` - Weight float64 `index:"3" re:"\d+\.?\d*"` - Schedule string `index:"4" re:""` - TargetType string `index:"5" re:""` - TargetIDs string `index:"6" re:""` - ActionID string `index:"7" re:""` - ActionFilterIDs string `index:"8" re:""` - ActionBlocker bool `index:"9" re:""` - ActionTTL string `index:"10" re:""` - ActionType string `index:"11" re:""` - ActionOpts string `index:"12" re:""` - ActionPath string `index:"13" re:""` - ActionValue string `index:"14" re:""` + Tenant string `index:"0" re:""` + ID string `index:"1" re:""` + FilterIDs string `index:"2" re:""` + Weights string `index:"3" re:"\d+\.?\d*"` + Schedule string `index:"4" re:""` + TargetType string `index:"5" re:""` + TargetIDs string `index:"6" re:""` + ActionID string `index:"7" re:""` + ActionFilterIDs string `index:"8" re:""` + ActionBlocker bool `index:"9" re:""` + ActionTTL string `index:"10" re:""` + ActionType string `index:"11" re:""` + ActionOpts string `index:"12" re:""` + ActionPath string `index:"13" re:""` + ActionValue string `index:"14" re:""` CreatedAt time.Time } diff --git a/engine/z_onstor_it_test.go b/engine/z_onstor_it_test.go index fad740ec4..0fbc05e66 100644 --- a/engine/z_onstor_it_test.go +++ b/engine/z_onstor_it_test.go @@ -1108,8 +1108,12 @@ func testOnStorITActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "TEST_ID1", FilterIDs: []string{"*string:~*req.Account:1001"}, - Weight: 20, - Schedule: utils.MetaASAP, + Weights: utils.DynamicWeights{ + { + Weight: 20, + }, + }, + Schedule: utils.MetaASAP, Targets: map[string]utils.StringSet{ utils.MetaAccounts: utils.NewStringSet([]string{"acc1", "acc2", "acc3"}), }, diff --git a/engine/z_stordb_it_test.go b/engine/z_stordb_it_test.go index 5fbe42ed5..26b82a59c 100644 --- a/engine/z_stordb_it_test.go +++ b/engine/z_stordb_it_test.go @@ -226,7 +226,7 @@ func testStorDBitCRUDTPActionProfiles(t *testing.T) { TPid: "TEST_ID1", ID: "sub_id1", FilterIDs: []string{"*string:~*req.Account:1001"}, - Weight: 20, + Weights: ";20", Schedule: utils.MetaASAP, Actions: []*utils.TPAPAction{ { @@ -243,7 +243,7 @@ func testStorDBitCRUDTPActionProfiles(t *testing.T) { TPid: "TEST_ID1", ID: "sub_id2", FilterIDs: []string{"*string:~*req.Destination:10"}, - Weight: 10, + Weights: ";10", Schedule: utils.MetaASAP, Actions: []*utils.TPAPAction{ { @@ -269,7 +269,7 @@ func testStorDBitCRUDTPActionProfiles(t *testing.T) { //UPDATE AND READ actPrf[0].FilterIDs = []string{"*string:~*req.Account:1007"} - actPrf[1].Weight = 20 + actPrf[1].Weights = ";20" if err := storDB.SetTPActionProfiles(actPrf); err != nil { t.Error(err) } else if rcv, err := storDB.GetTPActionProfiles(actPrf[0].TPid, diff --git a/general_tests/accountactions_it_test.go b/general_tests/accountactions_it_test.go index be8a09ef1..55e984a9d 100644 --- a/general_tests/accountactions_it_test.go +++ b/general_tests/accountactions_it_test.go @@ -121,9 +121,13 @@ func testAccActionsSetActionProfile(t *testing.T) { Tenant: "cgrates.org", ID: "CREATE_ACC", FilterIDs: []string{"*string:~*req.Account:1001"}, - Weight: 0, - Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, - Schedule: utils.MetaASAP, + Weights: utils.DynamicWeights{ + { + Weight: 0, + }, + }, + Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, + Schedule: utils.MetaASAP, Actions: []*engine.APAction{ { ID: "SET_NEW_BAL", @@ -283,9 +287,13 @@ func testAccActionsSetActionProfile2(t *testing.T) { Tenant: "cgrates.org", ID: "REM_ACC", FilterIDs: []string{"*string:~*req.Account:1001"}, - Weight: 0, - Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, - Schedule: utils.MetaASAP, + Weights: utils.DynamicWeights{ + { + Weight: 0, + }, + }, + Targets: map[string]utils.StringSet{utils.MetaAccounts: {"1001": {}}}, + Schedule: utils.MetaASAP, Actions: []*engine.APAction{ { ID: "REM_BAL", diff --git a/general_tests/export_it_test.go b/general_tests/export_it_test.go index fc67de03e..1f5a915ef 100644 --- a/general_tests/export_it_test.go +++ b/general_tests/export_it_test.go @@ -470,8 +470,12 @@ func testExpVerifyActionProfiles(t *testing.T) { Tenant: "cgrates.org", ID: "ONE_TIME_ACT", FilterIDs: []string{}, - Weight: 10, - Schedule: utils.MetaASAP, + Weights: utils.DynamicWeights{ + { + Weight: 10, + }, + }, + Schedule: utils.MetaASAP, Targets: map[string]utils.StringSet{ utils.MetaAccounts: {"1001": {}, "1002": {}}, }, diff --git a/migrator/tp_action_profile_it_test.go b/migrator/tp_action_profile_it_test.go index 4df428f8e..c3486c2e6 100644 --- a/migrator/tp_action_profile_it_test.go +++ b/migrator/tp_action_profile_it_test.go @@ -112,7 +112,7 @@ func testTpACtPrfPopulate(t *testing.T) { TPid: "TEST_ID1", ID: "sub_id1", FilterIDs: []string{"*string:~*req.Account:1001"}, - Weight: 20, + Weights: ";20", Schedule: utils.MetaASAP, Actions: []*utils.TPAPAction{ { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index a703a4731..e0974f60e 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -654,7 +654,7 @@ type TPActionProfile struct { Tenant string ID string FilterIDs []string - Weight float64 + Weights string Schedule string Targets []*TPActionTarget Actions []*TPAPAction