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("typerefl/include/types.hrl").
-include_lib("hocon/include/hoconsc.hrl"). -include_lib("hocon/include/hoconsc.hrl").
-include_lib("emqx/include/logger.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"). -include_lib("emqx_bridge/include/emqx_bridge.hrl").
-import(hoconsc, [mk/2, array/1, enum/1]). -import(hoconsc, [mk/2, array/1, enum/1]).

View File

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

View File

@ -247,13 +247,13 @@ nodes(get, _Params) ->
list_nodes(#{}). list_nodes(#{}).
node(get, #{bindings := #{node := NodeName}}) -> 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}}) -> 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}}) -> 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 %% api apply

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@
-include("emqx_ee_schema_registry.hrl"). -include("emqx_ee_schema_registry.hrl").
-include_lib("hocon/include/hoconsc.hrl"). -include_lib("hocon/include/hoconsc.hrl").
-include_lib("emqx/include/logger.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([ -export([
namespace/0, namespace/0,