From a12d80d415ac6871498d4e2a78e2dd2d03d09265 Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 30 Jan 2018 12:50:33 +0200 Subject: [PATCH] Remove Blocker from SupplierProfile and add to Supplier --- apier/v1/filter_indexes_it_test.go | 8 ++--- apier/v1/suppliers_it_test.go | 8 +++-- apier/v1/tpsuppliers_it_test.go | 8 +++-- .../mysql/create_tariffplan_tables.sql | 2 +- .../postgres/create_tariffplan_tables.sql | 2 +- data/tariffplans/testit/Suppliers.csv | 2 +- data/tariffplans/testtp/Suppliers.csv | 9 +++--- data/tariffplans/tutorial/Suppliers.csv | 8 ++--- engine/loader_csv_test.go | 8 ++--- engine/model_helpers.go | 9 +++--- engine/models.go | 4 +-- engine/suppliers.go | 8 +---- engine/suppliers_test.go | 32 +++++++++---------- migrator/migrator_it_test.go | 4 +-- utils/apitpdata.go | 2 +- 15 files changed, 58 insertions(+), 56 deletions(-) diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index b8f8d60ab..1f209860e 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -1023,10 +1023,10 @@ func testV1FIdxSetSupplierProfileIndexes(t *testing.T) { ResourceIDs: []string{"Res1", "ResGroup2"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, }, }, - Blocker: false, - Weight: 10, + Weight: 10, } if err := tFIdxRpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil { t.Error(err) @@ -1132,10 +1132,10 @@ func testV1FIdxSetSecondSupplierProfileIndexes(t *testing.T) { ResourceIDs: []string{"Res1", "ResGroup2"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, }, }, - Blocker: false, - Weight: 10, + Weight: 10, } if err := tFIdxRpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil { t.Error(err) diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index 7fdd73f80..7b785f2e4 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -237,11 +237,11 @@ func testV1SplSSetSupplierProfiles(t *testing.T) { ResourceIDs: []string{"Res1", "ResGroup2"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, SupplierParameters: "SortingParameter1", }, }, - Blocker: false, - Weight: 10, + Weight: 10, } var result string if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil { @@ -267,6 +267,7 @@ func testV1SplSUpdateSupplierProfiles(t *testing.T) { ResourceIDs: []string{"Res1", "ResGroup2"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, SupplierParameters: "SortingParameter1", }, &engine.Supplier{ @@ -277,6 +278,7 @@ func testV1SplSUpdateSupplierProfiles(t *testing.T) { ResourceIDs: []string{"Res2", "ResGroup2"}, StatIDs: []string{"Stat2"}, Weight: 20, + Blocker: true, SupplierParameters: "SortingParameter2", }, } @@ -289,6 +291,7 @@ func testV1SplSUpdateSupplierProfiles(t *testing.T) { ResourceIDs: []string{"Res2", "ResGroup2"}, StatIDs: []string{"Stat2"}, Weight: 20, + Blocker: true, SupplierParameters: "SortingParameter2", }, &engine.Supplier{ @@ -299,6 +302,7 @@ func testV1SplSUpdateSupplierProfiles(t *testing.T) { ResourceIDs: []string{"Res1", "ResGroup2"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, SupplierParameters: "SortingParameter1", }, } diff --git a/apier/v1/tpsuppliers_it_test.go b/apier/v1/tpsuppliers_it_test.go index b75965285..2e6069169 100644 --- a/apier/v1/tpsuppliers_it_test.go +++ b/apier/v1/tpsuppliers_it_test.go @@ -142,11 +142,11 @@ func testTPSplPrfSetTPSplPrf(t *testing.T) { ResourceIDs: []string{"ResGroup1"}, StatIDs: []string{"Stat1"}, Weight: 10, + Blocker: false, SupplierParameters: "SortingParam1", }, }, - Blocker: false, - Weight: 20, + Weight: 20, } var result string if err := tpSplPrfRPC.Call("ApierV1.SetTPSupplierProfile", @@ -189,6 +189,7 @@ func testTPSplPrfUpdateTPSplPrf(t *testing.T) { ResourceIDs: []string{"ResGroup1"}, StatIDs: []string{"Stat1"}, Weight: 10, + Blocker: true, SupplierParameters: "SortingParam1", }, &utils.TPSupplier{ @@ -199,6 +200,7 @@ func testTPSplPrfUpdateTPSplPrf(t *testing.T) { ResourceIDs: []string{"ResGroup1"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, SupplierParameters: "SortingParam2", }, } @@ -222,6 +224,7 @@ func testTPSplPrfGetTPSplPrfAfterUpdate(t *testing.T) { ResourceIDs: []string{"ResGroup1"}, StatIDs: []string{"Stat1"}, Weight: 20, + Blocker: false, SupplierParameters: "SortingParam2", }, &utils.TPSupplier{ @@ -232,6 +235,7 @@ func testTPSplPrfGetTPSplPrfAfterUpdate(t *testing.T) { ResourceIDs: []string{"ResGroup1"}, StatIDs: []string{"Stat1"}, Weight: 10, + Blocker: true, SupplierParameters: "SortingParam1", }, } diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 5738f64ce..2447b27fa 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -510,8 +510,8 @@ 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_blocker` BOOLEAN NOT NULL, `supplier_parameters` varchar(64) NOT NULL, - `blocker` BOOLEAN NOT NULL, `weight` decimal(8,2) NOT NULL, `created_at` TIMESTAMP, PRIMARY KEY (`pk`), diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 359541df8..d5e56bf1e 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -502,8 +502,8 @@ 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_blocker" BOOLEAN 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 f899f7da9..3a90da05a 100644 --- a/data/tariffplans/testit/Suppliers.csv +++ b/data/tariffplans/testit/Suppliers.csv @@ -1,3 +1,3 @@ -#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,Blocker,Weight +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierBlocker,SortingParameters,Weight 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 9948185d2..426ea3529 100644 --- a/data/tariffplans/testtp/Suppliers.csv +++ b/data/tariffplans/testtp/Suppliers.csv @@ -1,4 +1,5 @@ -#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,,, +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierBlocker,SortingParameters,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,SortingParameter1,10 +cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,,,10 +cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE,,,,supplier2,,,,,,20,,, +cgrates.org,SPL_WEIGHT_1,FLTR_ACNT_1007,,,,supplier3,FLTR_ACNT_dan,,,,,15,,, diff --git a/data/tariffplans/tutorial/Suppliers.csv b/data/tariffplans/tutorial/Suppliers.csv index 7d25f166e..0b3eae82b 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,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 +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierBlocker,SortingParameters,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,SortingParameter1,10 +cgrates.org,SPL_WEIGHT_1,FLTR_DST_DE;FLTR_ACNT_1007,2017-11-27T00:00:00Z,*weight,,supplier1,,,,,,10,,,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,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/loader_csv_test.go b/engine/loader_csv_test.go index a84468163..380e291ea 100755 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -291,8 +291,8 @@ 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,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 +#Tenant,ID,FilterIDs,ActivationInterval,Sorting,SortingParams,SupplierID,SupplierFilterIDs,SupplierAccountIDs,SupplierRatingPlanIDs,SupplierResourceIDs,SupplierStatIDs,SupplierWeight,SupplierBlocker,SupplierParameters,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,param1,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,,, @@ -1652,11 +1652,11 @@ func TestLoadSupplierProfiles(t *testing.T) { ResourceIDs: []string{"ResGroup1", "ResGroup2", "ResGroup3", "ResGroup4"}, StatIDs: []string{"Stat1", "Stat2", "Stat3"}, Weight: 10, + Blocker: true, SupplierParameters: "param1", }, }, - Blocker: true, - Weight: 20, + Weight: 20, }, } resKey := utils.TenantID{Tenant: "cgrates.org", ID: "SPP_1"} diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 597a2f4d8..7382f52c2 100755 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -2478,7 +2478,6 @@ func (tps TpSuppliers) AsTPSuppliers() (result []*utils.TPSupplierProfile) { TPid: tp.Tpid, Tenant: tp.Tenant, ID: tp.ID, - Blocker: tp.Blocker, Sorting: tp.Sorting, SortingParams: []string{}, } @@ -2490,8 +2489,9 @@ func (tps TpSuppliers) AsTPSuppliers() (result []*utils.TPSupplierProfile) { sup, found := suppliersMap[tp.ID][tp.SupplierID] if !found { sup = &utils.TPSupplier{ - ID: tp.SupplierID, - Weight: tp.SupplierWeight, + ID: tp.SupplierID, + Weight: tp.SupplierWeight, + Blocker: tp.SupplierBlocker, } } if tp.SupplierParameters != "" { @@ -2585,7 +2585,6 @@ func APItoModelTPSuppliers(st *utils.TPSupplierProfile) (mdls TpSuppliers) { if i == 0 { mdl.Sorting = st.Sorting mdl.Weight = st.Weight - mdl.Blocker = st.Blocker for i, val := range st.FilterIDs { if i != 0 { mdl.FilterIDs += utils.INFIELD_SEP @@ -2645,7 +2644,6 @@ func APItoSupplierProfile(tpTH *utils.TPSupplierProfile, timezone string) (th *S ID: tpTH.ID, Sorting: tpTH.Sorting, Weight: tpTH.Weight, - Blocker: tpTH.Blocker, Suppliers: make([]*Supplier, len(tpTH.Suppliers)), } for _, stp := range tpTH.SortingParams { @@ -2663,6 +2661,7 @@ func APItoSupplierProfile(tpTH *utils.TPSupplierProfile, timezone string) (th *S supl := &Supplier{ ID: suplier.ID, Weight: suplier.Weight, + Blocker: suplier.Blocker, RatingPlanIDs: suplier.RatingPlanIDs, FilterIDs: suplier.FilterIDs, ResourceIDs: suplier.ResourceIDs, diff --git a/engine/models.go b/engine/models.go index e534b933f..93e1bbe27 100755 --- a/engine/models.go +++ b/engine/models.go @@ -537,8 +537,8 @@ type TpSupplier struct { SupplierResourceIDs string `index:"10" re:""` SupplierStatIDs string `index:"11" re:""` SupplierWeight float64 `index:"12" re:"\d+\.?\d*"` - SupplierParameters string `index:"13" re:""` - Blocker bool `index:"14" re:""` + SupplierBlocker bool `index:"13" re:""` + SupplierParameters string `index:"14" re:""` Weight float64 `index:"15" re:"\d+\.?\d*"` CreatedAt time.Time } diff --git a/engine/suppliers.go b/engine/suppliers.go index e4844c785..452fc0039 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -39,6 +39,7 @@ type Supplier struct { ResourceIDs []string // queried in some strategies StatIDs []string // queried in some strategies Weight float64 + Blocker bool // do not process further supplier after this one SupplierParameters string } @@ -51,7 +52,6 @@ type SupplierProfile struct { Sorting string // Sorting strategy SortingParams []string Suppliers []*Supplier - Blocker bool // do not process further profiles after this one Weight float64 } @@ -160,12 +160,6 @@ func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *utils.CGREvent) i++ } sPrfls.Sort() - for i, sPrfl := range sPrfls { - if sPrfl.Blocker { // blocker will stop processing - sPrfls = sPrfls[:i+1] - break - } - } return } diff --git a/engine/suppliers_test.go b/engine/suppliers_test.go index ce6ab6c7b..d79c28a12 100644 --- a/engine/suppliers_test.go +++ b/engine/suppliers_test.go @@ -52,11 +52,11 @@ var ( ResourceIDs: []string{}, StatIDs: []string{}, Weight: 10.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 10, + Weight: 10, }, &SupplierProfile{ Tenant: "cgrates.org", @@ -97,11 +97,11 @@ var ( ResourceIDs: []string{}, StatIDs: []string{}, Weight: 30.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 20.0, + Weight: 20.0, }, &SupplierProfile{ Tenant: "cgrates.org", @@ -122,11 +122,11 @@ var ( ResourceIDs: []string{}, StatIDs: []string{}, Weight: 10.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 10, + Weight: 10, }, &SupplierProfile{ Tenant: "cgrates.org", @@ -167,11 +167,11 @@ var ( ResourceIDs: []string{}, StatIDs: []string{}, Weight: 30.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 20.0, + Weight: 20.0, }, } argPagEv = &ArgsGetSuppliers{ @@ -241,11 +241,11 @@ func TestSuppliersSort(t *testing.T) { ResourceIDs: []string{}, StatIDs: []string{}, Weight: 10.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 10, + Weight: 10, }, &SupplierProfile{ Tenant: "cgrates.org", @@ -266,11 +266,11 @@ func TestSuppliersSort(t *testing.T) { ResourceIDs: []string{}, StatIDs: []string{}, Weight: 20.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 20.0, + Weight: 20.0, }, } eSupplierProfile := SupplierProfiles{ @@ -293,11 +293,11 @@ func TestSuppliersSort(t *testing.T) { ResourceIDs: []string{}, StatIDs: []string{}, Weight: 20.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 20.0, + Weight: 20.0, }, &SupplierProfile{ Tenant: "cgrates.org", @@ -318,11 +318,11 @@ func TestSuppliersSort(t *testing.T) { ResourceIDs: []string{}, StatIDs: []string{}, Weight: 10.0, + Blocker: false, SupplierParameters: "param1", }, }, - Blocker: false, - Weight: 10.0, + Weight: 10.0, }, } sprs.Sort() diff --git a/migrator/migrator_it_test.go b/migrator/migrator_it_test.go index 8cb3e54e2..93d044c6e 100644 --- a/migrator/migrator_it_test.go +++ b/migrator/migrator_it_test.go @@ -2012,10 +2012,10 @@ func testMigratorTPSuppliers(t *testing.T) { ResourceIDs: []string{"ResGroup1"}, StatIDs: []string{"Stat1"}, Weight: 10, + Blocker: false, }, }, - Blocker: false, - Weight: 20, + Weight: 20, }, } switch action { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 5c2dab528..f0a618124 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1387,6 +1387,7 @@ type TPSupplier struct { ResourceIDs []string // queried in some strategies StatIDs []string // queried in some strategies Weight float64 + Blocker bool SupplierParameters string } @@ -1399,7 +1400,6 @@ type TPSupplierProfile struct { Sorting string SortingParams []string Suppliers []*TPSupplier - Blocker bool Weight float64 }