From 75fe09e4dc69ce55a4f1af638690679f4dc1fbdc Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 31 Oct 2017 12:53:27 +0200 Subject: [PATCH 1/4] Update integration_tests --- agents/dmtagent_it_test.go | 30 +- apier/v1/apier_it_test.go | 2 +- apier/v1/cdrstatsv1_it_test.go | 8 +- apier/v2/cdrs_it_test.go | 12 +- data/storage/mysql/create_cdrs_tables.sql | 8 +- data/storage/postgres/create_cdrs_tables.sql | 11 +- engine/cdr.go | 4 +- engine/cdr_it_test.go | 2 +- engine/models.go | 2 +- engine/storage_cdrs_it_test.go | 482 +++++++++---------- engine/storage_sql.go | 2 +- engine/stordb_it_test.go | 15 - general_tests/cdrs_onlexp_it_test.go | 5 +- general_tests/tutorial_it_test.go | 88 ++-- 14 files changed, 297 insertions(+), 374 deletions(-) diff --git a/agents/dmtagent_it_test.go b/agents/dmtagent_it_test.go index 23515985c..a38257282 100644 --- a/agents/dmtagent_it_test.go +++ b/agents/dmtagent_it_test.go @@ -229,10 +229,10 @@ func TestDmtAgentConnectDiameterClient(t *testing.T) { // cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2015-11-07T08:42:26Z" TimeEnd="2015-11-07T08:47:26Z"' func TestDmtAgentSendCCRInit(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testccr1", time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, - OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out", - Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", Supplier: "SUPPL1", + OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", SetupTime: time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2015, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, - Usage: time.Duration(0), PDD: time.Duration(7) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + Usage: time.Duration(0), ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, } ccr := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId, daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, daCfg.DiameterAgentCfg().DebitInterval, false) @@ -270,10 +270,10 @@ func TestDmtAgentSendCCRInit(t *testing.T) { // cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2015-11-07T08:42:26Z" TimeEnd="2015-11-07T08:52:26Z"' func TestDmtAgentSendCCRUpdate(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testccr1", time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, - OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out", - Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", Supplier: "SUPPL1", + OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", SetupTime: time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2015, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, - Usage: time.Duration(300) * time.Second, PDD: time.Duration(7) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + Usage: time.Duration(300) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, } ccr := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId, daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, daCfg.DiameterAgentCfg().DebitInterval, false) @@ -306,10 +306,10 @@ func TestDmtAgentSendCCRUpdate(t *testing.T) { // cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2015-11-07T08:42:26Z" TimeEnd="2015-11-07T08:57:26Z"' func TestDmtAgentSendCCRUpdate2(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testccr1", time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, - OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out", - Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", Supplier: "SUPPL1", + OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", SetupTime: time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2015, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, - Usage: time.Duration(600) * time.Second, PDD: time.Duration(7) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + Usage: time.Duration(600) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, } ccr := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId, daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, daCfg.DiameterAgentCfg().DebitInterval, false) @@ -341,10 +341,10 @@ func TestDmtAgentSendCCRUpdate2(t *testing.T) { func TestDmtAgentSendCCRTerminate(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testccr1", time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, - OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out", - Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", Supplier: "SUPPL1", + OriginID: "testccr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1004", SetupTime: time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2015, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, - Usage: time.Duration(610) * time.Second, PDD: time.Duration(7) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + Usage: time.Duration(610) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, } ccr := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId, daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, daCfg.DiameterAgentCfg().DebitInterval, true) @@ -535,10 +535,10 @@ func TestDmtAgentSendCCRSMSWrongAccount(t *testing.T) { // cgr-console 'cost Category="call" Tenant="cgrates.org" Subject="1001" Destination="1004" TimeStart="2015-11-07T08:42:26Z" TimeEnd="2015-11-07T08:47:26Z"' func TestDmtAgentSendCCRInitWrongAccount(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testccr4", time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, - OriginID: "testccr4", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out", - Tenant: "cgrates.org", Category: "call", Account: "non_existent", Subject: "non_existent", Destination: "1004", Supplier: "SUPPL1", + OriginID: "testccr4", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "non_existent", Subject: "non_existent", Destination: "1004", SetupTime: time.Date(2015, 11, 7, 8, 42, 20, 0, time.UTC), AnswerTime: time.Date(2015, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, - Usage: time.Duration(0) * time.Second, PDD: time.Duration(7) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + Usage: time.Duration(0) * time.Second, ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, } ccr := storedCdrToCCR(cdr, "UNIT_TEST", daCfg.DiameterAgentCfg().OriginRealm, daCfg.DiameterAgentCfg().VendorId, daCfg.DiameterAgentCfg().ProductName, utils.DIAMETER_FIRMWARE_REVISION, daCfg.DiameterAgentCfg().DebitInterval, false) diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index a492833af..c33445a81 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -1384,7 +1384,7 @@ func TestApierITGetCdrs(t *testing.T) { func TestApierITProcessCdr(t *testing.T) { var reply string cdr := engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", Source: "test", RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", + OriginHost: "192.168.1.1", Source: "test", RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, diff --git a/apier/v1/cdrstatsv1_it_test.go b/apier/v1/cdrstatsv1_it_test.go index 322087d27..929511d23 100644 --- a/apier/v1/cdrstatsv1_it_test.go +++ b/apier/v1/cdrstatsv1_it_test.go @@ -98,28 +98,28 @@ func TestCDRStatsitPostCdrs(t *testing.T) { storedCdrs := []*engine.CDR{ &engine.CDR{CGRID: utils.Sha1("dsafdsafa", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsafa", OriginHost: "192.168.1.1", Source: "test", - RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", + RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Now(), AnswerTime: time.Now(), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, }, &engine.CDR{CGRID: utils.Sha1("dsafdsafb", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsafb", OriginHost: "192.168.1.1", Source: "test", - RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", + RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Now(), AnswerTime: time.Now(), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(5) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, }, &engine.CDR{CGRID: utils.Sha1("dsafdsafc", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsafc", OriginHost: "192.168.1.1", Source: "test", - RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", + RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Now(), AnswerTime: time.Now(), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(30) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, }, &engine.CDR{CGRID: utils.Sha1("dsafdsafd", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsafd", OriginHost: "192.168.1.1", Source: "test", - RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", + RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Now(), AnswerTime: time.Time{}, RunID: utils.DEFAULT_RUNID, Usage: time.Duration(0) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, diff --git a/apier/v2/cdrs_it_test.go b/apier/v2/cdrs_it_test.go index 3f604cebb..a75fcece9 100644 --- a/apier/v2/cdrs_it_test.go +++ b/apier/v2/cdrs_it_test.go @@ -117,7 +117,7 @@ func testV2CDRsInjectUnratedCdr(t *testing.T) { } strCdr1 := &engine.CDR{CGRID: utils.Sha1("bbb1", time.Date(2015, 11, 21, 10, 47, 24, 0, time.UTC).String()), RunID: utils.MetaRaw, ToR: utils.VOICE, OriginID: "bbb1", OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoInjectUnratedCdr", RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2015, 11, 21, 10, 47, 24, 0, time.UTC), AnswerTime: time.Date(2015, 11, 21, 10, 47, 26, 0, time.UTC), Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: -1} @@ -144,7 +144,7 @@ func testV2CDRsProcessCdrRated(t *testing.T) { cdr := &engine.CDR{ CGRID: utils.Sha1("dsafdsaf", time.Date(2015, 12, 13, 18, 15, 26, 0, time.UTC).String()), RunID: utils.DEFAULT_RUNID, OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessCdrRated", RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", Category: "call", + OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessCdrRated", RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2015, 12, 13, 18, 15, 26, 0, time.UTC), AnswerTime: time.Date(2015, 12, 13, 18, 15, 26, 0, time.UTC), Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, @@ -162,7 +162,7 @@ func testV2CDRsProcessCdrRaw(t *testing.T) { cdr := &engine.CDR{ CGRID: utils.Sha1("abcdeftg", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, RunID: utils.MetaRaw, ToR: utils.VOICE, OriginID: "abcdeftg", - OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessCdrRaw", RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", Category: "call", + OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessCdrRaw", RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "1002", Subject: "1002", Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, @@ -229,19 +229,19 @@ func testV2CDRsProcessPrepaidCdr(t *testing.T) { var reply string cdrs := []*engine.CDR{ &engine.CDR{CGRID: utils.Sha1("dsafdsaf2", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessPrepaidCdr1", RequestType: utils.META_PREPAID, Direction: "*out", Tenant: "cgrates.org", + OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessPrepaidCdr1", RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, Rated: true, }, &engine.CDR{CGRID: utils.Sha1("abcdeftg2", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessPrepaidCdr2", RequestType: utils.META_PREPAID, Direction: "*out", Tenant: "cgrates.org", + OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessPrepaidCdr2", RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call", Account: "1002", Subject: "1002", Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, }, &engine.CDR{CGRID: utils.Sha1("aererfddf2", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsaf", - OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessPrepaidCdr3", RequestType: utils.META_PREPAID, Direction: "*out", Tenant: "cgrates.org", + OriginHost: "192.168.1.1", Source: "TestV2CdrsMongoProcessPrepaidCdr3", RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.DEFAULT_RUNID, Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, diff --git a/data/storage/mysql/create_cdrs_tables.sql b/data/storage/mysql/create_cdrs_tables.sql index 4423044ec..5f0b2b673 100644 --- a/data/storage/mysql/create_cdrs_tables.sql +++ b/data/storage/mysql/create_cdrs_tables.sql @@ -5,7 +5,7 @@ DROP TABLE IF EXISTS cdrs; CREATE TABLE cdrs ( id int(11) NOT NULL AUTO_INCREMENT, - cgrid char(40) NOT NULL, + `cgrid` varchar(40) NOT NULL, run_id varchar(64) NOT NULL, origin_host varchar(64) NOT NULL, source varchar(64) NOT NULL, @@ -29,13 +29,13 @@ CREATE TABLE cdrs ( updated_at TIMESTAMP NULL, deleted_at TIMESTAMP NULL, PRIMARY KEY (id), - UNIQUE KEY cdrrun (cgrid, run_id, origin_id) + UNIQUE KEY cdrrun (`cgrid`, run_id, origin_id) ); DROP TABLE IF EXISTS sm_costs; CREATE TABLE sm_costs ( id int(11) NOT NULL AUTO_INCREMENT, - cgrid char(40) NOT NULL, + `cgrid` varchar(40) NOT NULL, run_id varchar(64) NOT NULL, origin_host varchar(64) NOT NULL, origin_id varchar(64) NOT NULL, @@ -45,7 +45,7 @@ CREATE TABLE sm_costs ( created_at TIMESTAMP NULL, deleted_at TIMESTAMP NULL, PRIMARY KEY (`id`), - UNIQUE KEY costid (cgrid, run_id), + UNIQUE KEY costid (`cgrid`, run_id), KEY origin_idx (origin_host, origin_id), KEY run_origin_idx (run_id, origin_id), KEY deleted_at_idx (deleted_at) diff --git a/data/storage/postgres/create_cdrs_tables.sql b/data/storage/postgres/create_cdrs_tables.sql index 9b5c9c4fe..d144f9890 100644 --- a/data/storage/postgres/create_cdrs_tables.sql +++ b/data/storage/postgres/create_cdrs_tables.sql @@ -5,7 +5,7 @@ DROP TABLE IF EXISTS cdrs; CREATE TABLE cdrs ( id SERIAL PRIMARY KEY, - cgrid CHAR(40) NOT NULL, + "cgrid" VARCHAR(40) NOT NULL, run_id VARCHAR(64) NOT NULL, origin_host VARCHAR(64) NOT NULL, source VARCHAR(64) NOT NULL, @@ -28,7 +28,7 @@ CREATE TABLE cdrs ( created_at TIMESTAMP WITH TIME ZONE, updated_at TIMESTAMP WITH TIME ZONE NULL, deleted_at TIMESTAMP WITH TIME ZONE NULL, - UNIQUE (cgrid, run_id, origin_id) + UNIQUE ("cgrid", run_id, origin_id) ); ; DROP INDEX IF EXISTS deleted_at_cp_idx; @@ -38,7 +38,7 @@ CREATE INDEX deleted_at_cp_idx ON cdrs (deleted_at); DROP TABLE IF EXISTS sm_costs; CREATE TABLE sm_costs ( id SERIAL PRIMARY KEY, - cgrid CHAR(40) NOT NULL, + "cgrid" VARCHAR(40) NOT NULL, run_id VARCHAR(64) NOT NULL, origin_host VARCHAR(64) NOT NULL, origin_id VARCHAR(64) NOT NULL, @@ -47,14 +47,13 @@ CREATE TABLE sm_costs ( cost_details jsonb, created_at TIMESTAMP WITH TIME ZONE, deleted_at TIMESTAMP WITH TIME ZONE NULL, - UNIQUE (cgrid, run_id) + UNIQUE ("cgrid", run_id) ); DROP INDEX IF EXISTS cgrid_smcost_idx; -CREATE INDEX cgrid_smcost_idx ON sm_costs (cgrid, run_id); +CREATE INDEX cgrid_smcost_idx ON sm_costs ("cgrid", run_id); DROP INDEX IF EXISTS origin_smcost_idx; CREATE INDEX origin_smcost_idx ON sm_costs (origin_host, origin_id); DROP INDEX IF EXISTS run_origin_smcost_idx; CREATE INDEX run_origin_smcost_idx ON sm_costs (run_id, origin_id); DROP INDEX IF EXISTS deleted_at_smcost_idx; CREATE INDEX deleted_at_smcost_idx ON sm_costs (deleted_at); - diff --git a/engine/cdr.go b/engine/cdr.go index d2fbd3a97..241212fe7 100644 --- a/engine/cdr.go +++ b/engine/cdr.go @@ -761,7 +761,7 @@ func (cdr *CDR) AsExportMap(exportFields []*config.CfgCdrField, httpSkipTlsCheck // AsCDRsTBL converts the CDR into the format used for SQL storage func (cdr *CDR) AsCDRsql() (cdrSql *CDRsql) { cdrSql = new(CDRsql) - cdrSql.CGRID = cdr.CGRID + cdrSql.Cgrid = cdr.CGRID cdrSql.RunID = cdr.RunID cdrSql.OriginHost = cdr.OriginHost cdrSql.Source = cdr.Source @@ -788,7 +788,7 @@ func (cdr *CDR) AsCDRsql() (cdrSql *CDRsql) { // NewCDRFromSQL converts the CDRsql into CDR func NewCDRFromSQL(cdrSql *CDRsql) (cdr *CDR, err error) { cdr = new(CDR) - cdr.CGRID = cdrSql.CGRID + cdr.CGRID = cdrSql.Cgrid cdr.RunID = cdrSql.RunID cdr.OriginHost = cdrSql.OriginHost cdr.Source = cdrSql.Source diff --git a/engine/cdr_it_test.go b/engine/cdr_it_test.go index f1989e99b..6975abe7f 100644 --- a/engine/cdr_it_test.go +++ b/engine/cdr_it_test.go @@ -36,7 +36,7 @@ func TestHttpJsonPost(t *testing.T) { cdrOut := &ExternalCDR{CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC).String()), OrderID: 123, ToR: utils.VOICE, OriginID: "dsafdsaf", OriginHost: "192.168.1.1", - Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: "*out", Tenant: "cgrates.org", + Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "account1", Subject: "tgooiscs0014", Destination: "1002", SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC).String(), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String(), RunID: utils.DEFAULT_RUNID, diff --git a/engine/models.go b/engine/models.go index b123d13c0..bab45b5b0 100755 --- a/engine/models.go +++ b/engine/models.go @@ -464,7 +464,7 @@ type TpFilter struct { type CDRsql struct { ID int64 - CGRID string + Cgrid string RunID string OriginHost string Source string diff --git a/engine/storage_cdrs_it_test.go b/engine/storage_cdrs_it_test.go index 4483b8eae..912fdc408 100644 --- a/engine/storage_cdrs_it_test.go +++ b/engine/storage_cdrs_it_test.go @@ -90,28 +90,24 @@ func testSetCDR(cfg *config.CGRConfig) error { return err } rawCDR := &CDR{ - CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), - RunID: utils.MetaRaw, - OrderID: time.Now().UnixNano(), - OriginHost: "127.0.0.1", - Source: "testSetCDRs", - OriginID: "testevent1", - ToR: utils.VOICE, - RequestType: utils.META_PREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Account: "1004", - Subject: "1004", - Destination: "1007", - SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(35) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, - Cost: -1, + CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), + RunID: utils.MetaRaw, + OrderID: time.Now().UnixNano(), + OriginHost: "127.0.0.1", + Source: "testSetCDRs", + OriginID: "testevent1", + ToR: utils.VOICE, + RequestType: utils.META_PREPAID, + Tenant: "cgrates.org", + Category: "call", + Account: "1004", + Subject: "1004", + Destination: "1007", + SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(35) * time.Second, + ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, + Cost: -1, } if err := cdrStorage.SetCDR(rawCDR, false); err != nil { return fmt.Errorf("rawCDR: %+v, SetCDR err: %s", rawCDR, err.Error()) @@ -122,28 +118,24 @@ func testSetCDR(cfg *config.CGRConfig) error { return fmt.Errorf("rawCDR %+v, Unexpected number of CDRs returned: %d", rawCDR, len(cdrs)) } ratedCDR := &CDR{ - CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), - RunID: utils.META_DEFAULT, - OriginHost: "127.0.0.1", - Source: "testSetCDRs", - OriginID: "testevent1", - ToR: utils.VOICE, - RequestType: utils.META_PREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Account: "1004", - Subject: "1004", - Destination: "1007", - SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(35) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, - CostSource: "testSetCDRs", - Cost: 0.17, + CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), + RunID: utils.META_DEFAULT, + OriginHost: "127.0.0.1", + Source: "testSetCDRs", + OriginID: "testevent1", + ToR: utils.VOICE, + RequestType: utils.META_PREPAID, + Tenant: "cgrates.org", + Category: "call", + Account: "1004", + Subject: "1004", + Destination: "1007", + SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(35) * time.Second, + ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, + CostSource: "testSetCDRs", + Cost: 0.17, } if err := cdrStorage.SetCDR(ratedCDR, false); err != nil { return fmt.Errorf("ratedCDR: %+v, SetCDR err: %s", ratedCDR, err.Error()) @@ -253,245 +245,205 @@ func testGetCDRs(cfg *config.CGRConfig) error { } cdrs := []*CDR{ &CDR{ - CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), - RunID: utils.MetaRaw, - OriginHost: "127.0.0.1", - Source: "testGetCDRs", - OriginID: "testevent1", - ToR: utils.VOICE, - RequestType: utils.META_PREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Account: "1001", - Subject: "1001", - Destination: "1002", - SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(35) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, - CostSource: "", - Cost: -1, + CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), + RunID: utils.MetaRaw, + OriginHost: "127.0.0.1", + Source: "testGetCDRs", + OriginID: "testevent1", + ToR: utils.VOICE, + RequestType: utils.META_PREPAID, + Tenant: "cgrates.org", + Category: "call", + Account: "1001", + Subject: "1001", + Destination: "1002", + SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(35) * time.Second, + ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, + CostSource: "", + Cost: -1, }, &CDR{ - CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), - RunID: utils.META_DEFAULT, - OriginHost: "127.0.0.1", - Source: "testGetCDRs", - OriginID: "testevent1", - ToR: utils.VOICE, - RequestType: utils.META_PREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Account: "1001", - Subject: "1001", - Destination: "1002", - SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(35) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, - CostSource: "testGetCDRs", - Cost: 0.17, + CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), + RunID: utils.META_DEFAULT, + OriginHost: "127.0.0.1", + Source: "testGetCDRs", + OriginID: "testevent1", + ToR: utils.VOICE, + RequestType: utils.META_PREPAID, + Tenant: "cgrates.org", + Category: "call", + Account: "1001", + Subject: "1001", + Destination: "1002", + SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(35) * time.Second, + ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, + CostSource: "testGetCDRs", + Cost: 0.17, }, &CDR{ - CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), - RunID: "run2", - OriginHost: "127.0.0.1", - Source: "testGetCDRs", - OriginID: "testevent1", - ToR: utils.VOICE, - RequestType: utils.META_RATED, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call_derived", - Account: "1001", - Subject: "1002", - Destination: "1002", - SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(35) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, - CostSource: "testGetCDRs", - Cost: 0.17, + CGRID: utils.Sha1("testevent1", time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC).String()), + RunID: "run2", + OriginHost: "127.0.0.1", + Source: "testGetCDRs", + OriginID: "testevent1", + ToR: utils.VOICE, + RequestType: utils.META_RATED, + Tenant: "cgrates.org", + Category: "call_derived", + Account: "1001", + Subject: "1002", + Destination: "1002", + SetupTime: time.Date(2015, 12, 12, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(35) * time.Second, + ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, + CostSource: "testGetCDRs", + Cost: 0.17, }, &CDR{ - CGRID: utils.Sha1("testevent2", time.Date(2015, 12, 29, 12, 58, 0, 0, time.UTC).String()), - RunID: utils.META_DEFAULT, - OriginHost: "192.168.1.12", - Source: "testGetCDRs", - OriginID: "testevent2", - ToR: utils.VOICE, - RequestType: utils.META_POSTPAID, - Direction: utils.OUT, - Tenant: "itsyscom.com", - Category: "call", - Account: "1004", - Subject: "1004", - Destination: "1007", - SetupTime: time.Date(2015, 12, 29, 12, 58, 0, 0, time.UTC), - PDD: time.Duration(10) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 29, 12, 59, 0, 0, time.UTC), - Usage: time.Duration(0) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NO_ANSWER", - ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, - CostSource: "rater1", - Cost: 0, + CGRID: utils.Sha1("testevent2", time.Date(2015, 12, 29, 12, 58, 0, 0, time.UTC).String()), + RunID: utils.META_DEFAULT, + OriginHost: "192.168.1.12", + Source: "testGetCDRs", + OriginID: "testevent2", + ToR: utils.VOICE, + RequestType: utils.META_POSTPAID, + Tenant: "itsyscom.com", + Category: "call", + Account: "1004", + Subject: "1004", + Destination: "1007", + SetupTime: time.Date(2015, 12, 29, 12, 58, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 29, 12, 59, 0, 0, time.UTC), + Usage: time.Duration(0) * time.Second, + ExtraFields: map[string]string{"ExtraHeader1": "ExtraVal1", "ExtraHeader2": "ExtraVal2"}, + CostSource: "rater1", + Cost: 0, }, &CDR{ - CGRID: utils.Sha1("testevent3", time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC).String()), - RunID: utils.MetaRaw, - OriginHost: "192.168.1.13", - Source: "testGetCDRs3", - OriginID: "testevent3", - ToR: utils.VOICE, - RequestType: utils.META_PSEUDOPREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Account: "1002", - Subject: "1002", - Destination: "1003", - SetupTime: time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 28, 12, 58, 30, 0, time.UTC), - Usage: time.Duration(125) * time.Second, - Supplier: "SUPPLIER2", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{}, - CostSource: "", - Cost: -1, + CGRID: utils.Sha1("testevent3", time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC).String()), + RunID: utils.MetaRaw, + OriginHost: "192.168.1.13", + Source: "testGetCDRs3", + OriginID: "testevent3", + ToR: utils.VOICE, + RequestType: utils.META_PSEUDOPREPAID, + Tenant: "cgrates.org", + Category: "call", + Account: "1002", + Subject: "1002", + Destination: "1003", + SetupTime: time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 28, 12, 58, 30, 0, time.UTC), + Usage: time.Duration(125) * time.Second, + ExtraFields: map[string]string{}, + CostSource: "", + Cost: -1, }, &CDR{ - CGRID: utils.Sha1("testevent3", time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC).String()), - RunID: utils.META_DEFAULT, - OriginHost: "192.168.1.13", - Source: "testGetCDRs3", - OriginID: "testevent3", - ToR: utils.VOICE, - RequestType: utils.META_RATED, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "call", - Account: "1002", - Subject: "1002", - Destination: "1003", - SetupTime: time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC), - PDD: time.Duration(20) * time.Millisecond, - AnswerTime: time.Date(2015, 12, 28, 12, 58, 30, 0, time.UTC), - Usage: time.Duration(125) * time.Second, - Supplier: "SUPPLIER2", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{}, - CostSource: "testSetCDRs", - Cost: -1, - ExtraInfo: "AccountNotFound", + CGRID: utils.Sha1("testevent3", time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC).String()), + RunID: utils.META_DEFAULT, + OriginHost: "192.168.1.13", + Source: "testGetCDRs3", + OriginID: "testevent3", + ToR: utils.VOICE, + RequestType: utils.META_RATED, + Tenant: "cgrates.org", + Category: "call", + Account: "1002", + Subject: "1002", + Destination: "1003", + SetupTime: time.Date(2015, 12, 28, 12, 58, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 28, 12, 58, 30, 0, time.UTC), + Usage: time.Duration(125) * time.Second, + ExtraFields: map[string]string{}, + CostSource: "testSetCDRs", + Cost: -1, + ExtraInfo: "AccountNotFound", }, &CDR{ - CGRID: utils.Sha1("testevent4", time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC).String()), - RunID: utils.MetaRaw, - OriginHost: "192.168.1.14", - Source: "testGetCDRs", - OriginID: "testevent4", - ToR: utils.VOICE, - RequestType: utils.META_PSEUDOPREPAID, - Direction: utils.OUT, - Tenant: "itsyscom.com", - Category: "call", - Account: "1003", - Subject: "1003", - Destination: "1007", - SetupTime: time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(2) * time.Second, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(64) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader3": "ExtraVal3"}, - CostSource: "", - Cost: -1, + CGRID: utils.Sha1("testevent4", time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC).String()), + RunID: utils.MetaRaw, + OriginHost: "192.168.1.14", + Source: "testGetCDRs", + OriginID: "testevent4", + ToR: utils.VOICE, + RequestType: utils.META_PSEUDOPREPAID, + Tenant: "itsyscom.com", + Category: "call", + Account: "1003", + Subject: "1003", + Destination: "1007", + SetupTime: time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(64) * time.Second, + ExtraFields: map[string]string{"ExtraHeader3": "ExtraVal3"}, + CostSource: "", + Cost: -1, }, &CDR{ - CGRID: utils.Sha1("testevent4", time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC).String()), - RunID: utils.META_DEFAULT, - OriginHost: "192.168.1.14", - Source: "testGetCDRs", - OriginID: "testevent4", - ToR: utils.VOICE, - RequestType: utils.META_RATED, - Direction: utils.OUT, - Tenant: "itsyscom.com", - Category: "call", - Account: "1003", - Subject: "1003", - Destination: "1007", - SetupTime: time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC), - PDD: time.Duration(2) * time.Second, - AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), - Usage: time.Duration(64) * time.Second, - Supplier: "SUPPLIER1", - DisconnectCause: "NORMAL_DISCONNECT", - ExtraFields: map[string]string{"ExtraHeader3": "ExtraVal3"}, - CostSource: "testSetCDRs", - Cost: 1.205, + CGRID: utils.Sha1("testevent4", time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC).String()), + RunID: utils.META_DEFAULT, + OriginHost: "192.168.1.14", + Source: "testGetCDRs", + OriginID: "testevent4", + ToR: utils.VOICE, + RequestType: utils.META_RATED, + Tenant: "itsyscom.com", + Category: "call", + Account: "1003", + Subject: "1003", + Destination: "1007", + SetupTime: time.Date(2015, 12, 14, 14, 52, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 12, 14, 52, 20, 0, time.UTC), + Usage: time.Duration(64) * time.Second, + ExtraFields: map[string]string{"ExtraHeader3": "ExtraVal3"}, + CostSource: "testSetCDRs", + Cost: 1.205, }, &CDR{ - CGRID: utils.Sha1("testevent5", time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC).String()), - RunID: utils.MetaRaw, - OriginHost: "127.0.0.1", - Source: "testGetCDRs5", - OriginID: "testevent5", - ToR: utils.SMS, - RequestType: utils.META_PREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "sms", - Account: "1001", - Subject: "1001", - Destination: "1002", - SetupTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), - PDD: time.Duration(0), - AnswerTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), - Usage: time.Duration(1) * time.Second, - Supplier: "SUPPLIER3", - DisconnectCause: "SENT_OK", - ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, - CostSource: "", - Cost: -1, + CGRID: utils.Sha1("testevent5", time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC).String()), + RunID: utils.MetaRaw, + OriginHost: "127.0.0.1", + Source: "testGetCDRs5", + OriginID: "testevent5", + ToR: utils.SMS, + RequestType: utils.META_PREPAID, + Tenant: "cgrates.org", + Category: "sms", + Account: "1001", + Subject: "1001", + Destination: "1002", + SetupTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), + Usage: time.Duration(1) * time.Second, + ExtraFields: map[string]string{"Service-Context-Id": "voice@huawei.com"}, + CostSource: "", + Cost: -1, }, &CDR{ - CGRID: utils.Sha1("testevent5", time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC).String()), - RunID: utils.META_DEFAULT, - OriginHost: "127.0.0.1", - Source: "testGetCDRs5", - OriginID: "testevent5", - ToR: utils.SMS, - RequestType: utils.META_PREPAID, - Direction: utils.OUT, - Tenant: "cgrates.org", - Category: "sms", - Account: "1001", - Subject: "1001", - Destination: "1002", - SetupTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), - PDD: time.Duration(0), - AnswerTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), - Usage: time.Duration(1) * time.Second, - Supplier: "SUPPLIER3", - DisconnectCause: "SENT_OK", - ExtraFields: map[string]string{"Service-Context-Id": "voice2@huawei.com"}, - CostSource: "rater", - Cost: 0.15, + CGRID: utils.Sha1("testevent5", time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC).String()), + RunID: utils.META_DEFAULT, + OriginHost: "127.0.0.1", + Source: "testGetCDRs5", + OriginID: "testevent5", + ToR: utils.SMS, + RequestType: utils.META_PREPAID, + Tenant: "cgrates.org", + Category: "sms", + Account: "1001", + Subject: "1001", + Destination: "1002", + SetupTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), + AnswerTime: time.Date(2015, 12, 15, 18, 22, 0, 0, time.UTC), + Usage: time.Duration(1) * time.Second, + ExtraFields: map[string]string{"Service-Context-Id": "voice2@huawei.com"}, + CostSource: "rater", + Cost: 0.15, }, } // Store all CDRs diff --git a/engine/storage_sql.go b/engine/storage_sql.go index cb90a015d..13e1d4dd2 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -762,7 +762,7 @@ func (self *SQLStorage) SetCDR(cdr *CDR, allowUpdate bool) error { } tx = self.db.Begin() cdrSql.UpdatedAt = time.Now() - updated := tx.Model(&CDRsql{}).Where(&CDRsql{CGRID: cdr.CGRID, RunID: cdr.RunID, OriginID: cdr.OriginID}).Updates(cdrSql) + updated := tx.Model(&CDRsql{}).Where(&CDRsql{Cgrid: cdr.CGRID, RunID: cdr.RunID, OriginID: cdr.OriginID}).Updates(cdrSql) if updated.Error != nil { tx.Rollback() return updated.Error diff --git a/engine/stordb_it_test.go b/engine/stordb_it_test.go index 82fada23d..3d600a3bc 100755 --- a/engine/stordb_it_test.go +++ b/engine/stordb_it_test.go @@ -1677,9 +1677,6 @@ func testStorDBitCRUDCDRs(t *testing.T) { if !(reflect.DeepEqual(snd[0].RequestType, rcv[0].RequestType) || reflect.DeepEqual(snd[0].RequestType, rcv[1].RequestType)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].RequestType, rcv[0].RequestType, rcv[1].RequestType) } - if !(reflect.DeepEqual(snd[0].Direction, rcv[0].Direction) || reflect.DeepEqual(snd[0].Direction, rcv[1].Direction)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Direction, rcv[0].Direction, rcv[1].Direction) - } if !(reflect.DeepEqual(snd[0].Tenant, rcv[0].Tenant) || reflect.DeepEqual(snd[0].Tenant, rcv[1].Tenant)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Tenant, rcv[0].Tenant, rcv[1].Tenant) } @@ -1698,21 +1695,12 @@ func testStorDBitCRUDCDRs(t *testing.T) { if !(snd[0].SetupTime.Equal(rcv[0].SetupTime) || snd[0].SetupTime.Equal(rcv[1].SetupTime)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].SetupTime, rcv[0].SetupTime, rcv[1].SetupTime) } - if !(reflect.DeepEqual(snd[0].PDD, rcv[0].PDD) || reflect.DeepEqual(snd[0].PDD, rcv[1].PDD)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].PDD, rcv[0].PDD, rcv[1].PDD) - } if !(snd[0].AnswerTime.Equal(rcv[0].AnswerTime) || snd[0].AnswerTime.Equal(rcv[1].AnswerTime)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].AnswerTime, rcv[0].AnswerTime, rcv[1].AnswerTime) } if !(reflect.DeepEqual(snd[0].Usage, rcv[0].Usage) || reflect.DeepEqual(snd[0].Usage, rcv[1].Usage)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Usage, rcv[0].Usage, rcv[1].Usage) } - if !(reflect.DeepEqual(snd[0].Supplier, rcv[0].Supplier) || reflect.DeepEqual(snd[0].Supplier, rcv[1].Supplier)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].Supplier, rcv[0].Supplier, rcv[1].Supplier) - } - if !(reflect.DeepEqual(snd[0].DisconnectCause, rcv[0].DisconnectCause) || reflect.DeepEqual(snd[0].DisconnectCause, rcv[1].DisconnectCause)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].DisconnectCause, rcv[0].DisconnectCause, rcv[1].DisconnectCause) - } if !(reflect.DeepEqual(snd[0].ExtraFields, rcv[0].ExtraFields) || reflect.DeepEqual(snd[0].ExtraFields, rcv[1].ExtraFields)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ExtraFields, rcv[0].ExtraFields, rcv[1].ExtraFields) } @@ -1725,9 +1713,6 @@ func testStorDBitCRUDCDRs(t *testing.T) { if !(reflect.DeepEqual(snd[0].CostDetails, rcv[0].CostDetails) || reflect.DeepEqual(snd[0].CostDetails, rcv[1].CostDetails)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].CostDetails, rcv[0].CostDetails, rcv[1].CostDetails) } - if !(reflect.DeepEqual(snd[0].AccountSummary, rcv[0].AccountSummary) || reflect.DeepEqual(snd[0].AccountSummary, rcv[1].AccountSummary)) { - t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].AccountSummary, rcv[0].AccountSummary, rcv[1].AccountSummary) - } if !(reflect.DeepEqual(snd[0].ExtraInfo, rcv[0].ExtraInfo) || reflect.DeepEqual(snd[0].ExtraInfo, rcv[1].ExtraInfo)) { t.Errorf("Expecting: %+v, received: %+v || %+v", snd[0].ExtraInfo, rcv[0].ExtraInfo, rcv[1].ExtraInfo) } diff --git a/general_tests/cdrs_onlexp_it_test.go b/general_tests/cdrs_onlexp_it_test.go index 9c674cc6b..3e98febc4 100644 --- a/general_tests/cdrs_onlexp_it_test.go +++ b/general_tests/cdrs_onlexp_it_test.go @@ -93,7 +93,7 @@ func TestCDRsOnExpHttpCdrReplication(t *testing.T) { } testCdr1 := &engine.CDR{CGRID: utils.Sha1("httpjsonrpc1", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "httpjsonrpc1", OriginHost: "192.168.1.1", Source: "UNKNOWN", RequestType: utils.META_PSEUDOPREPAID, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2013, 12, 7, 8, 42, 26, 0, time.UTC), Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, RunID: utils.DEFAULT_RUNID, Cost: 1.201, Rated: true} @@ -125,7 +125,6 @@ func TestCDRsOnExpHttpCdrReplication(t *testing.T) { rcvedCdrs[0].ToR != testCdr1.ToR || rcvedCdrs[0].OriginHost != testCdr1.OriginHost || rcvedCdrs[0].RequestType != testCdr1.RequestType || - rcvedCdrs[0].Direction != testCdr1.Direction || rcvedCdrs[0].Tenant != testCdr1.Tenant || rcvedCdrs[0].Category != testCdr1.Category || rcvedCdrs[0].Account != testCdr1.Account || @@ -182,7 +181,7 @@ func TestCDRsOnExpAMQPReplication(t *testing.T) { time.Sleep(time.Duration(5 * time.Second)) testCdr := &engine.CDR{CGRID: utils.Sha1("amqpreconnect", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "amqpreconnect", OriginHost: "192.168.1.1", Source: "UNKNOWN", RequestType: utils.META_PSEUDOPREPAID, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2013, 12, 7, 8, 42, 26, 0, time.UTC), Usage: time.Duration(10) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, RunID: utils.DEFAULT_RUNID, Cost: 1.201, Rated: true} diff --git a/general_tests/tutorial_it_test.go b/general_tests/tutorial_it_test.go index 79d3325b5..008b387ae 100644 --- a/general_tests/tutorial_it_test.go +++ b/general_tests/tutorial_it_test.go @@ -498,7 +498,6 @@ func TestTutITDerivedMaxSessionTime(t *testing.T) { OriginID: "testevent1", OriginHost: "127.0.0.1", RequestType: utils.META_PREPAID, - Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "1004", @@ -507,7 +506,6 @@ func TestTutITDerivedMaxSessionTime(t *testing.T) { SetupTime: tStart, AnswerTime: tStart, Usage: time.Duration(120) * time.Second, - Supplier: "suppl1", Cost: -1, } var maxTime float64 @@ -520,7 +518,7 @@ func TestTutITDerivedMaxSessionTime(t *testing.T) { // Check MaxUsage func TestTutITMaxUsage(t *testing.T) { - setupReq := &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_PREPAID, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", + setupReq := &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1001", SetupTime: "2014-08-04T13:00:00Z", Usage: "1", } @@ -530,7 +528,7 @@ func TestTutITMaxUsage(t *testing.T) { } else if maxTime != 1 { t.Errorf("Calling ApierV2.MaxUsage got maxTime: %f", maxTime) } - setupReq = &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_RATED, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", + setupReq = &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_RATED, Tenant: "cgrates.org", Category: "call", Account: "test_max_usage", Destination: "1001", SetupTime: "2014-08-04T13:00:00Z", } @@ -543,7 +541,7 @@ func TestTutITMaxUsage(t *testing.T) { // Check DebitUsage func TestTutITDebitUsage(t *testing.T) { - setupReq := &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_PREPAID, Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", + setupReq := &engine.UsageRecord{ToR: utils.VOICE, RequestType: utils.META_PREPAID, Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1001", AnswerTime: "2014-08-04T13:00:00Z", Usage: "1", } @@ -558,10 +556,10 @@ func TestTutITDebitUsage(t *testing.T) { // Test CDR from external sources func TestTutITProcessExternalCdr(t *testing.T) { cdr := &engine.ExternalCDR{ToR: utils.VOICE, - OriginID: "testextcdr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: utils.OUT, - Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1001", Supplier: "SUPPL1", + OriginID: "testextcdr1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1001", SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", - Usage: "1", PDD: "7.0", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, + Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, } var reply string if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr, &reply); err != nil { @@ -574,10 +572,9 @@ func TestTutITProcessExternalCdr(t *testing.T) { // Test CDR involving UserProfile func TestTutITProcessExternalCdrUP(t *testing.T) { cdr := &engine.ExternalCDR{ToR: utils.VOICE, - OriginID: "testextcdr2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, Direction: utils.OUT, - RequestType: utils.USERS, Tenant: utils.USERS, Account: utils.USERS, Destination: "1001", Supplier: "SUPPL1", - SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", - Usage: "2", PDD: "0.2", DisconnectCause: "NORMAL_DISCONNECT", + OriginID: "testextcdr2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, + RequestType: utils.USERS, Tenant: utils.USERS, Account: utils.USERS, Destination: "1001", + SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", Usage: "2", ExtraFields: map[string]string{"Cli": "+4986517174964", "fieldextr2": "valextr2", "SysUserName": utils.USERS}, } var reply string @@ -589,10 +586,10 @@ func TestTutITProcessExternalCdrUP(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) eCdr := &engine.ExternalCDR{CGRID: "63a8d2bfeca2cfb790826c3ec461696d6574cfde", OrderID: 2, ToR: utils.VOICE, - OriginID: "testextcdr2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: utils.OUT, - Tenant: "cgrates.org", Category: "call", Account: "1004", Subject: "1004", Destination: "1001", Supplier: "SUPPL1", - SetupTime: time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC).Local().Format(time.RFC3339), AnswerTime: time.Date(2014, 8, 4, 13, 0, 7, 0, time.UTC).Local().Format(time.RFC3339), - Usage: "2", PDD: "0.2", DisconnectCause: "NORMAL_DISCONNECT", + OriginID: "testextcdr2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "call", Account: "1004", Subject: "1004", Destination: "1001", + SetupTime: time.Date(2014, 8, 4, 13, 0, 0, 0, time.UTC).Local().Format(time.RFC3339), + AnswerTime: time.Date(2014, 8, 4, 13, 0, 7, 0, time.UTC).Local().Format(time.RFC3339), Usage: "2", ExtraFields: map[string]string{"Cli": "+4986517174964", "fieldextr2": "valextr2", "SysUserName": "danb4"}, RunID: utils.DEFAULT_RUNID, Cost: 1} var cdrs []*engine.ExternalCDR @@ -629,33 +626,24 @@ func TestTutITProcessExternalCdrUP(t *testing.T) { if cdrs[0].Destination != eCdr.Destination { t.Errorf("Unexpected Destination for CDR: %+v", cdrs[0]) } - if cdrs[0].Supplier != eCdr.Supplier { - t.Errorf("Unexpected Supplier for CDR: %+v", cdrs[0]) - } if cdrs[0].SetupTime != eCdr.SetupTime { t.Errorf("Unexpected SetupTime for CDR: %+v", cdrs[0]) } - if cdrs[0].PDD != eCdr.PDD { - t.Errorf("Unexpected PDD for CDR: %+v", cdrs[0]) - } if cdrs[0].AnswerTime != eCdr.AnswerTime { t.Errorf("Unexpected AnswerTime for CDR: %+v", cdrs[0]) } if cdrs[0].Usage != eCdr.Usage { t.Errorf("Unexpected Usage for CDR: %+v", cdrs[0]) } - if cdrs[0].DisconnectCause != eCdr.DisconnectCause { - t.Errorf("Unexpected DisconnectCause for CDR: %+v", cdrs[0]) - } } } func TestTutITCostErrors(t *testing.T) { cdr := &engine.ExternalCDR{ToR: utils.VOICE, - OriginID: "TestTutIT_1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, Direction: utils.OUT, - Tenant: "cgrates.org", Category: "fake", Account: "2001", Subject: "2001", Destination: "1001", Supplier: "SUPPL1", + OriginID: "TestTutIT_1", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_RATED, + Tenant: "cgrates.org", Category: "fake", Account: "2001", Subject: "2001", Destination: "1001", SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", - Usage: "1", PDD: "7.0", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, + Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, } var reply string if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr, &reply); err != nil { @@ -679,10 +667,10 @@ func TestTutITCostErrors(t *testing.T) { } } cdr2 := &engine.ExternalCDR{ToR: utils.VOICE, - OriginID: "TestTutIT_2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_POSTPAID, Direction: utils.OUT, - Tenant: "cgrates.org", Category: "fake", Account: "2002", Subject: "2002", Destination: "1001", Supplier: "SUPPL1", + OriginID: "TestTutIT_2", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_POSTPAID, + Tenant: "cgrates.org", Category: "fake", Account: "2002", Subject: "2002", Destination: "1001", SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", - Usage: "1", PDD: "7.0", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, + Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, } if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr2, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) @@ -704,10 +692,10 @@ func TestTutITCostErrors(t *testing.T) { } } cdr3 := &engine.ExternalCDR{ToR: utils.VOICE, - OriginID: "TestTutIT_3", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_POSTPAID, Direction: utils.OUT, - Tenant: "cgrates.org", Category: "fake", Account: "1001", Subject: "1001", Destination: "2002", Supplier: "SUPPL1", + OriginID: "TestTutIT_3", OriginHost: "192.168.1.1", Source: utils.UNIT_TEST, RequestType: utils.META_POSTPAID, + Tenant: "cgrates.org", Category: "fake", Account: "1001", Subject: "1001", Destination: "2002", SetupTime: "2014-08-04T13:00:00Z", AnswerTime: "2014-08-04T13:00:07Z", - Usage: "1", PDD: "7.0", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, + Usage: "1", ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, } if err := tutLocalRpc.Call("CdrsV1.ProcessExternalCdr", cdr3, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) @@ -959,15 +947,15 @@ func TestTutITLcrQos(t *testing.T) { // Post some CDRs to influence stats testCdr1 := &engine.CDR{CGRID: utils.Sha1("testcdr1", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testcdr1", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1002", SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), - Usage: time.Duration(2) * time.Minute, Supplier: "suppl1", + Usage: time.Duration(2) * time.Minute, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} testCdr2 := &engine.CDR{CGRID: utils.Sha1("testcdr2", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testcdr2", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1002", Subject: "1002", Destination: "1003", + Tenant: "cgrates.org", Category: "call", Account: "1002", Subject: "1002", Destination: "1003", SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), - Usage: time.Duration(90) * time.Second, Supplier: "suppl2", + Usage: time.Duration(90) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} var reply string for _, cdr := range []*engine.CDR{testCdr1, testCdr2} { @@ -998,9 +986,9 @@ func TestTutITLcrQos(t *testing.T) { } testCdr3 := &engine.CDR{CGRID: utils.Sha1("testcdr3", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testcdr3", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", + Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), - Usage: time.Duration(180) * time.Second, Supplier: "suppl2"} + Usage: time.Duration(180) * time.Second} if err := tutLocalRpc.Call("CdrsV1.ProcessCdr", testCdr3, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { @@ -1061,9 +1049,9 @@ func TestTutITLcrQosThreshold(t *testing.T) { } testCdr4 := &engine.CDR{CGRID: utils.Sha1("testcdr4", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testcdr4", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", + Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), - Usage: time.Duration(60) * time.Second, Supplier: "suppl2"} + Usage: time.Duration(60) * time.Second} var reply string if err := tutLocalRpc.Call("CdrsV1.ProcessCdr", testCdr4, &reply); err != nil { // Should drop ACD under the 2m required by threshold, removing suppl2 from lcr t.Error("Unexpected error: ", err.Error()) @@ -1126,9 +1114,9 @@ func TestTutITLcrQosThreshold(t *testing.T) { } testCdr5 := &engine.CDR{CGRID: utils.Sha1("testcdr5", time.Date(2013, 12, 7, 8, 42, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testcdr5", OriginHost: "192.168.1.1", Source: "TEST_QOS_LCR", RequestType: utils.META_RATED, - Direction: "*out", Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", + Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), - Usage: time.Duration(1) * time.Second, Supplier: "suppl2"} + Usage: time.Duration(1) * time.Second} if err := tutLocalRpc.Call("CdrsV1.ProcessCdr", testCdr5, &reply); err != nil { // Should drop ACD under the 1m required by threshold, removing suppl2 from lcr t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { @@ -1302,9 +1290,9 @@ func TestTutITCdrStatsAfter(t *testing.T) { func TestTutITPrepaidCDRWithSMCost(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testprepaid1", time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testprepaid1", OriginHost: "192.168.1.1", Source: "TEST_PREPAID_CDR_SMCOST1", RequestType: utils.META_PREPAID, - Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003", SetupTime: time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC), AnswerTime: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC), - Usage: time.Duration(90) * time.Second, Supplier: "suppl1", + Usage: time.Duration(90) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} smCost := &engine.SMCost{CGRID: cdr.CGRID, RunID: utils.META_DEFAULT, @@ -1359,9 +1347,9 @@ func TestTutITPrepaidCDRWithSMCost(t *testing.T) { func TestTutITPrepaidCDRWithoutSMCost(t *testing.T) { cdr := &engine.CDR{CGRID: utils.Sha1("testprepaid2", time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC).String()), ToR: utils.VOICE, OriginID: "testprepaid2", OriginHost: "192.168.1.1", Source: "TEST_PREPAID_CDR_NO_SMCOST1", RequestType: utils.META_PREPAID, - Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003", SetupTime: time.Date(2016, 4, 6, 13, 29, 24, 0, time.UTC), AnswerTime: time.Date(2016, 4, 6, 13, 30, 0, 0, time.UTC), - Usage: time.Duration(90) * time.Second, Supplier: "suppl1", + Usage: time.Duration(90) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} var reply string if err := tutLocalRpc.Call("CdrsV1.ProcessCdr", cdr, &reply); err != nil { @@ -1390,9 +1378,9 @@ func TestTutITPrepaidCDRWithoutSMCost(t *testing.T) { func TestTutITExportCDR(t *testing.T) { cdr := &engine.CDR{ToR: utils.VOICE, OriginID: "testexportcdr1", OriginHost: "192.168.1.1", Source: "TestTutITExportCDR", RequestType: utils.META_RATED, - Direction: utils.OUT, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003", + Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001", Destination: "1003", SetupTime: time.Date(2016, 11, 30, 17, 5, 24, 0, time.UTC), AnswerTime: time.Date(2016, 11, 30, 17, 6, 4, 0, time.UTC), - Usage: time.Duration(98) * time.Second, Supplier: "suppl1", + Usage: time.Duration(98) * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} cdr.ComputeCGRID() var reply string From b7fb426b09dd390c5d6a2f8c5e8eb6c2cbed3f3d Mon Sep 17 00:00:00 2001 From: TeoV Date: Tue, 31 Oct 2017 13:05:02 +0200 Subject: [PATCH 2/4] Removing Quotes from data/storage --- data/storage/mysql/create_cdrs_tables.sql | 8 ++++---- data/storage/postgres/create_cdrs_tables.sql | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/data/storage/mysql/create_cdrs_tables.sql b/data/storage/mysql/create_cdrs_tables.sql index 5f0b2b673..c424c9e94 100644 --- a/data/storage/mysql/create_cdrs_tables.sql +++ b/data/storage/mysql/create_cdrs_tables.sql @@ -5,7 +5,7 @@ DROP TABLE IF EXISTS cdrs; CREATE TABLE cdrs ( id int(11) NOT NULL AUTO_INCREMENT, - `cgrid` varchar(40) NOT NULL, + cgrid varchar(40) NOT NULL, run_id varchar(64) NOT NULL, origin_host varchar(64) NOT NULL, source varchar(64) NOT NULL, @@ -29,13 +29,13 @@ CREATE TABLE cdrs ( updated_at TIMESTAMP NULL, deleted_at TIMESTAMP NULL, PRIMARY KEY (id), - UNIQUE KEY cdrrun (`cgrid`, run_id, origin_id) + UNIQUE KEY cdrrun (cgrid, run_id, origin_id) ); DROP TABLE IF EXISTS sm_costs; CREATE TABLE sm_costs ( id int(11) NOT NULL AUTO_INCREMENT, - `cgrid` varchar(40) NOT NULL, + cgrid varchar(40) NOT NULL, run_id varchar(64) NOT NULL, origin_host varchar(64) NOT NULL, origin_id varchar(64) NOT NULL, @@ -45,7 +45,7 @@ CREATE TABLE sm_costs ( created_at TIMESTAMP NULL, deleted_at TIMESTAMP NULL, PRIMARY KEY (`id`), - UNIQUE KEY costid (`cgrid`, run_id), + UNIQUE KEY costid (cgrid, run_id), KEY origin_idx (origin_host, origin_id), KEY run_origin_idx (run_id, origin_id), KEY deleted_at_idx (deleted_at) diff --git a/data/storage/postgres/create_cdrs_tables.sql b/data/storage/postgres/create_cdrs_tables.sql index d144f9890..ad565c068 100644 --- a/data/storage/postgres/create_cdrs_tables.sql +++ b/data/storage/postgres/create_cdrs_tables.sql @@ -5,7 +5,7 @@ DROP TABLE IF EXISTS cdrs; CREATE TABLE cdrs ( id SERIAL PRIMARY KEY, - "cgrid" VARCHAR(40) NOT NULL, + cgrid VARCHAR(40) NOT NULL, run_id VARCHAR(64) NOT NULL, origin_host VARCHAR(64) NOT NULL, source VARCHAR(64) NOT NULL, @@ -28,7 +28,7 @@ CREATE TABLE cdrs ( created_at TIMESTAMP WITH TIME ZONE, updated_at TIMESTAMP WITH TIME ZONE NULL, deleted_at TIMESTAMP WITH TIME ZONE NULL, - UNIQUE ("cgrid", run_id, origin_id) + UNIQUE (cgrid, run_id, origin_id) ); ; DROP INDEX IF EXISTS deleted_at_cp_idx; @@ -38,7 +38,7 @@ CREATE INDEX deleted_at_cp_idx ON cdrs (deleted_at); DROP TABLE IF EXISTS sm_costs; CREATE TABLE sm_costs ( id SERIAL PRIMARY KEY, - "cgrid" VARCHAR(40) NOT NULL, + cgrid VARCHAR(40) NOT NULL, run_id VARCHAR(64) NOT NULL, origin_host VARCHAR(64) NOT NULL, origin_id VARCHAR(64) NOT NULL, @@ -47,10 +47,10 @@ CREATE TABLE sm_costs ( cost_details jsonb, created_at TIMESTAMP WITH TIME ZONE, deleted_at TIMESTAMP WITH TIME ZONE NULL, - UNIQUE ("cgrid", run_id) + UNIQUE (cgrid, run_id) ); DROP INDEX IF EXISTS cgrid_smcost_idx; -CREATE INDEX cgrid_smcost_idx ON sm_costs ("cgrid", run_id); +CREATE INDEX cgrid_smcost_idx ON sm_costs (cgrid, run_id); DROP INDEX IF EXISTS origin_smcost_idx; CREATE INDEX origin_smcost_idx ON sm_costs (origin_host, origin_id); DROP INDEX IF EXISTS run_origin_smcost_idx; From 642f5b8ab0c184767581693ce125c6d55bdea5b8 Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 3 Nov 2017 13:13:08 +0200 Subject: [PATCH 3/4] Update CDRsFilter , --- apier/v1/apier_it_test.go | 4 +-- apier/v1/costs.go | 2 +- data/tariffplans/test/a1/Rates.csv | 1 + engine/cdr.go | 3 +- engine/storage_cdrs_it_test.go | 27 +--------------- engine/storage_mongo_stordb.go | 52 ++++++++++-------------------- engine/storage_sql.go | 34 ------------------- utils/apitpdata.go | 50 +++++++--------------------- 8 files changed, 34 insertions(+), 139 deletions(-) diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index c33445a81..136729664 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -1354,11 +1354,11 @@ func TestApierMaxDebitInexistentAcnt(t *testing.T) { func TestApierCdrServer(t *testing.T) { httpClient := new(http.Client) - cdrForm1 := url.Values{utils.ACCID: []string{"dsafdsaf"}, utils.CDRHOST: []string{"192.168.1.1"}, utils.REQTYPE: []string{utils.META_RATED}, utils.DIRECTION: []string{"*out"}, + cdrForm1 := url.Values{utils.ACCID: []string{"dsafdsaf"}, utils.CDRHOST: []string{"192.168.1.1"}, utils.REQTYPE: []string{utils.META_RATED}, utils.TENANT: []string{"cgrates.org"}, utils.CATEGORY: []string{"call"}, utils.ACCOUNT: []string{"1001"}, utils.SUBJECT: []string{"1001"}, utils.DESTINATION: []string{"1002"}, utils.SETUP_TIME: []string{"2013-11-07T08:42:22Z"}, utils.ANSWER_TIME: []string{"2013-11-07T08:42:26Z"}, utils.USAGE: []string{"10"}, "field_extr1": []string{"val_extr1"}, "fieldextr2": []string{"valextr2"}} - cdrForm2 := url.Values{utils.ACCID: []string{"adsafdsaf"}, utils.CDRHOST: []string{"192.168.1.1"}, utils.REQTYPE: []string{utils.META_RATED}, utils.DIRECTION: []string{"*out"}, + cdrForm2 := url.Values{utils.ACCID: []string{"adsafdsaf"}, utils.CDRHOST: []string{"192.168.1.1"}, utils.REQTYPE: []string{utils.META_RATED}, utils.TENANT: []string{"cgrates.org"}, utils.CATEGORY: []string{"call"}, utils.ACCOUNT: []string{"1001"}, utils.SUBJECT: []string{"1001"}, utils.DESTINATION: []string{"1002"}, utils.SETUP_TIME: []string{"2013-11-07T08:42:23Z"}, utils.ANSWER_TIME: []string{"2013-11-07T08:42:26Z"}, utils.USAGE: []string{"10"}, "field_extr1": []string{"val_extr1"}, "fieldextr2": []string{"valextr2"}} diff --git a/apier/v1/costs.go b/apier/v1/costs.go index b006e94e1..37e93c4c0 100644 --- a/apier/v1/costs.go +++ b/apier/v1/costs.go @@ -34,7 +34,7 @@ type AttrGetDataCost struct { } func (apier *ApierV1) GetDataCost(attrs AttrGetDataCost, reply *engine.DataCost) error { - usageAsDuration := time.Duration(attrs.Usage) * time.Second // Convert to seconds to match the loaded rates + usageAsDuration := time.Duration(attrs.Usage) * time.Nanosecond // Convert to seconds to match the loaded rates cd := &engine.CallDescriptor{ Direction: attrs.Direction, Category: attrs.Category, diff --git a/data/tariffplans/test/a1/Rates.csv b/data/tariffplans/test/a1/Rates.csv index aa04963f7..c4fbab57e 100644 --- a/data/tariffplans/test/a1/Rates.csv +++ b/data/tariffplans/test/a1/Rates.csv @@ -1 +1,2 @@ +#Id,ConnectFee,Rate,RateUnit,RateIncrement,GroupIntervalStart RT_DATA1,0,0.0,1048576,10240,0 diff --git a/engine/cdr.go b/engine/cdr.go index 243ae8046..ab987f5d3 100644 --- a/engine/cdr.go +++ b/engine/cdr.go @@ -803,7 +803,6 @@ func NewCDRFromSQL(cdrSql *CDRsql) (cdr *CDR, err error) { cdr.SetupTime = cdrSql.SetupTime cdr.AnswerTime = cdrSql.AnswerTime cdr.Usage = time.Duration(cdrSql.Usage) - cdr.CostSource = cdrSql.CostSource cdr.Cost = cdrSql.Cost cdr.ExtraInfo = cdrSql.ExtraInfo @@ -813,7 +812,7 @@ func NewCDRFromSQL(cdrSql *CDRsql) (cdr *CDR, err error) { } } if cdrSql.CostDetails != "" { - if err = json.Unmarshal([]byte(cdrSql.CostDetails), cdr.CostDetails); err != nil { + if err = json.Unmarshal([]byte(cdrSql.CostDetails), &cdr.CostDetails); err != nil { return nil, err } } diff --git a/engine/storage_cdrs_it_test.go b/engine/storage_cdrs_it_test.go index 912fdc408..46b1fe5ff 100644 --- a/engine/storage_cdrs_it_test.go +++ b/engine/storage_cdrs_it_test.go @@ -574,13 +574,6 @@ func testGetCDRs(cfg *config.CGRConfig) error { } else if len(CDRs) != 6 { return fmt.Errorf("testGetCDRs #35, unexpected number of CDRs returned: %+v", CDRs) } - - // Filter on direction - if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{Directions: []string{utils.OUT}}, false); err != nil { - return fmt.Errorf("testGetCDRs #36 err: %v", err) - } else if len(CDRs) != 10 { - return fmt.Errorf("testGetCDRs #37, unexpected number of CDRs returned: %+v", CDRs) - } // Filter on Tenant if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{Tenants: []string{"itsyscom.com"}}, false); err != nil { return fmt.Errorf("testGetCDRs #38 err: %v", err) @@ -661,7 +654,7 @@ func testGetCDRs(cfg *config.CGRConfig) error { return fmt.Errorf("testGetCDRs #63, unexpected number of CDRs returned: %+v", CDRs) } // Filter on MinUsage - if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{MinUsage: "125"}, false); err != nil { + if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{MinUsage: "125s"}, false); err != nil { return fmt.Errorf("testGetCDRs #64, err: %v", err) } else if len(CDRs) != 2 { return fmt.Errorf("testGetCDRs #65, unexpected number of CDRs returned: %d", len(CDRs)) @@ -718,24 +711,6 @@ func testGetCDRs(cfg *config.CGRConfig) error { } else if len(CDRs) != 2 { return fmt.Errorf("testGetCDRs #77, unexpected number of CDRs returned: %+v", CDRs) } - // Filter on MinPDD - if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{MinPDD: "20ms"}, false); err != nil { - return fmt.Errorf("testGetCDRs #78, err: %v", err) - } else if len(CDRs) != 7 { - return fmt.Errorf("testGetCDRs #79, unexpected number of CDRs returned: %+v", CDRs) - } - // Filter on maxPdd - if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{MaxPDD: "1s"}, false); err != nil { - return fmt.Errorf("testGetCDRs #80, err: %v", err) - } else if len(CDRs) != 8 { - return fmt.Errorf("testGetCDRs #81, unexpected number of CDRs returned: %+v", CDRs) - } - // Filter on minPdd, maxPdd - if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{MinPDD: "10ms", MaxPDD: "1s"}, false); err != nil { - return fmt.Errorf("testGetCDRs #82, err: %v", err) - } else if len(CDRs) != 6 { - return fmt.Errorf("testGetCDRs #83, unexpected number of CDRs returned: %+v", CDRs) - } // Combined filter if CDRs, _, err := cdrStorage.GetCDRs(&utils.CDRsFilter{RequestTypes: []string{utils.META_RATED}, AnswerTimeStart: &timeStart, AnswerTimeEnd: &timeEnd}, false); err != nil { return fmt.Errorf("testGetCDRs #84, err: %v", err) diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 3169e154a..f21ede633 100755 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -982,21 +982,7 @@ func (ms *MongoStorage) cleanEmptyFilters(filters bson.M) { // _, err := col(utils.CDRsTBL).UpdateAll(bson.M{CGRIDLow: bson.M{"$in": cgrIds}}, bson.M{"$set": bson.M{"deleted_at": time.Now()}}) func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, int64, error) { - var minPDD, maxPDD, minUsage, maxUsage *time.Duration - if len(qryFltr.MinPDD) != 0 { - if parsed, err := utils.ParseDurationWithNanosecs(qryFltr.MinPDD); err != nil { - return nil, 0, err - } else { - minPDD = &parsed - } - } - if len(qryFltr.MaxPDD) != 0 { - if parsed, err := utils.ParseDurationWithNanosecs(qryFltr.MaxPDD); err != nil { - return nil, 0, err - } else { - maxPDD = &parsed - } - } + var minUsage, maxUsage *time.Duration if len(qryFltr.MinUsage) != 0 { if parsed, err := utils.ParseDurationWithNanosecs(qryFltr.MinUsage); err != nil { return nil, 0, err @@ -1012,26 +998,22 @@ func (ms *MongoStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, } } filters := bson.M{ - CGRIDLow: bson.M{"$in": qryFltr.CGRIDs, "$nin": qryFltr.NotCGRIDs}, - RunIDLow: bson.M{"$in": qryFltr.RunIDs, "$nin": qryFltr.NotRunIDs}, - OrderIDLow: bson.M{"$gte": qryFltr.OrderIDStart, "$lt": qryFltr.OrderIDEnd}, - ToRLow: bson.M{"$in": qryFltr.ToRs, "$nin": qryFltr.NotToRs}, - CDRHostLow: bson.M{"$in": qryFltr.OriginHosts, "$nin": qryFltr.NotOriginHosts}, - CDRSourceLow: bson.M{"$in": qryFltr.Sources, "$nin": qryFltr.NotSources}, - RequestTypeLow: bson.M{"$in": qryFltr.RequestTypes, "$nin": qryFltr.NotRequestTypes}, - DirectionLow: bson.M{"$in": qryFltr.Directions, "$nin": qryFltr.NotDirections}, - TenantLow: bson.M{"$in": qryFltr.Tenants, "$nin": qryFltr.NotTenants}, - CategoryLow: bson.M{"$in": qryFltr.Categories, "$nin": qryFltr.NotCategories}, - AccountLow: bson.M{"$in": qryFltr.Accounts, "$nin": qryFltr.NotAccounts}, - SubjectLow: bson.M{"$in": qryFltr.Subjects, "$nin": qryFltr.NotSubjects}, - SupplierLow: bson.M{"$in": qryFltr.Suppliers, "$nin": qryFltr.NotSuppliers}, - DisconnectCauseLow: bson.M{"$in": qryFltr.DisconnectCauses, "$nin": qryFltr.NotDisconnectCauses}, - SetupTimeLow: bson.M{"$gte": qryFltr.SetupTimeStart, "$lt": qryFltr.SetupTimeEnd}, - AnswerTimeLow: bson.M{"$gte": qryFltr.AnswerTimeStart, "$lt": qryFltr.AnswerTimeEnd}, - CreatedAtLow: bson.M{"$gte": qryFltr.CreatedAtStart, "$lt": qryFltr.CreatedAtEnd}, - UpdatedAtLow: bson.M{"$gte": qryFltr.UpdatedAtStart, "$lt": qryFltr.UpdatedAtEnd}, - UsageLow: bson.M{"$gte": minUsage, "$lt": maxUsage}, - PDDLow: bson.M{"$gte": minPDD, "$lt": maxPDD}, + CGRIDLow: bson.M{"$in": qryFltr.CGRIDs, "$nin": qryFltr.NotCGRIDs}, + RunIDLow: bson.M{"$in": qryFltr.RunIDs, "$nin": qryFltr.NotRunIDs}, + OrderIDLow: bson.M{"$gte": qryFltr.OrderIDStart, "$lt": qryFltr.OrderIDEnd}, + ToRLow: bson.M{"$in": qryFltr.ToRs, "$nin": qryFltr.NotToRs}, + CDRHostLow: bson.M{"$in": qryFltr.OriginHosts, "$nin": qryFltr.NotOriginHosts}, + CDRSourceLow: bson.M{"$in": qryFltr.Sources, "$nin": qryFltr.NotSources}, + RequestTypeLow: bson.M{"$in": qryFltr.RequestTypes, "$nin": qryFltr.NotRequestTypes}, + TenantLow: bson.M{"$in": qryFltr.Tenants, "$nin": qryFltr.NotTenants}, + CategoryLow: bson.M{"$in": qryFltr.Categories, "$nin": qryFltr.NotCategories}, + AccountLow: bson.M{"$in": qryFltr.Accounts, "$nin": qryFltr.NotAccounts}, + SubjectLow: bson.M{"$in": qryFltr.Subjects, "$nin": qryFltr.NotSubjects}, + SetupTimeLow: bson.M{"$gte": qryFltr.SetupTimeStart, "$lt": qryFltr.SetupTimeEnd}, + AnswerTimeLow: bson.M{"$gte": qryFltr.AnswerTimeStart, "$lt": qryFltr.AnswerTimeEnd}, + CreatedAtLow: bson.M{"$gte": qryFltr.CreatedAtStart, "$lt": qryFltr.CreatedAtEnd}, + UpdatedAtLow: bson.M{"$gte": qryFltr.UpdatedAtStart, "$lt": qryFltr.UpdatedAtEnd}, + UsageLow: bson.M{"$gte": minUsage, "$lt": maxUsage}, //CostDetailsLow + "." + AccountLow: bson.M{"$in": qryFltr.RatedAccounts, "$nin": qryFltr.NotRatedAccounts}, //CostDetailsLow + "." + SubjectLow: bson.M{"$in": qryFltr.RatedSubjects, "$nin": qryFltr.NotRatedSubjects}, } diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 13e1d4dd2..d1df9cedd 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -817,12 +817,6 @@ func (self *SQLStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, if len(qryFltr.NotRequestTypes) != 0 { q = q.Where("request_type not in (?)", qryFltr.NotRequestTypes) } - if len(qryFltr.Directions) != 0 { - q = q.Where("direction in (?)", qryFltr.Directions) - } - if len(qryFltr.NotDirections) != 0 { - q = q.Where("direction not in (?)", qryFltr.NotDirections) - } if len(qryFltr.Tenants) != 0 { q = q.Where("tenant in (?)", qryFltr.Tenants) } @@ -869,18 +863,6 @@ func (self *SQLStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, qIds.WriteString(" )") q = q.Where(qIds.String()) } - if len(qryFltr.Suppliers) != 0 { - q = q.Where("supplier in (?)", qryFltr.Subjects) - } - if len(qryFltr.NotSuppliers) != 0 { - q = q.Where("supplier not in (?)", qryFltr.NotSubjects) - } - if len(qryFltr.DisconnectCauses) != 0 { - q = q.Where("disconnect_cause in (?)", qryFltr.DisconnectCauses) - } - if len(qryFltr.NotDisconnectCauses) != 0 { - q = q.Where("disconnect_cause not in (?)", qryFltr.NotDisconnectCauses) - } if len(qryFltr.Costs) != 0 { q = q.Where(utils.CDRsTBL+".cost in (?)", qryFltr.Costs) } @@ -974,22 +956,6 @@ func (self *SQLStorage) GetCDRs(qryFltr *utils.CDRsFilter, remove bool) ([]*CDR, } } - if len(qryFltr.MinPDD) != 0 { - if minPDD, err := utils.ParseDurationWithNanosecs(qryFltr.MinPDD); err != nil { - return nil, 0, err - } else { - q = q.Where("pdd >= ?", minPDD.Nanoseconds()) - } - - } - if len(qryFltr.MaxPDD) != 0 { - if maxPDD, err := utils.ParseDurationWithNanosecs(qryFltr.MaxPDD); err != nil { - return nil, 0, err - } else { - q = q.Where("pdd < ?", maxPDD.Nanoseconds()) - } - } - if qryFltr.MinCost != nil { if qryFltr.MaxCost == nil { q = q.Where("cost >= ?", *qryFltr.MinCost) diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 402201db9..c3cc74cf2 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -761,7 +761,6 @@ func (self *AttrExpFileCdrs) AsCDRsFilter(timezone string) (*CDRsFilter, error) OriginHosts: self.CdrHosts, Sources: self.CdrSources, RequestTypes: self.ReqTypes, - Directions: self.Directions, Tenants: self.Tenants, Categories: self.Categories, Accounts: self.Accounts, @@ -835,7 +834,6 @@ func (self *AttrGetCdrs) AsCDRsFilter(timezone string) (*CDRsFilter, error) { OriginHosts: self.CdrHosts, Sources: self.CdrSources, RequestTypes: self.ReqTypes, - Directions: self.Directions, Tenants: self.Tenants, Categories: self.Categories, Accounts: self.Accounts, @@ -879,7 +877,6 @@ type AttrRateCdrs struct { CdrHosts []string // If provided, it will filter cdrhost CdrSources []string // If provided, it will filter cdrsource ReqTypes []string // If provided, it will fiter reqtype - Directions []string // If provided, it will fiter direction Tenants []string // If provided, it will filter tenant Categories []string // If provided, it will filter çategory Accounts []string // If provided, it will filter account @@ -902,7 +899,6 @@ func (attrRateCDRs *AttrRateCdrs) AsCDRsFilter(timezone string) (*CDRsFilter, er Sources: attrRateCDRs.CdrSources, ToRs: attrRateCDRs.TORs, RequestTypes: attrRateCDRs.ReqTypes, - Directions: attrRateCDRs.Directions, Tenants: attrRateCDRs.Tenants, Categories: attrRateCDRs.Categories, Accounts: attrRateCDRs.Accounts, @@ -1013,8 +1009,6 @@ type CDRsFilter struct { NotToRs []string // Filter specific TORs out RequestTypes []string // If provided, it will fiter reqtype NotRequestTypes []string // Filter out specific request types - Directions []string // If provided, it will fiter direction - NotDirections []string // Filter out specific directions Tenants []string // If provided, it will filter tenant NotTenants []string // If provided, it will filter tenant Categories []string // If provided, it will filter çategory @@ -1025,10 +1019,6 @@ type CDRsFilter struct { NotSubjects []string // Filter out specific subjects DestinationPrefixes []string // If provided, it will filter on destination prefix NotDestinationPrefixes []string // Filter out specific destination prefixes - Suppliers []string // If provided, it will filter the supplier - NotSuppliers []string // Filter out specific suppliers - DisconnectCauses []string // Filter for disconnect Cause - NotDisconnectCauses []string // Filter out specific disconnect causes Costs []float64 // Query based on costs specified NotCosts []float64 // Filter out specific costs out from result ExtraFields map[string]string // Query based on extra fields content @@ -1045,8 +1035,6 @@ type CDRsFilter struct { UpdatedAtEnd *time.Time // End interval, smaller than MinUsage string // Start of the usage interval (>=) MaxUsage string // End of the usage interval (<) - MinPDD string // Start of the pdd interval (>=) - MaxPDD string // End of the pdd interval (<) MinCost *float64 // Start of the cost interval (>=) MaxCost *float64 // End of the usage interval (<) Unscoped bool // Include soft-deleted records in results @@ -1069,8 +1057,6 @@ type RPCCDRsFilter struct { NotToRs []string // Filter specific TORs out RequestTypes []string // If provided, it will fiter reqtype NotRequestTypes []string // Filter out specific request types - Directions []string // If provided, it will fiter direction - NotDirections []string // Filter out specific directions Tenants []string // If provided, it will filter tenant NotTenants []string // If provided, it will filter tenant Categories []string // If provided, it will filter çategory @@ -1081,10 +1067,6 @@ type RPCCDRsFilter struct { NotSubjects []string // Filter out specific subjects DestinationPrefixes []string // If provided, it will filter on destination prefix NotDestinationPrefixes []string // Filter out specific destination prefixes - Suppliers []string // If provided, it will filter the supplier - NotSuppliers []string // Filter out specific suppliers - DisconnectCauses []string // Filter for disconnect Cause - NotDisconnectCauses []string // Filter out specific disconnect causes Costs []float64 // Query based on costs specified NotCosts []float64 // Filter out specific costs out from result ExtraFields map[string]string // Query based on extra fields content @@ -1101,8 +1083,6 @@ type RPCCDRsFilter struct { UpdatedAtEnd string // End interval, smaller than MinUsage string // Start of the usage interval (>=) MaxUsage string // End of the usage interval (<) - MinPDD string // Start of the pdd interval (>=) - MaxPDD string // End of the pdd interval (<) MinCost *float64 // Start of the cost interval (>=) MaxCost *float64 // End of the usage interval (<) Paginator // Add pagination @@ -1122,8 +1102,6 @@ func (self *RPCCDRsFilter) AsCDRsFilter(timezone string) (*CDRsFilter, error) { NotSources: self.NotSources, RequestTypes: self.RequestTypes, NotRequestTypes: self.NotRequestTypes, - Directions: self.Directions, - NotDirections: self.NotDirections, Tenants: self.Tenants, NotTenants: self.NotTenants, Categories: self.Categories, @@ -1134,23 +1112,17 @@ func (self *RPCCDRsFilter) AsCDRsFilter(timezone string) (*CDRsFilter, error) { NotSubjects: self.NotSubjects, DestinationPrefixes: self.DestinationPrefixes, NotDestinationPrefixes: self.NotDestinationPrefixes, - Suppliers: self.Suppliers, - NotSuppliers: self.NotSuppliers, - DisconnectCauses: self.DisconnectCauses, - NotDisconnectCauses: self.NotDisconnectCauses, - Costs: self.Costs, - NotCosts: self.NotCosts, - ExtraFields: self.ExtraFields, - NotExtraFields: self.NotExtraFields, - OrderIDStart: self.OrderIDStart, - OrderIDEnd: self.OrderIDEnd, - MinUsage: self.MinUsage, - MaxUsage: self.MaxUsage, - MinPDD: self.MinPDD, - MaxPDD: self.MaxPDD, - MinCost: self.MinCost, - MaxCost: self.MaxCost, - Paginator: self.Paginator, + Costs: self.Costs, + NotCosts: self.NotCosts, + ExtraFields: self.ExtraFields, + NotExtraFields: self.NotExtraFields, + OrderIDStart: self.OrderIDStart, + OrderIDEnd: self.OrderIDEnd, + MinUsage: self.MinUsage, + MaxUsage: self.MaxUsage, + MinCost: self.MinCost, + MaxCost: self.MaxCost, + Paginator: self.Paginator, } if len(self.SetupTimeStart) != 0 { if sTimeStart, err := ParseTimeDetectLayout(self.SetupTimeStart, timezone); err != nil { From fda5210a4916141f606981f82c2e76e9dbce30ca Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 3 Nov 2017 13:38:40 +0200 Subject: [PATCH 4/4] Update CDRsFilter , RPCCDRsFilter , AttrExpFileCdrs structure --- utils/apitpdata.go | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/apitpdata.go b/utils/apitpdata.go index c3cc74cf2..a53f77b9a 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -736,7 +736,6 @@ type AttrExpFileCdrs struct { CdrHosts []string // If provided, it will filter cdrhost CdrSources []string // If provided, it will filter cdrsource ReqTypes []string // If provided, it will fiter reqtype - Directions []string // If provided, it will fiter direction Tenants []string // If provided, it will filter tenant Categories []string // If provided, it will filter çategory Accounts []string // If provided, it will filter account