TT#26466 test data generator

+ 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: I0a79e9db80737e5d9975ede780ea5090cf624908
changes/63/17363/4
Rene Krenn 8 years ago
parent ce9fc9073d
commit 5ab47b7ba7

2
debian/control vendored

@ -60,6 +60,8 @@ Depends:
libxml-libxml-perl,
libyaml-libyaml-perl,
libio-compress-perl,
libsys-cpuaffinity-perl,
libdata-rmap-perl,
perl,
${misc:Depends},
${perl:Depends},

@ -119,6 +119,8 @@ our @EXPORT_OK = qw(
@jobservers
$jobnamespace
@config_search_paths
);
#set process umask for open and mkdir calls:
@ -126,11 +128,11 @@ umask 0000;
# general constants
our $system_name = 'Sipwise Bulk Processing Framework';
our $VERSION = '0.0.1';
our $VERSION = '1.0.1';
our $system_version = $VERSION; #keep this filename-save
our $system_abbreviation = 'sbpf'; #keep this filename-, dbname-save
our $system_instance = 'initial'; #'test'; #'2014'; #dbname-save 0-9a-z_
our $system_instance_label = 'test';
our $system_abbreviation = 'bulkprocessor'; #keep this filename-, dbname-save
our $system_instance = 'ngcp'; #'test'; #'2014'; #dbname-save 0-9a-z_
our $system_instance_label = 'some node';
our $local_ip = get_ipaddress();
our $local_fqdn = get_hostfqdn();
@ -224,7 +226,7 @@ our $emailloglevel = 'OFF'; #'INFO';
our @config_search_paths = ('/var/sipwise/');
# local db setup
our $local_db_path = $working_path . 'db/';

@ -15,6 +15,7 @@ use NGCP::BulkProcessor::Globals qw(
$enablemultithreading
$is_perl_debug
update_masterconfig
@config_search_paths
);
use NGCP::BulkProcessor::Logging qw(
@ -54,32 +55,47 @@ our $YAML_CONFIG_TYPE = 2;
our $ANY_CONFIG_TYPE = 3;
#my $logger = getlogger(__PACKAGE__);
my $debug_config_ext_prefix = 'debug';
sub load_config {
my ($configfile,$process_code,$configtype,$configparser_args) = @_;
my $is_master = 'CODE' ne ref $process_code;
my $data;
my $variant = $configfile;
if (defined $configfile) {
if (-e $configfile) {
$data = _parse_config($configfile,$configtype,$configparser_args);
} else {
my $relative_configfile = $executable_path . $configfile;
if (-e $relative_configfile) {
$configfile = $relative_configfile;
$data = _parse_config($configfile,$configtype,$configparser_args);
my @variants = ();
if ($is_perl_debug) {
push(@variants,_prefix_ext($configfile,$debug_config_ext_prefix));
}
push(@variants,$configfile);
my %dupes = ();
while (not defined $data and ($variant = shift @variants)) {
next if exists $dupes{$variant};
$dupes{$variant} = 1;
if (-e $variant) {
$data = _parse_config($variant,$configtype,$configparser_args);
} else {
configurationwarn($configfile,'no ' . ($is_master ? 'master config' : 'config') . ' file ' . $relative_configfile,getlogger(__PACKAGE__));
$relative_configfile = $application_path . $configfile;
if (-e $relative_configfile) {
$configfile = $relative_configfile;
$data = _parse_config($configfile,$configtype,$configparser_args);
} else {
configurationerror($configfile,'no ' . ($is_master ? 'master config' : 'config') . ' file ' . $relative_configfile,getlogger(__PACKAGE__));
return 0;
my @paths = ();
my %path_dupes = ();
my @search_paths = (@config_search_paths,$executable_path,$application_path); #todo: add /etc/bulkprocessor or similar here once
($variant,$data) = _search_path($variant,$configtype,$configparser_args,\@search_paths,\@paths,\%path_dupes);
@search_paths = ();
if (not defined $data) {
if (index($executable_path,$application_path) > -1) {
my $module_path = 'NGCP/BulkProcessor/' . substr($executable_path,length($application_path));
push(@search_paths,map { eval{ Cwd::abs_path($_ . '/') . '/' . $module_path; }; } @INC);
}
push(@search_paths,map { eval{ Cwd::abs_path($_ . '/') . '/'; }; } @INC);
($variant,$data) = _search_path($variant,$configtype,$configparser_args,\@search_paths,\@paths,\%path_dupes);
}
}
}
if (not defined $data) {
configurationerror($configfile,'no ' . ($is_master ? 'master config' : 'config') . ' variant found',getlogger(__PACKAGE__));
}
} else {
fileerror('no ' . ($is_master ? 'master config' : 'config') . ' file specified',getlogger(__PACKAGE__));
return 0;
@ -88,7 +104,7 @@ sub load_config {
if ($is_master) {
my %context = (
data => $data,
configfile => $configfile,
configfile => $variant,
split_tuplecode => \&split_tuple,
format_numbercode => \&format_number,
parse_regexpcode => \&parse_regexp,
@ -102,7 +118,7 @@ sub load_config {
configlogger => getlogger(__PACKAGE__),
);
my ($result,$loadconfig_args,$postprocesscode) = update_masterconfig(%context);
_splashinfo($configfile);
_splashinfo($variant);
if (defined $loadconfig_args and 'ARRAY' eq ref $loadconfig_args) {
foreach my $loadconfig_arg (@$loadconfig_args) {
$result &= load_config(@$loadconfig_arg);
@ -113,13 +129,45 @@ sub load_config {
}
return $result;
} else {
my $result = &$process_code($data,$configfile);
configurationinfo('config file ' . $configfile . ' loaded',getlogger(__PACKAGE__));
my $result = &$process_code($data,$variant);
configurationinfo('config file ' . $variant . ' loaded',getlogger(__PACKAGE__));
return $result;
}
}
sub _prefix_ext {
my ($configfile,$ext_suffix) = @_;
return $configfile unless $ext_suffix;
if ($configfile =~ /\.([^\.]+)$/) {
$configfile =~ s/\.([^\.]+)$/.$ext_suffix.$1/;
} else {
$configfile .= '.' . $ext_suffix;
}
return $configfile;
}
sub _search_path {
my ($configfile,$configtype,$configparser_args,$search_paths,$paths,$dupes) = @_;
my $data = undef;
$dupes //= {};
while (not defined $data and (my $path = shift @$search_paths)) {
next if exists $dupes->{$path};
push(@$paths,$path);
$dupes->{$path} = 1;
my $relative_configfile = $path . $configfile;
if (-e $relative_configfile) {
$configfile = $relative_configfile;
$data = _parse_config($configfile,$configtype,$configparser_args);
#} else {
# configurationwarn($configfile,'no ' . ($is_master ? 'master config' : 'config') . ' file ' . $relative_configfile,getlogger(__PACKAGE__));
}
}
return ($configfile,$data);
}
sub _splashinfo {
my ($configfile) = @_;

@ -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;

@ -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

@ -348,7 +348,10 @@ sub post_get {
$self->_request_error();
return undef;
} else {
return $self->get($self->response()->header('Location'),$get_headers);
my @ids = $self->_extract_ids_from_response_location();
my $item = $self->get($self->response()->header('Location'),$get_headers);
$item->{id} = $ids[0] if (scalar @ids) > 0;
return $item;
}
}

@ -10,6 +10,8 @@ use NGCP::BulkProcessor::ConnectorPool qw(
use NGCP::BulkProcessor::RestProcessor qw(
copy_row
get_query_string
);
use NGCP::BulkProcessor::RestConnectors::NGCPRestApi qw();
@ -22,6 +24,7 @@ our @EXPORT_OK = qw(
create_item
delete_item
get_item_path
findby_billingprofileid
);
my $get_restapi = \&get_ngcp_restapi;
@ -33,6 +36,13 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $findby_billingprofileid_path_query = sub {
my ($billing_profile_id) = @_;
my $filters = {};
$filters->{billing_profile_id} = $billing_profile_id if defined $billing_profile_id;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'billing_zone_id',
'destination',
@ -48,6 +58,8 @@ my $fieldnames = [
'purge_existing',
'source',
'use_free_time',
'id',
];
sub new {
@ -69,6 +81,15 @@ sub get_item {
}
sub findby_billingprofileid {
my ($billing_profile_id,$load_recursive,$headers) = @_;
my $restapi = &$get_restapi();
return builditems_fromrows($restapi->extract_collection_items($restapi->get(&$findby_billingprofileid_path_query($billing_profile_id),$headers),undef,undef,
{ $NGCP::BulkProcessor::RestConnectors::NGCPRestApi::ITEM_REL_PARAM => $item_relation }),$load_recursive);
}
sub create_item {
my ($data,$load,$load_recursive,$post_headers,$get_headers) = @_;

@ -11,6 +11,7 @@ use NGCP::BulkProcessor::ConnectorPool qw(
use NGCP::BulkProcessor::RestProcessor qw(
process_collection
copy_row
get_query_string
);
use NGCP::BulkProcessor::RestConnectors::NGCPRestApi qw();
@ -23,6 +24,7 @@ our @EXPORT_OK = qw(
create_item
process_items
get_item_path
findby_resellerid
);
my $get_restapi = \&get_ngcp_restapi;
@ -34,6 +36,13 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $findby_resellerid_path_query = sub {
my ($reseller_id) = @_;
my $filters = {};
$filters->{reseller_id} = $reseller_id if defined $reseller_id;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'currency',
'fraud_daily_limit',
@ -52,6 +61,8 @@ my $fieldnames = [
'peaktime_weekdays',
'prepaid',
'reseller_id',
'id',
];
sub new {
@ -73,6 +84,15 @@ sub get_item {
}
sub findby_resellerid {
my ($reseller_id,$load_recursive,$headers) = @_;
my $restapi = &$get_restapi();
return builditems_fromrows($restapi->extract_collection_items($restapi->get(&$findby_resellerid_path_query($reseller_id),$headers),undef,undef,
{ $NGCP::BulkProcessor::RestConnectors::NGCPRestApi::ITEM_REL_PARAM => $item_relation }),$load_recursive);
}
sub create_item {
my ($data,$load,$load_recursive,$post_headers,$get_headers) = @_;

@ -10,6 +10,8 @@ use NGCP::BulkProcessor::ConnectorPool qw(
use NGCP::BulkProcessor::RestProcessor qw(
copy_row
get_query_string
);
use NGCP::BulkProcessor::RestConnectors::NGCPRestApi qw();
@ -21,6 +23,7 @@ our @EXPORT_OK = qw(
get_item
create_item
get_item_path
findby_billingprofileid
);
my $get_restapi = \&get_ngcp_restapi;
@ -32,10 +35,19 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $findby_billingprofileid_path_query = sub {
my ($billing_profile_id) = @_;
my $filters = {};
$filters->{billing_profile_id} = $billing_profile_id if defined $billing_profile_id;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'billing_profile_id',
'detail',
'zone',
'id',
];
sub new {
@ -57,6 +69,15 @@ sub get_item {
}
sub findby_billingprofileid {
my ($billing_profile_id,$load_recursive,$headers) = @_;
my $restapi = &$get_restapi();
return builditems_fromrows($restapi->extract_collection_items($restapi->get(&$findby_billingprofileid_path_query($billing_profile_id),$headers),undef,undef,
{ $NGCP::BulkProcessor::RestConnectors::NGCPRestApi::ITEM_REL_PARAM => $item_relation }),$load_recursive);
}
sub create_item {
my ($data,$load,$load_recursive,$post_headers,$get_headers) = @_;

@ -42,6 +42,8 @@ my $fieldnames = [
'external_id',
'status',
'type',
'id',
];
sub new {

@ -60,6 +60,8 @@ my $fieldnames = [
'reseller_id',
'street',
'vatnum',
'id',
];
sub new {

@ -52,6 +52,8 @@ my $fieldnames = [
'subscriber_email_template',
'type',
'vat_rate',
'id',
];
our $TERMINATED_STATE = 'terminated';

@ -37,16 +37,18 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $fieldnames = [
'domain',
'reseller_id',
];
my $get_item_filter_path_query = sub {
my ($filters) = @_;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'domain',
'reseller_id',
'id',
];
sub new {
my $class = shift;

@ -37,17 +37,20 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $get_item_filter_path_query = sub {
my ($filters) = @_;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'authorative',
'name',
'prefix',
'skip_rewrite',
];
my $get_item_filter_path_query = sub {
my ($filters) = @_;
return 'api/' . $resource . '/' . get_query_string($filters);
};
'id',
];
sub new {

@ -37,18 +37,20 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $get_item_filter_path_query = sub {
my ($filters) = @_;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'description',
'level',
'local_ac',
'mode',
'reseller_id',
];
my $get_item_filter_path_query = sub {
my ($filters) = @_;
return 'api/' . $resource . '/' . get_query_string($filters);
};
'id',
];
sub new {

@ -10,6 +10,8 @@ use NGCP::BulkProcessor::ConnectorPool qw(
use NGCP::BulkProcessor::RestProcessor qw(
copy_row
get_query_string
);
use NGCP::BulkProcessor::RestConnectors::NGCPRestApi qw();
@ -22,6 +24,7 @@ our @EXPORT_OK = qw(
create_item
get_item_path
get_item_filtered
);
my $get_restapi = \&get_ngcp_restapi;
@ -33,12 +36,19 @@ my $get_item_path_query = sub {
};
my $collection_path_query = 'api/' . $resource . '/';
my $get_item_filter_path_query = sub {
my ($filters) = @_;
return 'api/' . $resource . '/' . get_query_string($filters);
};
my $fieldnames = [
'contract_id',
'enable_rtc',
'name',
'rtc_networks',
'status',
'id',
];
sub new {
@ -60,6 +70,15 @@ sub get_item {
}
sub get_item_filtered {
my ($filters,$load_recursive,$headers) = @_;
my $restapi = &$get_restapi();
return builditems_fromrows($restapi->extract_collection_items($restapi->get(&$get_item_filter_path_query($filters),$headers),undef,undef,
{ $NGCP::BulkProcessor::RestConnectors::NGCPRestApi::ITEM_REL_PARAM => $item_relation }),$load_recursive)->[0];
}
sub create_item {
my ($data,$load,$load_recursive,$post_headers,$get_headers) = @_;

@ -58,6 +58,8 @@ my $fieldnames = [
'username',
'webpassword',
'webusername',
'id',
];
sub new {

@ -59,6 +59,8 @@ my $fieldnames = [
'postcode',
'street',
'vatnum',
'id',
];
sub new {

@ -39,7 +39,7 @@ use File::Path qw(remove_tree make_path);
#use Sys::Info::Constants qw( :device_cpu );
# after all, the only reliable way to get the true vCPU count:
#use Sys::CpuAffinity; # qw(getNumCpus); not exported?
use Sys::CpuAffinity; # qw(getNumCpus); not exported?
#disabling for now, no debian package yet.
require Exporter;
@ -829,7 +829,7 @@ sub secs_to_years {
}
sub get_cpucount {
my $cpucount = 0; #Sys::CpuAffinity::getNumCpus() + 0;
my $cpucount = Sys::CpuAffinity::getNumCpus() + 0;
return ($cpucount > 0) ? $cpucount : 1;
#my $info = Sys::Info->new();
#my $cpu = $info->device('CPU'); # => %options );

Loading…
Cancel
Save