diff options
| author | kjnilsson <knilsson@pivotal.io> | 2019-05-23 16:12:32 +0100 |
|---|---|---|
| committer | kjnilsson <knilsson@pivotal.io> | 2019-05-23 16:12:32 +0100 |
| commit | ee12c561b5f073d4a3b5a19863ef582c34c7016e (patch) | |
| tree | ca34f5b22a6f2aa34b0de34723cec7076c15f719 | |
| parent | a4033d826ed4f7546019753cb98b1cdca1939210 (diff) | |
| download | rabbitmq-server-git-ee12c561b5f073d4a3b5a19863ef582c34c7016e.tar.gz | |
Improve quorum_status command
Make it compatible with the pretty table formatter.
| -rw-r--r-- | src/rabbit_quorum_queue.erl | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/src/rabbit_quorum_queue.erl b/src/rabbit_quorum_queue.erl index 8258584e3c..75bd9515f1 100644 --- a/src/rabbit_quorum_queue.erl +++ b/src/rabbit_quorum_queue.erl @@ -644,7 +644,6 @@ cluster_state(Name) -> end. -spec status(rabbit_types:vhost(), Name :: rabbit_misc:resource_name()) -> rabbit_types:infos() | {error, term()}. - status(Vhost, QueueName) -> %% Handle not found queues QName = #resource{virtual_host = Vhost, name = QueueName, kind = queue}, @@ -653,19 +652,52 @@ status(Vhost, QueueName) -> {ok, Q} when ?amqqueue_is_classic(Q) -> {error, classic_queue_not_supported}; {ok, Q} when ?amqqueue_is_quorum(Q) -> - {_, Leader} = amqqueue:get_pid(Q), Nodes = amqqueue:get_quorum_nodes(Q), - Info = [{leader, Leader}, {members, Nodes}], - case ets:lookup(ra_state, RName) of - [{_, State}] -> - [{local_state, State} | Info]; - [] -> - Info - end; + [begin + case get_sys_status({RName, N}) of + {ok, Sys} -> + {_, M} = lists:keyfind(ra_server_state, 1, Sys), + {_, RaftState} = lists:keyfind(raft_state, 1, Sys), + #{commit_index := Commit, + machine_version := MacVer, + current_term := Term, + log := #{last_index := Last, + snapshot_index := SnapIdx}} = M, + [{<<"Node Name">>, N}, + {<<"Raft State">>, RaftState}, + {<<"Log Index">>, Last}, + {<<"Commit Index">>, Commit}, + {<<"Snapshot Index">>, SnapIdx}, + {<<"Term">>, Term}, + {<<"Machine Version">>, MacVer} + ]; + {error, Err} -> + [{<<"Node Name">>, N}, + {<<"Raft State">>, Err}, + {<<"Log Index">>, <<>>}, + {<<"Commit Index">>, <<>>}, + {<<"Snapshot Index">>, <<>>}, + {<<"Term">>, <<>>}, + {<<"Machine Version">>, <<>>} + ] + end + end || N <- Nodes]; {error, not_found} = E -> E end. +get_sys_status(Proc) -> + try lists:nth(5, element(4, sys:get_status(Proc))) of + Sys -> {ok, Sys} + catch + _:Err when is_tuple(Err) -> + {error, element(1, Err)}; + _:_ -> + {error, other} + + end. + + add_member(VHost, Name, Node) -> QName = #resource{virtual_host = VHost, name = Name, kind = queue}, case rabbit_amqqueue:lookup(QName) of |
