When attributes is require and isn't found return mandatory ie missing fixes #1315

This commit is contained in:
TeoV
2018-11-21 06:15:13 -05:00
committed by Dan Christian Bogos
parent 0a1c499646
commit 7f66a22701
3 changed files with 35 additions and 4 deletions

View File

@@ -54,6 +54,7 @@ var sTestsAlsPrf = []func(t *testing.T){
testAttributeSGetAttributeForEventNotFound,
testAttributeSGetAttributeForEventWithMetaAnyContext,
testAttributeSProcessEvent,
testAttributeSProcessEventMissing,
testAttributeSProcessEventWithNoneSubstitute,
testAttributeSProcessEventWithNoneSubstitute2,
testAttributeSProcessEventWithNoneSubstitute3,
@@ -349,6 +350,24 @@ func testAttributeSProcessEvent(t *testing.T) {
}
}
func testAttributeSProcessEventMissing(t *testing.T) {
ev := &utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSProcessEvent",
Context: utils.StringPointer(utils.MetaSessionS),
Event: map[string]interface{}{
utils.Account: "NonExist",
utils.Category: "*attributes",
utils.Destination: "+491511231234",
},
}
var rplyEv engine.AttrSProcessEventReply
if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
ev, &rplyEv); err == nil && err != utils.ErrMandatoryIeMissing {
t.Error(err)
}
}
func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) {
ev := &utils.CGREvent{
Tenant: "cgrates.org",

View File

@@ -165,6 +165,15 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) (
rply *AttrSProcessEventReply, err error) {
attrPrf, err := alS.attributeProfileForEvent(args)
if err != nil {
if err == utils.ErrNotFound {
// change the error in case that at least one field need to be processed by attributes
for _, valIface := range args.CGREvent.Event {
if valIface == interface{}(utils.MetaAttributes) {
err = utils.ErrMandatoryIeMissing
break
}
}
}
return nil, err
}
rply = &AttrSProcessEventReply{
@@ -204,11 +213,12 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent) (
}
for _, valIface := range rply.CGREvent.Event {
if valIface == interface{}(utils.MetaAttributes) {
// mandatory IE missing
return nil, utils.NewCGRError(
utils.AttributeSv1ProcessEvent,
utils.AttributesNotFound,
utils.AttributesNotFound,
utils.AttributesNotFound)
utils.ErrMandatoryIeMissing.Error(),
utils.ErrMandatoryIeMissing.Error(),
utils.ErrMandatoryIeMissing.Error())
}
}
return
@@ -239,7 +249,7 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent,
for i := 0; i < *args.ProcessRuns; i++ {
evRply, err := alS.processEvent(args)
if err != nil {
if err != utils.ErrNotFound {
if err != utils.ErrNotFound && err != utils.ErrMandatoryIeMissing {
err = utils.NewErrServerError(err)
} else if i != 0 { // ignore "not found" in a loop different than 0
err = nil

View File

@@ -30,6 +30,8 @@ type Metric interface {
GetValue() float64
}
// Old metric (deprecated)
// New mtric are in statmetrics.go
const ASR = "ASR"
const ACD = "ACD"
const TCD = "TCD"