Skip to content

Commit

Permalink
WHISTLE-42: compare decoded call ids only, and allow fs longer to ret…
Browse files Browse the repository at this point in the history
…urn a list of calls
  • Loading branch information
k-anderson committed Feb 25, 2012
1 parent e1487b9 commit 94c4adb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 40 deletions.
12 changes: 6 additions & 6 deletions ecallmgr/src/ecallmgr_call_control.erl
Expand Up @@ -145,11 +145,11 @@ add_leg(Props) ->
%% by call_control, if so add the leg to it %% by call_control, if so add the leg to it
CallId = props:get_value(<<"Other-Leg-Unique-ID">>, Props), CallId = props:get_value(<<"Other-Leg-Unique-ID">>, Props),
put(callid, CallId), put(callid, CallId),
case is_binary(CallId) andalso ecallmgr_call_control_sup:find_worker(CallId) of case is_binary(CallId) andalso ecallmgr_call_control_sup:find_workers(CallId) of
false -> ok; false -> ok;
{error, _} -> ok; {error, _} -> ok;
{ok, Srv} -> {ok, Srvs} ->
gen_server:cast(Srv, {add_leg, wh_json:from_list(Props)}) [gen_server:cast(Srv, {add_leg, wh_json:from_list(Props)}) || Srv <- Srvs]
end end
end). end).


Expand All @@ -160,11 +160,11 @@ rm_leg(Props) ->
%% by call_control, if so remove the leg from it %% by call_control, if so remove the leg from it
CallId = props:get_value(<<"Other-Leg-Unique-ID">>, Props), CallId = props:get_value(<<"Other-Leg-Unique-ID">>, Props),
put(callid, CallId), put(callid, CallId),
case is_binary(CallId) andalso ecallmgr_call_control_sup:find_worker(CallId) of case is_binary(CallId) andalso ecallmgr_call_control_sup:find_workers(CallId) of
false -> ok; false -> ok;
{error, _} -> ok; {error, _} -> ok;
{ok, Srv} -> {ok, Srvs} ->
gen_server:cast(Srv, {rm_leg, wh_json:from_list(Props)}) [gen_server:cast(Srv, {rm_leg, wh_json:from_list(Props)}) || Srv <- Srvs]
end end
end). end).


Expand Down
25 changes: 14 additions & 11 deletions ecallmgr/src/ecallmgr_call_control_sup.erl
Expand Up @@ -17,7 +17,7 @@
%% API %% API
-export([start_link/0, start_proc/1]). -export([start_link/0, start_proc/1]).
-export([workers/0]). -export([workers/0]).
-export([find_worker/1]). -export([find_workers/1]).
-export([find_control_queue/1]). -export([find_control_queue/1]).


-include("ecallmgr.hrl"). -include("ecallmgr.hrl").
Expand Down Expand Up @@ -52,24 +52,27 @@ workers() ->
Worker =:= ecallmgr_call_control Worker =:= ecallmgr_call_control
]. ].


-spec find_worker/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', pid()}. -spec find_workers/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', [pid(),...]}.
-spec do_find_worker/2 :: ([pid(),...] | [], ne_binary()) -> {'error', 'not_found'} | {'ok', pid()}. -spec do_find_worker/3 :: ([pid(),...] | [], [pid(),...] | [], ne_binary()) -> {'error', 'not_found'} | {'ok', pid()}.
find_worker(CallID) -> find_workers(CallID) ->
do_find_worker(workers(), CallID). C = wh_util:to_binary(http_uri:decode(wh_util:to_list(CallID))),
do_find_worker(workers(), [], C).


do_find_worker([], _CallId) -> do_find_worker([], [], _CallId) ->
{error, not_found}; {error, not_found};
do_find_worker([Srv|T], CallID) -> do_find_worker([], Acc, _CallId) ->
{ok, Acc};
do_find_worker([Srv|T], Acc, CallID) ->
case catch(ecallmgr_call_control:callid(Srv)) of case catch(ecallmgr_call_control:callid(Srv)) of
CallID -> {ok, Srv}; CallID -> do_find_worker(T, [Srv|Acc], CallID);
_E -> do_find_worker(T, CallID) _E -> do_find_worker(T, Acc, CallID)
end. end.


-spec find_control_queue/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', ne_binary()}. -spec find_control_queue/1 :: (ne_binary()) -> {'error', 'not_found'} | {'ok', ne_binary()}.
find_control_queue(CallID) -> find_control_queue(CallID) ->
case find_worker(CallID) of case find_workers(CallID) of
{error, _}=E -> E; {error, _}=E -> E;
{ok, Worker} -> {ok, [Worker|_]} ->
{ok, ecallmgr_call_control:queue_name(Worker)} {ok, ecallmgr_call_control:queue_name(Worker)}
end. end.


Expand Down
44 changes: 28 additions & 16 deletions ecallmgr/src/ecallmgr_fs_node.erl
Expand Up @@ -52,35 +52,35 @@ distributed_presence(Srv, Type, Event) ->


-spec show_channels/1 :: (pid()) -> [proplist(),...] | []. -spec show_channels/1 :: (pid()) -> [proplist(),...] | [].
show_channels(Srv) -> show_channels(Srv) ->
case catch(gen_server:call(Srv, show_channels, 100)) of case catch(gen_server:call(Srv, show_channels, ?FS_TIMEOUT)) of
{'EXIT', _} -> []; {'EXIT', _} -> [];
Else -> Else Else -> Else
end. end.


-spec hostname/1 :: (pid()) -> fs_api_ret(). -spec hostname/1 :: (pid()) -> fs_api_ret().
hostname(Srv) -> hostname(Srv) ->
case catch(gen_server:call(Srv, hostname, 100)) of case catch(gen_server:call(Srv, hostname, ?FS_TIMEOUT)) of
{'EXIT', _} -> timeout; {'EXIT', _} -> timeout;
Else -> Else Else -> Else
end. end.


-spec fs_node/1 :: (pid()) -> atom(). -spec fs_node/1 :: (pid()) -> atom().
fs_node(Srv) -> fs_node(Srv) ->
case catch(gen_server:call(Srv, fs_node, 100)) of case catch(gen_server:call(Srv, fs_node, ?FS_TIMEOUT)) of
{'EXIT', _} -> undefined; {'EXIT', _} -> undefined;
Else -> Else Else -> Else
end. end.


-spec uuid_exists/2 :: (pid(), ne_binary()) -> boolean(). -spec uuid_exists/2 :: (pid(), ne_binary()) -> boolean().
uuid_exists(Srv, UUID) -> uuid_exists(Srv, UUID) ->
case catch(gen_server:call(Srv, {uuid_exists, UUID}, 100)) of case catch(gen_server:call(Srv, {uuid_exists, UUID}, ?FS_TIMEOUT)) of
{'EXIT', _} -> false; {'EXIT', _} -> false;
Else -> Else Else -> Else
end. end.


-spec uuid_dump/2 :: (pid(), ne_binary()) -> {'ok', proplist()} | {'error', ne_binary()} | 'timeout'. -spec uuid_dump/2 :: (pid(), ne_binary()) -> {'ok', proplist()} | {'error', ne_binary()} | 'timeout'.
uuid_dump(Srv, UUID) -> uuid_dump(Srv, UUID) ->
case catch(gen_server:call(Srv, {uuid_dump, UUID}, 100)) of case catch(gen_server:call(Srv, {uuid_dump, UUID}, ?FS_TIMEOUT)) of
{'EXIT', _} -> []; {'EXIT', _} -> [];
Else -> Else Else -> Else
end. end.
Expand Down Expand Up @@ -449,10 +449,14 @@ process_transfer_event(<<"BLIND_TRANSFER">>, Data) ->
_ -> _ ->
props:get_value(<<"Transferee-UUID">>, Data) props:get_value(<<"Transferee-UUID">>, Data)
end, end,
case ecallmgr_call_control_sup:find_worker(TransfererCtrlUUId) of case ecallmgr_call_control_sup:find_workers(TransfererCtrlUUId) of
{ok, Pid1} -> {ok, Pids} ->
?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid1]), [begin
ecallmgr_call_control:transferer(Pid1, Data); ecallmgr_call_control:transferer(Pid, Data),
?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid])
end
|| Pid <- Pids
];
{error, not_found} -> {error, not_found} ->
ok ok
end; end;
Expand All @@ -463,18 +467,26 @@ process_transfer_event(_, Data) ->
_ -> _ ->
props:get_value(<<"Transferee-UUID">>, Data) props:get_value(<<"Transferee-UUID">>, Data)
end, end,
case ecallmgr_call_control_sup:find_worker(TransfererCtrlUUId) of case ecallmgr_call_control_sup:find_workers(TransfererCtrlUUId) of
{ok, Pid1} -> {ok, TransfererPids} ->
?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid1]), [begin
ecallmgr_call_control:transferer(Pid1, Data); ecallmgr_call_control:transferer(Pid, Data),
?LOG(TransfererCtrlUUId, "sending transferer notice to ecallmgr_call_control ~p", [Pid])
end
|| Pid <- TransfererPids
];
{error, not_found} -> {error, not_found} ->
ok ok
end, end,
TransfereeCtrlUUId = props:get_value(<<"Replaces">>, Data), TransfereeCtrlUUId = props:get_value(<<"Replaces">>, Data),
case ecallmgr_call_control_sup:find_worker(TransfereeCtrlUUId) of case ecallmgr_call_control_sup:find_worker(TransfereeCtrlUUId) of
{ok, Pid2} -> {ok, ReplacesPids} ->
?LOG(TransfereeCtrlUUId, "sending transferee notice to ecallmgr_call_control ~p", [Pid2]), [begin
ecallmgr_call_control:transferee(Pid2, Data); ecallmgr_call_control:transferee(Pid, Data),
?LOG(TransfereeCtrlUUId, "sending transferee notice to ecallmgr_call_control ~p", [Pid])
end
|| Pid <- ReplacesPids
];
{error, not_found} -> {error, not_found} ->
ok ok
end. end.
Expand Down
8 changes: 1 addition & 7 deletions ecallmgr/src/ecallmgr_fs_query.erl
Expand Up @@ -127,13 +127,7 @@ handle_channel_query(JObj, _Props) ->


-spec channel_query/1 :: (wh_json:json_object()) -> wh_json:json_objects(). -spec channel_query/1 :: (wh_json:json_object()) -> wh_json:json_objects().
channel_query(JObj) -> channel_query(JObj) ->
SearchParams = lists:foldl(fun(Field, Acc) -> Channels = lists:concat([ecallmgr_fs_node:show_channels(Pid) || Pid <- ecallmgr_fs_sup:node_handlers()]),
case wh_json:get_value(Field, JObj) of
undefined -> Acc;
Value -> [{Field, Value} | Acc]
end
end, [], wapi_call:channel_query_search_fields()),
Channels = lists:flatten([ecallmgr_fs_node:show_channels(Pid) || Pid <- ecallmgr_fs_sup:node_handlers()]),
SearchParams = lists:foldl(fun(Field, Acc) -> SearchParams = lists:foldl(fun(Field, Acc) ->
case wh_json:get_value(Field, JObj) of case wh_json:get_value(Field, JObj) of
undefined -> Acc; undefined -> Acc;
Expand Down

0 comments on commit 94c4adb

Please sign in to comment.