diff --git a/apps/emqx/src/bpapi/emqx_bpapi_trans.erl b/apps/emqx/src/bpapi/emqx_bpapi_trans.erl index f39215069..eedaacd69 100644 --- a/apps/emqx/src/bpapi/emqx_bpapi_trans.erl +++ b/apps/emqx/src/bpapi/emqx_bpapi_trans.erl @@ -150,6 +150,10 @@ extract_mfa(?BACKEND(emqx_rpc, CallOrCast), [_Node, M, F, A]) -> extract_mfa(?BACKEND(emqx_rpc, CallOrCast), [_Tag, _Node, M, F, A]) -> {call_or_cast(CallOrCast), M, F, A}; %% (e)rpc: +extract_mfa(?BACKEND(rpc, multicall), [M, F, A]) -> + {call_or_cast(multicall), M, F, A}; +extract_mfa(?BACKEND(rpc, multicall), [M, F, A, {integer, _, _Timeout}]) -> + {call_or_cast(multicall), M, F, A}; extract_mfa(?BACKEND(RPC, CallOrCast), [_Node, M, F, A]) when ?IS_RPC(RPC) -> {call_or_cast(CallOrCast), M, F, A}; extract_mfa(?BACKEND(RPC, CallOrCast), [_Node, M, F, A, _Timeout]) when ?IS_RPC(RPC) -> diff --git a/apps/emqx_conf/src/emqx_conf.erl b/apps/emqx_conf/src/emqx_conf.erl index 16d3b4a5d..26da6ac14 100644 --- a/apps/emqx_conf/src/emqx_conf.erl +++ b/apps/emqx_conf/src/emqx_conf.erl @@ -55,22 +55,22 @@ get_raw(KeyPath, Default) -> %% @doc Returns all values in the cluster. -spec get_all(emqx_map_lib:config_key_path()) -> #{node() => term()}. get_all(KeyPath) -> - {ResL, []} = rpc:multicall(?MODULE, get_node_and_config, [KeyPath], 5000), + {ResL, []} = emqx_conf_proto_v1:get_all(KeyPath), maps:from_list(ResL). %% @doc Returns the specified node's KeyPath, or exception if not found -spec get_by_node(node(), emqx_map_lib:config_key_path()) -> term(). -get_by_node(Node, KeyPath)when Node =:= node() -> +get_by_node(Node, KeyPath) when Node =:= node() -> emqx:get_config(KeyPath); get_by_node(Node, KeyPath) -> - rpc:call(Node, ?MODULE, get_by_node, [Node, KeyPath]). + emqx_conf_proto_v1:get_config(Node, KeyPath). %% @doc Returns the specified node's KeyPath, or the default value if not found -spec get_by_node(node(), emqx_map_lib:config_key_path(), term()) -> term(). -get_by_node(Node, KeyPath, Default)when Node =:= node() -> +get_by_node(Node, KeyPath, Default) when Node =:= node() -> emqx:get_config(KeyPath, Default); get_by_node(Node, KeyPath, Default) -> - rpc:call(Node, ?MODULE, get_by_node, [Node, KeyPath, Default]). + emqx_conf_proto_v1:get_config(Node, KeyPath, Default). %% @doc Returns the specified node's KeyPath, or config_not_found if key path not found -spec get_node_and_config(emqx_map_lib:config_key_path()) -> term(). @@ -88,11 +88,11 @@ update(KeyPath, UpdateReq, Opts0) -> %% @doc Update the specified node's key path in local-override.conf. -spec update(node(), emqx_map_lib:config_key_path(), emqx_config:update_request(), emqx_config:update_opts()) -> - {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}. -update(Node, KeyPath, UpdateReq, Opts0)when Node =:= node() -> + {ok, emqx_config:update_result()} | {error, emqx_config:update_error()} | emqx_rpc:badrpc(). +update(Node, KeyPath, UpdateReq, Opts0) when Node =:= node() -> emqx:update_config(KeyPath, UpdateReq, Opts0#{override_to => local}); -update(Node, KeyPath, UpdateReq, Opts0) -> - rpc:call(Node, ?MODULE, update, [Node, KeyPath, UpdateReq, Opts0], 5000). +update(Node, KeyPath, UpdateReq, Opts) -> + emqx_conf_proto_v1:update(Node, KeyPath, UpdateReq, Opts). %% @doc remove all value of key path in cluster-override.conf or local-override.conf. -spec remove(emqx_map_lib:config_key_path(), emqx_config:update_opts()) -> @@ -107,7 +107,7 @@ remove(KeyPath, Opts0) -> remove(Node, KeyPath, Opts) when Node =:= node() -> emqx:remove_config(KeyPath, Opts#{override_to => local}); remove(Node, KeyPath, Opts) -> - rpc:call(Node, ?MODULE, remove, [KeyPath, Opts]). + emqx_conf_proto_v1:remove_config(Node, KeyPath, Opts). %% @doc reset all value of key path in cluster-override.conf or local-override.conf. -spec reset(emqx_map_lib:config_key_path(), emqx_config:update_opts()) -> diff --git a/apps/emqx_conf/src/proto/emqx_conf_proto_v1.erl b/apps/emqx_conf/src/proto/emqx_conf_proto_v1.erl new file mode 100644 index 000000000..9e92c8c76 --- /dev/null +++ b/apps/emqx_conf/src/proto/emqx_conf_proto_v1.erl @@ -0,0 +1,65 @@ +%%-------------------------------------------------------------------- +%% 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_conf_proto_v1). + +-behaviour(emqx_bpapi). + +-export([ introduced_in/0 + + , get_config/2 + , get_config/3 + , get_all/1 + + , update/4 + , remove_config/3 + ]). + +-include_lib("emqx/include/bpapi.hrl"). + +-type update_config_key_path() :: [emqx_map_lib:config_key(), ...]. + +introduced_in() -> + "5.0.0". + +-spec get_config(node(), emqx_map_lib:config_key_path()) -> + term() | emqx_rpc:badrpc(). +get_config(Node, KeyPath) -> + rpc:call(Node, emqx, get_config, [KeyPath]). + +-spec get_config(node(), emqx_map_lib:config_key_path(), _Default) -> + term() | emqx_rpc:badrpc(). +get_config(Node, KeyPath, Default) -> + rpc:call(Node, emqx, get_config, [KeyPath, Default]). + +-spec get_all(emqx_map_lib:config_key_path()) -> emqx_rpc:multicall_result(). +get_all(KeyPath) -> + rpc:multicall(emqx_conf, get_node_and_config, [KeyPath], 5000). + +-spec update(node(), update_config_key_path(), emqx_config:update_request(), + emqx_config:update_opts()) -> + {ok, emqx_config:update_result()} + | {error, emqx_config:update_error()} + | emqx_rpc:badrpc(). +update(Node, KeyPath, UpdateReq, Opts) -> + rpc:call(Node, emqx, update_config, [KeyPath, UpdateReq, Opts], 5000). + +-spec remove_config(node(), update_config_key_path(), emqx_config:update_opts()) -> + {ok, emqx_config:update_result()} + | {error, emqx_config:update_error()} + | emqx_rpc:badrpc(). +remove_config(Node, KeyPath, Opts) -> + rpc:call(Node, emqx, remove_config, [KeyPath, Opts], 5000).