]> git.proxmox.com Git - ceph.git/blame - ceph/src/messages/MMgrBeacon.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / messages / MMgrBeacon.h
CommitLineData
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
9f95a23c 25class MMgrBeacon : public PaxosServiceMessage {
11fdf7f2 26private:
9f95a23c 27 static constexpr int HEAD_VERSION = 10;
11fdf7f2 28 static constexpr int COMPAT_VERSION = 8;
7c673cae
FG
29
30protected:
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
46 map<string,string> metadata; ///< misc metadata about this osd
47
9f95a23c
TL
48 std::vector<entity_addrvec_t> clients;
49
50 uint64_t mgr_features = 0; ///< reporting mgr's features
51
7c673cae
FG
52public:
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_,
9f95a23c
TL
61 map<string,string>&& metadata_,
62 std::vector<entity_addrvec_t> clients,
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
TL
66 fsid(fsid_), modules(std::move(modules_)), metadata(std::move(metadata_)),
67 clients(std::move(clients)),
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
FG
110private:
111 ~MMgrBeacon() override {}
112
113public:
114
11fdf7f2 115 std::string_view get_type_name() const override { return "mgrbeacon"; }
7c673cae
FG
116
117 void print(ostream& out) const override {
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
TL
128
129 if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) {
130 header.version = 7;
131 header.compat_version = 1;
132 encode(server_addrs.legacy_addr(), payload, features);
133 } else {
134 encode(server_addrs, payload, features);
135 }
136 encode(gid, payload);
137 encode(available, payload);
138 encode(name, payload);
139 encode(fsid, payload);
140
141 // Fill out old-style list of module names (deprecated by
142 // later field of full ModuleInfos)
143 std::set<std::string> module_names;
144 for (const auto &info : modules) {
145 module_names.insert(info.name);
146 }
147 encode(module_names, payload);
148
149 encode(command_descs, payload);
150 encode(metadata, payload);
151 encode(services, payload);
152
153 encode(modules, payload);
9f95a23c
TL
154 encode(mgr_features, payload);
155 encode(clients, payload, features);
7c673cae
FG
156 }
157 void decode_payload() override {
11fdf7f2 158 auto p = payload.cbegin();
7c673cae 159 paxos_decode(p);
11fdf7f2
TL
160 decode(server_addrs, p); // entity_addr_t for version < 8
161 decode(gid, p);
162 decode(available, p);
163 decode(name, p);
7c673cae 164 if (header.version >= 2) {
11fdf7f2 165 decode(fsid, p);
7c673cae 166 }
224ce89b 167 if (header.version >= 3) {
11fdf7f2
TL
168 std::set<std::string> module_name_list;
169 decode(module_name_list, p);
170 // Only need to unpack this field if we won't have the full
171 // ModuleInfo structures added in v7
172 if (header.version < 7) {
173 for (const auto &i : module_name_list) {
174 MgrMap::ModuleInfo info;
175 info.name = i;
176 modules.push_back(std::move(info));
177 }
178 }
224ce89b 179 }
c07f9fc5 180 if (header.version >= 4) {
11fdf7f2 181 decode(command_descs, p);
c07f9fc5
FG
182 }
183 if (header.version >= 5) {
11fdf7f2 184 decode(metadata, p);
c07f9fc5 185 }
3efd9988 186 if (header.version >= 6) {
11fdf7f2
TL
187 decode(services, p);
188 }
189 if (header.version >= 7) {
190 decode(modules, p);
3efd9988 191 }
9f95a23c
TL
192 if (header.version >= 9) {
193 decode(mgr_features, p);
194 }
195 if (header.version >= 10) {
196 decode(clients, p);
197 }
7c673cae 198 }
9f95a23c
TL
199private:
200 template<class T, typename... Args>
201 friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
7c673cae
FG
202};
203
11fdf7f2 204
7c673cae 205#endif