From 95694b688e33f686eb98dd8ad830b86848924403 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 10 Aug 2015 15:47:38 +0200 Subject: [PATCH] LcrRequest.IgnoreErrors flag implementation, fixes #142 --- apier/v1/lcr.go | 13 ++++++++----- engine/lcr.go | 20 ++++++++++++-------- general_tests/tutorial_local_test.go | 10 +++++----- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/apier/v1/lcr.go b/apier/v1/lcr.go index 1f73fac8b..513bc64e0 100644 --- a/apier/v1/lcr.go +++ b/apier/v1/lcr.go @@ -38,14 +38,17 @@ func (self *ApierV1) GetLcr(lcrReq engine.LcrRequest, lcrReply *engine.LcrReply) if lcrQried.Entry == nil { return utils.ErrNotFound } - if lcrQried.HasErrors() { - lcrQried.LogErrors() - return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_COMPUTE_ERRORS") - } lcrReply.DestinationId = lcrQried.Entry.DestinationId lcrReply.RPCategory = lcrQried.Entry.RPCategory lcrReply.Strategy = lcrQried.Entry.Strategy for _, qriedSuppl := range lcrQried.SupplierCosts { + if qriedSuppl.Error != "" { + engine.Logger.Err(fmt.Sprintf("LCR_ERROR: supplier <%s>, error <%s>", qriedSuppl.Supplier, qriedSuppl.Error)) + if !lcrReq.IgnoreErrors { + return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_COMPUTE_ERRORS") + } + continue + } if dtcs, err := utils.NewDTCSFromRPKey(qriedSuppl.Supplier); err != nil { return utils.NewErrServerError(err) } else { @@ -65,7 +68,7 @@ func (self *ApierV1) GetLcrSuppliers(lcrReq engine.LcrRequest, suppliers *string if err := self.Responder.GetLCR(&engine.AttrGetLcr{CallDescriptor: cd, Paginator: lcrReq.Paginator}, &lcrQried); err != nil { return utils.NewErrServerError(err) } - if lcrQried.HasErrors() { + if lcrQried.HasErrors() && !lcrReq.IgnoreErrors { lcrQried.LogErrors() return fmt.Errorf("%s:%s", utils.ErrServerError.Error(), "LCR_ERRORS") } diff --git a/engine/lcr.go b/engine/lcr.go index 192635584..f5925d256 100644 --- a/engine/lcr.go +++ b/engine/lcr.go @@ -48,14 +48,15 @@ const ( // A request for LCR, used in APIer and SM where we need to expose it type LcrRequest struct { - Direction string - Tenant string - Category string - Account string - Subject string - Destination string - StartTime string - Duration string + Direction string + Tenant string + Category string + Account string + Subject string + Destination string + StartTime string + Duration string + IgnoreErrors bool *utils.Paginator } @@ -434,6 +435,9 @@ func (lc *LCRCost) SuppliersSlice() ([]string, error) { } supps := []string{} for _, supplCost := range lc.SupplierCosts { + if supplCost.Error != "" { + continue // Do not add the supplier with cost errors to list of suppliers available + } if dtcs, err := utils.NewDTCSFromRPKey(supplCost.Supplier); err != nil { return nil, err } else if len(dtcs.Subject) != 0 { diff --git a/general_tests/tutorial_local_test.go b/general_tests/tutorial_local_test.go index 041a25a76..ede31b1ee 100644 --- a/general_tests/tutorial_local_test.go +++ b/general_tests/tutorial_local_test.go @@ -117,7 +117,7 @@ func TestTutLocalCacheStats(t *testing.T) { } var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 4, RatingPlans: 3, RatingProfiles: 8, Actions: 7, SharedGroups: 1, RatingAliases: 1, AccountAliases: 1, - DerivedChargers: 1, LcrProfiles: 4, CdrStats: 6, Users: 2} + DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 2} var args utils.AttrCacheStats if err := tutLocalRpc.Call("ApierV1.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) @@ -898,8 +898,8 @@ func TestTutLocalLeastCost(t *testing.T) { Direction: "*out", Category: "call", Tenant: "cgrates.org", - Subject: "1004", - Account: "1004", + Subject: "1005", + Account: "1005", Destination: "1002", TimeStart: tStart, TimeEnd: tEnd, @@ -924,8 +924,8 @@ func TestTutLocalLeastCost(t *testing.T) { Direction: "*out", Category: "call", Tenant: "cgrates.org", - Subject: "1004", - Account: "1004", + Subject: "1005", + Account: "1005", Destination: "1003", TimeStart: tStart, TimeEnd: tEnd,