Define pubsub node configuration per route/host explicitly

This commit is contained in:
Evgeniy Khramtsov 2016-03-13 13:16:43 +03:00
parent 357e48fb6b
commit 5045fb584d
1 changed files with 26 additions and 20 deletions

View File

@ -257,22 +257,26 @@ init([ServerHost, Opts]) ->
DefaultNodeCfg = gen_mod:get_opt(default_node_config, Opts,
fun(A) when is_list(A) -> filter_node_options(A) end, []),
pubsub_index:init(Host, ServerHost, Opts),
ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]),
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
mnesia:create_table(pubsub_last_item,
[{ram_copies, [node()]},
{attributes, record_info(fields, pubsub_last_item)}]),
mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {nodetree, NodeTree}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {plugins, Plugins}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_subscriptions_node, MaxSubsNode}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {default_node_config, DefaultNodeCfg}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {access, Access}),
lists:foreach(
fun(H) ->
T = gen_mod:get_module_proc(H, config),
ets:new(T, [set, named_table]),
ets:insert(T, {nodetree, NodeTree}),
ets:insert(T, {plugins, Plugins}),
ets:insert(T, {last_item_cache, LastItemCache}),
ets:insert(T, {max_items_node, MaxItemsNode}),
ets:insert(T, {max_subscriptions_node, MaxSubsNode}),
ets:insert(T, {default_node_config, DefaultNodeCfg}),
ets:insert(T, {pep_mapping, PepMapping}),
ets:insert(T, {ignore_pep_from_offline, PepOffline}),
ets:insert(T, {host, Host}),
ets:insert(T, {access, Access})
end, [Host, ServerHost]),
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost,
?MODULE, on_user_offline, 75),
ejabberd_hooks:add(disco_local_identity, ServerHost,
@ -3641,7 +3645,7 @@ get_option(Options, Var, Def) ->
end.
node_options(Host, Type) ->
case config(serverhost(Host), default_node_config) of
case config(Host, default_node_config) of
undefined -> node_plugin_options(Host, Type);
[] -> node_plugin_options(Host, Type);
Config -> Config
@ -3954,15 +3958,15 @@ set_xoption(Host, [_ | Opts], NewOpts) ->
set_xoption(Host, Opts, NewOpts).
get_max_items_node(Host) ->
config(serverhost(Host), max_items_node, undefined).
config(Host, max_items_node, undefined).
get_max_subscriptions_node(Host) ->
config(serverhost(Host), max_subscriptions_node, undefined).
config(Host, max_subscriptions_node, undefined).
%%%% last item cache handling
is_last_item_cache_enabled(Host) ->
config(serverhost(Host), last_item_cache, false).
config(Host, last_item_cache, false).
set_cached_item({_, ServerHost, _}, Nidx, ItemId, Publisher, Payload) ->
set_cached_item(ServerHost, Nidx, ItemId, Publisher, Payload);
@ -4013,13 +4017,12 @@ host(ServerHost) ->
config(ServerHost, host, <<"pubsub.", ServerHost/binary>>).
serverhost({_U, ServerHost, _R})->
ServerHost;
serverhost(ServerHost);
serverhost(Host) ->
[_, ServerHost] = binary:split(Host, <<".">>),
ServerHost.
ejabberd_router:host_of_route(Host).
tree(Host) ->
case config(serverhost(Host), nodetree) of
case config(Host, nodetree) of
undefined -> tree(Host, ?STDTREE);
Tree -> Tree
end.
@ -4041,7 +4044,7 @@ plugin(Host, Name) ->
end.
plugins(Host) ->
case config(serverhost(Host), plugins) of
case config(Host, plugins) of
undefined -> [?STDNODE];
[] -> [?STDNODE];
Plugins -> Plugins
@ -4056,6 +4059,9 @@ subscription_plugin(Host) ->
config(ServerHost, Key) ->
config(ServerHost, Key, undefined).
config({_User, Host, _Resource}, Key, Default) ->
config(Host, Key, Default);
config(ServerHost, Key, Default) ->
case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), Key) of
[{Key, Value}] -> Value;