]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: make service summary string customizable; simple default
authorSage Weil <sage@redhat.com>
Tue, 27 Jun 2017 13:32:44 +0000 (09:32 -0400)
committerSage Weil <sage@redhat.com>
Sun, 9 Jul 2017 18:09:05 +0000 (14:09 -0400)
Eventually the mgr can populate this field with something tailored to the
service.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/ServiceMap.cc
src/mgr/ServiceMap.h
src/mon/Monitor.cc

index fc3a775f53af5681f1cfaa73f8d52f216da3fdb4..9074e2f8716fc1e252f8652c5133ebc58d42ae0d 100644 (file)
@@ -56,6 +56,7 @@ void ServiceMap::Service::encode(bufferlist& bl, uint64_t features) const
 {
   ENCODE_START(1, 1, bl);
   ::encode(daemons, bl, features);
+  ::encode(summary, bl);
   ENCODE_FINISH(bl);
 }
 
@@ -63,12 +64,14 @@ void ServiceMap::Service::decode(bufferlist::iterator& p)
 {
   DECODE_START(1, p);
   ::decode(daemons, p);
+  ::decode(summary, p);
   DECODE_FINISH(p);
 }
 
 void ServiceMap::Service::dump(Formatter *f) const
 {
   f->open_object_section("daemons");
+  f->dump_string("summary", summary);
   for (auto& p : daemons) {
     f->dump_object(p.first.c_str(), p.second);
   }
index d9121c664f9f7c81ac1c4d432b729ff6ac9a77ce..5137f9f84f26a8bec89bb428b78f26009a79f1b8 100644 (file)
@@ -6,6 +6,7 @@
 #include <string>
 #include <map>
 #include <list>
+#include <sstream>
 
 #include "include/utime.h"
 #include "include/buffer.h"
@@ -31,11 +32,25 @@ struct ServiceMap {
 
   struct Service {
     map<std::string,Daemon> daemons;
+    std::string summary;   ///< summary status string for 'ceph -s'
 
     void encode(bufferlist& bl, uint64_t features) const;
     void decode(bufferlist::iterator& p);
     void dump(Formatter *f) const;
     static void generate_test_instances(std::list<Service*>& ls);
+
+    std::string get_summary() const {
+      if (summary.size()) {
+       return summary;
+      }
+      if (daemons.empty()) {
+       return "no daemons active";
+      }
+      std::ostringstream ss;
+      ss << daemons.size() << (daemons.size() > 1 ? "daemonss" : "daemon")
+        << " active";
+      return ss.str();
+    }
   };
 
   epoch_t epoch = 0;
index 0cb35b7e79a65b18a405d1f23a9c672e5f946e58..0df54bc965d567480f76470991e625bdafac8a13 100644 (file)
@@ -2657,13 +2657,8 @@ void Monitor::get_cluster_status(stringstream &ss, Formatter *f)
       osdmon()->osdmap.print_summary(NULL, ss, string(maxlen + 6, ' '));
       ss << "\n";
       for (auto& p : service_map.services) {
-       set<string> active;
-       for (auto& q : p.second.daemons) {
-         active.insert(q.first);
-       }
        ss << "    " << p.first << ": " << string(maxlen - p.first.size(), ' ')
-          << p.second.daemons.size() << " active: "
-          << active << "\n";
+          << p.second.get_summary() << "\n";
       }
     }