1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved.
-module('Elixir.RabbitMQ.CLI.Ctl.Commands.DecommissionMqttNodeCommand').
-include("rabbit_mqtt.hrl").
-behaviour('Elixir.RabbitMQ.CLI.CommandBehaviour').
-export([scopes/0,
switches/0,
aliases/0,
usage/0,
usage_doc_guides/0,
banner/2,
validate/2,
merge_defaults/2,
run/2,
output/2,
description/0,
help_section/0]).
scopes() -> [ctl].
switches() -> [].
aliases() -> [].
description() -> <<"Removes cluster member and permanently deletes its cluster-wide MQTT state">>.
help_section() ->
{plugin, mqtt}.
validate([], _Opts) ->
{validation_failure, not_enough_args};
validate([_, _ | _], _Opts) ->
{validation_failure, too_many_args};
validate([_], _) ->
ok.
merge_defaults(Args, Opts) ->
{Args, Opts}.
usage() ->
<<"decommission_mqtt_node <node>">>.
usage_doc_guides() ->
[?MQTT_GUIDE_URL].
run([Node], #{node := NodeName,
timeout := Timeout}) ->
case rabbit_misc:rpc_call(NodeName, rabbit_mqtt_collector, leave, [Node], Timeout) of
{badrpc, _} = Error ->
Error;
nodedown ->
{ok, list_to_binary(io_lib:format("Node ~s is down but has been successfully removed"
" from the cluster", [Node]))};
Result ->
%% 'ok' or 'timeout'
%% TODO: Ra will timeout if the node is not a cluster member - should this be fixed??
Result
end.
banner([Node], _) -> list_to_binary(io_lib:format("Removing node ~s from the list of MQTT nodes...", [Node])).
output(Result, _Opts) ->
'Elixir.RabbitMQ.CLI.DefaultOutput':output(Result).
|