fix: apply suggestions from code review, thanks @zmstone
This commit is contained in:
parent
5dc96a37e2
commit
a40c7d646a
|
@ -512,7 +512,7 @@ plugin_config(put, #{bindings := #{name := NameVsn}, body := AvroJsonMap}) ->
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
case emqx_plugins:decode_plugin_config_map(NameVsn, AvroJsonMap) of
|
case emqx_plugins:decode_plugin_config_map(NameVsn, AvroJsonMap) of
|
||||||
{ok, ?plugin_without_config_schema} ->
|
{ok, ?plugin_without_config_schema} ->
|
||||||
%% no plugin avro schema, just put the json map it as-is
|
%% no plugin avro schema, just put the json map as-is
|
||||||
_Res = emqx_mgmt_api_plugins_proto_v3:update_plugin_config(
|
_Res = emqx_mgmt_api_plugins_proto_v3:update_plugin_config(
|
||||||
Nodes, NameVsn, AvroJsonMap, ?plugin_without_config_schema
|
Nodes, NameVsn, AvroJsonMap, ?plugin_without_config_schema
|
||||||
),
|
),
|
||||||
|
@ -616,7 +616,7 @@ ensure_action(Name, restart) ->
|
||||||
) ->
|
) ->
|
||||||
ok.
|
ok.
|
||||||
do_update_plugin_config(NameVsn, AvroJsonMap, AvroValue) ->
|
do_update_plugin_config(NameVsn, AvroJsonMap, AvroValue) ->
|
||||||
%% TODO: maybe use `PluginConfigMap` to validate config
|
%% TODO: maybe use `AvroValue` to validate config
|
||||||
emqx_plugins:put_config(NameVsn, AvroJsonMap, AvroValue).
|
emqx_plugins:put_config(NameVsn, AvroJsonMap, AvroValue).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -162,7 +162,8 @@ ensure_installed(NameVsn) ->
|
||||||
case ensure_exists_and_installed(NameVsn) of
|
case ensure_exists_and_installed(NameVsn) of
|
||||||
ok ->
|
ok ->
|
||||||
maybe_post_op_after_installed(NameVsn),
|
maybe_post_op_after_installed(NameVsn),
|
||||||
_ = maybe_ensure_plugin_config(NameVsn);
|
_ = maybe_ensure_plugin_config(NameVsn),
|
||||||
|
ok;
|
||||||
{error, _Reason} = Err ->
|
{error, _Reason} = Err ->
|
||||||
Err
|
Err
|
||||||
end
|
end
|
||||||
|
@ -1166,6 +1167,7 @@ do_create_config_dir(NameVsn) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec maybe_ensure_plugin_config(name_vsn()) -> ok.
|
||||||
maybe_ensure_plugin_config(NameVsn) ->
|
maybe_ensure_plugin_config(NameVsn) ->
|
||||||
maybe
|
maybe
|
||||||
true ?= with_plugin_avsc(NameVsn),
|
true ?= with_plugin_avsc(NameVsn),
|
||||||
|
@ -1174,10 +1176,13 @@ maybe_ensure_plugin_config(NameVsn) ->
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec ensure_plugin_config(name_vsn()) -> ok.
|
||||||
ensure_plugin_config(NameVsn) ->
|
ensure_plugin_config(NameVsn) ->
|
||||||
%% fetch plugin hocon config from cluster
|
%% fetch plugin hocon config from cluster
|
||||||
Nodes = [N || N <- mria:running_nodes(), N /= node()],
|
Nodes = [N || N <- mria:running_nodes(), N /= node()],
|
||||||
ensure_plugin_config(NameVsn, Nodes).
|
ensure_plugin_config(NameVsn, Nodes).
|
||||||
|
|
||||||
|
-spec ensure_plugin_config(name_vsn(), list()) -> ok.
|
||||||
ensure_plugin_config(NameVsn, []) ->
|
ensure_plugin_config(NameVsn, []) ->
|
||||||
?SLOG(debug, #{
|
?SLOG(debug, #{
|
||||||
msg => "default_plugin_config_used",
|
msg => "default_plugin_config_used",
|
||||||
|
@ -1200,6 +1205,7 @@ ensure_plugin_config(NameVsn, Nodes) ->
|
||||||
cp_default_config_file(NameVsn)
|
cp_default_config_file(NameVsn)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec cp_default_config_file(name_vsn()) -> ok.
|
||||||
cp_default_config_file(NameVsn) ->
|
cp_default_config_file(NameVsn) ->
|
||||||
%% always copy default hocon file into config dir when can not get config from other nodes
|
%% always copy default hocon file into config dir when can not get config from other nodes
|
||||||
Source = default_plugin_config_file(NameVsn),
|
Source = default_plugin_config_file(NameVsn),
|
||||||
|
@ -1211,7 +1217,6 @@ cp_default_config_file(NameVsn) ->
|
||||||
ok = filelib:ensure_dir(Destination),
|
ok = filelib:ensure_dir(Destination),
|
||||||
case file:copy(Source, Destination) of
|
case file:copy(Source, Destination) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
ok,
|
|
||||||
ensure_config_map(NameVsn);
|
ensure_config_map(NameVsn);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?SLOG(warning, #{
|
?SLOG(warning, #{
|
||||||
|
|
Loading…
Reference in New Issue