mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Updated ProcessMessage reply
This commit is contained in:
@@ -369,9 +369,10 @@ func (da *DiameterAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
msgArgs, rply)
|
||||
if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) {
|
||||
cgrEv.Event[utils.Usage] = 0 // avoid further debits
|
||||
} else if rply.MaxUsage != nil {
|
||||
cgrEv.Event[utils.Usage] = *rply.MaxUsage // make sure the CDR reflects the debit
|
||||
} else if msgArgs.Debit {
|
||||
cgrEv.Event[utils.Usage] = rply.MaxUsage // make sure the CDR reflects the debit
|
||||
}
|
||||
rply.SetMaxUsageNeeded(msgArgs.Debit)
|
||||
if err = agReq.setCGRReply(rply, err); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -492,7 +492,7 @@ func TestProcessRequest(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
MaxUsage: utils.DurationPointer(10 * time.Second),
|
||||
MaxUsage: 10 * time.Second,
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -296,9 +296,10 @@ func (da *DNSAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
evArgs, rply)
|
||||
if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) {
|
||||
cgrEv.Event[utils.Usage] = 0 // avoid further debits
|
||||
} else if rply.MaxUsage != nil {
|
||||
cgrEv.Event[utils.Usage] = *rply.MaxUsage // make sure the CDR reflects the debit
|
||||
} else if evArgs.Debit {
|
||||
cgrEv.Event[utils.Usage] = rply.MaxUsage // make sure the CDR reflects the debit
|
||||
}
|
||||
rply.SetMaxUsageNeeded(evArgs.Debit)
|
||||
if err = agReq.setCGRReply(rply, err); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -219,9 +219,10 @@ func (ha *HTTPAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
evArgs, rply)
|
||||
if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) {
|
||||
cgrEv.Event[utils.Usage] = 0 // avoid further debits
|
||||
} else if rply.MaxUsage != nil {
|
||||
cgrEv.Event[utils.Usage] = *rply.MaxUsage // make sure the CDR reflects the debit
|
||||
} else if evArgs.Debit {
|
||||
cgrEv.Event[utils.Usage] = rply.MaxUsage // make sure the CDR reflects the debit
|
||||
}
|
||||
rply.SetMaxUsageNeeded(evArgs.Debit)
|
||||
if err = agReq.setCGRReply(nil, err); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -328,11 +328,7 @@ func (kev KamEvent) AsKamProcessMessageReply(procEvArgs *sessions.V1ProcessMessa
|
||||
kar.ResourceAllocation = *procEvReply.ResourceAllocation
|
||||
}
|
||||
if procEvArgs.Debit {
|
||||
if *procEvReply.MaxUsage == -1 { // For calls different than unlimited, set limits
|
||||
kar.MaxUsage = -1
|
||||
} else {
|
||||
kar.MaxUsage = int(utils.Round(procEvReply.MaxUsage.Seconds(), 0, utils.ROUNDING_MIDDLE))
|
||||
}
|
||||
kar.MaxUsage = int(utils.Round(procEvReply.MaxUsage.Seconds(), 0, utils.ROUNDING_MIDDLE))
|
||||
}
|
||||
if procEvArgs.GetSuppliers && procEvReply.Suppliers != nil {
|
||||
kar.Suppliers = procEvReply.Suppliers.Digest()
|
||||
|
||||
@@ -403,7 +403,7 @@ func TestKamEvAsKamProcessEventReply(t *testing.T) {
|
||||
},
|
||||
}
|
||||
procEvhRply := &sessions.V1ProcessMessageReply{
|
||||
MaxUsage: utils.DurationPointer(time.Duration(5 * time.Second)),
|
||||
MaxUsage: 5 * time.Second,
|
||||
}
|
||||
expected := &KamReply{
|
||||
Event: CGR_PROCESS_MESSAGE,
|
||||
|
||||
@@ -264,9 +264,10 @@ func (ra *RadiusAgent) processRequest(reqProcessor *config.RequestProcessor,
|
||||
err = ra.sessionS.Call(utils.SessionSv1ProcessMessage, evArgs, rply)
|
||||
if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) {
|
||||
cgrEv.Event[utils.Usage] = 0 // avoid further debits
|
||||
} else if rply.MaxUsage != nil {
|
||||
cgrEv.Event[utils.Usage] = *rply.MaxUsage // make sure the CDR reflects the debit
|
||||
} else if evArgs.Debit {
|
||||
cgrEv.Event[utils.Usage] = rply.MaxUsage // make sure the CDR reflects the debit
|
||||
}
|
||||
rply.SetMaxUsageNeeded(evArgs.Debit)
|
||||
if err = agReq.setCGRReply(rply, err); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -588,8 +588,8 @@ func testSSv1ItProcessEvent(t *testing.T) {
|
||||
// in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
|
||||
// and in case of postpaid and rated we expect the value of Usage field
|
||||
// if this was missing the MaxUsage should be equal to MaxCallDuration from config
|
||||
if *rply.MaxUsage != initUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", *rply.MaxUsage)
|
||||
if rply.MaxUsage != initUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
if *rply.ResourceAllocation != "RES_ACNT_1001" {
|
||||
t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
|
||||
|
||||
@@ -553,7 +553,7 @@ func testDspSessionProcessEvent(t *testing.T) {
|
||||
args, &rply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if *rply.MaxUsage != initUsage {
|
||||
if rply.MaxUsage != initUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
if *rply.ResourceAllocation != "RES_ACNT_1001" {
|
||||
@@ -620,7 +620,7 @@ func testDspSessionProcessEvent2(t *testing.T) {
|
||||
args, &rply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if *rply.MaxUsage != initUsage {
|
||||
if rply.MaxUsage != initUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
if *rply.ResourceAllocation != "RES_ACNT_1001" {
|
||||
|
||||
@@ -251,8 +251,8 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, rdrCfg *config.EventRe
|
||||
evArgs, rply)
|
||||
if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) {
|
||||
cgrEv.Event[utils.Usage] = 0 // avoid further debits
|
||||
} else if rply.MaxUsage != nil {
|
||||
cgrEv.Event[utils.Usage] = *rply.MaxUsage // make sure the CDR reflects the debit
|
||||
} else if evArgs.Debit {
|
||||
cgrEv.Event[utils.Usage] = rply.MaxUsage // make sure the CDR reflects the debit
|
||||
}
|
||||
case utils.MetaEvent:
|
||||
evArgs := &sessions.V1ProcessEventArgs{
|
||||
|
||||
@@ -605,7 +605,7 @@ func testRPCMethodsProcessEvent(t *testing.T) {
|
||||
if err := rpcRpc.Call(utils.SessionSv1ProcessMessage,
|
||||
args, &rplyFirst); err != nil {
|
||||
t.Error(err)
|
||||
} else if *rplyFirst.MaxUsage != initUsage {
|
||||
} else if rplyFirst.MaxUsage != initUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rplyFirst.MaxUsage)
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ func testSes3ItProcessEvent(t *testing.T) {
|
||||
args, &rply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if *rply.MaxUsage != initUsage {
|
||||
if rply.MaxUsage != initUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
if *rply.ResourceAllocation != "RES_ACNT_1001" {
|
||||
|
||||
@@ -2760,12 +2760,21 @@ func (args *V1ProcessMessageArgs) ParseFlags(flags string) {
|
||||
|
||||
// V1ProcessMessageReply is the reply for the ProcessMessage API
|
||||
type V1ProcessMessageReply struct {
|
||||
MaxUsage *time.Duration
|
||||
MaxUsage time.Duration
|
||||
ResourceAllocation *string
|
||||
Attributes *engine.AttrSProcessEventReply
|
||||
Suppliers *engine.SortedSuppliers
|
||||
ThresholdIDs *[]string
|
||||
StatQueueIDs *[]string
|
||||
getMaxUsage bool
|
||||
}
|
||||
|
||||
// SetMaxUsageNeeded used by agent that use the reply as NavigableMapper
|
||||
func (v1Rply *V1ProcessMessageReply) SetMaxUsageNeeded(getMaxUsage bool) {
|
||||
if v1Rply == nil {
|
||||
return
|
||||
}
|
||||
v1Rply.getMaxUsage = getMaxUsage
|
||||
}
|
||||
|
||||
// AsNavigableMap is part of engine.NavigableMapper interface
|
||||
@@ -2773,8 +2782,8 @@ func (v1Rply *V1ProcessMessageReply) AsNavigableMap(
|
||||
ignr []*config.FCTemplate) (*config.NavigableMap, error) {
|
||||
cgrReply := make(map[string]interface{})
|
||||
if v1Rply != nil {
|
||||
if v1Rply.MaxUsage != nil {
|
||||
cgrReply[utils.CapMaxUsage] = *v1Rply.MaxUsage
|
||||
if v1Rply.getMaxUsage {
|
||||
cgrReply[utils.CapMaxUsage] = v1Rply.MaxUsage
|
||||
}
|
||||
if v1Rply.ResourceAllocation != nil {
|
||||
cgrReply[utils.CapResourceAllocation] = *v1Rply.ResourceAllocation
|
||||
@@ -2886,7 +2895,7 @@ func (sS *SessionS) BiRPCv1ProcessMessage(clnt rpcclient.RpcClientConnection,
|
||||
engine.MapEvent(args.CGREvent.Event), args.ArgDispatcher); err != nil {
|
||||
return utils.NewErrRALs(err)
|
||||
}
|
||||
rply.MaxUsage = &maxUsage
|
||||
rply.MaxUsage = maxUsage
|
||||
}
|
||||
if args.ProcessThresholds {
|
||||
tIDs, err := sS.processThreshold(args.CGREvent, args.ArgDispatcher,
|
||||
|
||||
@@ -1266,8 +1266,9 @@ func TestSessionSV1ProcessMessageReplyAsNavigableMap(t *testing.T) {
|
||||
t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply)
|
||||
}
|
||||
|
||||
v1PrcEvRpl.MaxUsage = utils.DurationPointer(5 * time.Minute)
|
||||
v1PrcEvRpl.MaxUsage = 5 * time.Minute
|
||||
expected.Set([]string{utils.CapMaxUsage}, 5*time.Minute, false, false)
|
||||
v1PrcEvRpl.SetMaxUsageNeeded(true)
|
||||
if rply, _ := v1PrcEvRpl.AsNavigableMap(nil); !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply)
|
||||
}
|
||||
@@ -1292,7 +1293,7 @@ func TestSessionSV1ProcessMessageReplyAsNavigableMap(t *testing.T) {
|
||||
expected.Set([]string{utils.CapSuppliers}, tmpSuppliers.AsNavigableMap(), false, false)
|
||||
expected.Set([]string{utils.CapThresholds}, tmpTresholdIDs, false, false)
|
||||
expected.Set([]string{utils.CapStatQueues}, tmpStatQueueIDs, false, false)
|
||||
|
||||
v1PrcEvRpl.SetMaxUsageNeeded(true)
|
||||
if rply, _ := v1PrcEvRpl.AsNavigableMap(nil); !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("Expecting \n%+v\n, received: \n%+v", expected, rply)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user