]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/Dispatcher.h" | |
18 | #include "mon/MgrMap.h" | |
19 | ||
20 | #include "msg/Connection.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 | SafeTimer timer; | |
63 | ||
64 | CommandTable<MgrCommand> command_table; | |
65 | ||
66 | utime_t last_connect_attempt; | |
67 | ||
68 | Context *report_callback = nullptr; | |
69 | Context *connect_retry_callback = nullptr; | |
70 | ||
71 | // If provided, use this to compose an MPGStats to send with | |
72 | // our reports (hook for use by OSD) | |
73 | std::function<MPGStats*()> pgstats_cb; | |
74 | ||
75 | void reconnect(); | |
76 | ||
77 | public: | |
78 | MgrClient(CephContext *cct_, Messenger *msgr_); | |
79 | ||
80 | void set_messenger(Messenger *msgr_) { msgr = msgr_; } | |
81 | ||
82 | void init(); | |
83 | void shutdown(); | |
84 | ||
85 | bool ms_dispatch(Message *m) override; | |
86 | bool ms_handle_reset(Connection *con) override; | |
87 | void ms_handle_remote_reset(Connection *con) override {} | |
88 | bool ms_handle_refused(Connection *con) override; | |
89 | ||
90 | bool handle_mgr_map(MMgrMap *m); | |
91 | bool handle_mgr_configure(MMgrConfigure *m); | |
92 | bool handle_command_reply(MCommandReply *m); | |
93 | ||
94 | void send_report(); | |
95 | ||
96 | void set_pgstats_cb(std::function<MPGStats*()> cb_) | |
97 | { | |
98 | Mutex::Locker l(lock); | |
99 | pgstats_cb = cb_; | |
100 | } | |
101 | ||
102 | int start_command(const vector<string>& cmd, const bufferlist& inbl, | |
103 | bufferlist *outbl, string *outs, | |
104 | Context *onfinish); | |
105 | }; | |
106 | ||
107 | #endif | |
108 |