]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/mgr/MgrClient.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / mgr / MgrClient.h
index 09764afaf8cce679bda05f67751e6cf0b61ebb3a..6ac56fec970d2dcebd0a74f2111c5b31338f4a12 100644 (file)
 #ifndef MGR_CLIENT_H_
 #define MGR_CLIENT_H_
 
+#include <boost/variant.hpp>
+
 #include "msg/Connection.h"
 #include "msg/Dispatcher.h"
 #include "mon/MgrMap.h"
 #include "mgr/DaemonHealthMetric.h"
 
 #include "messages/MMgrReport.h"
-#include "mgr/OSDPerfMetricTypes.h"
+#include "mgr/MetricTypes.h"
 
 #include "common/perf_counters.h"
 #include "common/Timer.h"
@@ -32,6 +34,7 @@ class MMgrClose;
 class Messenger;
 class MCommandReply;
 class MPGStats;
+class MonMap;
 
 class MgrSessionState
 {
@@ -46,6 +49,8 @@ class MgrSessionState
 class MgrCommand : public CommandOp
 {
   public:
+  std::string name;
+  bool tell = false;
 
   explicit MgrCommand(ceph_tid_t t) : CommandOp(t) {}
   MgrCommand() : CommandOp() {}
@@ -57,11 +62,12 @@ protected:
   CephContext *cct;
   MgrMap map;
   Messenger *msgr;
+  MonMap *monmap;
 
-  unique_ptr<MgrSessionState> session;
+  std::unique_ptr<MgrSessionState> session;
 
-  Mutex lock = {"MgrClient::lock"};
-  Cond shutdown_cond;
+  ceph::mutex lock = ceph::make_mutex("MgrClient::lock");
+  ceph::condition_variable shutdown_cond;
 
   uint32_t stats_period = 0;
   uint32_t stats_threshold = 0;
@@ -69,7 +75,8 @@ protected:
 
   CommandTable<MgrCommand> command_table;
 
-  utime_t last_connect_attempt;
+  using clock_t = ceph::real_clock;
+  clock_t::time_point last_connect_attempt;
 
   uint64_t last_config_bl_version = 0;
 
@@ -79,17 +86,17 @@ protected:
   // If provided, use this to compose an MPGStats to send with
   // our reports (hook for use by OSD)
   std::function<MPGStats*()> pgstats_cb;
-  std::function<void(const std::map<OSDPerfMetricQuery,
-                                    OSDPerfMetricLimits> &)> set_perf_queries_cb;
-  std::function<void(std::map<OSDPerfMetricQuery,
-                              OSDPerfMetricReport> *)> get_perf_report_cb;
+  std::function<void(const ConfigPayload &)> set_perf_queries_cb;
+  std::function<MetricPayload()> get_perf_report_cb;
 
   // for service registration and beacon
   bool service_daemon = false;
   bool daemon_dirty_status = false;
+  bool task_dirty_status = false;
   std::string service_name, daemon_name;
   std::map<std::string,std::string> daemon_metadata;
   std::map<std::string,std::string> daemon_status;
+  std::map<std::string,std::string> task_status;
   std::vector<DaemonHealthMetric> daemon_health_metrics;
 
   void reconnect();
@@ -100,7 +107,7 @@ protected:
   bool mgr_optional = false;
 
 public:
-  MgrClient(CephContext *cct_, Messenger *msgr_);
+  MgrClient(CephContext *cct_, Messenger *msgr_, MonMap *monmap);
 
   void set_messenger(Messenger *msgr_) { msgr = msgr_; }
 
@@ -109,21 +116,23 @@ public:
 
   void set_mgr_optional(bool optional_) {mgr_optional = optional_;}
 
-  bool ms_dispatch(Message *m) override;
+  bool ms_dispatch2(const ceph::ref_t<Message>& m) override;
   bool ms_handle_reset(Connection *con) override;
   void ms_handle_remote_reset(Connection *con) override {}
   bool ms_handle_refused(Connection *con) override;
 
-  bool handle_mgr_map(MMgrMap *m);
-  bool handle_mgr_configure(MMgrConfigure *m);
-  bool handle_mgr_close(MMgrClose *m);
-  bool handle_command_reply(MCommandReply *m);
+  bool handle_mgr_map(ceph::ref_t<MMgrMap> m);
+  bool handle_mgr_configure(ceph::ref_t<MMgrConfigure> m);
+  bool handle_mgr_close(ceph::ref_t<MMgrClose> m);
+  bool handle_command_reply(
+    uint64_t tid,
+    bufferlist& data,
+    const std::string& rs,
+    int r);
 
   void set_perf_metric_query_cb(
-    std::function<void(const std::map<OSDPerfMetricQuery,
-                                      OSDPerfMetricLimits> &)> cb_set,
-          std::function<void(std::map<OSDPerfMetricQuery,
-                                      OSDPerfMetricReport> *)> cb_get)
+    std::function<void(const ConfigPayload &)> cb_set,
+    std::function<MetricPayload()> cb_get)
   {
       std::lock_guard l(lock);
       set_perf_queries_cb = cb_set;
@@ -137,9 +146,15 @@ public:
     pgstats_cb = std::move(cb_);
   }
 
-  int start_command(const vector<string>& cmd, const bufferlist& inbl,
-                   bufferlist *outbl, string *outs,
-                   Context *onfinish);
+  int start_command(
+    const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
+    ceph::buffer::list *outbl, std::string *outs,
+    Context *onfinish);
+  int start_tell_command(
+    const string& name,
+    const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
+    ceph::buffer::list *outbl, std::string *outs,
+    Context *onfinish);
 
   int service_daemon_register(
     const std::string& service,
@@ -147,12 +162,41 @@ public:
     const std::map<std::string,std::string>& metadata);
   int service_daemon_update_status(
     std::map<std::string,std::string>&& status);
+  int service_daemon_update_task_status(
+    std::map<std::string,std::string> &&task_status);
   void update_daemon_health(std::vector<DaemonHealthMetric>&& metrics);
 
+  bool is_initialized() const { return initialized; }
+
 private:
+  void handle_config_payload(const OSDConfigPayload &payload) {
+    if (set_perf_queries_cb) {
+      set_perf_queries_cb(payload);
+    }
+  }
+
+  void handle_config_payload(const UnknownConfigPayload &payload) {
+    ceph_abort();
+  }
+
+  struct HandlePayloadVisitor : public boost::static_visitor<void> {
+    MgrClient *mgrc;
+
+    HandlePayloadVisitor(MgrClient *mgrc)
+      : mgrc(mgrc) {
+    }
+
+    template <typename ConfigPayload>
+    inline void operator()(const ConfigPayload &payload) const {
+      mgrc->handle_config_payload(payload);
+    }
+  };
+
   void _send_stats();
   void _send_pgstats();
   void _send_report();
+
+  bool initialized = false;
 };
 
 #endif