From 734a551903b34dcfda461a97bd03dbdf04ae9ec2 Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 10 Apr 2018 07:43:37 -0400 Subject: [PATCH] Add SuppliersMaxCost in freeswtich and kaamailio , fixes #1039 , fixes #1036 --- agents/fsevent.go | 6 ++++++ agents/fsevent_test.go | 11 ++++++++++- agents/kamevent.go | 6 ++++++ agents/kamevent_test.go | 10 +++++++++- data/tariffplans/testit/Destinations.csv | 2 -- engine/spls_leastcost.go | 12 +++++++----- utils/consts.go | 2 ++ 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/agents/fsevent.go b/agents/fsevent.go index 79ccaca9b..983db1a87 100644 --- a/agents/fsevent.go +++ b/agents/fsevent.go @@ -418,6 +418,12 @@ func (fsev FSEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) { } if strings.Index(subsystems, utils.MetaSuppliers) != -1 { args.GetSuppliers = true + if strings.Index(subsystems, utils.MetaSuppliersEventCost) != -1 { + args.SuppliersMaxCost = utils.MetaEventCost + } + if strings.Index(subsystems, utils.MetaSuppliersIgnoreErrors) != -1 { + args.SuppliersIgnoreErrors = true + } } if strings.Index(subsystems, utils.MetaAttributes) != -1 { args.GetAttributes = true diff --git a/agents/fsevent_test.go b/agents/fsevent_test.go index d42e4d6e3..3fa322f80 100644 --- a/agents/fsevent_test.go +++ b/agents/fsevent_test.go @@ -336,7 +336,8 @@ variable_rtp_audio_out_skip_packet_count: 0 variable_rtp_audio_out_dtmf_packet_count: 0 variable_rtp_audio_out_cng_packet_count: 0 variable_rtp_audio_rtcp_packet_count: 1450 -variable_rtp_audio_rtcp_octet_count: 45940` +variable_rtp_audio_rtcp_octet_count: 45940 +variable_cgr_subsystems: *resources%3B*attributes%3B*sessions%3B*suppliers%3B*suppliers_event_cost%3B*suppliers_ignore_errors%3B*accounts` func TestEventCreation(t *testing.T) { body := `Event-Name: RE_SCHEDULE @@ -988,6 +989,10 @@ func TestFsEvV1AuthorizeArgs(t *testing.T) { Time: &sTime, Event: ev.AsMapStringInterface(timezone), }, + GetSuppliers: true, + GetAttributes: true, + SuppliersIgnoreErrors: true, + SuppliersMaxCost: utils.MetaEventCost, } rcv := ev.V1AuthorizeArgs() if !reflect.DeepEqual(expected.CGREvent.Tenant, rcv.CGREvent.Tenant) { @@ -1004,6 +1009,10 @@ func TestFsEvV1AuthorizeArgs(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expected.GetSuppliers, rcv.GetSuppliers) } else if !reflect.DeepEqual(expected.GetAttributes, rcv.GetAttributes) { t.Errorf("Expecting: %+v, received: %+v", expected.GetAttributes, rcv.GetAttributes) + } else if !reflect.DeepEqual(expected.SuppliersMaxCost, rcv.SuppliersMaxCost) { + t.Errorf("Expecting: %+v, received: %+v", expected.SuppliersMaxCost, rcv.SuppliersMaxCost) + } else if !reflect.DeepEqual(expected.SuppliersIgnoreErrors, rcv.SuppliersIgnoreErrors) { + t.Errorf("Expecting: %+v, received: %+v", expected.SuppliersIgnoreErrors, rcv.SuppliersIgnoreErrors) } } diff --git a/agents/kamevent.go b/agents/kamevent.go index 04d5524cd..202f17648 100644 --- a/agents/kamevent.go +++ b/agents/kamevent.go @@ -242,6 +242,12 @@ func (kev KamEvent) V1AuthorizeArgs() (args *sessions.V1AuthorizeArgs) { } if strings.Index(subsystems, utils.MetaSuppliers) != -1 { args.GetSuppliers = true + if strings.Index(subsystems, utils.MetaSuppliersEventCost) != -1 { + args.SuppliersMaxCost = utils.MetaEventCost + } + if strings.Index(subsystems, utils.MetaSuppliersIgnoreErrors) != -1 { + args.SuppliersIgnoreErrors = true + } } if strings.Index(subsystems, utils.MetaAttributes) != -1 { args.GetAttributes = true diff --git a/agents/kamevent_test.go b/agents/kamevent_test.go index 257a673a0..b5b6935f4 100644 --- a/agents/kamevent_test.go +++ b/agents/kamevent_test.go @@ -175,7 +175,8 @@ func TestKamEvV1AuthorizeArgs(t *testing.T) { "cgr_destination": "1002", "cgr_answertime": "1419839310", "cgr_duration": "3", "cgr_pdd": "4", utils.CGR_SUPPLIER: "supplier2", - utils.CGR_DISCONNECT_CAUSE: "200"} + utils.CGR_DISCONNECT_CAUSE: "200", + KamCGRSubsystems: "*accounts;**suppliers_event_cost;*suppliers_ignore_errors"} sTime, err := utils.ParseTimeDetectLayout(kamEv[utils.AnswerTime], timezone) if err != nil { return @@ -189,6 +190,9 @@ func TestKamEvV1AuthorizeArgs(t *testing.T) { Time: &sTime, Event: kamEv.AsMapStringInterface(), }, + GetSuppliers: true, + SuppliersIgnoreErrors: true, + SuppliersMaxCost: utils.MetaEventCost, } rcv := kamEv.V1AuthorizeArgs() if !reflect.DeepEqual(expected.CGREvent.Tenant, rcv.CGREvent.Tenant) { @@ -205,6 +209,10 @@ func TestKamEvV1AuthorizeArgs(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expected.GetSuppliers, rcv.GetSuppliers) } else if !reflect.DeepEqual(expected.GetAttributes, rcv.GetAttributes) { t.Errorf("Expecting: %+v, received: %+v", expected.GetAttributes, rcv.GetAttributes) + } else if !reflect.DeepEqual(expected.SuppliersMaxCost, rcv.SuppliersMaxCost) { + t.Errorf("Expecting: %+v, received: %+v", expected.SuppliersMaxCost, rcv.SuppliersMaxCost) + } else if !reflect.DeepEqual(expected.SuppliersIgnoreErrors, rcv.SuppliersIgnoreErrors) { + t.Errorf("Expecting: %+v, received: %+v", expected.SuppliersIgnoreErrors, rcv.SuppliersIgnoreErrors) } } diff --git a/data/tariffplans/testit/Destinations.csv b/data/tariffplans/testit/Destinations.csv index 5b5a564a8..57580e2df 100755 --- a/data/tariffplans/testit/Destinations.csv +++ b/data/tariffplans/testit/Destinations.csv @@ -2,7 +2,5 @@ DST_1002,1002 DST_FS,10 DST_DE_MOBILE,+49151 -DST_DE_MOBILE,+49161 -DST_DE_MOBILE,+49171 diff --git a/engine/spls_leastcost.go b/engine/spls_leastcost.go index 2f8b6d689..d80c742e7 100644 --- a/engine/spls_leastcost.go +++ b/engine/spls_leastcost.go @@ -56,7 +56,8 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier, utils.SupplierS, prflID, s.ID)) continue } - if extraOpts.maxCost != 0 && costData[utils.Cost].(float64) > extraOpts.maxCost { + if extraOpts.maxCost != 0 && + costData[utils.Cost].(float64) > extraOpts.maxCost { continue } srtData := map[string]interface{}{ @@ -65,10 +66,11 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string, suppls []*Supplier, for k, v := range costData { srtData[k] = v } - sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{ - SupplierID: s.ID, - SortingData: srtData, - SupplierParameters: s.SupplierParameters}) + sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, + &SortedSupplier{ + SupplierID: s.ID, + SortingData: srtData, + SupplierParameters: s.SupplierParameters}) } if len(sortedSuppls.SortedSuppliers) == 0 { return nil, utils.ErrNotFound diff --git a/utils/consts.go b/utils/consts.go index 338ab70a1..53f891f7d 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -533,6 +533,8 @@ const ( LoaderS = "LoaderS" Pong = "Pong" MetaEventCost = "*event_cost" + MetaSuppliersEventCost = "*suppliers_event_cost" + MetaSuppliersIgnoreErrors = "*suppliers_ignore_errors" ) //MetaMetrics