From 78d399d0c39fdbfe019c847bbe6ff72a97841436 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Tue, 30 May 2017 23:38:17 +0200 Subject: [PATCH] KAZOO-5492: declare exchange to handle check_sync messages (#3726) * formatting * KAZOO-5492: declare exchange to handle check_sync messages * KAZOO-5492: crossbar does not directly rely on this exchange * KAZOO-5492: keep declaring kapi_switch exchange in crossbar cause it`s actually used in there --- applications/ecallmgr/src/ecallmgr_app.erl | 10 +++++----- applications/ecallmgr/src/ecallmgr_fs_notify.erl | 12 ++++-------- core/kazoo_amqp/src/api/kapi_conf.erl | 3 ++- core/kazoo_amqp/src/api/kz_api.erl | 4 +--- core/kazoo_caches/src/kz_cache.erl | 9 +++++---- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/applications/ecallmgr/src/ecallmgr_app.erl b/applications/ecallmgr/src/ecallmgr_app.erl index 465c22247c4..f07bd27eb43 100644 --- a/applications/ecallmgr/src/ecallmgr_app.erl +++ b/applications/ecallmgr/src/ecallmgr_app.erl @@ -32,11 +32,10 @@ start(_StartType, _StartArgs) -> -spec request(kz_nodes:request_acc()) -> kz_nodes:request_acc(). request(Acc) -> Servers = [{kz_term:to_binary(Server) - ,kz_json:set_values([{<<"Startup">>, Started} - ,{<<"Interface">>, kz_json:from_list(ecallmgr_fs_node:interface(Server))} - ] - ,kz_json:new() - ) + ,kz_json:from_list_recursive( + [{<<"Startup">>, Started} + ,{<<"Interface">>, [ecallmgr_fs_node:interface(Server)]} + ]) } || {Server, Started} <- ecallmgr_fs_nodes:connected('true') ], @@ -69,6 +68,7 @@ declare_exchanges() -> _ = kapi_route:declare_exchanges(), _ = kapi_sysconf:declare_exchanges(), _ = kapi_sms:declare_exchanges(), + _ = kapi_switch:declare_exchanges(), _ = kapi_presence:declare_exchanges(), kapi_self:declare_exchanges(). diff --git a/applications/ecallmgr/src/ecallmgr_fs_notify.erl b/applications/ecallmgr/src/ecallmgr_fs_notify.erl index 90910a28791..88ec3687759 100644 --- a/applications/ecallmgr/src/ecallmgr_fs_notify.erl +++ b/applications/ecallmgr/src/ecallmgr_fs_notify.erl @@ -106,32 +106,28 @@ resp_to_probe(State, User, Realm) -> check_sync_api(JObj, _Props) -> 'true' = kapi_switch:check_sync_v(JObj), kz_util:put_callid(JObj), - check_sync(kapi_switch:check_sync_username(JObj) - ,kapi_switch:check_sync_realm(JObj) - ). + check_sync(kapi_switch:check_sync_username(JObj), kapi_switch:check_sync_realm(JObj)). -spec check_sync(ne_binary(), ne_binary()) -> 'ok'. check_sync(Username, Realm) -> lager:info("looking up registration information for ~s@~s", [Username, Realm]), case ecallmgr_registrar:lookup_registration(Realm, Username) of {'error', 'not_found'} -> - lager:warning("failed to find contact for ~s@~s, not sending check-sync", [Username, Realm]); + lager:warning("failed to find contact ~s@~s, not sending check-sync", [Username, Realm]); {'ok', Registration} -> Contact = kz_json:get_first_defined([<<"Bridge-RURI">>, <<"Contact">>], Registration), [Node|_] = kz_term:shuffle_list(ecallmgr_fs_nodes:connected()), lager:info("calling check sync on ~s for ~s@~s and contact ~s", [Node, Username, Realm, Contact]), case ensure_contact_user(Contact, Username, Realm) of 'undefined' -> - lager:error("invalid contact : ~p : ~p", [Contact, Registration]); + lager:error("invalid contact ~p: ~p", [Contact, Registration]); Valid -> send_check_sync(Node, Username, Realm, Valid) end end. -spec send_check_sync(atom(), ne_binary(), ne_binary(), ne_binary()) -> 'ok'. send_check_sync(Node, Username, Realm, Contact) -> - To = kzsip_uri:uri(#uri{user=Username, domain=Realm}), - From = kzsip_uri:uri(#uri{user=Username, domain=Realm}), - AOR = kzsip_uri:ruri(#uri{user=Username, domain=Realm}), + AOR = To = From = kzsip_uri:ruri(#uri{user=Username, domain=Realm}), SIPHeaders = <<"X-KAZOO-AOR : ", AOR/binary, "\r\n">>, Headers = [{"profile", ?DEFAULT_FS_PROFILE} ,{"contact-uri", Contact} diff --git a/core/kazoo_amqp/src/api/kapi_conf.erl b/core/kazoo_amqp/src/api/kapi_conf.erl index 7787a5da1a0..9206f317496 100644 --- a/core/kazoo_amqp/src/api/kapi_conf.erl +++ b/core/kazoo_amqp/src/api/kapi_conf.erl @@ -109,7 +109,8 @@ get_value(JObj, Key) -> kz_json:get_value(Key, JObj). %%-------------------------------------------------------------------- -%% @doc Format a call event from the switch for the listener +%% @doc +%% Format a call event from the switch for the listener %% Takes proplist, creates JSON string or error %% @end %%-------------------------------------------------------------------- diff --git a/core/kazoo_amqp/src/api/kz_api.erl b/core/kazoo_amqp/src/api/kz_api.erl index 6dc00d26a6c..946548ecdc2 100644 --- a/core/kazoo_amqp/src/api/kz_api.erl +++ b/core/kazoo_amqp/src/api/kz_api.erl @@ -513,9 +513,7 @@ values_check_all(Prop, {Key, V}) -> 'undefined' -> 'true'; % isn't defined in Prop, has_all will error if req'd V -> 'true'; _Val -> - lager:debug("API key '~s' value '~p' is not '~p'" - ,[Key, _Val, V] - ), + lager:debug("API key '~s' value '~p' is not '~p'", [Key, _Val, V]), 'false' end. diff --git a/core/kazoo_caches/src/kz_cache.erl b/core/kazoo_caches/src/kz_cache.erl index a95adc84f9d..0c36e0d5e3e 100644 --- a/core/kazoo_caches/src/kz_cache.erl +++ b/core/kazoo_caches/src/kz_cache.erl @@ -47,7 +47,7 @@ -include("kz_caches.hrl"). -define(SERVER, ?MODULE). --define(EXPIRES, ?SECONDS_IN_HOUR). %% an hour +-define(EXPIRES, ?SECONDS_IN_HOUR). -define(EXPIRE_PERIOD, 10 * ?MILLISECONDS_IN_SECOND). -define(EXPIRE_PERIOD_MSG, 'expire_cache_objects'). -define(DEFAULT_WAIT_TIMEOUT, 5). @@ -65,7 +65,7 @@ -type store_options() :: [{'origin', origin_tuple() | origin_tuples()} | {'expires', kz_timeout()} | {'callback', 'undefined' | callback_fun()} - ] | []. + ]. -export_type([store_options/0]). -record(state, {name :: atom() @@ -108,7 +108,8 @@ start_link(Name, ExpirePeriod, Props) -> BindingProps -> lager:debug("started new cache process (gen_listener): ~s", [Name]), Bindings = [{'conf', ['federate' | P]} || P <- maybe_add_db_binding(BindingProps)], - gen_listener:start_link({'local', Name}, ?MODULE + gen_listener:start_link({'local', Name} + ,?MODULE ,[{'bindings', Bindings} ,{'responders', ?RESPONDERS} ,{'queue_name', ?QUEUE_NAME} @@ -597,7 +598,7 @@ handle_event(JObj, #state{tab=Tab}=State) -> of 'true' -> handle_document_change(JObj, State); 'false' when V -> 'ok'; - 'false' -> lager:error("payload invalid for kapi_conf : ~p", [JObj]) + 'false' -> lager:error("payload invalid for kapi_conf: ~p", [JObj]) end, 'ignore'.