Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mocchira committed Aug 29, 2014
1 parent ef322ef commit 6356d01
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/leo_manager.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@
_ -> 3
end).

-define(env_console_num_of_histories(),
case application:get_env(leo_manager, num_of_histories) of
{ok, EnvNumOfHistories} -> EnvNumOfHistories;
_ -> 200
end).

-define(env_console_user_id(),
case application:get_env(leo_manager, console_user_id) of
{ok, EnvConsoleUserId} -> EnvConsoleUserId;
Expand Down
2 changes: 2 additions & 0 deletions priv/leo_manager_0.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ console.port.json = 10020
console.acceptors.cui = 3
console.acceptors.json = 16

## # of histories to display at once
console.histories.num_of_display = 200

## --------------------------------------------------------------------
## MANAGER - System
Expand Down
8 changes: 8 additions & 0 deletions priv/leo_manager_0.schema
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@
{default, 16}
]}.

%% @doc # of histories to display at once
{mapping,
"console.histories.num_of_display",
"leo_manager.num_of_histories",
[
{datatype, integer},
{default, 200}
]}.

%% --------------------------------------------------------------------
%% MANAGER - System
Expand Down
2 changes: 2 additions & 0 deletions priv/leo_manager_1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ console.port.json = 10021
console.acceptors.cui = 3
console.acceptors.json = 16

## # of histories to display at once
console.histories.num_of_display = 200

## --------------------------------------------------------------------
## MANAGER - Mnesia
Expand Down
8 changes: 8 additions & 0 deletions priv/leo_manager_1.schema
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@
{default, 16}
]}.

%% @doc # of histories to display at once
{mapping,
"console.histories.num_of_display",
"leo_manager.num_of_histories",
[
{datatype, integer},
{default, 200}
]}.

%% --------------------------------------------------------------------
%% MANAGER - Mnesia
Expand Down
2 changes: 1 addition & 1 deletion src/leo_manager_console.erl
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ handle_call(_Socket, <<?CMD_UPDATE_MANAGERS, ?SPACE, Option/binary>> = Command,
%%
handle_call(_Socket, <<?CMD_HISTORY, ?CRLF>>, #state{formatter = Formatter} = State) ->
Fun = fun() ->
case leo_manager_mnesia:get_histories_all() of
case leo_manager_mnesia:get_histories() of
{ok, Histories} ->
Formatter:histories(Histories);
not_found ->
Expand Down
30 changes: 30 additions & 0 deletions src/leo_manager_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
get_rebalance_info_all/0,
get_rebalance_info_by_node/1,
get_histories_all/0,
get_histories/0,
get_histories/1,
get_available_commands_all/0,
get_available_command_by_name/1,

Expand Down Expand Up @@ -369,6 +371,34 @@ get_histories_all() ->
leo_mnesia:read(F)
end.

%% @doc Retrieve histories with default
%%
-spec(get_histories() ->
{ok, list()} | not_found | {error, any()}).
get_histories() ->
get_histories(?env_console_num_of_histories()).

%% @doc Retrieve histories with specified number
%%
-spec(get_histories(pos_integer()) ->
{ok, list()} | not_found | {error, any()}).
get_histories(Count) ->
Tbl = ?TBL_HISTORIES,

case catch mnesia:table_info(Tbl, all) of
{'EXIT', _Cause} ->
{error, ?ERROR_MNESIA_NOT_START};
_ ->
F = fun() ->
Total = mnesia:table_info(Tbl, size),
StartPos = Total - Count + 1,
Q1 = qlc:q([X || {_, ID, _, _} = X <- mnesia:table(Tbl), ID >= StartPos]),
Q2 = qlc:sort(Q1, [{order, ascending}]),
qlc:e(Q2)
end,
leo_mnesia:read(F)
end.


%% @doc Retrieve all available commands
%%
Expand Down

0 comments on commit 6356d01

Please sign in to comment.