|
@@ -132,13 +132,14 @@ create(BridgeId, Conf) ->
|
|
|
create(Type, Name, Conf) ->
|
|
create(Type, Name, Conf) ->
|
|
|
create(Type, Name, Conf, #{}).
|
|
create(Type, Name, Conf, #{}).
|
|
|
|
|
|
|
|
-create(Type, Name, Conf, Opts) ->
|
|
|
|
|
|
|
+create(Type, Name, Conf, Opts0) ->
|
|
|
?SLOG(info, #{
|
|
?SLOG(info, #{
|
|
|
msg => "create bridge",
|
|
msg => "create bridge",
|
|
|
type => Type,
|
|
type => Type,
|
|
|
name => Name,
|
|
name => Name,
|
|
|
config => Conf
|
|
config => Conf
|
|
|
}),
|
|
}),
|
|
|
|
|
+ Opts = override_start_after_created(Conf, Opts0),
|
|
|
{ok, _Data} = emqx_resource:create_local(
|
|
{ok, _Data} = emqx_resource:create_local(
|
|
|
resource_id(Type, Name),
|
|
resource_id(Type, Name),
|
|
|
<<"emqx_bridge">>,
|
|
<<"emqx_bridge">>,
|
|
@@ -146,7 +147,7 @@ create(Type, Name, Conf, Opts) ->
|
|
|
parse_confs(bin(Type), Name, Conf),
|
|
parse_confs(bin(Type), Name, Conf),
|
|
|
Opts
|
|
Opts
|
|
|
),
|
|
),
|
|
|
- maybe_disable_bridge(Type, Name, Conf).
|
|
|
|
|
|
|
+ ok.
|
|
|
|
|
|
|
|
update(BridgeId, {OldConf, Conf}) ->
|
|
update(BridgeId, {OldConf, Conf}) ->
|
|
|
{BridgeType, BridgeName} = parse_bridge_id(BridgeId),
|
|
{BridgeType, BridgeName} = parse_bridge_id(BridgeId),
|
|
@@ -155,7 +156,7 @@ update(BridgeId, {OldConf, Conf}) ->
|
|
|
update(Type, Name, {OldConf, Conf}) ->
|
|
update(Type, Name, {OldConf, Conf}) ->
|
|
|
update(Type, Name, {OldConf, Conf}, #{}).
|
|
update(Type, Name, {OldConf, Conf}, #{}).
|
|
|
|
|
|
|
|
-update(Type, Name, {OldConf, Conf}, Opts) ->
|
|
|
|
|
|
|
+update(Type, Name, {OldConf, Conf}, Opts0) ->
|
|
|
%% TODO: sometimes its not necessary to restart the bridge connection.
|
|
%% TODO: sometimes its not necessary to restart the bridge connection.
|
|
|
%%
|
|
%%
|
|
|
%% - if the connection related configs like `servers` is updated, we should restart/start
|
|
%% - if the connection related configs like `servers` is updated, we should restart/start
|
|
@@ -164,6 +165,7 @@ update(Type, Name, {OldConf, Conf}, Opts) ->
|
|
|
%% the `method` or `headers` of a WebHook is changed, then the bridge can be updated
|
|
%% the `method` or `headers` of a WebHook is changed, then the bridge can be updated
|
|
|
%% without restarting the bridge.
|
|
%% without restarting the bridge.
|
|
|
%%
|
|
%%
|
|
|
|
|
+ Opts = override_start_after_created(Conf, Opts0),
|
|
|
case emqx_map_lib:if_only_to_toggle_enable(OldConf, Conf) of
|
|
case emqx_map_lib:if_only_to_toggle_enable(OldConf, Conf) of
|
|
|
false ->
|
|
false ->
|
|
|
?SLOG(info, #{
|
|
?SLOG(info, #{
|
|
@@ -174,10 +176,10 @@ update(Type, Name, {OldConf, Conf}, Opts) ->
|
|
|
}),
|
|
}),
|
|
|
case recreate(Type, Name, Conf, Opts) of
|
|
case recreate(Type, Name, Conf, Opts) of
|
|
|
{ok, _} ->
|
|
{ok, _} ->
|
|
|
- maybe_disable_bridge(Type, Name, Conf);
|
|
|
|
|
|
|
+ ok;
|
|
|
{error, not_found} ->
|
|
{error, not_found} ->
|
|
|
?SLOG(warning, #{
|
|
?SLOG(warning, #{
|
|
|
- msg => "updating_a_non-exist_bridge_need_create_a_new_one",
|
|
|
|
|
|
|
+ msg => "updating_a_non_existing_bridge",
|
|
|
type => Type,
|
|
type => Type,
|
|
|
name => Name,
|
|
name => Name,
|
|
|
config => Conf
|
|
config => Conf
|
|
@@ -242,12 +244,6 @@ remove(Type, Name, _Conf, _Opts) ->
|
|
|
{error, Reason} -> {error, Reason}
|
|
{error, Reason} -> {error, Reason}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-maybe_disable_bridge(Type, Name, Conf) ->
|
|
|
|
|
- case maps:get(enable, Conf, true) of
|
|
|
|
|
- false -> stop(Type, Name);
|
|
|
|
|
- true -> ok
|
|
|
|
|
- end.
|
|
|
|
|
-
|
|
|
|
|
maybe_clear_certs(TmpPath, #{ssl := SslConf} = Conf) ->
|
|
maybe_clear_certs(TmpPath, #{ssl := SslConf} = Conf) ->
|
|
|
%% don't remove the cert files if they are in use
|
|
%% don't remove the cert files if they are in use
|
|
|
case is_tmp_path_conf(TmpPath, SslConf) of
|
|
case is_tmp_path_conf(TmpPath, SslConf) of
|
|
@@ -321,3 +317,8 @@ str(Str) when is_list(Str) -> Str.
|
|
|
bin(Bin) when is_binary(Bin) -> Bin;
|
|
bin(Bin) when is_binary(Bin) -> Bin;
|
|
|
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
|
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
|
|
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
|
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
|
|
|
|
+
|
|
|
|
|
+override_start_after_created(Config, Opts) ->
|
|
|
|
|
+ Enabled = maps:get(enable, Config, true),
|
|
|
|
|
+ StartAfterCreated = Enabled andalso maps:get(start_after_created, Opts, Enabled),
|
|
|
|
|
+ Opts#{start_after_created => StartAfterCreated}.
|