]> git.proxmox.com Git - ceph.git/blame - ceph/src/mgr/MgrClient.h
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / mgr / MgrClient.h
CommitLineData
f67539c2 1
7c673cae
FG
2// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
3// vim: ts=8 sw=2 smarttab
4/*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 */
14
15#ifndef MGR_CLIENT_H_
16#define MGR_CLIENT_H_
17
9f95a23c
TL
18#include <boost/variant.hpp>
19
b32b8144 20#include "msg/Connection.h"
7c673cae
FG
21#include "msg/Dispatcher.h"
22#include "mon/MgrMap.h"
11fdf7f2
TL
23#include "mgr/DaemonHealthMetric.h"
24
25#include "messages/MMgrReport.h"
9f95a23c 26#include "mgr/MetricTypes.h"
7c673cae
FG
27
28#include "common/perf_counters.h"
29#include "common/Timer.h"
30#include "common/CommandTable.h"
31
32class MMgrMap;
33class MMgrConfigure;
11fdf7f2 34class MMgrClose;
7c673cae
FG
35class Messenger;
36class MCommandReply;
37class MPGStats;
9f95a23c 38class MonMap;
7c673cae
FG
39
40class MgrSessionState
41{
42 public:
43 // Which performance counters have we already transmitted schema for?
44 std::set<std::string> declared;
45
46 // Our connection to the mgr
47 ConnectionRef con;
48};
49
50class MgrCommand : public CommandOp
51{
52 public:
9f95a23c
TL
53 std::string name;
54 bool tell = false;
7c673cae 55
11fdf7f2 56 explicit MgrCommand(ceph_tid_t t) : CommandOp(t) {}
7c673cae
FG
57 MgrCommand() : CommandOp() {}
58};
59
60class MgrClient : public Dispatcher
61{
62protected:
63 CephContext *cct;
64 MgrMap map;
65 Messenger *msgr;
9f95a23c 66 MonMap *monmap;
7c673cae 67
9f95a23c 68 std::unique_ptr<MgrSessionState> session;
7c673cae 69
9f95a23c
TL
70 ceph::mutex lock = ceph::make_mutex("MgrClient::lock");
71 ceph::condition_variable shutdown_cond;
7c673cae
FG
72
73 uint32_t stats_period = 0;
3efd9988 74 uint32_t stats_threshold = 0;
7c673cae
FG
75 SafeTimer timer;
76
77 CommandTable<MgrCommand> command_table;
78
20effc67 79 using clock_t = ceph::mono_clock;
9f95a23c 80 clock_t::time_point last_connect_attempt;
7c673cae 81
11fdf7f2
TL
82 uint64_t last_config_bl_version = 0;
83
7c673cae
FG
84 Context *report_callback = nullptr;
85 Context *connect_retry_callback = nullptr;
86
87 // If provided, use this to compose an MPGStats to send with
88 // our reports (hook for use by OSD)
89 std::function<MPGStats*()> pgstats_cb;
9f95a23c
TL
90 std::function<void(const ConfigPayload &)> set_perf_queries_cb;
91 std::function<MetricPayload()> get_perf_report_cb;
7c673cae 92
224ce89b
WB
93 // for service registration and beacon
94 bool service_daemon = false;
95 bool daemon_dirty_status = false;
9f95a23c 96 bool task_dirty_status = false;
2a845540 97 bool need_metadata_update = true;
224ce89b
WB
98 std::string service_name, daemon_name;
99 std::map<std::string,std::string> daemon_metadata;
100 std::map<std::string,std::string> daemon_status;
9f95a23c 101 std::map<std::string,std::string> task_status;
11fdf7f2 102 std::vector<DaemonHealthMetric> daemon_health_metrics;
224ce89b 103
7c673cae 104 void reconnect();
224ce89b 105 void _send_open();
2a845540 106 void _send_update();
7c673cae 107
11fdf7f2
TL
108 // In pre-luminous clusters, the ceph-mgr service is absent or optional,
109 // so we must not block in start_command waiting for it.
110 bool mgr_optional = false;
111
7c673cae 112public:
9f95a23c 113 MgrClient(CephContext *cct_, Messenger *msgr_, MonMap *monmap);
7c673cae
FG
114
115 void set_messenger(Messenger *msgr_) { msgr = msgr_; }
116
117 void init();
118 void shutdown();
119
11fdf7f2
TL
120 void set_mgr_optional(bool optional_) {mgr_optional = optional_;}
121
9f95a23c 122 bool ms_dispatch2(const ceph::ref_t<Message>& m) override;
7c673cae
FG
123 bool ms_handle_reset(Connection *con) override;
124 void ms_handle_remote_reset(Connection *con) override {}
125 bool ms_handle_refused(Connection *con) override;
126
9f95a23c
TL
127 bool handle_mgr_map(ceph::ref_t<MMgrMap> m);
128 bool handle_mgr_configure(ceph::ref_t<MMgrConfigure> m);
129 bool handle_mgr_close(ceph::ref_t<MMgrClose> m);
130 bool handle_command_reply(
131 uint64_t tid,
f67539c2 132 ceph::buffer::list& data,
9f95a23c
TL
133 const std::string& rs,
134 int r);
7c673cae 135
11fdf7f2 136 void set_perf_metric_query_cb(
9f95a23c
TL
137 std::function<void(const ConfigPayload &)> cb_set,
138 std::function<MetricPayload()> cb_get)
11fdf7f2
TL
139 {
140 std::lock_guard l(lock);
141 set_perf_queries_cb = cb_set;
142 get_perf_report_cb = cb_get;
143 }
144
31f18b77 145 void send_pgstats();
11fdf7f2 146 void set_pgstats_cb(std::function<MPGStats*()>&& cb_)
7c673cae 147 {
11fdf7f2
TL
148 std::lock_guard l(lock);
149 pgstats_cb = std::move(cb_);
7c673cae
FG
150 }
151
9f95a23c
TL
152 int start_command(
153 const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
154 ceph::buffer::list *outbl, std::string *outs,
155 Context *onfinish);
156 int start_tell_command(
f67539c2 157 const std::string& name,
9f95a23c
TL
158 const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
159 ceph::buffer::list *outbl, std::string *outs,
160 Context *onfinish);
224ce89b 161
2a845540
TL
162 int update_daemon_metadata(
163 const std::string& service,
164 const std::string& name,
165 const std::map<std::string,std::string>& metadata);
224ce89b
WB
166 int service_daemon_register(
167 const std::string& service,
168 const std::string& name,
169 const std::map<std::string,std::string>& metadata);
170 int service_daemon_update_status(
11fdf7f2 171 std::map<std::string,std::string>&& status);
9f95a23c
TL
172 int service_daemon_update_task_status(
173 std::map<std::string,std::string> &&task_status);
11fdf7f2 174 void update_daemon_health(std::vector<DaemonHealthMetric>&& metrics);
91327a77 175
9f95a23c
TL
176 bool is_initialized() const { return initialized; }
177
91327a77 178private:
9f95a23c
TL
179 void handle_config_payload(const OSDConfigPayload &payload) {
180 if (set_perf_queries_cb) {
181 set_perf_queries_cb(payload);
182 }
183 }
184
f67539c2
TL
185 void handle_config_payload(const MDSConfigPayload &payload) {
186 if (set_perf_queries_cb) {
187 set_perf_queries_cb(payload);
188 }
189 }
190
9f95a23c
TL
191 void handle_config_payload(const UnknownConfigPayload &payload) {
192 ceph_abort();
193 }
194
195 struct HandlePayloadVisitor : public boost::static_visitor<void> {
196 MgrClient *mgrc;
197
198 HandlePayloadVisitor(MgrClient *mgrc)
199 : mgrc(mgrc) {
200 }
201
202 template <typename ConfigPayload>
203 inline void operator()(const ConfigPayload &payload) const {
204 mgrc->handle_config_payload(payload);
205 }
206 };
207
91327a77
AA
208 void _send_stats();
209 void _send_pgstats();
210 void _send_report();
9f95a23c
TL
211
212 bool initialized = false;
7c673cae
FG
213};
214
215#endif