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