chore: create_local/5 for emqx_resource_proto_v1
This commit is contained in:
parent
f29988ed8e
commit
2bb062d3a3
|
@ -187,7 +187,8 @@ do_create(
|
|||
ResourceId,
|
||||
?AUTHN_RESOURCE_GROUP,
|
||||
emqx_authn_jwks_connector,
|
||||
connector_opts(Config)
|
||||
connector_opts(Config),
|
||||
#{}
|
||||
),
|
||||
{ok, #{
|
||||
jwk_resource => ResourceId,
|
||||
|
|
|
@ -199,9 +199,13 @@ test_user_auth(#{
|
|||
|
||||
t_authenticate_disabled_prepared_statements(_Config) ->
|
||||
ResConfig = maps:merge(pgsql_config(), #{disable_prepared_statements => true}),
|
||||
{ok, _} = emqx_resource:recreate_local(postgresql, ?PGSQL_RESOURCE, emqx_postgresql, ResConfig),
|
||||
{ok, _} = emqx_resource:recreate_local(
|
||||
postgresql, ?PGSQL_RESOURCE, emqx_postgresql, ResConfig, #{}
|
||||
),
|
||||
on_exit(fun() ->
|
||||
emqx_resource:recreate_local(postgresql, ?PGSQL_RESOURCE, emqx_postgresql, pgsql_config())
|
||||
emqx_resource:recreate_local(
|
||||
postgresql, ?PGSQL_RESOURCE, emqx_postgresql, pgsql_config(), #{}
|
||||
)
|
||||
end),
|
||||
ok = lists:foreach(
|
||||
fun(Sample0) ->
|
||||
|
|
|
@ -39,12 +39,10 @@
|
|||
|
||||
-export([
|
||||
%% store the config and start the instance
|
||||
create_local/5,
|
||||
create_local/6,
|
||||
create_dry_run_local/3,
|
||||
create_dry_run_local/4,
|
||||
create_dry_run_local/5,
|
||||
recreate_local/4,
|
||||
recreate_local/5,
|
||||
%% remove the config and stop the instance
|
||||
remove_local/1,
|
||||
|
@ -142,6 +140,9 @@
|
|||
|
||||
-export([is_dry_run/1]).
|
||||
|
||||
%% For emqx_resource_proto_v1 rpc only
|
||||
-export([create_local/5, recreate_local/4, create_dry_run_local/2]).
|
||||
|
||||
-export_type([
|
||||
query_mode/0,
|
||||
resource_id/0,
|
||||
|
@ -281,12 +282,6 @@ is_resource_mod(Module) ->
|
|||
%% =================================================================================
|
||||
%% APIs for resource instances
|
||||
%% =================================================================================
|
||||
|
||||
-spec create_local(type(), resource_id(), resource_group(), resource_type(), resource_config()) ->
|
||||
{ok, resource_data() | 'already_created'} | {error, Reason :: term()}.
|
||||
create_local(Type, ResId, Group, ResourceType, Config) ->
|
||||
create_local(Type, ResId, Group, ResourceType, Config, #{}).
|
||||
|
||||
-spec create_local(
|
||||
type(),
|
||||
resource_id(),
|
||||
|
@ -320,11 +315,6 @@ when
|
|||
create_dry_run_local(Type, ResId, ResourceType, Config, OnReadyCallback) ->
|
||||
emqx_resource_manager:create_dry_run(Type, ResId, ResourceType, Config, OnReadyCallback).
|
||||
|
||||
-spec recreate_local(type(), resource_id(), resource_type(), resource_config()) ->
|
||||
{ok, resource_data()} | {error, Reason :: term()}.
|
||||
recreate_local(Type, ResId, ResourceType, Config) ->
|
||||
recreate_local(Type, ResId, ResourceType, Config, #{}).
|
||||
|
||||
-spec recreate_local(type(), resource_id(), resource_type(), resource_config(), creation_opts()) ->
|
||||
{ok, resource_data()} | {error, Reason :: term()}.
|
||||
recreate_local(Type, ResId, ResourceType, Config, Opts) ->
|
||||
|
@ -339,11 +329,15 @@ remove_local(ResId) ->
|
|||
ok;
|
||||
Error ->
|
||||
%% Only log, the ResId worker is always removed in manager's remove action.
|
||||
?SLOG(warning, #{
|
||||
?SLOG(
|
||||
warning,
|
||||
#{
|
||||
msg => "remove_resource_failed",
|
||||
error => Error,
|
||||
resource_id => ResId
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
ok
|
||||
end.
|
||||
|
||||
|
@ -815,3 +809,18 @@ validate_name(Name, Opts) ->
|
|||
|
||||
-spec invalid_data(binary()) -> no_return().
|
||||
invalid_data(Reason) -> throw(#{kind => validation_error, reason => Reason}).
|
||||
|
||||
%% Those functions is only used in the emqx_resource_proto_v1
|
||||
%% for versions that are less than version 5.6.0.
|
||||
%% begin
|
||||
-spec create_local(
|
||||
resource_id(), resource_group(), resource_type(), resource_config(), creation_opts()
|
||||
) ->
|
||||
{ok, resource_data() | 'already_created'} | {error, Reason :: term()}.
|
||||
create_local(ResId, Group, ResourceType, Config, Opts) ->
|
||||
create_local(deprecated, ResId, Group, ResourceType, Config, Opts).
|
||||
create_dry_run_local(ResourceType, Config) ->
|
||||
create_dry_run_local(deprecated, ResourceType, Config).
|
||||
recreate_local(ResId, ResourceType, Config, Opts) ->
|
||||
recreate_local(deprecated, ResId, ResourceType, Config, Opts).
|
||||
%% end
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
start(Name, Mod, Options) ->
|
||||
case ecpool:start_sup_pool(Name, Mod, Options) of
|
||||
{ok, _} ->
|
||||
?SLOG(info, #{msg => "start_ecpool_ok", pool_name => Name}),
|
||||
?SLOG(info, #{msg => "start_ecpool_ok", pool_name => Name}, #{tag => ?TAG}),
|
||||
ok;
|
||||
{error, {already_started, _Pid}} ->
|
||||
stop(Name),
|
||||
|
@ -46,27 +46,35 @@ start(Name, Mod, Options) ->
|
|||
{error, Reason} ->
|
||||
NReason = parse_reason(Reason),
|
||||
IsDryRun = emqx_resource:is_dry_run(Name),
|
||||
?SLOG(?LOG_LEVEL(IsDryRun), #{
|
||||
?SLOG(
|
||||
?LOG_LEVEL(IsDryRun),
|
||||
#{
|
||||
msg => "start_ecpool_error",
|
||||
resource_id => Name,
|
||||
reason => NReason
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
{error, {start_pool_failed, Name, NReason}}
|
||||
end.
|
||||
|
||||
stop(Name) ->
|
||||
case ecpool:stop_sup_pool(Name) of
|
||||
ok ->
|
||||
?SLOG(info, #{msg => "stop_ecpool_ok", pool_name => Name});
|
||||
?SLOG(info, #{msg => "stop_ecpool_ok", pool_name => Name}, #{tag => ?TAG});
|
||||
{error, not_found} ->
|
||||
ok;
|
||||
{error, Reason} ->
|
||||
IsDryRun = emqx_resource:is_dry_run(Name),
|
||||
?SLOG(?LOG_LEVEL(IsDryRun), #{
|
||||
?SLOG(
|
||||
?LOG_LEVEL(IsDryRun),
|
||||
#{
|
||||
msg => "stop_ecpool_failed",
|
||||
resource_id => Name,
|
||||
reason => Reason
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
error({stop_pool_failed, Name, Reason})
|
||||
end.
|
||||
|
||||
|
|
|
@ -3506,7 +3506,7 @@ gauge_metric_set_fns() ->
|
|||
].
|
||||
|
||||
create(Id, Group, Type, Config) ->
|
||||
emqx_resource:create_local(test, Id, Group, Type, Config).
|
||||
emqx_resource:create_local(test, Id, Group, Type, Config, #{}).
|
||||
|
||||
create(Id, Group, Type, Config, Opts) ->
|
||||
emqx_resource:create_local(test, Id, Group, Type, Config, Opts).
|
||||
|
|
Loading…
Reference in New Issue