From 9f7566ed88373c1b4d54ccebe6140e4f2b4f67f0 Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Tue, 2 Aug 2016 18:55:51 +0200 Subject: [PATCH] MT#21609 add possibility to register peer_auth at only one instance Change-Id: I965eb4708535498575f7aa926b3f52a2913c1950 --- lib/NGCP/Panel/Utils/Sems.pm | 33 ++++++++++++++++++++++++--- lib/NGCP/Panel/Utils/XMLDispatcher.pm | 2 +- ngcp_panel.conf | 4 ++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/NGCP/Panel/Utils/Sems.pm b/lib/NGCP/Panel/Utils/Sems.pm index f4f3f0366b..34985b2bb7 100644 --- a/lib/NGCP/Panel/Utils/Sems.pm +++ b/lib/NGCP/Panel/Utils/Sems.pm @@ -12,6 +12,11 @@ sub create_peer_registration { return 1; } + my $all = 1; + if($c->config->{sems}->{single_host_registration}) { + $all = 0; + } + my $dispatcher = NGCP::Panel::Utils::XMLDispatcher->new; $c->log->debug("creating peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'"); @@ -20,7 +25,7 @@ sub create_peer_registration { my $uuid = $prov_subscriber->uuid; my $contact = $c->config->{sip}->{lb_ext}; - my @ret = $dispatcher->dispatch($c, "appserver", 1, 1, <dispatch($c, "appserver", $all, 1, < db_reg_agent.createRegistration @@ -34,6 +39,10 @@ sub create_peer_registration { EOF + if (!$all && @ret && $ret[-1][1] == 1 && $ret[-1][2] =~ m#OK#) { # single host okay + return 1; + } + if(grep { $$_[1] != 1 or $$_[2] !~ m#OK# } @ret) { # error $c->log->error("Failed XML-RPC call to appserver: ". Dumper \@ret); @@ -63,6 +72,11 @@ sub update_peer_registration { return 1; } + my $all = 1; + if($c->config->{sems}->{single_host_registration}) { + $all = 0; + } + my $dispatcher = NGCP::Panel::Utils::XMLDispatcher->new; $c->log->debug("trying to update peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'"); @@ -78,7 +92,7 @@ sub update_peer_registration { $c->log->debug("+++++++++++++++++++ uuid=$uuid"); $c->log->debug("+++++++++++++++++++ contact=$contact"); - my @ret = $dispatcher->dispatch($c, "appserver", 1, 1, <dispatch($c, "appserver", $all, 1, < db_reg_agent.updateRegistration @@ -92,6 +106,10 @@ sub update_peer_registration { EOF + if (!$all && @ret && $ret[-1][1] == 1 && $ret[-1][2] =~ m#OK#) { # single host okay + return 1; + } + if(grep { $$_[1] != 1 or $$_[2] !~ m#OK# } @ret) { # error $c->log->error("Failed XML-RPC call to appserver: ". Dumper \@ret); @@ -125,6 +143,11 @@ sub delete_peer_registration { return 1; } + my $all = 1; + if($c->config->{sems}->{single_host_registration}) { + $all = 0; + } + my $dispatcher = NGCP::Panel::Utils::XMLDispatcher->new; $c->log->debug("trying to delete peer registration for subscriber '".$prov_subscriber->username.'@'.$prov_subscriber->domain->domain."'"); @@ -133,7 +156,7 @@ sub delete_peer_registration { my $uuid = $prov_subscriber->uuid; my $contact = $c->config->{sip}->{lb_ext}; - my @ret = $dispatcher->dispatch($c, "appserver", 1, 1, <dispatch($c, "appserver", $all, 1, < db_reg_agent.removeRegistration @@ -143,6 +166,10 @@ sub delete_peer_registration { EOF + if (!$all && @ret && $ret[-1][1] == 1 && $ret[-1][2] =~ m#OK#) { # single host okay + return 1; + } + if(grep { $$_[1] != 1 or $$_[2] !~ m#OK# } @ret) { # error $c->log->error("Failed XML-RPC call to appserver: ". Dumper \@ret); diff --git a/lib/NGCP/Panel/Utils/XMLDispatcher.pm b/lib/NGCP/Panel/Utils/XMLDispatcher.pm index b9e972b846..1d5cf45e58 100644 --- a/lib/NGCP/Panel/Utils/XMLDispatcher.pm +++ b/lib/NGCP/Panel/Utils/XMLDispatcher.pm @@ -28,7 +28,7 @@ sub dispatch { else { my $host_rs = $schema->resultset('xmlgroups') ->search_rs({name => $target}) - ->search_related('xmlhostgroups')->search_related('host'); + ->search_related('xmlhostgroups')->search_related('host', {}, { order_by => 'id' }); $hosts = [map +{ip => $_->ip, port => $_->port, path => $_->path, id => $_->id}, $host_rs->all]; } diff --git a/ngcp_panel.conf b/ngcp_panel.conf index 0fd2214e7f..f5b049e0bd 100644 --- a/ngcp_panel.conf +++ b/ngcp_panel.conf @@ -380,5 +380,9 @@ log4perl.appender.Default.layout.ConversionPattern=%d{ISO8601} [%p] [%F +%L] %m{ iv tww21lQe6cmywrp3 + + single_host_registration 0 + +