|
@@ -18,6 +18,7 @@
|
|
|
-module(emqx_config_handler).
|
|
-module(emqx_config_handler).
|
|
|
|
|
|
|
|
-include("logger.hrl").
|
|
-include("logger.hrl").
|
|
|
|
|
+-include("emqx.hrl").
|
|
|
-include("emqx_schema.hrl").
|
|
-include("emqx_schema.hrl").
|
|
|
-include_lib("hocon/include/hocon_types.hrl").
|
|
-include_lib("hocon/include/hocon_types.hrl").
|
|
|
|
|
|
|
@@ -30,6 +31,7 @@
|
|
|
add_handler/2,
|
|
add_handler/2,
|
|
|
remove_handler/1,
|
|
remove_handler/1,
|
|
|
update_config/3,
|
|
update_config/3,
|
|
|
|
|
+ update_config/4,
|
|
|
get_raw_cluster_override_conf/0,
|
|
get_raw_cluster_override_conf/0,
|
|
|
info/0
|
|
info/0
|
|
|
]).
|
|
]).
|
|
@@ -50,12 +52,17 @@
|
|
|
-define(WKEY, '?').
|
|
-define(WKEY, '?').
|
|
|
|
|
|
|
|
-type handler_name() :: module().
|
|
-type handler_name() :: module().
|
|
|
|
|
+-type cluster_rpc_opts() :: map().
|
|
|
|
|
|
|
|
-optional_callbacks([
|
|
-optional_callbacks([
|
|
|
pre_config_update/3,
|
|
pre_config_update/3,
|
|
|
|
|
+ pre_config_update/4,
|
|
|
propagated_pre_config_update/3,
|
|
propagated_pre_config_update/3,
|
|
|
|
|
+ propagated_pre_config_update/4,
|
|
|
post_config_update/5,
|
|
post_config_update/5,
|
|
|
- propagated_post_config_update/5
|
|
|
|
|
|
|
+ post_config_update/6,
|
|
|
|
|
+ propagated_post_config_update/5,
|
|
|
|
|
+ propagated_post_config_update/6
|
|
|
]).
|
|
]).
|
|
|
|
|
|
|
|
-callback pre_config_update([atom()], emqx_config:update_request(), emqx_config:raw_config()) ->
|
|
-callback pre_config_update([atom()], emqx_config:update_request(), emqx_config:raw_config()) ->
|
|
@@ -83,6 +90,35 @@
|
|
|
) ->
|
|
) ->
|
|
|
ok | {ok, Result :: any()} | {error, Reason :: term()}.
|
|
ok | {ok, Result :: any()} | {error, Reason :: term()}.
|
|
|
|
|
|
|
|
|
|
+-callback pre_config_update(
|
|
|
|
|
+ [atom()], emqx_config:update_request(), emqx_config:raw_config(), cluster_rpc_opts()
|
|
|
|
|
+) ->
|
|
|
|
|
+ ok | {ok, emqx_config:update_request()} | {error, term()}.
|
|
|
|
|
+-callback propagated_pre_config_update(
|
|
|
|
|
+ [binary()], emqx_config:update_request(), emqx_config:raw_config(), cluster_rpc_opts()
|
|
|
|
|
+) ->
|
|
|
|
|
+ ok | {ok, emqx_config:update_request()} | {error, term()}.
|
|
|
|
|
+
|
|
|
|
|
+-callback post_config_update(
|
|
|
|
|
+ [atom()],
|
|
|
|
|
+ emqx_config:update_request(),
|
|
|
|
|
+ emqx_config:config(),
|
|
|
|
|
+ emqx_config:config(),
|
|
|
|
|
+ emqx_config:app_envs(),
|
|
|
|
|
+ cluster_rpc_opts()
|
|
|
|
|
+) ->
|
|
|
|
|
+ ok | {ok, Result :: any()} | {error, Reason :: term()}.
|
|
|
|
|
+
|
|
|
|
|
+-callback propagated_post_config_update(
|
|
|
|
|
+ [atom()],
|
|
|
|
|
+ emqx_config:update_request(),
|
|
|
|
|
+ emqx_config:config(),
|
|
|
|
|
+ emqx_config:config(),
|
|
|
|
|
+ emqx_config:app_envs(),
|
|
|
|
|
+ cluster_rpc_opts()
|
|
|
|
|
+) ->
|
|
|
|
|
+ ok | {ok, Result :: any()} | {error, Reason :: term()}.
|
|
|
|
|
+
|
|
|
-type state() :: #{handlers := any()}.
|
|
-type state() :: #{handlers := any()}.
|
|
|
-type config_key_path() :: emqx_utils_maps:config_key_path().
|
|
-type config_key_path() :: emqx_utils_maps:config_key_path().
|
|
|
|
|
|
|
@@ -92,12 +128,17 @@ start_link() ->
|
|
|
stop() ->
|
|
stop() ->
|
|
|
gen_server:stop(?MODULE).
|
|
gen_server:stop(?MODULE).
|
|
|
|
|
|
|
|
--spec update_config(module(), config_key_path(), emqx_config:update_args()) ->
|
|
|
|
|
- {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
|
|
|
|
|
update_config(SchemaModule, ConfKeyPath, UpdateArgs) ->
|
|
update_config(SchemaModule, ConfKeyPath, UpdateArgs) ->
|
|
|
|
|
+ update_config(SchemaModule, ConfKeyPath, UpdateArgs, #{}).
|
|
|
|
|
+
|
|
|
|
|
+-spec update_config(module(), config_key_path(), emqx_config:update_args(), map()) ->
|
|
|
|
|
+ {ok, emqx_config:update_result()} | {error, emqx_config:update_error()}.
|
|
|
|
|
+update_config(SchemaModule, ConfKeyPath, UpdateArgs, ClusterOpts) ->
|
|
|
%% force convert the path to a list of atoms, as there maybe some wildcard names/ids in the path
|
|
%% force convert the path to a list of atoms, as there maybe some wildcard names/ids in the path
|
|
|
AtomKeyPath = [atom(Key) || Key <- ConfKeyPath],
|
|
AtomKeyPath = [atom(Key) || Key <- ConfKeyPath],
|
|
|
- gen_server:call(?MODULE, {change_config, SchemaModule, AtomKeyPath, UpdateArgs}, infinity).
|
|
|
|
|
|
|
+ gen_server:call(
|
|
|
|
|
+ ?MODULE, {change_config, SchemaModule, AtomKeyPath, UpdateArgs, ClusterOpts}, infinity
|
|
|
|
|
+ ).
|
|
|
|
|
|
|
|
-spec add_handler(config_key_path(), handler_name()) ->
|
|
-spec add_handler(config_key_path(), handler_name()) ->
|
|
|
ok | {error, {conflict, list()}}.
|
|
ok | {error, {conflict, list()}}.
|
|
@@ -130,11 +171,11 @@ handle_call({add_handler, ConfKeyPath, HandlerName}, _From, State = #{handlers :
|
|
|
{error, _Reason} = Error -> {reply, Error, State}
|
|
{error, _Reason} = Error -> {reply, Error, State}
|
|
|
end;
|
|
end;
|
|
|
handle_call(
|
|
handle_call(
|
|
|
- {change_config, SchemaModule, ConfKeyPath, UpdateArgs},
|
|
|
|
|
|
|
+ {change_config, SchemaModule, ConfKeyPath, UpdateArgs, ClusterRpcOpts},
|
|
|
_From,
|
|
_From,
|
|
|
#{handlers := Handlers} = State
|
|
#{handlers := Handlers} = State
|
|
|
) ->
|
|
) ->
|
|
|
- Result = handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs),
|
|
|
|
|
|
|
+ Result = handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs, ClusterRpcOpts),
|
|
|
{reply, Result, State};
|
|
{reply, Result, State};
|
|
|
handle_call(get_raw_cluster_override_conf, _From, State) ->
|
|
handle_call(get_raw_cluster_override_conf, _From, State) ->
|
|
|
Reply = emqx_config:read_override_conf(#{override_to => cluster}),
|
|
Reply = emqx_config:read_override_conf(#{override_to => cluster}),
|
|
@@ -203,9 +244,9 @@ filter_top_level_handlers(Handlers) ->
|
|
|
Handlers
|
|
Handlers
|
|
|
).
|
|
).
|
|
|
|
|
|
|
|
-handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
|
|
|
|
|
|
|
+handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs, ClusterRpcOpts) ->
|
|
|
try
|
|
try
|
|
|
- do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs)
|
|
|
|
|
|
|
+ do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs, ClusterRpcOpts)
|
|
|
catch
|
|
catch
|
|
|
throw:Reason ->
|
|
throw:Reason ->
|
|
|
{error, Reason};
|
|
{error, Reason};
|
|
@@ -217,13 +258,14 @@ handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
|
|
|
update_req => UpdateArgs,
|
|
update_req => UpdateArgs,
|
|
|
module => SchemaModule,
|
|
module => SchemaModule,
|
|
|
key_path => ConfKeyPath,
|
|
key_path => ConfKeyPath,
|
|
|
|
|
+ cluster_rpc_opts => ClusterRpcOpts,
|
|
|
stacktrace => ST
|
|
stacktrace => ST
|
|
|
}),
|
|
}),
|
|
|
{error, {config_update_crashed, Reason}}
|
|
{error, {config_update_crashed, Reason}}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
|
|
|
|
|
- case process_update_request(ConfKeyPath, Handlers, UpdateArgs) of
|
|
|
|
|
|
|
+do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs, ClusterOpts) ->
|
|
|
|
|
+ case process_update_request(ConfKeyPath, Handlers, UpdateArgs, ClusterOpts) of
|
|
|
{ok, NewRawConf, OverrideConf, Opts} ->
|
|
{ok, NewRawConf, OverrideConf, Opts} ->
|
|
|
check_and_save_configs(
|
|
check_and_save_configs(
|
|
|
SchemaModule,
|
|
SchemaModule,
|
|
@@ -232,23 +274,24 @@ do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
|
|
|
NewRawConf,
|
|
NewRawConf,
|
|
|
OverrideConf,
|
|
OverrideConf,
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
- Opts
|
|
|
|
|
|
|
+ Opts,
|
|
|
|
|
+ ClusterOpts
|
|
|
);
|
|
);
|
|
|
{error, Result} ->
|
|
{error, Result} ->
|
|
|
{error, Result}
|
|
{error, Result}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-process_update_request([_], _Handlers, {remove, _Opts}) ->
|
|
|
|
|
|
|
+process_update_request([_], _Handlers, {remove, _Opts}, _ClusterRpcOpts) ->
|
|
|
{error, "remove_root_is_forbidden"};
|
|
{error, "remove_root_is_forbidden"};
|
|
|
-process_update_request(ConfKeyPath, _Handlers, {remove, Opts}) ->
|
|
|
|
|
|
|
+process_update_request(ConfKeyPath, _Handlers, {remove, Opts}, _ClusterRpcOpts) ->
|
|
|
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
|
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
|
|
BinKeyPath = bin_path(ConfKeyPath),
|
|
BinKeyPath = bin_path(ConfKeyPath),
|
|
|
NewRawConf = emqx_utils_maps:deep_remove(BinKeyPath, OldRawConf),
|
|
NewRawConf = emqx_utils_maps:deep_remove(BinKeyPath, OldRawConf),
|
|
|
OverrideConf = remove_from_override_config(BinKeyPath, Opts),
|
|
OverrideConf = remove_from_override_config(BinKeyPath, Opts),
|
|
|
{ok, NewRawConf, OverrideConf, Opts};
|
|
{ok, NewRawConf, OverrideConf, Opts};
|
|
|
-process_update_request(ConfKeyPath, Handlers, {{update, UpdateReq}, Opts}) ->
|
|
|
|
|
|
|
+process_update_request(ConfKeyPath, Handlers, {{update, UpdateReq}, Opts}, ClusterRpcOpts) ->
|
|
|
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
|
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
|
|
|
- case do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq) of
|
|
|
|
|
|
|
+ case do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq, ClusterRpcOpts) of
|
|
|
{ok, NewRawConf} ->
|
|
{ok, NewRawConf} ->
|
|
|
OverrideConf = merge_to_override_config(NewRawConf, Opts),
|
|
OverrideConf = merge_to_override_config(NewRawConf, Opts),
|
|
|
{ok, NewRawConf, OverrideConf, Opts};
|
|
{ok, NewRawConf, OverrideConf, Opts};
|
|
@@ -256,15 +299,16 @@ process_update_request(ConfKeyPath, Handlers, {{update, UpdateReq}, Opts}) ->
|
|
|
Error
|
|
Error
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq) ->
|
|
|
|
|
- do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq, []).
|
|
|
|
|
|
|
+do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq, ClusterRpcOpts) ->
|
|
|
|
|
+ do_update_config(ConfKeyPath, Handlers, OldRawConf, UpdateReq, ClusterRpcOpts, []).
|
|
|
|
|
|
|
|
-do_update_config([], Handlers, OldRawConf, UpdateReq, ConfKeyPath) ->
|
|
|
|
|
|
|
+do_update_config([], Handlers, OldRawConf, UpdateReq, ClusterRpcOpts, ConfKeyPath) ->
|
|
|
call_pre_config_update(#{
|
|
call_pre_config_update(#{
|
|
|
handlers => Handlers,
|
|
handlers => Handlers,
|
|
|
old_raw_conf => OldRawConf,
|
|
old_raw_conf => OldRawConf,
|
|
|
update_req => UpdateReq,
|
|
update_req => UpdateReq,
|
|
|
conf_key_path => ConfKeyPath,
|
|
conf_key_path => ConfKeyPath,
|
|
|
|
|
+ cluster_rpc_opts => ClusterRpcOpts,
|
|
|
callback => pre_config_update,
|
|
callback => pre_config_update,
|
|
|
is_propagated => false
|
|
is_propagated => false
|
|
|
});
|
|
});
|
|
@@ -273,13 +317,18 @@ do_update_config(
|
|
|
Handlers,
|
|
Handlers,
|
|
|
OldRawConf,
|
|
OldRawConf,
|
|
|
UpdateReq,
|
|
UpdateReq,
|
|
|
|
|
+ ClusterRpcOpts,
|
|
|
ConfKeyPath0
|
|
ConfKeyPath0
|
|
|
) ->
|
|
) ->
|
|
|
ConfKeyPath = ConfKeyPath0 ++ [ConfKey],
|
|
ConfKeyPath = ConfKeyPath0 ++ [ConfKey],
|
|
|
ConfKeyBin = bin(ConfKey),
|
|
ConfKeyBin = bin(ConfKey),
|
|
|
SubOldRawConf = get_sub_config(ConfKeyBin, OldRawConf),
|
|
SubOldRawConf = get_sub_config(ConfKeyBin, OldRawConf),
|
|
|
SubHandlers = get_sub_handlers(ConfKey, Handlers),
|
|
SubHandlers = get_sub_handlers(ConfKey, Handlers),
|
|
|
- case do_update_config(SubConfKeyPath, SubHandlers, SubOldRawConf, UpdateReq, ConfKeyPath) of
|
|
|
|
|
|
|
+ case
|
|
|
|
|
+ do_update_config(
|
|
|
|
|
+ SubConfKeyPath, SubHandlers, SubOldRawConf, UpdateReq, ClusterRpcOpts, ConfKeyPath
|
|
|
|
|
+ )
|
|
|
|
|
+ of
|
|
|
{ok, NewUpdateReq} ->
|
|
{ok, NewUpdateReq} ->
|
|
|
merge_to_old_config(#{ConfKeyBin => NewUpdateReq}, OldRawConf);
|
|
merge_to_old_config(#{ConfKeyBin => NewUpdateReq}, OldRawConf);
|
|
|
Error ->
|
|
Error ->
|
|
@@ -293,12 +342,18 @@ check_and_save_configs(
|
|
|
NewRawConf,
|
|
NewRawConf,
|
|
|
OverrideConf,
|
|
OverrideConf,
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
- Opts
|
|
|
|
|
|
|
+ Opts,
|
|
|
|
|
+ ClusterOpts
|
|
|
) ->
|
|
) ->
|
|
|
Schema = schema(SchemaModule, ConfKeyPath),
|
|
Schema = schema(SchemaModule, ConfKeyPath),
|
|
|
|
|
+ Kind = maps:get(kind, ClusterOpts, ?KIND_INITIATE),
|
|
|
{AppEnvs, NewConf} = emqx_config:check_config(Schema, NewRawConf),
|
|
{AppEnvs, NewConf} = emqx_config:check_config(Schema, NewRawConf),
|
|
|
OldConf = emqx_config:get_root(ConfKeyPath),
|
|
OldConf = emqx_config:get_root(ConfKeyPath),
|
|
|
- case do_post_config_update(ConfKeyPath, Handlers, OldConf, NewConf, AppEnvs, UpdateArgs, #{}) of
|
|
|
|
|
|
|
+ case
|
|
|
|
|
+ do_post_config_update(
|
|
|
|
|
+ ConfKeyPath, Handlers, OldConf, NewConf, AppEnvs, UpdateArgs, ClusterOpts, #{}
|
|
|
|
|
+ )
|
|
|
|
|
+ of
|
|
|
{ok, Result0} ->
|
|
{ok, Result0} ->
|
|
|
post_update_ok(
|
|
post_update_ok(
|
|
|
AppEnvs,
|
|
AppEnvs,
|
|
@@ -310,21 +365,24 @@ check_and_save_configs(
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
Result0
|
|
Result0
|
|
|
);
|
|
);
|
|
|
- {error, {post_config_update, HandlerName, Reason}} ->
|
|
|
|
|
- HandlePostFailureFun =
|
|
|
|
|
- fun() ->
|
|
|
|
|
- post_update_ok(
|
|
|
|
|
- AppEnvs,
|
|
|
|
|
- NewConf,
|
|
|
|
|
- NewRawConf,
|
|
|
|
|
- OverrideConf,
|
|
|
|
|
- Opts,
|
|
|
|
|
- ConfKeyPath,
|
|
|
|
|
- UpdateArgs,
|
|
|
|
|
- #{}
|
|
|
|
|
- )
|
|
|
|
|
- end,
|
|
|
|
|
- {error, {post_config_update, HandlerName, {Reason, HandlePostFailureFun}}}
|
|
|
|
|
|
|
+ {error, {post_config_update, HandlerName, Reason}} when Kind =/= ?KIND_INITIATE ->
|
|
|
|
|
+ ?SLOG(critical, #{
|
|
|
|
|
+ msg => "post_config_update_failed_but_save_the_config_anyway",
|
|
|
|
|
+ handler => HandlerName,
|
|
|
|
|
+ reason => Reason
|
|
|
|
|
+ }),
|
|
|
|
|
+ post_update_ok(
|
|
|
|
|
+ AppEnvs,
|
|
|
|
|
+ NewConf,
|
|
|
|
|
+ NewRawConf,
|
|
|
|
|
+ OverrideConf,
|
|
|
|
|
+ Opts,
|
|
|
|
|
+ ConfKeyPath,
|
|
|
|
|
+ UpdateArgs,
|
|
|
|
|
+ #{}
|
|
|
|
|
+ );
|
|
|
|
|
+ {error, _} = Error ->
|
|
|
|
|
+ Error
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
post_update_ok(AppEnvs, NewConf, NewRawConf, OverrideConf, Opts, ConfKeyPath, UpdateArgs, Result0) ->
|
|
post_update_ok(AppEnvs, NewConf, NewRawConf, OverrideConf, Opts, ConfKeyPath, UpdateArgs, Result0) ->
|
|
@@ -332,7 +390,9 @@ post_update_ok(AppEnvs, NewConf, NewRawConf, OverrideConf, Opts, ConfKeyPath, Up
|
|
|
Result1 = return_change_result(ConfKeyPath, UpdateArgs),
|
|
Result1 = return_change_result(ConfKeyPath, UpdateArgs),
|
|
|
{ok, Result1#{post_config_update => Result0}}.
|
|
{ok, Result1#{post_config_update => Result0}}.
|
|
|
|
|
|
|
|
-do_post_config_update(ConfKeyPath, Handlers, OldConf, NewConf, AppEnvs, UpdateArgs, Result) ->
|
|
|
|
|
|
|
+do_post_config_update(
|
|
|
|
|
+ ConfKeyPath, Handlers, OldConf, NewConf, AppEnvs, UpdateArgs, ClusterOpts, Result
|
|
|
|
|
+) ->
|
|
|
do_post_config_update(
|
|
do_post_config_update(
|
|
|
ConfKeyPath,
|
|
ConfKeyPath,
|
|
|
Handlers,
|
|
Handlers,
|
|
@@ -340,6 +400,7 @@ do_post_config_update(ConfKeyPath, Handlers, OldConf, NewConf, AppEnvs, UpdateAr
|
|
|
NewConf,
|
|
NewConf,
|
|
|
AppEnvs,
|
|
AppEnvs,
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
|
|
+ ClusterOpts,
|
|
|
Result,
|
|
Result,
|
|
|
[]
|
|
[]
|
|
|
).
|
|
).
|
|
@@ -352,6 +413,7 @@ do_post_config_update(
|
|
|
AppEnvs,
|
|
AppEnvs,
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
Result,
|
|
Result,
|
|
|
|
|
+ ClusterOpts,
|
|
|
ConfKeyPath
|
|
ConfKeyPath
|
|
|
) ->
|
|
) ->
|
|
|
call_post_config_update(#{
|
|
call_post_config_update(#{
|
|
@@ -362,6 +424,7 @@ do_post_config_update(
|
|
|
update_req => up_req(UpdateArgs),
|
|
update_req => up_req(UpdateArgs),
|
|
|
result => Result,
|
|
result => Result,
|
|
|
conf_key_path => ConfKeyPath,
|
|
conf_key_path => ConfKeyPath,
|
|
|
|
|
+ cluster_rpc_opts => ClusterOpts,
|
|
|
callback => post_config_update
|
|
callback => post_config_update
|
|
|
});
|
|
});
|
|
|
do_post_config_update(
|
|
do_post_config_update(
|
|
@@ -371,6 +434,7 @@ do_post_config_update(
|
|
|
NewConf,
|
|
NewConf,
|
|
|
AppEnvs,
|
|
AppEnvs,
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
|
|
+ ClusterOpts,
|
|
|
Result,
|
|
Result,
|
|
|
ConfKeyPath0
|
|
ConfKeyPath0
|
|
|
) ->
|
|
) ->
|
|
@@ -385,6 +449,7 @@ do_post_config_update(
|
|
|
SubNewConf,
|
|
SubNewConf,
|
|
|
AppEnvs,
|
|
AppEnvs,
|
|
|
UpdateArgs,
|
|
UpdateArgs,
|
|
|
|
|
+ ClusterOpts,
|
|
|
Result,
|
|
Result,
|
|
|
ConfKeyPath
|
|
ConfKeyPath
|
|
|
).
|
|
).
|
|
@@ -428,37 +493,41 @@ call_proper_pre_config_update(
|
|
|
#{
|
|
#{
|
|
|
handlers := #{?MOD := Module},
|
|
handlers := #{?MOD := Module},
|
|
|
callback := Callback,
|
|
callback := Callback,
|
|
|
- update_req := UpdateReq,
|
|
|
|
|
- old_raw_conf := OldRawConf
|
|
|
|
|
|
|
+ update_req := UpdateReq
|
|
|
} = Ctx
|
|
} = Ctx
|
|
|
) ->
|
|
) ->
|
|
|
- case erlang:function_exported(Module, Callback, 3) of
|
|
|
|
|
- true ->
|
|
|
|
|
- case apply_pre_config_update(Module, Ctx) of
|
|
|
|
|
- {ok, NewUpdateReq} ->
|
|
|
|
|
- {ok, NewUpdateReq};
|
|
|
|
|
- ok ->
|
|
|
|
|
- {ok, UpdateReq};
|
|
|
|
|
- {error, Reason} ->
|
|
|
|
|
- {error, {pre_config_update, Module, Reason}}
|
|
|
|
|
- end;
|
|
|
|
|
- false ->
|
|
|
|
|
- merge_to_old_config(UpdateReq, OldRawConf)
|
|
|
|
|
|
|
+ Arity = get_function_arity(Module, Callback, [3, 4]),
|
|
|
|
|
+ case apply_pre_config_update(Module, Callback, Arity, Ctx) of
|
|
|
|
|
+ {ok, NewUpdateReq} ->
|
|
|
|
|
+ {ok, NewUpdateReq};
|
|
|
|
|
+ ok ->
|
|
|
|
|
+ {ok, UpdateReq};
|
|
|
|
|
+ {error, Reason} ->
|
|
|
|
|
+ {error, {pre_config_update, Module, Reason}}
|
|
|
end;
|
|
end;
|
|
|
call_proper_pre_config_update(
|
|
call_proper_pre_config_update(
|
|
|
#{update_req := UpdateReq}
|
|
#{update_req := UpdateReq}
|
|
|
) ->
|
|
) ->
|
|
|
{ok, UpdateReq}.
|
|
{ok, UpdateReq}.
|
|
|
|
|
|
|
|
-apply_pre_config_update(Module, #{
|
|
|
|
|
|
|
+apply_pre_config_update(Module, Callback, 3, #{
|
|
|
|
|
+ conf_key_path := ConfKeyPath,
|
|
|
|
|
+ update_req := UpdateReq,
|
|
|
|
|
+ old_raw_conf := OldRawConf
|
|
|
|
|
+}) ->
|
|
|
|
|
+ Module:Callback(ConfKeyPath, UpdateReq, OldRawConf);
|
|
|
|
|
+apply_pre_config_update(Module, Callback, 4, #{
|
|
|
conf_key_path := ConfKeyPath,
|
|
conf_key_path := ConfKeyPath,
|
|
|
update_req := UpdateReq,
|
|
update_req := UpdateReq,
|
|
|
old_raw_conf := OldRawConf,
|
|
old_raw_conf := OldRawConf,
|
|
|
- callback := Callback
|
|
|
|
|
|
|
+ cluster_rpc_opts := ClusterRpcOpts
|
|
|
}) ->
|
|
}) ->
|
|
|
- Module:Callback(
|
|
|
|
|
- ConfKeyPath, UpdateReq, OldRawConf
|
|
|
|
|
- ).
|
|
|
|
|
|
|
+ Module:Callback(ConfKeyPath, UpdateReq, OldRawConf, ClusterRpcOpts);
|
|
|
|
|
+apply_pre_config_update(_Module, _Callback, false, #{
|
|
|
|
|
+ update_req := UpdateReq,
|
|
|
|
|
+ old_raw_conf := OldRawConf
|
|
|
|
|
+}) ->
|
|
|
|
|
+ merge_to_old_config(UpdateReq, OldRawConf).
|
|
|
|
|
|
|
|
propagate_pre_config_updates_to_subconf(
|
|
propagate_pre_config_updates_to_subconf(
|
|
|
#{handlers := #{?WKEY := _}} = Ctx
|
|
#{handlers := #{?WKEY := _}} = Ctx
|
|
@@ -560,28 +629,23 @@ call_proper_post_config_update(
|
|
|
result := Result
|
|
result := Result
|
|
|
} = Ctx
|
|
} = Ctx
|
|
|
) ->
|
|
) ->
|
|
|
- case erlang:function_exported(Module, Callback, 5) of
|
|
|
|
|
- true ->
|
|
|
|
|
- case apply_post_config_update(Module, Ctx) of
|
|
|
|
|
- ok -> {ok, Result};
|
|
|
|
|
- {ok, Result1} -> {ok, Result#{Module => Result1}};
|
|
|
|
|
- {error, Reason} -> {error, {post_config_update, Module, Reason}}
|
|
|
|
|
- end;
|
|
|
|
|
- false ->
|
|
|
|
|
- {ok, Result}
|
|
|
|
|
|
|
+ Arity = get_function_arity(Module, Callback, [5, 6]),
|
|
|
|
|
+ case apply_post_config_update(Module, Callback, Arity, Ctx) of
|
|
|
|
|
+ ok -> {ok, Result};
|
|
|
|
|
+ {ok, Result1} -> {ok, Result#{Module => Result1}};
|
|
|
|
|
+ {error, Reason} -> {error, {post_config_update, Module, Reason}}
|
|
|
end;
|
|
end;
|
|
|
call_proper_post_config_update(
|
|
call_proper_post_config_update(
|
|
|
#{result := Result} = _Ctx
|
|
#{result := Result} = _Ctx
|
|
|
) ->
|
|
) ->
|
|
|
{ok, Result}.
|
|
{ok, Result}.
|
|
|
|
|
|
|
|
-apply_post_config_update(Module, #{
|
|
|
|
|
|
|
+apply_post_config_update(Module, Callback, 5, #{
|
|
|
conf_key_path := ConfKeyPath,
|
|
conf_key_path := ConfKeyPath,
|
|
|
update_req := UpdateReq,
|
|
update_req := UpdateReq,
|
|
|
new_conf := NewConf,
|
|
new_conf := NewConf,
|
|
|
old_conf := OldConf,
|
|
old_conf := OldConf,
|
|
|
- app_envs := AppEnvs,
|
|
|
|
|
- callback := Callback
|
|
|
|
|
|
|
+ app_envs := AppEnvs
|
|
|
}) ->
|
|
}) ->
|
|
|
Module:Callback(
|
|
Module:Callback(
|
|
|
ConfKeyPath,
|
|
ConfKeyPath,
|
|
@@ -589,7 +653,25 @@ apply_post_config_update(Module, #{
|
|
|
NewConf,
|
|
NewConf,
|
|
|
OldConf,
|
|
OldConf,
|
|
|
AppEnvs
|
|
AppEnvs
|
|
|
- ).
|
|
|
|
|
|
|
+ );
|
|
|
|
|
+apply_post_config_update(Module, Callback, 6, #{
|
|
|
|
|
+ conf_key_path := ConfKeyPath,
|
|
|
|
|
+ update_req := UpdateReq,
|
|
|
|
|
+ cluster_rpc_opts := ClusterRpcOpts,
|
|
|
|
|
+ new_conf := NewConf,
|
|
|
|
|
+ old_conf := OldConf,
|
|
|
|
|
+ app_envs := AppEnvs
|
|
|
|
|
+}) ->
|
|
|
|
|
+ Module:Callback(
|
|
|
|
|
+ ConfKeyPath,
|
|
|
|
|
+ UpdateReq,
|
|
|
|
|
+ NewConf,
|
|
|
|
|
+ OldConf,
|
|
|
|
|
+ AppEnvs,
|
|
|
|
|
+ ClusterRpcOpts
|
|
|
|
|
+ );
|
|
|
|
|
+apply_post_config_update(_Module, _Callback, false, _Ctx) ->
|
|
|
|
|
+ ok.
|
|
|
|
|
|
|
|
propagate_post_config_updates_to_subconf(
|
|
propagate_post_config_updates_to_subconf(
|
|
|
#{handlers := #{?WKEY := _}} = Ctx
|
|
#{handlers := #{?WKEY := _}} = Ctx
|
|
@@ -811,3 +893,11 @@ load_prev_handlers() ->
|
|
|
|
|
|
|
|
save_handlers(Handlers) ->
|
|
save_handlers(Handlers) ->
|
|
|
application:set_env(emqx, ?MODULE, Handlers).
|
|
application:set_env(emqx, ?MODULE, Handlers).
|
|
|
|
|
+
|
|
|
|
|
+get_function_arity(_Module, _Callback, []) ->
|
|
|
|
|
+ false;
|
|
|
|
|
+get_function_arity(Module, Callback, [Arity | Opts]) ->
|
|
|
|
|
+ case erlang:function_exported(Module, Callback, Arity) of
|
|
|
|
|
+ true -> Arity;
|
|
|
|
|
+ false -> get_function_arity(Module, Callback, Opts)
|
|
|
|
|
+ end.
|