From a0c19be103ff16081fe58f7e6992e7235ab6091a Mon Sep 17 00:00:00 2001 From: TeoV Date: Wed, 17 Jan 2018 11:46:58 +0200 Subject: [PATCH] Adding SupplierParameters to suppliers --- apier/v1/suppliers_it_test.go | 75 ++++++----- apier/v1/tpattributes_it_test.go | 13 +- apier/v1/tpstats_it_test.go | 37 ++++-- apier/v1/tpsuppliers_it_test.go | 96 ++++++++++---- .../mysql/create_tariffplan_tables.sql | 1 + .../postgres/create_tariffplan_tables.sql | 1 + data/tariffplans/testit/Suppliers.csv | 5 +- data/tariffplans/testtp/Suppliers.csv | 6 +- data/tariffplans/tutorial/Suppliers.csv | 16 +-- engine/libsuppliers.go | 10 +- engine/libsuppliers_test.go | 38 ++++-- engine/loader_csv_test.go | 25 ++-- engine/model_helpers.go | 17 ++- engine/models.go | 5 +- engine/onstor_it_test.go | 107 ++++++--------- engine/spls_leastcost.go | 5 +- engine/suppliers.go | 15 ++- engine/suppliers_test.go | 123 ++++++++++-------- utils/apitpdata.go | 15 ++- 19 files changed, 347 insertions(+), 263 deletions(-) diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index efd4924fc..3494cd6b1 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -226,13 +226,14 @@ func testV1SplSSetSupplierProfiles(t *testing.T) { SortingParams: []string{"Param1", "Param2"}, Suppliers: []*engine.Supplier{ &engine.Supplier{ - ID: "SPL1", - RatingPlanIDs: []string{"RP1"}, - FilterIDs: []string{"FLTR_1"}, - AccountIDs: []string{"Acc"}, - ResourceIDs: []string{"Res1", "ResGroup2"}, - StatIDs: []string{"Stat1"}, - Weight: 20, + ID: "SPL1", + RatingPlanIDs: []string{"RP1"}, + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res1", "ResGroup2"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + SupplierParameters: "SortingParameter1", }, }, Blocker: false, @@ -255,42 +256,46 @@ func testV1SplSSetSupplierProfiles(t *testing.T) { func testV1SplSUpdateSupplierProfiles(t *testing.T) { splPrf.Suppliers = []*engine.Supplier{ &engine.Supplier{ - ID: "SPL1", - RatingPlanIDs: []string{"RP1"}, - FilterIDs: []string{"FLTR_1"}, - AccountIDs: []string{"Acc"}, - ResourceIDs: []string{"Res1", "ResGroup2"}, - StatIDs: []string{"Stat1"}, - Weight: 20, + ID: "SPL1", + RatingPlanIDs: []string{"RP1"}, + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res1", "ResGroup2"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + SupplierParameters: "SortingParameter1", }, &engine.Supplier{ - ID: "SPL2", - RatingPlanIDs: []string{"RP2"}, - FilterIDs: []string{"FLTR_2"}, - AccountIDs: []string{"Acc"}, - ResourceIDs: []string{"Res2", "ResGroup2"}, - StatIDs: []string{"Stat2"}, - Weight: 20, + ID: "SPL2", + RatingPlanIDs: []string{"RP2"}, + FilterIDs: []string{"FLTR_2"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res2", "ResGroup2"}, + StatIDs: []string{"Stat2"}, + Weight: 20, + SupplierParameters: "SortingParameter2", }, } reverseSuppliers := []*engine.Supplier{ &engine.Supplier{ - ID: "SPL2", - RatingPlanIDs: []string{"RP2"}, - FilterIDs: []string{"FLTR_2"}, - AccountIDs: []string{"Acc"}, - ResourceIDs: []string{"Res2", "ResGroup2"}, - StatIDs: []string{"Stat2"}, - Weight: 20, + ID: "SPL2", + RatingPlanIDs: []string{"RP2"}, + FilterIDs: []string{"FLTR_2"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res2", "ResGroup2"}, + StatIDs: []string{"Stat2"}, + Weight: 20, + SupplierParameters: "SortingParameter2", }, &engine.Supplier{ - ID: "SPL1", - RatingPlanIDs: []string{"RP1"}, - FilterIDs: []string{"FLTR_1"}, - AccountIDs: []string{"Acc"}, - ResourceIDs: []string{"Res1", "ResGroup2"}, - StatIDs: []string{"Stat1"}, - Weight: 20, + ID: "SPL1", + RatingPlanIDs: []string{"RP1"}, + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc"}, + ResourceIDs: []string{"Res1", "ResGroup2"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + SupplierParameters: "SortingParameter1", }, } var result string diff --git a/apier/v1/tpattributes_it_test.go b/apier/v1/tpattributes_it_test.go index 5e30a9e06..70cf06cec 100644 --- a/apier/v1/tpattributes_it_test.go +++ b/apier/v1/tpattributes_it_test.go @@ -129,7 +129,7 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) { ActivationTime: "2014-07-29T15:00:00Z", ExpiryTime: "", }, - Context: "con1", + Contexts: []string{"con1"}, Attributes: []*utils.TPAttribute{ &utils.TPAttribute{ FieldName: "FL1", @@ -192,7 +192,8 @@ func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) { func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { var reply *utils.TPAttributeProfile - if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", &AttrGetTPAttributeProfile{TPid: "TP1", ID: "Attr1"}, &reply); err != nil { + if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", + &AttrGetTPAttributeProfile{TPid: "TP1", ID: "Attr1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpAlsPrf, reply) { t.Errorf("Expecting : %+v, received: %+v", tpAlsPrf, reply) @@ -201,7 +202,9 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { func testTPAlsPrfRemTPAlsPrf(t *testing.T) { var resp string - if err := tpAlsPrfRPC.Call("ApierV1.RemTPAttributeProfile", &AttrRemTPAttributeProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &resp); err != nil { + if err := tpAlsPrfRPC.Call("ApierV1.RemTPAttributeProfile", + &AttrRemTPAttributeProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, + &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -210,7 +213,9 @@ func testTPAlsPrfRemTPAlsPrf(t *testing.T) { func testTPAlsPrfGetTPAlsPrfAfterRemove(t *testing.T) { var reply *utils.TPAttributeProfile - if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", &AttrGetTPAttributeProfile{TPid: "TP1", ID: "ALS1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpAlsPrfRPC.Call("ApierV1.GetTPAttributeProfile", + &AttrGetTPAttributeProfile{TPid: "TP1", ID: "ALS1"}, + &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } diff --git a/apier/v1/tpstats_it_test.go b/apier/v1/tpstats_it_test.go index 439c8ebad..3c46c6bee 100644 --- a/apier/v1/tpstats_it_test.go +++ b/apier/v1/tpstats_it_test.go @@ -120,7 +120,9 @@ func testTPStatsRpcConn(t *testing.T) { func testTPStatsGetTPStatBeforeSet(t *testing.T) { var reply *utils.TPStats - if err := tpStatRPC.Call("ApierV1.GetTPStat", AttrGetTPStat{TPid: "TPS1", ID: "Stat1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpStatRPC.Call("ApierV1.GetTPStat", + &AttrGetTPStat{TPid: "TPS1", ID: "Stat1"}, + &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -135,8 +137,13 @@ func testTPStatsSetTPStat(t *testing.T) { ActivationTime: "2014-07-29T15:00:00Z", ExpiryTime: "", }, - TTL: "1", - Metrics: []string{"MetricValue", "MetricValueTwo"}, + TTL: "1", + Metrics: []*utils.MetricWithParams{ + &utils.MetricWithParams{ + MetricID: "*sum", + Parameters: "Param1", + }, + }, Blocker: false, Stored: false, Weight: 20, @@ -153,7 +160,8 @@ func testTPStatsSetTPStat(t *testing.T) { func testTPStatsGetTPStatAfterSet(t *testing.T) { var respond *utils.TPStats - if err := tpStatRPC.Call("ApierV1.GetTPStat", &AttrGetTPStat{TPid: tpStat.TPid, ID: tpStat.ID}, &respond); err != nil { + if err := tpStatRPC.Call("ApierV1.GetTPStat", + &AttrGetTPStat{TPid: tpStat.TPid, ID: tpStat.ID}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpStat, respond) { t.Errorf("Expecting: %+v, received: %+v", tpStat, respond) @@ -163,7 +171,16 @@ func testTPStatsGetTPStatAfterSet(t *testing.T) { func testTPStatsUpdateTPStat(t *testing.T) { var result string tpStat.Weight = 21 - tpStat.FilterIDs = []string{"FLTR_1", "FLTR_STS1"} + tpStat.Metrics = []*utils.MetricWithParams{ + &utils.MetricWithParams{ + MetricID: "*sum", + Parameters: "Param1", + }, + &utils.MetricWithParams{ + MetricID: "*averege", + Parameters: "Param1", + }, + } if err := tpStatRPC.Call("ApierV1.SetTPStat", tpStat, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -173,7 +190,8 @@ func testTPStatsUpdateTPStat(t *testing.T) { func testTPStatsGetTPStatAfterUpdate(t *testing.T) { var expectedTPS *utils.TPStats - if err := tpStatRPC.Call("ApierV1.GetTPStat", &AttrGetTPStat{TPid: tpStat.TPid, ID: tpStat.ID}, &expectedTPS); err != nil { + if err := tpStatRPC.Call("ApierV1.GetTPStat", + &AttrGetTPStat{TPid: tpStat.TPid, ID: tpStat.ID}, &expectedTPS); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpStat, expectedTPS) { t.Errorf("Expecting: %+v, received: %+v", tpStat, expectedTPS) @@ -182,7 +200,8 @@ func testTPStatsGetTPStatAfterUpdate(t *testing.T) { func testTPStatsRemTPStat(t *testing.T) { var resp string - if err := tpStatRPC.Call("ApierV1.RemTPStat", &AttrGetTPStat{TPid: tpStat.TPid, ID: tpStat.ID}, &resp); err != nil { + if err := tpStatRPC.Call("ApierV1.RemTPStat", + &AttrGetTPStat{TPid: tpStat.TPid, ID: tpStat.ID}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -191,7 +210,9 @@ func testTPStatsRemTPStat(t *testing.T) { func testTPStatsGetTPStatAfterRemove(t *testing.T) { var respond *utils.TPStats - if err := tpStatRPC.Call("ApierV1.GetTPStat", &AttrGetTPStat{TPid: "TPS1", ID: "Stat1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpStatRPC.Call("ApierV1.GetTPStat", + &AttrGetTPStat{TPid: "TPS1", ID: "Stat1"}, + &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } diff --git a/apier/v1/tpsuppliers_it_test.go b/apier/v1/tpsuppliers_it_test.go index e9623bd0c..b75965285 100644 --- a/apier/v1/tpsuppliers_it_test.go +++ b/apier/v1/tpsuppliers_it_test.go @@ -114,7 +114,9 @@ func testTPSplPrfRPCConn(t *testing.T) { func testTPSplPrfGetTPSplPrfBeforeSet(t *testing.T) { var reply *utils.TPSupplier - if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", + &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, + &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -133,19 +135,22 @@ func testTPSplPrfSetTPSplPrf(t *testing.T) { SortingParams: []string{}, Suppliers: []*utils.TPSupplier{ &utils.TPSupplier{ - ID: "supplier1", - FilterIDs: []string{"FLTR_1"}, - AccountIDs: []string{"Acc1", "Acc2"}, - RatingPlanIDs: []string{"RPL_1"}, - ResourceIDs: []string{"ResGroup1"}, - StatIDs: []string{"Stat1"}, + ID: "supplier1", + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc1", "Acc2"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGroup1"}, + StatIDs: []string{"Stat1"}, + Weight: 10, + SupplierParameters: "SortingParam1", }, }, Blocker: false, Weight: 20, } var result string - if err := tpSplPrfRPC.Call("ApierV1.SetTPSupplierProfile", tpSplPr, &result); err != nil { + if err := tpSplPrfRPC.Call("ApierV1.SetTPSupplierProfile", + tpSplPr, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -154,7 +159,8 @@ func testTPSplPrfSetTPSplPrf(t *testing.T) { func testTPSplPrfGetTPSplPrfAfterSet(t *testing.T) { var reply *utils.TPSupplierProfile - if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil { + if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", + &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpSplPr, reply) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply)) @@ -164,7 +170,8 @@ func testTPSplPrfGetTPSplPrfAfterSet(t *testing.T) { func testTPSplPrfGetTPSplPrfIDs(t *testing.T) { var result []string expectedTPID := []string{"SUPL_1"} - if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfileIDs", &AttrGetTPSupplierProfileIDs{TPid: "TP1"}, &result); err != nil { + if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfileIDs", + &AttrGetTPSupplierProfileIDs{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result) @@ -175,24 +182,29 @@ func testTPSplPrfGetTPSplPrfIDs(t *testing.T) { func testTPSplPrfUpdateTPSplPrf(t *testing.T) { tpSplPr.Suppliers = []*utils.TPSupplier{ &utils.TPSupplier{ - ID: "supplier1", - FilterIDs: []string{"FLTR_1"}, - AccountIDs: []string{"Acc1", "Acc2"}, - RatingPlanIDs: []string{"RPL_1"}, - ResourceIDs: []string{"ResGroup1"}, - StatIDs: []string{"Stat1"}, + ID: "supplier1", + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc1", "Acc2"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGroup1"}, + StatIDs: []string{"Stat1"}, + Weight: 10, + SupplierParameters: "SortingParam1", }, &utils.TPSupplier{ - ID: "supplier2", - FilterIDs: []string{"FLTR_1"}, - AccountIDs: []string{"Acc3"}, - RatingPlanIDs: []string{"RPL_1"}, - ResourceIDs: []string{"ResGroup1"}, - StatIDs: []string{"Stat1"}, + ID: "supplier2", + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc3"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGroup1"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + SupplierParameters: "SortingParam2", }, } var result string - if err := tpSplPrfRPC.Call("ApierV1.SetTPSupplierProfile", tpSplPr, &result); err != nil { + if err := tpSplPrfRPC.Call("ApierV1.SetTPSupplierProfile", + tpSplPr, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -201,16 +213,42 @@ func testTPSplPrfUpdateTPSplPrf(t *testing.T) { func testTPSplPrfGetTPSplPrfAfterUpdate(t *testing.T) { var reply *utils.TPSupplierProfile - if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil { + reverseSuppliers := []*utils.TPSupplier{ + &utils.TPSupplier{ + ID: "supplier2", + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc3"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGroup1"}, + StatIDs: []string{"Stat1"}, + Weight: 20, + SupplierParameters: "SortingParam2", + }, + &utils.TPSupplier{ + ID: "supplier1", + FilterIDs: []string{"FLTR_1"}, + AccountIDs: []string{"Acc1", "Acc2"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGroup1"}, + StatIDs: []string{"Stat1"}, + Weight: 10, + SupplierParameters: "SortingParam1", + }, + } + if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", + &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err != nil { t.Error(err) - } else if !reflect.DeepEqual(tpSplPr, reply) { - t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply)) + } else if !reflect.DeepEqual(tpSplPr.Suppliers, reply.Suppliers) && + !reflect.DeepEqual(tpSplPr.Suppliers, reverseSuppliers) { + t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tpSplPr), utils.ToJSON(reply)) } } func testTPSplPrfRemTPSplPrf(t *testing.T) { var resp string - if err := tpSplPrfRPC.Call("ApierV1.RemTPSupplierProfile", &AttrRemTPSupplierProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"}, &resp); err != nil { + if err := tpSplPrfRPC.Call("ApierV1.RemTPSupplierProfile", + &AttrRemTPSupplierProfile{TPid: "TP1", Tenant: "cgrates.org", ID: "SUPL_1"}, + &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -219,7 +257,9 @@ func testTPSplPrfRemTPSplPrf(t *testing.T) { func testTPSplPrfGetTPSplPrfAfterRemove(t *testing.T) { var reply *utils.TPSupplierProfile - if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpSplPrfRPC.Call("ApierV1.GetTPSupplierProfile", + &AttrGetTPSupplierProfile{TPid: "TP1", ID: "SUPL_1"}, + &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 608e946c4..c70d466fe 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -510,6 +510,7 @@ CREATE TABLE tp_suppliers ( `supplier_resource_ids` varchar(64) NOT NULL, `supplier_stat_ids` varchar(64) NOT NULL, `supplier_weight` decimal(8,2) NOT NULL, + `supplier_parameters` varchar(64) NOT NULL, `blocker` BOOLEAN NOT NULL, `weight` decimal(8,2) NOT NULL, `created_at` TIMESTAMP, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 591198534..9c97893d6 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -502,6 +502,7 @@ CREATE TABLE tp_suppliers ( "supplier_resource_ids" varchar(64) NOT NULL, "supplier_stat_ids" varchar(64) NOT NULL, "supplier_weight" decimal(8,2) NOT NULL, + "supplier_parameters" varchar(64) NOT NULL, "blocker" BOOLEAN NOT NULL, "weight" decimal(8,2) NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE diff --git a/data/tariffplans/testit/Suppliers.csv b/data/tariffplans/testit/Suppliers.csv index 27e5a8c4c..f899f7da9 100644 --- a/data/tariffplans/testit/Suppliers.csv +++ b/data/tariffplans/testit/Suppliers.csv @@ -1,4 +1,3 @@ #Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,Blocker,Weight -cgrates.org,SPL_ACNT_1001,FLTR_ACCOUNT_1001,,*weight,,supplier1,,,,,,20,,10 -cgrates.org,SPL_ACNT_1001,,,,,supplier2,,,,,,10,, - +cgrates.org,SPL_ACNT_1001,FLTR_ACCOUNT_1001,,*weight,,supplier1,,,,,,20,,,10 +cgrates.org,SPL_ACNT_1001,,,,,supplier2,,,,,,10,,, diff --git a/data/tariffplans/testtp/Suppliers.csv b/data/tariffplans/testtp/Suppliers.csv index 1f93be5a2..9948185d2 100644 --- a/data/tariffplans/testtp/Suppliers.csv +++ b/data/tariffplans/testtp/Suppliers.csv @@ -1,4 +1,4 @@ #Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,Blocker,Weight -cgrates.org,SPP_1,FLTR_ACNT_dan;FLTR_DST_DE,2017-07-29T15:00:00Z,*lowest_cost,,supplier1,FLTR_ACNT_dan,,RPL_1,ResGroup1,Stat1,10,false,10 -cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,false,10 -cgrates.org,SPL_WEIGHT_1,,,,,supplier2,,,,,,20,, +cgrates.org,SPP_1,FLTR_ACNT_dan;FLTR_DST_DE,2017-07-29T15:00:00Z,*lowest_cost,,supplier1,FLTR_ACNT_dan,,RPL_1,ResGroup1,Stat1,10,,false,10 +cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,,false,10 +cgrates.org,SPL_WEIGHT_1,,,,,supplier2,,,,,,20,,, diff --git a/data/tariffplans/tutorial/Suppliers.csv b/data/tariffplans/tutorial/Suppliers.csv index ca20a267d..7d25f166e 100644 --- a/data/tariffplans/tutorial/Suppliers.csv +++ b/data/tariffplans/tutorial/Suppliers.csv @@ -1,8 +1,8 @@ -#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,Blocker,Weight -cgrates.org,SPP_1,FLTR_ACNT_dan;FLTR_DST_DE,2017-07-29T15:00:00Z,*lowest_cost,,supplier1,FLTR_ACNT_dan,,RPL_1,ResGroup1,Stat1,10,false,10 -cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,false,10 -cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE,,,,supplier2,,,,,,20,, -cgrates.org,SPL_WEIGHT_1,FLTR_ACNT_1007,,,,supplier3,FLTR_ACNT_dan,,,,,15,, -cgrates.org,SPL_LEASTCOST_1,FLTR_1,2017-11-27T00:00:00Z,*least_cost,,supplier1,,,RP_SPECIAL_1002,,,10,false,10 -cgrates.org,SPL_LEASTCOST_1,,,,,supplier2,,,RP_RETAIL1,,,20,, -cgrates.org,SPL_LEASTCOST_1,,,,,supplier3,,,RP_SPECIAL_1002,,,15,, +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SortingParameters,Blocker,Weight +cgrates.org,SPP_1,FLTR_ACNT_dan;FLTR_DST_DE,2017-07-29T15:00:00Z,*lowest_cost,,supplier1,FLTR_ACNT_dan,,RPL_1,ResGroup1,Stat1,10,SortingParameter1,false,10 +cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,,false,10 +cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE,,,,supplier2,,,,,,20,,, +cgrates.org,SPL_WEIGHT_1,FLTR_ACNT_1007,,,,supplier3,FLTR_ACNT_dan,,,,,15,,, +cgrates.org,SPL_LEASTCOST_1,FLTR_1,2017-11-27T00:00:00Z,*least_cost,,supplier1,,,RP_SPECIAL_1002,,,10,,false,10 +cgrates.org,SPL_LEASTCOST_1,,,,,supplier2,,,RP_RETAIL1,,,20,,, +cgrates.org,SPL_LEASTCOST_1,,,,,supplier3,,,RP_SPECIAL_1002,,,15,,, diff --git a/engine/libsuppliers.go b/engine/libsuppliers.go index 82ca3762f..335c0b30e 100644 --- a/engine/libsuppliers.go +++ b/engine/libsuppliers.go @@ -28,8 +28,9 @@ import ( // SupplierReply represents one supplier in type SortedSupplier struct { - SupplierID string - SortingData map[string]interface{} // store here extra info like cost or stats + SupplierID string + SortingData map[string]interface{} // store here extra info like cost or stats + SupplierParameters string } // SuppliersReply is returned as part of GetSuppliers call @@ -108,8 +109,9 @@ func (ws *WeightSorter) SortSuppliers(prflID string, SortedSuppliers: make([]*SortedSupplier, len(suppls))} for i, s := range suppls { sortedSuppls.SortedSuppliers[i] = &SortedSupplier{ - SupplierID: s.ID, - SortingData: map[string]interface{}{utils.Weight: s.Weight}} + SupplierID: s.ID, + SortingData: map[string]interface{}{utils.Weight: s.Weight}, + SupplierParameters: s.SupplierParameters} } sortedSuppls.SortWeight() return diff --git a/engine/libsuppliers_test.go b/engine/libsuppliers_test.go index a78ddb739..296842eb6 100644 --- a/engine/libsuppliers_test.go +++ b/engine/libsuppliers_test.go @@ -33,6 +33,7 @@ func TestLibSuppliersSortCost(t *testing.T) { utils.Cost: 0.1, utils.Weight: 10.0, }, + SupplierParameters: "param1", }, &SortedSupplier{ SupplierID: "supplier2", @@ -40,6 +41,7 @@ func TestLibSuppliersSortCost(t *testing.T) { utils.Cost: 0.1, utils.Weight: 20.0, }, + SupplierParameters: "param2", }, &SortedSupplier{ SupplierID: "supplier3", @@ -47,6 +49,7 @@ func TestLibSuppliersSortCost(t *testing.T) { utils.Cost: 0.05, utils.Weight: 10.0, }, + SupplierParameters: "param3", }, }, } @@ -59,6 +62,7 @@ func TestLibSuppliersSortCost(t *testing.T) { utils.Cost: 0.05, utils.Weight: 10.0, }, + SupplierParameters: "param3", }, &SortedSupplier{ SupplierID: "supplier2", @@ -66,6 +70,7 @@ func TestLibSuppliersSortCost(t *testing.T) { utils.Cost: 0.1, utils.Weight: 20.0, }, + SupplierParameters: "param2", }, &SortedSupplier{ SupplierID: "supplier1", @@ -73,6 +78,7 @@ func TestLibSuppliersSortCost(t *testing.T) { utils.Cost: 0.1, utils.Weight: 10.0, }, + SupplierParameters: "param1", }, }, } @@ -85,22 +91,24 @@ func TestLibSuppliersSortCost(t *testing.T) { func TestLibSuppliersSortWeight(t *testing.T) { spl := []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 10.0, + ID: "supplier1", + FilterIDs: []string{}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 10.0, + SupplierParameters: "param1", }, &Supplier{ - ID: "supplier2", - FilterIDs: []string{}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 20.0, + ID: "supplier2", + FilterIDs: []string{}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 20.0, + SupplierParameters: "param2", }, } eSpls := SortedSuppliers{ @@ -112,12 +120,14 @@ func TestLibSuppliersSortWeight(t *testing.T) { SortingData: map[string]interface{}{ "Weight": 20.0, }, + SupplierParameters: "param2", }, &SortedSupplier{ SupplierID: "supplier1", SortingData: map[string]interface{}{ "Weight": 10.0, }, + SupplierParameters: "param1", }, }, } diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index ad9f24814..67258543f 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -291,11 +291,11 @@ cgrates.org,FLTR_DST_DE,*destinations,Destination,DST_DE,2014-07-29T15:00:00Z cgrates.org,FLTR_DST_NL,*destinations,Destination,DST_NL,2014-07-29T15:00:00Z ` sppProfiles = ` -#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,Blocker,Weight -cgrates.org,SPP_1,FLTR_ACNT_dan,2014-07-29T15:00:00Z,*lowest_cost,,supplier1,FLTR_ACNT_dan,Account1;Account1_1,RPL_1,ResGroup1,Stat1,10,true,20 -cgrates.org,SPP_1,,,,,supplier1,,,RPL_2,ResGroup2,,10,, -cgrates.org,SPP_1,,,,,supplier1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,, -cgrates.org,SPP_1,,,,,supplier1,,,,ResGroup4,Stat3,10,, +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierParameters,Blocker,Weight +cgrates.org,SPP_1,FLTR_ACNT_dan,2014-07-29T15:00:00Z,*lowest_cost,,supplier1,FLTR_ACNT_dan,Account1;Account1_1,RPL_1,ResGroup1,Stat1,10,param1,true,20 +cgrates.org,SPP_1,,,,,supplier1,,,RPL_2,ResGroup2,,10,,, +cgrates.org,SPP_1,,,,,supplier1,FLTR_DST_DE,Account2,RPL_3,ResGroup3,Stat2,10,,, +cgrates.org,SPP_1,,,,,supplier1,,,,ResGroup4,Stat3,10,,, ` attributeProfiles = ` #Tenant,ID,Contexts,FilterIDs,ActivationInterval,FieldName,Initial,Substitute,Append,Weight @@ -1645,13 +1645,14 @@ func TestLoadSupplierProfiles(t *testing.T) { SortingParams: []string{}, Suppliers: []*utils.TPSupplier{ &utils.TPSupplier{ - ID: "supplier1", - FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, - AccountIDs: []string{"Account1", "Account1_1", "Account2"}, - RatingPlanIDs: []string{"RPL_1", "RPL_2", "RPL_3"}, - ResourceIDs: []string{"ResGroup1", "ResGroup2", "ResGroup3", "ResGroup4"}, - StatIDs: []string{"Stat1", "Stat2", "Stat3"}, - Weight: 10, + ID: "supplier1", + FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"}, + AccountIDs: []string{"Account1", "Account1_1", "Account2"}, + RatingPlanIDs: []string{"RPL_1", "RPL_2", "RPL_3"}, + ResourceIDs: []string{"ResGroup1", "ResGroup2", "ResGroup3", "ResGroup4"}, + StatIDs: []string{"Stat1", "Stat2", "Stat3"}, + Weight: 10, + SupplierParameters: "param1", }, }, Blocker: true, diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 0769525a0..333507b5b 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2494,6 +2494,9 @@ func (tps TpSuppliers) AsTPSuppliers() (result []*utils.TPSupplierProfile) { Weight: tp.SupplierWeight, } } + if tp.SupplierParameters != "" { + sup.SupplierParameters = tp.SupplierParameters + } if tp.SupplierFilterIDs != "" { supFilterSplit := strings.Split(tp.SupplierFilterIDs, utils.INFIELD_SEP) sup.FilterIDs = append(sup.FilterIDs, supFilterSplit...) @@ -2630,6 +2633,7 @@ func APItoModelTPSuppliers(st *utils.TPSupplierProfile) (mdls TpSuppliers) { mdl.SupplierStatIDs += val } mdl.SupplierWeight = supl.Weight + mdl.SupplierParameters = supl.SupplierParameters mdls = append(mdls, mdl) } return @@ -2657,12 +2661,13 @@ func APItoSupplierProfile(tpTH *utils.TPSupplierProfile, timezone string) (th *S } for i, suplier := range tpTH.Suppliers { supl := &Supplier{ - ID: suplier.ID, - Weight: suplier.Weight, - RatingPlanIDs: suplier.RatingPlanIDs, - FilterIDs: suplier.FilterIDs, - ResourceIDs: suplier.ResourceIDs, - StatIDs: suplier.StatIDs, + ID: suplier.ID, + Weight: suplier.Weight, + RatingPlanIDs: suplier.RatingPlanIDs, + FilterIDs: suplier.FilterIDs, + ResourceIDs: suplier.ResourceIDs, + StatIDs: suplier.StatIDs, + SupplierParameters: suplier.SupplierParameters, } th.Suppliers[i] = supl } diff --git a/engine/models.go b/engine/models.go index 30b26f525..568d05c2f 100755 --- a/engine/models.go +++ b/engine/models.go @@ -537,8 +537,9 @@ type TpSupplier struct { SupplierResourceIDs string `index:"10" re:""` SupplierStatIDs string `index:"11" re:""` SupplierWeight float64 `index:"12" re:"\d+\.?\d*"` - Blocker bool `index:"13" re:""` - Weight float64 `index:"14" re:"\d+\.?\d*"` + SupplierParameters string `index:"13" re:""` + Blocker bool `index:"14" re:""` + Weight float64 `index:"15" re:"\d+\.?\d*"` CreatedAt time.Time } diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index 034e14c1a..3ba86dd45 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -33,10 +33,11 @@ import ( ) var ( - rdsITdb *RedisStorage - mgoITdb *MongoStorage - onStor *DataManager - onStorCfg string + rdsITdb *RedisStorage + mgoITdb *MongoStorage + onStor *DataManager + onStorCfg string + sleepDelay time.Duration ) // subtests to be executed for each confDIR @@ -112,6 +113,7 @@ func TestOnStorITRedis(t *testing.T) { } func TestOnStorITMongoConnect(t *testing.T) { + sleepDelay = 5 * time.Millisecond cdrsMongoCfgPath := path.Join(*dataDir, "conf", "samples", "cdrsv2mongo") mgoITCfg, err := config.NewCGRConfigFromFolder(cdrsMongoCfgPath) if err != nil { @@ -759,9 +761,7 @@ func testOnStorITRatingPlan(t *testing.T) { StartTime: "00:00:00", }, } - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetRatingPlan(rp, utils.NonTransactional); err != nil { t.Error(err) } @@ -839,9 +839,7 @@ func testOnStorITRatingProfile(t *testing.T) { CdrStatQueueIds: []string{}, }, } - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetRatingProfile(rpf, utils.NonTransactional); err != nil { t.Error(err) } @@ -1234,9 +1232,7 @@ func testOnStorITActions(t *testing.T) { }, }, } - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetActions(acts[0].Id, acts, utils.NonTransactional); err != nil { t.Error(err) @@ -1805,9 +1801,7 @@ func testOnStorITResourceProfile(t *testing.T) { } //update rL.Thresholds = []string{"TH1", "TH2"} - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetResourceProfile(rL, false); err != nil { t.Error(err) } @@ -1883,9 +1877,7 @@ func testOnStorITResource(t *testing.T) { } //update res.TTLIdx = []string{"RU1", "RU2"} - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetResource(res); err != nil { t.Error(err) } @@ -1955,9 +1947,7 @@ func testOnStorITTiming(t *testing.T) { } //update tmg.MonthDays = utils.MonthDays{1, 2, 3, 4, 5, 6, 7} - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetTiming(tmg); err != nil { t.Error(err) } @@ -2064,9 +2054,7 @@ func testOnStorITStatQueueProfile(t *testing.T) { } //update sq.Thresholds = []string{"TH1", "TH2"} - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetStatQueueProfile(sq, false); err != nil { t.Error(err) } @@ -2162,9 +2150,7 @@ func testOnStorITStatQueue(t *testing.T) { }, }, } - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetStatQueue(sq); err != nil { t.Error(err) } @@ -2257,9 +2243,7 @@ func testOnStorITThresholdProfile(t *testing.T) { } //update th.ActionIDs = []string{"Action1", "Action2"} - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetThresholdProfile(th, true); err != nil { t.Error(err) } @@ -2329,9 +2313,7 @@ func testOnStorITThreshold(t *testing.T) { } //update th.Hits = 20 - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetThreshold(th); err != nil { t.Error(err) } @@ -2420,9 +2402,7 @@ func testOnStorITFilter(t *testing.T) { Values: []string{"10", "20"}, }, } - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetFilter(fp); err != nil { t.Error(err) } @@ -2467,13 +2447,14 @@ func testOnStorITSupplierProfile(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{"FLTR_DST_DE"}, - AccountIDs: []string{"Account1"}, - RatingPlanIDs: []string{"RPL_1"}, - ResourceIDs: []string{"ResGR1"}, - StatIDs: []string{"Stat1"}, - Weight: 10, + ID: "supplier1", + FilterIDs: []string{"FLTR_DST_DE"}, + AccountIDs: []string{"Account1"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGR1"}, + StatIDs: []string{"Stat1"}, + Weight: 10, + SupplierParameters: "param1", }, }, Weight: 20, @@ -2508,27 +2489,27 @@ func testOnStorITSupplierProfile(t *testing.T) { //update splProfile.Suppliers = []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{"FLTR_DST_DE"}, - AccountIDs: []string{"Account1"}, - RatingPlanIDs: []string{"RPL_1"}, - ResourceIDs: []string{"ResGR1"}, - StatIDs: []string{"Stat1"}, - Weight: 10, + ID: "supplier1", + FilterIDs: []string{"FLTR_DST_DE"}, + AccountIDs: []string{"Account1"}, + RatingPlanIDs: []string{"RPL_1"}, + ResourceIDs: []string{"ResGR1"}, + StatIDs: []string{"Stat1"}, + Weight: 10, + SupplierParameters: "param1", }, &Supplier{ - ID: "supplier2", - FilterIDs: []string{"FLTR_DST_DE"}, - AccountIDs: []string{"Account2"}, - RatingPlanIDs: []string{"RPL_2"}, - ResourceIDs: []string{"ResGR2"}, - StatIDs: []string{"Stat2"}, - Weight: 20, + ID: "supplier2", + FilterIDs: []string{"FLTR_DST_DE"}, + AccountIDs: []string{"Account2"}, + RatingPlanIDs: []string{"RPL_2"}, + ResourceIDs: []string{"ResGR2"}, + StatIDs: []string{"Stat2"}, + Weight: 20, + SupplierParameters: "param2", }, } - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) if err := onStor.SetSupplierProfile(splProfile, false); err != nil { t.Error(err) } @@ -2610,9 +2591,7 @@ func testOnStorITAttributeProfile(t *testing.T) { t.Errorf("Expected : %+v, but received %+v", expectedT, itm) } //update - if onStor.DataDB().GetStorageType() == utils.MONGO { - time.Sleep(5 * time.Millisecond) - } + time.Sleep(sleepDelay) attrProfile.Contexts = []string{"con1", "con2", "con3"} if err := onStor.SetAttributeProfile(attrProfile, false); err != nil { t.Error(err) diff --git a/engine/spls_leastcost.go b/engine/spls_leastcost.go index b55eaabaf..c62d9a37d 100644 --- a/engine/spls_leastcost.go +++ b/engine/spls_leastcost.go @@ -57,8 +57,9 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, srtData[k] = v } sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{ - SupplierID: s.ID, - SortingData: srtData}) + SupplierID: s.ID, + SortingData: srtData, + SupplierParameters: s.SupplierParameters}) } sortedSuppls.SortCost() return diff --git a/engine/suppliers.go b/engine/suppliers.go index 7ffee8ce4..a912ae1c6 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -32,13 +32,14 @@ import ( // Supplier defines supplier related information used within a SupplierProfile type Supplier struct { - ID string // SupplierID - FilterIDs []string - AccountIDs []string - RatingPlanIDs []string // used when computing price - ResourceIDs []string // queried in some strategies - StatIDs []string // queried in some strategies - Weight float64 + ID string // SupplierID + FilterIDs []string + AccountIDs []string + RatingPlanIDs []string // used when computing price + ResourceIDs []string // queried in some strategies + StatIDs []string // queried in some strategies + Weight float64 + SupplierParameters string } // SupplierProfile represents the configuration of a Supplier profile diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go index 2b43bc931..3d47083c5 100644 --- a/engine/suppliers_test.go +++ b/engine/suppliers_test.go @@ -47,13 +47,14 @@ func TestSuppliersSort(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 10.0, + ID: "supplier1", + FilterIDs: []string{}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 10.0, + SupplierParameters: "param1", }, }, Blocker: false, @@ -71,13 +72,14 @@ func TestSuppliersSort(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 20.0, + ID: "supplier1", + FilterIDs: []string{}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 20.0, + SupplierParameters: "param1", }, }, Blocker: false, @@ -97,13 +99,14 @@ func TestSuppliersSort(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 20.0, + ID: "supplier1", + FilterIDs: []string{}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 20.0, + SupplierParameters: "param1", }, }, Blocker: false, @@ -121,13 +124,14 @@ func TestSuppliersSort(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 10.0, + ID: "supplier1", + FilterIDs: []string{}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 10.0, + SupplierParameters: "param1", }, }, Blocker: false, @@ -214,13 +218,14 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier1", - FilterIDs: []string{"filter3"}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 10.0, + ID: "supplier1", + FilterIDs: []string{"filter3"}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 10.0, + SupplierParameters: "param1", }, }, Blocker: false, @@ -238,31 +243,34 @@ func TestSuppliersPopulateSupplierService(t *testing.T) { SortingParams: []string{}, Suppliers: []*Supplier{ &Supplier{ - ID: "supplier2", - FilterIDs: []string{"filter4"}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 20.0, + ID: "supplier2", + FilterIDs: []string{"filter4"}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 20.0, + SupplierParameters: "param2", }, &Supplier{ - ID: "supplier3", - FilterIDs: []string{"filter4"}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 10.0, + ID: "supplier3", + FilterIDs: []string{"filter4"}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 10.0, + SupplierParameters: "param3", }, &Supplier{ - ID: "supplier1", - FilterIDs: []string{"filter4"}, - AccountIDs: []string{}, - RatingPlanIDs: []string{}, - ResourceIDs: []string{}, - StatIDs: []string{}, - Weight: 30.0, + ID: "supplier1", + FilterIDs: []string{"filter4"}, + AccountIDs: []string{}, + RatingPlanIDs: []string{}, + ResourceIDs: []string{}, + StatIDs: []string{}, + Weight: 30.0, + SupplierParameters: "param1", }, }, Blocker: false, @@ -304,18 +312,21 @@ func TestSuppliersSortedForEvent(t *testing.T) { SortingData: map[string]interface{}{ "Weight": 30.0, }, + SupplierParameters: "param1", }, &SortedSupplier{ SupplierID: "supplier2", SortingData: map[string]interface{}{ "Weight": 20.0, }, + SupplierParameters: "param2", }, &SortedSupplier{ SupplierID: "supplier3", SortingData: map[string]interface{}{ "Weight": 10.0, }, + SupplierParameters: "param3", }, }, } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 85697ddb4..c3daf1ccf 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1380,13 +1380,14 @@ type TPFilter struct { } type TPSupplier struct { - ID string // SupplierID - FilterIDs []string - AccountIDs []string - RatingPlanIDs []string // used when computing price - ResourceIDs []string // queried in some strategies - StatIDs []string // queried in some strategies - Weight float64 + ID string // SupplierID + FilterIDs []string + AccountIDs []string + RatingPlanIDs []string // used when computing price + ResourceIDs []string // queried in some strategies + StatIDs []string // queried in some strategies + Weight float64 + SupplierParameters string } type TPSupplierProfile struct {