Skip to content

Commit 41d89e5

Browse files
committed
CLI: force_standalone_khepri_boot command
1 parent ea79e42 commit 41d89e5

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

deps/rabbit/test/clustering_management_SUITE.erl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ groups() ->
100100
start_nodes_in_stop_order,
101101
start_nodes_in_stop_order_with_force_boot
102102
]}
103+
]},
104+
{clustered_3_nodes, [],
105+
[{cluster_size_3, [], [
106+
force_standalone_boot
107+
]}
103108
]}
104109
]}
105110
].
@@ -1222,6 +1227,23 @@ start_nodes_in_stop_order_with_force_boot(Config) ->
12221227
ok = rabbit_ct_broker_helpers:start_node(Config, Bunny),
12231228
assert_clustered([Rabbit, Hare, Bunny]).
12241229

1230+
%% TODO test force_standalone after restarting this last node
1231+
force_standalone_boot(Config) ->
1232+
[Rabbit, Hare, Bunny] = cluster_members(Config),
1233+
1234+
assert_cluster_status({[Rabbit, Hare, Bunny], [Rabbit, Hare, Bunny], [Rabbit, Hare, Bunny]},
1235+
[Rabbit, Hare, Bunny]),
1236+
1237+
ok = rabbit_ct_broker_helpers:stop_node(Config, Hare),
1238+
ok = rabbit_ct_broker_helpers:stop_node(Config, Bunny),
1239+
ok = force_standalone_khepri_boot(Rabbit),
1240+
1241+
assert_cluster_status({[Rabbit], [Rabbit], [Rabbit, Hare, Bunny],
1242+
[Rabbit, Hare, Bunny], [Rabbit]},
1243+
[Rabbit]),
1244+
1245+
ok.
1246+
12251247
%% ----------------------------------------------------------------------------
12261248
%% Internal utils
12271249
%% ----------------------------------------------------------------------------
@@ -1368,6 +1390,9 @@ change_cluster_node_type(Node, Type) ->
13681390
update_cluster_nodes(Node, DiscoveryNode) ->
13691391
rabbit_control_helper:command(update_cluster_nodes, Node, [atom_to_list(DiscoveryNode)]).
13701392

1393+
force_standalone_khepri_boot(Node) ->
1394+
rabbit_control_helper:command(force_standalone_khepri_boot, Node, []).
1395+
13711396
stop_join_start(Node, ClusterTo, Ram) ->
13721397
ok = stop_app(Node),
13731398
ok = join_cluster(Node, ClusterTo, Ram),
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## This Source Code Form is subject to the terms of the Mozilla Public
2+
## License, v. 2.0. If a copy of the MPL was not distributed with this
3+
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
##
5+
## Copyright (c) 2007-2023 VMware, Inc. or its affiliates. All rights reserved.
6+
7+
defmodule RabbitMQ.CLI.Ctl.Commands.ForceStandaloneKhepriBootCommand do
8+
alias RabbitMQ.CLI.Core.{Config, DocGuide}
9+
10+
@behaviour RabbitMQ.CLI.CommandBehaviour
11+
12+
use RabbitMQ.CLI.Core.MergesNoDefaults
13+
use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
14+
15+
def run([], %{node: node_name} = opts) do
16+
ret =
17+
:rabbit_misc.rpc_call(node_name, :rabbit_khepri, :force_shrink_member_to_current_member, [])
18+
19+
case ret do
20+
{:badrpc, {:EXIT, {:undef, _}}} ->
21+
{:error, RabbitMQ.CLI.Core.ExitCodes.exit_usage(),
22+
"This command is not supported by node #{node_name}"}
23+
24+
_ ->
25+
ret
26+
end
27+
end
28+
29+
use RabbitMQ.CLI.DefaultOutput
30+
31+
def usage, do: "force_standalone_khepri_boot"
32+
33+
def usage_doc_guides() do
34+
[
35+
DocGuide.clustering()
36+
]
37+
end
38+
39+
def help_section(), do: :cluster_management
40+
41+
def description(),
42+
do: "Forces node to start as a standalone node"
43+
44+
def banner(_, _), do: nil
45+
end

0 commit comments

Comments
 (0)