Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,32 @@ run([Name], #{node := Node, vhost := VHost}) ->
undefined ->
try_force_removing(Node, VHost, Name, ActingUser),
{error, rabbit_data_coercion:to_binary(ErrMsg)};
Match ->
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} = Match,
{_, HostingNode} = lists:keyfind(node, 1, Opts),
case rabbit_misc:rpc_call(
HostingNode, rabbit_shovel_util, delete_shovel, [VHost, Name, ActingUser]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
ErrMsg = rabbit_misc:format("Shovel with the given name was not found "
"on the target node '~ts' and/or virtual host '~ts'. "
"It may be failing to connect and report its state, will delete its runtime parameter...",
[Node, VHost]),
try_force_removing(HostingNode, VHost, Name, ActingUser),
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok ->
_ = try_clearing_runtime_parameter(Node, VHost, Name, ActingUser),
ok
end
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} ->
delete_shovel(ErrMsg, VHost, Opts, Name, Node, ActingUser);
%% Forward compatibility with >= 4.1
{{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} ->
delete_shovel(ErrMsg, VHost, Opts, Name, Node, ActingUser)
end
end.

delete_shovel(ErrMsg, VHost, Opts, Name, Node, ActingUser) ->
{_, HostingNode} = lists:keyfind(node, 1, Opts),
case rabbit_misc:rpc_call(
HostingNode, rabbit_shovel_util, delete_shovel, [VHost, Name, ActingUser]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
ErrMsg = rabbit_misc:format("Shovel with the given name was not found "
"on the target node '~ts' and/or virtual host '~ts'. "
"It may be failing to connect and report its state, will delete its runtime parameter...",
[Node, VHost]),
try_force_removing(HostingNode, VHost, Name, ActingUser),
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok ->
_ = try_clearing_runtime_parameter(Node, VHost, Name, ActingUser),
ok
end.

switches() ->
[].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,25 @@ run([Name], #{node := Node, vhost := VHost}) ->
case rabbit_shovel_status:find_matching_shovel(VHost, Name, Xs) of
undefined ->
{error, rabbit_data_coercion:to_binary(ErrMsg)};
Match ->
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} = Match,
{_, HostingNode} = lists:keyfind(node, 1, Opts),
case rabbit_misc:rpc_call(
HostingNode, rabbit_shovel_util, restart_shovel, [VHost, Name]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok -> ok
end
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} ->
restart_shovel(ErrMsg, VHost, Name, Opts);
%% Forward compatibility with >= 4.1
{{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} ->
restart_shovel(ErrMsg, VHost, Name, Opts)
end
end.

restart_shovel(ErrMsg, VHost, Name, Opts) ->
{_, HostingNode} = lists:keyfind(node, 1, Opts),
case rabbit_misc:rpc_call(
HostingNode, rabbit_shovel_util, restart_shovel, [VHost, Name]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok -> ok
end.

output(Output, _Opts) ->
'Elixir.RabbitMQ.CLI.DefaultOutput':output(Output).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ aliases() ->
[].

output({stream, ShovelStatus}, _Opts) ->
Formatted = [fmt_name(Name,
fmt_status(Status,
#{type => Type,
last_changed => fmt_ts(Timestamp)}))
|| {Name, Type, Status, Timestamp} <- ShovelStatus],
Formatted = lists:map(fun ({Name, Type, Status, Timestamp}) ->
fmt_name(Name,
fmt_status(Status,
#{type => Type,
last_changed => fmt_ts(Timestamp)}));
%% Forward compatibility with >= 4.1
({Name, Type, Status, _Metrics, Timestamp}) ->
fmt_name(Name,
fmt_status(Status,
#{type => Type,
last_changed => fmt_ts(Timestamp)}))
end, ShovelStatus),
{stream, Formatted};
output(E, _Opts) ->
'Elixir.RabbitMQ.CLI.DefaultOutput':output(E).
Expand Down
5 changes: 4 additions & 1 deletion deps/rabbitmq_shovel/src/rabbit_shovel_status.erl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ inject_node_info(Node, Shovels) ->
find_matching_shovel(VHost, Name, Shovels) ->
case lists:filter(
fun ({{V, S}, _Kind, _Status, _}) ->
VHost =:= V andalso Name =:= S
VHost =:= V andalso Name =:= S;
%% Forward compatibility with >= 4.1
({{V, S}, _Kind, _Status, _Metrics, _}) ->
VHost =:= V andalso Name =:= S
end, Shovels) of
[] -> undefined;
[S | _] -> S
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ status(Node) ->
end.

format(Node, {Name, Type, Info, TS}) ->
[{node, Node}, {timestamp, format_ts(TS)}] ++
format_name(Type, Name) ++
format_info(Info);
%% Forward compatibility with >= 4.1
format(Node, {Name, Type, Info, _Metrics, TS}) ->
[{node, Node}, {timestamp, format_ts(TS)}] ++
format_name(Type, Name) ++
format_info(Info).
Expand Down
Loading