Skip to content

Commit

Permalink
CLI: Finish check_if_any_deprecated_features_are_used implementation
Browse files Browse the repository at this point in the history
[Why]
The previous implementation bypassed the deprecated features subsystem.
It only cared about classic mirrored queues and called some
queue-related code directly to determine if this specific feature was
used.

[How]
The command code is simplified by calling the deprecated subsystem to
list used deprecated features instead.

References #12619.
  • Loading branch information
dumbbell committed Nov 11, 2024
1 parent 38bc831 commit ddaea6f
Showing 1 changed file with 18 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,30 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.CheckIfAnyDeprecatedFeaturesAreUsedC
use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning

def run([], opts) do
are_deprecated_features_used = %{
:classic_queue_mirroring => is_used_classic_queue_mirroring(opts)
}

deprecated_features_list =
Enum.reduce(
are_deprecated_features_used,
[],
fn
{_feat, _result}, {:badrpc, _} = acc ->
acc

{feat, result}, acc ->
case result do
{:badrpc, _} = err -> err
{:error, _} = err -> err
true -> [feat | acc]
false -> acc
end
end
)
def run([], %{node: node_name, timeout: timeout}) do
deprecated_features_list = :rabbit_misc.rpc_call(
node_name,
:rabbit_deprecated_features,
:list,
[:used],
timeout
)

# health checks return true if they pass
case deprecated_features_list do
{:badrpc, _} = err -> err
{:error, _} = err -> err
[] -> true
xs when is_list(xs) -> {false, deprecated_features_list}
{:badrpc, _} = err ->
err
{:error, _} = err ->
err
_ ->
names = Enum.sort(Map.keys(deprecated_features_list))
case names do
[] -> true
_ -> {false, names}
end
end
end

def is_used_classic_queue_mirroring(%{node: node_name, timeout: timeout}) do
:rabbit_misc.rpc_call(
node_name,
:rabbit_mirror_queue_misc,
:are_cmqs_used,
[:none],
timeout
)
end

def output(true, %{formatter: "json"}) do
{:ok, %{"result" => "ok"}}
end
Expand Down

0 comments on commit ddaea6f

Please sign in to comment.