Update copyright and format code

This commit is contained in:
Feng Lee 2017-02-16 11:19:02 +08:00
parent 640c9287c2
commit d93caa7c9e
1 changed files with 26 additions and 9 deletions

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_cli). -module(emqttd_cli).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_cli.hrl"). -include("emqttd_cli.hrl").
@ -57,6 +59,7 @@ is_cmd(Fun) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Node status %% @doc Node status
status([]) -> status([]) ->
{InternalStatus, _ProvidedStatus} = init:get_status(), {InternalStatus, _ProvidedStatus} = init:get_status(),
?PRINT("Node ~p is ~p~n", [node(), InternalStatus]), ?PRINT("Node ~p is ~p~n", [node(), InternalStatus]),
@ -71,6 +74,7 @@ status(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Query broker %% @doc Query broker
broker([]) -> broker([]) ->
Funs = [sysdescr, version, uptime, datetime], Funs = [sysdescr, version, uptime, datetime],
foreach(fun(Fun) -> foreach(fun(Fun) ->
@ -105,6 +109,7 @@ broker(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Cluster with other nodes %% @doc Cluster with other nodes
cluster(["join", SNode]) -> cluster(["join", SNode]) ->
case emqttd_cluster:join(emqttd_node:parse_name(SNode)) of case emqttd_cluster:join(emqttd_node:parse_name(SNode)) of
ok -> ok ->
@ -143,10 +148,12 @@ cluster(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Users usage %% @doc Users usage
users(Args) -> emq_auth_username:cli(Args). users(Args) -> emq_auth_username:cli(Args).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Query clients %% @doc Query clients
clients(["list"]) -> clients(["list"]) ->
dump(mqtt_client); dump(mqtt_client);
@ -169,14 +176,17 @@ if_client(ClientId, Fun) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Sessions Command %% @doc Sessions Command
sessions(["list"]) -> sessions(["list"]) ->
dump(mqtt_local_session); dump(mqtt_local_session);
%% performance issue? %% performance issue?
sessions(["list", "persistent"]) -> sessions(["list", "persistent"]) ->
lists:foreach(fun print/1, ets:match_object(mqtt_local_session, {'_', '_', false, '_'})); lists:foreach(fun print/1, ets:match_object(mqtt_local_session, {'_', '_', false, '_'}));
%% performance issue? %% performance issue?
sessions(["list", "transient"]) -> sessions(["list", "transient"]) ->
lists:foreach(fun print/1, ets:match_object(mqtt_local_session, {'_', '_', true, '_'})); lists:foreach(fun print/1, ets:match_object(mqtt_local_session, {'_', '_', true, '_'}));
@ -194,6 +204,7 @@ sessions(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Routes Command %% @doc Routes Command
routes(["list"]) -> routes(["list"]) ->
Routes = emqttd_router:dump(), Routes = emqttd_router:dump(),
foreach(fun print/1, Routes); foreach(fun print/1, Routes);
@ -207,6 +218,7 @@ routes(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Topics Command %% @doc Topics Command
topics(["list"]) -> topics(["list"]) ->
lists:foreach(fun(Topic) -> ?PRINT("~s~n", [Topic]) end, emqttd:topics()); lists:foreach(fun(Topic) -> ?PRINT("~s~n", [Topic]) end, emqttd:topics());
@ -260,14 +272,14 @@ subscriptions(_) ->
{"subscriptions del <ClientId>", "Delete static subscriptions manually"}, {"subscriptions del <ClientId>", "Delete static subscriptions manually"},
{"subscriptions del <ClientId> <Topic>", "Delete a static subscription manually"}]). {"subscriptions del <ClientId> <Topic>", "Delete a static subscription manually"}]).
if_could_print(Tab, Fun) -> % if_could_print(Tab, Fun) ->
case mnesia:table_info(Tab, size) of % case mnesia:table_info(Tab, size) of
Size when Size >= ?MAX_LIMIT -> % Size when Size >= ?MAX_LIMIT ->
?PRINT("Could not list, too many ~ss: ~p~n", [Tab, Size]); % ?PRINT("Could not list, too many ~ss: ~p~n", [Tab, Size]);
_Size -> % _Size ->
Keys = mnesia:dirty_all_keys(Tab), % Keys = mnesia:dirty_all_keys(Tab),
foreach(fun(Key) -> Fun(ets:lookup(Tab, Key)) end, Keys) % foreach(fun(Key) -> Fun(ets:lookup(Tab, Key)) end, Keys)
end. % end.
if_valid_qos(QoS, Fun) -> if_valid_qos(QoS, Fun) ->
try list_to_integer(QoS) of try list_to_integer(QoS) of
@ -303,6 +315,7 @@ plugins(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Bridges command %% @doc Bridges command
bridges(["list"]) -> bridges(["list"]) ->
foreach(fun({Node, Topic, _Pid}) -> foreach(fun({Node, Topic, _Pid}) ->
?PRINT("bridge: ~s--~s-->~s~n", [node(), Topic, Node]) ?PRINT("bridge: ~s--~s-->~s~n", [node(), Topic, Node])
@ -360,6 +373,7 @@ parse_opt(_Cmd, Opt, _Val) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc vm command %% @doc vm command
vm([]) -> vm([]) ->
vm(["all"]); vm(["all"]);
@ -398,6 +412,7 @@ vm(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc mnesia Command %% @doc mnesia Command
mnesia([]) -> mnesia([]) ->
mnesia:system_info(); mnesia:system_info();
@ -406,6 +421,7 @@ mnesia(_) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Trace Command %% @doc Trace Command
trace(["list"]) -> trace(["list"]) ->
foreach(fun({{Who, Name}, LogFile}) -> foreach(fun({{Who, Name}, LogFile}) ->
?PRINT("trace ~s ~s -> ~s~n", [Who, Name, LogFile]) ?PRINT("trace ~s ~s -> ~s~n", [Who, Name, LogFile])
@ -448,6 +464,7 @@ trace_off(Who, Name) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Listeners Command %% @doc Listeners Command
listeners([]) -> listeners([]) ->
foreach(fun({{Protocol, ListenOn}, Pid}) -> foreach(fun({{Protocol, ListenOn}, Pid}) ->
Info = [{acceptors, esockd:get_acceptors(Pid)}, Info = [{acceptors, esockd:get_acceptors(Pid)},