fix(emqx_data_bridge): update bridge failed
This commit is contained in:
parent
fdd0233103
commit
1de2f5cb2f
|
@ -52,7 +52,6 @@ on_jsonify(#{<<"server">> := Server, <<"user">> := User, <<"database">> := DB,
|
||||||
}.
|
}.
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
on_start(InstId, #{<<"server">> := {Host, Port},
|
on_start(InstId, #{<<"server">> := {Host, Port},
|
||||||
<<"database">> := DB,
|
<<"database">> := DB,
|
||||||
<<"user">> := User,
|
<<"user">> := User,
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-rest_api(#{ name => update_data_bridge
|
-rest_api(#{ name => update_data_bridge
|
||||||
, method => 'POST'
|
, method => 'PUT'
|
||||||
, path => "/data_bridges/:bin:name"
|
, path => "/data_bridges/:bin:name"
|
||||||
, func => update_bridge
|
, func => update_bridge
|
||||||
, descr => "Update an existing data bridge"
|
, descr => "Update an existing data bridge"
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
|
%% TODO: trigger the `updated` message from emqx_resource.
|
||||||
notify_updated() ->
|
notify_updated() ->
|
||||||
gen_server:cast(?MODULE, updated).
|
gen_server:cast(?MODULE, updated).
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ handle_call(_Request, _From, State) ->
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{reply, Reply, State}.
|
{reply, Reply, State}.
|
||||||
|
|
||||||
|
%% TODO: change the config handler as a behavoir that calls back the Mod:format_config/1
|
||||||
handle_cast(updated, State) ->
|
handle_cast(updated, State) ->
|
||||||
Configs = [format_conf(Data) || Data <- emqx_data_bridge:list_bridges()],
|
Configs = [format_conf(Data) || Data <- emqx_data_bridge:list_bridges()],
|
||||||
emqx_config_handler ! {emqx_data_bridge, Configs},
|
emqx_config_handler ! {emqx_data_bridge, Configs},
|
||||||
|
|
|
@ -67,6 +67,8 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
load_bridges(Configs) ->
|
load_bridges(Configs) ->
|
||||||
lists:foreach(fun load_bridge/1, Configs).
|
lists:foreach(fun load_bridge/1, Configs).
|
||||||
|
|
||||||
|
%% TODO: move this monitor into emqx_resource
|
||||||
|
%% emqx_resource:check_and_create_local(ResourceId, ResourceType, Config, #{keep_retry => true}).
|
||||||
load_bridge(#{<<"name">> := Name, <<"type">> := Type,
|
load_bridge(#{<<"name">> := Name, <<"type">> := Type,
|
||||||
<<"config">> := Config}) ->
|
<<"config">> := Config}) ->
|
||||||
case emqx_resource:check_and_create_local(
|
case emqx_resource:check_and_create_local(
|
||||||
|
|
|
@ -255,13 +255,9 @@ call_stop(InstId, Mod, ResourceState) ->
|
||||||
-spec call_config_merge(module(), resource_config(), resource_config(), term()) ->
|
-spec call_config_merge(module(), resource_config(), resource_config(), term()) ->
|
||||||
resource_config().
|
resource_config().
|
||||||
call_config_merge(Mod, OldConfig, NewConfig, Params) ->
|
call_config_merge(Mod, OldConfig, NewConfig, Params) ->
|
||||||
case erlang:function_exported(Mod, on_jsonify, 1) of
|
case erlang:function_exported(Mod, on_config_merge, 3) of
|
||||||
true ->
|
true -> ?SAFE_CALL(Mod:on_config_merge(OldConfig, NewConfig, Params));
|
||||||
?SAFE_CALL(Mod:on_config_merge(OldConfig, NewConfig, Params));
|
false -> NewConfig
|
||||||
false when is_map(OldConfig), is_map(NewConfig) ->
|
|
||||||
maps:merge(OldConfig, NewConfig);
|
|
||||||
false ->
|
|
||||||
NewConfig
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec call_jsonify(module(), resource_config()) -> jsx:json_term().
|
-spec call_jsonify(module(), resource_config()) -> jsx:json_term().
|
||||||
|
|
Loading…
Reference in New Issue