diff --git a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm index 3d993d0894..beb3d0c47e 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringGroups.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringGroups.pm @@ -99,13 +99,13 @@ sub POST :Allow { my $guard = $c->model('DB')->txn_scope_guard; { my $resource = $self->get_valid_post_data( - c => $c, + c => $c, media_type => 'application/json', ); last unless $resource; my $form = $self->get_form($c); - + last unless $self->validate_form( c => $c, resource => $resource, @@ -125,7 +125,6 @@ sub POST :Allow { try { $item = $c->model('DB')->resultset('voip_peer_groups')->create($resource); - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); } catch($e){ $c->log->error("failed to create peering group: $e"); # TODO: user, message, trace, ... $self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create peering group."); @@ -134,6 +133,8 @@ sub POST :Allow { $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + $c->response->status(HTTP_CREATED); $c->response->header(Location => sprintf('/%s%d', $c->request->path, $item->id)); $c->response->body(q()); diff --git a/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm b/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm index 2f08fbdac9..f6e0de5f72 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringGroupsItem.pm @@ -51,7 +51,7 @@ sub PATCH :Allow { last unless $preference; my $json = $self->get_valid_patch_data( - c => $c, + c => $c, id => $id, media_type => 'application/json-patch+json', ); @@ -66,7 +66,7 @@ sub PATCH :Allow { my $form = $self->get_form($c); $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - + $guard->commit; $self->return_representation($c, 'item' => $item, 'form' => $form, 'preference' => $preference ); @@ -95,7 +95,7 @@ sub PUT :Allow { $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - $guard->commit; + $guard->commit; $self->return_representation($c, 'item' => $item, 'form' => $form, 'preference' => $preference ); } @@ -124,6 +124,7 @@ sub DELETE :Allow { } $item->delete; $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); $c->response->status(HTTP_NO_CONTENT); diff --git a/lib/NGCP/Panel/Controller/API/PeeringRules.pm b/lib/NGCP/Panel/Controller/API/PeeringRules.pm index 4abacf6600..f175741ca4 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringRules.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringRules.pm @@ -161,6 +161,7 @@ sub POST :Allow { } $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); $c->response->status(HTTP_CREATED); diff --git a/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm b/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm index 5865275e43..c8671fb157 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringRulesItem.pm @@ -63,7 +63,7 @@ sub PATCH :Allow { last unless $preference; my $json = $self->get_valid_patch_data( - c => $c, + c => $c, id => $id, media_type => 'application/json-patch+json', ); @@ -78,7 +78,7 @@ sub PATCH :Allow { my $form = $self->get_form($c); $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - + $guard->commit; $self->return_representation($c, 'item' => $item, 'form' => $form, 'preference' => $preference ); @@ -121,9 +121,10 @@ sub DELETE :Allow { my $item = $self->item_by_id($c, $id); last unless $self->resource_exists($c, peeringrule => $item); $item->delete; - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + $c->response->status(HTTP_NO_CONTENT); $c->response->body(q()); } diff --git a/lib/NGCP/Panel/Controller/API/PeeringServers.pm b/lib/NGCP/Panel/Controller/API/PeeringServers.pm index 7ee6feb643..a83f71fd7b 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServers.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServers.pm @@ -167,7 +167,6 @@ sub POST :Allow { try { $item = $c->model('DB')->resultset('voip_peer_hosts')->create($resource); - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if($resource->{probe}) { NGCP::Panel::Utils::Peering::_sip_dispatcher_reload(c => $c); } @@ -179,8 +178,9 @@ sub POST :Allow { $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if($resource->{probe}) { NGCP::Panel::Utils::Peering::_sip_dispatcher_reload(c => $c); } diff --git a/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm b/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm index b25dba051f..2757942415 100644 --- a/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm +++ b/lib/NGCP/Panel/Controller/API/PeeringServersItem.pm @@ -63,7 +63,7 @@ sub PATCH :Allow { last unless $preference; my $json = $self->get_valid_patch_data( - c => $c, + c => $c, id => $id, media_type => 'application/json-patch+json', ); @@ -78,11 +78,12 @@ sub PATCH :Allow { my $form = $self->get_form($c); $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - + $guard->commit; + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if (($item->probe && $old_resource->{enabled} && !$item->enabled) || ($old_resource->{probe} && !$item->probe)) { NGCP::Panel::Utils::Peering::_sip_delete_probe( c => $c, @@ -136,9 +137,11 @@ sub PUT :Allow { $item = $self->update_item($c, $item, $old_resource, $resource, $form); last unless $item; - $guard->commit; + $guard->commit; + + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if (($item->probe && $old_resource->{enabled} && !$item->enabled) || ($old_resource->{probe} && !$item->probe)) { NGCP::Panel::Utils::Peering::_sip_delete_probe( c => $c, @@ -181,8 +184,10 @@ sub DELETE :Allow { my $probe = $item->probe; $item->delete; $guard->commit; + + NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); + try { - NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c); if($probe) { NGCP::Panel::Utils::Peering::_sip_delete_probe( c => $c, diff --git a/lib/NGCP/Panel/Utils/XMLDispatcher.pm b/lib/NGCP/Panel/Utils/XMLDispatcher.pm index e7c65cc054..52bc66e755 100644 --- a/lib/NGCP/Panel/Utils/XMLDispatcher.pm +++ b/lib/NGCP/Panel/Utils/XMLDispatcher.pm @@ -70,7 +70,7 @@ sub dispatch { } # failure - + $c->log->info("failure: $@"); $all or next; @@ -147,10 +147,6 @@ sub _unqueue { sub sip_domain_reload { my ($c, $domain_name) = @_; - my $NUM_TRIES = 3; - my $SLEEP_BEFORE_RETRY = 1; - my $res; - my $reload_command = < @@ -159,41 +155,15 @@ sub sip_domain_reload { EOF - my $dump_command = < - -domain.dump - - -EOF + my @ret = dispatch($c, "proxy-ng", 1, 1, $reload_command); # we're only checking first host here - for (my $i = 0; $i < $NUM_TRIES; $i++) { - sleep $SLEEP_BEFORE_RETRY if ($i > 0); - - ($res) = dispatch($c, "proxy-ng", 1, 1, $reload_command); # we're only checking first host here - if ($res->[1] == 0) { - die "couldn't reload domains"; - } - return () unless $domain_name; - my @replies = dispatch($c, "proxy-ng", 1, 1, $dump_command); - my $all_successful = 1; - for my $reply (@replies) { - if ($reply->[1] == -1) { - # skip inactive host - } elsif ($reply->[1] && $reply->[2] =~ m/$domain_name/) { - # successful - } else { - $c->log->debug("Domain not loaded. Retrying..."); - $all_successful = 0; - } - } - if ($all_successful) { - $c->log->debug("Domain successfully loaded in all active proxies"); - return; - } + if (grep { $_->[1] == 0 } @ret) { + die "Couldn't reload domain"; } - die "couldn't load domain into all proxies. Tried $NUM_TRIES times."; + $c->log->debug("Domain successfully loaded in all active proxies"); + + return; }