From 6fa2778d52de12067e87d8f986885569c85315e9 Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Sun, 17 Dec 2017 03:31:20 +0200 Subject: [PATCH] Fixed failing integration test --- apier/v1/resourcesv1_it_test.go | 200 +++++++++++++++++++++-------- engine/resources.go | 38 ++---- integration_test.sh | 5 +- sessionmanager/fssessionmanager.go | 20 +-- sessionmanager/kamailiosm.go | 28 ++-- utils/apitpdata.go | 4 +- 6 files changed, 194 insertions(+), 101 deletions(-) diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 18ce1d7a4..61b91a639 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -132,14 +132,17 @@ func testV1RsFromFolder(t *testing.T) { func testV1RsGetResourcesForEvent(t *testing.T) { var reply *[]*engine.ResourceProfile - args := &utils.ArgRSv1ResourceUsage{} - args.CGREvent.Tenant="cgrates.org" - args.CGREvent.Event=map[string]interface{}{"Unknown": "unknown" } + args := &utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{"Unknown": "unknown"}, + }, + } if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } time.Sleep(time.Duration(500) * time.Millisecond) - args.Event = map[string]interface{}{"Destination": "10"} + args.CGREvent.Event = map[string]interface{}{"Destination": "10"} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } @@ -151,12 +154,12 @@ func testV1RsGetResourcesForEvent(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", "ResGroup2", (*reply)[0].ID) } - args.Event = map[string]interface{}{"Destination": "20"} + args.CGREvent.Event = map[string]interface{}{"Destination": "20"} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - args.Event = map[string]interface{}{"Account": "1002", "Subject": "test", "Destination": "1002"} + args.CGREvent.Event = map[string]interface{}{"Account": "1002", "Subject": "test", "Destination": "1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } @@ -164,7 +167,7 @@ func testV1RsGetResourcesForEvent(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", 2, len(*reply)) } - args.Event = map[string]interface{}{"Account": "1002", "Subject": "test", "Destination": "1001"} + args.CGREvent.Event = map[string]interface{}{"Account": "1002", "Subject": "test", "Destination": "1001"} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } @@ -179,41 +182,58 @@ func testV1RsGetResourcesForEvent(t *testing.T) { func testV1RsTTL0(t *testing.T) { // only matching Resource3 argsRU := utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "3001", + "Destination": "3002"}, + }, UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e21", - Units: 1, + Units: 1, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account": "3001","Destination": "3002"} var reply string if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { t.Error(err) } // second allocation should be also allowed argsRU = utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "3001", + "Destination": "3002"}, + }, UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e21", - Units: 1, + Units: 1, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account": "3001","Destination": "3002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { t.Error(err) } // too many units should be rejected argsRU = utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "3001", + "Destination": "3002"}, + }, UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e22", - Units: 2, + Units: 2, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account": "3001","Destination": "3002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err == nil || err.Error() != utils.ErrResourceUnavailable.Error() { t.Error(err) } // make sure no usage was recorded var rs *engine.Resources - args := &utils.ArgRSv1ResourceUsage{} - args.CGREvent.Tenant="cgrates.org" - args.CGREvent.Event=map[string]interface{}{"Account": "3001","Destination": "3002"} + args := &utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "3001", + "Destination": "3002"}, + }, + } if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 1 { @@ -228,9 +248,13 @@ func testV1RsTTL0(t *testing.T) { var releaseReply string argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e25", // same ID should be accepted by first group since the previous resource should be expired + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "3001", + "Destination": "3002"}, + }, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account": "3001","Destination": "3002"} if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResource, argsRU, &releaseReply); err != nil { t.Error(err) } @@ -241,10 +265,15 @@ func testV1RsAllocateResource(t *testing.T) { var reply string argsRU := utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e51", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 3, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { t.Error(err) } @@ -255,10 +284,15 @@ func testV1RsAllocateResource(t *testing.T) { // Second event to test matching of exact limit of first resource argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e52", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 4, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { t.Error(err) } @@ -269,10 +303,15 @@ func testV1RsAllocateResource(t *testing.T) { // Third event testing overflow to second resource which still has one resource available argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e53", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "dan", + "Subject": "dan", + "Destination": "1002"}, + }, Units: 1, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"dan","Subject":"dan","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { t.Error(err) } @@ -283,10 +322,14 @@ func testV1RsAllocateResource(t *testing.T) { // Test resource unavailable argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e54", // same ID should be accepted by first group since the previous resource should be expired - Units: 1, + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 1, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err == nil || err.Error() != utils.ErrResourceUnavailable.Error() { t.Error(err) } @@ -295,10 +338,15 @@ func testV1RsAllocateResource(t *testing.T) { argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 1, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { t.Error(err) } @@ -312,11 +360,15 @@ func testV1RsAllowUsage(t *testing.T) { var allowed bool argsRU := utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 6, } - - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllowUsage, argsRU, &allowed); err != nil { t.Error(err) } else if !allowed { // already 3 usages active before allow call, we should have now more than allowed @@ -324,10 +376,16 @@ func testV1RsAllowUsage(t *testing.T) { } argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, + Units: 7, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1AllowUsage, argsRU, &allowed); err != nil { t.Error(err) } else if allowed { // already 3 usages active before allow call, we should have now more than allowed @@ -340,9 +398,14 @@ func testV1RsReleaseResource(t *testing.T) { var reply string argsRU := utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResource, argsRU, &reply); err != nil { t.Error(err) } @@ -350,10 +413,15 @@ func testV1RsReleaseResource(t *testing.T) { // only match Resource1 since we don't want for storing of the resource2 bellow argsRU = utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 7, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} var allowed bool if err := rlsV1Rpc.Call(utils.ResourceSv1AllowUsage, argsRU, &allowed); err != nil { t.Error(err) @@ -361,9 +429,14 @@ func testV1RsReleaseResource(t *testing.T) { t.Error("resource should be allowed") } var rs *engine.Resources - args := &utils.ArgRSv1ResourceUsage{} - args.CGREvent.Tenant="cgrates.org" - args.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} + args := &utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 2 { @@ -381,10 +454,15 @@ func testV1RsReleaseResource(t *testing.T) { func testV1RsDBStore(t *testing.T) { argsRU := utils.ArgRSv1ResourceUsage{ UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e71", + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }, Units: 1, } - argsRU.CGREvent.Tenant="cgrates.org" - argsRU.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} var reply string eAllocationMsg := "ResGroup1" if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResource, argsRU, &reply); err != nil { @@ -393,9 +471,14 @@ func testV1RsDBStore(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply) } var rs *engine.Resources - args := &utils.ArgRSv1ResourceUsage{} - args.CGREvent.Tenant="cgrates.org" - args.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} + args := &utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 2 { @@ -423,10 +506,14 @@ func testV1RsDBStore(t *testing.T) { t.Fatal("Could not connect to rater: ", err.Error()) } rs = new(engine.Resources) - args = &utils.ArgRSv1ResourceUsage{} - args.CGREvent.Tenant="cgrates.org" - args.CGREvent.Event=map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"} - + args = &utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + "Account": "1002", + "Subject": "1001", + "Destination": "1002"}, + }} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 2 { @@ -535,3 +622,10 @@ func testV1RsStopEngine(t *testing.T) { t.Error(err) } } + +// args = &utils.ArgRSv1ResourceUsage{ +// CGREvent:utils.CGREvent{ +// Tenant:"cgrates.org", +// Event:map[string]interface{}{"Account":"1002","Subject":"1001","Destination":"1002"}, +// }, +// } diff --git a/engine/resources.go b/engine/resources.go index a7cc1196a..fa51c4458 100755 --- a/engine/resources.go +++ b/engine/resources.go @@ -512,18 +512,16 @@ func (rS *ResourceService) processThresholds(r *Resource) (err error) { func (rS *ResourceService) V1ResourcesForEvent(args utils.ArgRSv1ResourceUsage, reply *Resources) (err error) { if args.CGREvent.Tenant == "" { return utils.NewErrMandatoryIeMissing("Tenant") - } else if args.UsageID == "" { - return utils.NewErrMandatoryIeMissing("UsageID") } var mtcRLs Resources if args.UsageID != "" { // only cached if UsageID is present - mtcRLs = rS.cachedResourcesForEvent(args.CGREvent.TenantID()) + mtcRLs = rS.cachedResourcesForEvent(args.TenantID()) } if mtcRLs == nil { if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil { return err } - cache.Set(utils.EventResourcesPrefix+args.CGREvent.TenantID(), mtcRLs.tenantIDs(), true, "") + cache.Set(utils.EventResourcesPrefix+args.TenantID(), mtcRLs.tenantIDs(), true, "") } if len(mtcRLs) == 0 { return utils.ErrNotFound @@ -532,25 +530,21 @@ func (rS *ResourceService) V1ResourcesForEvent(args utils.ArgRSv1ResourceUsage, return } -//cgrevent tenant +id si la args USAGEID - // V1AllowUsage queries service to find if an Usage is allowed func (rS *ResourceService) V1AllowUsage(args utils.ArgRSv1ResourceUsage, allow *bool) (err error) { - if args.CGREvent.Tenant == "" { - return utils.NewErrMandatoryIeMissing("Tenant") - } else if args.UsageID == "" { - return utils.NewErrMandatoryIeMissing("UsageID") + if missing := utils.MissingStructFields(&args, []string{"CGREvent.Tenant", "UsageID"}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) } mtcRLs := rS.cachedResourcesForEvent(args.TenantID()) if mtcRLs == nil { - if mtcRLs, err = rS.matchingResourcesForEvent(args.Tenant, args.Event); err != nil { + if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil { return err } cache.Set(utils.EventResourcesPrefix+args.TenantID(), mtcRLs.tenantIDs(), true, "") } if _, err = mtcRLs.allocateResource( &ResourceUsage{ - Tenant: args.Tenant, + Tenant: args.CGREvent.Tenant, ID: args.UsageID, Units: args.Units}, true); err != nil { if err == utils.ErrResourceUnavailable { @@ -566,22 +560,20 @@ func (rS *ResourceService) V1AllowUsage(args utils.ArgRSv1ResourceUsage, allow * // V1AllocateResource is called when a resource requires allocation func (rS *ResourceService) V1AllocateResource(args utils.ArgRSv1ResourceUsage, reply *string) (err error) { - if args.CGREvent.Tenant == "" { - return utils.NewErrMandatoryIeMissing("Tenant") - } else if args.UsageID == "" { - return utils.NewErrMandatoryIeMissing("UsageID") + if missing := utils.MissingStructFields(&args, []string{"CGREvent.Tenant", "UsageID"}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) } var wasCached bool mtcRLs := rS.cachedResourcesForEvent(args.UsageID) if mtcRLs == nil { - if mtcRLs, err = rS.matchingResourcesForEvent(args.Tenant, args.Event); err != nil { + if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil { return } } else { wasCached = true } alcMsg, err := mtcRLs.allocateResource( - &ResourceUsage{Tenant: args.Tenant, ID: args.UsageID, Units: args.Units}, false) + &ResourceUsage{Tenant: args.CGREvent.Tenant, ID: args.UsageID, Units: args.Units}, false) if err != nil { return err } @@ -621,14 +613,12 @@ func (rS *ResourceService) V1AllocateResource(args utils.ArgRSv1ResourceUsage, r // V1ReleaseResource is called when we need to clear an allocation func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, reply *string) (err error) { - if args.CGREvent.Tenant == "" { - return utils.NewErrMandatoryIeMissing("Tenant") - } else if args.UsageID == "" { - return utils.NewErrMandatoryIeMissing("UsageID") + if missing := utils.MissingStructFields(&args, []string{"CGREvent.Tenant", "UsageID"}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) } mtcRLs := rS.cachedResourcesForEvent(args.UsageID) if mtcRLs == nil { - if mtcRLs, err = rS.matchingResourcesForEvent(args.Tenant, args.Event); err != nil { + if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil { return } } @@ -655,4 +645,4 @@ func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, re } *reply = utils.OK return nil -} +} \ No newline at end of file diff --git a/integration_test.sh b/integration_test.sh index 8e93c0301..218a83121 100755 --- a/integration_test.sh +++ b/integration_test.sh @@ -28,5 +28,8 @@ agts=$? echo 'go test github.com/cgrates/cgrates/sessionmanager -tags=integration' go test github.com/cgrates/cgrates/sessionmanager -tags=integration smg=$? +echo 'go test github.com/cgrates/cgrates/migrator -tags=integration' +go test github.com/cgrates/cgrates/migrator -tags=integration +mgr=$? -exit $gen && $ap1 && $ap2 && $en && $cdrc && $cfg && $utl && $gnr && $agts && $smg +exit $gen && $ap1 && $ap2 && $en && $cdrc && $cfg && $utl && $gnr && $agts && $smg && $mgr diff --git a/sessionmanager/fssessionmanager.go b/sessionmanager/fssessionmanager.go index 7cc339eec..29b03ec50 100644 --- a/sessionmanager/fssessionmanager.go +++ b/sessionmanager/fssessionmanager.go @@ -214,12 +214,13 @@ func (sm *FSSessionManager) onChannelPark(ev engine.Event, connId string) { if sm.rls != nil { var reply string attrRU := utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: ev.(FSEvent).GetTenant(utils.META_DEFAULT), + Event: ev.(FSEvent).AsMapStringInterface(sm.timezone), + }, UsageID: ev.GetUUID(), Units: 1, } - attrRU.CGREvent.ID=utils.UUIDSha1Prefix() - attrRU.CGREvent.Tenant=ev.(FSEvent).GetTenant(utils.META_DEFAULT) - attrRU.CGREvent.Event=ev.(FSEvent).AsMapStringInterface(sm.timezone) if err := sm.rls.Call(utils.ResourceSv1AllocateResource, attrRU, &reply); err != nil { if err.Error() == utils.ErrResourceUnavailable.Error() { sm.unparkCall(ev.GetUUID(), connId, ev.GetCallDestNr(utils.META_DEFAULT), "-"+utils.ErrResourceUnavailable.Error()) @@ -281,12 +282,13 @@ func (sm *FSSessionManager) onChannelHangupComplete(ev engine.Event) { } var reply string attrRU := utils.ArgRSv1ResourceUsage{ - UsageID: ev.GetUUID(), - Units: 1, - } - attrRU.CGREvent.ID=utils.UUIDSha1Prefix() - attrRU.CGREvent.Tenant=ev.(FSEvent).GetTenant(utils.META_DEFAULT) - attrRU.CGREvent.Event=ev.(FSEvent).AsMapStringInterface(sm.timezone) + CGREvent: utils.CGREvent{ + Tenant: ev.(FSEvent).GetTenant(utils.META_DEFAULT), + Event: ev.(FSEvent).AsMapStringInterface(sm.timezone), + }, + UsageID: ev.GetUUID(), + Units: 1, + } if sm.rls != nil { if err := sm.rls.Call(utils.ResourceSv1ReleaseResource, attrRU, &reply); err != nil { utils.Logger.Err(fmt.Sprintf(" RLs API error: %s", err.Error())) diff --git a/sessionmanager/kamailiosm.go b/sessionmanager/kamailiosm.go index a5fb40237..f3230d8d4 100644 --- a/sessionmanager/kamailiosm.go +++ b/sessionmanager/kamailiosm.go @@ -81,12 +81,13 @@ func (self *KamailioSessionManager) allocateResources(kev KamEvent) (err error) return } attrRU := utils.ArgRSv1ResourceUsage{ - UsageID: kev.GetUUID(), - Units: 1, - } - attrRU.CGREvent.ID=utils.UUIDSha1Prefix() - attrRU.CGREvent.Tenant=kev.GetTenant(utils.META_DEFAULT) - attrRU.CGREvent.Event=ev + CGREvent: utils.CGREvent{ + Tenant: kev.GetTenant(utils.META_DEFAULT), + Event: ev, + }, + UsageID: kev.GetUUID(), + Units: 1, // One channel reserved + } var reply string return self.rlS.Call(utils.ResourceSv1AllocateResource, attrRU, &reply) } @@ -215,13 +216,14 @@ func (self *KamailioSessionManager) onCallEnd(evData []byte, connId string) { return } var reply string - attrRU := utils.ArgRSv1ResourceUsage{ - UsageID: kev.GetUUID(), - Units: 1, - } - attrRU.CGREvent.ID=utils.UUIDSha1Prefix() - attrRU.CGREvent.Tenant=kev.GetTenant(utils.META_DEFAULT) - attrRU.CGREvent.Event=ev + attrRU := utils.ArgRSv1ResourceUsage{ + CGREvent: utils.CGREvent{ + Tenant: kev.GetTenant(utils.META_DEFAULT), + Event: ev, + }, + UsageID: kev.GetUUID(), + Units: 1, + } if err := self.rlS.Call(utils.ResourceSv1ReleaseResource, attrRU, &reply); err != nil { utils.Logger.Err(fmt.Sprintf(" RLs API error: %s", err.Error())) } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index b059b4c41..a1f9ceb4d 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -1277,13 +1277,15 @@ type AttrRLsCache struct { } type ArgRSv1ResourceUsage struct { + // Tenant string + // Event map[string]interface{} CGREvent UsageID string // ResourceUsage Identifier Units float64 } func (args *ArgRSv1ResourceUsage) TenantID() string { - return ConcatenatedKey(args.Tenant, args.UsageID) + return ConcatenatedKey(args.CGREvent.Tenant, args.UsageID) } // AsActivationTime converts TPActivationInterval into ActivationInterval