Remove Blocker from SupplierProfile and add to Supplier

This commit is contained in:
TeoV
2018-01-30 12:50:33 +02:00
committed by Dan Christian Bogos
parent 24f19d6646
commit a12d80d415
15 changed files with 58 additions and 56 deletions

View File

@@ -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"}

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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()