From bb6291edd5af4bdcd664d8fb45e9427b8d4abbc3 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Fri, 7 Sep 2018 14:26:43 +0200 Subject: [PATCH] TT#44095 adjust subscriber/cdr generator to new billing mappings Change-Id: Ibdb78286939a496ab5816389e6ec97b4ae60d7c2 --- .../Dao/Trunk/billing/contracts.pm | 6 +- .../contracts_billing_profile_network.pm | 94 ++++++++++++++ ...tracts_billing_profile_network_schedule.pm | 120 ++++++++++++++++++ .../Massive/Generator/Provisioning.pm | 18 ++- .../Massive/Generator/settings.debug.cfg | 4 +- 5 files changed, 232 insertions(+), 10 deletions(-) create mode 100644 lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network.pm create mode 100644 lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network_schedule.pm diff --git a/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts.pm b/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts.pm index 611b980..173b6ce 100755 --- a/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts.pm +++ b/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts.pm @@ -22,7 +22,7 @@ use NGCP::BulkProcessor::SqlProcessor qw( ); use NGCP::BulkProcessor::SqlRecord qw(); -use NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings qw(); +#use NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::billing_profiles qw(); require Exporter; @@ -183,7 +183,7 @@ sub countby_free_cash { my $table = $db->tableidentifier($tablename); my $stmt = 'SELECT COUNT(DISTINCT c.id) FROM ' . $table . ' AS c' . - ' INNER JOIN ' . $db->tableidentifier(NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings::gettablename()) . ' AS bm ON bm.contract_id = c.id' . + ' INNER JOIN ' . $db->tableidentifier('v_actual_billing_profiles') . ' AS bm ON bm.contract_id = c.id' . ' INNER JOIN ' . $db->tableidentifier(NGCP::BulkProcessor::Dao::Trunk::billing::billing_profiles::gettablename()) . ' AS bp ON bp.id = bm.billing_profile_id' . ' WHERE c.status != "terminated" AND bp.interval_free_cash <> 0.0'; @@ -285,7 +285,7 @@ sub process_free_cash_contracts { my $table = $db->tableidentifier($tablename); my $stmt = 'FROM ' . $table . ' AS c' . - ' INNER JOIN ' . $db->tableidentifier(NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings::gettablename()) . ' AS bm ON bm.contract_id = c.id' . + ' INNER JOIN ' . $db->tableidentifier('v_actual_billing_profiles') . ' AS bm ON bm.contract_id = c.id' . ' INNER JOIN ' . $db->tableidentifier(NGCP::BulkProcessor::Dao::Trunk::billing::billing_profiles::gettablename()) . ' AS bp ON bp.id = bm.billing_profile_id' . ' WHERE c.status != "terminated" AND bp.interval_free_cash <> 0.0'; diff --git a/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network.pm b/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network.pm new file mode 100644 index 0000000..ba73ad9 --- /dev/null +++ b/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network.pm @@ -0,0 +1,94 @@ +package NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network; +use strict; + +## no critic + +use NGCP::BulkProcessor::Logging qw( + getlogger +); + +use NGCP::BulkProcessor::ConnectorPool qw( + get_billing_db +); + +use NGCP::BulkProcessor::SqlProcessor qw( + checktableinfo + copy_row +); +use NGCP::BulkProcessor::SqlRecord qw(); + +require Exporter; +our @ISA = qw(Exporter NGCP::BulkProcessor::SqlRecord); +our @EXPORT_OK = qw( + gettablename + check_table + + +); + +my $tablename = 'contracts_billing_profile_network'; +my $get_db = \&get_billing_db; + +my $expected_fieldnames = [ + 'id', + 'contract_id', + 'billing_profile_id', + 'billing_network_id', + 'start_date', + 'end_date', + 'base', +]; + +my $indexes = {}; + +#my $insert_unique_fields = []; + +sub new { + + my $class = shift; + my $self = NGCP::BulkProcessor::SqlRecord->new($class,$get_db, + $tablename,$expected_fieldnames,$indexes); + + copy_row($self,shift,$expected_fieldnames); + + return $self; + +} + +sub buildrecords_fromrows { + + my ($rows,$load_recursive) = @_; + + my @records = (); + my $record; + + if (defined $rows and ref $rows eq 'ARRAY') { + foreach my $row (@$rows) { + $record = __PACKAGE__->new($row); + + # transformations go here ... + + push @records,$record; + } + } + + return \@records; + +} + +sub gettablename { + + return $tablename; + +} + +sub check_table { + + return checktableinfo($get_db, + __PACKAGE__,$tablename, + $expected_fieldnames, + $indexes); + +} + +1; diff --git a/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network_schedule.pm b/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network_schedule.pm new file mode 100644 index 0000000..9da3e2d --- /dev/null +++ b/lib/NGCP/BulkProcessor/Dao/Trunk/billing/contracts_billing_profile_network_schedule.pm @@ -0,0 +1,120 @@ +package NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network_schedule; +use strict; + +## no critic + +use NGCP::BulkProcessor::Logging qw( + getlogger +); + +use NGCP::BulkProcessor::ConnectorPool qw( + get_billing_db +); + +use NGCP::BulkProcessor::SqlProcessor qw( + checktableinfo + copy_row +); +use NGCP::BulkProcessor::SqlRecord qw(); +use NGCP::BulkProcessor::Calendar qw(datetime_to_string); + +use NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network qw(); + +require Exporter; +our @ISA = qw(Exporter NGCP::BulkProcessor::SqlRecord); +our @EXPORT_OK = qw( + gettablename + check_table + + append_billing_mappings +); + +my $tablename = 'contracts_billing_profile_network_schedule'; +my $get_db = \&get_billing_db; + +my $expected_fieldnames = [ + 'id', + 'profile_network_id', + 'effective_start_time', +]; + +my $indexes = {}; + +#my $insert_unique_fields = []; + +sub new { + + my $class = shift; + my $self = NGCP::BulkProcessor::SqlRecord->new($class,$get_db, + $tablename,$expected_fieldnames,$indexes); + + copy_row($self,shift,$expected_fieldnames); + + return $self; + +} + +sub append_billing_mappings { + + my ($xa_db,$contract_id,$mappings_to_create,$now,$delete_mappings) = @_; + return unless $mappings_to_create; + + check_table(); + NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network::check_table(); + my $db = &$get_db(); + $xa_db //= $db; + + my $mappings = ''; + foreach my $mapping (@$mappings_to_create) { + $mappings .= (defined $mapping->{start_date} ? datetime_to_string($mapping->{start_date}) : '') . ','; + $mappings .= (defined $mapping->{end_date} ? datetime_to_string($mapping->{end_date}) : '') . ','; + $mappings .= (defined $mapping->{billing_profile_id} ? $mapping->{billing_profile_id} : '') . ','; + $mappings .= (defined $mapping->{network_id} ? $mapping->{network_id} : '') . ','; + $mappings .= ';'; #last = 1 by default + } + + $xa_db->db_do('call billing.schedule_contract_billing_profile_network(?,?,?)', + $contract_id, + ((defined $now and $delete_mappings) ? datetime_to_string($now) : undef), + $mappings + ); + +} + +sub buildrecords_fromrows { + + my ($rows,$load_recursive) = @_; + + my @records = (); + my $record; + + if (defined $rows and ref $rows eq 'ARRAY') { + foreach my $row (@$rows) { + $record = __PACKAGE__->new($row); + + # transformations go here ... + + push @records,$record; + } + } + + return \@records; + +} + +sub gettablename { + + return $tablename; + +} + +sub check_table { + + return checktableinfo($get_db, + __PACKAGE__,$tablename, + $expected_fieldnames, + $indexes); + +} + +1; diff --git a/lib/NGCP/BulkProcessor/Projects/Massive/Generator/Provisioning.pm b/lib/NGCP/BulkProcessor/Projects/Massive/Generator/Provisioning.pm index b180276..d05b412 100755 --- a/lib/NGCP/BulkProcessor/Projects/Massive/Generator/Provisioning.pm +++ b/lib/NGCP/BulkProcessor/Projects/Massive/Generator/Provisioning.pm @@ -46,7 +46,9 @@ use NGCP::BulkProcessor::Dao::Trunk::billing::billing_profiles qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::products qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::contacts qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::contracts qw(); -use NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings qw(); +#use NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings qw(); +use NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network qw(); +use NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network_schedule qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::contract_balances qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::domains qw(); use NGCP::BulkProcessor::Dao::Trunk::billing::resellers qw(); @@ -89,6 +91,7 @@ use NGCP::BulkProcessor::ConnectorPool qw( use NGCP::BulkProcessor::Utils qw(create_uuid threadid timestamp zerofill); # stringtobool check_ipnet trim); #use NGCP::BulkProcessor::DSSorter qw(sort_by_configs); use NGCP::BulkProcessor::RandomString qw(createtmpstring); +use NGCP::BulkProcessor::SqlConnectors::MySQLDB qw(); require Exporter; our @ISA = qw(Exporter); @@ -190,6 +193,7 @@ sub _provision_subscriber { my $retry = 1; while ($retry > 0) { eval { + $context->{db}->set_transaction_isolation($NGCP::BulkProcessor::SqlConnectors::MySQLDB::READ_COMMITTED); $context->{db}->db_begin(); #_info($context,"test" . $subscriber_count); #die() if (($tid == 1 or $tid == 0) and $subscriber_count == 500); @@ -547,11 +551,15 @@ sub _create_contract { $context->{bill_subscriber}->{contract_id} = $context->{contract}->{id}; $context->{prov_subscriber}->{account_id} = $context->{contract}->{id}; - $context->{contract}->{billing_mapping_id} = NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings::insert_row($context->{db}, - billing_profile_id => $context->{billing_profile}->{id}, - contract_id => $context->{contract}->{id}, - product_id => $context->{sip_account_product}->{id}, + NGCP::BulkProcessor::Dao::Trunk::billing::contracts_billing_profile_network_schedule::append_billing_mappings($context->{db}, + $context->{contract}->{id}, + [{ billing_profile_id => $context->{billing_profile}->{id}, }], ); + #$context->{contract}->{billing_mapping_id} = NGCP::BulkProcessor::Dao::Trunk::billing::billing_mappings::insert_row($context->{db}, + # billing_profile_id => $context->{billing_profile}->{id}, + # contract_id => $context->{contract}->{id}, + # product_id => $context->{sip_account_product}->{id}, + #); $context->{contract}->{contract_balance_id} = NGCP::BulkProcessor::Dao::Trunk::billing::contract_balances::insert_row($context->{db}, contract_id => $context->{contract}->{id}, diff --git a/lib/NGCP/BulkProcessor/Projects/Massive/Generator/settings.debug.cfg b/lib/NGCP/BulkProcessor/Projects/Massive/Generator/settings.debug.cfg index 4a02d53..4d18144 100755 --- a/lib/NGCP/BulkProcessor/Projects/Massive/Generator/settings.debug.cfg +++ b/lib/NGCP/BulkProcessor/Projects/Massive/Generator/settings.debug.cfg @@ -8,10 +8,10 @@ webpassword_length = 8 webusername_length = 8 sippassword_length = 16 sipusername_length = 8 -provision_subscriber_count = 50000 +provision_subscriber_count = 30000 providers_yml = providers.yml generate_cdr_multithreading = 1 #generate_cdr_numofthreads = 2 -generate_cdr_count = 500 +generate_cdr_count = 5