TT#36005 add Storage model support, callflows use Storage model

* Storage model provides with a layer for more than one
      DBIx::Class connection and handles them, currently only
      first connection is supported.
    * Storage model also uses different DSN than the DB model
    * Callflows use the Storage model to fetch captured dialogs

Change-Id: I6e742b7a7f1f9f047ca68ea75f6eea01349c8664
changes/94/21494/2
Kirill Solomko 8 years ago
parent 6e8dd1a2a1
commit 8f28e18ba3

@ -49,8 +49,8 @@ sub ajax :Chained('root') :PathPart('ajax') :Args(0) {
my $calls_rs_cb = sub {
my %params = @_;
my $total_count = $c->model('DB')->resultset('messages')->search(undef,{group_by => 'call_id'})->count;
my $base_rs = $c->model('DB')->resultset('messages_custom');
my $total_count = $c->model('Storage')->resultset('messages')->search(undef,{group_by => 'call_id'})->count;
my $base_rs = $c->model('Storage')->resultset('messages_custom');
my $searchstring = $params{searchstring} ? $params{searchstring}.'%' : '';
my @bind_vals = (($searchstring) x 3, $params{offset}, $params{rows});
@ -88,7 +88,7 @@ sub get_pcap :Chained('callflow_base') :PathPart('pcap') :Args(0) {
my ($self, $c) = @_;
my $cid = $c->stash->{callid};
my $packet_rs = $c->model('DB')->resultset('packets')->search({
my $packet_rs = $c->model('Storage')->resultset('packets')->search({
'message.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
join => { message_packets => 'message' },
@ -106,7 +106,7 @@ sub get_png :Chained('callflow_base') :PathPart('png') :Args(0) {
my ($self, $c) = @_;
my $cid = $c->stash->{callid};
my $calls_rs = $c->model('DB')->resultset('messages')->search({
my $calls_rs = $c->model('Storage')->resultset('messages')->search({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
order_by => { -asc => 'timestamp' },
@ -125,7 +125,7 @@ sub get_callmap :Chained('callflow_base') :PathPart('callmap') :Args(0) {
my $cid = $c->stash->{callid};
$c->stash->{template} = 'callflow/callmap.tt';
my $calls_rs = $c->model('DB')->resultset('messages')->search({
my $calls_rs = $c->model('Storage')->resultset('messages')->search({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
order_by => { -asc => 'timestamp' },
@ -145,7 +145,7 @@ sub get_packet :Chained('callflow_base') :PathPart('packet') :Args() {
my ($self, $c, $packet_id) = @_;
my $cid = $c->stash->{callid};
my $packet = $c->model('DB')->resultset('messages')->find({
my $packet = $c->model('Storage')->resultset('messages')->find({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
'me.id' => $packet_id,
}, {

@ -3679,7 +3679,7 @@ sub ajax_recording_streams :Chained('recording') :PathPart('streams/ajax') :Args
sub ajax_captured_calls :Chained('master') :PathPart('callflow/ajax') :Args(0) {
my ($self, $c) = @_;
my $rs = $c->model('DB')->resultset('messages')->search({
my $rs = $c->model('Storage')->resultset('messages')->search({
-or => [
'me.caller_uuid' => $c->stash->{subscriber}->uuid,
'me.callee_uuid' => $c->stash->{subscriber}->uuid,
@ -4736,7 +4736,7 @@ sub get_pcap :Chained('callflow_base') :PathPart('pcap') :Args(0) {
my ($self, $c) = @_;
my $cid = $c->stash->{callid};
my $packet_rs = $c->model('DB')->resultset('packets')->search({
my $packet_rs = $c->model('Storage')->resultset('packets')->search({
'message.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
join => { message_packets => 'message' },
@ -4770,7 +4770,7 @@ sub get_json :Chained('callflow_base') :PathPart('json') :Args(0) {
my ($self, $c) = @_;
my $cid = $c->stash->{callid};
my $calls_rs = $c->model('DB')->resultset('messages')->search({
my $calls_rs = $c->model('Storage')->resultset('messages')->search({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
order_by => { -asc => 'timestamp' },
@ -4799,7 +4799,7 @@ sub get_png :Chained('callflow_base') :PathPart('png') :Args(0) {
my ($self, $c) = @_;
my $cid = $c->stash->{callid};
my $calls_rs = $c->model('DB')->resultset('messages')->search({
my $calls_rs = $c->model('Storage')->resultset('messages')->search({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
order_by => { -asc => 'timestamp' },
@ -4817,7 +4817,7 @@ sub get_callmap :Chained('callflow_base') :PathPart('callmap') :Args(0) {
my ($self, $c) = @_;
my $cid = $c->stash->{callid};
my $calls_rs = $c->model('DB')->resultset('messages')->search({
my $calls_rs = $c->model('Storage')->resultset('messages')->search({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
}, {
order_by => { -asc => 'timestamp' },
@ -4836,7 +4836,7 @@ sub get_packet :Chained('callflow_base') :PathPart('packet') :Args() {
my ($self, $c, $packet_id) = @_;
my $cid = $c->stash->{callid};
my $packet = $c->model('DB')->resultset('messages')->find({
my $packet = $c->model('Storage')->resultset('messages')->find({
'me.call_id' => { -in => [ $cid, $cid.'_b2b-1', $cid.'_pbx-1' ] },
'me.id' => $packet_id,
}, {

@ -0,0 +1,63 @@
package NGCP::Panel::Model::Storage;
use Sipwise::Base;
use Moose;
use XML::Simple;
use NGCP::Schema;
use parent 'Catalyst::Component';
__PACKAGE__->config(
connectors => [],
);
has connectors => (
is => 'rw',
);
sub COMPONENT {
my ($class, $app, $args) = @_;
$args = $class->merge_config_hashes($class->config, $args);
my $self = $class->new($app, $args);
$self->connect_storage();
return $self;
}
sub get_config_filename {
return '/etc/ngcp-panel/provisioning.conf';
}
sub add_connector {
my ($self, $conn) = @_;
$self->connectors([@{$self->connectors // []},
NGCP::Schema->connect($conn)]);
return;
}
sub connect_storage {
my ($self, $c) = @_;
unless (@{$self->config->{connectors}}) {
my $conf = XML::Simple->new->XMLin(get_config_filename(), ForceArray => 1);
if ($conf && $conf->{ngcp_storage_info}) {
my $connectors = $conf->{ngcp_storage_info}->[0]->{connectors} // [];
map { $self->add_connector($_); } @$connectors;
}
}
return;
}
sub resultset {
my ($self, $rs) = @_;
return unless $self->connectors->[0];
# TODO: only one is used now, support multiple storages at once
return $self->connectors->[0]->resultset($rs);
}
1;
# vim: set tabstop=4 expandtab
Loading…
Cancel
Save