MT#61630 invalidate rtpengine cached files

Add class to make RPC calls to rtpengine.

Add invokations to clear rtpengine audio cache where appropriate,
whenever a file stored in DB is deleted or changed.

Change-Id: I3660f9f67dfb0c68c1af80a5439982046be3b6f6
mr13.2
Richard Fuchs 1 year ago
parent 1bcc6430a4
commit b2b5600c16

@ -10,6 +10,7 @@ use NGCP::Panel::Utils::ValidateJSON qw();
require Catalyst::ActionRole::ACL;
require NGCP::Panel::Role::HTTPMethods;
require Catalyst::ActionRole::RequireSSL;
use NGCP::Panel::Utils::Rtpengine;
sub allowed_methods{
return [qw/GET OPTIONS HEAD PUT PATCH DELETE/];
@ -137,6 +138,7 @@ sub DELETE :Allow {
my $group_name = $item->handle->group->name;
try {
NGCP::Panel::Utils::Sems::clear_audio_cache($c, $item->set_id, $item->handle->name, $group_name);
NGCP::Panel::Utils::Rtpengine::clear_audio_cache_files($c, $item->id);
} catch ($e) {
$c->log->warn("Failed to clear audio cache for group " . $group_name);
}

@ -90,6 +90,7 @@ sub delete_item {
# clear audio cache of the current sound set and
# and all potentially affected children sets
NGCP::Panel::Utils::Sems::clear_audio_cache($c, $item->id);
NGCP::Panel::Utils::Rtpengine::clear_audio_cache_set($c, $item->id);
$item->delete;

@ -11,6 +11,7 @@ use File::Type;
use NGCP::Panel::Utils::Sounds;
use NGCP::Panel::Utils::Navigation;
use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::Rtpengine;
use List::Util qw(any);
sub auto :Private {
@ -361,6 +362,7 @@ sub delete_sound :Chained('base') :PathPart('delete') {
# clear audio cache of the current sound set and
# all potentially affected children sets
NGCP::Panel::Utils::Sems::clear_audio_cache($c, $own_id);
NGCP::Panel::Utils::Rtpengine::clear_audio_cache_set($c, $own_id);
$c->stash->{set_result}->delete;
});
@ -720,6 +722,7 @@ sub handles_delete :Chained('handles_base') :PathPart('delete') {
my $group_name = $handle->group->name;
try {
NGCP::Panel::Utils::Sems::clear_audio_cache($c, $c->stash->{file_result}->set_id, $handle->name, $group_name);
NGCP::Panel::Utils::Rtpengine::clear_audio_cache_files($c, $c->stash->{file_result}->id);
} catch ($e) {
$c->log->warn("Failed to clear audio cache for group " . $group_name);
}

@ -13,6 +13,7 @@ use HTTP::Status qw(:constants);
use File::Temp qw(tempfile);
use NGCP::Panel::Utils::Sounds;
use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::Rtpengine;
use NGCP::Panel::Utils::Generic;
sub transcode_data {
@ -216,6 +217,7 @@ sub update_item {
try {
if ($item) {
$item->update($resource);
NGCP::Panel::Utils::Rtpengine::clear_audio_cache_files($c, $item->id);
} else {
$item = $c->model('DB')->resultset('voip_sound_files')->create($resource);
}

@ -0,0 +1,50 @@
package NGCP::Panel::Utils::Rtpengine;
use Sipwise::Base;
use NGCP::Panel::Utils::HTTPDispatcher;
use NGCP::Panel::Utils::Sounds;
use List::Util qw(any);
sub clear_audio_cache_files {
my ($c, @sound_ids) = @_;
return unless @sound_ids;
my @all;
if (@sound_ids < 1000) {
my @ret = NGCP::Panel::Utils::HTTPDispatcher::dispatch($c, "rtpengine", 1, 1, "POST", "text/plain",
"media evict cache @sound_ids");
push(@all, @ret);
@ret = NGCP::Panel::Utils::HTTPDispatcher::dispatch($c, "rtpengine", 1, 1, "POST", "text/plain",
"media evict db @sound_ids");
push(@all, @ret);
} else {
my @ret = NGCP::Panel::Utils::HTTPDispatcher::dispatch($c, "rtpengine", 1, 1, "POST", "text/plain",
"media evict caches");
push(@all, @ret);
@ret = NGCP::Panel::Utils::HTTPDispatcher::dispatch($c, "rtpengine", 1, 1, "POST", "text/plain",
"media evict dbs");
push(@all, @ret);
}
if (any { $$_[1] != 1 } @all) {
die "failed to clear rtpengine audio cache";
}
return;
}
sub clear_audio_cache_set {
my ($c, $set_id) = @_;
my $handles = NGCP::Panel::Utils::Sounds::get_file_handles(c => $c, set_id => $set_id);
my @db_ids = map { $_->{file_id} // () } @{$handles};
clear_audio_cache_files($c, @db_ids);
return;
}
1;
# vim: set tabstop=4 expandtab:

@ -6,9 +6,11 @@ use English;
use Capture::Tiny qw(capture);
use File::Temp qw/tempfile/;
use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::Rtpengine;
use NGCP::Panel::Utils::Preferences;
use File::Slurp;
use File::Basename;
use Data::Dumper;
sub transcode_file {
my ($tmpfile, $source_codec, $target_codec) = @_;
@ -235,6 +237,7 @@ sub apply_default_soundset_files{
my $schema = $c->model('DB');
my $base = "/var/lib/ngcp-soundsets";
my @reload_ids;
foreach my $h (@{$file_handles}) {
my $handle_name = $h->{handle_name};
my @paths = (
@ -273,6 +276,8 @@ sub apply_default_soundset_files{
data => ${data_ref},
loopplay => $loopplay,
});
push(@reload_ids, $file_id);
} else {
$c->log->debug("skip $path as $handle_name exists via id $file_id and override is not set");
}
@ -296,6 +301,8 @@ sub apply_default_soundset_files{
NGCP::Panel::Utils::Sems::clear_audio_cache($c, $fres->set_id,
$fres->handle->name, $group_name);
}
NGCP::Panel::Utils::Rtpengine::clear_audio_cache_files($c, @reload_ids);
}
sub contract_sound_set_propagate {

Loading…
Cancel
Save