fix: ensure plugin tarball and extracted
This commit is contained in:
parent
1abc8cf502
commit
3ce091e9d7
|
@ -166,7 +166,7 @@ ensure_installed(NameVsn) ->
|
||||||
_ = maybe_ensure_plugin_config(NameVsn);
|
_ = maybe_ensure_plugin_config(NameVsn);
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
ok = purge(NameVsn),
|
ok = purge(NameVsn),
|
||||||
case do_ensure_installed(NameVsn) of
|
case ensure_exists_and_installed(NameVsn) of
|
||||||
ok ->
|
ok ->
|
||||||
maybe_post_op_after_installed(NameVsn);
|
maybe_post_op_after_installed(NameVsn);
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -303,7 +303,7 @@ get_config(Name, Vsn, Options, Default) ->
|
||||||
{ok, plugin_config()}
|
{ok, plugin_config()}
|
||||||
| {error, term()}.
|
| {error, term()}.
|
||||||
get_config(NameVsn) ->
|
get_config(NameVsn) ->
|
||||||
get_config(bin(NameVsn), #{format => ?CONFIG_FORMAT_MAP}).
|
get_config(NameVsn, #{format => ?CONFIG_FORMAT_MAP}).
|
||||||
|
|
||||||
-spec get_config(name_vsn(), Options :: map()) ->
|
-spec get_config(name_vsn(), Options :: map()) ->
|
||||||
{ok, avro_binary() | plugin_config()}
|
{ok, avro_binary() | plugin_config()}
|
||||||
|
@ -317,8 +317,9 @@ get_config(NameVsn, #{format := ?CONFIG_FORMAT_AVRO}) ->
|
||||||
get_config(NameVsn, Options = #{format := ?CONFIG_FORMAT_MAP}) ->
|
get_config(NameVsn, Options = #{format := ?CONFIG_FORMAT_MAP}) ->
|
||||||
get_config(NameVsn, Options, #{}).
|
get_config(NameVsn, Options, #{}).
|
||||||
|
|
||||||
|
%% Present default config value only in map format.
|
||||||
get_config(NameVsn, #{format := ?CONFIG_FORMAT_MAP}, Default) ->
|
get_config(NameVsn, #{format := ?CONFIG_FORMAT_MAP}, Default) ->
|
||||||
{ok, persistent_term:get(?PLUGIN_PERSIS_CONFIG_KEY(NameVsn), Default)}.
|
{ok, persistent_term:get(?PLUGIN_PERSIS_CONFIG_KEY(bin(NameVsn)), Default)}.
|
||||||
|
|
||||||
%% @doc Update plugin's config.
|
%% @doc Update plugin's config.
|
||||||
%% RPC call from Management API or CLI.
|
%% RPC call from Management API or CLI.
|
||||||
|
@ -1133,21 +1134,24 @@ do_create_config_dir(NameVsn) ->
|
||||||
|
|
||||||
maybe_ensure_plugin_config(NameVsn) ->
|
maybe_ensure_plugin_config(NameVsn) ->
|
||||||
maybe
|
maybe
|
||||||
true ?= filelib:is_regular(avro_config_file(NameVsn)),
|
true ?= with_plugin_avsc(NameVsn),
|
||||||
ensure_avro_config(NameVsn)
|
_ = do_ensure_plugin_config(NameVsn)
|
||||||
else
|
else
|
||||||
_ -> do_ensure_plugin_config(NameVsn)
|
_ -> ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_ensure_plugin_config(NameVsn) ->
|
do_ensure_plugin_config(NameVsn) ->
|
||||||
|
%% fetch plugin avro config from cluster
|
||||||
Nodes = [N || N <- mria:running_nodes(), N /= node()],
|
Nodes = [N || N <- mria:running_nodes(), N /= node()],
|
||||||
case get_avro_config_from_any_node(Nodes, NameVsn, []) of
|
case get_avro_config_from_any_node(Nodes, NameVsn, []) of
|
||||||
{ok, AvroJsonMap} when is_map(AvroJsonMap) ->
|
{ok, AvroJsonMap} when is_map(AvroJsonMap) ->
|
||||||
AvroJsonBin = emqx_utils_json:encode(AvroJsonMap),
|
AvroJsonBin = emqx_utils_json:encode(AvroJsonMap),
|
||||||
ok = file:write_file(avro_config_file(NameVsn), AvroJsonBin),
|
ok = file:write_file(avro_config_file(NameVsn), AvroJsonBin),
|
||||||
ensure_avro_config(NameVsn);
|
ensure_avro_config(NameVsn);
|
||||||
%% {ok, ?plugin_conf_not_found} ->
|
|
||||||
_ ->
|
_ ->
|
||||||
|
?SLOG(warning, #{msg => "config_not_found_from_cluster"}),
|
||||||
|
%% otherwise cp default avro file
|
||||||
|
%% i.e. Clean installation
|
||||||
cp_default_avro_file(NameVsn),
|
cp_default_avro_file(NameVsn),
|
||||||
ensure_avro_config(NameVsn)
|
ensure_avro_config(NameVsn)
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue