fix: ensure plugin configured states after join cluster
This commit is contained in:
parent
874bcd9a8b
commit
43506495ae
|
@ -1123,9 +1123,31 @@ for_plugins(ActionFun) ->
|
|||
ok
|
||||
end.
|
||||
|
||||
maybe_post_op_after_installed(NameVsn) ->
|
||||
maybe_post_op_after_installed(NameVsn0) ->
|
||||
NameVsn = wrap_to_list(NameVsn0),
|
||||
_ = maybe_load_config_schema(NameVsn),
|
||||
_ = ensure_state(NameVsn, no_move, false, global),
|
||||
ok = maybe_ensure_state(NameVsn).
|
||||
|
||||
maybe_ensure_state(NameVsn) ->
|
||||
EnsureStateFun = fun(#{name_vsn := NV, enable := Bool}, AccIn) ->
|
||||
case NV of
|
||||
NameVsn ->
|
||||
%% Configured, using existed cluster config
|
||||
ensure_state(NV, no_move, Bool, global),
|
||||
AccIn#{ensured => true};
|
||||
_ ->
|
||||
AccIn
|
||||
end
|
||||
end,
|
||||
case lists:foldl(EnsureStateFun, #{ensured => false}, configured()) of
|
||||
#{ensured := true} ->
|
||||
ok;
|
||||
#{ensured := false} ->
|
||||
?SLOG(info, #{msg => "plugin_not_configured", name_vsn => NameVsn}),
|
||||
%% Clean installation, no config, ensure with `Enable = false`
|
||||
_ = ensure_state(NameVsn, no_move, false, global),
|
||||
ok
|
||||
end,
|
||||
ok.
|
||||
|
||||
maybe_load_config_schema(NameVsn) ->
|
||||
|
@ -1137,7 +1159,7 @@ maybe_load_config_schema(NameVsn) ->
|
|||
_ = maybe_create_config_dir(NameVsn).
|
||||
|
||||
do_load_config_schema(NameVsn, AvscPath) ->
|
||||
case emqx_plugins_serde:add_schema(NameVsn, AvscPath) of
|
||||
case emqx_plugins_serde:add_schema(bin(NameVsn), AvscPath) of
|
||||
ok -> ok;
|
||||
{error, already_exists} -> ok;
|
||||
{error, _Reason} -> ok
|
||||
|
@ -1345,23 +1367,23 @@ read_file_fun(Path, ErrMsg, #{read_mode := ?JSON_MAP}) ->
|
|||
%% Directorys
|
||||
-spec plugin_dir(name_vsn()) -> string().
|
||||
plugin_dir(NameVsn) ->
|
||||
wrap_list_path(filename:join([install_dir(), NameVsn])).
|
||||
wrap_to_list(filename:join([install_dir(), NameVsn])).
|
||||
|
||||
-spec plugin_priv_dir(name_vsn()) -> string().
|
||||
plugin_priv_dir(NameVsn) ->
|
||||
case read_plugin_info(NameVsn, #{fill_readme => false}) of
|
||||
{ok, #{<<"name">> := Name, <<"metadata_vsn">> := Vsn}} ->
|
||||
AppDir = make_name_vsn_string(Name, Vsn),
|
||||
wrap_list_path(filename:join([plugin_dir(NameVsn), AppDir, "priv"]));
|
||||
wrap_to_list(filename:join([plugin_dir(NameVsn), AppDir, "priv"]));
|
||||
_ ->
|
||||
wrap_list_path(filename:join([install_dir(), NameVsn, "priv"]))
|
||||
wrap_to_list(filename:join([install_dir(), NameVsn, "priv"]))
|
||||
end.
|
||||
|
||||
-spec plugin_config_dir(name_vsn()) -> string() | {error, Reason :: string()}.
|
||||
plugin_config_dir(NameVsn) ->
|
||||
case parse_name_vsn(NameVsn) of
|
||||
{ok, NameAtom, _Vsn} ->
|
||||
wrap_list_path(filename:join([emqx:data_dir(), "plugins", atom_to_list(NameAtom)]));
|
||||
wrap_to_list(filename:join([emqx:data_dir(), "plugins", atom_to_list(NameAtom)]));
|
||||
{error, Reason} ->
|
||||
?SLOG(warning, #{
|
||||
msg => "failed_to_generate_plugin_config_dir_for_plugin",
|
||||
|
@ -1374,32 +1396,32 @@ plugin_config_dir(NameVsn) ->
|
|||
%% Files
|
||||
-spec pkg_file_path(name_vsn()) -> string().
|
||||
pkg_file_path(NameVsn) ->
|
||||
wrap_list_path(filename:join([install_dir(), bin([NameVsn, ".tar.gz"])])).
|
||||
wrap_to_list(filename:join([install_dir(), bin([NameVsn, ".tar.gz"])])).
|
||||
|
||||
-spec info_file_path(name_vsn()) -> string().
|
||||
info_file_path(NameVsn) ->
|
||||
wrap_list_path(filename:join([plugin_dir(NameVsn), "release.json"])).
|
||||
wrap_to_list(filename:join([plugin_dir(NameVsn), "release.json"])).
|
||||
|
||||
-spec avsc_file_path(name_vsn()) -> string().
|
||||
avsc_file_path(NameVsn) ->
|
||||
wrap_list_path(filename:join([plugin_priv_dir(NameVsn), "config_schema.avsc"])).
|
||||
wrap_to_list(filename:join([plugin_priv_dir(NameVsn), "config_schema.avsc"])).
|
||||
|
||||
-spec plugin_config_file(name_vsn()) -> string().
|
||||
plugin_config_file(NameVsn) ->
|
||||
wrap_list_path(filename:join([plugin_config_dir(NameVsn), "config.hocon"])).
|
||||
wrap_to_list(filename:join([plugin_config_dir(NameVsn), "config.hocon"])).
|
||||
|
||||
%% should only used when plugin installing
|
||||
-spec default_plugin_config_file(name_vsn()) -> string().
|
||||
default_plugin_config_file(NameVsn) ->
|
||||
wrap_list_path(filename:join([plugin_priv_dir(NameVsn), "config.hocon"])).
|
||||
wrap_to_list(filename:join([plugin_priv_dir(NameVsn), "config.hocon"])).
|
||||
|
||||
-spec i18n_file_path(name_vsn()) -> string().
|
||||
i18n_file_path(NameVsn) ->
|
||||
wrap_list_path(filename:join([plugin_priv_dir(NameVsn), "config_i18n.json"])).
|
||||
wrap_to_list(filename:join([plugin_priv_dir(NameVsn), "config_i18n.json"])).
|
||||
|
||||
-spec readme_file(name_vsn()) -> string().
|
||||
readme_file(NameVsn) ->
|
||||
wrap_list_path(filename:join([plugin_dir(NameVsn), "README.md"])).
|
||||
wrap_to_list(filename:join([plugin_dir(NameVsn), "README.md"])).
|
||||
|
||||
running_apps() ->
|
||||
lists:map(
|
||||
|
@ -1431,5 +1453,5 @@ bin(A) when is_atom(A) -> atom_to_binary(A, utf8);
|
|||
bin(L) when is_list(L) -> unicode:characters_to_binary(L, utf8);
|
||||
bin(B) when is_binary(B) -> B.
|
||||
|
||||
wrap_list_path(Path) ->
|
||||
wrap_to_list(Path) ->
|
||||
binary_to_list(iolist_to_binary(Path)).
|
||||
|
|
Loading…
Reference in New Issue