]>
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) 2004-2006 Sage Weil <sage@newdream.net> | |
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 | ||
15 | #ifndef CEPH_MMGRBEACON_H | |
16 | #define CEPH_MMGRBEACON_H | |
17 | ||
18 | #include "messages/PaxosServiceMessage.h" | |
c07f9fc5 | 19 | #include "mon/MonCommand.h" |
11fdf7f2 | 20 | #include "mon/MgrMap.h" |
7c673cae FG |
21 | |
22 | #include "include/types.h" | |
23 | ||
24 | ||
f67539c2 | 25 | class MMgrBeacon final : public PaxosServiceMessage { |
11fdf7f2 | 26 | private: |
1e59de90 | 27 | static constexpr int HEAD_VERSION = 11; |
11fdf7f2 | 28 | static constexpr int COMPAT_VERSION = 8; |
7c673cae FG |
29 | |
30 | protected: | |
31 | uint64_t gid; | |
11fdf7f2 | 32 | entity_addrvec_t server_addrs; |
7c673cae FG |
33 | bool available; |
34 | std::string name; | |
35 | uuid_d fsid; | |
c07f9fc5 | 36 | |
3efd9988 FG |
37 | // From active daemon to populate MgrMap::services |
38 | std::map<std::string, std::string> services; | |
39 | ||
c07f9fc5 FG |
40 | // Only populated during activation |
41 | std::vector<MonCommand> command_descs; | |
7c673cae | 42 | |
11fdf7f2 TL |
43 | // Information about the modules found locally on this daemon |
44 | std::vector<MgrMap::ModuleInfo> modules; | |
45 | ||
f67539c2 | 46 | std::map<std::string,std::string> metadata; ///< misc metadata about this osd |
11fdf7f2 | 47 | |
1e59de90 | 48 | std::multimap<std::string, entity_addrvec_t> clients; |
9f95a23c TL |
49 | |
50 | uint64_t mgr_features = 0; ///< reporting mgr's features | |
51 | ||
7c673cae FG |
52 | public: |
53 | MMgrBeacon() | |
9f95a23c | 54 | : PaxosServiceMessage{MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION}, |
7c673cae | 55 | gid(0), available(false) |
9f95a23c | 56 | {} |
7c673cae FG |
57 | |
58 | MMgrBeacon(const uuid_d& fsid_, uint64_t gid_, const std::string &name_, | |
11fdf7f2 TL |
59 | entity_addrvec_t server_addrs_, bool available_, |
60 | std::vector<MgrMap::ModuleInfo>&& modules_, | |
f67539c2 | 61 | std::map<std::string,std::string>&& metadata_, |
1e59de90 | 62 | std::multimap<std::string, entity_addrvec_t>&& clients_, |
9f95a23c TL |
63 | uint64_t feat) |
64 | : PaxosServiceMessage{MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION}, | |
11fdf7f2 | 65 | gid(gid_), server_addrs(server_addrs_), available(available_), name(name_), |
9f95a23c | 66 | fsid(fsid_), modules(std::move(modules_)), metadata(std::move(metadata_)), |
1e59de90 | 67 | clients(std::move(clients_)), |
9f95a23c | 68 | mgr_features(feat) |
7c673cae FG |
69 | { |
70 | } | |
71 | ||
72 | uint64_t get_gid() const { return gid; } | |
11fdf7f2 | 73 | entity_addrvec_t get_server_addrs() const { return server_addrs; } |
7c673cae FG |
74 | bool get_available() const { return available; } |
75 | const std::string& get_name() const { return name; } | |
76 | const uuid_d& get_fsid() const { return fsid; } | |
c07f9fc5 FG |
77 | const std::map<std::string,std::string>& get_metadata() const { |
78 | return metadata; | |
79 | } | |
3efd9988 FG |
80 | const std::map<std::string,std::string>& get_services() const { |
81 | return services; | |
82 | } | |
9f95a23c | 83 | uint64_t get_mgr_features() const { return mgr_features; } |
3efd9988 FG |
84 | |
85 | void set_services(const std::map<std::string, std::string> &svcs) | |
86 | { | |
87 | services = svcs; | |
88 | } | |
89 | ||
c07f9fc5 FG |
90 | void set_command_descs(const std::vector<MonCommand> &cmds) |
91 | { | |
92 | command_descs = cmds; | |
93 | } | |
94 | ||
95 | const std::vector<MonCommand> &get_command_descs() | |
96 | { | |
97 | return command_descs; | |
98 | } | |
7c673cae | 99 | |
11fdf7f2 TL |
100 | const std::vector<MgrMap::ModuleInfo> &get_available_modules() const |
101 | { | |
102 | return modules; | |
103 | } | |
104 | ||
9f95a23c TL |
105 | const auto& get_clients() const |
106 | { | |
107 | return clients; | |
108 | } | |
109 | ||
7c673cae | 110 | private: |
f67539c2 | 111 | ~MMgrBeacon() final {} |
7c673cae FG |
112 | |
113 | public: | |
114 | ||
11fdf7f2 | 115 | std::string_view get_type_name() const override { return "mgrbeacon"; } |
7c673cae | 116 | |
f67539c2 | 117 | void print(std::ostream& out) const override { |
7c673cae | 118 | out << get_type_name() << " mgr." << name << "(" << fsid << "," |
11fdf7f2 | 119 | << gid << ", " << server_addrs << ", " << available |
224ce89b | 120 | << ")"; |
7c673cae FG |
121 | } |
122 | ||
123 | void encode_payload(uint64_t features) override { | |
11fdf7f2 TL |
124 | header.version = HEAD_VERSION; |
125 | header.compat_version = COMPAT_VERSION; | |
126 | using ceph::encode; | |
7c673cae | 127 | paxos_encode(); |
11fdf7f2 | 128 | |
20effc67 TL |
129 | assert(HAVE_FEATURE(features, SERVER_NAUTILUS)); |
130 | encode(server_addrs, payload, features); | |
11fdf7f2 TL |
131 | encode(gid, payload); |
132 | encode(available, payload); | |
133 | encode(name, payload); | |
134 | encode(fsid, payload); | |
135 | ||
136 | // Fill out old-style list of module names (deprecated by | |
137 | // later field of full ModuleInfos) | |
138 | std::set<std::string> module_names; | |
139 | for (const auto &info : modules) { | |
140 | module_names.insert(info.name); | |
141 | } | |
142 | encode(module_names, payload); | |
143 | ||
144 | encode(command_descs, payload); | |
145 | encode(metadata, payload); | |
146 | encode(services, payload); | |
147 | ||
148 | encode(modules, payload); | |
9f95a23c | 149 | encode(mgr_features, payload); |
1e59de90 TL |
150 | |
151 | std::vector<std::string> clients_names; | |
152 | std::vector<entity_addrvec_t> clients_addrs; | |
153 | for (const auto& i : clients) { | |
154 | clients_names.push_back(i.first); | |
155 | clients_addrs.push_back(i.second); | |
156 | } | |
157 | // The address vector needs to be encoded first to produce a | |
158 | // backwards compatible messsage for older monitors. | |
159 | encode(clients_addrs, payload, features); | |
160 | encode(clients_names, payload, features); | |
7c673cae FG |
161 | } |
162 | void decode_payload() override { | |
f67539c2 | 163 | using ceph::decode; |
11fdf7f2 | 164 | auto p = payload.cbegin(); |
7c673cae | 165 | paxos_decode(p); |
20effc67 | 166 | assert(header.version >= 8); |
11fdf7f2 TL |
167 | decode(server_addrs, p); // entity_addr_t for version < 8 |
168 | decode(gid, p); | |
169 | decode(available, p); | |
170 | decode(name, p); | |
20effc67 TL |
171 | decode(fsid, p); |
172 | std::set<std::string> module_name_list; | |
173 | decode(module_name_list, p); | |
174 | decode(command_descs, p); | |
175 | decode(metadata, p); | |
176 | decode(services, p); | |
177 | decode(modules, p); | |
9f95a23c TL |
178 | if (header.version >= 9) { |
179 | decode(mgr_features, p); | |
180 | } | |
181 | if (header.version >= 10) { | |
1e59de90 TL |
182 | std::vector<entity_addrvec_t> clients_addrs; |
183 | decode(clients_addrs, p); | |
184 | clients.clear(); | |
185 | if (header.version >= 11) { | |
186 | std::vector<std::string> clients_names; | |
187 | decode(clients_names, p); | |
188 | if (clients_names.size() != clients_addrs.size()) { | |
189 | throw ceph::buffer::malformed_input( | |
190 | "clients_names.size() != clients_addrs.size()"); | |
191 | } | |
192 | auto cn = clients_names.begin(); | |
193 | auto ca = clients_addrs.begin(); | |
194 | for(; cn != clients_names.end(); ++cn, ++ca) { | |
195 | clients.emplace(*cn, *ca); | |
196 | } | |
197 | } else { | |
198 | for (const auto& i : clients_addrs) { | |
199 | clients.emplace("", i); | |
200 | } | |
201 | } | |
9f95a23c | 202 | } |
7c673cae | 203 | } |
9f95a23c TL |
204 | private: |
205 | template<class T, typename... Args> | |
206 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); | |
7c673cae FG |
207 | }; |
208 | ||
11fdf7f2 | 209 | |
7c673cae | 210 | #endif |