Skip to content

Commit

Permalink
Merge pull request #4211 from esl/mod-caps-for-rdbms
Browse files Browse the repository at this point in the history
Add mod_caps_rdbms
  • Loading branch information
NelsonVides authored Jan 16, 2024
2 parents 00072e0 + eba748b commit e8087b4
Show file tree
Hide file tree
Showing 22 changed files with 256 additions and 121 deletions.
6 changes: 3 additions & 3 deletions big_tests/tests/disco_and_caps_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
-include_lib("escalus/include/escalus_xmlns.hrl").

-import(domain_helper, [host_type/0, domain/0]).
-import(config_parser_helper, [default_mod_config/1, mod_config/2]).
-import(config_parser_helper, [default_mod_config/1, mod_config/2, mod_config_with_auto_backend/1]).

all() ->
[{group, disco_with_caps},
Expand Down Expand Up @@ -196,10 +196,10 @@ user_can_query_server_info(Config) ->
%% Helpers

required_modules(disco_with_caps) ->
[{mod_caps, config_parser_helper:default_mod_config(mod_caps)},
[{mod_caps, mod_config_with_auto_backend(mod_caps)},
{mod_disco, default_mod_config(mod_disco)}];
required_modules(disco_with_caps_and_extra_features) ->
[{mod_caps, config_parser_helper:default_mod_config(mod_caps)},
[{mod_caps, mod_config_with_auto_backend(mod_caps)},
{mod_disco, mod_config(mod_disco, extra_disco_opts())}];
required_modules(disco_with_extra_features) ->
[{mod_disco, mod_config(mod_disco, extra_disco_opts())}].
Expand Down
3 changes: 2 additions & 1 deletion big_tests/tests/gdpr_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ pubsub_required_modules(Plugins) ->
host => HostPattern,
nodetree => nodetree_tree,
plugins => Plugins}),
[{mod_caps, config_parser_helper:default_mod_config(mod_caps)}, {mod_pubsub, PubsubConfig}].
[{mod_caps, config_parser_helper:mod_config_with_auto_backend(mod_caps)},
{mod_pubsub, PubsubConfig}].

is_mim2_started() ->
#{node := Node} = distributed_helper:mim2(),
Expand Down
14 changes: 6 additions & 8 deletions big_tests/tests/graphql_offline_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-import(domain_helper, [host_type/0, domain/0]).
-import(graphql_helper, [execute_command/4, get_ok_value/2, get_err_code/1, user_to_bin/1,
get_unauthorized/1, get_not_loaded/1, get_coercion_err_msg/1]).
-import(config_parser_helper, [mod_config/2]).
-import(config_parser_helper, [mod_config_with_auto_backend/1]).
-import(mongooseimctl_helper, [mongooseimctl/3, rpc_call/3]).

-include_lib("eunit/include/eunit.hrl").
Expand Down Expand Up @@ -70,9 +70,9 @@ init_per_suite(Config) ->
Config2 = ejabberd_node_utils:init(mim(), Config1),
escalus:init_per_suite(Config2).

-spec create_config(atom()) -> [{mod_offline, gen_mod:module_opts()}].
create_config(Backend) ->
[{mod_offline, mod_config(mod_offline, #{backend => Backend})}].
-spec create_config() -> [{mod_offline, gen_mod:module_opts()}].
create_config() ->
[{mod_offline, mod_config_with_auto_backend(mod_offline)}].

end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
Expand All @@ -87,10 +87,8 @@ init_per_group(domain_admin, Config) ->
init_per_group(GroupName, Config) when GroupName =:= admin_offline;
GroupName =:= domain_admin_offline ->
HostType = host_type(),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
ModConfig = create_config(Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
[{backend, Backend} | escalus:init_per_suite(Config)];
dynamic_modules:ensure_modules(HostType, create_config()),
escalus:init_per_suite(Config);
init_per_group(admin_offline_not_configured, Config) ->
dynamic_modules:ensure_modules(host_type(), [{mod_offline, stopped}]),
Config;
Expand Down
13 changes: 6 additions & 7 deletions big_tests/tests/graphql_private_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-import(distributed_helper, [mim/0, require_rpc_nodes/1]).
-import(graphql_helper, [execute_user_command/5, execute_command/4, get_ok_value/2, get_err_code/1,
user_to_bin/1, get_unauthorized/1, get_not_loaded/1, get_coercion_err_msg/1]).
-import(config_parser_helper, [mod_config_with_auto_backend/2]).

-include_lib("eunit/include/eunit.hrl").
-include_lib("exml/include/exml.hrl").
Expand Down Expand Up @@ -67,11 +68,11 @@ init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Config2 = ejabberd_node_utils:init(mim(), Config1),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
escalus:init_per_suite([{backend, Backend} | Config2]).
escalus:init_per_suite(Config2).

create_config(Backend) ->
[{mod_private, #{backend => Backend, iqdisc => one_queue}}].
create_config() ->
[{mod_private,
mod_config_with_auto_backend(mod_private, #{iqdisc => one_queue})}].

end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
Expand All @@ -95,9 +96,7 @@ init_per_group(Group, Config) when Group =:= admin_private_not_configured;

ensure_private_started(Config) ->
HostType = domain_helper:host_type(),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
ModConfig = create_config(Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
dynamic_modules:ensure_modules(HostType, create_config()),
Config.

ensure_private_stopped(Config) ->
Expand Down
12 changes: 6 additions & 6 deletions big_tests/tests/last_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
-include_lib("escalus/include/escalus_xmlns.hrl").
-include_lib("exml/include/exml.hrl").

-import(config_parser_helper, [mod_config_with_auto_backend/2]).

%%--------------------------------------------------------------------
%% Suite configuration
%%--------------------------------------------------------------------
Expand All @@ -45,9 +47,8 @@ suite() ->
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
dynamic_modules:ensure_modules(HostType, required_modules(Backend)),
escalus:init_per_suite([{backend, Backend} | Config1]).
dynamic_modules:ensure_modules(HostType, required_modules()),
escalus:init_per_suite(Config1).

end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
Expand Down Expand Up @@ -190,6 +191,5 @@ answer_last_activity(IQ = #xmlel{name = <<"iq">>}) ->
{<<"seconds">>, <<"0">>}]}
]}.

required_modules(Backend) ->
[{mod_last, #{backend => Backend,
iqdisc => one_queue}}].
required_modules() ->
[{mod_last, mod_config_with_auto_backend(mod_last, #{iqdisc => one_queue})}].
11 changes: 4 additions & 7 deletions big_tests/tests/mod_blocking_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
-include_lib("eunit/include/eunit.hrl").
-include_lib("escalus/include/escalus_xmlns.hrl").

-import(config_parser_helper, [mod_config_with_auto_backend/1]).

-define(SLEEP_TIME, 50).

%%--------------------------------------------------------------------
Expand Down Expand Up @@ -99,14 +101,9 @@ suite() ->
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
ModConfig = [{mod_blocking, set_opts(Backend)}],
ModConfig = [{mod_blocking, mod_config_with_auto_backend(mod_blocking)}],
dynamic_modules:ensure_modules(HostType, ModConfig),
[{backend, Backend} |
escalus:init_per_suite(Config1)].

set_opts(Backend) ->
#{backend => Backend}.
escalus:init_per_suite(Config1).

end_per_suite(Config) ->
escalus_fresh:clean(),
Expand Down
11 changes: 5 additions & 6 deletions big_tests/tests/mod_event_pusher_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

-import(domain_helper, [host_type/0]).

-import(config_parser_helper, [config/2, mod_config/2, mod_event_pusher_http_handler/0]).
-import(config_parser_helper, [config/2, mod_config_with_auto_backend/1, mod_event_pusher_http_handler/0]).

%%%===================================================================
%%% Suite configuration
Expand Down Expand Up @@ -178,16 +178,15 @@ stop_pool() ->

set_modules(Config0, ExtraHandlerOpts) ->
Config = dynamic_modules:save_modules(host_type(), Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms(host_type()),
ModOffline = create_offline_config(Backend),
ModOffline = create_offline_config(),
Handler = maps:merge(mod_event_pusher_http_handler(), ExtraHandlerOpts),
ModOpts = #{http => #{handlers => [Handler]}},
dynamic_modules:ensure_modules(host_type(), [{mod_event_pusher, ModOpts} | ModOffline]),
Config.

-spec create_offline_config(atom()) -> [{mod_offline, gen_mod:module_opts()}].
create_offline_config(Backend) ->
[{mod_offline, mod_config(mod_offline, #{backend => Backend})}].
-spec create_offline_config() -> [{mod_offline, gen_mod:module_opts()}].
create_offline_config() ->
[{mod_offline, mod_config_with_auto_backend(mod_offline)}].

start_http_listener(simple_message, Prefix) ->
http_helper:start(http_notifications_port(), Prefix, fun process_notification/1);
Expand Down
17 changes: 7 additions & 10 deletions big_tests/tests/offline_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

-import(domain_helper, [host_type/0]).
-import(mongoose_helper, [wait_for_n_offline_messages/2]).
-import(config_parser_helper, [mod_config/2]).
-import(config_parser_helper, [mod_config/2, mod_config_with_auto_backend/1]).

%%%===================================================================
%%% Suite configuration
Expand Down Expand Up @@ -60,15 +60,12 @@ suite() ->
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
ModConfig = create_config(Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
[{backend, Backend} |
escalus:init_per_suite(Config1)].

-spec create_config(atom()) -> [{mod_offline, gen_mod:module_opts()}].
create_config(Backend) ->
[{mod_offline, mod_config(mod_offline, #{backend => Backend})}].
dynamic_modules:ensure_modules(HostType, create_config()),
escalus:init_per_suite(Config1).

-spec create_config() -> [{mod_offline, gen_mod:module_opts()}].
create_config() ->
[{mod_offline, mod_config_with_auto_backend(mod_offline)}].

end_per_suite(Config) ->
escalus_fresh:clean(),
Expand Down
5 changes: 3 additions & 2 deletions big_tests/tests/pep_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,15 @@ field_spec({Var, Value}) when is_list(Value) -> #{var => Var, values => Value};
field_spec({Var, Value}) -> #{var => Var, values => [Value]}.

required_modules() ->
[{mod_caps, config_parser_helper:default_mod_config(mod_caps)},
[{mod_caps, config_parser_helper:mod_config_with_auto_backend(mod_caps)},
{mod_pubsub, mod_config(mod_pubsub, #{plugins => [<<"dag">>, <<"pep">>],
nodetree => nodetree_dag,
backend => mongoose_helper:mnesia_or_rdbms_backend(),
pep_mapping => #{},
host => subhost_pattern("pubsub.@HOST@")})}].
required_modules(cache_tests) ->
[{mod_caps, config_parser_helper:default_mod_config(mod_caps)},
HostType = domain_helper:host_type(),
[{mod_caps, config_parser_helper:mod_config_with_auto_backend(mod_caps)},
{mod_pubsub, mod_config(mod_pubsub, #{plugins => [<<"dag">>, <<"pep">>],
nodetree => nodetree_dag,
backend => mongoose_helper:mnesia_or_rdbms_backend(),
Expand Down
10 changes: 2 additions & 8 deletions big_tests/tests/privacy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,9 @@ suite() ->
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
ModConfig = [{mod_privacy, set_opts(Backend)}],
ModConfig = [{mod_privacy, config_parser_helper:mod_config_with_auto_backend(mod_privacy)}],
dynamic_modules:ensure_modules(HostType, ModConfig),
[{escalus_no_stanzas_after_story, true},
{backend, Backend} |
escalus:init_per_suite(Config1)].

set_opts(Backend) ->
config_parser_helper:mod_config(mod_privacy, #{backend => Backend}).
[{escalus_no_stanzas_after_story, true} | escalus:init_per_suite(Config1)].

end_per_suite(Config) ->
escalus_fresh:clean(),
Expand Down
16 changes: 7 additions & 9 deletions big_tests/tests/private_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
-include_lib("escalus/include/escalus.hrl").
-include_lib("common_test/include/ct.hrl").

-import(config_parser_helper, [mod_config_with_auto_backend/2]).

%%--------------------------------------------------------------------
%% Suite configuration
%%--------------------------------------------------------------------
Expand Down Expand Up @@ -47,13 +49,12 @@ suite() ->
init_per_suite(Config0) ->
HostType = domain_helper:host_type(),
Config1 = dynamic_modules:save_modules(HostType, Config0),
Backend = mongoose_helper:get_backend_mnesia_rdbms(HostType),
ModConfig = create_config(Backend),
dynamic_modules:ensure_modules(HostType, ModConfig),
escalus:init_per_suite([{backend, Backend} | Config1]).
dynamic_modules:ensure_modules(HostType, create_config()),
escalus:init_per_suite(Config1).

create_config(Backend) ->
[{mod_private, #{backend => Backend, iqdisc => one_queue}}].
create_config() ->
[{mod_private,
mod_config_with_auto_backend(mod_private, #{iqdisc => one_queue})}].

end_per_suite(Config) ->
dynamic_modules:restore_modules(Config),
Expand Down Expand Up @@ -175,6 +176,3 @@ check_body_rec(Element, [Name | Names]) ->
[Child] = Element#xmlel.children,
Name = Child#xmlel.name,
check_body_rec(Child, Names).

required_modules(Backend) ->
[{mod_private, [{backend, Backend}]}].
5 changes: 5 additions & 0 deletions doc/modules/mod_caps.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ The size of a cache_tab (the amount of entries) holding the information about ca

Time (in seconds) after which entries will be removed.

### `modules.mod_caps.backend`
* **Syntax:** string, one of `"mnesia"`, `"rdbms"`.
* **Default:** "mnesia"
* **Example:** `backend = "mnesia"`

## Example Configuration

```toml
Expand Down
7 changes: 7 additions & 0 deletions priv/mssql2012.sql
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,10 @@ CREATE TABLE discovery_nodes (
PRIMARY KEY (cluster_name, node_name)
);
CREATE UNIQUE INDEX i_discovery_nodes_node_num ON discovery_nodes(cluster_name, node_num);

CREATE TABLE caps (
node varchar(250) NOT NULL,
sub_node varchar(250) NOT NULL,
features text NOT NULL,
PRIMARY KEY (node, sub_node)
);
7 changes: 7 additions & 0 deletions priv/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,10 @@ CREATE TABLE discovery_nodes (
PRIMARY KEY (cluster_name, node_name)
);
CREATE UNIQUE INDEX i_discovery_nodes_node_num USING BTREE ON discovery_nodes(cluster_name, node_num);

CREATE TABLE caps (
node varchar(250) NOT NULL,
sub_node varchar(250) NOT NULL,
features text NOT NULL,
PRIMARY KEY (node, sub_node)
);
7 changes: 7 additions & 0 deletions priv/pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,10 @@ CREATE TABLE discovery_nodes (
PRIMARY KEY (cluster_name, node_name)
);
CREATE UNIQUE INDEX i_discovery_nodes_node_num ON discovery_nodes USING BTREE(cluster_name, node_num);

CREATE TABLE caps (
node varchar(250) NOT NULL,
sub_node varchar(250) NOT NULL,
features text NOT NULL,
PRIMARY KEY (node, sub_node)
);
Loading

0 comments on commit e8087b4

Please sign in to comment.