TT#121250 improve sip_lcr_reload and sip_domain_reload

* sip_lcr_reload is now called after "commit" in all API endpoints,
  to correctly reflect updated DB changes. It was correct in
  /api/peeringrules POST but not correct in DELETE, as well as
  also not correct in /api/peeringservers and /api/peeringgroups
* sip_domain_reload does not check if the domain is successfully
  reload in kamailio proxy as is logic is redundant, it fails
  however if domain reload XMLRPC request failed on any available
  proxy servers. Another reason is by default tcp_conn_wq_max
  in kamailio-proxy is 32KB by default and that causes an impact
  when domain.dump XMLRPC is used on very large domain sets (600+),
  as well as sip_domain_reload has improved performance with the removed
  XMLRPC domain.dump body parsing.

Change-Id: I17c5718198b06b1ce78b2654f3d7c3bd2830f60b
mr10.0
Kirill Solomko 5 years ago
parent d3a7825df1
commit d17c4be4a5

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

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

@ -161,6 +161,7 @@ sub POST :Allow {
}
$guard->commit;
NGCP::Panel::Utils::Peering::_sip_lcr_reload(c => $c);
$c->response->status(HTTP_CREATED);

@ -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());
}

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

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

@ -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 = <<EOF;
<?xml version="1.0" ?>
<methodCall>
@ -159,41 +155,15 @@ sub sip_domain_reload {
</methodCall>
EOF
my $dump_command = <<EOF;
<?xml version="1.0" ?>
<methodCall>
<methodName>domain.dump</methodName>
<params/>
</methodCall>
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;
}

Loading…
Cancel
Save