chore: add invite_node/2 bpapi

This commit is contained in:
Zhongwen Deng 2022-04-11 09:49:55 +08:00
parent 7799600271
commit 5acf19a947
3 changed files with 40 additions and 2 deletions

View File

@ -21,3 +21,4 @@
{emqx_telemetry,1}. {emqx_telemetry,1}.
{emqx_topic_metrics,1}. {emqx_topic_metrics,1}.
{emqx_delayed,1}. {emqx_delayed,1}.
{emqx_mgmt_cluster,1}.

View File

@ -21,7 +21,7 @@
-include_lib("hocon/include/hoconsc.hrl"). -include_lib("hocon/include/hoconsc.hrl").
-export([api_spec/0, fields/1, paths/0, schema/1, namespace/0]). -export([api_spec/0, fields/1, paths/0, schema/1, namespace/0]).
-export([cluster_info/2, invite_node/2, force_leave/2]). -export([cluster_info/2, invite_node/2, force_leave/2, join/1]).
namespace() -> "cluster". namespace() -> "cluster".
@ -103,7 +103,7 @@ cluster_info(get, _) ->
invite_node(put, #{bindings := #{node := Node0}}) -> invite_node(put, #{bindings := #{node := Node0}}) ->
Node = ekka_node:parse_name(binary_to_list(Node0)), Node = ekka_node:parse_name(binary_to_list(Node0)),
case rpc:call(Node, ekka, join, [node()]) of case emqx_mgmt_cluster_proto_v1:invite_node(Node, node()) of
ok -> ok ->
{200}; {200};
ignore -> ignore ->
@ -125,5 +125,9 @@ force_leave(delete, #{bindings := #{node := Node0}}) ->
{400, #{code => 'BAD_REQUEST', message => error_message(Error)}} {400, #{code => 'BAD_REQUEST', message => error_message(Error)}}
end. end.
-spec(join(node()) -> ok | ignore | {error, term()}).
join(Node) ->
ekka:join(Node).
error_message(Msg) -> error_message(Msg) ->
iolist_to_binary(io_lib:format("~p", [Msg])). iolist_to_binary(io_lib:format("~p", [Msg])).

View File

@ -0,0 +1,33 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_mgmt_cluster_proto_v1).
-behaviour(emqx_bpapi).
-export([
introduced_in/0,
invite_node/2
]).
-include_lib("emqx/include/bpapi.hrl").
introduced_in() ->
"5.0.0".
-spec invite_node(node(), node()) -> ok | ignore | {error, term()} | emqx_rpc:badrpc().
invite_node(Node, Self) ->
rpc:call(Node, emqx_mgmt_api_cluster, join, [Self], 5000).