Skip to content

Commit

Permalink
Merge pull request #297 from dmitry-sinina/1.6cp3
Browse files Browse the repository at this point in the history
1.6cp3
  • Loading branch information
dmitry-sinina committed Apr 16, 2018
2 parents 8a55996 + 8389f86 commit eb9b94a
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ GIT

GIT
remote: https://github.com/yeti-switch/yetis_node.git
revision: 1b0b40789a5385ff3935d7739211f42402e385c4
revision: 99440a719fde0904b4ad093ede27d6661e595190
specs:
yetis_node (1.0.0)
jrpc (~> 1.0, >= 0.4.6)
Expand Down
1 change: 1 addition & 0 deletions app/admin/routing/destinations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@

filter :external_id_eq, label: 'EXTERNAL_ID'

acts_as_filter_by_routing_tag_ids


permit_params :enabled, :prefix, :dst_number_min_length, :dst_number_max_length, :rateplan_id, :next_rate, :connect_fee,
Expand Down
2 changes: 2 additions & 0 deletions app/admin/routing/dialpeers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def update
filter :external_id
filter :exclusive_route, as: :select, collection: [["Yes", true], ["No", false]]

acts_as_filter_by_routing_tag_ids


form do |f|
f.semantic_errors *f.object.errors.keys
Expand Down
1 change: 1 addition & 0 deletions app/admin/routing/routing_tag_detection_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ def update
filter :src_area, input_html: {class: 'chosen'}
filter :dst_area, input_html: {class: 'chosen'}

acts_as_filter_by_routing_tag_ids
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Api::Rest::Admin::Routing::AreaPrefixesController < Api::Rest::Admin::BaseController
end
2 changes: 1 addition & 1 deletion app/jobs/jobs/calls_monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def call_price(attrs)
initial_interval = attrs.fetch("#{key}_initial_interval").to_i #TODO: check if needed cast to int
next_interval = attrs.fetch("#{key}_next_interval").to_i #TODO: check if needed cast to int
connect_fee = attrs.fetch("#{key}_fee").to_f
vat = key == 'destination' ? attrs.fetch("customer_acc_vat", 0) : 0
vat = key == 'destination' ? attrs.fetch("customer_acc_vat", 0).to_f : 0
initial_interval_billing = connect_fee + initial_interval * i_per_second_rate
next_interval_billing = (duration > initial_interval ? 1 : 0) * ((duration - initial_interval).to_f / next_interval).ceil * next_interval * n_per_second_rate
(initial_interval_billing + next_interval_billing) * (1 + vat / 100.0)
Expand Down
19 changes: 19 additions & 0 deletions app/models/concerns/routing_tag_ids_scopeable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module RoutingTagIdsScopeable
extend ActiveSupport::Concern

included do

scope :routing_tag_ids_covers, ->(*id) do
where("yeti_ext.tag_compare(routing_tag_ids, ARRAY[#{id.join(',')}])>0")
end

scope :tagged, ->(value) do
if ActiveRecord::Type::Boolean.new.type_cast_from_user(value)
where("routing_tag_ids <> '{}'") # has tags
else
where("routing_tag_ids = '{}'") # no tags
end
end

end
end
6 changes: 5 additions & 1 deletion app/models/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Destination < Yeti::ActiveRecord

include Yeti::NetworkDetector

include RoutingTagIdsScopeable

scope :low_quality, -> { where quality_alarm: true }

scope :where_customer, -> (id) do
Expand Down Expand Up @@ -152,7 +154,9 @@ def is_valid_till?

def self.ransackable_scopes(auth_object = nil)
[
:routing_for_contains
:routing_for_contains,
:routing_tag_ids_covers,
:tagged
]
end

Expand Down
5 changes: 4 additions & 1 deletion app/models/dialpeer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Dialpeer < Yeti::ActiveRecord

include Yeti::ResourceStatus
include Yeti::NetworkDetector
include RoutingTagIdsScopeable

scope :locked, -> { where locked: true }

Expand Down Expand Up @@ -197,7 +198,9 @@ def vendor_owners_the_gateway_group

def self.ransackable_scopes(auth_object = nil)
[
:routing_for_contains
:routing_for_contains,
:routing_tag_ids_covers,
:tagged
]
end

Expand Down
10 changes: 10 additions & 0 deletions app/models/routing/routing_tag_detection_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ class Routing::RoutingTagDetectionRule < Yeti::ActiveRecord
array_belongs_to :routing_tags, class_name: 'Routing::RoutingTag', foreign_key: :routing_tag_ids
array_belongs_to :tag_action_values, class_name: 'Routing::RoutingTag', foreign_key: :tag_action_value

include RoutingTagIdsScopeable

def display_name
"#{self.id}"
end

private

def self.ransackable_scopes(auth_object = nil)
[
:routing_tag_ids_covers,
:tagged
]
end
end
7 changes: 7 additions & 0 deletions app/resources/api/rest/admin/routing/area_prefix_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::Rest::Admin::Routing::AreaPrefixResource < ::BaseResource
model_name 'Routing::AreaPrefix'

attributes :prefix

has_one :area, class_name: 'Area'
end
1 change: 1 addition & 0 deletions config/initializers/yeti.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ActiveAdmin::ResourceDSL.send :include, ResourceDSL::ActsAsAsyncDestroy
ActiveAdmin::ResourceDSL.send :include, ResourceDSL::ActsAsAsyncUpdate
ActiveAdmin::ResourceDSL.send :include, ResourceDSL::ActsAsDelayedJobLock
ActiveAdmin::ResourceDSL.send :include, ResourceDSL::ActsAsFilterByRoutingTagIds

# ActiveAdmin::CSVBuilder.send(:include, Yeti::CSVBuilder)

Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ en:
formtastic:
hints:
gateway:
is_shared: "Allows gateway to be used as origination equipment for any customer"
is_shared: "Allows gateway to be used as origination/termination equipment by any customer/vendor"
max_30x_redirects: "How many 301/302 redirects Yeti will process"
max_transfers: "How many SIP REFERs Yeti will process"
system_sensor:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@

namespace :routing do
jsonapi_resources :areas
jsonapi_resources :area_prefixes
jsonapi_resources :numberlists
jsonapi_resources :numberlist_items
jsonapi_resources :numberlist_actions
Expand Down
178 changes: 178 additions & 0 deletions db/migrate/20180403104223_fix_shared_gw.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
class FixSharedGw < ActiveRecord::Migration
def up
execute %q{
CREATE OR REPLACE FUNCTION switch15.process_dp(i_profile switch15.callprofile58_ty, i_destination class4.destinations, i_dp class4.dialpeers, i_customer_acc billing.accounts, i_customer_gw class4.gateways, i_vendor_acc billing.accounts, i_pop_id integer, i_send_billing_information boolean, i_max_call_length integer) RETURNS SETOF switch15.callprofile58_ty
LANGUAGE plpgsql STABLE SECURITY DEFINER COST 10000
AS $$
DECLARE
/*dbg{*/
v_start timestamp;
v_end timestamp;
/*}dbg*/
v_gw class4.gateways%rowtype;
BEGIN
/*dbg{*/
v_start:=now();
--RAISE NOTICE 'process_dp in: %',i_profile;5
v_end:=clock_timestamp();
RAISE NOTICE '% ms -> process-DP. Found dialpeer: %',EXTRACT(MILLISECOND from v_end-v_start),row_to_json(i_dp,true);
/*}dbg*/
--RAISE NOTICE 'process_dp dst: %',i_destination;
if i_dp.gateway_id is null then
PERFORM id from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop;
IF FOUND THEN
/*rel{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.contractor_id=i_dp.vendor_id and cg.enabled ORDER BY cg.pop_id=i_pop_id desc,cg.priority desc, random() LOOP
return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}rel*/
/*dbg{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id AND cg.enabled ORDER BY cg.pop_id=i_pop_id desc,cg.priority desc, random() LOOP
IF v_gw.contractor_id!=i_dp.vendor_id THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway';
continue;
end if;
return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}dbg*/
else
/*rel{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.contractor_id=i_dp.vendor_id AND cg.enabled ORDER BY cg.priority desc, random() LOOP
return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}rel*/
/*dbg{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.enabled ORDER BY cg.priority desc, random() LOOP
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway';
continue;
end if;
return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}dbg*/
end if;
else
select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled;
if FOUND THEN
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing';
return;
end if;
/*rel{*/
return query select * from
process_gw_release(i_profile, i_destination, i_dp, i_customer_acc,i_customer_gw, i_vendor_acc, v_gw, i_send_billing_information,i_max_call_length);
/*}rel*/
/*dbg{*/
return query select * from
process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc,i_customer_gw, i_vendor_acc, v_gw, i_send_billing_information,i_max_call_length);
/*}dbg*/
else
return;
end if;
end if;
END;
$$;
set search_path TO switch15;
SELECT * from switch15.preprocess_all();
set search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import;
}
end

def down
execute %q{
CREATE OR REPLACE FUNCTION switch15.process_dp(i_profile switch15.callprofile58_ty, i_destination class4.destinations, i_dp class4.dialpeers, i_customer_acc billing.accounts, i_customer_gw class4.gateways, i_vendor_acc billing.accounts, i_pop_id integer, i_send_billing_information boolean, i_max_call_length integer) RETURNS SETOF switch15.callprofile58_ty
LANGUAGE plpgsql STABLE SECURITY DEFINER COST 10000
AS $$
DECLARE
/*dbg{*/
v_start timestamp;
v_end timestamp;
/*}dbg*/
v_gw class4.gateways%rowtype;
BEGIN
/*dbg{*/
v_start:=now();
--RAISE NOTICE 'process_dp in: %',i_profile;5
v_end:=clock_timestamp();
RAISE NOTICE '% ms -> process-DP. Found dialpeer: %',EXTRACT(MILLISECOND from v_end-v_start),row_to_json(i_dp,true);
/*}dbg*/
--RAISE NOTICE 'process_dp dst: %',i_destination;
if i_dp.gateway_id is null then
PERFORM id from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop;
IF FOUND THEN
/*rel{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.contractor_id=i_dp.vendor_id and cg.enabled ORDER BY cg.pop_id=i_pop_id desc,cg.priority desc, random() LOOP
return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}rel*/
/*dbg{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id AND cg.enabled ORDER BY cg.pop_id=i_pop_id desc,cg.priority desc, random() LOOP
IF v_gw.contractor_id!=i_dp.vendor_id THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway';
continue;
end if;
return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}dbg*/
else
/*rel{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.contractor_id=i_dp.vendor_id AND cg.enabled ORDER BY cg.priority desc, random() LOOP
return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}rel*/
/*dbg{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.enabled ORDER BY cg.priority desc, random() LOOP
IF v_gw.contractor_id!=i_dp.vendor_id THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway';
continue;
end if;
return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc,
i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length);
end loop;
/*}dbg*/
end if;
else
select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled;
if FOUND THEN
IF v_gw.contractor_id!=i_dp.vendor_id THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing';
return;
end if;
/*rel{*/
return query select * from
process_gw_release(i_profile, i_destination, i_dp, i_customer_acc,i_customer_gw, i_vendor_acc, v_gw, i_send_billing_information,i_max_call_length);
/*}rel*/
/*dbg{*/
return query select * from
process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc,i_customer_gw, i_vendor_acc, v_gw, i_send_billing_information,i_max_call_length);
/*}dbg*/
else
return;
end if;
end if;
END;
$$;
set search_path TO switch15;
SELECT * from switch15.preprocess_all();
set search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import;
}
end
end
12 changes: 7 additions & 5 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14771,7 +14771,7 @@ BEGIN
/*}rel*/
/*dbg{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.enabled ORDER BY cg.priority desc, random() LOOP
IF v_gw.contractor_id!=i_dp.vendor_id THEN
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway';
continue;
end if;
Expand All @@ -14783,7 +14783,7 @@ BEGIN
else
select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled;
if FOUND THEN
IF v_gw.contractor_id!=i_dp.vendor_id THEN
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing';
return;
end if;
Expand Down Expand Up @@ -14844,7 +14844,7 @@ BEGIN

/*dbg{*/
FOr v_gw in select * from class4.gateways cg where cg.gateway_group_id=i_dp.gateway_group_id and cg.enabled ORDER BY cg.priority desc, random() LOOP
IF v_gw.contractor_id!=i_dp.vendor_id THEN
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway';
continue;
end if;
Expand All @@ -14856,7 +14856,7 @@ BEGIN
else
select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled;
if FOUND THEN
IF v_gw.contractor_id!=i_dp.vendor_id THEN
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing';
return;
end if;
Expand Down Expand Up @@ -14910,7 +14910,7 @@ BEGIN
else
select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled;
if FOUND THEN
IF v_gw.contractor_id!=i_dp.vendor_id THEN
IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN
RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing';
return;
end if;
Expand Down Expand Up @@ -26611,3 +26611,5 @@ INSERT INTO public.schema_migrations (version) VALUES ('20180318143341');

INSERT INTO public.schema_migrations (version) VALUES ('20180320120746');

INSERT INTO public.schema_migrations (version) VALUES ('20180403104223');

Loading

0 comments on commit eb9b94a

Please sign in to comment.