From 2ddcfdf36539c5eaafae4285d85982fc37047dd3 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Fri, 23 Jul 2021 17:07:29 +0800 Subject: [PATCH 1/4] refactor(config): rename emqx_config:update_config/2 to emqx_config:update/2 --- apps/emqx/src/emqx_config.erl | 6 +++--- apps/emqx/test/emqx_alarm_SUITE.erl | 4 ++-- apps/emqx_authz/src/emqx_authz.erl | 2 +- apps/emqx_authz/test/emqx_authz_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_http_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_redis_SUITE.erl | 4 ++-- apps/emqx_data_bridge/src/emqx_data_bridge.erl | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index 88ba41bdf..fb9d82fc1 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -46,7 +46,7 @@ , find_listener_conf/3 ]). --export([ update_config/2 +-export([ update/2 ]). %% raw configs is the config that is now parsed and tranlated by hocon schema @@ -126,9 +126,9 @@ put(Config) -> put(KeyPath, Config) -> put(emqx_map_lib:deep_put(KeyPath, get(), Config)). --spec update_config(emqx_map_lib:config_key_path(), update_request()) -> +-spec update(emqx_map_lib:config_key_path(), update_request()) -> ok | {error, term()}. -update_config(ConfKeyPath, UpdateReq) -> +update(ConfKeyPath, UpdateReq) -> emqx_config_handler:update_config(ConfKeyPath, UpdateReq, get_raw()). -spec get_raw() -> map(). diff --git a/apps/emqx/test/emqx_alarm_SUITE.erl b/apps/emqx/test/emqx_alarm_SUITE.erl index e21dff30a..1157f94bc 100644 --- a/apps/emqx/test/emqx_alarm_SUITE.erl +++ b/apps/emqx/test/emqx_alarm_SUITE.erl @@ -28,14 +28,14 @@ all() -> emqx_ct:all(?MODULE). init_per_testcase(t_size_limit, Config) -> emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), - emqx_config:update_config([alarm], #{ + emqx_config:update([alarm], #{ <<"size_limit">> => 2 }), Config; init_per_testcase(t_validity_period, Config) -> emqx_ct_helpers:boot_modules(all), emqx_ct_helpers:start_apps([]), - emqx_config:update_config([alarm], #{ + emqx_config:update([alarm], #{ <<"validity_period">> => <<"1s">> }), Config; diff --git a/apps/emqx_authz/src/emqx_authz.erl b/apps/emqx_authz/src/emqx_authz.erl index 784889954..00b2a8e93 100644 --- a/apps/emqx_authz/src/emqx_authz.erl +++ b/apps/emqx_authz/src/emqx_authz.erl @@ -49,7 +49,7 @@ lookup() -> emqx_config:get(?CONF_KEY_PATH, []). update(Cmd, Rules) -> - emqx_config:update_config(?CONF_KEY_PATH, {Cmd, Rules}). + emqx_config:update(?CONF_KEY_PATH, {Cmd, Rules}). %% For now we only support re-creating the entire rule list handle_update_config({head, Rule}, OldConf) when is_map(Rule), is_list(OldConf) -> diff --git a/apps/emqx_authz/test/emqx_authz_SUITE.erl b/apps/emqx_authz/test/emqx_authz_SUITE.erl index 98d2c343c..4c7c0f36c 100644 --- a/apps/emqx_authz/test/emqx_authz_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_SUITE.erl @@ -30,8 +30,8 @@ groups() -> init_per_suite(Config) -> ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update_config([zones, default, acl, cache, enable], false), - ok = emqx_config:update_config([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, acl, cache, enable], false), + ok = emqx_config:update([zones, default, acl, enable], true), emqx_authz:update(replace, []), Config. diff --git a/apps/emqx_authz/test/emqx_authz_http_SUITE.erl b/apps/emqx_authz/test/emqx_authz_http_SUITE.erl index 8d698ff21..5ec5ffa49 100644 --- a/apps/emqx_authz/test/emqx_authz_http_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_http_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update_config([zones, default, acl, cache, enable], false), - ok = emqx_config:update_config([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, acl, cache, enable], false), + ok = emqx_config:update([zones, default, acl, enable], true), Rules = [#{ <<"config">> => #{ <<"url">> => <<"https://fake.com:443/">>, <<"headers">> => #{}, diff --git a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl index a7a1ffbda..dacb7c7a0 100644 --- a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl @@ -38,8 +38,8 @@ init_per_suite(Config) -> ok = emqx_ct_helpers:start_apps([emqx_authz]), ct:pal("---- emqx_hooks: ~p", [ets:tab2list(emqx_hooks)]), - ok = emqx_config:update_config([zones, default, acl, cache, enable], false), - ok = emqx_config:update_config([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, acl, cache, enable], false), + ok = emqx_config:update([zones, default, acl, enable], true), Rules = [#{ <<"config">> => #{ <<"mongo_type">> => <<"single">>, <<"server">> => <<"127.0.0.1:27017">>, diff --git a/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl index abda72618..edd4cb83b 100644 --- a/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update_config([zones, default, acl, cache, enable], false), - ok = emqx_config:update_config([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, acl, cache, enable], false), + ok = emqx_config:update([zones, default, acl, enable], true), Rules = [#{ <<"config">> => #{ <<"server">> => <<"127.0.0.1:27017">>, <<"pool_size">> => 1, diff --git a/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl b/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl index ee1d789f7..4e6a1ce61 100644 --- a/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update_config([zones, default, acl, cache, enable], false), - ok = emqx_config:update_config([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, acl, cache, enable], false), + ok = emqx_config:update([zones, default, acl, enable], true), Rules = [#{ <<"config">> => #{ <<"server">> => <<"127.0.0.1:27017">>, <<"pool_size">> => 1, diff --git a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl index aa932e5e1..7119c07ee 100644 --- a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update_config([zones, default, acl, cache, enable], false), - ok = emqx_config:update_config([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, acl, cache, enable], false), + ok = emqx_config:update([zones, default, acl, enable], true), Rules = [#{ <<"config">> => #{ <<"server">> => <<"127.0.0.1:27017">>, <<"pool_size">> => 1, diff --git a/apps/emqx_data_bridge/src/emqx_data_bridge.erl b/apps/emqx_data_bridge/src/emqx_data_bridge.erl index e37b2f94b..9c27ff8d5 100644 --- a/apps/emqx_data_bridge/src/emqx_data_bridge.erl +++ b/apps/emqx_data_bridge/src/emqx_data_bridge.erl @@ -60,4 +60,4 @@ config_key_path() -> [emqx_data_bridge, bridges]. update_config(ConfigReq) -> - emqx_config:update_config(config_key_path(), ConfigReq). + emqx_config:update(config_key_path(), ConfigReq). From 7a628e201f19531f6262ae88482e79134622314a Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Fri, 23 Jul 2021 18:20:45 +0800 Subject: [PATCH 2/4] fix(config): merge conflicts --- apps/emqx_statsd/src/emqx_statsd_api.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqx_statsd/src/emqx_statsd_api.erl b/apps/emqx_statsd/src/emqx_statsd_api.erl index 13391646a..ce3296ba5 100644 --- a/apps/emqx_statsd/src/emqx_statsd_api.erl +++ b/apps/emqx_statsd/src/emqx_statsd_api.erl @@ -92,7 +92,7 @@ statsd(put, Request) -> {ok, Body, _} = cowboy_req:read_body(Request), Params = emqx_json:decode(Body, [return_maps]), Enable = maps:get(<<"enable">>, Params), - ok = emqx_config:update_config([emqx_statsd], Params), + ok = emqx_config:update([emqx_statsd], Params), enable_statsd(Enable). enable_statsd(true) -> From bbf40a85bfb57e495cc0a55e1372db52d9f51d9b Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Fri, 23 Jul 2021 18:49:09 +0800 Subject: [PATCH 3/4] fix(config): merge conflicts --- apps/emqx_authz/test/emqx_authz_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_http_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_redis_SUITE.erl | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/apps/emqx_authz/test/emqx_authz_SUITE.erl b/apps/emqx_authz/test/emqx_authz_SUITE.erl index 4c7c0f36c..94a312c9e 100644 --- a/apps/emqx_authz/test/emqx_authz_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_SUITE.erl @@ -30,8 +30,8 @@ groups() -> init_per_suite(Config) -> ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update([zones, default, acl, cache, enable], false), - ok = emqx_config:update([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, authorization, cache, enable], false), + ok = emqx_config:update([zones, default, authorization, enable], true), emqx_authz:update(replace, []), Config. diff --git a/apps/emqx_authz/test/emqx_authz_http_SUITE.erl b/apps/emqx_authz/test/emqx_authz_http_SUITE.erl index 5ec5ffa49..405f216ff 100644 --- a/apps/emqx_authz/test/emqx_authz_http_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_http_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update([zones, default, acl, cache, enable], false), - ok = emqx_config:update([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, authorization, cache, enable], false), + ok = emqx_config:update([zones, default, authorization, enable], true), Rules = [#{ <<"config">> => #{ <<"url">> => <<"https://fake.com:443/">>, <<"headers">> => #{}, diff --git a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl index dacb7c7a0..81a95e9a5 100644 --- a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl @@ -38,8 +38,8 @@ init_per_suite(Config) -> ok = emqx_ct_helpers:start_apps([emqx_authz]), ct:pal("---- emqx_hooks: ~p", [ets:tab2list(emqx_hooks)]), - ok = emqx_config:update([zones, default, acl, cache, enable], false), - ok = emqx_config:update([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, authorization, cache, enable], false), + ok = emqx_config:update([zones, default, authorization, enable], true), Rules = [#{ <<"config">> => #{ <<"mongo_type">> => <<"single">>, <<"server">> => <<"127.0.0.1:27017">>, diff --git a/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl index edd4cb83b..6426cbe4d 100644 --- a/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update([zones, default, acl, cache, enable], false), - ok = emqx_config:update([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, authorization, cache, enable], false), + ok = emqx_config:update([zones, default, authorization, enable], true), Rules = [#{ <<"config">> => #{ <<"server">> => <<"127.0.0.1:27017">>, <<"pool_size">> => 1, diff --git a/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl b/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl index 4e6a1ce61..dfad14ca4 100644 --- a/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update([zones, default, acl, cache, enable], false), - ok = emqx_config:update([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, authorization, cache, enable], false), + ok = emqx_config:update([zones, default, authorization, enable], true), Rules = [#{ <<"config">> => #{ <<"server">> => <<"127.0.0.1:27017">>, <<"pool_size">> => 1, diff --git a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl index 7119c07ee..0b35c9de3 100644 --- a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl @@ -36,8 +36,8 @@ init_per_suite(Config) -> meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), ok = emqx_ct_helpers:start_apps([emqx_authz]), - ok = emqx_config:update([zones, default, acl, cache, enable], false), - ok = emqx_config:update([zones, default, acl, enable], true), + ok = emqx_config:update([zones, default, authorization, cache, enable], false), + ok = emqx_config:update([zones, default, authorization, enable], true), Rules = [#{ <<"config">> => #{ <<"server">> => <<"127.0.0.1:27017">>, <<"pool_size">> => 1, From 935ef0db20c0ee34e06f1e5300e7684066898659 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Fri, 23 Jul 2021 18:56:30 +0800 Subject: [PATCH 4/4] fix(config): rename callback functions for emqx_config_handler --- apps/emqx/src/emqx_alarm.erl | 6 +-- apps/emqx/src/emqx_config_handler.erl | 40 +++++++++---------- apps/emqx_authz/src/emqx_authz.erl | 12 +++--- .../src/emqx_data_bridge_app.erl | 8 ++-- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/apps/emqx/src/emqx_alarm.erl b/apps/emqx/src/emqx_alarm.erl index ea96f14ff..086447c8c 100644 --- a/apps/emqx/src/emqx_alarm.erl +++ b/apps/emqx/src/emqx_alarm.erl @@ -30,7 +30,7 @@ -boot_mnesia({mnesia, [boot]}). -copy_mnesia({mnesia, [copy]}). --export([handle_update_config/2]). +-export([pre_config_update/2]). -export([ start_link/0 , stop/0 @@ -153,10 +153,10 @@ get_alarms(activated) -> get_alarms(deactivated) -> gen_server:call(?MODULE, {get_alarms, deactivated}). -handle_update_config(#{<<"validity_period">> := Period0} = NewConf, OldConf) -> +pre_config_update(#{<<"validity_period">> := Period0} = NewConf, OldConf) -> ?MODULE ! {update_timer, hocon_postprocess:duration(Period0)}, maps:merge(OldConf, NewConf); -handle_update_config(NewConf, OldConf) -> +pre_config_update(NewConf, OldConf) -> maps:merge(OldConf, NewConf). format(#activated_alarm{name = Name, message = Message, activate_at = At, details = Details}) -> diff --git a/apps/emqx/src/emqx_config_handler.erl b/apps/emqx/src/emqx_config_handler.erl index 627cb4c98..e051b27eb 100644 --- a/apps/emqx/src/emqx_config_handler.erl +++ b/apps/emqx/src/emqx_config_handler.erl @@ -29,7 +29,7 @@ ]). %% emqx_config_handler callbacks --export([ handle_update_config/2 +-export([ pre_config_update/2 ]). %% gen_server callbacks @@ -45,14 +45,14 @@ -type handler_name() :: module(). -type handlers() :: #{emqx_config:config_key() => handlers(), ?MOD => handler_name()}. --optional_callbacks([ handle_update_config/2 - , post_update_config/2 +-optional_callbacks([ pre_config_update/2 + , post_config_update/2 ]). --callback handle_update_config(emqx_config:update_request(), emqx_config:raw_config()) -> +-callback pre_config_update(emqx_config:update_request(), emqx_config:raw_config()) -> emqx_config:update_request(). --callback post_update_config(emqx_config:config(), emqx_config:config()) -> any(). +-callback post_config_update(emqx_config:config(), emqx_config:config()) -> any(). -type state() :: #{ handlers := handlers(), @@ -88,7 +88,7 @@ handle_call({update_config, ConfKeyPath, UpdateReq, RawConf}, _From, OldConf = emqx_config:get(), try {RootKeys, Conf} = do_update_config(ConfKeyPath, Handlers, RawConf, UpdateReq), Result = emqx_config:save_configs(Conf, #{overridden_keys => RootKeys}), - do_post_update_config(ConfKeyPath, Handlers, OldConf, emqx_config:get()), + do_post_config_update(ConfKeyPath, Handlers, OldConf, emqx_config:get()), {reply, Result, State} catch Error : Reason : ST -> @@ -113,43 +113,43 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}. do_update_config([], Handlers, OldRawConf, UpdateReq) -> - call_handle_update_config(Handlers, OldRawConf, UpdateReq); + call_pre_config_update(Handlers, OldRawConf, UpdateReq); do_update_config([ConfKey | ConfKeyPath], Handlers, OldRawConf, UpdateReq) -> SubOldRawConf = get_sub_config(bin(ConfKey), OldRawConf), SubHandlers = maps:get(ConfKey, Handlers, #{}), NewUpdateReq = do_update_config(ConfKeyPath, SubHandlers, SubOldRawConf, UpdateReq), - call_handle_update_config(Handlers, OldRawConf, #{bin(ConfKey) => NewUpdateReq}). + call_pre_config_update(Handlers, OldRawConf, #{bin(ConfKey) => NewUpdateReq}). -do_post_update_config([], Handlers, OldConf, NewConf) -> - call_post_update_config(Handlers, OldConf, NewConf); -do_post_update_config([ConfKey | ConfKeyPath], Handlers, OldConf, NewConf) -> +do_post_config_update([], Handlers, OldConf, NewConf) -> + call_post_config_update(Handlers, OldConf, NewConf); +do_post_config_update([ConfKey | ConfKeyPath], Handlers, OldConf, NewConf) -> SubOldConf = get_sub_config(ConfKey, OldConf), SubNewConf = get_sub_config(ConfKey, NewConf), SubHandlers = maps:get(ConfKey, Handlers, #{}), - _ = do_post_update_config(ConfKeyPath, SubHandlers, SubOldConf, SubNewConf), - call_post_update_config(Handlers, OldConf, NewConf). + _ = do_post_config_update(ConfKeyPath, SubHandlers, SubOldConf, SubNewConf), + call_post_config_update(Handlers, OldConf, NewConf). get_sub_config(ConfKey, Conf) when is_map(Conf) -> maps:get(ConfKey, Conf, undefined); get_sub_config(_, _Conf) -> %% the Conf is a primitive undefined. -call_handle_update_config(Handlers, OldRawConf, UpdateReq) -> +call_pre_config_update(Handlers, OldRawConf, UpdateReq) -> HandlerName = maps:get(?MOD, Handlers, undefined), - case erlang:function_exported(HandlerName, handle_update_config, 2) of - true -> HandlerName:handle_update_config(UpdateReq, OldRawConf); + case erlang:function_exported(HandlerName, pre_config_update, 2) of + true -> HandlerName:pre_config_update(UpdateReq, OldRawConf); false -> merge_to_old_config(UpdateReq, OldRawConf) end. -call_post_update_config(Handlers, OldConf, NewConf) -> +call_post_config_update(Handlers, OldConf, NewConf) -> HandlerName = maps:get(?MOD, Handlers, undefined), - case erlang:function_exported(HandlerName, post_update_config, 2) of - true -> _ = HandlerName:post_update_config(NewConf, OldConf); + case erlang:function_exported(HandlerName, post_config_update, 2) of + true -> _ = HandlerName:post_config_update(NewConf, OldConf); false -> ok end. %% callbacks for the top-level handler -handle_update_config(UpdateReq, OldConf) -> +pre_config_update(UpdateReq, OldConf) -> FullRawConf = merge_to_old_config(UpdateReq, OldConf), {maps:keys(UpdateReq), FullRawConf}. diff --git a/apps/emqx_authz/src/emqx_authz.erl b/apps/emqx_authz/src/emqx_authz.erl index 00b2a8e93..8a85dc417 100644 --- a/apps/emqx_authz/src/emqx_authz.erl +++ b/apps/emqx_authz/src/emqx_authz.erl @@ -31,7 +31,7 @@ , match/4 ]). --export([post_update_config/2, handle_update_config/2]). +-export([post_config_update/2, pre_config_update/2]). -define(CONF_KEY_PATH, [emqx_authz, rules]). @@ -52,21 +52,21 @@ update(Cmd, Rules) -> emqx_config:update(?CONF_KEY_PATH, {Cmd, Rules}). %% For now we only support re-creating the entire rule list -handle_update_config({head, Rule}, OldConf) when is_map(Rule), is_list(OldConf) -> +pre_config_update({head, Rule}, OldConf) when is_map(Rule), is_list(OldConf) -> [Rule | OldConf]; -handle_update_config({tail, Rule}, OldConf) when is_map(Rule), is_list(OldConf) -> +pre_config_update({tail, Rule}, OldConf) when is_map(Rule), is_list(OldConf) -> OldConf ++ [Rule]; -handle_update_config({_, NewConf}, _OldConf) -> +pre_config_update({_, NewConf}, _OldConf) -> %% overwrite the entire config! case is_list(NewConf) of true -> NewConf; false -> [NewConf] end. -post_update_config(undefined, _OldConf) -> +post_config_update(undefined, _OldConf) -> %_ = [release_rules(Rule) || Rule <- OldConf], ok; -post_update_config(NewRules, _OldConf) -> +post_config_update(NewRules, _OldConf) -> %_ = [release_rules(Rule) || Rule <- OldConf], InitedRules = [init_rule(Rule) || Rule <- NewRules], Action = find_action_in_hooks(), diff --git a/apps/emqx_data_bridge/src/emqx_data_bridge_app.erl b/apps/emqx_data_bridge/src/emqx_data_bridge_app.erl index ccd98f010..26128841b 100644 --- a/apps/emqx_data_bridge/src/emqx_data_bridge_app.erl +++ b/apps/emqx_data_bridge/src/emqx_data_bridge_app.erl @@ -19,7 +19,7 @@ -behaviour(emqx_config_handler). --export([start/2, stop/1, handle_update_config/2]). +-export([start/2, stop/1, pre_config_update/2]). start(_StartType, _StartArgs) -> {ok, Sup} = emqx_data_bridge_sup:start_link(), @@ -31,11 +31,11 @@ stop(_State) -> ok. %% internal functions -handle_update_config({update, Bridge = #{<<"name">> := Name}}, OldConf) -> +pre_config_update({update, Bridge = #{<<"name">> := Name}}, OldConf) -> [Bridge | remove_bridge(Name, OldConf)]; -handle_update_config({delete, Name}, OldConf) -> +pre_config_update({delete, Name}, OldConf) -> remove_bridge(Name, OldConf); -handle_update_config(NewConf, _OldConf) when is_list(NewConf) -> +pre_config_update(NewConf, _OldConf) when is_list(NewConf) -> %% overwrite the entire config! NewConf.