|
| 1 | +class FixProcessDp < ActiveRecord::Migration[5.2] |
| 2 | + def up |
| 3 | + |
| 4 | + execute %q{ |
| 5 | +
|
| 6 | + 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 |
| 7 | + LANGUAGE plpgsql STABLE SECURITY DEFINER COST 10000 |
| 8 | + AS $$ |
| 9 | +DECLARE |
| 10 | + /*dbg{*/ |
| 11 | + v_start timestamp; |
| 12 | + v_end timestamp; |
| 13 | + /*}dbg*/ |
| 14 | + v_gw class4.gateways%rowtype; |
| 15 | + v_gateway_group class4.gateway_groups%rowtype; |
| 16 | +BEGIN |
| 17 | + /*dbg{*/ |
| 18 | + v_start:=now(); |
| 19 | + --RAISE NOTICE 'process_dp in: %',i_profile;5 |
| 20 | + v_end:=clock_timestamp(); |
| 21 | + RAISE NOTICE '% ms -> process-DP. Found dialpeer: %',EXTRACT(MILLISECOND from v_end-v_start),row_to_json(i_dp,true); |
| 22 | + /*}dbg*/ |
| 23 | +
|
| 24 | + --RAISE NOTICE 'process_dp dst: %',i_destination; |
| 25 | + if i_dp.gateway_id is null then /* termination to gw group */ |
| 26 | + select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id; |
| 27 | + IF v_gateway_group.balancing_mode_id=2 THEN |
| 28 | + /*rel{*/ |
| 29 | + FOR v_gw in |
| 30 | + select * from class4.gateways cg |
| 31 | + where |
| 32 | + cg.gateway_group_id=i_dp.gateway_group_id and |
| 33 | + cg.contractor_id=i_dp.vendor_id and |
| 34 | + cg.enabled |
| 35 | + ORDER BY |
| 36 | + cg.pop_id=i_pop_id desc, |
| 37 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 38 | + LOOP |
| 39 | + return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc, |
| 40 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 41 | + end loop; |
| 42 | + /*}rel*/ |
| 43 | + /*dbg{*/ |
| 44 | + FOR v_gw in |
| 45 | + select * from class4.gateways cg |
| 46 | + where |
| 47 | + cg.gateway_group_id=i_dp.gateway_group_id AND |
| 48 | + cg.enabled |
| 49 | + ORDER BY |
| 50 | + cg.pop_id=i_pop_id desc, |
| 51 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 52 | + LOOP |
| 53 | + IF v_gw.contractor_id!=i_dp.vendor_id THEN |
| 54 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway'; |
| 55 | + continue; |
| 56 | + end if; |
| 57 | + return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc, |
| 58 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 59 | + end loop; |
| 60 | + /*}dbg*/ |
| 61 | + elsif v_gateway_group.balancing_mode_id=1 then |
| 62 | + /*rel{*/ |
| 63 | + FOR v_gw in |
| 64 | + select * from class4.gateways cg |
| 65 | + where |
| 66 | + cg.gateway_group_id=i_dp.gateway_group_id AND |
| 67 | + cg.contractor_id=i_dp.vendor_id AND |
| 68 | + cg.enabled |
| 69 | + ORDER BY |
| 70 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 71 | + LOOP |
| 72 | + return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc, |
| 73 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 74 | + end loop; |
| 75 | + /*}rel*/ |
| 76 | + /*dbg{*/ |
| 77 | + FOR v_gw in |
| 78 | + select * from class4.gateways cg |
| 79 | + where |
| 80 | + cg.gateway_group_id=i_dp.gateway_group_id and |
| 81 | + cg.enabled |
| 82 | + ORDER BY |
| 83 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 84 | + LOOP |
| 85 | + IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN |
| 86 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway'; |
| 87 | + continue; |
| 88 | + end if; |
| 89 | + return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc, |
| 90 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 91 | + end loop; |
| 92 | + /*}dbg*/ |
| 93 | +
|
| 94 | + elsif v_gateway_group.balancing_mode_id=3 THEN |
| 95 | + /*rel{*/ |
| 96 | + FOR v_gw in |
| 97 | + select * from class4.gateways cg |
| 98 | + where |
| 99 | + (cg.pop_id is null OR cg.pop_id=i_pop_id) and |
| 100 | + cg.gateway_group_id=i_dp.gateway_group_id and |
| 101 | + cg.contractor_id=i_dp.vendor_id and |
| 102 | + cg.enabled |
| 103 | + ORDER BY |
| 104 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 105 | + LOOP |
| 106 | + return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc, |
| 107 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 108 | + end loop; |
| 109 | + /*}rel*/ |
| 110 | + /*dbg{*/ |
| 111 | + FOR v_gw in |
| 112 | + select * from class4.gateways cg |
| 113 | + where |
| 114 | + cg.gateway_group_id=i_dp.gateway_group_id AND |
| 115 | + cg.enabled |
| 116 | + ORDER BY |
| 117 | + cg.pop_id=i_pop_id desc, |
| 118 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 119 | + LOOP |
| 120 | + IF v_gw.pop_id is not null and v_gw.pop_id!=i_pop_id THEN |
| 121 | + RAISE WARNING 'process_dp: Gateway POP is %, call pop %, skipping.',v_gw.pop_id, i_pop_id; |
| 122 | + continue; |
| 123 | + end if; |
| 124 | + IF v_gw.contractor_id!=i_dp.vendor_id THEN |
| 125 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway'; |
| 126 | + continue; |
| 127 | + end if; |
| 128 | + return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc, |
| 129 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 130 | + end loop; |
| 131 | + /*}dbg*/ |
| 132 | + end if; |
| 133 | + else |
| 134 | + select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled; |
| 135 | + if FOUND THEN |
| 136 | + IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN |
| 137 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing'; |
| 138 | + return; |
| 139 | + end if; |
| 140 | +
|
| 141 | + /*rel{*/ |
| 142 | + return query select * from |
| 143 | + 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); |
| 144 | + /*}rel*/ |
| 145 | + /*dbg{*/ |
| 146 | + return query select * from |
| 147 | + 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); |
| 148 | + /*}dbg*/ |
| 149 | + else |
| 150 | + return; |
| 151 | + end if; |
| 152 | + end if; |
| 153 | +END; |
| 154 | +$$; |
| 155 | +
|
| 156 | +
|
| 157 | + set search_path TO switch18; |
| 158 | + SELECT * from switch18.preprocess_all(); |
| 159 | + set search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import; |
| 160 | +} |
| 161 | + |
| 162 | + |
| 163 | + end |
| 164 | + def down |
| 165 | + |
| 166 | + execute %q{ |
| 167 | +
|
| 168 | +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 |
| 169 | + LANGUAGE plpgsql STABLE SECURITY DEFINER COST 10000 |
| 170 | + AS $$ |
| 171 | +DECLARE |
| 172 | + /*dbg{*/ |
| 173 | + v_start timestamp; |
| 174 | + v_end timestamp; |
| 175 | + /*}dbg*/ |
| 176 | + v_gw class4.gateways%rowtype; |
| 177 | + v_gateway_group class4.gateway_groups%rowtype; |
| 178 | +BEGIN |
| 179 | + /*dbg{*/ |
| 180 | + v_start:=now(); |
| 181 | + --RAISE NOTICE 'process_dp in: %',i_profile;5 |
| 182 | + v_end:=clock_timestamp(); |
| 183 | + RAISE NOTICE '% ms -> process-DP. Found dialpeer: %',EXTRACT(MILLISECOND from v_end-v_start),row_to_json(i_dp,true); |
| 184 | + /*}dbg*/ |
| 185 | +
|
| 186 | + --RAISE NOTICE 'process_dp dst: %',i_destination; |
| 187 | + if i_dp.gateway_id is null then /* termination to gw group */ |
| 188 | + select into v_gateway_group * from class4.gateway_groups where id=i_dp.gateway_group_id and prefer_same_pop; |
| 189 | + IF v_gateway_group.balancing_mode_id=2 THEN |
| 190 | + /*rel{*/ |
| 191 | + FOR v_gw in |
| 192 | + select * from class4.gateways cg |
| 193 | + where |
| 194 | + cg.gateway_group_id=i_dp.gateway_group_id and |
| 195 | + cg.contractor_id=i_dp.vendor_id and |
| 196 | + cg.enabled |
| 197 | + ORDER BY |
| 198 | + cg.pop_id=i_pop_id desc, |
| 199 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 200 | + LOOP |
| 201 | + return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc, |
| 202 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 203 | + end loop; |
| 204 | + /*}rel*/ |
| 205 | + /*dbg{*/ |
| 206 | + FOR v_gw in |
| 207 | + select * from class4.gateways cg |
| 208 | + where |
| 209 | + cg.gateway_group_id=i_dp.gateway_group_id AND |
| 210 | + cg.enabled |
| 211 | + ORDER BY |
| 212 | + cg.pop_id=i_pop_id desc, |
| 213 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 214 | + LOOP |
| 215 | + IF v_gw.contractor_id!=i_dp.vendor_id THEN |
| 216 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway'; |
| 217 | + continue; |
| 218 | + end if; |
| 219 | + return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc, |
| 220 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 221 | + end loop; |
| 222 | + /*}dbg*/ |
| 223 | + elsif v_gateway_group.balancing_mode_id=1 then |
| 224 | + /*rel{*/ |
| 225 | + FOR v_gw in |
| 226 | + select * from class4.gateways cg |
| 227 | + where |
| 228 | + cg.gateway_group_id=i_dp.gateway_group_id AND |
| 229 | + cg.contractor_id=i_dp.vendor_id AND |
| 230 | + cg.enabled |
| 231 | + ORDER BY |
| 232 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 233 | + LOOP |
| 234 | + return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc, |
| 235 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 236 | + end loop; |
| 237 | + /*}rel*/ |
| 238 | + /*dbg{*/ |
| 239 | + FOR v_gw in |
| 240 | + select * from class4.gateways cg |
| 241 | + where |
| 242 | + cg.gateway_group_id=i_dp.gateway_group_id and |
| 243 | + cg.enabled |
| 244 | + ORDER BY |
| 245 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 246 | + LOOP |
| 247 | + IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN |
| 248 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway'; |
| 249 | + continue; |
| 250 | + end if; |
| 251 | + return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc, |
| 252 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 253 | + end loop; |
| 254 | + /*}dbg*/ |
| 255 | +
|
| 256 | + elsif v_gateway_group.balancing_mode_id=3 THEN |
| 257 | + /*rel{*/ |
| 258 | + FOR v_gw in |
| 259 | + select * from class4.gateways cg |
| 260 | + where |
| 261 | + (cg.pop_id is null OR cg.pop_id=i_pop_id) and |
| 262 | + cg.gateway_group_id=i_dp.gateway_group_id and |
| 263 | + cg.contractor_id=i_dp.vendor_id and |
| 264 | + cg.enabled |
| 265 | + ORDER BY |
| 266 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 267 | + LOOP |
| 268 | + return query select * from process_gw_release(i_profile, i_destination, i_dp, i_customer_acc, |
| 269 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 270 | + end loop; |
| 271 | + /*}rel*/ |
| 272 | + /*dbg{*/ |
| 273 | + FOR v_gw in |
| 274 | + select * from class4.gateways cg |
| 275 | + where |
| 276 | + cg.gateway_group_id=i_dp.gateway_group_id AND |
| 277 | + cg.enabled |
| 278 | + ORDER BY |
| 279 | + cg.pop_id=i_pop_id desc, |
| 280 | + yeti_ext.rank_dns_srv(cg.weight) over ( partition by cg.priority order by cg.weight) |
| 281 | + LOOP |
| 282 | + IF v_gw.pop_id is not null and v_gw.pop_id!=i_pop_id THEN |
| 283 | + RAISE WARNING 'process_dp: Gateway POP is %, call pop %, skipping.',v_gw.pop_id, i_pop_id; |
| 284 | + continue; |
| 285 | + end if; |
| 286 | + IF v_gw.contractor_id!=i_dp.vendor_id THEN |
| 287 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Skip gateway'; |
| 288 | + continue; |
| 289 | + end if; |
| 290 | + return query select * from process_gw_debug(i_profile, i_destination, i_dp, i_customer_acc, |
| 291 | + i_customer_gw, i_vendor_acc , v_gw, i_send_billing_information,i_max_call_length); |
| 292 | + end loop; |
| 293 | + /*}dbg*/ |
| 294 | + end if; |
| 295 | + else |
| 296 | + select into v_gw * from class4.gateways cg where cg.id=i_dp.gateway_id and cg.enabled; |
| 297 | + if FOUND THEN |
| 298 | + IF v_gw.contractor_id!=i_dp.vendor_id AND NOT v_gw.is_shared THEN |
| 299 | + RAISE WARNING 'process_dp: Gateway owner !=dialpeer owner. Stop processing'; |
| 300 | + return; |
| 301 | + end if; |
| 302 | +
|
| 303 | + /*rel{*/ |
| 304 | + return query select * from |
| 305 | + 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); |
| 306 | + /*}rel*/ |
| 307 | + /*dbg{*/ |
| 308 | + return query select * from |
| 309 | + 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); |
| 310 | + /*}dbg*/ |
| 311 | + else |
| 312 | + return; |
| 313 | + end if; |
| 314 | + end if; |
| 315 | +END; |
| 316 | +$$; |
| 317 | +
|
| 318 | +
|
| 319 | +
|
| 320 | + set search_path TO switch18; |
| 321 | + SELECT * from switch18.preprocess_all(); |
| 322 | + set search_path TO gui, public, switch, billing, class4, runtime_stats, sys, logs, data_import; |
| 323 | +
|
| 324 | +} |
| 325 | + |
| 326 | + end |
| 327 | +end |
0 commit comments