66
77defmodule RabbitMQ.CLI.Upgrade.Commands.AwaitOnlineSynchronizedMirrorCommand do
88 alias RabbitMQ.CLI.Core.DocGuide
9+ import RabbitMQ.CLI.Core.Config , only: [ output_less?: 1 ]
910
1011 @ behaviour RabbitMQ.CLI.CommandBehaviour
1112
@@ -28,19 +29,38 @@ defmodule RabbitMQ.CLI.Upgrade.Commands.AwaitOnlineSynchronizedMirrorCommand do
2829
2930 def run ( [ ] , % { node: node_name , timeout: timeout } ) do
3031 rpc_timeout = timeout + 500
31- case :rabbit_misc . rpc_call ( node_name , :rabbit_upgrade_preparation , :await_online_synchronised_mirrors , [ timeout ] , rpc_timeout ) do
32- { :error , _ } = err -> err
33- { :error , _ , _ } = err -> err
34- { :badrpc , _ } = err -> err
32+ case :rabbit_misc . rpc_call ( node_name , :rabbit_nodes , :is_single_node_cluster , [ ] , rpc_timeout ) do
33+ # if target node is the only one in the cluster, the command makes little sense
34+ # and false positives can be misleading
35+ true -> { :ok , :single_node_cluster }
36+ false ->
37+ case :rabbit_misc . rpc_call ( node_name , :rabbit_upgrade_preparation , :await_online_synchronised_mirrors , [ timeout ] , rpc_timeout ) do
38+ { :error , _ } = err -> err
39+ { :error , _ , _ } = err -> err
40+ { :badrpc , _ } = err -> err
3541
36- true -> :ok
37- false -> { :error , "time is up, no synchronised mirror came online for at least some classic mirrored queues" }
42+ true -> :ok
43+ false -> { :error , "time is up, no synchronised mirror came online for at least some classic mirrored queues" }
44+ end
45+ other -> other
3846 end
3947 end
4048
49+ def output ( { :ok , :single_node_cluster } , % { formatter: "json" } ) do
50+ { :ok , % {
51+ "result" => "ok" ,
52+ "message" => "Target node seems to be the only one in a single node cluster, the check does not apply"
53+ } }
54+ end
4155 def output ( { :error , msg } , % { node: node_name , formatter: "json" } ) do
4256 { :error , % { "result" => "error" , "node" => node_name , "message" => msg } }
4357 end
58+ def output ( { :ok , :single_node_cluster } , opts ) do
59+ case output_less? ( opts ) do
60+ true -> :ok ;
61+ false -> { :ok , "Target node seems to be the only one in a single node cluster, the command does not apply" }
62+ end
63+ end
4464 use RabbitMQ.CLI.DefaultOutput
4565
4666 def usage , do: "await_online_synchronized_mirror"
0 commit comments