]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/mgr/ServiceMap.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / mgr / ServiceMap.h
index d2a1c9b37c140b5d1a77b9e31a2b25a81d5950d6..169038f3044750927949e9dbd8a4c41d3103de76 100644 (file)
@@ -23,20 +23,21 @@ struct ServiceMap {
     epoch_t start_epoch = 0;   ///< epoch first registered
     utime_t start_stamp;       ///< timestamp daemon started/registered
     std::map<std::string,std::string> metadata;  ///< static metadata
+    std::map<std::string,std::string> task_status; ///< running task status
 
-    void encode(bufferlist& bl, uint64_t features) const;
-    void decode(bufferlist::const_iterator& p);
-    void dump(Formatter *f) const;
+    void encode(ceph::buffer::list& bl, uint64_t features) const;
+    void decode(ceph::buffer::list::const_iterator& p);
+    void dump(ceph::Formatter *f) const;
     static void generate_test_instances(std::list<Daemon*>& ls);
   };
 
   struct Service {
-    map<std::string,Daemon> daemons;
-    std::string summary;   ///< summary status string for 'ceph -s'
+    std::map<std::string,Daemon> daemons;
+    std::string summary;   ///< summary status std::string for 'ceph -s'
 
-    void encode(bufferlist& bl, uint64_t features) const;
-    void decode(bufferlist::const_iterator& p);
-    void dump(Formatter *f) const;
+    void encode(ceph::buffer::list& bl, uint64_t features) const;
+    void decode(ceph::buffer::list::const_iterator& p);
+    void dump(ceph::Formatter *f) const;
     static void generate_test_instances(std::list<Service*>& ls);
 
     std::string get_summary() const {
@@ -64,7 +65,34 @@ struct ServiceMap {
       return ss.str();
     }
 
-    void count_metadata(const string& field,
+    std::string get_task_summary(const std::string_view task_prefix) const {
+      // contruct a map similar to:
+      //     {"service1 status" -> {"service1.0" -> "running"}}
+      //     {"service2 status" -> {"service2.0" -> "idle"},
+      //                           {"service2.1" -> "running"}}
+      std::map<std::string, std::map<std::string, std::string>> by_task;
+      for (const auto &p : daemons) {
+        std::stringstream d;
+        d << task_prefix << "." << p.first;
+        for (const auto &q : p.second.task_status) {
+          auto p1 = by_task.emplace(q.first, std::map<std::string, std::string>{}).first;
+          auto p2 = p1->second.emplace(d.str(), std::string()).first;
+          p2->second = q.second;
+        }
+      }
+
+      std::stringstream ss;
+      for (const auto &p : by_task) {
+        ss << "\n    " << p.first << ":";
+        for (auto q : p.second) {
+          ss << "\n        " << q.first << ": " << q.second;
+        }
+      }
+
+      return ss.str();
+    }
+
+    void count_metadata(const std::string& field,
                        std::map<std::string,int> *out) const {
       for (auto& p : daemons) {
        auto q = p.second.metadata.find(field);
@@ -80,16 +108,18 @@ struct ServiceMap {
 
   epoch_t epoch = 0;
   utime_t modified;
-  map<std::string,Service> services;
+  std::map<std::string,Service> services;
 
-  void encode(bufferlist& bl, uint64_t features) const;
-  void decode(bufferlist::const_iterator& p);
-  void dump(Formatter *f) const;
+  void encode(ceph::buffer::list& bl, uint64_t features) const;
+  void decode(ceph::buffer::list::const_iterator& p);
+  void dump(ceph::Formatter *f) const;
   static void generate_test_instances(std::list<ServiceMap*>& ls);
 
-  Daemon* get_daemon(const std::string& service,
-                    const std::string& daemon) {
-    return &services[service].daemons[daemon];
+  std::pair<Daemon*,bool> get_daemon(const std::string& service,
+                                    const std::string& daemon) {
+    auto& s = services[service];
+    auto [d, added] = s.daemons.try_emplace(daemon);
+    return {&d->second, added};
   }
 
   bool rm_daemon(const std::string& service,
@@ -108,6 +138,18 @@ struct ServiceMap {
     }
     return true;
   }
+
+  static inline bool is_normal_ceph_entity(std::string_view type) {
+    if (type == "osd" ||
+        type == "client" ||
+        type == "mon" ||
+        type == "mds" ||
+        type == "mgr") {
+      return true;
+    }
+
+    return false;
+  }
 };
 WRITE_CLASS_ENCODER_FEATURES(ServiceMap)
 WRITE_CLASS_ENCODER_FEATURES(ServiceMap::Service)