chore: apply suggestions from code review
Co-authored-by: Zaiming (Stone) Shi <zmstone@gmail.com>
This commit is contained in:
parent
d2991dae03
commit
93ef6766ef
|
@ -27,7 +27,7 @@
|
||||||
cluster_topology/2,
|
cluster_topology/2,
|
||||||
invite_node/2,
|
invite_node/2,
|
||||||
invite_node_async/2,
|
invite_node_async/2,
|
||||||
get_invitation_view/2,
|
get_invitation_status/2,
|
||||||
force_leave/2,
|
force_leave/2,
|
||||||
join/1,
|
join/1,
|
||||||
connected_replicants/0
|
connected_replicants/0
|
||||||
|
@ -179,7 +179,7 @@ fields(invitation_view) ->
|
||||||
{succeed,
|
{succeed,
|
||||||
?HOCON(
|
?HOCON(
|
||||||
?ARRAY(?REF(node_invitation_succeed)),
|
?ARRAY(?REF(node_invitation_succeed)),
|
||||||
#{desc => <<"A list of information about nodes that were successfully invited">>}
|
#{desc => <<"A list of information about nodes which are successfully invited">>}
|
||||||
)},
|
)},
|
||||||
{in_progress,
|
{in_progress,
|
||||||
?HOCON(
|
?HOCON(
|
||||||
|
@ -198,7 +198,7 @@ fields(node_invitation_failed) ->
|
||||||
{reason,
|
{reason,
|
||||||
?HOCON(
|
?HOCON(
|
||||||
binary(),
|
binary(),
|
||||||
#{desc => <<"Failed reason">>, example => <<"Bad RPC to target node">>}
|
#{desc => <<"Failure reason">>, example => <<"Bad RPC to target node">>}
|
||||||
)}
|
)}
|
||||||
];
|
];
|
||||||
fields(node_invitation_succeed) ->
|
fields(node_invitation_succeed) ->
|
||||||
|
@ -208,7 +208,7 @@ fields(node_invitation_succeed) ->
|
||||||
?HOCON(
|
?HOCON(
|
||||||
emqx_utils_calendar:epoch_millisecond(),
|
emqx_utils_calendar:epoch_millisecond(),
|
||||||
#{
|
#{
|
||||||
desc => <<"The end time of the invitation task, in millisecond">>,
|
desc => <<"The time of the async invitation result is received, millisecond precision epoch">>,
|
||||||
example => <<"1705044829915">>
|
example => <<"1705044829915">>
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
|
@ -224,7 +224,7 @@ fields(node_invitation_in_progress) ->
|
||||||
?HOCON(
|
?HOCON(
|
||||||
emqx_utils_calendar:epoch_millisecond(),
|
emqx_utils_calendar:epoch_millisecond(),
|
||||||
#{
|
#{
|
||||||
desc => <<"The start time of the invitation task, in millisecond">>,
|
desc => <<"The start timestamp of the invitation, millisecond precision epoch">>,
|
||||||
example => <<"1705044829915">>
|
example => <<"1705044829915">>
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
|
@ -289,15 +289,15 @@ invite_node(put, #{bindings := #{node := Node0}, body := Body}) ->
|
||||||
Node = ekka_node:parse_name(binary_to_list(Node0)),
|
Node = ekka_node:parse_name(binary_to_list(Node0)),
|
||||||
case maps:get(<<"timeout">>, Body, ?DEFAULT_INVITE_TIMEOUT) of
|
case maps:get(<<"timeout">>, Body, ?DEFAULT_INVITE_TIMEOUT) of
|
||||||
T when not is_integer(T) ->
|
T when not is_integer(T) ->
|
||||||
{400, #{code => 'BAD_REQUEST', message => <<"timeout must be integer">>}};
|
{400, #{code => 'BAD_REQUEST', message => <<"timeout must be an integer">>}};
|
||||||
T when T < 5000 ->
|
T when T < 5000 ->
|
||||||
{400, #{code => 'BAD_REQUEST', message => <<"timeout can't less than 5000ms">>}};
|
{400, #{code => 'BAD_REQUEST', message => <<"timeout cannot be less than 5000ms">>}};
|
||||||
Timeout ->
|
Timeout ->
|
||||||
case emqx_mgmt_cluster_proto_v3:invite_node(Node, node(), Timeout) of
|
case emqx_mgmt_cluster_proto_v3:invite_node(Node, node(), Timeout) of
|
||||||
ok ->
|
ok ->
|
||||||
{200};
|
{200};
|
||||||
ignore ->
|
ignore ->
|
||||||
{400, #{code => 'BAD_REQUEST', message => <<"Can't invite self">>}};
|
{400, #{code => 'BAD_REQUEST', message => <<"Cannot invite self">>}};
|
||||||
{badrpc, Error} ->
|
{badrpc, Error} ->
|
||||||
{400, #{code => 'BAD_REQUEST', message => error_message(Error)}};
|
{400, #{code => 'BAD_REQUEST', message => error_message(Error)}};
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
|
|
|
@ -45,14 +45,14 @@ invite_async(Node) ->
|
||||||
JoinTo = node(),
|
JoinTo = node(),
|
||||||
case Node =/= JoinTo of
|
case Node =/= JoinTo of
|
||||||
true ->
|
true ->
|
||||||
gen_server:call(?MODULE, {invite_async, Node, JoinTo});
|
gen_server:call(?MODULE, {invite_async, Node, JoinTo}, infinity);
|
||||||
false ->
|
false ->
|
||||||
ignore
|
ignore
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec invitation_view() -> map().
|
-spec invitation_view() -> map().
|
||||||
invitation_view() ->
|
invitation_view() ->
|
||||||
gen_server:call(?MODULE, invitation_view).
|
gen_server:call(?MODULE, invitation_view, infinity).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
@ -196,4 +196,4 @@ is_succeed_result(Result) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
format_error_reason(Term) ->
|
format_error_reason(Term) ->
|
||||||
iolist_to_binary(io_lib:format("~p", [Term])).
|
iolist_to_binary(io_lib:format("~0p", [Term])).
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Add a new `timeout` parameter to the `cluster/:node/invite` interface.
|
Add a new `timeout` parameter to the `cluster/:node/invite` interface.
|
||||||
Previously the default timeout was 5s which would often be caused by HTTP API calls due to emqx taking too long to join cluster.
|
Previously the default timeout was 5s which would often be caused by HTTP API calls due to emqx taking too long to join cluster.
|
||||||
|
|
||||||
Add a new endpoint `/cluster/:node/invite_async` to support an asynchronous way to invite nodes to join the cluster.
|
Add a new endpoint `/cluster/:node/invite_async` to support an asynchronous way to invite nodes to join the cluster,
|
||||||
|
and a new endpoint `cluster/invitation` to inspect the join status.
|
||||||
|
|
|
@ -16,9 +16,9 @@ invite_node.label:
|
||||||
"""Invite node to cluster"""
|
"""Invite node to cluster"""
|
||||||
|
|
||||||
invite_node_async.desc:
|
invite_node_async.desc:
|
||||||
"""Asynchronously invite the target node to join the cluster"""
|
"""Send a join invitation to a node to join the cluster but do not wait for the join result. Join status can be retrieved with `GET api/<version>/invitation`"""
|
||||||
invite_node_async.label:
|
invite_node_async.label:
|
||||||
"""Asynchronously invite the target node to join the cluster"""
|
"""Asynchronously invite"""
|
||||||
|
|
||||||
force_remove_node.desc:
|
force_remove_node.desc:
|
||||||
"""Force leave node from cluster"""
|
"""Force leave node from cluster"""
|
||||||
|
|
Loading…
Reference in New Issue