|
|
@@ -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().
|
|
|
@@ -81,25 +81,23 @@ get_node_and_config(KeyPath) ->
|
|
|
-spec update(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(KeyPath, UpdateReq, Opts0) ->
|
|
|
- Args = [KeyPath, UpdateReq, Opts0],
|
|
|
- multicall(emqx, update_config, Args).
|
|
|
+update(KeyPath, UpdateReq, Opts) ->
|
|
|
+ check_cluster_rpc_result(emqx_conf_proto_v1:update(KeyPath, UpdateReq, Opts)).
|
|
|
|
|
|
%% @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()) ->
|
|
|
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
|
|
|
-remove(KeyPath, Opts0) ->
|
|
|
- Args = [KeyPath, Opts0],
|
|
|
- multicall(emqx, remove_config, Args).
|
|
|
+remove(KeyPath, Opts) ->
|
|
|
+ check_cluster_rpc_result(emqx_conf_proto_v1:remove_config(KeyPath, Opts)).
|
|
|
|
|
|
%% @doc remove the specified node's key path in local-override.conf.
|
|
|
-spec remove(node(), emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
|
|
|
@@ -107,14 +105,13 @@ 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()) ->
|
|
|
{ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
|
|
|
-reset(KeyPath, Opts0) ->
|
|
|
- Args = [KeyPath, Opts0],
|
|
|
- multicall(emqx, reset_config, Args).
|
|
|
+reset(KeyPath, Opts) ->
|
|
|
+ check_cluster_rpc_result(emqx_conf_proto_v1:reset(KeyPath, Opts)).
|
|
|
|
|
|
%% @doc reset the specified node's key path in local-override.conf.
|
|
|
-spec reset(node(), emqx_map_lib:config_key_path(), emqx_config:update_opts()) ->
|
|
|
@@ -122,7 +119,7 @@ reset(KeyPath, Opts0) ->
|
|
|
reset(Node, KeyPath, Opts) when Node =:= node() ->
|
|
|
emqx:reset_config(KeyPath, Opts#{override_to => local});
|
|
|
reset(Node, KeyPath, Opts) ->
|
|
|
- rpc:call(Node, ?MODULE, reset, [KeyPath, Opts]).
|
|
|
+ emqx_conf_proto_v1:reset(Node, KeyPath, Opts).
|
|
|
|
|
|
-spec gen_doc(file:name_all()) -> ok.
|
|
|
gen_doc(File) ->
|
|
|
@@ -138,14 +135,14 @@ gen_doc(File) ->
|
|
|
%% Internal functions
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
-multicall(M, F, Args) ->
|
|
|
- case emqx_cluster_rpc:multicall(M, F, Args) of
|
|
|
+check_cluster_rpc_result(Result) ->
|
|
|
+ case Result of
|
|
|
{ok, _TnxId, Res} -> Res;
|
|
|
{retry, TnxId, Res, Nodes} ->
|
|
|
%% The init MFA return ok, but other nodes failed.
|
|
|
%% We return ok and alert an alarm.
|
|
|
?SLOG(error, #{msg => "failed_to_update_config_in_cluster", nodes => Nodes,
|
|
|
- tnx_id => TnxId, mfa => {M, F, Args}}),
|
|
|
+ tnx_id => TnxId}),
|
|
|
Res;
|
|
|
{error, Error} -> %% all MFA return not ok or {ok, term()}.
|
|
|
Error
|