]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: 'node ls' mgr support
authorGu Zhongyan <guzhongyan@360.cn>
Mon, 5 Mar 2018 09:55:36 +0000 (17:55 +0800)
committerGu Zhongyan <guzhongyan@360.cn>
Tue, 6 Mar 2018 07:13:59 +0000 (15:13 +0800)
mgr is not included in 'node ls'
add mgr support in 'node ls'

Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
qa/workunits/cephtool/test.sh
src/common/util.cc
src/include/util.h
src/mon/MgrMonitor.cc
src/mon/MgrMonitor.h
src/mon/MonCommands.h
src/mon/Monitor.cc

index 2f01b64ba0951bb0153c686dc76b5956928c77bc..6d8dc36a466a8f4555cf536669ef15445878adef 100755 (executable)
@@ -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
 
index 3f454f93f70208275fe9d611532948242b608e48..51bd8b17ea9b220bf721734c59222fb4d3f332c2 100644 (file)
@@ -303,6 +303,21 @@ void dump_services(Formatter* f, const map<string, list<int> >& services, const
   f->close_section();
 }
 
+void dump_services(Formatter* f, const map<string, list<string> >& 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.
index 4b27cc1f3e3dc38776424d2b5148cc22c23fe604..7c7a4a54b855b6363a6e283236e61ce2cf37527e 100644 (file)
@@ -83,6 +83,11 @@ void collect_sys_info(map<string, string> *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<string, list<int> >& 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<string, list<string> >& services, const char* type);
 
 string cleanbin(bufferlist &bl, bool &b64);
 string cleanbin(string &str);
index 4f3976cf40c92d5ebd65ebc9d11c01bbc442b280..945a3a2189f1478c923113b45f40fa28210f83d1 100644 (file)
@@ -932,7 +932,7 @@ void MgrMonitor::on_shutdown()
 }
 
 int MgrMonitor::load_metadata(const string& name, std::map<string, string>& 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<string, list<string> > mgrs; // hostname => mgr
+  auto ls = map.get_all_names();
+  for (auto& name : ls) {
+    std::map<string,string> 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<MonCommand> &MgrMonitor::get_command_descs() const
 {
   if (command_descs.empty()) {
index 40d40c0a7a10999d9683ec7186475bab6d8777ff..d73b1f26dd98d503845bc036aa1789aef9c53fb2 100644 (file)
@@ -111,8 +111,9 @@ public:
   const std::vector<MonCommand> &get_command_descs() const;
 
   int load_metadata(const string& name, std::map<string, string>& 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<string,int> *out);
 
index 0f1729d4f9a2fb44bcbd47f11ad6ace747a6e34c..f442419768115b26b61b1de2ec5e248838e691fe 100644 (file)
@@ -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'
index df0c83adbf37816e97878641141e87f195e1a93a..10520bcb8d58e8d72194f392df1fb8f94be4757d 100644 (file)
@@ -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);