Skip to content

Commit

Permalink
PISTON-609: send registration notifications from local zone only (260…
Browse files Browse the repository at this point in the history
…0hz#5502)

* PISTON-609: send registration notifications from local zone only

* PISTON-609: fall back to original behaviour if reg zone has no ecallmgrs
  • Loading branch information
danielfinke authored May 1, 2020
1 parent 8ff64d7 commit 379fbfe
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions applications/ecallmgr/src/ecallmgr_registrar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
,initial_registration = kz_time:now_s() :: kz_time:gregorian_seconds() | '_'
,registrar_node :: kz_term:api_ne_binary() | '_'
,registrar_hostname :: kz_term:api_ne_binary() | '_'
,registrar_zone :: atom() | '_'
,suppress_unregister = 'true' :: boolean() | '_'
,register_overwrite_notify = 'false' :: boolean() | '_'
,account_db :: kz_term:api_binary() | '_'
Expand Down Expand Up @@ -836,6 +837,11 @@ create_registration(JObj) ->
,JObj
,Reg#registration.registrar_hostname
),
RegistrarZone =
kz_term:to_atom(kz_json:get_ne_binary_value(<<"AMQP-Broker-Zone">>
,JObj
,kz_nodes:local_zone()
), 'true'),
augment_registration(Reg#registration{username=Username
,realm=Realm
,proxy=Proxy
Expand All @@ -845,6 +851,7 @@ create_registration(JObj) ->
,expires=Expires
,registrar_node=RegistrarNode
,registrar_hostname=RegistrarHostname
,registrar_zone=RegistrarZone
,contact=fix_contact(OriginalContact)
,original_contact=OriginalContact
,bridge_uri=bridge_uri(OriginalContact, Proxy, Username, Realm)
Expand Down Expand Up @@ -1114,8 +1121,9 @@ update_registration(#registration{authorizing_id=AuthorizingId
-spec maybe_send_register_notice(registration()) -> registration().
maybe_send_register_notice(#registration{username=Username
,realm=Realm
,registrar_zone=Zone
}=Reg) ->
case oldest_registrar() of
case should_handle_reg_notice(Zone) of
'false' -> Reg;
'true' ->
lager:debug("sending register notice for ~s@~s", [Username, Realm]),
Expand All @@ -1140,9 +1148,10 @@ maybe_send_deregister_notice(#registration{username=Username
maybe_send_deregister_notice(#registration{username=Username
,realm=Realm
,call_id=CallId
,registrar_zone=Zone
}=Reg) ->
kz_log:put_callid(CallId),
case oldest_registrar() of
case should_handle_reg_notice(Zone) of
'false' -> 'ok';
'true' ->
lager:debug("sending deregister notice for ~s@~s", [Username, Realm]),
Expand Down Expand Up @@ -1226,10 +1235,21 @@ to_props(Reg) ->
]
).

-spec oldest_registrar() -> boolean().
oldest_registrar() ->
kz_nodes:whapp_count(?APP_NAME, 'true') =:= 1
orelse kz_nodes:whapp_oldest_node(?APP_NAME, 'true') =:= node().
-spec should_handle_reg_notice(atom()) -> boolean().
should_handle_reg_notice(Zone) ->
(kz_nodes:local_zone() =:= Zone
andalso oldest_registrar('false'))
orelse (no_registrar_in_reg_zone(Zone)
andalso oldest_registrar('true')).

-spec no_registrar_in_reg_zone(atom()) -> boolean().
no_registrar_in_reg_zone(Zone) ->
kz_nodes:whapp_oldest_node(?APP_NAME, Zone) =:= 'undefined'.

-spec oldest_registrar(boolean()) -> boolean().
oldest_registrar(Federated) ->
kz_nodes:whapp_zone_count(?APP_NAME) =:= 1
orelse kz_nodes:whapp_oldest_node(?APP_NAME, Federated) =:= node().

-spec get_fs_contact(kzd_freeswitch:data()) -> kz_term:ne_binary().
get_fs_contact(FSJObj) ->
Expand Down

0 comments on commit 379fbfe

Please sign in to comment.