Skip to content

Commit

Permalink
Merge pull request yeti-switch#562 from dmitry-sinina/fix_gateway_group
Browse files Browse the repository at this point in the history
Fix gateway group
  • Loading branch information
dmitry-sinina authored Oct 22, 2019
2 parents d044a93 + c09d4f5 commit f84b50c
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 5 deletions.
3 changes: 2 additions & 1 deletion config/initializers/pg_dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = [
'-T', 'cdr.cdr_2*',
'-T', 'auth_log.auth_log_2*',
'-T', 'rtp_statistics.streams_*',
'-T', 'rtp_statistics.streams_2*',
'-T', 'logs.api_requests_2*',
'-T', 'pgq.*',
'-T', 'pgq_ext.*'
]
327 changes: 327 additions & 0 deletions db/migrate/20191018180427_fix_process_dp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
class FixProcessDp < ActiveRecord::Migration[5.2]
def up

execute %q{
CREATE or replace FUNCTION switch18.process_dp(i_profile switch18.callprofile62_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 switch18.callprofile62_ty
LANGUAGE plpgsql STABLE SECURITY DEFINER COST 10000
AS $$
DECLARE
/*dbg{*/
v_start timestamp;
v_end timestamp;
/*}dbg*/
v_gw class4.gateways%rowtype;
v_gateway_group class4.gateway_groups%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 /* termination to gw group */
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id;
IF v_gateway_group.balancing_mode_id=2 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,
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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,
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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*/
elsif v_gateway_group.balancing_mode_id=1 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
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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*/
elsif v_gateway_group.balancing_mode_id=3 THEN
/*rel{*/
FOR v_gw in
select * from class4.gateways cg
where
(cg.pop_id is null OR cg.pop_id=i_pop_id) and
cg.gateway_group_id=i_dp.gateway_group_id and
cg.contractor_id=i_dp.vendor_id and
cg.enabled
ORDER BY
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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,
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
LOOP
IF v_gw.pop_id is not null and v_gw.pop_id!=i_pop_id THEN
RAISE WARNING 'process_dp: Gateway POP is %, call pop %, skipping.',v_gw.pop_id, i_pop_id;
continue;
end if;
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 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 switch18;
SELECT * from switch18.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 switch18.process_dp(i_profile switch18.callprofile62_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 switch18.callprofile62_ty
LANGUAGE plpgsql STABLE SECURITY DEFINER COST 10000
AS $$
DECLARE
/*dbg{*/
v_start timestamp;
v_end timestamp;
/*}dbg*/
v_gw class4.gateways%rowtype;
v_gateway_group class4.gateway_groups%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 /* termination to gw group */
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop;
IF v_gateway_group.balancing_mode_id=2 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,
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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,
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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*/
elsif v_gateway_group.balancing_mode_id=1 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
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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*/
elsif v_gateway_group.balancing_mode_id=3 THEN
/*rel{*/
FOR v_gw in
select * from class4.gateways cg
where
(cg.pop_id is null OR cg.pop_id=i_pop_id) and
cg.gateway_group_id=i_dp.gateway_group_id and
cg.contractor_id=i_dp.vendor_id and
cg.enabled
ORDER BY
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
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,
yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight)
LOOP
IF v_gw.pop_id is not null and v_gw.pop_id!=i_pop_id THEN
RAISE WARNING 'process_dp: Gateway POP is %, call pop %, skipping.',v_gw.pop_id, i_pop_id;
continue;
end if;
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 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 switch18;
SELECT * from switch18.preprocess_all();
set search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import;
}

end
end
9 changes: 5 additions & 4 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32546,7 +32546,7 @@ BEGIN

--RAISE NOTICE 'process_dp dst: %',i_destination;
if i_dp.gateway_id is null then /* termination to gw group */
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop;
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id;
IF v_gateway_group.balancing_mode_id=2 THEN
/*rel{*/
FOR v_gw in
Expand Down Expand Up @@ -32701,7 +32701,7 @@ BEGIN

--RAISE NOTICE 'process_dp dst: %',i_destination;
if i_dp.gateway_id is null then /* termination to gw group */
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop;
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id;
IF v_gateway_group.balancing_mode_id=2 THEN

/*dbg{*/
Expand Down Expand Up @@ -32804,7 +32804,7 @@ BEGIN

--RAISE NOTICE 'process_dp dst: %',i_destination;
if i_dp.gateway_id is null then /* termination to gw group */
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop;
select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id;
IF v_gateway_group.balancing_mode_id=2 THEN
/*rel{*/
FOR v_gw in
Expand Down Expand Up @@ -47058,6 +47058,7 @@ INSERT INTO "public"."schema_migrations" (version) VALUES
('20190707141219'),
('20190904174903'),
('20190919080917'),
('20191016183312');
('20191016183312'),
('20191018180427');


0 comments on commit f84b50c

Please sign in to comment.