]> git.proxmox.com Git - ceph.git/blob - ceph/src/mgr/MgrClient.h
update sources to v12.2.3
[ceph.git] / ceph / src / mgr / MgrClient.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 */
13
14 #ifndef MGR_CLIENT_H_
15 #define MGR_CLIENT_H_
16
17 #include "msg/Connection.h"
18 #include "msg/Dispatcher.h"
19 #include "mon/MgrMap.h"
20 #include "osd/OSDHealthMetric.h"
21
22 #include "common/perf_counters.h"
23 #include "common/Timer.h"
24 #include "common/CommandTable.h"
25
26 class MMgrMap;
27 class MMgrConfigure;
28 class Messenger;
29 class MCommandReply;
30 class MPGStats;
31
32 class MgrSessionState
33 {
34 public:
35 // Which performance counters have we already transmitted schema for?
36 std::set<std::string> declared;
37
38 // Our connection to the mgr
39 ConnectionRef con;
40 };
41
42 class MgrCommand : public CommandOp
43 {
44 public:
45
46 MgrCommand(ceph_tid_t t) : CommandOp(t) {}
47 MgrCommand() : CommandOp() {}
48 };
49
50 class MgrClient : public Dispatcher
51 {
52 protected:
53 CephContext *cct;
54 MgrMap map;
55 Messenger *msgr;
56
57 unique_ptr<MgrSessionState> session;
58
59 Mutex lock = {"MgrClient::lock"};
60
61 uint32_t stats_period = 0;
62 uint32_t stats_threshold = 0;
63 SafeTimer timer;
64
65 CommandTable<MgrCommand> command_table;
66
67 utime_t last_connect_attempt;
68
69 Context *report_callback = nullptr;
70 Context *connect_retry_callback = nullptr;
71
72 // If provided, use this to compose an MPGStats to send with
73 // our reports (hook for use by OSD)
74 std::function<MPGStats*()> pgstats_cb;
75
76 // for service registration and beacon
77 bool service_daemon = false;
78 bool daemon_dirty_status = false;
79 std::string service_name, daemon_name;
80 std::map<std::string,std::string> daemon_metadata;
81 std::map<std::string,std::string> daemon_status;
82 std::vector<OSDHealthMetric> osd_health_metrics;
83
84 void reconnect();
85 void _send_open();
86
87 public:
88 MgrClient(CephContext *cct_, Messenger *msgr_);
89
90 void set_messenger(Messenger *msgr_) { msgr = msgr_; }
91
92 void init();
93 void shutdown();
94
95 bool ms_dispatch(Message *m) override;
96 bool ms_handle_reset(Connection *con) override;
97 void ms_handle_remote_reset(Connection *con) override {}
98 bool ms_handle_refused(Connection *con) override;
99
100 bool handle_mgr_map(MMgrMap *m);
101 bool handle_mgr_configure(MMgrConfigure *m);
102 bool handle_command_reply(MCommandReply *m);
103
104 void send_report();
105 void send_pgstats();
106
107 void set_pgstats_cb(std::function<MPGStats*()> cb_)
108 {
109 Mutex::Locker l(lock);
110 pgstats_cb = cb_;
111 }
112
113 int start_command(const vector<string>& cmd, const bufferlist& inbl,
114 bufferlist *outbl, string *outs,
115 Context *onfinish);
116
117 int service_daemon_register(
118 const std::string& service,
119 const std::string& name,
120 const std::map<std::string,std::string>& metadata);
121 int service_daemon_update_status(
122 const std::map<std::string,std::string>& status);
123 void update_osd_health(std::vector<OSDHealthMetric>&& metrics);
124 };
125
126 #endif
127