Permalink
Browse files

KAZOO-590: Refactor wh_config, amqp & couch bootstrap

  • Loading branch information...
1 parent 9b68da0 commit d93d45be8d092dd988dd3a53e1f5748d1ac54423 Peter Defebvre committed Mar 21, 2013
@@ -42,7 +42,7 @@
%% @end
%%--------------------------------------------------------------------
start_link() ->
- gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+ gen_server:start_link({'local', ?SERVER}, ?MODULE, [], []).
%%%===================================================================
%%% gen_server callbacks
@@ -62,7 +62,7 @@ start_link() ->
init([]) ->
put(callid, ?LOG_SYSTEM_ID),
Init = get_config(),
- URIs = case props:get_value(uri, Init, ?DEFAULT_AMQP_URI) of
+ URIs = case props:get_value('uri', Init, ?DEFAULT_AMQP_URI) of
URI = "amqp://"++_ ->
[URI];
URI = "amqps://"++_ ->
@@ -75,7 +75,7 @@ init([]) ->
wh_amqp_connections:wait_for_available(),
timer:sleep(2000),
lager:debug("current amqp connection: ~p", [wh_amqp_connections:current()]),
- {ok, #state{}, 100}.
+ {'ok', #state{}, 100}.
%%--------------------------------------------------------------------
%% @private
@@ -92,7 +92,7 @@ init([]) ->
%% @end
%%--------------------------------------------------------------------
handle_call(_Request, _From, State) ->
- {reply, {error, not_implemented}, State}.
+ {'reply', {'error', 'not_implemented'}, State}.
%%--------------------------------------------------------------------
%% @private
@@ -105,7 +105,7 @@ handle_call(_Request, _From, State) ->
%% @end
%%--------------------------------------------------------------------
handle_cast(_Msg, State) ->
- {noreply, State}.
+ {'noreply', State}.
%%--------------------------------------------------------------------
%% @private
@@ -117,12 +117,12 @@ handle_cast(_Msg, State) ->
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
-handle_info(timeout, State) ->
+handle_info('timeout', State) ->
_ = wh_amqp_sup:stop_bootstrap(),
- {noreply, State};
+ {'noreply', State};
handle_info(_Info, State) ->
lager:debug("unhandled message: ~p", [_Info]),
- {noreply, State}.
+ {'noreply', State}.
%%--------------------------------------------------------------------
%% @private
@@ -147,7 +147,7 @@ terminate(_Reason, _State) ->
%% @end
%%--------------------------------------------------------------------
code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
+ {'ok', State}.
%%%===================================================================
%%% Internal functions
@@ -80,9 +80,11 @@ get_atom(Section, Key, Default) ->
%% Return values of the config file
%% @end
%%--------------------------------------------------------------------
+-spec get_integer(section(), atom(), Default) -> [integer(),...] | ?DEFAULT_DEFAULT.
get_integer(Section, Key) ->
get_integer(Section, Key, ?DEFAULT_DEFAULT).
+-spec get_integer(section(), atom(), Default) -> [integer(),...] | Default.
get_integer(Section, Key, Default) ->
case ?MODULE:get(Section, Key, Default) of
Default -> Default;
@@ -95,9 +97,11 @@ get_integer(Section, Key, Default) ->
%% Return values of the config file
%% @end
%%--------------------------------------------------------------------
+-spec get_string(section(), string(), Default) -> [string(),...] | ?DEFAULT_DEFAULT.
get_string(Section, Key) ->
get_string(Section, Key, ?DEFAULT_DEFAULT).
+-spec get_string(section(), string(), Default) -> [string(),...] | Default.
get_string(Section, Key, Default) ->
case ?MODULE:get(Section, Key, Default) of
Default -> Default;
@@ -110,6 +114,7 @@ get_string(Section, Key, Default) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec get_atom(section(), atom(), Default) -> [integer(),...] | ?DEFAULT_DEFAULT.
find_values(Section, 'undefined') ->
{'ok', Prop} = load(),
get_sections(Section, Prop);
@@ -130,6 +135,7 @@ find_values(Section, Key) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec get_sections(section(), wh_proplist()) -> wh_proplist() | [].
get_sections(Section, Prop) ->
Sections = proplists:get_all_values(Section, Prop),
format_sections(Sections).
@@ -140,6 +146,7 @@ get_sections(Section, Prop) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec format_sections(wh_proplist()) -> wh_proplist() | [].
format_sections(Sections) ->
format_sections(Sections, []).
@@ -159,6 +166,7 @@ format_sections([Section | T], Acc) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec local_sections(wh_proplist()) -> wh_proplist() | [].
local_sections(Sections) ->
local_sections(Sections, []).
@@ -180,6 +188,7 @@ local_sections([Section | T], Acc) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec is_local_section({ne_binary(), _}) -> {'false', 'generic'} | {boolean(), ne_binary()}.
is_local_section({SectionHost, _}) ->
LocalHost = wh_util:to_binary(wh_network_utils:get_hostname()),
case SectionHost of
@@ -200,6 +209,7 @@ is_local_section({SectionHost, _}) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec get_value(atom(), wh_proplist()) -> lists().
get_values(Key, Sections) ->
get_values(Sections, Key, []).
@@ -217,6 +227,7 @@ get_values([{_, Values} | T], Key, Acc) ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec load() -> {'ok', wh_proplist()} | _.
load() ->
case os:getenv(?CONFIG_FILE_ENV) of
'false' ->
@@ -231,6 +242,7 @@ load() ->
%%
%% @end
%%--------------------------------------------------------------------
+-spec load_file(string()) -> {'ok', wh_proplist()} | _.
load_file(File) ->
case zucchini:parse_file(File) of
{'ok', Prop} ->
@@ -58,12 +58,12 @@ init([]) ->
%% TODO: for the time being just maintain backward compatability
wh_couch_connections:add(create_connection(Config)),
wh_couch_connections:add(create_admin_connection(Config)),
- AutoCmpt = wh_config:get('bigcouch', 'compact_automatically'),
+ [AutoCmpt|_] = wh_config:get('bigcouch', 'compact_automatically'),
CacheProps = [{'expires', 'infinity'}
,{'origin', {'db', ?WH_CONFIG_DB, <<"whistle_couch">>}}
],
wh_cache:store_local(?WH_COUCH_CACHE, <<"compact_automatically">>, AutoCmpt, CacheProps),
- Cookie = wh_config:get_atom('bigcouch', 'cookie', 'change_me'),
+ [Cookie|_] = wh_config:get_atom('bigcouch', 'cookie', 'change_me'),
wh_couch_connections:set_node_cookie(Cookie),
lager:info("waiting for first bigcouch/haproxy connection...", []),
wh_couch_connections:wait_for_connection(),
@@ -146,14 +146,12 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================
-spec get_config() -> {'ok', wh_proplist()}.
get_config() ->
- [{'default_couch_host',
- {wh_config:get_default(bigcouch, ip, "")
- ,wh_config:get_integer(bigcouch, port, 5984)
- ,wh_config:get_string(bigcouch, username, "")
- ,wh_config:get_string(bigcouch, password, "")
- ,wh_config:get_integer(bigcouch, admin_port, 5986)
- }
- }].
+ [IP|_] = wh_config:get(bigcouch, ip, [""]),
+ [Port|_] = wh_config:get_integer(bigcouch, port, 5984),
+ [Username|_] = wh_config:get_string(bigcouch, username, [""]),
+ [Pwd|_] = wh_config:get_string(bigcouch, password, [""]),
+ [AdminPort|_] = wh_config:get_integer(bigcouch, admin_port, 5986),
+ [{'default_couch_host', {IP, Port, Username, Pwd, AdminPort}}].
-spec create_connection(wh_proplist()) -> couch_connection().
create_connection(Props) ->

0 comments on commit d93d45b

Please sign in to comment.