chore: reformat mgmt

This commit is contained in:
Zhongwen Deng 2022-04-20 02:27:31 +08:00
parent 2b73a80dba
commit c70462f287
4 changed files with 94 additions and 67 deletions

View File

@ -106,9 +106,11 @@ schema("/configs_reset/:rootname") ->
post => #{ post => #{
tags => [conf], tags => [conf],
description => description =>
<<"Reset the config entry specified by the query string parameter `conf_path`.<br/>\n" <<
"Reset the config entry specified by the query string parameter `conf_path`.<br/>\n"
"- For a config entry that has default value, this resets it to the default value;\n" "- For a config entry that has default value, this resets it to the default value;\n"
"- For a config entry that has no default value, an error 400 will be returned">>, "- For a config entry that has no default value, an error 400 will be returned"
>>,
%% We only return "200" rather than the new configs that has been changed, as %% We only return "200" rather than the new configs that has been changed, as
%% the schema of the changed configs is depends on the request parameter %% the schema of the changed configs is depends on the request parameter
%% `conf_path`, it cannot be defined here. %% `conf_path`, it cannot be defined here.

View File

@ -61,10 +61,13 @@ schema("/listeners_status") ->
get => #{ get => #{
tags => [<<"listeners">>], tags => [<<"listeners">>],
desc => <<"List all running node's listeners live status. group by listener type">>, desc => <<"List all running node's listeners live status. group by listener type">>,
responses => #{200 => responses => #{
200 =>
emqx_dashboard_swagger:schema_with_example( emqx_dashboard_swagger:schema_with_example(
?ARRAY(?R_REF(listener_type_status)), ?ARRAY(?R_REF(listener_type_status)),
listener_type_status_example())} listener_type_status_example()
)
}
} }
}; };
schema("/listeners") -> schema("/listeners") ->
@ -80,10 +83,13 @@ schema("/listeners") ->
#{desc => "Listener type", in => query, required => false, example => tcp} #{desc => "Listener type", in => query, required => false, example => tcp}
)} )}
], ],
responses => #{200 => responses => #{
200 =>
emqx_dashboard_swagger:schema_with_example( emqx_dashboard_swagger:schema_with_example(
?ARRAY(?R_REF(listener_id_status)), ?ARRAY(?R_REF(listener_id_status)),
listener_id_status_example())} listener_id_status_example()
)
}
} }
}; };
schema("/listeners/:id") -> schema("/listeners/:id") ->
@ -188,8 +194,11 @@ fields(listener_id_status) ->
[ [
{enable, ?HOCON(boolean(), #{desc => "Listener enable", required => true})}, {enable, ?HOCON(boolean(), #{desc => "Listener enable", required => true})},
{number, ?HOCON(typerefl:pos_integer(), #{desc => "ListenerId counter"})}, {number, ?HOCON(typerefl:pos_integer(), #{desc => "ListenerId counter"})},
{bind, ?HOCON(hoconsc:union([emqx_schema:ip_port(), integer()]), {bind,
#{desc => "Listener bind addr", required => true})}, ?HOCON(
hoconsc:union([emqx_schema:ip_port(), integer()]),
#{desc => "Listener bind addr", required => true}
)},
{acceptors, ?HOCON(typerefl:pos_integer(), #{desc => "ListenerId acceptors"})}, {acceptors, ?HOCON(typerefl:pos_integer(), #{desc => "ListenerId acceptors"})},
{status, ?HOCON(?R_REF(status))}, {status, ?HOCON(?R_REF(status))},
{node_status, ?HOCON(?ARRAY(?R_REF(node_status)))} {node_status, ?HOCON(?ARRAY(?R_REF(node_status)))}
@ -210,7 +219,8 @@ fields(Type) ->
listener_schema(Opts) -> listener_schema(Opts) ->
emqx_dashboard_swagger:schema_with_example( emqx_dashboard_swagger:schema_with_example(
?UNION(lists:map(fun(#{ref := Ref}) -> Ref end, listeners_info(Opts))), ?UNION(lists:map(fun(#{ref := Ref}) -> Ref end, listeners_info(Opts))),
tcp_schema_example()). tcp_schema_example()
).
listeners_type() -> listeners_type() ->
lists:map( lists:map(
@ -274,11 +284,13 @@ validate_id(Id) ->
%% api %% api
listener_type_status(get, _Request) -> listener_type_status(get, _Request) ->
Listeners = maps:to_list(listener_status_by_type(list_listeners(), #{})), Listeners = maps:to_list(listener_status_by_type(list_listeners(), #{})),
List = lists:map(fun({Type, L}) -> List = lists:map(
fun({Type, L}) ->
L1 = maps:without([bind, acceptors], L), L1 = maps:without([bind, acceptors], L),
L1#{type => Type} L1#{type => Type}
end, end,
Listeners), Listeners
),
{200, List}. {200, List}.
list_listeners(get, #{query_string := Query}) -> list_listeners(get, #{query_string := Query}) ->
@ -566,10 +578,12 @@ listener_type_status_example() ->
node_status => #{ node_status => #{
'emqx@127.0.0.1' => #{ 'emqx@127.0.0.1' => #{
current_connections => 11, current_connections => 11,
max_connections => 1024000}, max_connections => 1024000
},
'emqx@127.0.0.2' => #{ 'emqx@127.0.0.2' => #{
current_connections => 10, current_connections => 10,
max_connections => 1024000} max_connections => 1024000
}
}, },
status => #{ status => #{
current_connections => 21, current_connections => 21,
@ -583,10 +597,12 @@ listener_type_status_example() ->
node_status => #{ node_status => #{
'emqx@127.0.0.1' => #{ 'emqx@127.0.0.1' => #{
current_connections => 31, current_connections => 31,
max_connections => infinity}, max_connections => infinity
},
'emqx@127.0.0.2' => #{ 'emqx@127.0.0.2' => #{
current_connections => 40, current_connections => 40,
max_connections => infinity} max_connections => infinity
}
}, },
status => #{ status => #{
current_connections => 71, current_connections => 71,

View File

@ -22,14 +22,14 @@
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
%% API %% API
-export([ api_spec/0 -export([
, paths/0 api_spec/0,
, schema/1 paths/0,
, namespace/0 schema/1,
]). namespace/0
]).
-export([ sys/2 -export([sys/2]).
]).
-define(TAGS, [<<"sys">>]). -define(TAGS, [<<"sys">>]).
@ -77,14 +77,18 @@ schema("/mqtt/sys_topics") ->
schema_sys_topics() -> schema_sys_topics() ->
emqx_dashboard_swagger:schema_with_example( emqx_dashboard_swagger:schema_with_example(
hoconsc:ref(emqx_schema, "sys_topics"), example_sys_topics()). hoconsc:ref(emqx_schema, "sys_topics"), example_sys_topics()
).
example_sys_topics() -> example_sys_topics() ->
#{<<"sys_event_messages">> => #{
#{<<"client_connected">> => true, <<"sys_event_messages">> =>
#{
<<"client_connected">> => true,
<<"client_disconnected">> => true, <<"client_disconnected">> => true,
<<"client_subscribed">> => false, <<"client_subscribed">> => false,
<<"client_unsubscribed">> => false}, <<"client_unsubscribed">> => false
},
<<"sys_heartbeat_interval">> => <<"30s">>, <<"sys_heartbeat_interval">> => <<"30s">>,
<<"sys_msg_interval">> => <<"1m">> <<"sys_msg_interval">> => <<"1m">>
}. }.

View File

@ -33,14 +33,19 @@ end_per_suite(_) ->
t_get_put(_) -> t_get_put(_) ->
{ok, Default} = get_sys_topics_config(), {ok, Default} = get_sys_topics_config(),
?assertEqual( ?assertEqual(
#{<<"sys_event_messages">> => #{
#{<<"client_connected">> => true, <<"sys_event_messages">> =>
#{
<<"client_connected">> => true,
<<"client_disconnected">> => true, <<"client_disconnected">> => true,
<<"client_subscribed">> => false, <<"client_subscribed">> => false,
<<"client_unsubscribed">> => false <<"client_unsubscribed">> => false
}, },
<<"sys_heartbeat_interval">> => <<"30s">>, <<"sys_heartbeat_interval">> => <<"30s">>,
<<"sys_msg_interval">> => <<"1m">>}, Default), <<"sys_msg_interval">> => <<"1m">>
},
Default
),
NConfig = Default#{ NConfig = Default#{
<<"sys_msg_interval">> => <<"4m">>, <<"sys_msg_interval">> => <<"4m">>,