fix: enusre plugin installed when do config operation
This commit is contained in:
parent
b0aa3bb70f
commit
1869f6fd0a
|
@ -200,7 +200,7 @@ schema("/plugins/:name/config") ->
|
||||||
responses => #{
|
responses => #{
|
||||||
204 => <<"Config updated successfully">>,
|
204 => <<"Config updated successfully">>,
|
||||||
400 => emqx_dashboard_swagger:error_codes(
|
400 => emqx_dashboard_swagger:error_codes(
|
||||||
['UNEXPECTED_ERROR'], <<"Update plugin config failed">>
|
['BAD_CONFIG', 'UNEXPECTED_ERROR'], <<"Update plugin config failed">>
|
||||||
),
|
),
|
||||||
404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND'], <<"Plugin Not Found">>)
|
404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND'], <<"Plugin Not Found">>)
|
||||||
}
|
}
|
||||||
|
@ -485,31 +485,41 @@ update_plugin(put, #{bindings := #{name := Name, action := Action}}) ->
|
||||||
Res = emqx_mgmt_api_plugins_proto_v2:ensure_action(Name, Action),
|
Res = emqx_mgmt_api_plugins_proto_v2:ensure_action(Name, Action),
|
||||||
return(204, Res).
|
return(204, Res).
|
||||||
|
|
||||||
plugin_config(get, #{bindings := #{name := Name}}) ->
|
plugin_config(get, #{bindings := #{name := NameVsn}}) ->
|
||||||
case emqx_plugins:get_plugin_config(Name, #{format => ?CONFIG_FORMAT_MAP}) of
|
case emqx_plugins:describe(NameVsn) of
|
||||||
{ok, AvroJson} ->
|
{ok, _} ->
|
||||||
{200, #{<<"content-type">> => <<"'application/json'">>}, AvroJson};
|
case emqx_plugins:get_plugin_config(NameVsn, #{format => ?CONFIG_FORMAT_MAP}) of
|
||||||
{error, _} ->
|
{ok, AvroJson} ->
|
||||||
{400, #{
|
{200, #{<<"content-type">> => <<"'application/json'">>}, AvroJson};
|
||||||
code => 'BAD_CONFIG',
|
{error, _} ->
|
||||||
message => <<"Failed to get plugin config">>
|
{400, #{
|
||||||
}}
|
code => 'BAD_CONFIG',
|
||||||
|
message => <<"Failed to get plugin config">>
|
||||||
|
}}
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
{404, plugin_not_found_msg()}
|
||||||
end;
|
end;
|
||||||
plugin_config(put, #{bindings := #{name := Name}, body := AvroJsonMap}) ->
|
plugin_config(put, #{bindings := #{name := NameVsn}, body := AvroJsonMap}) ->
|
||||||
AvroJsonBin = emqx_utils_json:encode(AvroJsonMap),
|
case emqx_plugins:describe(NameVsn) of
|
||||||
case emqx_plugins:decode_plugin_avro_config(Name, AvroJsonBin) of
|
{ok, _} ->
|
||||||
{ok, AvroValueConfig} ->
|
AvroJsonBin = emqx_utils_json:encode(AvroJsonMap),
|
||||||
Nodes = emqx:running_nodes(),
|
case emqx_plugins:decode_plugin_avro_config(NameVsn, AvroJsonBin) of
|
||||||
%% cluster call with config in map (binary key-value)
|
{ok, AvroValueConfig} ->
|
||||||
_Res = emqx_mgmt_api_plugins_proto_v3:update_plugin_config(
|
Nodes = emqx:running_nodes(),
|
||||||
Nodes, Name, AvroJsonMap, AvroValueConfig
|
%% cluster call with config in map (binary key-value)
|
||||||
),
|
_Res = emqx_mgmt_api_plugins_proto_v3:update_plugin_config(
|
||||||
{204};
|
Nodes, NameVsn, AvroJsonMap, AvroValueConfig
|
||||||
{error, Reason} ->
|
),
|
||||||
{400, #{
|
{204};
|
||||||
code => 'BAD_CONFIG',
|
{error, Reason} ->
|
||||||
message => readable_error_msg(Reason)
|
{400, #{
|
||||||
}}
|
code => 'BAD_CONFIG',
|
||||||
|
message => readable_error_msg(Reason)
|
||||||
|
}}
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
{404, plugin_not_found_msg()}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
plugin_schema(get, #{bindings := #{name := NameVsn}}) ->
|
plugin_schema(get, #{bindings := #{name := NameVsn}}) ->
|
||||||
|
@ -517,10 +527,7 @@ plugin_schema(get, #{bindings := #{name := NameVsn}}) ->
|
||||||
{ok, _Plugin} ->
|
{ok, _Plugin} ->
|
||||||
{200, format_plugin_avsc_and_i18n(NameVsn)};
|
{200, format_plugin_avsc_and_i18n(NameVsn)};
|
||||||
_ ->
|
_ ->
|
||||||
{404, #{
|
{404, plugin_not_found_msg()}
|
||||||
code => 'NOT_FOUND',
|
|
||||||
message => <<"Plugin Not Found">>
|
|
||||||
}}
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
update_boot_order(post, #{bindings := #{name := Name}, body := Body}) ->
|
update_boot_order(post, #{bindings := #{name := Name}, body := Body}) ->
|
||||||
|
@ -610,6 +617,12 @@ return(_, {error, #{error_msg := "bad_avro_config_file", reason := {enoent, _} =
|
||||||
return(_, {error, Reason}) ->
|
return(_, {error, Reason}) ->
|
||||||
{400, #{code => 'PARAM_ERROR', message => readable_error_msg(Reason)}}.
|
{400, #{code => 'PARAM_ERROR', message => readable_error_msg(Reason)}}.
|
||||||
|
|
||||||
|
plugin_not_found_msg() ->
|
||||||
|
#{
|
||||||
|
code => 'NOT_FOUND',
|
||||||
|
message => <<"Plugin Not Found">>
|
||||||
|
}.
|
||||||
|
|
||||||
readable_error_msg(Msg) ->
|
readable_error_msg(Msg) ->
|
||||||
emqx_utils:readable_error_msg(Msg).
|
emqx_utils:readable_error_msg(Msg).
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,11 @@ ensure_action(Name, Action) ->
|
||||||
map()
|
map()
|
||||||
) ->
|
) ->
|
||||||
emqx_rpc:multicall_result().
|
emqx_rpc:multicall_result().
|
||||||
update_plugin_config(Nodes, Name, AvroJsonMap, PluginConfig) ->
|
update_plugin_config(Nodes, NameVsn, AvroJsonMap, PluginConfig) ->
|
||||||
rpc:multicall(
|
rpc:multicall(
|
||||||
Nodes,
|
Nodes,
|
||||||
emqx_mgmt_api_plugins,
|
emqx_mgmt_api_plugins,
|
||||||
do_update_plugin_config,
|
do_update_plugin_config,
|
||||||
[Name, AvroJsonMap, PluginConfig],
|
[NameVsn, AvroJsonMap, PluginConfig],
|
||||||
10000
|
10000
|
||||||
).
|
).
|
||||||
|
|
Loading…
Reference in New Issue