Skip to content

Commit

Permalink
LcrRequest.IgnoreErrors flag implementation, fixes #142
Browse files Browse the repository at this point in the history
  • Loading branch information
danbogos committed Aug 10, 2015
1 parent 9b8afb6 commit 95694b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
13 changes: 8 additions & 5 deletions apier/v1/lcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down
20 changes: 12 additions & 8 deletions engine/lcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions general_tests/tutorial_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 95694b6

Please sign in to comment.