|
@@ -245,6 +245,24 @@ create_resource(#{type := Type, config := Config0} = Params) ->
|
|
|
{error, {resource_type_not_found, Type}}
|
|
{error, {resource_type_not_found, Type}}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
|
|
+update_resource(#{id := Id, type := Type, config := NewConfig, description := Description}
|
|
|
|
|
+ = NewResource) ->
|
|
|
|
|
+ case emqx_rule_registry:find_resource_type(Type) of
|
|
|
|
|
+ {ok, #resource_type{on_create = {Module, Create},
|
|
|
|
|
+ params_spec = ParamSpec}} ->
|
|
|
|
|
+ Config = emqx_rule_validator:validate_params(NewConfig, ParamSpec),
|
|
|
|
|
+ delete_resource(Id),
|
|
|
|
|
+ emqx_rule_registry:add_resource(#resource{id = Id,
|
|
|
|
|
+ config = Config,
|
|
|
|
|
+ type = Type,
|
|
|
|
|
+ description = Description,
|
|
|
|
|
+ created_at = erlang:system_time(millisecond)}),
|
|
|
|
|
+ catch cluster_call(init_resource, [Module, Create, Id, Config]),
|
|
|
|
|
+ {ok, NewResource};
|
|
|
|
|
+ not_found ->
|
|
|
|
|
+ {error, {resource_type_not_found, Type}}
|
|
|
|
|
+ end.
|
|
|
|
|
+
|
|
|
-spec(start_resource(resource_id()) -> ok | {error, Reason :: term()}).
|
|
-spec(start_resource(resource_id()) -> ok | {error, Reason :: term()}).
|
|
|
start_resource(ResId) ->
|
|
start_resource(ResId) ->
|
|
|
case emqx_rule_registry:find_resource(ResId) of
|
|
case emqx_rule_registry:find_resource(ResId) of
|
|
@@ -310,18 +328,6 @@ delete_resource(ResId) ->
|
|
|
{error, {resource_not_found, ResId}}
|
|
{error, {resource_not_found, ResId}}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
-update_resource(#{id := Id,
|
|
|
|
|
- config := Config,
|
|
|
|
|
- type := Type,
|
|
|
|
|
- description := Description,
|
|
|
|
|
- created_at := CreatedAt} = NewResource) ->
|
|
|
|
|
- ok = refresh_resource(#resource{id = Id,
|
|
|
|
|
- config = Config,
|
|
|
|
|
- type = Type,
|
|
|
|
|
- description = Description,
|
|
|
|
|
- created_at = CreatedAt}),
|
|
|
|
|
- create_resource(NewResource).
|
|
|
|
|
-
|
|
|
|
|
%% @doc Ensure resource deleted. `resource_not_found` error is discarded.
|
|
%% @doc Ensure resource deleted. `resource_not_found` error is discarded.
|
|
|
-spec(ensure_resource_deleted(resource_id()) -> ok).
|
|
-spec(ensure_resource_deleted(resource_id()) -> ok).
|
|
|
ensure_resource_deleted(ResId) ->
|
|
ensure_resource_deleted(ResId) ->
|