diff --git a/big_tests/tests/dynamic_domains_SUITE.erl b/big_tests/tests/dynamic_domains_SUITE.erl index 7093c59f8cf..1c23f08b6d4 100644 --- a/big_tests/tests/dynamic_domains_SUITE.erl +++ b/big_tests/tests/dynamic_domains_SUITE.erl @@ -43,9 +43,9 @@ init_per_group(with_mod_dynamic_domains_test, Config) -> [ok = rpc(mim(), meck, new, [Module, [passthrough, no_link]]) || Module <- MockedModules], dynamic_modules:start(?HOST_TYPE, mod_dynamic_domains_test, - [{host1, subhost_pattern("subdomain1.@HOST@")}, - {host2, subhost_pattern("subdomain2.@HOST@")}, - {namespace, <<"dummy.namespace">>}]), + #{host1 => subhost_pattern("subdomain1.@HOST@"), + host2 => subhost_pattern("subdomain2.@HOST@"), + namespace => <<"dummy.namespace">>}), [{reset_meck, MockedModules} | Config]; init_per_group(_, Config) -> Config. diff --git a/big_tests/tests/service_mongoose_system_metrics_SUITE.erl b/big_tests/tests/service_mongoose_system_metrics_SUITE.erl index a99f74018b0..57da0fca4ce 100644 --- a/big_tests/tests/service_mongoose_system_metrics_SUITE.erl +++ b/big_tests/tests/service_mongoose_system_metrics_SUITE.erl @@ -221,6 +221,7 @@ module_opts_are_reported(_Config) -> check_module_backend(mod_bosh, mnesia), check_module_backend(mod_event_pusher, push), check_module_backend(mod_event_pusher_push, Backend), + check_module_backend(mod_http_upload, s3), check_module_backend(mod_last, Backend), check_module_backend(mod_muc, Backend), check_module_backend(mod_muc_light, Backend), @@ -341,6 +342,7 @@ modules_to_test(module_opts_are_reported) -> [required_module(mod_bosh), required_module(mod_event_pusher, #{push => config([modules, mod_event_pusher, push], #{backend => Backend})}), + required_module(mod_http_upload, s3), required_module(mod_last, Backend), required_module(mod_muc, Backend), required_module(mod_muc_light, Backend), diff --git a/doc/migrations/5.0.0_5.1.0.md b/doc/migrations/5.0.0_5.1.0.md index d9c157b8bfd..cdc1d91ca22 100644 --- a/doc/migrations/5.0.0_5.1.0.md +++ b/doc/migrations/5.0.0_5.1.0.md @@ -59,3 +59,6 @@ The archive functionality recently introduced has been extended to support many ## Removal of deprecated modules * `mod_revproxy` - removed from the code base as it was unsupported since 4.2.0. * `mod_aws_sns` - its functionality is fully covered by [`mod_event_pusher`](../modules/mod_event_pusher.md). + +## Internal module configuration rework +If you are using your own extension modules (or services), you need to update the code. The most important change is that configuration options were stored in proplists before, and now they are stored in maps, so e.g. the `start/2` function of your module should expect a map as the second argument. diff --git a/doc/modules/mod_event_pusher_push.md b/doc/modules/mod_event_pusher_push.md index 960f53d7d8a..64e021df71f 100644 --- a/doc/modules/mod_event_pusher_push.md +++ b/doc/modules/mod_event_pusher_push.md @@ -24,6 +24,13 @@ with 100 asynchronous workers that will handle all push notification related wor ## Options +### `modules.mod_event_pusher.push.iqdisc.type` +* **Syntax:** string, one of `"one_queue"`, `"no_queue"`, `"queues"`, `"parallel"` +* **Default:** `"one_queue"` + +Strategy to handle incoming stanzas. For details, please refer to +[IQ processing policies](../configuration/Modules.md#iq-processing-policies). + ### `modules.mod_event_pusher.push.backend` * **Syntax:** string, one of `"mnesia"`, `"rdbms"` * **Default:** `"mnesia"` diff --git a/src/admin_extra/service_admin_extra_vcard.erl b/src/admin_extra/service_admin_extra_vcard.erl index 1a8c6c3ed91..070cfa27096 100644 --- a/src/admin_extra/service_admin_extra_vcard.erl +++ b/src/admin_extra/service_admin_extra_vcard.erl @@ -170,18 +170,10 @@ set_vcard(User, Host, Name, Subname, SomeContent) -> %% %% Internal vcard --spec get_module_resource(jid:server()) -> string(). -get_module_resource(Server) -> - case gen_mod:get_module_opt(Server, ?MODULE, module_resource, none) of - none -> atom_to_list(?MODULE); - R when is_list(R) -> R - end. - - -spec get_vcard_content(jid:jid(), any()) -> {error, string()} | list(binary()). get_vcard_content(#jid{lserver = LServer} = NoResJID, Data) -> - JID = jid:replace_resource(NoResJID, list_to_binary(get_module_resource(LServer))), + JID = jid:replace_resource(NoResJID, atom_to_binary(?MODULE)), IQ = #iq{type = get, xmlns = ?NS_VCARD, sub_el = []}, {ok, HostType} = mongoose_domain_api:get_domain_host_type(LServer), Acc = mongoose_acc:new(#{ location => ?LOCATION, diff --git a/src/config/mongoose_config_parser.erl b/src/config/mongoose_config_parser.erl index 608066e217c..462893132d1 100644 --- a/src/config/mongoose_config_parser.erl +++ b/src/config/mongoose_config_parser.erl @@ -9,9 +9,6 @@ %% state API -export([build_state/3, get_opts/1]). -%% config post-processing --export([unfold_opts/1]). - -callback parse_file(FileName :: string()) -> state(). -include("mongoose.hrl"). @@ -138,7 +135,7 @@ post_process_services(State = #state{opts = Opts}) -> post_process_services_opt({services, Services}) -> ServicesWithDeps = mongoose_service_deps:resolve_deps(Services), - {services, unfold_all_opts(ServicesWithDeps)}; + {services, ServicesWithDeps}; post_process_services_opt(Other) -> Other. @@ -149,16 +146,10 @@ post_process_modules(State = #state{opts = Opts}) -> post_process_modules_opt({{modules, HostType}, Modules}) -> ModulesWithDeps = gen_mod_deps:resolve_deps(HostType, Modules), - {{modules, HostType}, unfold_all_opts(ModulesWithDeps)}; + {{modules, HostType}, ModulesWithDeps}; post_process_modules_opt(Other) -> Other. -unfold_all_opts(Modules) -> - maps:map(fun(_Mod, Opts) -> unfold_opts(Opts) end, Modules). - -unfold_opts(Opts) when is_map(Opts) -> Opts; -unfold_opts(Opts) -> proplists:unfold(Opts). - %% local functions -spec halt_with_msg(string(), [any()]) -> no_return(). diff --git a/src/config/mongoose_config_spec.erl b/src/config/mongoose_config_spec.erl index 4e19ba3996a..0e7599714b1 100644 --- a/src/config/mongoose_config_spec.erl +++ b/src/config/mongoose_config_spec.erl @@ -12,7 +12,6 @@ -export([process_root/1, process_host/1, process_general/1, - process_sm_backend/1, process_ctl_access_rule/1, process_listener/2, process_verify_peer/1, @@ -184,7 +183,6 @@ general() -> wrap = global_config}, <<"sm_backend">> => #option{type = atom, validate = {module, ejabberd_sm}, - process = fun ?MODULE:process_sm_backend/1, wrap = global_config}, <<"max_fsm_queue">> => #option{type = integer, validate = positive, @@ -222,7 +220,7 @@ general_defaults() -> <<"registration_timeout">> => 600, <<"language">> => <<"en">>, <<"all_metrics_are_global">> => false, - <<"sm_backend">> => {mnesia, []}, + <<"sm_backend">> => mnesia, <<"rdbms_server_type">> => generic, <<"mongooseimctl_access_commands">> => [], <<"routing_modules">> => mongoose_router:default_routing_modules(), @@ -795,7 +793,7 @@ modules() -> || Module <- configurable_modules()], Items = maps:from_list(Modules), #section{ - items = Items#{default => #section{items = #{}}}, + items = Items#{default => #section{items = #{}, format_items = map}}, validate_keys = module, format_items = map, wrap = host_config @@ -1062,9 +1060,6 @@ process_ctl_access_rule(KVs) -> ArgRestrictions = proplists:get_value(argument_restrictions, KVs, []), {Commands, ArgRestrictions}. -process_sm_backend(Backend) -> - {Backend, []}. - process_host(Host) -> Node = jid:nodeprep(Host), true = Node =/= error, diff --git a/src/ejabberd_cowboy.erl b/src/ejabberd_cowboy.erl index b96b29a2e87..46e9dc0d554 100644 --- a/src/ejabberd_cowboy.erl +++ b/src/ejabberd_cowboy.erl @@ -132,7 +132,7 @@ execute(Req, Env) -> %%-------------------------------------------------------------------- start_cowboy(Ref, Opts) -> - {Retries, SleepTime} = gen_mod:get_opt(retries, Opts, {20, 50}), + {Retries, SleepTime} = proplists:get_value(retries, Opts, {20, 50}), do_start_cowboy(Ref, Opts, Retries, SleepTime). @@ -148,14 +148,14 @@ do_start_cowboy(Ref, Opts, Retries, SleepTime) -> end. do_start_cowboy(Ref, Opts) -> - SSLOpts = gen_mod:get_opt(ssl, Opts, undefined), - NumAcceptors = gen_mod:get_opt(num_acceptors, Opts, 100), - TransportOpts0 = gen_mod:get_opt(transport_options, Opts, #{}), + SSLOpts = proplists:get_value(ssl, Opts), + NumAcceptors = proplists:get_value(num_acceptors, Opts, 100), + TransportOpts0 = proplists:get_value(transport_options, Opts, #{}), TransportOpts = TransportOpts0#{num_acceptors => NumAcceptors}, - Modules = gen_mod:get_opt(modules, Opts), + Modules = proplists:get_value(modules, Opts), Dispatch = cowboy_router:compile(get_routes(Modules)), ProtocolOpts = [{env, [{dispatch, Dispatch}]} | - gen_mod:get_opt(protocol_options, Opts, [])], + proplists:get_value(protocol_options, Opts, [])], ok = trails_store(Modules), case catch start_http_or_https(SSLOpts, Ref, TransportOpts, ProtocolOpts) of {error, {{shutdown, @@ -194,7 +194,7 @@ add_common_middleware(Map) -> Map#{ middlewares => [cowboy_router, ?MODULE, cowboy_handler] }. reload_dispatch(Ref, Opts) -> - Dispatch = cowboy_router:compile(get_routes(gen_mod:get_opt(modules, Opts))), + Dispatch = cowboy_router:compile(get_routes(proplists:get_value(modules, Opts))), cowboy:set_env(Ref, dispatch, Dispatch). stop_cowboy(Ref) -> @@ -267,7 +267,7 @@ filter_options(_, []) -> []. maybe_set_verify_fun(SSLOptions) -> - case proplists:get_value(verify_mode, SSLOptions, undefined) of + case proplists:get_value(verify_mode, SSLOptions) of undefined -> SSLOptions; Mode -> @@ -279,7 +279,7 @@ maybe_set_verify_fun(SSLOptions) -> % used max_connections tuple for all ejabberd_cowboy listeners maybe_insert_max_connections(TransportOpts, Opts) -> Key = max_connections, - case gen_mod:get_opt(Key, Opts, undefined) of + case proplists:get_value(Key, Opts) of undefined -> TransportOpts; Value -> diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index ce1c9470f41..a27087d8c3d 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -491,8 +491,8 @@ node_cleanup(Acc, Node) -> %%-------------------------------------------------------------------- -spec init(_) -> {ok, state()}. init([]) -> - {Backend, Opts} = mongoose_config:get_opt(sm_backend), - ejabberd_sm_backend:init([{backend, Backend}|Opts]), + Backend = mongoose_config:get_opt(sm_backend), + ejabberd_sm_backend:init(#{backend => Backend}), ets:new(sm_iqtable, [named_table, protected, {read_concurrency, true}]), ejabberd_hooks:add(node_cleanup, global, ?MODULE, node_cleanup, 50), diff --git a/src/ejabberd_sm_backend.erl b/src/ejabberd_sm_backend.erl index 96f21fa19d0..6ebc2018e65 100644 --- a/src/ejabberd_sm_backend.erl +++ b/src/ejabberd_sm_backend.erl @@ -1,7 +1,7 @@ %% Generic module to access SM backend modules -module(ejabberd_sm_backend). --callback init(list()) -> +-callback init(map()) -> any(). -callback get_sessions() -> [ejabberd_sm:session()]. @@ -29,7 +29,7 @@ -callback total_count() -> integer(). -callback unique_count() -> integer(). --export([init/1, +-export([init/1, get_sessions/0, get_sessions/1, get_sessions/2, get_sessions/3, create_session/4, update_session/4, delete_session/4, cleanup/1, total_count/0, unique_count/0]). @@ -38,7 +38,7 @@ -define(MAIN_MODULE, ejabberd_sm). --spec init(list()) -> any(). +-spec init(map()) -> any(). init(Opts) -> Args = [Opts], mongoose_backend:init(global, ?MAIN_MODULE, [], Opts), diff --git a/src/ejabberd_sm_mnesia.erl b/src/ejabberd_sm_mnesia.erl index c8492bea6be..0f939cf6573 100644 --- a/src/ejabberd_sm_mnesia.erl +++ b/src/ejabberd_sm_mnesia.erl @@ -25,7 +25,7 @@ total_count/0, unique_count/0]). --spec init(list()) -> any(). +-spec init(map()) -> any(). init(_Opts) -> mnesia:create_table(session, [{ram_copies, [node()]}, diff --git a/src/ejabberd_sm_redis.erl b/src/ejabberd_sm_redis.erl index 1f4b61105ba..a3fa855253b 100644 --- a/src/ejabberd_sm_redis.erl +++ b/src/ejabberd_sm_redis.erl @@ -27,7 +27,7 @@ -ignore_xref([maybe_initial_cleanup/2]). --spec init(list()) -> any(). +-spec init(map()) -> any(). init(_Opts) -> %% Clean current node's sessions from previous life {Elapsed, RetVal} = timer:tc(?MODULE, maybe_initial_cleanup, [node(), true]), diff --git a/src/event_pusher/mod_event_pusher_push.erl b/src/event_pusher/mod_event_pusher_push.erl index 3b9e01fb52b..b49b3b6b8a6 100644 --- a/src/event_pusher/mod_event_pusher_push.erl +++ b/src/event_pusher/mod_event_pusher_push.erl @@ -74,8 +74,7 @@ start(HostType, Opts) -> start_pool(HostType, #{wpool := WpoolOpts}) -> {ok, _} = mongoose_wpool:start(generic, HostType, pusher_push, maps:to_list(WpoolOpts)). -init_iq_handlers(HostType, Opts) -> - IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue), +init_iq_handlers(HostType, #{iqdisc := IQDisc}) -> gen_iq_handler:add_iq_handler(ejabberd_local, HostType, ?NS_PUSH, ?MODULE, iq_handler, IQDisc), gen_iq_handler:add_iq_handler(ejabberd_sm, HostType, ?NS_PUSH, ?MODULE, @@ -96,11 +95,13 @@ config_spec() -> VirtPubSubHost = #option{type = string, validate = subdomain_template, process = fun mongoose_subdomain_utils:make_subdomain_pattern/1}, #section{ - items = #{<<"backend">> => #option{type = atom, validate = {module, ?MODULE}}, + items = #{<<"iqdisc">> => mongoose_config_spec:iqdisc(), + <<"backend">> => #option{type = atom, validate = {module, ?MODULE}}, <<"wpool">> => wpool_spec(), <<"plugin_module">> => #option{type = atom, validate = module}, <<"virtual_pubsub_hosts">> => #list{items = VirtPubSubHost}}, - defaults = #{<<"backend">> => mnesia, + defaults = #{<<"iqdisc">> => one_queue, + <<"backend">> => mnesia, <<"plugin_module">> => mod_event_pusher_push_plugin:default_plugin_module(), <<"virtual_pubsub_hosts">> => []}, format_items = map diff --git a/src/event_pusher/mod_event_pusher_sns.erl b/src/event_pusher/mod_event_pusher_sns.erl index 4de3c8289e5..6218be88b1d 100644 --- a/src/event_pusher/mod_event_pusher_sns.erl +++ b/src/event_pusher/mod_event_pusher_sns.erl @@ -20,7 +20,6 @@ %%%=================================================================== -define(TOPIC_BASE, ["arn", "aws", "sns"]). --define(PUBLISH_RETRY_COUNT_DEFAULT, 2). -type user_guid() :: binary(). -type topic_arn() :: string(). %% Full topic ARN in format arn:aws:sns:{REGION}:{ACCOUNT_ID}:{TOPIC} @@ -115,11 +114,10 @@ push_event(Acc, _) -> -spec user_presence_changed(mongooseim:host_type(), UserJID :: jid:jid(), IsOnline :: boolean()) -> ok. user_presence_changed(HostType, UserJID, IsOnline) -> - Topic = opt(HostType, presence_updates_topic), - case Topic of - undefined -> + case gen_mod:lookup_module_opt(HostType, ?MODULE, presence_updates_topic) of + {error, not_found} -> skip; - Topic -> + {ok, Topic} -> UserGUID = user_guid(HostType, UserJID), Content = #{user_id => UserGUID, present => IsOnline}, TopicARN = make_topic_arn(HostType, Topic), @@ -158,7 +156,7 @@ handle_packet(HostType, From, To, Packet) -> -spec async_publish(mongooseim:host_type(), topic_arn(), Content :: jiffy:json_value(), attributes()) -> ok. async_publish(HostType, TopicARN, Content, Attributes) -> - Retry = opt(HostType, publish_retry_count, ?PUBLISH_RETRY_COUNT_DEFAULT), + Retry = gen_mod:get_module_opt(HostType, ?MODULE, publish_retry_count), mongoose_wpool:cast(generic, HostType, pusher_sns, {?MODULE, try_publish, [HostType, TopicARN, Content, Attributes, Retry]}). @@ -198,10 +196,8 @@ publish(HostType, TopicARN, Content, Attributes) -> %% @doc Returns AWS SNS handle base on configured AWS credentials -spec aws_handle(mongooseim:host_type()) -> aws_config(). aws_handle(HostType) -> - AccessKeyId = opt(HostType, access_key_id), - SecretKey = opt(HostType, secret_access_key), - SNSHost = opt(HostType, sns_host), - + Opts = gen_mod:get_loaded_module_opts(HostType, ?MODULE), + #{access_key_id := AccessKeyId, secret_access_key := SecretKey, sns_host := SNSHost} = Opts, erlcloud_sns:new(AccessKeyId, SecretKey, SNSHost). %% @doc Returns notification topic based on packet type and module configuration @@ -209,9 +205,9 @@ aws_handle(HostType) -> get_topic(HostType, Packet) -> case message_type(Packet) of pm -> - opt(HostType, pm_messages_topic); + gen_mod:get_module_opt(HostType, ?MODULE, pm_messages_topic, undefined); muc -> - opt(HostType, muc_messages_topic); + gen_mod:get_module_opt(HostType, ?MODULE, muc_messages_topic, undefined); _ -> undefined end. @@ -219,9 +215,8 @@ get_topic(HostType, Packet) -> %% @doc Constructs SNS TopicArn from given topic suffix -spec make_topic_arn(mongooseim:host_type(), topic()) -> topic_arn(). make_topic_arn(HostType, Topic) -> - AWSRegion = opt(HostType, region), - AWSAccountId = opt(HostType, account_id), - + Opts = gen_mod:get_loaded_module_opts(HostType, ?MODULE), + #{region := AWSRegion, account_id := AWSAccountId} = Opts, string:join(?TOPIC_BASE ++ [AWSRegion, AWSAccountId, Topic], ":"). %% @doc Returns message type @@ -233,43 +228,32 @@ message_type(Packet) -> _ -> undefined end. -%% Getter for module options --spec opt(mongooseim:host_type(), gen_mod:opt_key()) -> gen_mod:opt_value() | undefined. -opt(HostType, Option) -> - opt(HostType, Option, undefined). - -%% Getter for module options with default value --spec opt(mongooseim:host_type(), gen_mod:opt_key(), Default :: gen_mod:opt_value()) -> - gen_mod:opt_value(). -opt(HostType, Option, Default) -> - gen_mod:get_module_opt(HostType, ?MODULE, Option, Default). - %% ---------------------------------------------------------------------- %% Callbacks -spec user_guid(mongooseim:host_type(), UserJID :: jid:jid()) -> user_guid(). user_guid(HostType, UserJID) -> - PluginModule = opt(HostType, plugin_module, mod_event_pusher_sns_defaults), + PluginModule = gen_mod:get_module_opt(HostType, ?MODULE, plugin_module), PluginModule:user_guid(UserJID). -spec message_attributes(mongooseim:host_type(), TopicARN :: topic_arn(), UserJID :: jid:jid(), IsOnline :: boolean()) -> attributes(). message_attributes(HostType, TopicARN, UserJID, IsOnline) -> - PluginModule = opt(HostType, plugin_module, mod_event_pusher_sns_defaults), + PluginModule = gen_mod:get_module_opt(HostType, ?MODULE, plugin_module), PluginModule:message_attributes(TopicARN, UserJID, IsOnline). -spec message_attributes(mongooseim:host_type(), TopicARN :: topic_arn(), From :: jid:jid(), To :: jid:jid(), MessageType :: pm | muc, Packet :: exml:element()) -> attributes(). message_attributes(HostType, TopicARN, From, To, MessageType, Packet) -> - PluginModule = opt(HostType, plugin_module, mod_event_pusher_sns_defaults), + PluginModule = gen_mod:get_module_opt(HostType, ?MODULE, plugin_module), PluginModule:message_attributes(TopicARN, From, To, MessageType, Packet). -spec calc_backoff_time(mongooseim:host_type(), integer()) -> integer(). calc_backoff_time(HostType, Retry) -> - MaxRetry = opt(HostType, publish_retry_count, ?PUBLISH_RETRY_COUNT_DEFAULT), - BaseTime = opt(HostType, publish_retry_time_ms, 50), + Opts = gen_mod:get_loaded_module_opts(HostType, ?MODULE), + #{publish_retry_count := MaxRetry, publish_retry_time_ms := BaseTime} = Opts, BackoffMaxTime = round(math:pow(2, MaxRetry - Retry)) * BaseTime, Random = rand:uniform(BaseTime), BackoffMaxTime - Random. diff --git a/src/gen_mod.erl b/src/gen_mod.erl index ca91ceaa757..3d7913cf37a 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -31,13 +31,13 @@ -export([ % Modules start & stop, do NOT use in the tests, use mongoose_modules API instead start_module/3, - start_backend_module/3, stop_module/2, does_module_support/2, config_spec/1, % Get/set opts by host or from a list get_opt/2, get_opt/3, + lookup_module_opt/3, get_module_opt/3, get_module_opt/4, get_module_opts/2, @@ -67,8 +67,7 @@ -type key_path() :: mongoose_config:key_path(). -type opt_key() :: atom(). -type opt_value() :: mongoose_config:value(). --type module_opts() :: [{opt_key(), opt_value()}] % deprecated, will be removed - | #{opt_key() => opt_value()}. % recommended +-type module_opts() :: #{opt_key() => opt_value()}. -callback start(HostType :: host_type(), Opts :: module_opts()) -> any(). -callback stop(HostType :: host_type()) -> any(). @@ -92,9 +91,7 @@ %% @doc This function should be called by mongoose_modules only. %% To start a new module at runtime, use mongoose_modules:ensure_module/3 instead. --spec start_module(HostType :: host_type(), - Module :: module(), - Opts :: [any()]) -> {ok, term()}. +-spec start_module(host_type(), module(), module_opts()) -> {ok, term()}. start_module(HostType, Module, Opts) -> assert_loaded(HostType, Module), start_module_for_host_type(HostType, Module, Opts). @@ -172,11 +169,6 @@ is_common_test_running() -> false end. -%% @deprecated To be removed when mod_pubsub does not use it anymore -start_backend_module(Module, Opts, TrackedFuncs) -> - Backend = gen_mod:get_opt(backend, Opts, mnesia), - backend_module:create(Module, Backend, TrackedFuncs). - -spec is_app_running(_) -> boolean(). is_app_running(AppName) -> %% Use a high timeout to prevent a false positive in a high load system @@ -246,43 +238,44 @@ wait_for_stop(MonitorReference) -> get_opt(Path, Opts) when is_list(Path), is_map(Opts) -> lists:foldl(fun maps:get/2, Opts, Path); get_opt(Opt, Opts) when is_map(Opts) -> - maps:get(Opt, Opts); -get_opt(Opt, Opts) -> - case lists:keysearch(Opt, 1, Opts) of - false -> - throw({undefined_option, Opt}); - {value, {_, Val}} -> - Val - end. + maps:get(Opt, Opts). -spec get_opt(opt_key() | key_path(), module_opts(), opt_value()) -> opt_value(). get_opt(Path, Opts, Default) -> try get_opt(Path, Opts) catch - error:{badkey, _} -> Default; - throw:{undefined_option, _} -> Default + error:{badkey, _} -> Default end. +-spec lookup_module_opt(mongooseim:host_type(), module(), opt_key() | key_path()) -> + {ok, opt_value()} | {error, not_found}. +lookup_module_opt(HostType, Module, Key) -> + mongoose_config:lookup_opt(config_path(HostType, Module, Key)). + -spec get_module_opt(mongooseim:host_type(), module(), opt_key() | key_path(), opt_value()) -> opt_value(). -get_module_opt(HostType, Module, Opt, Default) -> +get_module_opt(HostType, Module, Key, Default) -> %% Fail in dev builds. %% It protects against passing something weird as a Module argument %% or against wrong argument order. ?ASSERT_MODULE(Module), - ModuleOpts = get_module_opts(HostType, Module), - get_opt(Opt, ModuleOpts, Default). + mongoose_config:get_opt(config_path(HostType, Module, Key), Default). -spec get_module_opt(mongooseim:host_type(), module(), opt_key() | key_path()) -> opt_value(). -get_module_opt(HostType, Module, Opt) -> - ?ASSERT_MODULE(Module), - ModuleOpts = get_loaded_module_opts(HostType, Module), - get_opt(Opt, ModuleOpts). +get_module_opt(HostType, Module, Key) -> + mongoose_config:get_opt(config_path(HostType, Module, Key)). + +-spec config_path(mongooseim:host_type(), module(), opt_key() | key_path()) -> key_path(). +config_path(HostType, Module, Path) when is_list(Path) -> + [{modules, HostType}, Module] ++ Path; +config_path(HostType, Module, Key) when is_atom(Key) -> + [{modules, HostType}, Module, Key]. -spec get_module_opts(mongooseim:host_type(), module()) -> module_opts(). get_module_opts(HostType, Module) -> - mongoose_config:get_opt([{modules, HostType}, Module], []). + ?ASSERT_MODULE(Module), + mongoose_config:get_opt([{modules, HostType}, Module], #{}). -spec get_loaded_module_opts(mongooseim:host_type(), module()) -> module_opts(). get_loaded_module_opts(HostType, Module) -> @@ -357,10 +350,7 @@ is_loaded(HostType, Module) -> -spec get_deps(host_type(), module(), module_opts()) -> gen_mod_deps:module_deps(). get_deps(HostType, Module, Opts) -> - %% the module has to be loaded, - %% otherwise the erlang:function_exported/3 returns false - code:ensure_loaded(Module), - case erlang:function_exported(Module, deps, 2) of + case backend_module:is_exported(Module, deps, 2) of true -> Deps = Module:deps(HostType, Opts), lists:filter(fun(D) -> element(1, D) =/= service end, Deps); @@ -370,10 +360,7 @@ get_deps(HostType, Module, Opts) -> -spec get_required_services(host_type(), module(), module_opts()) -> [mongoose_service:service()]. get_required_services(HostType, Module, Options) -> - %% the module has to be loaded, - %% otherwise the erlang:function_exported/3 returns false - code:ensure_loaded(Module), - case erlang:function_exported(Module, deps, 2) of + case backend_module:is_exported(Module, deps, 2) of true -> [Service || {service, Service} <- Module:deps(HostType, Options)]; _ -> diff --git a/src/gen_mod_deps.erl b/src/gen_mod_deps.erl index 50ded6a3a29..229770f79aa 100644 --- a/src/gen_mod_deps.erl +++ b/src/gen_mod_deps.erl @@ -111,10 +111,6 @@ resolve_deps(HostType, [{Module, Opts} | ModuleQueue], OptionalMods, KnownModule %% Merges module opts prioritizing the new ones, and warns on overrides. %% @end -spec merge_opts(module(), module_opts(), module_opts()) -> module_opts(). -merge_opts(Module, PreviousOpts, Opts) when is_list(PreviousOpts), is_list(Opts) -> - %% Temporary clause, should be removed when all modules support maps - maps:to_list(merge_opts(Module, maps:from_list(proplists:unfold(PreviousOpts)), - maps:from_list(proplists:unfold(Opts)))); merge_opts(Module, PreviousOpts, Opts) when is_map(PreviousOpts), is_map(Opts) -> case changed_opts(PreviousOpts, Opts) of [] -> diff --git a/src/inbox/mod_inbox.erl b/src/inbox/mod_inbox.erl index 038cbad8311..c740159afce 100644 --- a/src/inbox/mod_inbox.erl +++ b/src/inbox/mod_inbox.erl @@ -562,9 +562,9 @@ hooks(HostType) -> get_groupchat_types(HostType) -> gen_mod:get_module_opt(HostType, ?MODULE, groupchat). +-spec config_metrics(mongooseim:host_type()) -> [{gen_mod:opt_key(), gen_mod:opt_value()}]. config_metrics(HostType) -> - OptsToReport = [{backend, rdbms}], %list of tuples {option, defualt_value} - mongoose_module_metrics:opts_for_module(HostType, ?MODULE, OptsToReport). + mongoose_module_metrics:opts_for_module(HostType, ?MODULE, [backend]). -spec muclight_enabled(HostType :: mongooseim:host_type()) -> boolean(). muclight_enabled(HostType) -> diff --git a/src/mam/mod_mam.erl b/src/mam/mod_mam.erl index 1c57ab3eeda..79112663a83 100644 --- a/src/mam/mod_mam.erl +++ b/src/mam/mod_mam.erl @@ -206,15 +206,15 @@ archive_id(Server, User) %% gen_mod callbacks %% Starting and stopping functions for users' archives --spec start(HostType :: host_type(), Opts :: list()) -> any(). +-spec start(host_type(), gen_mod:module_opts()) -> any(). start(HostType, Opts) -> ?LOG_INFO(#{what => mam_starting, host_type => HostType}), ensure_metrics(HostType), ejabberd_hooks:add(hooks(HostType)), - add_id_handlers(HostType, Opts), + add_iq_handlers(HostType, Opts), ok. --spec stop(HostType :: host_type()) -> any(). +-spec stop(host_type()) -> any(). stop(HostType) -> ?LOG_INFO(#{what => mam_stopping, host_type => HostType}), ejabberd_hooks:delete(hooks(HostType)), @@ -747,7 +747,7 @@ hooks(HostType) -> {get_personal_data, HostType, ?MODULE, get_personal_data, 50} | mongoose_metrics_mam_hooks:get_mam_hooks(HostType)]. -add_id_handlers(HostType, Opts) -> +add_iq_handlers(HostType, Opts) -> Component = ejabberd_sm, %% `parallel' is the only one recommended here. ExecutionType = gen_mod:get_opt(iqdisc, Opts, parallel), diff --git a/src/mam/mod_mam_meta.erl b/src/mam/mod_mam_meta.erl index 3830ce8dcf2..1007983c765 100644 --- a/src/mam/mod_mam_meta.erl +++ b/src/mam/mod_mam_meta.erl @@ -35,12 +35,12 @@ supported_features() -> [dynamic_domains]. --spec start(Host :: jid:server(), Opts :: list()) -> any(). -start(_Host, _Opts) -> +-spec start(mongooseim:host_type(), module_opts()) -> any(). +start(_HostType, _Opts) -> ok. --spec stop(Host :: jid:server()) -> any(). -stop(_Host) -> +-spec stop(mongooseim:host_type()) -> any(). +stop(_HostType) -> ok. -spec config_spec() -> mongoose_config_spec:config_section(). diff --git a/src/mam/mod_mam_muc.erl b/src/mam/mod_mam_muc.erl index 59c16ada8c6..72ba5989f20 100644 --- a/src/mam/mod_mam_muc.erl +++ b/src/mam/mod_mam_muc.erl @@ -147,7 +147,7 @@ archive_id(MucHost, RoomName) when is_binary(MucHost), is_binary(RoomName) -> %% gen_mod callbacks %% Starting and stopping functions for MUC archives --spec start(HostType :: host_type(), Opts :: list()) -> any(). +-spec start(host_type(), gen_mod:module_opts()) -> any(). start(HostType, Opts) -> ?LOG_DEBUG(#{what => mam_muc_starting}), ensure_metrics(HostType), @@ -155,7 +155,7 @@ start(HostType, Opts) -> add_iq_handlers(HostType, Opts), ok. --spec stop(HostType :: host_type()) -> any(). +-spec stop(host_type()) -> any(). stop(HostType) -> ?LOG_DEBUG(#{what => mam_muc_stopping}), ejabberd_hooks:delete(hooks(HostType)), diff --git a/src/mam/mod_mam_muc_rdbms_arch.erl b/src/mam/mod_mam_muc_rdbms_arch.erl index bf035b60613..9114fc63d32 100644 --- a/src/mam/mod_mam_muc_rdbms_arch.erl +++ b/src/mam/mod_mam_muc_rdbms_arch.erl @@ -327,13 +327,17 @@ remove_domain_trans(HostType, MucHost) -> mongoose_rdbms:execute_successfully(HostType, mam_muc_remove_domain_users, [MucHost]). get_subhosts(HostType, Domain) -> - MucHostPattern = gen_mod:get_module_opt(HostType, mod_muc, host, - mod_muc:default_host()), - LightHostPattern = gen_mod:get_module_opt(HostType, mod_muc_light, host, - mod_muc_light:default_host()), - MucHost = mongoose_subdomain_utils:get_fqdn(MucHostPattern, Domain), - LightHost = mongoose_subdomain_utils:get_fqdn(LightHostPattern, Domain), - lists:usort([MucHost, LightHost]). + lists:usort( + lists:flatmap(fun(Module) -> get_subhosts_for_module(HostType, Domain, Module) end, + [mod_muc, mod_muc_light])). + +get_subhosts_for_module(HostType, Domain, Module) -> + case gen_mod:get_module_opts(HostType, Module) of + #{host := HostPattern} -> + [mongoose_subdomain_utils:get_fqdn(HostPattern, Domain)]; + #{} -> + [] + end. %% GDPR logic extract_gdpr_messages(HostType, SenderID) -> diff --git a/src/mod_caps.erl b/src/mod_caps.erl index 7a934c8d280..32148ae7f9b 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -93,13 +93,13 @@ -type state() :: #state{}. --spec start_link(mongooseim:host_type(), list()) -> any(). +-spec start_link(mongooseim:host_type(), gen_mod:module_opts()) -> any(). start_link(HostType, Opts) -> Proc = gen_mod:get_module_proc(HostType, ?PROCNAME), gen_server:start_link({local, Proc}, ?MODULE, [HostType, Opts], []). --spec start(mongooseim:host_type(), list()) -> any(). +-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> any(). start(HostType, Opts) -> Proc = gen_mod:get_module_proc(HostType, ?PROCNAME), ChildSpec = {Proc, {?MODULE, start_link, [HostType, Opts]}, diff --git a/src/mod_dynamic_domains_test.erl b/src/mod_dynamic_domains_test.erl index cd23060db41..b366d80bd56 100644 --- a/src/mod_dynamic_domains_test.erl +++ b/src/mod_dynamic_domains_test.erl @@ -13,26 +13,24 @@ -ignore_xref([config_spec/0, process_packet/5, start/2, stop/1, supported_features/0]). --define(DUMMY_NAMESPACE, <<"dummy.namespace">>). - -spec config_spec() -> mongoose_config_spec:config_section(). config_spec() -> - #section{items = #{ - <<"host1">> => - #option{type = string, - validate = subdomain_template, - process = fun mongoose_subdomain_utils:make_subdomain_pattern/1}, - <<"host2">> => - #option{type = string, - validate = subdomain_template, - process = fun mongoose_subdomain_utils:make_subdomain_pattern/1}, - <<"namespace">> => - #option{type = binary, - validate = non_empty}}}. + #section{items = #{<<"host1">> => + #option{type = string, + validate = subdomain_template, + process = fun mongoose_subdomain_utils:make_subdomain_pattern/1}, + <<"host2">> => + #option{type = string, + validate = subdomain_template, + process = fun mongoose_subdomain_utils:make_subdomain_pattern/1}, + <<"namespace">> => + #option{type = binary, + validate = non_empty}}, + format_items = map}. supported_features() -> [dynamic_domains]. --spec start(Host :: jid:server(), Opts :: list()) -> ok. +-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok. start(HostType, Opts) -> Namespace = gen_mod:get_opt(namespace, Opts), @@ -70,7 +68,7 @@ start(HostType, Opts) -> one_queue), ok. --spec stop(Host :: jid:server()) -> ok. +-spec stop(mongooseim:host_type()) -> ok. stop(HostType) -> Opts = gen_mod:get_module_opts(HostType, ?MODULE), Namespace = gen_mod:get_opt(namespace, Opts), diff --git a/src/mod_private_riak.erl b/src/mod_private_riak.erl index e53e3568830..ee524156d50 100644 --- a/src/mod_private_riak.erl +++ b/src/mod_private_riak.erl @@ -27,7 +27,7 @@ -include("jlib.hrl"). --spec init(mongooseim:host_type(), list()) -> ok. +-spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. init(_HostType, _Opts) -> ok. diff --git a/src/mod_register.erl b/src/mod_register.erl index f46bca3422a..e289320497a 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -372,10 +372,10 @@ verify_password_and_register(HostType, #jid{} = JID, Password, SourceRaw, Lang) end. send_welcome_message(HostType, #jid{lserver = Server} = JID) -> - case gen_mod:get_module_opt(HostType, ?MODULE, welcome_message, undefined) of - undefined -> + case gen_mod:lookup_module_opt(HostType, ?MODULE, welcome_message) of + {error, not_found} -> ok; - {Subj, Body} -> + {ok, {Subj, Body}} -> ejabberd_router:route( jid:make_noprep(<<>>, Server, <<>>), JID, diff --git a/src/mod_websockets.erl b/src/mod_websockets.erl index 7a22099f589..73cc4d5af6e 100644 --- a/src/mod_websockets.erl +++ b/src/mod_websockets.erl @@ -68,7 +68,7 @@ init(Req, Opts) -> Req1 = add_sec_websocket_protocol_header(Req), ?LOG_DEBUG(#{what => ws_init, text => <<"New websockets request">>, req => Req, opts => Opts}), - Timeout = gen_mod:get_opt(timeout, Opts, 60000), + Timeout = proplists:get_value(timeout, Opts, 60000), AllModOpts = [{peer, Peer}, {peercert, PeerCert} | Opts], %% upgrade protocol @@ -83,10 +83,10 @@ terminate(_Reason, _Req, _State) -> % Called for every new websocket connection. websocket_init(Opts) -> - PingRate = gen_mod:get_opt(ping_rate, Opts, none), - MaxStanzaSize = gen_mod:get_opt(max_stanza_size, Opts, infinity), - Peer = gen_mod:get_opt(peer, Opts), - PeerCert = gen_mod:get_opt(peercert, Opts), + PingRate = proplists:get_value(ping_rate, Opts, none), + MaxStanzaSize = proplists:get_value(max_stanza_size, Opts, infinity), + Peer = proplists:get_value(peer, Opts), + PeerCert = proplists:get_value(peercert, Opts), maybe_send_ping_request(PingRate), ?LOG_DEBUG(#{what => ws_init, text => <<"New websockets connection">>, peer => Peer, opts => Opts}), @@ -197,7 +197,7 @@ maybe_start_fsm([#xmlstreamstart{ name = <<"stream", _/binary>>, attrs = Attrs} #ws_state{fsm_pid = undefined, opts = Opts}=State) -> case lists:keyfind(<<"xmlns">>, 1, Attrs) of {<<"xmlns">>, ?NS_COMPONENT} -> - ServiceOpts = gen_mod:get_opt(ejabberd_service, Opts, []), + ServiceOpts = proplists:get_value(ejabberd_service, Opts, []), do_start_fsm(ejabberd_service, ServiceOpts, State); _ -> {stop, State} diff --git a/src/mongoose_api.erl b/src/mongoose_api.erl index 634c21dad94..bb49357cca1 100644 --- a/src/mongoose_api.erl +++ b/src/mongoose_api.erl @@ -58,7 +58,7 @@ %% ejabberd_cowboy callbacks %%-------------------------------------------------------------------- cowboy_router_paths(Base, Opts) -> - Handlers = gen_mod:get_opt(handlers, Opts, []), + Handlers = proplists:get_value(handlers, Opts, []), lists:flatmap(pa:bind(fun register_handler/2, Base), Handlers). register_handler(Base, Handler) -> diff --git a/src/mongoose_backend.erl b/src/mongoose_backend.erl index aa2afdfb0ff..ee0b9682b13 100644 --- a/src/mongoose_backend.erl +++ b/src/mongoose_backend.erl @@ -25,10 +25,10 @@ -spec init(HostType :: host_type_or_global(), MainModule :: main_module(), TrackedFuns :: [function_name()], - Opts :: gen_mod:module_opts()) -> ok. + Opts :: map()) -> ok. init(HostType, MainModule, TrackedFuns, Opts) -> ensure_backend_metrics(MainModule, TrackedFuns), - Backend = gen_mod:get_opt(backend, Opts, mnesia), + Backend = maps:get(backend, Opts, mnesia), BackendModule = backend_module(MainModule, Backend), persist_backend_name(HostType, MainModule, Backend, BackendModule), ok. diff --git a/src/mongoose_modules.erl b/src/mongoose_modules.erl index be1a4a7a3e6..12c84ad175f 100644 --- a/src/mongoose_modules.erl +++ b/src/mongoose_modules.erl @@ -67,8 +67,7 @@ ensure_stopped(HostType, Module) -> %% @doc Make sure the module is running with the provided options. -spec ensure_started(mongooseim:host_type(), module(), module_opts()) -> already_started | {started, term()} | {restarted, module_opts(), term()}. -ensure_started(HostType, Module, RawOpts) -> - Opts = mongoose_config_parser:unfold_opts(RawOpts), +ensure_started(HostType, Module, Opts) -> Modules = get_modules(HostType), case maps:find(Module, Modules) of error -> diff --git a/src/mongoose_service.erl b/src/mongoose_service.erl index c00a1ff784c..1a7cafcbc96 100644 --- a/src/mongoose_service.erl +++ b/src/mongoose_service.erl @@ -37,8 +37,7 @@ -type service() :: module(). -type opt_key() :: atom(). -type opt_value() :: mongoose_config:value(). --type options() :: [{opt_key(), opt_value()}] % deprecated, will be removed - | #{opt_key() => opt_value()}. % recommended +-type options() :: #{opt_key() => opt_value()}. -type start_result() :: any(). -type service_list() :: [{service(), options()}]. -type service_map() :: #{service() => options()}. diff --git a/src/muc_light/mod_muc_light.erl b/src/muc_light/mod_muc_light.erl index beaf28821ec..594e8d30e67 100644 --- a/src/muc_light/mod_muc_light.erl +++ b/src/muc_light/mod_muc_light.erl @@ -24,7 +24,6 @@ -behaviour(mongoose_module_metrics). %% API --export([default_host/0]). -export([server_host_to_muc_host/2]). -export([config_schema/1]). @@ -171,7 +170,7 @@ delete_room({_, RoomS} = RoomUS) -> start(HostType, Opts) -> Codec = host_type_to_codec(HostType), mod_muc_light_db_backend:start(HostType, Opts), - mod_muc_light_codec_backend:start(HostType, [{backend, Codec}]), + mod_muc_light_codec_backend:start(HostType, #{backend => Codec}), ejabberd_hooks:add(hooks(HostType)), %% Handler SubdomainPattern = subdomain_pattern(HostType), diff --git a/src/offline/mod_offline.erl b/src/offline/mod_offline.erl index 2d984c8b1c9..3f4ecf274c9 100644 --- a/src/offline/mod_offline.erl +++ b/src/offline/mod_offline.erl @@ -164,7 +164,7 @@ hooks(HostType) -> {failed_to_store_message, HostType, ?MODULE, amp_failed_event, 30}, {get_personal_data, HostType, ?MODULE, get_personal_data, 50} ], - case gen_mod:get_module_opt(HostType, ?MODULE, store_groupchat_messages, false) of + case gen_mod:get_module_opt(HostType, ?MODULE, store_groupchat_messages) of true -> GroupChatHook = {offline_groupchat_message_hook, HostType, ?MODULE, inspect_packet, 50}, diff --git a/src/pubsub/mod_pubsub.erl b/src/pubsub/mod_pubsub.erl index af01edccea4..15c9725ad3c 100644 --- a/src/pubsub/mod_pubsub.erl +++ b/src/pubsub/mod_pubsub.erl @@ -400,11 +400,10 @@ init([ServerHost, Opts = #{host := SubdomainPattern}]) -> PacketHandler = mongoose_packet_handler:new(?MODULE, #{state => State}), %% TODO: Conversion of this module is not done, it doesn't support dynamic %% domains yet. Only subdomain registration is done properly. - SubdomainPattern = gen_mod:get_module_opt(ServerHost, ?MODULE, host, default_host()), mongoose_domain_api:register_subdomain(ServerHost, SubdomainPattern, PacketHandler), {ok, State}. -init_backend(ServerHost, Opts) -> +init_backend(ServerHost, Opts = #{backend := Backend}) -> TrackedDBFuns = [create_node, del_node, get_state, get_states, get_states_by_lus, get_states_by_bare, get_states_by_full, get_own_nodes_states, @@ -414,7 +413,7 @@ init_backend(ServerHost, Opts) -> find_node_by_name, delete_node, get_subnodes, get_subnodes_tree, get_parentnodes_tree ], - gen_mod:start_backend_module(mod_pubsub_db, Opts, TrackedDBFuns), + backend_module:create(mod_pubsub_db, Backend, TrackedDBFuns), mod_pubsub_db_backend:start(), maybe_start_cache_module(ServerHost, Opts). @@ -488,11 +487,10 @@ init_send_loop(ServerHost, #{last_item_cache := LastItemCache, max_items_node := %%

The modules are initialized in alphabetical order and the list is checked %% and sorted to ensure that each module is initialized only once.

%%

See {@link node_hometree:init/1} for an example implementation.

-init_plugins(Host, ServerHost, Opts = #{nodetree := TreePlugin}) -> +init_plugins(Host, ServerHost, Opts = #{nodetree := TreePlugin, plugins := Plugins}) -> {ok, HostType} = mongoose_domain_api:get_host_type(ServerHost), ?LOG_DEBUG(#{what => pubsub_tree_plugin, tree_plugin => TreePlugin}), gen_pubsub_nodetree:init(TreePlugin, HostType, Opts), - Plugins = gen_mod:get_opt(plugins, Opts), PluginsOK = lists:foldl(pa:bind(fun init_plugin/5, Host, ServerHost, Opts), [], Plugins), lists:reverse(PluginsOK). @@ -3560,7 +3558,7 @@ get_node_subs(#pubsub_node{type = Type, id = Nidx}) -> %% Execute broadcasting step in a new process %% F contains one or more broadcast_stanza calls, executed sequentially broadcast_step(Host, F) -> - case gen_mod:get_module_opt(Host, ?MODULE, sync_broadcast, false) of + case gen_mod:get_module_opt(serverhost(Host), ?MODULE, sync_broadcast) of true -> F(); false -> @@ -4047,28 +4045,20 @@ get_max_items_node(Host) -> get_max_subscriptions_node({_, ServerHost, _}) -> get_max_subscriptions_node(ServerHost); get_max_subscriptions_node(Host) -> - config(serverhost(Host), max_subscriptions_node, undefined). + config(serverhost(Host), max_subscriptions_node). %%%% last item cache handling -maybe_start_cache_module(ServerHost, Opts) -> - case gen_mod:get_opt(last_item_cache, Opts, false) of - false -> - ok; - _Backend -> - mod_pubsub_cache_backend:start(ServerHost, Opts) +maybe_start_cache_module(ServerHost, #{last_item_cache := Cache} = Opts) -> + case Cache of + false -> ok; + _Backend -> mod_pubsub_cache_backend:start(ServerHost, Opts) end. - is_last_item_cache_enabled(Host) -> - case cache_backend(Host) of - false -> - false; - _ -> - true - end. + cache_backend(Host) =/= false. cache_backend(Host) -> - gen_mod:get_module_opt(serverhost(Host), mod_pubsub, last_item_cache, false). + gen_mod:get_module_opt(serverhost(Host), mod_pubsub, last_item_cache). set_cached_item({_, ServerHost, _}, Nidx, ItemId, Publisher, Payload) -> set_cached_item(ServerHost, Nidx, ItemId, Publisher, Payload); @@ -4108,7 +4098,7 @@ host(HostType, ServerHost) -> serverhost({_U, Server, _R})-> Server; serverhost(Host) -> - case config(Host, host, undefined) of + case config(Host, host) of undefined -> [_, ServerHost] = binary:split(Host, <<".">>), ServerHost; diff --git a/src/system_metrics/mongoose_module_metrics.erl b/src/system_metrics/mongoose_module_metrics.erl index 9294d2d3a53..e1ce5112ea1 100644 --- a/src/system_metrics/mongoose_module_metrics.erl +++ b/src/system_metrics/mongoose_module_metrics.erl @@ -8,7 +8,8 @@ -optional_callbacks([config_metrics/1]). --spec opts_for_module(mongooseim:host_type(), module(), list()) -> list(). +-spec opts_for_module(mongooseim:host_type(), module(), [gen_mod:opt_key()]) -> + [{gen_mod:opt_key(), gen_mod:opt_value()}]. opts_for_module(HostType, Module, OptsToReport) -> try Opts = gen_mod:get_module_opts(HostType, Module), @@ -17,8 +18,5 @@ opts_for_module(HostType, Module, OptsToReport) -> _:_ -> [{none, none}] end. -get_opt({Opt, DefaultValue}, Opts) -> - % Deprecated, defaults should be specified in the config spec - {Opt, gen_mod:get_opt(Opt, Opts, DefaultValue)}; get_opt(Opt, Opts) -> {Opt, gen_mod:get_opt(Opt, Opts)}. diff --git a/src/wpool/mongoose_wpool_rdbms.erl b/src/wpool/mongoose_wpool_rdbms.erl index 9811ff66f08..aff2b22d476 100644 --- a/src/wpool/mongoose_wpool_rdbms.erl +++ b/src/wpool/mongoose_wpool_rdbms.erl @@ -35,8 +35,7 @@ stop(_, _) -> do_start(HostType, Tag, WpoolOpts0, RdbmsOpts) when is_list(WpoolOpts0) and is_map(RdbmsOpts) -> BackendName = backend_name(RdbmsOpts), KVRdbmsOpts = maps:to_list(RdbmsOpts), - BackendOpts = KVRdbmsOpts ++ [{backend, BackendName}], - mongoose_backend:init(global, mongoose_rdbms, [query, execute], BackendOpts), + mongoose_backend:init(global, mongoose_rdbms, [query, execute], #{backend => BackendName}), mongoose_metrics:ensure_db_pool_metric({rdbms, HostType, Tag}), WpoolOpts = make_wpool_opts(WpoolOpts0, KVRdbmsOpts), diff --git a/test/common/config_parser_helper.erl b/test/common/config_parser_helper.erl index ecbe52f542b..3fc7748efec 100644 --- a/test/common/config_parser_helper.erl +++ b/test/common/config_parser_helper.erl @@ -24,7 +24,7 @@ options("host_types") -> {services, #{service_domain_db => config([services, service_domain_db], #{event_cleaning_interval => 1000, event_max_age => 5000})}}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{s2s, <<"another host type">>}, default_s2s()}, {{s2s, <<"localhost">>}, default_s2s()}, {{s2s, <<"some host type">>}, default_s2s()}, @@ -46,7 +46,7 @@ options("host_types") -> {{modules, <<"localhost">>}, #{mod_vcard => default_mod_config(mod_vcard)}}, {{modules, <<"some host type">>}, #{}}, {{modules, <<"this is host type">>}, #{}}, - {{modules, <<"yet another host type">>}, #{mod_amp => []}}, + {{modules, <<"yet another host type">>}, #{mod_amp => #{}}}, {{replaced_wait_timeout, <<"another host type">>}, 2000}, {{replaced_wait_timeout, <<"localhost">>}, 2000}, {{replaced_wait_timeout, <<"some host type">>}, 2000}, @@ -88,7 +88,7 @@ options("miscellaneous") -> tracking_id => "UA-123456789"}}}, {{s2s, <<"anonymous.localhost">>}, default_s2s()}, {{s2s, <<"localhost">>}, default_s2s()}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{auth, <<"anonymous.localhost">>}, custom_auth()}, {{auth, <<"localhost">>}, custom_auth()}, {{modules, <<"anonymous.localhost">>}, #{}}, @@ -113,7 +113,7 @@ options("modules") -> {services, #{}}, {{s2s, <<"dummy_host">>}, default_s2s()}, {{s2s, <<"localhost">>}, default_s2s()}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{auth, <<"dummy_host">>}, default_auth()}, {{auth, <<"localhost">>}, default_auth()}, {{modules, <<"dummy_host">>}, all_modules()}, @@ -253,7 +253,7 @@ options("mongooseim-pgsql") -> service_mongoose_system_metrics => #{initial_report => 300000, periodic_report => 10800000}}}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{auth, <<"anonymous.localhost">>}, (default_auth())#{anonymous => #{allow_multiple_connections => true, protocol => both}, @@ -359,7 +359,7 @@ options("outgoing_pools") -> {{s2s, <<"anonymous.localhost">>}, default_s2s()}, {{s2s, <<"localhost">>}, default_s2s()}, {{s2s, <<"localhost.bis">>}, default_s2s()}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{auth, <<"anonymous.localhost">>}, default_auth()}, {{auth, <<"localhost">>}, default_auth()}, {{auth, <<"localhost.bis">>}, default_auth()}, @@ -383,7 +383,7 @@ options("s2s_only") -> {registration_timeout, 600}, {routing_modules, mongoose_router:default_routing_modules()}, {services, #{}}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{auth, <<"dummy_host">>}, default_auth()}, {{auth, <<"localhost">>}, default_auth()}, {{modules, <<"dummy_host">>}, #{}}, @@ -629,7 +629,8 @@ custom_mod_event_pusher_http() -> pool_name => http_pool}]}. custom_mod_event_pusher_push() -> - #{backend => mnesia, + #{iqdisc => one_queue, + backend => mnesia, plugin_module => mod_event_pusher_push_plugin_defaults, virtual_pubsub_hosts => [{fqdn,<<"host1">>},{fqdn,<<"host2">>}], @@ -665,12 +666,12 @@ custom_mod_event_pusher_sns() -> pgsql_modules() -> #{mod_adhoc => default_mod_config(mod_adhoc), - mod_amp => [], mod_blocking => default_mod_config(mod_blocking), + mod_amp => #{}, mod_blocking => default_mod_config(mod_blocking), mod_bosh => default_mod_config(mod_bosh), - mod_carboncopy => default_mod_config(mod_carboncopy), mod_commands => [], + mod_carboncopy => default_mod_config(mod_carboncopy), mod_commands => #{}, mod_disco => mod_config(mod_disco, #{users_can_see_hidden_services => false}), mod_last => mod_config(mod_last, #{backend => rdbms}), - mod_muc_commands => [], mod_muc_light_commands => [], + mod_muc_commands => #{}, mod_muc_light_commands => #{}, mod_offline => mod_config(mod_offline, #{backend => rdbms}), mod_privacy => mod_config(mod_privacy, #{backend => rdbms}), mod_private => default_mod_config(mod_private), @@ -1049,7 +1050,8 @@ default_config([modules, M]) -> default_config([modules, mod_event_pusher, http]) -> #{handlers => []}; default_config([modules, mod_event_pusher, push]) -> - #{backend => mnesia, + #{iqdisc => one_queue, + backend => mnesia, wpool => default_config([modules, mod_event_pusher, push, wpool]), plugin_module => mod_event_pusher_push_plugin_defaults, virtual_pubsub_hosts => []}; diff --git a/test/config_parser_SUITE.erl b/test/config_parser_SUITE.erl index 6ecbca6c7da..3340c2e3fc8 100644 --- a/test/config_parser_SUITE.erl +++ b/test/config_parser_SUITE.erl @@ -316,8 +316,8 @@ supported_features(_Config) -> ?cfg([{auth, <<"type1">>}, methods], [internal], maps:merge(Gen, Auth)), ?cfg([{auth, <<"type1">>}, methods], [internal], Gen#{<<"host_config">> => [Auth#{<<"host_type">> => <<"type1">>}]}), - ?cfg([{modules, <<"type1">>}, mod_amp], [], maps:merge(Gen, Mod)), - ?cfg([{modules, <<"type1">>}, mod_amp], [], + ?cfg([{modules, <<"type1">>}, mod_amp], #{}, maps:merge(Gen, Mod)), + ?cfg([{modules, <<"type1">>}, mod_amp], #{}, Gen#{<<"host_config">> => [Mod#{<<"host_type">> => <<"type1">>}]}). unsupported_features(_Config) -> @@ -408,9 +408,9 @@ all_metrics_are_global(_Config) -> ?err(#{<<"general">> => #{<<"all_metrics_are_global">> => <<"true">>}}). sm_backend(_Config) -> - ?cfg(sm_backend, {mnesia, []}, #{}), % default - ?cfg(sm_backend, {mnesia, []}, #{<<"general">> => #{<<"sm_backend">> => <<"mnesia">>}}), - ?cfg(sm_backend, {redis, []}, #{<<"general">> => #{<<"sm_backend">> => <<"redis">>}}), + ?cfg(sm_backend, mnesia, #{}), % default + ?cfg(sm_backend, mnesia, #{<<"general">> => #{<<"sm_backend">> => <<"mnesia">>}}), + ?cfg(sm_backend, redis, #{<<"general">> => #{<<"sm_backend">> => <<"redis">>}}), ?err(#{<<"general">> => #{<<"sm_backend">> => <<"amnesia">>}}). max_fsm_queue(_Config) -> @@ -1583,7 +1583,7 @@ s2s_max_retry_delay(_Config) -> mod_adhoc(_Config) -> check_module_defaults(mod_adhoc), - check_iqdisc_map(mod_adhoc), + check_iqdisc(mod_adhoc), P = [modules, mod_adhoc], T = fun(K, V) -> #{<<"modules">> => #{<<"mod_adhoc">> => #{K => V}}} end, %% report_commands_node is boolean @@ -1594,7 +1594,7 @@ mod_adhoc(_Config) -> mod_auth_token(_Config) -> check_module_defaults(mod_auth_token), - check_iqdisc_map(mod_auth_token), + check_iqdisc(mod_auth_token), P = [modules, mod_auth_token], T = fun(K, V) -> #{<<"modules">> => #{<<"mod_auth_token">> => #{K => V}}} end, ?cfgh(P ++ [backend], rdbms, T(<<"backend">>, <<"rdbms">>)), @@ -1661,7 +1661,7 @@ mod_cache_users(_Config) -> ?errh(T(<<"number_of_segments">>, <<"infinity">>)). mod_carboncopy(_Config) -> - check_iqdisc_map(mod_carboncopy). + check_iqdisc(mod_carboncopy). mod_csi(_Config) -> check_module_defaults(mod_csi), @@ -1673,7 +1673,7 @@ mod_csi(_Config) -> mod_disco(_Config) -> check_module_defaults(mod_disco), - check_iqdisc_map(mod_disco), + check_iqdisc(mod_disco), P = [modules, mod_disco], T = fun(K, V) -> #{<<"modules">> => #{<<"mod_disco">> => #{K => V}}} end, ?cfgh(P ++ [users_can_see_hidden_services], true, @@ -1710,7 +1710,7 @@ mod_disco(_Config) -> mod_extdisco(_Config) -> check_module_defaults(mod_extdisco), - check_iqdisc_map(mod_extdisco), + check_iqdisc(mod_extdisco), P = [modules, mod_extdisco, service], T = fun(Opts) -> #{<<"modules">> => #{<<"mod_extdisco">> => @@ -1734,7 +1734,7 @@ mod_extdisco(_Config) -> mod_inbox(_Config) -> check_module_defaults(mod_inbox), - check_iqdisc_map(mod_inbox), + check_iqdisc(mod_inbox), P = [modules, mod_inbox], T = fun(Opts) -> #{<<"modules">> => #{<<"mod_inbox">> => Opts}} end, ChatMarkers = [<<"displayed">>, <<"received">>, <<"acknowledged">>], @@ -1970,6 +1970,7 @@ mod_event_pusher_push(_Config) -> #{<<"mod_event_pusher">> => #{<<"push">> => Opts}}} end, ?cfgh(P, default_config(P), T(#{})), + check_iqdisc(P, T), test_wpool(P ++ [wpool], fun(Opts) -> T(#{<<"wpool">> => Opts}) end), ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})), ?cfgh(P ++ [plugin_module], mod_event_pusher_push_plugin_enhanced, @@ -2077,7 +2078,7 @@ mod_http_upload(_Config) -> ?errh(T(RequiredOpts#{<<"host">> => [<<"invalid.sub@HOST@">>]})), ?errh(T(RequiredOpts#{<<"host">> => [<<"invalid.sub.@HOST@.as.well">>]})), ?errh(T(RequiredOpts#{<<"host">> => [<<"not.supported.any.more.@HOSTS@">>]})), - check_iqdisc_map(mod_http_upload, RequiredOpts). + check_iqdisc(mod_http_upload, RequiredOpts). mod_http_upload_s3(_Config) -> T = fun(Opts) -> #{<<"modules">> => #{<<"mod_http_upload">> => @@ -2164,7 +2165,7 @@ mod_keystore_keys(_Config) -> <<"path">> => <<"priv/access_psk">>}])). mod_last(_Config) -> - check_iqdisc_map(mod_last), + check_iqdisc(mod_last), check_module_defaults(mod_last), T = fun(Opts) -> #{<<"modules">> => #{<<"mod_last">> => Opts}} end, P = [modules, mod_last], @@ -2577,7 +2578,7 @@ mod_offline_chatmarkers(_Config) -> mod_ping(_Config) -> T = fun(Opts) -> #{<<"modules">> => #{<<"mod_ping">> => Opts}} end, P = [modules, mod_ping], - check_iqdisc_map(mod_ping), + check_iqdisc(mod_ping), check_module_defaults(mod_ping), ?cfgh(P ++ [send_pings], true, T(#{<<"send_pings">> => true})), @@ -2619,7 +2620,7 @@ test_privacy_opts(Module) -> ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})). mod_private(_Config) -> - check_iqdisc_map(mod_private), + check_iqdisc(mod_private), check_module_defaults(mod_private), T = fun(Opts) -> #{<<"modules">> => #{<<"mod_private">> => Opts}} end, P = [modules, mod_private], @@ -2631,7 +2632,7 @@ mod_private(_Config) -> ?errh(T(#{<<"riak">> => #{<<"bucket_type">> => 1}})). mod_pubsub(_Config) -> - check_iqdisc_map(mod_pubsub), + check_iqdisc(mod_pubsub), check_module_defaults(mod_pubsub), T = fun(Opts) -> #{<<"modules">> => #{<<"mod_pubsub">> => Opts}} end, P = [modules, mod_pubsub], @@ -2757,7 +2758,7 @@ mod_push_service_mongoosepush(_Config) -> mod_register(_Config) -> check_module_defaults(mod_register), - check_iqdisc_map(mod_register), + check_iqdisc(mod_register), P = [modules, mod_register], ?cfgh(P ++ [access], register, ip_access_register(<<"127.0.0.1">>)), @@ -2828,7 +2829,7 @@ registration_watchers(JidBins) -> #{<<"modules">> => #{<<"mod_register">> => Opts}}. mod_roster(_Config) -> - check_iqdisc_map(mod_roster), + check_iqdisc(mod_roster), check_module_defaults(mod_roster), P = [modules, mod_roster], T = fun(Opts) -> #{<<"modules">> => #{<<"mod_roster">> => Opts}} end, @@ -2922,11 +2923,11 @@ mod_shared_roster_ldap(_Config) -> mod_sic(_Config) -> check_module_defaults(mod_sic), - check_iqdisc_map(mod_sic). + check_iqdisc(mod_sic). mod_smart_markers(_Config) -> check_module_defaults(mod_smart_markers), - check_iqdisc_map(mod_smart_markers), + check_iqdisc(mod_smart_markers), P = [modules, mod_smart_markers], T = fun(Opts) -> #{<<"modules">> => #{<<"mod_smart_markers">> => Opts}} end, ?cfgh(P ++ [backend], rdbms, T(#{<<"backend">> => <<"rdbms">>})), @@ -2966,12 +2967,12 @@ mod_stream_management_stale_h(_Config) -> ?errh(T(#{<<"geriatric">> => <<"one">>})). mod_time(_Config) -> - check_iqdisc_map(mod_time), + check_iqdisc(mod_time), check_module_defaults(mod_time). mod_vcard(_Config) -> check_module_defaults(mod_vcard), - check_iqdisc_map(mod_vcard), + check_iqdisc(mod_vcard), P = [modules, mod_vcard], T = fun(Opts) -> #{<<"modules">> => #{<<"mod_vcard">> => Opts}} end, ?cfgh(P ++ [iqdisc], one_queue, @@ -3088,14 +3089,14 @@ mod_vcard_ldap_search_reported(_Config) -> mod_version(_Config) -> check_module_defaults(mod_version), - check_iqdisc_map(mod_version), + check_iqdisc(mod_version), P = [modules, mod_version], T = fun(Opts) -> #{<<"modules">> => #{<<"mod_version">> => Opts}} end, ?cfgh(P ++ [os_info], true, T(#{<<"os_info">> => true})), ?errh(T(#{<<"os_info">> => 1})). modules_without_config(_Config) -> - ?cfgh(modopts(mod_amp, []), #{<<"modules">> => #{<<"mod_amp">> => #{}}}), + ?cfgh([modules, mod_amp], #{}, #{<<"modules">> => #{<<"mod_amp">> => #{}}}), ?errh(#{<<"modules">> => #{<<"mod_wrong">> => #{}}}). incorrect_module(_Config) -> @@ -3140,43 +3141,33 @@ service_mongoose_system_metrics(_Config) -> %% Helpers for module tests -iqdisc({queues, Workers}) -> #{<<"type">> => <<"queues">>, <<"workers">> => Workers}; -iqdisc(Atom) -> #{<<"type">> => atom_to_binary(Atom, utf8)}. - -iq_disc_generic(Module, RequiredOpts, Value) -> - Opts = RequiredOpts#{<<"iqdisc">> => Value}, - #{<<"modules">> => #{atom_to_binary(Module, utf8) => Opts}}. - check_iqdisc(Module) -> - check_iqdisc(Module, [], #{}). - -check_iqdisc(Module, ExpectedCfg, RequiredOpts) -> - ?cfgh(modopts(Module, ExpectedCfg ++ [{iqdisc, {queues, 10}}]), - iq_disc_generic(Module, RequiredOpts, iqdisc({queues, 10}))), - ?cfgh(modopts(Module, ExpectedCfg ++ [{iqdisc, parallel}]), - iq_disc_generic(Module, RequiredOpts, iqdisc(parallel))), - ?errh(iq_disc_generic(Module, RequiredOpts, iqdisc(bad_haha))). - -check_iqdisc_map(Module) -> - check_iqdisc_map(Module, #{}). + P = [modules, Module], + T = fun(Opts) -> #{<<"modules">> => #{atom_to_binary(Module) => Opts}} end, + check_iqdisc(P, T). -check_iqdisc_map(Module, RequiredOpts) -> - ?cfgh([modules, Module, iqdisc], {queues, 10}, - iq_disc_generic(Module, RequiredOpts, iqdisc({queues, 10}))), - ?cfgh([modules, Module, iqdisc], parallel, - iq_disc_generic(Module, RequiredOpts, iqdisc(parallel))), - ?errh(iq_disc_generic(Module, RequiredOpts, iqdisc(bad_haha))). +check_iqdisc(Module, RequiredOpts) when is_map(RequiredOpts) -> + P = [modules, Module], + T = fun(Opts) -> + #{<<"modules">> => #{atom_to_binary(Module) => maps:merge(RequiredOpts, Opts)}} + end, + check_iqdisc(P, T); +check_iqdisc(ParentP, ParentT) when is_function(ParentT, 1) -> + P = ParentP ++ [iqdisc], + T = fun(Opts) -> ParentT(#{<<"iqdisc">> => Opts}) end, + ?cfgh(P, {queues, 10}, T(#{<<"type">> => <<"queues">>, <<"workers">> => 10})), + ?cfgh(P, parallel, T(#{<<"type">> => <<"parallel">>})), + ?cfgh(P, one_queue, T(#{<<"type">> => <<"one_queue">>})), + ?cfgh(P, no_queue, T(#{<<"type">> => <<"no_queue">>})), + ?errh(T(#{<<"type">> => <<"one_queue_and_a_half">>})), + ?errh(T(#{<<"type">> => <<"queues">>, <<"workers">> => 0})), + ?errh(T(#{<<"type">> => <<"no_queue">>, <<"workers">> => 10})), + ?errh(T(#{<<"workers">> => 10})). check_module_defaults(Mod) -> ExpectedCfg = default_mod_config(Mod), ?cfgh([modules, Mod], ExpectedCfg, #{<<"modules">> => #{atom_to_binary(Mod) => #{}}}). -modopts(Mod, Opts) -> - [{[modules, Mod], Opts}]. - -servopts(Service, Opts) -> - [{[services, Service], Opts}]. - %% helpers for 'listen' tests listener_config(Mod, Opts) -> @@ -3331,8 +3322,6 @@ compare_nodes([listen], V1, V2) -> compare_unordered_lists(V1, V2, fun handle_listener/2); compare_nodes([outgoing_pools], V1, V2) -> compare_unordered_lists(V1, V2, fun handle_conn_pool/2); -compare_nodes([services], V1, V2) -> - compare_unordered_lists(V1, V2, fun handle_item_with_opts/2); compare_nodes([{auth_method, _}], V1, V2) when is_atom(V1) -> ?eq([V1], V2); compare_nodes([{s2s_addr, _}], {_, _, _, _} = IP1, IP2) -> @@ -3342,8 +3331,6 @@ compare_nodes(Node, V1, V2) when is_map(V1), is_map(V2) -> ?eq(K1, K2), compare_nodes(Node ++ [K1], MV1, MV2) end); -compare_nodes([{modules, _}, _Module], V1, V2) -> - compare_unordered_lists(V1, V2, fun handle_module_options/2); compare_nodes(Node, V1, V2) -> ?eq({Node, V1}, {Node, V2}). @@ -3408,14 +3395,6 @@ handle_db_server_opt({ssl_opts, O1}, {ssl_opts, O2}) -> compare_unordered_lists(O1, O2); handle_db_server_opt(V1, V2) -> ?eq(V1, V2). -handle_module_options({configs, [Configs1]}, {configs, [Configs2]}) -> - compare_unordered_lists(Configs1, Configs2, fun handle_module_options/2); -handle_module_options({Name, Opts = [{_, _}|_]}, {Name2, Opts2 = [{_, _}|_]}) -> - ?eq(Name, Name2), - compare_unordered_lists(Opts, Opts2, fun handle_module_options/2); -handle_module_options(V1, V2) -> - ?eq(V1, V2). - %% Generic assertions, use the 'F' handler for any custom cases compare_unordered_lists(L1, L2) when is_list(L1), is_list(L2) -> compare_unordered_lists(L1, L2, fun(V1, V2) -> ?eq(V1, V2) end). diff --git a/test/ejabberd_sm_SUITE.erl b/test/ejabberd_sm_SUITE.erl index 2ed05789c65..d357b309d06 100644 --- a/test/ejabberd_sm_SUITE.erl +++ b/test/ejabberd_sm_SUITE.erl @@ -608,10 +608,8 @@ opts(Config) -> {all_metrics_are_global, false}, {sm_backend, sm_backend(?config(backend, Config))}]. -sm_backend(ejabberd_sm_redis) -> - {redis, [{pool_size, 3}, {worker_config, [{host, "localhost"}, {port, 6379}]}]}; -sm_backend(ejabberd_sm_mnesia) -> - {mnesia, []}. +sm_backend(ejabberd_sm_redis) -> redis; +sm_backend(ejabberd_sm_mnesia) -> mnesia. set_meck() -> meck:expect(gen_hook, add_handler, fun(_, _, _, _, _) -> ok end), diff --git a/test/gen_mod_SUITE.erl b/test/gen_mod_SUITE.erl index 99665a3f23d..038a6067d8f 100644 --- a/test/gen_mod_SUITE.erl +++ b/test/gen_mod_SUITE.erl @@ -31,6 +31,8 @@ all() -> stop_error, loaded_modules, loaded_modules_with_opts, + get_module_opt, + lookup_module_opt, hosts_with_module, hosts_and_opts_with_module]. @@ -80,6 +82,18 @@ loaded_modules_with_opts(_Config) -> ?assertEqual(MB, gen_mod:loaded_modules_with_opts(host(b))), ?assertEqual(#{host(a) => MA, host(b) => MB}, gen_mod:loaded_modules_with_opts()). +get_module_opt(_Config) -> + ?assertEqual(v, gen_mod:get_module_opt(host(b), b_module, k)), + ?assertError({badkey, k}, gen_mod:get_module_opt(host(a), a_module, k)), + ?assertError({badkey, b_module}, gen_mod:get_module_opt(host(a), b_module, k)), + ?assertEqual(default, gen_mod:get_module_opt(host(a), a_module, k, default)), + ?assertEqual(default, gen_mod:get_module_opt(host(a), b_module, k, default)). + +lookup_module_opt(_Config) -> + ?assertEqual({ok, v}, gen_mod:lookup_module_opt(host(b), b_module, k)), + ?assertEqual({error, not_found}, gen_mod:lookup_module_opt(host(a), a_module, k)), + ?assertEqual({error, not_found}, gen_mod:lookup_module_opt(host(a), b_module, k)). + hosts_with_module(_Config) -> ?assertEqual([host(a)], gen_mod:hosts_with_module(a_module)), ?assertEqual([host(b)], gen_mod:hosts_with_module(b_module)). diff --git a/test/mongoose_config_SUITE.erl b/test/mongoose_config_SUITE.erl index 926e8bd25bc..c3e4b7be305 100644 --- a/test/mongoose_config_SUITE.erl +++ b/test/mongoose_config_SUITE.erl @@ -185,7 +185,7 @@ minimal_config_opts() -> {registration_timeout, 600}, {routing_modules, mongoose_router:default_routing_modules()}, {services, #{}}, - {sm_backend, {mnesia, []}}, + {sm_backend, mnesia}, {{auth, <<"localhost">>}, config_parser_helper:default_auth()}, {{modules, <<"localhost">>}, #{}}, {{replaced_wait_timeout, <<"localhost">>}, 2000}, diff --git a/test/mongoose_rdbms_SUITE.erl b/test/mongoose_rdbms_SUITE.erl index c875bffdc00..e513208426f 100644 --- a/test/mongoose_rdbms_SUITE.erl +++ b/test/mongoose_rdbms_SUITE.erl @@ -39,13 +39,13 @@ tests() -> init_per_group(odbc, Config) -> case code:ensure_loaded(eodbc) of {module, eodbc} -> - mongoose_backend:init(global, mongoose_rdbms, [], [{backend, odbc}]), + mongoose_backend:init(global, mongoose_rdbms, [], #{backend => odbc}), [{db_type, odbc} | Config]; _ -> {skip, no_odbc_application} end; init_per_group(Group, Config) -> - mongoose_backend:init(global, mongoose_rdbms, [], [{backend, Group}]), + mongoose_backend:init(global, mongoose_rdbms, [], #{backend => Group}), [{db_type, Group} | Config]. end_per_group(_, Config) ->