refactor(ft): prefer plain `files` over `exports` in generic APIs
So there's no more `exports` magically becomings `files` in the REST API which was slightly confusing.
This commit is contained in:
parent
c24c7eca34
commit
45e3b62dc4
|
@ -67,9 +67,9 @@ schema("/file_transfer/files") ->
|
|||
}.
|
||||
|
||||
'/file_transfer/files'(get, #{}) ->
|
||||
case emqx_ft_storage:exports() of
|
||||
{ok, Transfers} ->
|
||||
{200, #{<<"files">> => lists:map(fun format_export_info/1, Transfers)}};
|
||||
case emqx_ft_storage:files() of
|
||||
{ok, Files} ->
|
||||
{200, #{<<"files">> => lists:map(fun format_file_info/1, Files)}};
|
||||
{error, _} ->
|
||||
{503, error_msg('SERVICE_UNAVAILABLE', <<"Service unavailable">>)}
|
||||
end.
|
||||
|
@ -84,7 +84,7 @@ roots() ->
|
|||
%% Helpers
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
format_export_info(
|
||||
format_file_info(
|
||||
Info = #{
|
||||
name := Name,
|
||||
size := Size,
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
store_segment/2,
|
||||
assemble/2,
|
||||
|
||||
exports/0,
|
||||
files/0,
|
||||
|
||||
with_storage_type/2,
|
||||
with_storage_type/3
|
||||
|
@ -34,13 +34,13 @@
|
|||
-type storage() :: emqx_config:config().
|
||||
|
||||
-export_type([assemble_callback/0]).
|
||||
-export_type([export_info/0]).
|
||||
-export_type([file_info/0]).
|
||||
-export_type([export_data/0]).
|
||||
-export_type([reader/0]).
|
||||
|
||||
-type assemble_callback() :: fun((ok | {error, term()}) -> any()).
|
||||
|
||||
-type export_info() :: #{
|
||||
-type file_info() :: #{
|
||||
transfer := emqx_ft:transfer(),
|
||||
name := file:name(),
|
||||
size := _Bytes :: non_neg_integer(),
|
||||
|
@ -68,8 +68,8 @@
|
|||
-callback assemble(storage(), emqx_ft:transfer(), _Size :: emqx_ft:bytes()) ->
|
||||
ok | {async, pid()} | {error, term()}.
|
||||
|
||||
-callback exports(storage()) ->
|
||||
{ok, [export_info()]} | {error, term()}.
|
||||
-callback files(storage()) ->
|
||||
{ok, [file_info()]} | {error, term()}.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% API
|
||||
|
@ -104,11 +104,11 @@ assemble(Transfer, Size) ->
|
|||
Mod = mod(),
|
||||
Mod:assemble(storage(), Transfer, Size).
|
||||
|
||||
-spec exports() ->
|
||||
{ok, [export_info()]} | {error, term()}.
|
||||
exports() ->
|
||||
-spec files() ->
|
||||
{ok, [file_info()]} | {error, term()}.
|
||||
files() ->
|
||||
Mod = mod(),
|
||||
Mod:exports(storage()).
|
||||
Mod:files(storage()).
|
||||
|
||||
-spec with_storage_type(atom(), atom() | function()) -> any().
|
||||
with_storage_type(Type, Fun) ->
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
ok | {error, _Reason}.
|
||||
|
||||
-callback list(options()) ->
|
||||
{ok, [emqx_ft_storage:export_info()]} | {error, _Reason}.
|
||||
{ok, [emqx_ft_storage:file_info()]} | {error, _Reason}.
|
||||
|
||||
%%
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
-export([get_subdir/2]).
|
||||
-export([get_subdir/3]).
|
||||
|
||||
-export([exports/1]).
|
||||
-export([files/1]).
|
||||
|
||||
-export_type([storage/0]).
|
||||
-export_type([filefrag/1]).
|
||||
|
@ -209,7 +209,7 @@ assemble(Storage, Transfer, Size) ->
|
|||
|
||||
%%
|
||||
|
||||
exports(Storage) ->
|
||||
files(Storage) ->
|
||||
emqx_ft_storage_exporter:list(Storage).
|
||||
|
||||
%%
|
||||
|
|
|
@ -29,7 +29,7 @@ introduced_in() ->
|
|||
"5.0.17".
|
||||
|
||||
-spec list_exports([node()]) ->
|
||||
emqx_rpc:erpc_multicall([emqx_ft_storage:export_info()]).
|
||||
emqx_rpc:erpc_multicall([emqx_ft_storage:file_info()]).
|
||||
list_exports(Nodes) ->
|
||||
erpc:multicall(
|
||||
Nodes,
|
||||
|
|
|
@ -216,7 +216,7 @@ t_simple_transfer(Config) ->
|
|||
emqtt:publish(C, mk_fin_topic(FileId, Filesize), <<>>, 1)
|
||||
),
|
||||
|
||||
[Export] = list_exports(?config(clientid, Config)),
|
||||
[Export] = list_files(?config(clientid, Config)),
|
||||
?assertEqual(
|
||||
{ok, iolist_to_binary(Data)},
|
||||
read_export(Export)
|
||||
|
@ -234,7 +234,7 @@ t_nasty_clientids_fileids(_Config) ->
|
|||
ok = lists:foreach(
|
||||
fun({ClientId, FileId}) ->
|
||||
ok = emqx_ft_test_helpers:upload_file(ClientId, FileId, "justfile", ClientId),
|
||||
[Export] = list_exports(ClientId),
|
||||
[Export] = list_files(ClientId),
|
||||
?assertEqual({ok, ClientId}, read_export(Export))
|
||||
end,
|
||||
Transfers
|
||||
|
@ -463,7 +463,7 @@ t_switch_node(Config) ->
|
|||
|
||||
%% Now check consistency of the file
|
||||
|
||||
[Export] = list_exports(ClientId),
|
||||
[Export] = list_files(ClientId),
|
||||
?assertEqual(
|
||||
{ok, iolist_to_binary(Data)},
|
||||
read_export(Export)
|
||||
|
@ -539,7 +539,7 @@ t_unreliable_migrating_client(Config) ->
|
|||
],
|
||||
_Context = run_commands(Commands, Context),
|
||||
|
||||
Exports = list_exports(?config(clientid, Config)),
|
||||
Exports = list_files(?config(clientid, Config)),
|
||||
|
||||
% NOTE
|
||||
% The cluster had 2 assemblers running on two different nodes, because client sent `fin`
|
||||
|
@ -659,9 +659,9 @@ meta(FileName, Data) ->
|
|||
size => byte_size(FullData)
|
||||
}.
|
||||
|
||||
list_exports(ClientId) ->
|
||||
{ok, Exports} = emqx_ft_storage:exports(),
|
||||
[Export || Export = #{transfer := {CId, _}} <- Exports, CId == ClientId].
|
||||
list_files(ClientId) ->
|
||||
{ok, Files} = emqx_ft_storage:files(),
|
||||
[File || File = #{transfer := {CId, _}} <- Files, CId == ClientId].
|
||||
|
||||
read_export(#{path := AbsFilepath}) ->
|
||||
% TODO: only works for the local filesystem exporter right now
|
||||
|
|
|
@ -83,7 +83,7 @@ t_multinode_ready_transfers(Config) ->
|
|||
#{transfer := {<<"c/1">>, <<"f:1">>}, name := "fn1"},
|
||||
#{transfer := {<<"c/2">>, <<"f:2">>}, name := "fn2"}
|
||||
],
|
||||
lists:sort(list_exports(Config))
|
||||
lists:sort(list_files(Config))
|
||||
).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
@ -103,6 +103,6 @@ storage(Config) ->
|
|||
}
|
||||
}.
|
||||
|
||||
list_exports(Config) ->
|
||||
{ok, Exports} = emqx_ft_storage_fs:exports(storage(Config)),
|
||||
Exports.
|
||||
list_files(Config) ->
|
||||
{ok, Files} = emqx_ft_storage_fs:files(storage(Config)),
|
||||
Files.
|
||||
|
|
Loading…
Reference in New Issue