Skip to content

Commit

Permalink
Merge pull request #3158 from esl/multi-tenancy-cleanup
Browse files Browse the repository at this point in the history
cleaning up some issues with multitenancy support

this PR introduces the following changes:

    add verification of dynamic_domains feature support at gen_mod
    Add dynamic_domains support declaration for the modules tested with dynamic_domains.spec. Please note that these modules are dynamically enabled during the integration tests, there is no warranty that they are fully converted and tested properly with the current dynamic_domains.spec. We must create a follow-up ticket to recheck all of that modules, here is the list of them:
        mod_mam
        mod_mam_cache_user
        mod_mam_meta - this one is not tested, but it's required for a normal MAM configuration through the TOML file
        mod_mam_mnesia_prefs
        mod_mam_muc
        mod_mam_muc_cache_user
        mod_mam_muc_rdbms_arch
        mod_mam_muc_rdbms_async_pool_writer
        mod_mam_rdbms_arch
        mod_mam_rdbms_async_pool_writer
        mod_mam_rdbms_prefs
        mod_mam_rdbms_user
        mod_muc
        mod_muc_light
        mod_muc_log
    minor fix for mod_domain_isolation.
    declaration of dynamic_domains support for 'mod_commands' and 'mod_muc_light_commands' modules. Quick check shows that these modules are converted, however there is no proper testing done for them. these 2 modules are changed mostly for alignment with bkpr's codebase.
  • Loading branch information
NelsonVides committed Jun 22, 2021
2 parents 78880e6 + 5943b7a commit 18a65f6
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 71 deletions.
2 changes: 2 additions & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

{suites, "tests", offline_stub_SUITE}.

{suites, "tests", domain_isolation_SUITE}.

{suites, "tests", sm_SUITE}.
{skip_cases, "tests", sm_SUITE,
[basic_ack,
Expand Down
11 changes: 0 additions & 11 deletions doc/modules/mod_domain_isolation.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
## Module Description

This module limits message passing between domains.

## Options

### `modules.mod_domain_isolation.extra_domains`

Allows to specify more domains, the rules are applied to.
No filtering is done to subdomains, unless they are specified in the `extra_domains` list.

* **Syntax:** a list of domain templates (as lists)
* **Default:** `[]`
* **Example:** `extra_domains = ["muclight.@HOST@"]`
2 changes: 1 addition & 1 deletion include/mongoose.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%% If the ejabberd application description isn't loaded, returns atom: undefined
-define(MONGOOSE_VERSION, element(2, application:get_key(mongooseim,vsn))).

-define(MYHOSTS, ejabberd_config:get_global_option(hosts)).
-define(MYHOSTS, ejabberd_config:get_global_option_or_default(hosts, [])).
-define(ALL_HOST_TYPES, ejabberd_config:get_global_option_or_default(hosts, []) ++
ejabberd_config:get_global_option_or_default(host_types, [])).
-define(MYNAME, ejabberd_config:get_global_option(default_server_domain)).
Expand Down
12 changes: 12 additions & 0 deletions src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ start_module_for_host_type(HostType, Module, Opts0) ->
try
lists:map(fun mongoose_service:assert_loaded/1,
get_required_services(HostType, Module, Opts)),
check_dynamic_domains_support(HostType, Module),
Res = Module:start(HostType, Opts),
{links, LinksAfter} = erlang:process_info(self(), links),
case lists:sort(LinksBefore) =:= lists:sort(LinksAfter) of
Expand Down Expand Up @@ -186,6 +187,17 @@ start_module_for_host_type(HostType, Module, Opts0) ->
end
end.

check_dynamic_domains_support(HostType, Module) ->
case lists:member(HostType, ?MYHOSTS) of
true -> ok;
false ->
case gen_mod:does_module_support(Module, dynamic_domains) of
true -> ok;
false ->
error({Module, HostType, dynamic_domains_feature_is_not_supported})
end
end.

is_mim_or_ct_running() ->
?MODULE:is_app_running(mongooseim)
%% Common tests would be very confused if we kill the whole node
Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
archive_id/2]).

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% ejabberd handlers
-export([disco_local_features/1,
Expand Down Expand Up @@ -211,6 +211,10 @@ stop(HostType) ->
remove_iq_handlers(HostType),
ok.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

%% ----------------------------------------------------------------------
%% hooks and handlers

Expand Down
7 changes: 5 additions & 2 deletions src/mam/mod_mam_cache_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
-behaviour(mongoose_module_metrics).

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% ejabberd handlers
-export([cached_archive_id/3,
Expand Down Expand Up @@ -55,7 +55,6 @@ su_key(#jid{lserver = LServer, luser = LUser}) ->
%% ----------------------------------------------------------------------
%% gen_mod callbacks
%% Starting and stopping functions for users' archives

-spec start(HostType :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> ok.
start(HostType, _Opts) ->
start_server(),
Expand All @@ -67,6 +66,10 @@ stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)),
ok.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

writer_child_spec() ->
MFA = {?MODULE, start_link, []},
{?MODULE, MFA, permanent, 5000, worker, [?MODULE]}.
Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_meta.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

-type deps() :: #{module() => proplists:proplist()}.

-export([start/2, stop/1, config_spec/0,
-export([start/2, stop/1, config_spec/0, supported_features/0,
deps/2, get_mam_module_configuration/3, get_mam_module_opt/4]).

-export([config_metrics/1]).
Expand All @@ -31,6 +31,10 @@
%% API
%%--------------------------------------------------------------------

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

-spec start(Host :: jid:server(), Opts :: list()) -> any().
start(_Host, _Opts) ->
ok.
Expand Down
5 changes: 4 additions & 1 deletion src/mam/mod_mam_mnesia_prefs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%% Exports

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% MAM hook handlers
-behaviour(ejabberd_gen_mam_prefs).
Expand Down Expand Up @@ -73,6 +73,9 @@ stop(Host) ->
ok
end.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

%% ----------------------------------------------------------------------
%% Add hooks for mod_mam
Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
archive_id/2]).

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% ejabberd room handlers
-export([disco_muc_features/1,
Expand Down Expand Up @@ -158,6 +158,10 @@ stop(HostType) ->
remove_iq_handlers(HostType),
ok.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

%% ----------------------------------------------------------------------
%% hooks and handlers for MUC

Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_muc_cache_user.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-module(mod_mam_muc_cache_user).

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% ejabberd handlers
-export([cached_archive_id/3,
Expand Down Expand Up @@ -49,6 +49,10 @@ stop(HostType) ->
clean_mnesia(HostType),
ok.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

%% ----------------------------------------------------------------------
%% Init

Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_muc_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%% Exports

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% MAM hook handlers
-behaviour(ejabberd_gen_mam_archive).
Expand Down Expand Up @@ -61,6 +61,10 @@ start(HostType, _Opts) ->
stop(HostType) ->
stop_hooks(HostType).

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

-spec get_mam_muc_gdpr_data(ejabberd_gen_mam_archive:mam_pm_gdpr_data(),
host_type(), jid:jid()) ->
ejabberd_gen_mam_archive:mam_muc_gdpr_data().
Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_muc_rdbms_async_pool_writer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%% Exports

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% MAM hook handlers
-behaviour(ejabberd_gen_mam_archive).
Expand Down Expand Up @@ -95,6 +95,10 @@ stop(HostType) ->
stop_muc(HostType),
stop_workers(HostType).

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

%% ----------------------------------------------------------------------
%% Add hooks for mod_mam_muc

Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_rdbms_arch.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%% Exports

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% MAM hook handlers
-behaviour(ejabberd_gen_mam_archive).
Expand Down Expand Up @@ -76,6 +76,10 @@ start(HostType, Opts) ->
stop(HostType) ->
stop_hooks(HostType).

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

-spec get_mam_pm_gdpr_data(ejabberd_gen_mam_archive:mam_pm_gdpr_data(),
host_type(), jid:jid()) ->
ejabberd_gen_mam_archive:mam_pm_gdpr_data().
Expand Down
6 changes: 5 additions & 1 deletion src/mam/mod_mam_rdbms_async_pool_writer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
%% Exports

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% MAM hook handlers
-behaviour(ejabberd_gen_mam_archive).
Expand Down Expand Up @@ -119,6 +119,10 @@ stop(HostType) ->
end,
stop_workers(HostType).

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

%% ----------------------------------------------------------------------
%% Add hooks for mod_mam

Expand Down
7 changes: 5 additions & 2 deletions src/mam/mod_mam_rdbms_prefs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%% Exports

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% MAM hook handlers
-behaviour(ejabberd_gen_mam_prefs).
Expand All @@ -34,7 +34,6 @@
%% ----------------------------------------------------------------------
%% gen_mod callbacks
%% Starting and stopping functions for users' archives

-spec start(mongooseim:host_type(), _) -> ok.
start(HostType, _Opts) ->
prepare_queries(HostType),
Expand All @@ -46,6 +45,10 @@ stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)),
ok.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

hooks(HostType) ->
PM = gen_mod:get_module_opt(HostType, ?MODULE, pm, false),
MUC = gen_mod:get_module_opt(HostType, ?MODULE, muc, false),
Expand Down
7 changes: 5 additions & 2 deletions src/mam/mod_mam_rdbms_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-module(mod_mam_rdbms_user).

%% gen_mod handlers
-export([start/2, stop/1]).
-export([start/2, stop/1, supported_features/0]).

%% ejabberd handlers
-export([archive_id/3,
Expand All @@ -25,7 +25,6 @@

%% ----------------------------------------------------------------------
%% gen_mod callbacks

-spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
start(HostType, _Opts) ->
prepare_queries(),
Expand All @@ -37,6 +36,10 @@ stop(HostType) ->
ejabberd_hooks:delete(hooks(HostType)),
ok.

-spec supported_features() -> [atom()].
supported_features() ->
[dynamic_domains].

hooks(HostType) ->
[{Hook, HostType, ?MODULE, Fun, N}
|| {true, Hook, Fun, N} <- hooks2(HostType)].
Expand Down
13 changes: 10 additions & 3 deletions src/mod_commands.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-behaviour(gen_mod).
-behaviour(mongoose_module_metrics).

-export([start/0, stop/0,
-export([start/0, stop/0, supported_features/0,
start/2, stop/1,
register/3,
unregister/2,
Expand Down Expand Up @@ -43,6 +43,13 @@ stop() ->
start(_, _) -> start().
stop(_) -> stop().

-spec supported_features() -> [atom()].
supported_features() ->
%% TODO: this module should be reworked into service
%% from the quick look it seems that the conversion for dynamic domains is done,
%% but there's no testing for this module enabled at dynamic_domains.spec yet.
[dynamic_domains].

%%%
%%% mongoose commands
%%%
Expand Down Expand Up @@ -504,8 +511,8 @@ run_subscription(Type, CallerJid, OtherJid) ->
lserver => LServer,
element => El }),
% set subscription to
Acc2 = mongoose_hooks:roster_out_subscription(
LServer, Acc1, CallerJid, OtherJid, Type),
Acc2 = mongoose_hooks:roster_out_subscription(HostType, Acc1, CallerJid,
OtherJid, Type),
ejabberd_router:route(CallerJid, OtherJid, Acc2),
ok.

Expand Down
Loading

0 comments on commit 18a65f6

Please sign in to comment.