From 8392092a19550c1b09f20cea6bcd022c0ab6ac55 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 27 Mar 2020 11:11:49 +0200 Subject: [PATCH] Move *cost as subflag in *rals for SessionSv1.ProcessEvent + Remove *cost flag from SessionSv1.GetCost --- apier/v1/sessions_process_event_it_test.go | 10 +- dispatchers/sessions_it_test.go | 1 - packages/debian/changelog | 3 + sessions/sessions.go | 232 ++++++++++----------- 4 files changed, 123 insertions(+), 123 deletions(-) diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go index 79fe6a757..a570804ed 100644 --- a/apier/v1/sessions_process_event_it_test.go +++ b/apier/v1/sessions_process_event_it_test.go @@ -475,7 +475,7 @@ func testSSv1ItGetCDRs(t *testing.T) { func testSSv1ItProcessEventWithGetCost(t *testing.T) { // GetCost for ANY2CNT Subject args := &sessions.V1ProcessEventArgs{ - Flags: []string{utils.MetaAttributes, utils.MetaCost}, + Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventWithGetCost", @@ -514,7 +514,7 @@ func testSSv1ItProcessEventWithGetCost(t *testing.T) { func testSSv1ItProcessEventWithGetCost2(t *testing.T) { // GetCost for SPECIAL_1002 Subject args := &sessions.V1ProcessEventArgs{ - Flags: []string{utils.MetaAttributes, utils.MetaCost}, + Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventWithGetCost2", @@ -555,7 +555,7 @@ func testSSv1ItProcessEventWithGetCost3(t *testing.T) { // 0.8 connect fee + 0.4 for first minute // for the 9 minutes remaining apply args := &sessions.V1ProcessEventArgs{ - Flags: []string{utils.MetaAttributes, utils.MetaCost}, + Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventWithGetCost3", @@ -593,7 +593,7 @@ func testSSv1ItProcessEventWithGetCost3(t *testing.T) { func testSSv1ItProcessEventWithGetCost4(t *testing.T) { args := &sessions.V1ProcessEventArgs{ - Flags: []string{utils.MetaAttributes, utils.MetaCost}, + Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItProcessEventWithGetCost4", @@ -621,7 +621,7 @@ func testSSv1ItProcessEventWithGetCost4(t *testing.T) { func testSSv1ItGetCost(t *testing.T) { // GetCost for ANY2CNT Subject args := &sessions.V1ProcessEventArgs{ - Flags: []string{utils.MetaAttributes, utils.MetaCost}, + Flags: []string{utils.MetaAttributes}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItGetCost", diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go index 1591ee207..49f6cf805 100755 --- a/dispatchers/sessions_it_test.go +++ b/dispatchers/sessions_it_test.go @@ -937,7 +937,6 @@ func testDspSessionProcessEvent3(t *testing.T) { func testDspSessionGetCost(t *testing.T) { args := &sessions.V1ProcessEventArgs{ - Flags: []string{utils.MetaCost}, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSSv1ItGetCost", diff --git a/packages/debian/changelog b/packages/debian/changelog index 356579bef..1a318e0e9 100644 --- a/packages/debian/changelog +++ b/packages/debian/changelog @@ -41,6 +41,9 @@ cgrates (0.11.0~dev) UNRELEASED; urgency=medium MSCHAPV2) * [SessionS] Update subflags for *rals ( *authorize and *initiate ) * [AgentS] Uniformize flags (*auth -> *authorize) + * [SessionS] Move *cost as subflag in *rals for + SessionSv1.ProcessEvent + * [SessionS] Remove *cost flag from SessionSv1.GetCost -- Alexandru Tripon Wed, 19 Feb 2020 13:25:52 +0200 diff --git a/sessions/sessions.go b/sessions/sessions.go index 6318355e4..181a98c00 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -2939,64 +2939,6 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, return utils.NewErrAttributeS(err) } } - // check for *cost - if argsFlagsWithParams.HasKey(utils.MetaCost) { - //compose the CallDescriptor with Args - me := engine.MapEvent(args.CGREvent.Event).Clone() - startTime := me.GetTimeIgnoreErrors(utils.AnswerTime, - sS.cgrCfg.GeneralCfg().DefaultTimezone) - if startTime.IsZero() { // AnswerTime not parsable, try SetupTime - startTime = me.GetTimeIgnoreErrors(utils.SetupTime, - sS.cgrCfg.GeneralCfg().DefaultTimezone) - } - category := me.GetStringIgnoreErrors(utils.Category) - if len(category) == 0 { - category = sS.cgrCfg.GeneralCfg().DefaultCategory - } - subject := me.GetStringIgnoreErrors(utils.Subject) - if len(subject) == 0 { - subject = me.GetStringIgnoreErrors(utils.Account) - } - - cd := &engine.CallDescriptor{ - RunID: me.GetStringIgnoreErrors(utils.RunID), - ToR: me.GetStringIgnoreErrors(utils.ToR), - Tenant: args.CGREvent.Tenant, - Category: category, - Subject: subject, - Account: me.GetStringIgnoreErrors(utils.Account), - Destination: me.GetStringIgnoreErrors(utils.Destination), - TimeStart: startTime, - TimeEnd: startTime.Add(me.GetDurationIgnoreErrors(utils.Usage)), - } - var argDsp *utils.ArgDispatcher - //check if we have APIKey in event and in case it has add it in ArgDispatcher - apiKey, errAPIKey := me.GetString(utils.MetaApiKey) - if errAPIKey == nil { - argDsp = &utils.ArgDispatcher{ - APIKey: utils.StringPointer(apiKey), - } - } - //check if we have RouteID in event and in case it has add it in ArgDispatcher - if routeID, err := me.GetString(utils.MetaRouteID); err == nil { - if errAPIKey == utils.ErrNotFound { //in case we don't have APIKey, but we have RouteID we need to initialize the struct - argDsp = &utils.ArgDispatcher{ - RouteID: utils.StringPointer(routeID), - } - } else { - argDsp.RouteID = utils.StringPointer(routeID) - } - } - - var cc engine.CallCost - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, - utils.ResponderGetCost, - &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, - ArgDispatcher: argDsp}, &cc); err != nil { - return - } - rply.Cost = utils.Float64Pointer(cc.Cost) - } // check for *resources if argsFlagsWithParams.HasKey(utils.MetaResources) { if len(sS.cgrCfg.SessionSCfg().ResSConns) == 0 { @@ -3047,7 +2989,65 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, if ralsOpts := argsFlagsWithParams.ParamsSlice(utils.MetaRALs); len(ralsOpts) != 0 { //check for subflags and convert them into utils.FlagsWithParams ralsFlagsWithParams, err := utils.FlagsWithParamsFromSlice(ralsOpts) - //for the moment only the the flag will be executed + // check for *cost + if ralsFlagsWithParams.HasKey(utils.MetaCost) { + //compose the CallDescriptor with Args + me := engine.MapEvent(args.CGREvent.Event).Clone() + startTime := me.GetTimeIgnoreErrors(utils.AnswerTime, + sS.cgrCfg.GeneralCfg().DefaultTimezone) + if startTime.IsZero() { // AnswerTime not parsable, try SetupTime + startTime = me.GetTimeIgnoreErrors(utils.SetupTime, + sS.cgrCfg.GeneralCfg().DefaultTimezone) + } + category := me.GetStringIgnoreErrors(utils.Category) + if len(category) == 0 { + category = sS.cgrCfg.GeneralCfg().DefaultCategory + } + subject := me.GetStringIgnoreErrors(utils.Subject) + if len(subject) == 0 { + subject = me.GetStringIgnoreErrors(utils.Account) + } + + cd := &engine.CallDescriptor{ + CgrID: args.CGREvent.ID, + RunID: me.GetStringIgnoreErrors(utils.RunID), + ToR: me.GetStringIgnoreErrors(utils.ToR), + Tenant: args.CGREvent.Tenant, + Category: category, + Subject: subject, + Account: me.GetStringIgnoreErrors(utils.Account), + Destination: me.GetStringIgnoreErrors(utils.Destination), + TimeStart: startTime, + TimeEnd: startTime.Add(me.GetDurationIgnoreErrors(utils.Usage)), + } + var argDsp *utils.ArgDispatcher + //check if we have APIKey in event and in case it has add it in ArgDispatcher + apiKey, errAPIKey := me.GetString(utils.MetaApiKey) + if errAPIKey == nil { + argDsp = &utils.ArgDispatcher{ + APIKey: utils.StringPointer(apiKey), + } + } + //check if we have RouteID in event and in case it has add it in ArgDispatcher + if routeID, err := me.GetString(utils.MetaRouteID); err == nil { + if errAPIKey == utils.ErrNotFound { //in case we don't have APIKey, but we have RouteID we need to initialize the struct + argDsp = &utils.ArgDispatcher{ + RouteID: utils.StringPointer(routeID), + } + } else { + argDsp.RouteID = utils.StringPointer(routeID) + } + } + + var cc engine.CallCost + if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + utils.ResponderGetCost, + &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, + ArgDispatcher: argDsp}, &cc); err != nil { + return err + } + rply.Cost = utils.Float64Pointer(cc.Cost) + } switch { //check for auth session case ralsFlagsWithParams.HasKey(utils.MetaAuthorize): @@ -3258,66 +3258,64 @@ func (sS *SessionS) BiRPCv1GetCost(clnt rpcclient.ClientConnector, return utils.NewErrAttributeS(err) } } - // check for *cost - if argsFlagsWithParams.HasKey(utils.MetaCost) { - //compose the CallDescriptor with Args - me := engine.MapEvent(args.CGREvent.Event).Clone() - startTime := me.GetTimeIgnoreErrors(utils.AnswerTime, + //compose the CallDescriptor with Args + me := engine.MapEvent(args.CGREvent.Event).Clone() + startTime := me.GetTimeIgnoreErrors(utils.AnswerTime, + sS.cgrCfg.GeneralCfg().DefaultTimezone) + if startTime.IsZero() { // AnswerTime not parsable, try SetupTime + startTime = me.GetTimeIgnoreErrors(utils.SetupTime, sS.cgrCfg.GeneralCfg().DefaultTimezone) - if startTime.IsZero() { // AnswerTime not parsable, try SetupTime - startTime = me.GetTimeIgnoreErrors(utils.SetupTime, - sS.cgrCfg.GeneralCfg().DefaultTimezone) - } - category := me.GetStringIgnoreErrors(utils.Category) - if len(category) == 0 { - category = sS.cgrCfg.GeneralCfg().DefaultCategory - } - subject := me.GetStringIgnoreErrors(utils.Subject) - if len(subject) == 0 { - subject = me.GetStringIgnoreErrors(utils.Account) - } - - cd := &engine.CallDescriptor{ - RunID: me.GetStringIgnoreErrors(utils.RunID), - ToR: me.GetStringIgnoreErrors(utils.ToR), - Tenant: args.CGREvent.Tenant, - Category: category, - Subject: subject, - Account: me.GetStringIgnoreErrors(utils.Account), - Destination: me.GetStringIgnoreErrors(utils.Destination), - TimeStart: startTime, - TimeEnd: startTime.Add(me.GetDurationIgnoreErrors(utils.Usage)), - } - var argDsp *utils.ArgDispatcher - //check if we have APIKey in event and in case it has add it in ArgDispatcher - apiKey, errAPIKey := me.GetString(utils.MetaApiKey) - if errAPIKey == nil { - argDsp = &utils.ArgDispatcher{ - APIKey: utils.StringPointer(apiKey), - } - } - //check if we have RouteID in event and in case it has add it in ArgDispatcher - if routeID, err := me.GetString(utils.MetaRouteID); err == nil { - if errAPIKey == utils.ErrNotFound { //in case we don't have APIKey, but we have RouteID we need to initialize the struct - argDsp = &utils.ArgDispatcher{ - RouteID: utils.StringPointer(routeID), - } - } else { - argDsp.RouteID = utils.StringPointer(routeID) - } - } - - var cc engine.CallCost - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, - utils.ResponderGetCost, - &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, - ArgDispatcher: argDsp}, &cc); err != nil { - return - } - ec := engine.NewEventCostFromCallCost(&cc, args.CGREvent.ID, me.GetStringIgnoreErrors(utils.RunID)) - ec.Compute() - rply.EventCost = ec } + category := me.GetStringIgnoreErrors(utils.Category) + if len(category) == 0 { + category = sS.cgrCfg.GeneralCfg().DefaultCategory + } + subject := me.GetStringIgnoreErrors(utils.Subject) + if len(subject) == 0 { + subject = me.GetStringIgnoreErrors(utils.Account) + } + + cd := &engine.CallDescriptor{ + CgrID: args.CGREvent.ID, + RunID: me.GetStringIgnoreErrors(utils.RunID), + ToR: me.GetStringIgnoreErrors(utils.ToR), + Tenant: args.CGREvent.Tenant, + Category: category, + Subject: subject, + Account: me.GetStringIgnoreErrors(utils.Account), + Destination: me.GetStringIgnoreErrors(utils.Destination), + TimeStart: startTime, + TimeEnd: startTime.Add(me.GetDurationIgnoreErrors(utils.Usage)), + } + var argDsp *utils.ArgDispatcher + //check if we have APIKey in event and in case it has add it in ArgDispatcher + apiKey, errAPIKey := me.GetString(utils.MetaApiKey) + if errAPIKey == nil { + argDsp = &utils.ArgDispatcher{ + APIKey: utils.StringPointer(apiKey), + } + } + //check if we have RouteID in event and in case it has add it in ArgDispatcher + if routeID, err := me.GetString(utils.MetaRouteID); err == nil { + if errAPIKey == utils.ErrNotFound { //in case we don't have APIKey, but we have RouteID we need to initialize the struct + argDsp = &utils.ArgDispatcher{ + RouteID: utils.StringPointer(routeID), + } + } else { + argDsp.RouteID = utils.StringPointer(routeID) + } + } + + var cc engine.CallCost + if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + utils.ResponderGetCost, + &engine.CallDescriptorWithArgDispatcher{CallDescriptor: cd, + ArgDispatcher: argDsp}, &cc); err != nil { + return + } + ec := engine.NewEventCostFromCallCost(&cc, args.CGREvent.ID, me.GetStringIgnoreErrors(utils.RunID)) + ec.Compute() + rply.EventCost = ec if withErrors { err = utils.ErrPartiallyExecuted }