chore: reformat mgmt
This commit is contained in:
parent
2b73a80dba
commit
c70462f287
|
@ -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"
|
<<
|
||||||
"- For a config entry that has default value, this resets it to the default value;\n"
|
"Reset the config entry specified by the query string parameter `conf_path`.<br/>\n"
|
||||||
"- For a config entry that has no default value, an error 400 will be returned">>,
|
"- 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"
|
||||||
|
>>,
|
||||||
%% 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.
|
||||||
|
|
|
@ -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 => #{
|
||||||
emqx_dashboard_swagger:schema_with_example(
|
200 =>
|
||||||
?ARRAY(?R_REF(listener_type_status)),
|
emqx_dashboard_swagger:schema_with_example(
|
||||||
listener_type_status_example())}
|
?ARRAY(?R_REF(listener_type_status)),
|
||||||
|
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 => #{
|
||||||
emqx_dashboard_swagger:schema_with_example(
|
200 =>
|
||||||
?ARRAY(?R_REF(listener_id_status)),
|
emqx_dashboard_swagger:schema_with_example(
|
||||||
listener_id_status_example())}
|
?ARRAY(?R_REF(listener_id_status)),
|
||||||
|
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(
|
||||||
L1 = maps:without([bind, acceptors], L),
|
fun({Type, L}) ->
|
||||||
L1#{type => Type}
|
L1 = maps:without([bind, acceptors], L),
|
||||||
end,
|
L1#{type => Type}
|
||||||
Listeners),
|
end,
|
||||||
|
Listeners
|
||||||
|
),
|
||||||
{200, List}.
|
{200, List}.
|
||||||
|
|
||||||
list_listeners(get, #{query_string := Query}) ->
|
list_listeners(get, #{query_string := Query}) ->
|
||||||
|
@ -566,13 +578,15 @@ 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,
|
||||||
max_connections => 2048000
|
max_connections => 2048000
|
||||||
},
|
},
|
||||||
type => tcp
|
type => tcp
|
||||||
|
@ -583,13 +597,15 @@ 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,
|
||||||
max_connections => infinity
|
max_connections => infinity
|
||||||
},
|
},
|
||||||
type => ssl
|
type => ssl
|
||||||
|
@ -600,8 +616,8 @@ listener_id_status_example() ->
|
||||||
[
|
[
|
||||||
#{
|
#{
|
||||||
acceptors => 16,
|
acceptors => 16,
|
||||||
bind => <<"0.0.0.0:1884">>,
|
bind => <<"0.0.0.0:1884">>,
|
||||||
enable => true,
|
enable => true,
|
||||||
id => <<"tcp:demo">>,
|
id => <<"tcp:demo">>,
|
||||||
node_status => #{
|
node_status => #{
|
||||||
'emqx@127.0.0.1' => #{
|
'emqx@127.0.0.1' => #{
|
||||||
|
@ -621,8 +637,8 @@ listener_id_status_example() ->
|
||||||
},
|
},
|
||||||
#{
|
#{
|
||||||
acceptors => 32,
|
acceptors => 32,
|
||||||
bind => <<"0.0.0.0:1883">>,
|
bind => <<"0.0.0.0:1883">>,
|
||||||
enable => true,
|
enable => true,
|
||||||
id => <<"tcp:default">>,
|
id => <<"tcp:default">>,
|
||||||
node_status => #{
|
node_status => #{
|
||||||
'emqx@127.0.0.1' => #{
|
'emqx@127.0.0.1' => #{
|
||||||
|
@ -652,8 +668,8 @@ tcp_schema_example() ->
|
||||||
max_connections => 204800,
|
max_connections => 204800,
|
||||||
mountpoint => <<"/">>,
|
mountpoint => <<"/">>,
|
||||||
proxy_protocol => false,
|
proxy_protocol => false,
|
||||||
proxy_protocol_timeout => <<"3s">>,
|
proxy_protocol_timeout => <<"3s">>,
|
||||||
running => true,
|
running => true,
|
||||||
tcp => #{
|
tcp => #{
|
||||||
active_n => 100,
|
active_n => 100,
|
||||||
backlog => 1024,
|
backlog => 1024,
|
||||||
|
|
|
@ -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">>]).
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ schema("/mqtt/sys_topics") ->
|
||||||
responses =>
|
responses =>
|
||||||
#{
|
#{
|
||||||
200 => schema_sys_topics()
|
200 => schema_sys_topics()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
put =>
|
put =>
|
||||||
#{
|
#{
|
||||||
tags => ?TAGS,
|
tags => ?TAGS,
|
||||||
|
@ -71,20 +71,24 @@ schema("/mqtt/sys_topics") ->
|
||||||
responses =>
|
responses =>
|
||||||
#{
|
#{
|
||||||
200 => schema_sys_topics()
|
200 => schema_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_disconnected">> => true,
|
#{
|
||||||
<<"client_subscribed">> => false,
|
<<"client_connected">> => true,
|
||||||
<<"client_unsubscribed">> => false},
|
<<"client_disconnected">> => true,
|
||||||
<<"sys_heartbeat_interval">> => <<"30s">>,
|
<<"client_subscribed">> => false,
|
||||||
<<"sys_msg_interval">> => <<"1m">>
|
<<"client_unsubscribed">> => false
|
||||||
}.
|
},
|
||||||
|
<<"sys_heartbeat_interval">> => <<"30s">>,
|
||||||
|
<<"sys_msg_interval">> => <<"1m">>
|
||||||
|
}.
|
||||||
|
|
|
@ -33,22 +33,27 @@ 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_disconnected">> => true,
|
#{
|
||||||
<<"client_subscribed">> => false,
|
<<"client_connected">> => true,
|
||||||
<<"client_unsubscribed">> => false
|
<<"client_disconnected">> => true,
|
||||||
},
|
<<"client_subscribed">> => false,
|
||||||
<<"sys_heartbeat_interval">> => <<"30s">>,
|
<<"client_unsubscribed">> => false
|
||||||
<<"sys_msg_interval">> => <<"1m">>}, Default),
|
},
|
||||||
|
<<"sys_heartbeat_interval">> => <<"30s">>,
|
||||||
|
<<"sys_msg_interval">> => <<"1m">>
|
||||||
|
},
|
||||||
|
Default
|
||||||
|
),
|
||||||
|
|
||||||
NConfig = Default#{
|
NConfig = Default#{
|
||||||
<<"sys_msg_interval">> => <<"4m">>,
|
<<"sys_msg_interval">> => <<"4m">>,
|
||||||
<<"sys_event_messages">> => #{<<"client_subscribed">> => false}
|
<<"sys_event_messages">> => #{<<"client_subscribed">> => false}
|
||||||
},
|
},
|
||||||
{ok, ConfigResp} = put_sys_topics_config(NConfig),
|
{ok, ConfigResp} = put_sys_topics_config(NConfig),
|
||||||
?assertEqual(NConfig, ConfigResp),
|
?assertEqual(NConfig, ConfigResp),
|
||||||
{ok, Default} = put_sys_topics_config(Default).
|
{ok, Default} = put_sys_topics_config(Default).
|
||||||
|
|
||||||
get_sys_topics_config() ->
|
get_sys_topics_config() ->
|
||||||
Path = emqx_mgmt_api_test_util:api_path(["mqtt", "sys_topics"]),
|
Path = emqx_mgmt_api_test_util:api_path(["mqtt", "sys_topics"]),
|
||||||
|
|
Loading…
Reference in New Issue