Skip to content

Commit b7e538d

Browse files
committed
RMQ-1263: An attempt to make shovel status tuple handling forward compatible
1 parent 23e1bdf commit b7e538d

5 files changed

+61
-35
lines changed

deps/rabbitmq_shovel/src/Elixir.RabbitMQ.CLI.Ctl.Commands.DeleteShovelCommand.erl

+23-18
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,32 @@ run([Name], #{node := Node, vhost := VHost}) ->
7676
undefined ->
7777
try_force_removing(Node, VHost, Name, ActingUser),
7878
{error, rabbit_data_coercion:to_binary(ErrMsg)};
79-
Match ->
80-
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} = Match,
81-
{_, HostingNode} = lists:keyfind(node, 1, Opts),
82-
case rabbit_misc:rpc_call(
83-
HostingNode, rabbit_shovel_util, delete_shovel, [VHost, Name, ActingUser]) of
84-
{badrpc, _} = Error ->
85-
Error;
86-
{error, not_found} ->
87-
ErrMsg = rabbit_misc:format("Shovel with the given name was not found "
88-
"on the target node '~ts' and/or virtual host '~ts'. "
89-
"It may be failing to connect and report its state, will delete its runtime parameter...",
90-
[Node, VHost]),
91-
try_force_removing(HostingNode, VHost, Name, ActingUser),
92-
{error, rabbit_data_coercion:to_binary(ErrMsg)};
93-
ok ->
94-
_ = try_clearing_runtime_parameter(Node, VHost, Name, ActingUser),
95-
ok
96-
end
79+
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} ->
80+
delete_shovel(ErrMsg, VHost, Opts, Name, Node, ActingUser);
81+
%% Forward compatibility with >= 4.1
82+
{{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} ->
83+
delete_shovel(ErrMsg, VHost, Opts, Name, Node, ActingUser)
9784
end
9885
end.
9986

87+
delete_shovel(ErrMsg, VHost, Opts, Name, Node, ActingUser) ->
88+
{_, HostingNode} = lists:keyfind(node, 1, Opts),
89+
case rabbit_misc:rpc_call(
90+
HostingNode, rabbit_shovel_util, delete_shovel, [VHost, Name, ActingUser]) of
91+
{badrpc, _} = Error ->
92+
Error;
93+
{error, not_found} ->
94+
ErrMsg = rabbit_misc:format("Shovel with the given name was not found "
95+
"on the target node '~ts' and/or virtual host '~ts'. "
96+
"It may be failing to connect and report its state, will delete its runtime parameter...",
97+
[Node, VHost]),
98+
try_force_removing(HostingNode, VHost, Name, ActingUser),
99+
{error, rabbit_data_coercion:to_binary(ErrMsg)};
100+
ok ->
101+
_ = try_clearing_runtime_parameter(Node, VHost, Name, ActingUser),
102+
ok
103+
end.
104+
100105
switches() ->
101106
[].
102107

deps/rabbitmq_shovel/src/Elixir.RabbitMQ.CLI.Ctl.Commands.RestartShovelCommand.erl

+16-11
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,25 @@ run([Name], #{node := Node, vhost := VHost}) ->
6262
case rabbit_shovel_status:find_matching_shovel(VHost, Name, Xs) of
6363
undefined ->
6464
{error, rabbit_data_coercion:to_binary(ErrMsg)};
65-
Match ->
66-
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} = Match,
67-
{_, HostingNode} = lists:keyfind(node, 1, Opts),
68-
case rabbit_misc:rpc_call(
69-
HostingNode, rabbit_shovel_util, restart_shovel, [VHost, Name]) of
70-
{badrpc, _} = Error ->
71-
Error;
72-
{error, not_found} ->
73-
{error, rabbit_data_coercion:to_binary(ErrMsg)};
74-
ok -> ok
75-
end
65+
{{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} ->
66+
restart_shovel(ErrMsg, VHost, Name, Opts);
67+
%% Forward compatibility with >= 4.1
68+
{{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} ->
69+
restart_shovel(ErrMsg, VHost, Name, Opts)
7670
end
7771
end.
7872

73+
restart_shovel(ErrMsg, VHost, Name, Opts) ->
74+
{_, HostingNode} = lists:keyfind(node, 1, Opts),
75+
case rabbit_misc:rpc_call(
76+
HostingNode, rabbit_shovel_util, restart_shovel, [VHost, Name]) of
77+
{badrpc, _} = Error ->
78+
Error;
79+
{error, not_found} ->
80+
{error, rabbit_data_coercion:to_binary(ErrMsg)};
81+
ok -> ok
82+
end.
83+
7984
output(Output, _Opts) ->
8085
'Elixir.RabbitMQ.CLI.DefaultOutput':output(Output).
8186

deps/rabbitmq_shovel/src/Elixir.RabbitMQ.CLI.Ctl.Commands.ShovelStatusCommand.erl

+12-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,18 @@ aliases() ->
7575
[].
7676

7777
output({stream, ShovelStatus}, _Opts) ->
78-
Formatted = [fmt_name(Name,
79-
fmt_status(Status,
80-
#{type => Type,
81-
last_changed => fmt_ts(Timestamp)}))
82-
|| {Name, Type, Status, Timestamp} <- ShovelStatus],
78+
Formatted = lists:map(fun ({Name, Type, Status, Timestamp}) ->
79+
fmt_name(Name,
80+
fmt_status(Status,
81+
#{type => Type,
82+
last_changed => fmt_ts(Timestamp)}));
83+
%% Forward compatibility with >= 4.1
84+
({Name, Type, Status, _Metrics, Timestamp}) ->
85+
fmt_name(Name,
86+
fmt_status(Status,
87+
#{type => Type,
88+
last_changed => fmt_ts(Timestamp)}))
89+
end, ShovelStatus),
8390
{stream, Formatted};
8491
output(E, _Opts) ->
8592
'Elixir.RabbitMQ.CLI.DefaultOutput':output(E).

deps/rabbitmq_shovel/src/rabbit_shovel_status.erl

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ inject_node_info(Node, Shovels) ->
191191
find_matching_shovel(VHost, Name, Shovels) ->
192192
case lists:filter(
193193
fun ({{V, S}, _Kind, _Status, _}) ->
194-
VHost =:= V andalso Name =:= S
194+
VHost =:= V andalso Name =:= S;
195+
%% Forward compatibility with >= 4.1
196+
({{V, S}, _Kind, _Status, _Metrics, _}) ->
197+
VHost =:= V andalso Name =:= S
195198
end, Shovels) of
196199
[] -> undefined;
197200
[S | _] -> S

deps/rabbitmq_shovel_management/src/rabbit_shovel_mgmt_util.erl

+6
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ status(Node) ->
4343
end.
4444

4545
format(Node, {Name, Type, Info, TS}) ->
46+
[{node, Node}, {timestamp, format_ts(TS)}] ++
47+
format_name(Type, Name) ++
48+
format_info(Info);
49+
%% Forward compatibility with >= 4.1
50+
format(Node, {Name, Type, Info, _Metrics, TS}) ->
4651
[{node, Node}, {timestamp, format_ts(TS)}] ++
4752
format_name(Type, Name) ++
4853
format_info(Info).
4954

55+
5056
format_name(static, Name) -> [{name, Name},
5157
{type, static}];
5258
format_name(dynamic, {VHost, Name}) -> [{name, Name},

0 commit comments

Comments
 (0)