From: Gu Zhongyan Date: Mon, 5 Mar 2018 09:55:36 +0000 (+0800) Subject: mon: 'node ls' mgr support X-Git-Tag: v13.0.2~56^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e8436e2bed6bcbc35fcccc8582aca5fc7d8b64c9;p=ceph-ci.git mon: 'node ls' mgr support mgr is not included in 'node ls' add mgr support in 'node ls' Signed-off-by: Gu Zhongyan --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 2f01b64ba09..6d8dc36a466 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -725,7 +725,7 @@ function test_mon_misc() ceph time-sync-status ceph node ls - for t in mon osd mds ; do + for t in mon osd mds mgr ; do ceph node ls $t done diff --git a/src/common/util.cc b/src/common/util.cc index 3f454f93f70..51bd8b17ea9 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -303,6 +303,21 @@ void dump_services(Formatter* f, const map >& services, const f->close_section(); } +void dump_services(Formatter* f, const map >& services, const char* type) +{ + assert(f); + + f->open_object_section(type); + for (const auto& host : services) { + f->open_array_section(host.first.c_str()); + const auto& hosted = host.second; + for (const auto& s : hosted) { + f->dump_string(type, s); + } + f->close_section(); + } + f->close_section(); +} // If non-printable characters found then convert bufferlist to // base64 encoded string indicating whether it did. diff --git a/src/include/util.h b/src/include/util.h index 4b27cc1f3e3..7c7a4a54b85 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -83,6 +83,11 @@ void collect_sys_info(map *m, CephContext *cct); /// @param services a map from hostname to a list of service id hosted by this host /// @param type the service type of given @p services, for example @p osd or @p mon. void dump_services(Formatter* f, const map >& services, const char* type); +/// dump service names grouped by their host to the specified formatter +/// @param f formatter for the output +/// @param services a map from hostname to a list of service name hosted by this host +/// @param type the service type of given @p services, for example @p osd or @p mon. +void dump_services(Formatter* f, const map >& services, const char* type); string cleanbin(bufferlist &bl, bool &b64); string cleanbin(string &str); diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index 4f3976cf40c..945a3a2189f 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -932,7 +932,7 @@ void MgrMonitor::on_shutdown() } int MgrMonitor::load_metadata(const string& name, std::map& m, - ostream *err) + ostream *err) const { bufferlist bl; int r = mon->store->get(MGR_METADATA_PREFIX, name, bl); @@ -987,6 +987,28 @@ int MgrMonitor::dump_metadata(const string& name, Formatter *f, ostream *err) return 0; } +void MgrMonitor::print_nodes(Formatter *f) const +{ + assert(f); + + std::map > mgrs; // hostname => mgr + auto ls = map.get_all_names(); + for (auto& name : ls) { + std::map meta; + if (load_metadata(name, meta, nullptr)) { + continue; + } + auto hostname = meta.find("hostname"); + if (hostname == meta.end()) { + // not likely though + continue; + } + mgrs[hostname->second].push_back(name); + } + + dump_services(f, mgrs, "mgr"); +} + const std::vector &MgrMonitor::get_command_descs() const { if (command_descs.empty()) { diff --git a/src/mon/MgrMonitor.h b/src/mon/MgrMonitor.h index 40d40c0a7a1..d73b1f26dd9 100644 --- a/src/mon/MgrMonitor.h +++ b/src/mon/MgrMonitor.h @@ -111,8 +111,9 @@ public: const std::vector &get_command_descs() const; int load_metadata(const string& name, std::map& m, - ostream *err); + ostream *err) const; int dump_metadata(const string& name, Formatter *f, ostream *err); + void print_nodes(Formatter *f) const; void count_metadata(const string& field, Formatter *f); void count_metadata(const string& field, std::map *out); diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index 0f1729d4f9a..f4424197681 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -242,7 +242,7 @@ COMMAND_WITH_FLAG("version", "show mon daemon version", "mon", "r", "cli,rest", FLAG(NOFORWARD)) COMMAND("node ls " \ - "name=type,type=CephChoices,strings=all|osd|mon|mds,req=false", + "name=type,type=CephChoices,strings=all|osd|mon|mds|mgr,req=false", "list all nodes in cluster [type]", "mon", "r", "cli,rest") /* * Monitor-specific commands under module 'mon' diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index df0c83adbf3..10520bcb8d5 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -3277,6 +3277,7 @@ void Monitor::handle_command(MonOpRequestRef op) print_nodes(f.get(), ds); osdmon()->print_nodes(f.get()); mdsmon()->print_nodes(f.get()); + mgrmon()->print_nodes(f.get()); f->close_section(); } else if (node_type == "mon") { print_nodes(f.get(), ds); @@ -3284,6 +3285,8 @@ void Monitor::handle_command(MonOpRequestRef op) osdmon()->print_nodes(f.get()); } else if (node_type == "mds") { mdsmon()->print_nodes(f.get()); + } else if (node_type == "mgr") { + mgrmon()->print_nodes(f.get()); } f->flush(ds); rdata.append(ds);