+ provider setup (create or load by rest-api): - reseller - domain - systemcontact, contract - provider fee (profile, zone, fees) - subscriber fees (profile, zone, fees each) + subscriber creation (DB operations) - contract - contact - balances - subscriber - primary and additional aliases - default preferences Change-Id: I0a79e9db80737e5d9975ede780ea5090cf624908changes/63/17363/4
parent
ce9fc9073d
commit
5ab47b7ba7
@ -0,0 +1,378 @@
|
|||||||
|
package NGCP::BulkProcessor::Projects::Massive::Generator::Api;
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
## no critic
|
||||||
|
|
||||||
|
use threads::shared qw();
|
||||||
|
#use List::Util qw();
|
||||||
|
use Data::Rmap qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Projects::Massive::Generator::Settings qw(
|
||||||
|
$dry
|
||||||
|
$skip_errors
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Logging qw (
|
||||||
|
getlogger
|
||||||
|
processing_info
|
||||||
|
processing_debug
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::LogError qw(
|
||||||
|
rowprocessingerror
|
||||||
|
rowprocessingwarn
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::SystemContacts qw();
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::Contracts qw();
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::Resellers qw();
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::Domains qw();
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::BillingProfiles qw();
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::BillingZones qw();
|
||||||
|
use NGCP::BulkProcessor::RestRequests::Trunk::BillingFees qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Utils qw(threadid);
|
||||||
|
|
||||||
|
require Exporter;
|
||||||
|
our @ISA = qw(Exporter);
|
||||||
|
our @EXPORT_OK = qw(
|
||||||
|
setup_provider
|
||||||
|
);
|
||||||
|
|
||||||
|
my $t = time;
|
||||||
|
my %entity_maps = ();
|
||||||
|
|
||||||
|
sub setup_provider {
|
||||||
|
my %params = @_;
|
||||||
|
my (
|
||||||
|
$domain_name,
|
||||||
|
$reseller_name,
|
||||||
|
$subscriber_rates,
|
||||||
|
$provider_rate,
|
||||||
|
$type
|
||||||
|
) = @params{qw/
|
||||||
|
domain
|
||||||
|
reseller
|
||||||
|
subscriber_rates
|
||||||
|
provider_rate
|
||||||
|
type
|
||||||
|
/};
|
||||||
|
my $provider = {};
|
||||||
|
if (not _load_provider($provider,$reseller_name,$domain_name) and not $dry) {
|
||||||
|
$provider->{contact} = _create_systemcontact();
|
||||||
|
_info("contact ID $provider->{contact}->{id} created");
|
||||||
|
$provider->{contract} = _create_contract(
|
||||||
|
contact_id => $provider->{contact}->{id},
|
||||||
|
billing_profile_id => 1, #default profile id
|
||||||
|
type => $type // 'reseller',
|
||||||
|
);
|
||||||
|
_info("contract ID $provider->{contract}->{id} created");
|
||||||
|
$provider->{reseller} = _create_reseller(
|
||||||
|
contract_id => $provider->{contract}->{id},
|
||||||
|
name => $reseller_name, #"test <t> <n>",
|
||||||
|
);
|
||||||
|
_info("reseller '$reseller_name' created");
|
||||||
|
if (defined $provider_rate) {
|
||||||
|
my $profile_fee = {};
|
||||||
|
($profile_fee->{profile},
|
||||||
|
$profile_fee->{zone},
|
||||||
|
$profile_fee->{fee},
|
||||||
|
$profile_fee->{fees}) = _setup_fees($provider->{reseller},
|
||||||
|
%$provider_rate
|
||||||
|
);
|
||||||
|
$provider->{profile} = $profile_fee->{profile};
|
||||||
|
$provider->{provider_fee} = $profile_fee;
|
||||||
|
$provider->{contract} = _update_contract(
|
||||||
|
id => $provider->{contract}->{id},
|
||||||
|
billing_profile_id => $provider->{profile}->{id},
|
||||||
|
);
|
||||||
|
_info("contract ID $provider->{contract}->{id} updated");
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider->{domain} = _create_domain(
|
||||||
|
reseller_id => $provider->{reseller}->{id},
|
||||||
|
#domain => $domain_name.'.<t>',
|
||||||
|
domain => $domain_name,
|
||||||
|
);
|
||||||
|
_info("domain '$domain_name' created");
|
||||||
|
$provider->{subscriber_fees} = [];
|
||||||
|
foreach my $rate (@$subscriber_rates) {
|
||||||
|
my $profile_fee = {};
|
||||||
|
($profile_fee->{profile},
|
||||||
|
$profile_fee->{zone},
|
||||||
|
$profile_fee->{fee},
|
||||||
|
$profile_fee->{fees}) = _setup_fees($provider->{reseller},
|
||||||
|
%$rate
|
||||||
|
);
|
||||||
|
push(@{$provider->{subscriber_fees}},$profile_fee);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _load_provider {
|
||||||
|
my ($provider,$reseller_name,$domain_name) = @_;
|
||||||
|
|
||||||
|
$provider->{reseller} = _find_entity('NGCP::BulkProcessor::RestRequests::Trunk::Resellers',
|
||||||
|
name => $reseller_name,
|
||||||
|
);
|
||||||
|
if (defined $provider->{reseller}) {
|
||||||
|
_info("reseller '$reseller_name' found");
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider->{contract} = NGCP::BulkProcessor::RestRequests::Trunk::Contracts::get_item($provider->{reseller}->{contract_id});
|
||||||
|
if (defined $provider->{contract}) {
|
||||||
|
_info("contract ID $provider->{reseller}->{contract_id} found");
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider->{contact} = NGCP::BulkProcessor::RestRequests::Trunk::SystemContacts::get_item($provider->{contract}->{contact_id});
|
||||||
|
if (defined $provider->{contact}) {
|
||||||
|
_info("contact ID $provider->{contract}->{contact_id} found");
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider->{domain} = _find_entity('NGCP::BulkProcessor::RestRequests::Trunk::Domains',
|
||||||
|
domain => $domain_name,
|
||||||
|
);
|
||||||
|
if (defined $provider->{domain}) {
|
||||||
|
_info("domain '$domain_name' found");
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $provider_profile = NGCP::BulkProcessor::RestRequests::Trunk::BillingProfiles::get_item($provider->{contract}->{billing_profile_id});
|
||||||
|
if (defined $provider_profile) {
|
||||||
|
_info("provider billing profile ID $provider_profile->{id} found");
|
||||||
|
}
|
||||||
|
if (defined $provider_profile) {
|
||||||
|
my $profile_fee = {};
|
||||||
|
($profile_fee->{profile},
|
||||||
|
$profile_fee->{zone},
|
||||||
|
$profile_fee->{fee},
|
||||||
|
$profile_fee->{fees}) = _load_fees($provider_profile);
|
||||||
|
$provider->{profile} = $profile_fee->{profile};
|
||||||
|
$provider->{provider_fee} = $profile_fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider->{subscriber_fees} = [];
|
||||||
|
foreach my $subscriber_profile (@{NGCP::BulkProcessor::RestRequests::Trunk::BillingProfiles::findby_resellerid($provider->{reseller}->{id})}) {
|
||||||
|
next if (defined $provider_profile and $provider_profile->{id} == $subscriber_profile->{id});
|
||||||
|
_info("subscriber billing profile ID $subscriber_profile->{id} found");
|
||||||
|
my $profile_fee = {};
|
||||||
|
($profile_fee->{profile},
|
||||||
|
$profile_fee->{zone},
|
||||||
|
$profile_fee->{fee},
|
||||||
|
$profile_fee->{fees}) = _load_fees($subscriber_profile);
|
||||||
|
push(@{$provider->{subscriber_fees}},$profile_fee);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _load_fees {
|
||||||
|
|
||||||
|
my ($profile) = @_;
|
||||||
|
my $result = 1;
|
||||||
|
my $zone = NGCP::BulkProcessor::RestRequests::Trunk::BillingZones::findby_billingprofileid($profile->{id})->[0];
|
||||||
|
$result &= defined $profile;
|
||||||
|
_info("billing zone ID $zone->{id} found") if $result;
|
||||||
|
my $fees = [];
|
||||||
|
$fees = NGCP::BulkProcessor::RestRequests::Trunk::BillingFees::findby_billingprofileid($profile->{id}) if $result;
|
||||||
|
foreach my $fee (@$fees) {
|
||||||
|
_info("billing fee ID $fee->{id} found");
|
||||||
|
}
|
||||||
|
return ($profile,$zone,$fees->[0],$fees);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _setup_fees {
|
||||||
|
my ($reseller,%params) = @_;
|
||||||
|
my $prepaid = delete $params{prepaid};
|
||||||
|
my $peaktime_weekdays = delete $params{peaktime_weekdays};
|
||||||
|
my $peaktime_specials = delete $params{peaktime_special};
|
||||||
|
my $interval_free_time = delete $params{interval_free_time};
|
||||||
|
#my $interval_free_cash = delete $params{interval_free_cash};
|
||||||
|
my $profile = _create_billing_profile(
|
||||||
|
reseller_id => $reseller->{id},
|
||||||
|
(defined $prepaid ? (prepaid => $prepaid) : ()),
|
||||||
|
(defined $peaktime_weekdays ? (peaktime_weekdays => $peaktime_weekdays) : ()),
|
||||||
|
(defined $peaktime_specials ? (peaktime_special => $peaktime_specials) : ()),
|
||||||
|
(defined $interval_free_time ? (interval_free_time => $interval_free_time) : ()),
|
||||||
|
#(defined $interval_free_cash ? (interval_free_cash => $interval_free_cash) : ()),
|
||||||
|
);
|
||||||
|
_info("billing profile ID $profile->{id} created");
|
||||||
|
my $zone = _create_billing_zone(
|
||||||
|
billing_profile_id => $profile->{id},
|
||||||
|
);
|
||||||
|
_info("billing zone ID $profile->{id} created");
|
||||||
|
my @fees = ();
|
||||||
|
if (exists $params{fees}) {
|
||||||
|
foreach my $fee (@{ $params{fees} }) {
|
||||||
|
push(@fees,_create_billing_fee(
|
||||||
|
billing_profile_id => $profile->{id},
|
||||||
|
billing_zone_id => $zone->{id},
|
||||||
|
%$fee,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
push(@fees,_create_billing_fee(
|
||||||
|
billing_profile_id => $profile->{id},
|
||||||
|
billing_zone_id => $zone->{id},
|
||||||
|
direction => "out",
|
||||||
|
destination => ".",
|
||||||
|
%params,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return ($profile,$zone,$fees[0],\@fees);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_systemcontact {
|
||||||
|
|
||||||
|
return _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::SystemContacts',
|
||||||
|
firstname => "syst_contact_<n>_first",
|
||||||
|
lastname => "syst_contact_<n>_last",
|
||||||
|
email => "syst_contact<n>\@custcontact.invalid",
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_contract {
|
||||||
|
|
||||||
|
return _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::Contracts',
|
||||||
|
status => "active",
|
||||||
|
type => "reseller",
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _update_contract {
|
||||||
|
|
||||||
|
return _update_entity('NGCP::BulkProcessor::RestRequests::Trunk::Contracts',
|
||||||
|
id => undef,
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_reseller {
|
||||||
|
|
||||||
|
return _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::Resellers',
|
||||||
|
status => "active",
|
||||||
|
name => "test <t> <n>",
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_domain {
|
||||||
|
|
||||||
|
return _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::Domains',
|
||||||
|
domain => 'test_<t>_<n>.example.org',
|
||||||
|
#reseller_id => $default_reseller_id,
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_billing_profile {
|
||||||
|
|
||||||
|
return _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::BillingProfiles',
|
||||||
|
name => "test <t> <n>",
|
||||||
|
handle => "test_<t>_<n>",
|
||||||
|
#reseller_id => $default_reseller_id,
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_billing_zone {
|
||||||
|
|
||||||
|
return _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::BillingZones',
|
||||||
|
zone => 'test<n>',
|
||||||
|
detail => 'test <n>',
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_billing_fee {
|
||||||
|
|
||||||
|
my $fee = _create_entity('NGCP::BulkProcessor::RestRequests::Trunk::BillingFees',
|
||||||
|
@_,
|
||||||
|
);
|
||||||
|
_info("billing fee ID $fee->{id} created");
|
||||||
|
return $fee;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _create_entity {
|
||||||
|
|
||||||
|
my $class = shift;
|
||||||
|
my (@params) = @_;
|
||||||
|
my $map = _get_entity_map($class);
|
||||||
|
my $n = 1 + scalar keys %$map;
|
||||||
|
Data::Rmap::rmap { $_ =~ s/<n>/$n/ if defined $_; $_ =~ s/<i>/$n/ if defined $_; $_ =~ s/<t>/$t/ if defined $_; } @params;
|
||||||
|
no strict 'refs';
|
||||||
|
my $entity = &{$class . '::create_item'}({@params},1);
|
||||||
|
$map->{$entity->{id}} = $entity;
|
||||||
|
return $entity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _update_entity {
|
||||||
|
|
||||||
|
my $class = shift;
|
||||||
|
my (@params) = @_;
|
||||||
|
my $map = _get_entity_map($class);
|
||||||
|
#my $n = 1 + scalar keys %$map;
|
||||||
|
Data::Rmap::rmap { $_ =~ s/<t>/$t/ if defined $_; } @params;
|
||||||
|
my $data = {@params};
|
||||||
|
my $id = delete $data->{id};
|
||||||
|
no strict 'refs';
|
||||||
|
my $entity = &{$class . '::update_item'}($id,$data);
|
||||||
|
$entity->{id} = $id;
|
||||||
|
$map->{$id} = $entity;
|
||||||
|
return $entity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _find_entity {
|
||||||
|
|
||||||
|
my $class = shift;
|
||||||
|
my (@params) = @_;
|
||||||
|
foreach my $param (@params) {
|
||||||
|
return undef if $param =~ /<n>|<i>|<t>/;
|
||||||
|
}
|
||||||
|
no strict 'refs';
|
||||||
|
return &{$class . '::get_item_filtered'}({@params});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _get_entity_map {
|
||||||
|
my $class = shift;
|
||||||
|
if (!exists $entity_maps{$class}) {
|
||||||
|
$entity_maps{$class} = {};
|
||||||
|
}
|
||||||
|
return $entity_maps{$class};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub _info {
|
||||||
|
|
||||||
|
my ($message,$debug) = @_;
|
||||||
|
if ($debug) {
|
||||||
|
processing_debug(threadid(),$message,getlogger(__PACKAGE__));
|
||||||
|
} else {
|
||||||
|
processing_info(threadid(),$message,getlogger(__PACKAGE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -0,0 +1,255 @@
|
|||||||
|
package NGCP::BulkProcessor::Projects::Massive::Generator::Preferences;
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
## no critic
|
||||||
|
|
||||||
|
no strict 'refs';
|
||||||
|
|
||||||
|
use threads::shared qw();
|
||||||
|
#use List::Util qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Projects::Migration::Teletek::Settings qw(
|
||||||
|
$dry
|
||||||
|
$skip_errors
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Logging qw (
|
||||||
|
getlogger
|
||||||
|
processing_info
|
||||||
|
processing_debug
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::LogError qw(
|
||||||
|
rowprocessingerror
|
||||||
|
rowprocessingwarn
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::billing::ncos_levels qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::billing::domains qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::billing::domain_resellers qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::billing::voip_subscribers qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Projects::Migration::Teletek::Dao::import::Subscriber qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_subscribers qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_preferences qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_usr_preferences qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_aig_sequence qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_allowed_ip_groups qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::ConnectorPool qw(
|
||||||
|
get_xa_db
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Projects::Migration::Teletek::ProjectConnectorPool qw(
|
||||||
|
destroy_all_dbs
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Utils qw(threadid);
|
||||||
|
|
||||||
|
require Exporter;
|
||||||
|
our @ISA = qw(Exporter);
|
||||||
|
our @EXPORT_OK = qw(
|
||||||
|
|
||||||
|
clear_subscriber_preferences
|
||||||
|
delete_subscriber_preference
|
||||||
|
set_subscriber_preference
|
||||||
|
get_subscriber_preference
|
||||||
|
|
||||||
|
set_allowed_ips_preferences
|
||||||
|
cleanup_aig_sequence_ids
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
sub cleanup_aig_sequence_ids {
|
||||||
|
my ($context) = @_;
|
||||||
|
eval {
|
||||||
|
$context->{db}->db_begin();
|
||||||
|
if (NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_aig_sequence::cleanup_ids($context->{db})) {
|
||||||
|
_info($context,'voip_aig_sequence cleaned up');
|
||||||
|
}
|
||||||
|
if ($dry) {
|
||||||
|
$context->{db}->db_rollback(0);
|
||||||
|
} else {
|
||||||
|
$context->{db}->db_commit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
my $err = $@;
|
||||||
|
if ($err) {
|
||||||
|
eval {
|
||||||
|
$context->{db}->db_rollback(1);
|
||||||
|
};
|
||||||
|
if ($skip_errors) {
|
||||||
|
_warn($context,"database problem with voip_aig_sequence clean up: " . $err);
|
||||||
|
} else {
|
||||||
|
_error($context,"database problem with voip_aig_sequence clean up: " . $err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub set_allowed_ips_preferences {
|
||||||
|
|
||||||
|
my ($context,$subscriber_id,$sip_username,$attribute,$allowed_ips) = @_;
|
||||||
|
|
||||||
|
#my $subscriber_id = $context->{prov_subscriber}->{id} ;
|
||||||
|
#my $attribute = $context->{attributes}->{allowed_ips_grp};
|
||||||
|
|
||||||
|
my $allowed_ips_grp_attribute_preference = NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_usr_preferences::findby_subscriberid_attributeid(
|
||||||
|
$context->{db},$subscriber_id,$attribute->{id})->[0];
|
||||||
|
|
||||||
|
my ($allowed_ip_group_id,$allowed_ip_group_preferrence_id);
|
||||||
|
|
||||||
|
if (defined $allowed_ips_grp_attribute_preference) {
|
||||||
|
$allowed_ip_group_id = $allowed_ips_grp_attribute_preference->{value};
|
||||||
|
$allowed_ip_group_preferrence_id = $allowed_ips_grp_attribute_preference->{id};
|
||||||
|
NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_allowed_ip_groups::delete_groupid($context->{db},$allowed_ip_group_id);
|
||||||
|
_info($context,"allowed ips group for subscriber $sip_username exists, ipnets deleted",1);
|
||||||
|
} else {
|
||||||
|
$allowed_ip_group_id = NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_aig_sequence::increment($context->{db});
|
||||||
|
_info($context,"new allowed ips group id for subscriber $sip_username aquired",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
my $allowed_ips_grp_ipnet_ids = NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_allowed_ip_groups::insert_rows($context->{db},$allowed_ip_group_id,$allowed_ips);
|
||||||
|
_info($context,"ipnets for allowed ips group for subscriber $sip_username created",1);
|
||||||
|
|
||||||
|
if (not defined $allowed_ips_grp_attribute_preference) {
|
||||||
|
$allowed_ip_group_preferrence_id = NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_usr_preferences::insert_row($context->{db},
|
||||||
|
attribute_id => $attribute->{id},
|
||||||
|
subscriber_id => $subscriber_id,
|
||||||
|
value => $allowed_ip_group_id,
|
||||||
|
);
|
||||||
|
_info($context,"new allowed ips group preference value for subscriber $sip_username added",1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($allowed_ip_group_id,$allowed_ip_group_preferrence_id);
|
||||||
|
|
||||||
|
#$context->{preferences}->{allowed_ips_grp} = { id => $allowed_ip_group_preferrence_id, $allowed_ip_group_id };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
my %get_preference_sub_names = (
|
||||||
|
voip_usr_preferences => 'findby_subscriberid_attributeid',
|
||||||
|
);
|
||||||
|
my %preference_id_cols = (
|
||||||
|
voip_usr_preferences => 'subscriber_id',
|
||||||
|
);
|
||||||
|
|
||||||
|
sub clear_subscriber_preferences {
|
||||||
|
my ($context,$subscriber_id,$attribute,$except_value) = @_;
|
||||||
|
return _clear_preferences($context,'voip_usr_preferences',$subscriber_id,$attribute,$except_value);
|
||||||
|
}
|
||||||
|
sub delete_subscriber_preference {
|
||||||
|
my ($context,$subscriber_id,$attribute,$value) = @_;
|
||||||
|
return _delete_preference($context,'voip_usr_preferences',$subscriber_id,$attribute,$value);
|
||||||
|
}
|
||||||
|
sub set_subscriber_preference {
|
||||||
|
my ($context,$subscriber_id,$attribute,$value) = @_;
|
||||||
|
return _set_preference($context,'voip_usr_preferences',$subscriber_id,$attribute,$value);
|
||||||
|
}
|
||||||
|
sub get_subscriber_preference {
|
||||||
|
my ($context,$subscriber_id,$attribute) = @_;
|
||||||
|
return _get_preference($context,'voip_usr_preferences',$subscriber_id,$attribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _clear_preferences {
|
||||||
|
my ($context,$pref_type,$id,$attribute,$except_value) = @_;
|
||||||
|
|
||||||
|
return &{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::delete_preferences'}($context->{db},
|
||||||
|
$id, $attribute->{id}, defined $except_value ? { 'NOT IN' => $except_value } : undef);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _delete_preference {
|
||||||
|
my ($context,$pref_type,$id,$attribute,$value) = @_;
|
||||||
|
|
||||||
|
return &{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::delete_preferences'}($context->{db},
|
||||||
|
$id, $attribute->{id}, { 'IN' => $value } );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _set_preference {
|
||||||
|
my ($context,$pref_type,$id,$attribute,$value) = @_;
|
||||||
|
|
||||||
|
if ($attribute->{max_occur} == 1) {
|
||||||
|
my $old_preferences = &{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::' . $get_preference_sub_names{$pref_type}}($context->{db},
|
||||||
|
$id,$attribute->{id});
|
||||||
|
if (defined $value) {
|
||||||
|
if ((scalar @$old_preferences) == 1) {
|
||||||
|
&{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::update_row'}($context->{db},{
|
||||||
|
id => $old_preferences->[0]->{id},
|
||||||
|
value => $value,
|
||||||
|
});
|
||||||
|
return $old_preferences->[0]->{id};
|
||||||
|
} else {
|
||||||
|
if ((scalar @$old_preferences) > 1) {
|
||||||
|
&{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::delete_preferences'}($context->{db},
|
||||||
|
$id,$attribute->{id});
|
||||||
|
}
|
||||||
|
return &{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::insert_row'}($context->{db},
|
||||||
|
attribute_id => $attribute->{id},
|
||||||
|
$preference_id_cols{$pref_type} => $id,
|
||||||
|
value => $value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
&{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::delete_preferences'}($context->{db},
|
||||||
|
$id,$attribute->{id});
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (defined $value) {
|
||||||
|
return &{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::insert_row'}($context->{db},
|
||||||
|
attribute_id => $attribute->{id},
|
||||||
|
$preference_id_cols{$pref_type} => $id,
|
||||||
|
value => $value,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _get_preference {
|
||||||
|
my ($context,$pref_type,$id,$attribute) = @_;
|
||||||
|
|
||||||
|
my $preferences = &{'NGCP::BulkProcessor::Dao::Trunk::provisioning::' . $pref_type . '::' . $get_preference_sub_names{$pref_type}}($context->{db},
|
||||||
|
$id,$attribute->{id});
|
||||||
|
|
||||||
|
if ($attribute->{max_occur} == 1) {
|
||||||
|
return $preferences->[0];
|
||||||
|
} else {
|
||||||
|
return $preferences;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _error {
|
||||||
|
|
||||||
|
my ($context,$message) = @_;
|
||||||
|
$context->{error_count} = $context->{error_count} + 1;
|
||||||
|
rowprocessingerror($context->{tid},$message,getlogger(__PACKAGE__));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _warn {
|
||||||
|
|
||||||
|
my ($context,$message) = @_;
|
||||||
|
$context->{warning_count} = $context->{warning_count} + 1;
|
||||||
|
rowprocessingwarn($context->{tid},$message,getlogger(__PACKAGE__));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _info {
|
||||||
|
|
||||||
|
my ($context,$message,$debug) = @_;
|
||||||
|
if ($debug) {
|
||||||
|
processing_debug($context->{tid},$message,getlogger(__PACKAGE__));
|
||||||
|
} else {
|
||||||
|
processing_info($context->{tid},$message,getlogger(__PACKAGE__));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,198 @@
|
|||||||
|
package NGCP::BulkProcessor::Projects::Massive::Generator::Settings;
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
## no critic
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Globals qw(
|
||||||
|
$working_path
|
||||||
|
$enablemultithreading
|
||||||
|
$cpucount
|
||||||
|
create_path
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Logging qw(
|
||||||
|
getlogger
|
||||||
|
scriptinfo
|
||||||
|
configurationinfo
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::LogError qw(
|
||||||
|
fileerror
|
||||||
|
filewarn
|
||||||
|
configurationwarn
|
||||||
|
configurationerror
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::LoadConfig qw(
|
||||||
|
split_tuple
|
||||||
|
parse_regexp
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::Utils qw(prompt timestampdigits);
|
||||||
|
#format_number check_ipnet
|
||||||
|
|
||||||
|
require Exporter;
|
||||||
|
our @ISA = qw(Exporter);
|
||||||
|
our @EXPORT_OK = qw(
|
||||||
|
update_settings
|
||||||
|
update_provider_config
|
||||||
|
check_dry
|
||||||
|
|
||||||
|
$input_path
|
||||||
|
$output_path
|
||||||
|
|
||||||
|
$defaultsettings
|
||||||
|
$defaultconfig
|
||||||
|
|
||||||
|
$dry
|
||||||
|
$skip_errors
|
||||||
|
$force
|
||||||
|
$deadlock_retries
|
||||||
|
|
||||||
|
$provision_subscriber_multithreading
|
||||||
|
$provision_subscriber_numofthreads
|
||||||
|
$provision_subscriber_count
|
||||||
|
$webpassword_length
|
||||||
|
$webusername_length
|
||||||
|
$sippassword_length
|
||||||
|
$sipusername_length
|
||||||
|
|
||||||
|
@provider_config
|
||||||
|
@providers
|
||||||
|
$providers_yml
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
our $defaultconfig = 'config.cfg';
|
||||||
|
our $defaultsettings = 'settings.cfg';
|
||||||
|
|
||||||
|
our $input_path = $working_path . 'input/';
|
||||||
|
our $output_path = $working_path . 'output/';
|
||||||
|
|
||||||
|
our $force = 0;
|
||||||
|
our $dry = 0;
|
||||||
|
our $skip_errors = 0;
|
||||||
|
|
||||||
|
our $deadlock_retries = 8;
|
||||||
|
|
||||||
|
our $provision_subscriber_multithreading = $enablemultithreading;
|
||||||
|
our $provision_subscriber_numofthreads = $cpucount;
|
||||||
|
our $webpassword_length = 8;
|
||||||
|
our $webusername_length = 8;
|
||||||
|
our $sippassword_length = 16;
|
||||||
|
our $sipusername_length = 8;
|
||||||
|
our $provision_subscriber_count = 0;
|
||||||
|
|
||||||
|
our @provider_config = ();
|
||||||
|
our @providers = ();
|
||||||
|
our $providers_yml = undef;
|
||||||
|
|
||||||
|
sub update_settings {
|
||||||
|
|
||||||
|
my ($data,$configfile) = @_;
|
||||||
|
|
||||||
|
if (defined $data) {
|
||||||
|
|
||||||
|
my $result = 1;
|
||||||
|
|
||||||
|
#&$configurationinfocode("testinfomessage",$configlogger);
|
||||||
|
|
||||||
|
$result &= _prepare_working_paths(1);
|
||||||
|
#if ($data->{report_filename}) {
|
||||||
|
# $report_filename = $output_path . sprintf('/' . $data->{report_filename},timestampdigits());
|
||||||
|
# if (-e $report_filename and (unlink $report_filename) == 0) {
|
||||||
|
# filewarn('cannot remove ' . $report_filename . ': ' . $!,getlogger(__PACKAGE__));
|
||||||
|
# $report_filename = undef;
|
||||||
|
# }
|
||||||
|
#} else {
|
||||||
|
# $report_filename = undef;
|
||||||
|
#}
|
||||||
|
|
||||||
|
$dry = $data->{dry} if exists $data->{dry};
|
||||||
|
$skip_errors = $data->{skip_errors} if exists $data->{skip_errors};
|
||||||
|
|
||||||
|
$provision_subscriber_multithreading = $data->{provision_subscriber_multithreading} if exists $data->{provision_subscriber_multithreading};
|
||||||
|
$provision_subscriber_numofthreads = _get_numofthreads($cpucount,$data,'provision_subscriber_numofthreads');
|
||||||
|
$webpassword_length = $data->{webpassword_length} if exists $data->{webpassword_length};
|
||||||
|
$webusername_length = $data->{webusername_length} if exists $data->{webusername_length};
|
||||||
|
$sippassword_length = $data->{sippassword_length} if exists $data->{sippassword_length};
|
||||||
|
$sipusername_length = $data->{sipusername_length} if exists $data->{sipusername_length};
|
||||||
|
$provision_subscriber_count = $data->{provision_subscriber_count} if exists $data->{provision_subscriber_count};
|
||||||
|
|
||||||
|
|
||||||
|
$providers_yml = $data->{providers_yml} if exists $data->{providers_yml};
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub update_provider_config {
|
||||||
|
|
||||||
|
my ($data,$configfile) = @_;
|
||||||
|
|
||||||
|
if (defined $data) {
|
||||||
|
|
||||||
|
my $result = 1;
|
||||||
|
|
||||||
|
eval {
|
||||||
|
@provider_config = @$data;
|
||||||
|
};
|
||||||
|
if ($@) { # or 'HASH' ne ref $barring_profiles or (scalar keys %$barring_profiles) == 0) {
|
||||||
|
@provider_config = () unless scalar @provider_config;
|
||||||
|
configurationerror($configfile,'cannot load reseller config',getlogger(__PACKAGE__));
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _prepare_working_paths {
|
||||||
|
|
||||||
|
my ($create) = @_;
|
||||||
|
my $result = 1;
|
||||||
|
my $path_result;
|
||||||
|
|
||||||
|
($path_result,$input_path) = create_path($working_path . 'input',$input_path,$create,\&fileerror,getlogger(__PACKAGE__));
|
||||||
|
$result &= $path_result;
|
||||||
|
($path_result,$output_path) = create_path($working_path . 'output',$output_path,$create,\&fileerror,getlogger(__PACKAGE__));
|
||||||
|
$result &= $path_result;
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _get_numofthreads {
|
||||||
|
my ($default_value,$data,$key) = @_;
|
||||||
|
my $numofthreads = $default_value;
|
||||||
|
$numofthreads = $data->{$key} if exists $data->{$key};
|
||||||
|
$numofthreads = $cpucount if $numofthreads > $cpucount;
|
||||||
|
return $numofthreads;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub check_dry {
|
||||||
|
|
||||||
|
if ($dry) {
|
||||||
|
scriptinfo('running in dry mode - NGCP databases will not be modified',getlogger(__PACKAGE__));
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
scriptinfo('NO DRY MODE - NGCP DATABASES WILL BE MODIFIED!',getlogger(__PACKAGE__));
|
||||||
|
if (!$force) {
|
||||||
|
if ('yes' eq lc(prompt("Type 'yes' to proceed: "))) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scriptinfo('force option applied',getlogger(__PACKAGE__));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -0,0 +1,62 @@
|
|||||||
|
##general settings:
|
||||||
|
working_path = /var/sipwise
|
||||||
|
#cpucount = 4
|
||||||
|
enablemultithreading = 1
|
||||||
|
|
||||||
|
##gearman/service listener config:
|
||||||
|
jobservers = 127.0.0.1:4730
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "accounting" db:
|
||||||
|
accounting_host = localhost
|
||||||
|
accounting_port = 3306
|
||||||
|
accounting_databasename = accounting
|
||||||
|
accounting_username = root
|
||||||
|
accounting_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "billing" db:
|
||||||
|
billing_host = localhost
|
||||||
|
billing_port = 3306
|
||||||
|
billing_databasename = billing
|
||||||
|
billing_username = root
|
||||||
|
billing_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "provisioning" db:
|
||||||
|
provisioning_host = localhost
|
||||||
|
provisioning_port = 3306
|
||||||
|
provisioning_databasename = provisioning
|
||||||
|
provisioning_username = root
|
||||||
|
provisioning_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "kamailio" db:
|
||||||
|
kamailio_host = localhost
|
||||||
|
kamailio_port = 3306
|
||||||
|
kamailio_databasename = kamailio
|
||||||
|
kamailio_username = root
|
||||||
|
kamailio_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - default db for distributed transactions (XA) to connect to:
|
||||||
|
xa_host = localhost
|
||||||
|
xa_port = 3306
|
||||||
|
xa_databasename = billing
|
||||||
|
xa_username = root
|
||||||
|
xa_password =
|
||||||
|
|
||||||
|
##NGCP REST-API connectivity:
|
||||||
|
ngcprestapi_uri = https://10.0.2.15:1443
|
||||||
|
ngcprestapi_username = administrator
|
||||||
|
ngcprestapi_password = administrator
|
||||||
|
ngcprestapi_realm = api_admin_http
|
||||||
|
|
||||||
|
##sending email:
|
||||||
|
emailenable = 0
|
||||||
|
erroremailrecipient =
|
||||||
|
warnemailrecipient =
|
||||||
|
completionemailrecipient = rkrenn@sipwise.com
|
||||||
|
doneemailrecipient =
|
||||||
|
|
||||||
|
##logging:
|
||||||
|
fileloglevel = INFO
|
||||||
|
#DEBUG
|
||||||
|
screenloglevel = INFO
|
||||||
|
#INFO
|
||||||
|
emailloglevel = OFF
|
@ -0,0 +1,62 @@
|
|||||||
|
##general settings:
|
||||||
|
working_path = /home/rkrenn/temp/massive
|
||||||
|
#cpucount = 4
|
||||||
|
enablemultithreading = 1
|
||||||
|
|
||||||
|
##gearman/service listener config:
|
||||||
|
jobservers = 127.0.0.1:4730
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "accounting" db:
|
||||||
|
accounting_host = 192.168.0.84
|
||||||
|
accounting_port = 3306
|
||||||
|
accounting_databasename = accounting
|
||||||
|
accounting_username = root
|
||||||
|
accounting_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "billing" db:
|
||||||
|
billing_host = 192.168.0.84
|
||||||
|
billing_port = 3306
|
||||||
|
billing_databasename = billing
|
||||||
|
billing_username = root
|
||||||
|
billing_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "provisioning" db:
|
||||||
|
provisioning_host = 192.168.0.84
|
||||||
|
provisioning_port = 3306
|
||||||
|
provisioning_databasename = provisioning
|
||||||
|
provisioning_username = root
|
||||||
|
provisioning_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - "kamailio" db:
|
||||||
|
kamailio_host = 192.168.0.84
|
||||||
|
kamailio_port = 3306
|
||||||
|
kamailio_databasename = kamailio
|
||||||
|
kamailio_username = root
|
||||||
|
kamailio_password =
|
||||||
|
|
||||||
|
##NGCP MySQL connectivity - default db for distributed transactions (XA) to connect to:
|
||||||
|
xa_host = 192.168.0.84
|
||||||
|
xa_port = 3306
|
||||||
|
xa_databasename = ngcp
|
||||||
|
xa_username = root
|
||||||
|
xa_password =
|
||||||
|
|
||||||
|
##NGCP REST-API connectivity:
|
||||||
|
ngcprestapi_uri = https://127.0.0.1:1443
|
||||||
|
ngcprestapi_username = administrator
|
||||||
|
ngcprestapi_password = administrator
|
||||||
|
ngcprestapi_realm = api_admin_http
|
||||||
|
|
||||||
|
##sending email:
|
||||||
|
emailenable = 0
|
||||||
|
erroremailrecipient =
|
||||||
|
warnemailrecipient =
|
||||||
|
completionemailrecipient = rkrenn@sipwise.com
|
||||||
|
doneemailrecipient =
|
||||||
|
|
||||||
|
##logging:
|
||||||
|
fileloglevel = INFO
|
||||||
|
#DEBUG
|
||||||
|
screenloglevel = INFO
|
||||||
|
#INFO
|
||||||
|
emailloglevel = OFF
|
@ -0,0 +1,284 @@
|
|||||||
|
use strict;
|
||||||
|
|
||||||
|
## no critic
|
||||||
|
|
||||||
|
use File::Basename;
|
||||||
|
use Cwd;
|
||||||
|
use lib Cwd::abs_path(File::Basename::dirname(__FILE__) . '/../../../../../');
|
||||||
|
|
||||||
|
use Getopt::Long qw(GetOptions);
|
||||||
|
use Fcntl qw(LOCK_EX LOCK_NB);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Globals qw();
|
||||||
|
use NGCP::BulkProcessor::Projects::Massive::Generator::Settings qw(
|
||||||
|
update_settings
|
||||||
|
update_provider_config
|
||||||
|
check_dry
|
||||||
|
$output_path
|
||||||
|
$defaultsettings
|
||||||
|
$defaultconfig
|
||||||
|
$dry
|
||||||
|
$skip_errors
|
||||||
|
$force
|
||||||
|
|
||||||
|
@provider_config
|
||||||
|
@providers
|
||||||
|
$providers_yml
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Logging qw(
|
||||||
|
init_log
|
||||||
|
getlogger
|
||||||
|
$attachmentlogfile
|
||||||
|
scriptinfo
|
||||||
|
cleanuplogfiles
|
||||||
|
$currentlogfile
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::LogError qw (
|
||||||
|
completion
|
||||||
|
done
|
||||||
|
scriptwarn
|
||||||
|
scripterror
|
||||||
|
filewarn
|
||||||
|
fileerror
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::LoadConfig qw(
|
||||||
|
load_config
|
||||||
|
$SIMPLE_CONFIG_TYPE
|
||||||
|
$YAML_CONFIG_TYPE
|
||||||
|
$ANY_CONFIG_TYPE
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::Array qw(removeduplicates);
|
||||||
|
use NGCP::BulkProcessor::Utils qw(getscriptpath prompt cleanupdir);
|
||||||
|
use NGCP::BulkProcessor::Mail qw(
|
||||||
|
cleanupmsgfiles
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::SqlConnectors::CSVDB qw(cleanupcvsdirs);
|
||||||
|
use NGCP::BulkProcessor::SqlConnectors::SQLiteDB qw(cleanupdbfiles);
|
||||||
|
use NGCP::BulkProcessor::RestConnectors::NGCPRestApi qw(cleanupcertfiles);
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::ConnectorPool qw(destroy_dbs);
|
||||||
|
|
||||||
|
#use NGCP::BulkProcessor::Projects::Massive::Generator::Dao::Blah qw();
|
||||||
|
|
||||||
|
#use NGCP::BulkProcessor::Dao::Trunk::accounting::cdr qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::billing::contracts qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::billing::voip_subscribers qw();
|
||||||
|
use NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_dbaliases qw();
|
||||||
|
|
||||||
|
use NGCP::BulkProcessor::Projects::Massive::Generator::Provisioning qw(
|
||||||
|
provision_subscribers
|
||||||
|
);
|
||||||
|
use NGCP::BulkProcessor::Projects::Massive::Generator::Api qw(
|
||||||
|
setup_provider
|
||||||
|
);
|
||||||
|
|
||||||
|
scripterror(getscriptpath() . ' already running',getlogger(getscriptpath())) unless flock DATA, LOCK_EX | LOCK_NB; # not tested on windows yet
|
||||||
|
|
||||||
|
my @TASK_OPTS = ();
|
||||||
|
|
||||||
|
my $tasks = [];
|
||||||
|
|
||||||
|
my $cleanup_task_opt = 'cleanup';
|
||||||
|
push(@TASK_OPTS,$cleanup_task_opt);
|
||||||
|
my $cleanup_all_task_opt = 'cleanup_all';
|
||||||
|
push(@TASK_OPTS,$cleanup_all_task_opt);
|
||||||
|
|
||||||
|
my $setup_provider_task_opt = 'setup_provider';
|
||||||
|
push(@TASK_OPTS,$setup_provider_task_opt);
|
||||||
|
|
||||||
|
my $provision_subscriber_task_opt = 'provision_subscriber';
|
||||||
|
push(@TASK_OPTS,$provision_subscriber_task_opt);
|
||||||
|
|
||||||
|
if (init()) {
|
||||||
|
main();
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub init {
|
||||||
|
|
||||||
|
my $configfile = $defaultconfig;
|
||||||
|
my $settingsfile = $defaultsettings;
|
||||||
|
|
||||||
|
return 0 unless GetOptions(
|
||||||
|
"config=s" => \$configfile,
|
||||||
|
"settings=s" => \$settingsfile,
|
||||||
|
"task=s" => $tasks,
|
||||||
|
#"run=s" => \$run_id,
|
||||||
|
"dry" => \$dry,
|
||||||
|
"skip-errors" => \$skip_errors,
|
||||||
|
"force" => \$force,
|
||||||
|
); # or scripterror('error in command line arguments',getlogger(getscriptpath()));
|
||||||
|
|
||||||
|
$tasks = removeduplicates($tasks,1);
|
||||||
|
|
||||||
|
my $result = load_config($configfile);
|
||||||
|
init_log();
|
||||||
|
$result &= load_config($settingsfile,\&update_settings,$SIMPLE_CONFIG_TYPE);
|
||||||
|
$result &= load_config($providers_yml,\&update_provider_config,$YAML_CONFIG_TYPE);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sub main() {
|
||||||
|
|
||||||
|
my @messages = ();
|
||||||
|
my @attachmentfiles = ();
|
||||||
|
my $result = 1;
|
||||||
|
my $completion = 0;
|
||||||
|
|
||||||
|
if (defined $tasks and 'ARRAY' eq ref $tasks and (scalar @$tasks) > 0) {
|
||||||
|
scriptinfo('skip-errors: processing won\'t stop upon errors',getlogger(__PACKAGE__)) if $skip_errors;
|
||||||
|
foreach my $task (@$tasks) {
|
||||||
|
|
||||||
|
if (lc($cleanup_task_opt) eq lc($task)) {
|
||||||
|
$result &= cleanup_task(\@messages,0) if taskinfo($cleanup_task_opt,$result);
|
||||||
|
} elsif (lc($cleanup_all_task_opt) eq lc($task)) {
|
||||||
|
$result &= cleanup_task(\@messages,1) if taskinfo($cleanup_all_task_opt,$result);
|
||||||
|
|
||||||
|
} elsif (lc($setup_provider_task_opt) eq lc($task)) {
|
||||||
|
if (taskinfo($setup_provider_task_opt,$result,1)) {
|
||||||
|
next unless check_dry();
|
||||||
|
$result &= setup_provider_task(\@messages);
|
||||||
|
$completion |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} elsif (lc($provision_subscriber_task_opt) eq lc($task)) {
|
||||||
|
if (taskinfo($provision_subscriber_task_opt,$result,1)) {
|
||||||
|
next unless check_dry();
|
||||||
|
$result &= provision_subscriber_task(\@messages);
|
||||||
|
$completion |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$result = 0;
|
||||||
|
scripterror("unknow task option '" . $task . "', must be one of " . join(', ',@TASK_OPTS),getlogger(getscriptpath()));
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = 0;
|
||||||
|
scripterror('at least one task option is required. supported tasks: ' . join(', ',@TASK_OPTS),getlogger(getscriptpath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
push(@attachmentfiles,$attachmentlogfile);
|
||||||
|
if ($completion) {
|
||||||
|
completion(join("\n\n",@messages),\@attachmentfiles,getlogger(getscriptpath()));
|
||||||
|
} else {
|
||||||
|
done(join("\n\n",@messages),\@attachmentfiles,getlogger(getscriptpath()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub taskinfo {
|
||||||
|
my ($task,$result) = @_;
|
||||||
|
scriptinfo($result ? "starting task: '$task'" : "skipping task '$task' due to previous problems",getlogger(getscriptpath()));
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub cleanup_task {
|
||||||
|
my ($messages,$clean_generated) = @_;
|
||||||
|
my $result = 0;
|
||||||
|
if (!$clean_generated or $force or 'yes' eq lc(prompt("Type 'yes' to proceed: "))) {
|
||||||
|
eval {
|
||||||
|
cleanupcvsdirs() if $clean_generated;
|
||||||
|
cleanupdbfiles() if $clean_generated;
|
||||||
|
cleanuplogfiles(\&fileerror,\&filewarn,($currentlogfile,$attachmentlogfile));
|
||||||
|
cleanupmsgfiles(\&fileerror,\&filewarn);
|
||||||
|
cleanupcertfiles();
|
||||||
|
cleanupdir($output_path,1,\&filewarn,getlogger(getscriptpath())) if $clean_generated;
|
||||||
|
$result = 1;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if ($@ or !$result) {
|
||||||
|
push(@$messages,'working directory cleanup INCOMPLETE');
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
push(@$messages,'working directory folders cleaned up');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub setup_provider_task {
|
||||||
|
my ($messages) = @_;
|
||||||
|
my $result = 1;
|
||||||
|
foreach my $params (@provider_config) {
|
||||||
|
my $provider = eval { setup_provider(%$params); };
|
||||||
|
if ($@ or not defined $provider) {
|
||||||
|
$result = 0;
|
||||||
|
last unless $skip_errors;
|
||||||
|
} else {
|
||||||
|
my %pp = (%$params,%$provider);
|
||||||
|
push(@providers,\%pp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my $stats = ": " . (scalar @providers) . ' resellers';
|
||||||
|
#eval {
|
||||||
|
#
|
||||||
|
#};
|
||||||
|
unless ($result) {
|
||||||
|
push(@$messages,"setup providers INCOMPLETE$stats");
|
||||||
|
} else {
|
||||||
|
push(@$messages,"setup providers completed$stats");
|
||||||
|
}
|
||||||
|
#destroy_dbs();
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub provision_subscriber_task {
|
||||||
|
|
||||||
|
my ($messages) = @_;
|
||||||
|
my ($result) = (0);
|
||||||
|
eval {
|
||||||
|
($result) = provision_subscribers();
|
||||||
|
};
|
||||||
|
my $err = $@;
|
||||||
|
my $stats = ":";
|
||||||
|
eval {
|
||||||
|
$stats .= "\n total contracts: " .
|
||||||
|
NGCP::BulkProcessor::Dao::Trunk::billing::contracts::countby_status_resellerid(undef,undef) . ' rows';
|
||||||
|
$stats .= "\n total subscribers: " .
|
||||||
|
NGCP::BulkProcessor::Dao::Trunk::billing::voip_subscribers::countby_status_resellerid(undef,undef) . ' rows';
|
||||||
|
|
||||||
|
$stats .= "\n total aliases: " .
|
||||||
|
NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_dbaliases::countby_subscriberidisprimary(undef,undef) . ' rows';
|
||||||
|
$stats .= "\n primary aliases: " .
|
||||||
|
NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_dbaliases::countby_subscriberidisprimary(undef,1) . ' rows';
|
||||||
|
|
||||||
|
#$stats .= "\n call forwards: " .
|
||||||
|
# NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_cf_mappings::countby_subscriberid_type(undef,undef) . ' rows';
|
||||||
|
#
|
||||||
|
#$stats .= "\n registrations: " .
|
||||||
|
# NGCP::BulkProcessor::Dao::Trunk::kamailio::location::countby_usernamedomain(undef,undef) . ' rows';
|
||||||
|
#
|
||||||
|
#$stats .= "\n trusted sources: " .
|
||||||
|
# NGCP::BulkProcessor::Dao::Trunk::provisioning::voip_trusted_sources::countby_subscriberid(undef) . ' rows';
|
||||||
|
#
|
||||||
|
#$stats .= "\n non-unique contacts skipped:\n " . join("\n ",keys %$nonunique_contacts)
|
||||||
|
# if (scalar keys %$nonunique_contacts) > 0;
|
||||||
|
};
|
||||||
|
if ($err or !$result) {
|
||||||
|
push(@$messages,"provision subscribers INCOMPLETE$stats");
|
||||||
|
} else {
|
||||||
|
push(@$messages,"provision subscribers completed$stats");
|
||||||
|
}
|
||||||
|
destroy_dbs();
|
||||||
|
return $result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#END {
|
||||||
|
# # this should not be required explicitly, but prevents Log4Perl's
|
||||||
|
# # "rootlogger not initialized error upon exit..
|
||||||
|
# destroy_all_dbs
|
||||||
|
#}
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
This exists to allow the locking code at the beginning of the file to work.
|
||||||
|
DO NOT REMOVE THESE LINES!
|
@ -0,0 +1,110 @@
|
|||||||
|
-
|
||||||
|
domain: narf1.com
|
||||||
|
reseller: narf1
|
||||||
|
numbers_per_subscriber: 3
|
||||||
|
cc:
|
||||||
|
- 888
|
||||||
|
- 999
|
||||||
|
ac:
|
||||||
|
- 123
|
||||||
|
- 456
|
||||||
|
sn: '000001-100000'
|
||||||
|
-
|
||||||
|
domain: narf2.com
|
||||||
|
reseller: narf2
|
||||||
|
cc:
|
||||||
|
- 888
|
||||||
|
- 999
|
||||||
|
ac:
|
||||||
|
- 123
|
||||||
|
- 456
|
||||||
|
sn: '000001-100000'
|
||||||
|
-
|
||||||
|
domain: narf3.com
|
||||||
|
reseller: narf3
|
||||||
|
cc:
|
||||||
|
- 888
|
||||||
|
- 999
|
||||||
|
ac:
|
||||||
|
- 123
|
||||||
|
- 456
|
||||||
|
sn: '000001-100000'
|
||||||
|
provider_rate:
|
||||||
|
prepaid: 0
|
||||||
|
fees:
|
||||||
|
-
|
||||||
|
destination: ^888.+
|
||||||
|
direction: out
|
||||||
|
offpeak_follow_interval: 5
|
||||||
|
offpeak_follow_rate: 1
|
||||||
|
offpeak_init_interval: 5
|
||||||
|
offpeak_init_rate: 2
|
||||||
|
onpeak_follow_interval: 5
|
||||||
|
onpeak_follow_rate: 1
|
||||||
|
onpeak_init_interval: 5
|
||||||
|
onpeak_init_rate: 2
|
||||||
|
-
|
||||||
|
destination: .
|
||||||
|
direction: in
|
||||||
|
offpeak_follow_interval: 5
|
||||||
|
offpeak_follow_rate: 1
|
||||||
|
offpeak_init_interval: 5
|
||||||
|
offpeak_init_rate: 1
|
||||||
|
onpeak_follow_interval: 5
|
||||||
|
onpeak_follow_rate: 1
|
||||||
|
onpeak_init_interval: 5
|
||||||
|
onpeak_init_rate: 1
|
||||||
|
source: ^888.+
|
||||||
|
subscriber_rates:
|
||||||
|
-
|
||||||
|
prepaid: 0
|
||||||
|
fees:
|
||||||
|
-
|
||||||
|
destination: ^8882.+
|
||||||
|
direction: out
|
||||||
|
offpeak_follow_interval: 5
|
||||||
|
offpeak_follow_rate: 1
|
||||||
|
offpeak_init_interval: 5
|
||||||
|
offpeak_init_rate: 6
|
||||||
|
onpeak_follow_interval: 5
|
||||||
|
onpeak_follow_rate: 1
|
||||||
|
onpeak_init_interval: 5
|
||||||
|
onpeak_init_rate: 6
|
||||||
|
-
|
||||||
|
destination: .
|
||||||
|
direction: in
|
||||||
|
offpeak_follow_interval: 5
|
||||||
|
offpeak_follow_rate: 1
|
||||||
|
offpeak_init_interval: 5
|
||||||
|
offpeak_init_rate: 5
|
||||||
|
onpeak_follow_interval: 5
|
||||||
|
onpeak_follow_rate: 1
|
||||||
|
onpeak_init_interval: 5
|
||||||
|
onpeak_init_rate: 5
|
||||||
|
source: ^8881.+
|
||||||
|
-
|
||||||
|
prepaid: 1
|
||||||
|
fees:
|
||||||
|
-
|
||||||
|
destination: ^8882.+
|
||||||
|
direction: out
|
||||||
|
offpeak_follow_interval: 5
|
||||||
|
offpeak_follow_rate: 1
|
||||||
|
offpeak_init_interval: 5
|
||||||
|
offpeak_init_rate: 4
|
||||||
|
onpeak_follow_interval: 5
|
||||||
|
onpeak_follow_rate: 1
|
||||||
|
onpeak_init_interval: 5
|
||||||
|
onpeak_init_rate: 4
|
||||||
|
-
|
||||||
|
destination: .
|
||||||
|
direction: in
|
||||||
|
offpeak_follow_interval: 5
|
||||||
|
offpeak_follow_rate: 1
|
||||||
|
offpeak_init_interval: 5
|
||||||
|
offpeak_init_rate: 3
|
||||||
|
onpeak_follow_interval: 5
|
||||||
|
onpeak_follow_rate: 1
|
||||||
|
onpeak_init_interval: 5
|
||||||
|
onpeak_init_rate: 3
|
||||||
|
source: ^8881.+
|
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
#dry=0
|
||||||
|
#skip_errors=0
|
||||||
|
|
||||||
|
provision_subscriber_multithreading = 1
|
||||||
|
#provision_subscriber_numofthreads = 2
|
||||||
|
webpassword_length = 8
|
||||||
|
webusername_length = 8
|
||||||
|
sippassword_length = 16
|
||||||
|
sipusername_length = 8
|
||||||
|
provision_subscriber_count = 2000
|
||||||
|
|
||||||
|
providers_yml = providers.yml
|
||||||
|
|
Loading…
Reference in new issue