diff --git a/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm b/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm index 70b1b581ac..b371a62a48 100644 --- a/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm +++ b/lib/NGCP/Panel/Controller/API/SoundFilesItem.pm @@ -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); } diff --git a/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm b/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm index 24f4cc33a7..97ee88a669 100644 --- a/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm +++ b/lib/NGCP/Panel/Controller/API/SoundSetsItem.pm @@ -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; diff --git a/lib/NGCP/Panel/Controller/Sound.pm b/lib/NGCP/Panel/Controller/Sound.pm index 586b401768..86fcf00689 100644 --- a/lib/NGCP/Panel/Controller/Sound.pm +++ b/lib/NGCP/Panel/Controller/Sound.pm @@ -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); } diff --git a/lib/NGCP/Panel/Role/API/SoundFiles.pm b/lib/NGCP/Panel/Role/API/SoundFiles.pm index d3aa8aa7a9..2d6d1c2da2 100644 --- a/lib/NGCP/Panel/Role/API/SoundFiles.pm +++ b/lib/NGCP/Panel/Role/API/SoundFiles.pm @@ -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); } diff --git a/lib/NGCP/Panel/Utils/Rtpengine.pm b/lib/NGCP/Panel/Utils/Rtpengine.pm new file mode 100644 index 0000000000..bcd9c3bf3f --- /dev/null +++ b/lib/NGCP/Panel/Utils/Rtpengine.pm @@ -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: diff --git a/lib/NGCP/Panel/Utils/Sounds.pm b/lib/NGCP/Panel/Utils/Sounds.pm index 378f5d47d5..1858e50986 100644 --- a/lib/NGCP/Panel/Utils/Sounds.pm +++ b/lib/NGCP/Panel/Utils/Sounds.pm @@ -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 {