refactor: rename emqx_api_lib to emqx_utils_api

This commit is contained in:
Stefan Strigler 2023-04-13 14:50:30 +02:00
parent 9c11bfce80
commit d0df086c80
8 changed files with 16 additions and 15 deletions

View File

@ -20,7 +20,7 @@
-include_lib("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/emqx_api_lib.hrl").
-include_lib("emqx_utils/include/emqx_utils_api.hrl").
-include_lib("emqx_bridge/include/emqx_bridge.hrl").
-import(hoconsc, [mk/2, array/1, enum/1]).

View File

@ -122,7 +122,7 @@ fields(sampler_current) ->
monitor(get, #{query_string := QS, bindings := Bindings}) ->
Latest = maps:get(<<"latest">>, QS, infinity),
RawNode = maps:get(node, Bindings, <<"all">>),
emqx_api_lib:with_node_or_cluster(RawNode, dashboard_samplers_fun(Latest)).
emqx_utils_api:with_node_or_cluster(RawNode, dashboard_samplers_fun(Latest)).
dashboard_samplers_fun(Latest) ->
fun(NodeOrCluster) ->
@ -133,10 +133,10 @@ dashboard_samplers_fun(Latest) ->
end.
monitor_current(get, #{bindings := []}) ->
emqx_api_lib:with_node_or_cluster(erlang:node(), fun emqx_dashboard_monitor:current_rate/1);
emqx_utils_api:with_node_or_cluster(erlang:node(), fun emqx_dashboard_monitor:current_rate/1);
monitor_current(get, #{bindings := Bindings}) ->
RawNode = maps:get(node, Bindings, <<"all">>),
emqx_api_lib:with_node_or_cluster(RawNode, fun current_rate/1).
emqx_utils_api:with_node_or_cluster(RawNode, fun current_rate/1).
current_rate(Node) ->
case emqx_dashboard_monitor:current_rate(Node) of

View File

@ -247,13 +247,13 @@ nodes(get, _Params) ->
list_nodes(#{}).
node(get, #{bindings := #{node := NodeName}}) ->
emqx_api_lib:with_node(NodeName, to_ok_result_fun(fun get_node/1)).
emqx_utils_api:with_node(NodeName, to_ok_result_fun(fun get_node/1)).
node_metrics(get, #{bindings := #{node := NodeName}}) ->
emqx_api_lib:with_node(NodeName, to_ok_result_fun(fun emqx_mgmt:get_metrics/1)).
emqx_utils_api:with_node(NodeName, to_ok_result_fun(fun emqx_mgmt:get_metrics/1)).
node_stats(get, #{bindings := #{node := NodeName}}) ->
emqx_api_lib:with_node(NodeName, to_ok_result_fun(fun emqx_mgmt:get_stats/1)).
emqx_utils_api:with_node(NodeName, to_ok_result_fun(fun emqx_mgmt:get_stats/1)).
%%--------------------------------------------------------------------
%% api apply

View File

@ -5,6 +5,7 @@
{vsn, "5.0.0"},
{modules, [
emqx_utils,
emqx_utils_api,
emqx_utils_binary,
emqx_utils_ets,
emqx_utils_json,

View File

@ -14,14 +14,14 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_api_lib).
-module(emqx_utils_api).
-export([
with_node/2,
with_node_or_cluster/2
]).
-include("emqx_api_lib.hrl").
-include("emqx_utils_api.hrl").
-define(NODE_NOT_FOUND(NODE), ?NOT_FOUND(<<"Node not found: ", NODE/binary>>)).

View File

@ -14,12 +14,12 @@
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_api_lib_SUITE).
-module(emqx_utils_api_SUITE).
-compile(export_all).
-compile(nowarn_export_all).
-include("emqx_api_lib.hrl").
-include("emqx_utils_api.hrl").
-include_lib("eunit/include/eunit.hrl").
-define(DUMMY, dummy_module).
@ -45,14 +45,14 @@ end_per_testcase(_Case, _Config) ->
meck:unload(?DUMMY).
t_with_node(_) ->
test_with(fun emqx_api_lib:with_node/2, [<<"all">>]).
test_with(fun emqx_utils_api:with_node/2, [<<"all">>]).
t_with_node_or_cluster(_) ->
test_with(fun emqx_api_lib:with_node_or_cluster/2, []),
test_with(fun emqx_utils_api:with_node_or_cluster/2, []),
meck:reset(?DUMMY),
?assertEqual(
?OK(success),
emqx_api_lib:with_node_or_cluster(
emqx_utils_api:with_node_or_cluster(
<<"all">>,
fun ?DUMMY:expect_success/1
)

View File

@ -8,7 +8,7 @@
-include("emqx_ee_schema_registry.hrl").
-include_lib("hocon/include/hoconsc.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/emqx_api_lib.hrl").
-include_lib("emqx_utils/include/emqx_utils_api.hrl").
-export([
namespace/0,