From 51c10841de30a176af88d586d54f173e53ebc722 Mon Sep 17 00:00:00 2001 From: TeoV Date: Sun, 17 Feb 2019 13:00:25 +0200 Subject: [PATCH] Move context out of CGREvent --- agents/kamevent.go | 6 +- agents/kamevent_test.go | 15 ++-- dispatchers/dispatchers.go | 8 +-- dispatchers/sessions_it_test.go | 2 +- engine/attributes.go | 3 +- engine/attributes_test.go | 121 +++++++++++++++----------------- engine/calldesc.go | 7 +- engine/calldesc_test.go | 15 ++-- engine/chargers.go | 7 +- engine/chargers_test.go | 15 ++-- engine/suppliers.go | 4 +- sessions/sessions.go | 16 ++--- sessions/sessions_test.go | 30 ++++---- utils/cgrevent.go | 12 ++-- utils/cgrevent_test.go | 11 +-- 15 files changed, 110 insertions(+), 162 deletions(-) diff --git a/agents/kamevent.go b/agents/kamevent.go index d5814527b..1e96d0cfa 100644 --- a/agents/kamevent.go +++ b/agents/kamevent.go @@ -40,13 +40,12 @@ const ( KamHashEntry = "h_entry" KamHashID = "h_id" KamReplyRoute = "reply_route" - KamCGRContext = "cgr_context" EvapiConnID = "EvapiConnID" // used to share connID info in event for remote disconnects CGR_DLG_LIST = "CGR_DLG_LIST" ) var ( - kamReservedEventFields = []string{EVENT, KamTRIndex, KamTRLabel, utils.CGRSubsystems, KamCGRContext, KamReplyRoute} + kamReservedEventFields = []string{EVENT, KamTRIndex, KamTRLabel, utils.CGRSubsystems, KamReplyRoute} kamReservedCDRFields = append(kamReservedEventFields, KamHashEntry, KamHashID) // HashEntry and id are needed in events for disconnects ) @@ -160,9 +159,6 @@ func (kev KamEvent) AsCGREvent(timezone string) (cgrEv *utils.CGREvent, err erro Time: &sTime, Event: kev.AsMapStringInterface(), } - if ctx, has := kev[KamCGRContext]; has { - cgrEv.Context = utils.StringPointer(ctx) - } return cgrEv, nil } diff --git a/agents/kamevent_test.go b/agents/kamevent_test.go index ea747c643..fb5e1997d 100644 --- a/agents/kamevent_test.go +++ b/agents/kamevent_test.go @@ -111,8 +111,7 @@ func TestKamEvAsCGREvent(t *testing.T) { "cgr_destination": "1002", "cgr_answertime": "1419839310", "cgr_duration": "3", "cgr_pdd": "4", utils.CGR_SUPPLIER: "supplier2", - utils.CGR_DISCONNECT_CAUSE: "200", - KamCGRContext: "account_profile"} + utils.CGR_DISCONNECT_CAUSE: "200"} sTime, err := utils.ParseTimeDetectLayout(kamEv[utils.AnswerTime], timezone) if err != nil { return @@ -120,10 +119,9 @@ func TestKamEvAsCGREvent(t *testing.T) { expected := &utils.CGREvent{ Tenant: utils.FirstNonEmpty(kamEv[utils.Tenant], config.CgrConfig().GeneralCfg().DefaultTenant), - ID: utils.UUIDSha1Prefix(), - Time: &sTime, - Context: utils.StringPointer("account_profile"), - Event: kamEv.AsMapStringInterface(), + ID: utils.UUIDSha1Prefix(), + Time: &sTime, + Event: kamEv.AsMapStringInterface(), } if rcv, err := kamEv.AsCGREvent(timezone); err != nil { t.Error(err) @@ -240,9 +238,8 @@ func TestKamEvAsKamAuthReply(t *testing.T) { MatchedProfiles: []string{"ATTR_1001_ACCOUNT_PROFILE"}, AlteredFields: []string{"Password", utils.RequestType}, CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "TestKamEvAsKamAuthReply", - Context: utils.StringPointer("account_profile"), + Tenant: "cgrates.org", + ID: "TestKamEvAsKamAuthReply", Event: map[string]interface{}{ utils.Tenant: "cgrates.org", utils.Account: "1001", diff --git a/dispatchers/dispatchers.go b/dispatchers/dispatchers.go index 5963c3763..0924da336 100755 --- a/dispatchers/dispatchers.go +++ b/dispatchers/dispatchers.go @@ -179,6 +179,7 @@ func (dS *DispatcherService) authorizeEvent(ev *utils.CGREvent, reply *engine.AttrSProcessEventReply) (err error) { if err = dS.attrS.Call(utils.AttributeSv1ProcessEvent, &engine.AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaAuth), CGREvent: *ev}, reply); err != nil { if err.Error() == utils.ErrNotFound.Error() { err = utils.ErrUnknownApiKey @@ -193,10 +194,9 @@ func (dS *DispatcherService) authorize(method, tenant, apiKey string, evTime *ti return utils.NewErrMandatoryIeMissing(utils.APIKey) } ev := &utils.CGREvent{ - Tenant: tenant, - ID: utils.UUIDSha1Prefix(), - Context: utils.StringPointer(utils.MetaAuth), - Time: evTime, + Tenant: tenant, + ID: utils.UUIDSha1Prefix(), + Time: evTime, Event: map[string]interface{}{ utils.APIKey: apiKey, }, diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go index 4e0230743..ac0ecaffa 100755 --- a/dispatchers/sessions_it_test.go +++ b/dispatchers/sessions_it_test.go @@ -330,7 +330,7 @@ func testDspSessionUpdate(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes)) } if *rply.MaxUsage != reqUsage { - t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) + t.Errorf("Unexpected MaxUsage: %v", utils.ToJSON(rply)) } } diff --git a/engine/attributes.go b/engine/attributes.go index 09d9f9771..bfe7826b3 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -142,7 +142,8 @@ func (attrReply *AttrSProcessEventReply) Digest() (rplyDigest string) { type AttrArgsProcessEvent struct { AttributeIDs []string - ProcessRuns *int // number of loops for ProcessEvent + Context *string // attach the event to a context + ProcessRuns *int // number of loops for ProcessEvent utils.CGREvent } diff --git a/engine/attributes_test.go b/engine/attributes_test.go index ec478ee36..e6b49f67e 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -43,10 +43,10 @@ var ( } attrEvs = []*AttrArgsProcessEvent{ { + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: utils.CGREvent{ //matching AttributeProfile1 - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Attribute": "AttributeProfile1", utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC), @@ -56,30 +56,30 @@ var ( }, }, { + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: utils.CGREvent{ //matching AttributeProfile2 - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Attribute": "AttributeProfile2", }, }, }, { + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: utils.CGREvent{ //matching AttributeProfilePrefix - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Attribute": "AttributeProfilePrefix", }, }, }, { + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: utils.CGREvent{ //matching AttributeProfilePrefix - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "DistinctMatch": 20, }, @@ -333,9 +333,8 @@ func TestAttributeEventReplyDigest(t *testing.T) { MatchedProfiles: []string{"ATTR_1"}, AlteredFields: []string{utils.Account, utils.Subject}, CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testAttributeSProcessEvent", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "testAttributeSProcessEvent", Event: map[string]interface{}{ utils.Account: "1001", utils.Subject: "1001", @@ -355,9 +354,8 @@ func TestAttributeEventReplyDigest2(t *testing.T) { MatchedProfiles: []string{"ATTR_1"}, AlteredFields: []string{}, CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testAttributeSProcessEvent", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "testAttributeSProcessEvent", Event: map[string]interface{}{ utils.Account: "1001", utils.Subject: "1001", @@ -377,9 +375,8 @@ func TestAttributeEventReplyDigest3(t *testing.T) { MatchedProfiles: []string{"ATTR_1"}, AlteredFields: []string{"Subject"}, CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testAttributeSProcessEvent", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "testAttributeSProcessEvent", Event: map[string]interface{}{ utils.Account: "1001", utils.Subject: "1001", @@ -399,9 +396,8 @@ func TestAttributeEventReplyDigest4(t *testing.T) { MatchedProfiles: []string{"ATTR_1"}, AlteredFields: []string{"Subject"}, CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testAttributeSProcessEvent", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "testAttributeSProcessEvent", Event: map[string]interface{}{ utils.Account: "1001", utils.Destinations: "+491511231234", @@ -559,11 +555,11 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(4), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, @@ -573,9 +569,8 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_3"}, AlteredFields: []string{"Field1", "Field2", "Field3"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", "Field1": "Value1", @@ -674,11 +669,11 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(4), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, @@ -688,9 +683,8 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, AlteredFields: []string{"Field1", "Field2"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", "Field1": "Value1", @@ -788,11 +782,11 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(2), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, @@ -802,9 +796,8 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, AlteredFields: []string{"Field1", "Field2"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", "Field1": "Value1", @@ -881,11 +874,11 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(4), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, @@ -895,9 +888,8 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, AlteredFields: []string{"Field1", "Field2"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", "Field1": "Value1", @@ -996,11 +988,11 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(4), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, @@ -1010,9 +1002,8 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, AlteredFields: []string{"Field1", "Field2"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", "Field1": "Value1", @@ -1111,11 +1102,11 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { t.Errorf("Error: %+v", err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(4), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", }, @@ -1125,9 +1116,8 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { MatchedProfiles: []string{"ATTR_1"}, AlteredFields: []string{"Field1"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "InitialField": "InitialValue", "Field1": "Value1", @@ -1183,11 +1173,11 @@ func TestAttributeProcessSubstitute(t *testing.T) { t.Error(err) } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), ProcessRuns: utils.IntPointer(1), CGREvent: utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Field1": "Value1", }, @@ -1197,9 +1187,8 @@ func TestAttributeProcessSubstitute(t *testing.T) { MatchedProfiles: []string{"ATTR_1"}, AlteredFields: []string{"Field2"}, CGREvent: &utils.CGREvent{ - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Field1": "Value1", "Field2": "Value1", diff --git a/engine/calldesc.go b/engine/calldesc.go index 1a0e74a0f..116a54dc3 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -193,10 +193,9 @@ type CallDescriptor struct { // AsCGREvent converts the CallDescriptor into CGREvent func (cd *CallDescriptor) AsCGREvent() *utils.CGREvent { cgrEv := &utils.CGREvent{ - Tenant: cd.Tenant, - ID: utils.UUIDSha1Prefix(), // make it unique - Context: utils.StringPointer(utils.MetaRating), - Event: make(map[string]interface{}), + Tenant: cd.Tenant, + ID: utils.UUIDSha1Prefix(), // make it unique + Event: make(map[string]interface{}), } for k, v := range cd.ExtraFields { cgrEv.Event[k] = v diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index dd5a6fab1..661ab614d 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -1847,11 +1847,9 @@ func TestCDDebitBalanceSubjectWithFallback(t *testing.T) { } } func TestCallDescriptorUpdateFromCGREvent(t *testing.T) { - context := "*rating" cgrEv := &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Generated", - Context: &context, + Tenant: "cgrates.org", + ID: "Generated", Event: map[string]interface{}{ "Account": "acc1", "AnswerTime": time.Date(2015, 3, 23, 6, 0, 0, 0, time.UTC), @@ -1891,9 +1889,8 @@ func TestCallDescriptorUpdateFromCGREvent(t *testing.T) { } } cgrEv = &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Generated", - Context: &context, + Tenant: "cgrates.org", + ID: "Generated", Event: map[string]interface{}{ "Account": "acc1", "AnswerTime": time.Date(2015, 3, 23, 6, 0, 0, 0, time.UTC), @@ -1926,10 +1923,8 @@ func TestCallDescriptorAsCGREvent(t *testing.T) { TimeEnd: time.Date(2015, 3, 23, 6, 30, 0, 0, time.UTC), MaxCostSoFar: 0, } - context := "*rating" eCGREvent := &utils.CGREvent{Tenant: "cgrates.org", - ID: "Generated", - Context: &context, + ID: "Generated", Event: map[string]interface{}{ "Account": "max", "AnswerTime": time.Date(2015, 3, 23, 6, 0, 0, 0, time.UTC), diff --git a/engine/chargers.go b/engine/chargers.go index 25f600986..559c0bed7 100644 --- a/engine/chargers.go +++ b/engine/chargers.go @@ -127,12 +127,11 @@ func (cS *ChargerService) processEvent(cgrEv *utils.CGREvent) (rply []*ChrgSProc if cS.attrS == nil { return nil, errors.New("no connection to AttributeS") } - if clonedEv.Context == nil { - clonedEv.Context = utils.StringPointer(utils.MetaChargers) - } + var evReply AttrSProcessEventReply if err = cS.attrS.Call(utils.AttributeSv1ProcessEvent, - &AttrArgsProcessEvent{cP.AttributeIDs, nil, *clonedEv}, + &AttrArgsProcessEvent{cP.AttributeIDs, + utils.StringPointer(utils.MetaChargers), nil, *clonedEv}, &evReply); err != nil { return nil, err } diff --git a/engine/chargers_test.go b/engine/chargers_test.go index 50280e22b..ac990a4c6 100755 --- a/engine/chargers_test.go +++ b/engine/chargers_test.go @@ -66,9 +66,8 @@ var ( } chargerEvents = []*utils.CGREvent{ { - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Charger": "ChargerProfile1", utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC), @@ -77,18 +76,16 @@ var ( }, }, { - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Charger": "ChargerProfile2", utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC), }, }, { - Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, - ID: utils.GenUUID(), - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, + ID: utils.GenUUID(), Event: map[string]interface{}{ "Charger": "DistinctMatch", utils.AnswerTime: time.Date(2014, 7, 14, 14, 30, 0, 0, time.UTC), diff --git a/engine/suppliers.go b/engine/suppliers.go index 530e0dcb7..1396d2933 100644 --- a/engine/suppliers.go +++ b/engine/suppliers.go @@ -456,10 +456,8 @@ func (spS *SupplierService) V1GetSuppliers(args *ArgsGetSuppliers, reply *Sorted return utils.NewErrMandatoryIeMissing("Event") } if spS.attributeS != nil { - if args.CGREvent.Context == nil { // populate if not already in - args.CGREvent.Context = utils.StringPointer(utils.MetaSuppliers) - } attrArgs := &AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSuppliers), CGREvent: args.CGREvent, } var rplyEv AttrSProcessEventReply diff --git a/sessions/sessions.go b/sessions/sessions.go index eedc25d63..1905e5eda 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1584,10 +1584,8 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.RpcClientConnection, if sS.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) } - if args.CGREvent.Context == nil { // populate if not already in - args.CGREvent.Context = utils.StringPointer(utils.MetaSessionS) - } attrArgs := &engine.AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: args.CGREvent, } var rplyEv engine.AttrSProcessEventReply @@ -1816,10 +1814,8 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection, if sS.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) } - if args.CGREvent.Context == nil { // populate if not already in - args.CGREvent.Context = utils.StringPointer(utils.MetaSessionS) - } attrArgs := &engine.AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: args.CGREvent, } var rplyEv engine.AttrSProcessEventReply @@ -2018,10 +2014,8 @@ func (sS *SessionS) BiRPCv1UpdateSession(clnt rpcclient.RpcClientConnection, if sS.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) } - if args.CGREvent.Context == nil { // populate if not already in - args.CGREvent.Context = utils.StringPointer(utils.MetaSessionS) - } attrArgs := &engine.AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: args.CGREvent, } var rplyEv engine.AttrSProcessEventReply @@ -2290,10 +2284,8 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.RpcClientConnection, if sS.attrS == nil { return utils.NewErrNotConnected(utils.AttributeS) } - if args.CGREvent.Context == nil { // populate if not already in - args.CGREvent.Context = utils.StringPointer(utils.MetaSessionS) - } attrArgs := &engine.AttrArgsProcessEvent{ + Context: utils.StringPointer(utils.MetaSessionS), CGREvent: args.CGREvent, } var rplyEv engine.AttrSProcessEventReply diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index 07e99de88..9bfa2b067 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -32,9 +32,8 @@ var attrs = &engine.AttrSProcessEventReply{ MatchedProfiles: []string{"ATTR_ACNT_1001"}, AlteredFields: []string{"OfficeGroup"}, CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "TestSSv1ItAuth", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "TestSSv1ItAuth", Event: map[string]interface{}{ utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9", utils.Tenant: "cgrates.org", @@ -736,9 +735,8 @@ func TestSessionSRegisterAndUnregisterPSessions(t *testing.T) { func TestSessionSNewV1AuthorizeArgs(t *testing.T) { cgrEv := utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Event", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "Event", Event: map[string]interface{}{ utils.Account: "1001", utils.Destination: "1002", @@ -772,9 +770,8 @@ func TestSessionSNewV1AuthorizeArgs(t *testing.T) { func TestSessionSNewV1UpdateSessionArgs(t *testing.T) { cgrEv := utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Event", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "Event", Event: map[string]interface{}{ utils.Account: "1001", utils.Destination: "1002", @@ -802,9 +799,8 @@ func TestSessionSNewV1UpdateSessionArgs(t *testing.T) { func TestSessionSNewV1TerminateSessionArgs(t *testing.T) { cgrEv := utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Event", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "Event", Event: map[string]interface{}{ utils.Account: "1001", utils.Destination: "1002", @@ -830,9 +826,8 @@ func TestSessionSNewV1TerminateSessionArgs(t *testing.T) { func TestSessionSNewV1ProcessEventArgs(t *testing.T) { cgrEv := utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Event", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "Event", Event: map[string]interface{}{ utils.Account: "1001", utils.Destination: "1002", @@ -861,9 +856,8 @@ func TestSessionSNewV1ProcessEventArgs(t *testing.T) { func TestSessionSNewV1InitSessionArgs(t *testing.T) { cgrEv := utils.CGREvent{ - Tenant: "cgrates.org", - ID: "Event", - Context: utils.StringPointer(utils.MetaSessionS), + Tenant: "cgrates.org", + ID: "Event", Event: map[string]interface{}{ utils.Account: "1001", utils.Destination: "1002", diff --git a/utils/cgrevent.go b/utils/cgrevent.go index 1c2aecb12..9ed095bb2 100644 --- a/utils/cgrevent.go +++ b/utils/cgrevent.go @@ -27,11 +27,10 @@ import ( // CGREvent is a generic event processed by CGR services type CGREvent struct { - Tenant string - ID string - Context *string // attach the event to a context - Time *time.Time // event time - Event map[string]interface{} + Tenant string + ID string + Time *time.Time // event time + Event map[string]interface{} } func (ev *CGREvent) HasField(fldName string) (has bool) { @@ -154,9 +153,6 @@ func (ev *CGREvent) Clone() (clned *CGREvent) { ID: ev.ID, Event: make(map[string]interface{}), // a bit forced but safe } - if ev.Context != nil { - clned.Context = StringPointer(*ev.Context) - } if ev.Time != nil { clned.Time = TimePointer(*ev.Time) } diff --git a/utils/cgrevent_test.go b/utils/cgrevent_test.go index 27ffc69f4..41f5ea832 100644 --- a/utils/cgrevent_test.go +++ b/utils/cgrevent_test.go @@ -163,13 +163,11 @@ func TestCGREventFieldAsFloat64(t *testing.T) { } } func TestCGREventClone(t *testing.T) { - contest := "cntxt" now := time.Now() ev := &CGREvent{ - Tenant: "cgrates.org", - ID: "supplierEvent1", - Context: &contest, - Time: &now, + Tenant: "cgrates.org", + ID: "supplierEvent1", + Time: &now, Event: map[string]interface{}{ AnswerTime: time.Now(), "supplierprofile1": "Supplier", @@ -182,9 +180,6 @@ func TestCGREventClone(t *testing.T) { if !reflect.DeepEqual(ev, cloned) { t.Errorf("Expecting: %+v, received: %+v", ev, cloned) } - if cloned.Context == ev.Context { - t.Errorf("Expecting: different pointer but received: %+v", cloned.Context) - } if cloned.Time == ev.Time { t.Errorf("Expecting: different pointer but received: %+v", cloned.Time) }