summaryrefslogtreecommitdiffstats
path: root/src/messages/MMgrBeacon.h
blob: 5b6ca3b60be04108249de6a9a9dfbea702d15a74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */

#ifndef CEPH_MMGRBEACON_H
#define CEPH_MMGRBEACON_H

#include "messages/PaxosServiceMessage.h"
#include "mon/MonCommand.h"
#include "mon/MgrMap.h"

#include "include/types.h"


class MMgrBeacon final : public PaxosServiceMessage {
private:
  static constexpr int HEAD_VERSION = 10;
  static constexpr int COMPAT_VERSION = 8;

protected:
  uint64_t gid;
  entity_addrvec_t server_addrs;
  bool available;
  std::string name;
  uuid_d fsid;

  // From active daemon to populate MgrMap::services
  std::map<std::string, std::string> services;

  // Only populated during activation
  std::vector<MonCommand> command_descs;

  // Information about the modules found locally on this daemon
  std::vector<MgrMap::ModuleInfo> modules;

  std::map<std::string,std::string> metadata; ///< misc metadata about this osd

  std::vector<entity_addrvec_t> clients;

  uint64_t mgr_features = 0;   ///< reporting mgr's features

public:
  MMgrBeacon()
    : PaxosServiceMessage{MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION},
      gid(0), available(false)
  {}

  MMgrBeacon(const uuid_d& fsid_, uint64_t gid_, const std::string &name_,
             entity_addrvec_t server_addrs_, bool available_,
	     std::vector<MgrMap::ModuleInfo>&& modules_,
	     std::map<std::string,std::string>&& metadata_,
             std::vector<entity_addrvec_t> clients,
	     uint64_t feat)
    : PaxosServiceMessage{MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION},
      gid(gid_), server_addrs(server_addrs_), available(available_), name(name_),
      fsid(fsid_), modules(std::move(modules_)), metadata(std::move(metadata_)),
      clients(std::move(clients)),
      mgr_features(feat)
  {
  }

  uint64_t get_gid() const { return gid; }
  entity_addrvec_t get_server_addrs() const { return server_addrs; }
  bool get_available() const { return available; }
  const std::string& get_name() const { return name; }
  const uuid_d& get_fsid() const { return fsid; }
  const std::map<std::string,std::string>& get_metadata() const {
    return metadata;
  }
  const std::map<std::string,std::string>& get_services() const {
    return services;
  }
  uint64_t get_mgr_features() const { return mgr_features; }

  void set_services(const std::map<std::string, std::string> &svcs)
  {
    services = svcs;
  }

  void set_command_descs(const std::vector<MonCommand> &cmds)
  {
    command_descs = cmds;
  }

  const std::vector<MonCommand> &get_command_descs()
  {
    return command_descs;
  }

  const std::vector<MgrMap::ModuleInfo> &get_available_modules() const
  {
    return modules;
  }

  const auto& get_clients() const
  {
    return clients;
  }

private:
  ~MMgrBeacon() final {}

public:

  std::string_view get_type_name() const override { return "mgrbeacon"; }

  void print(std::ostream& out) const override {
    out << get_type_name() << " mgr." << name << "(" << fsid << ","
	<< gid << ", " << server_addrs << ", " << available
	<< ")";
  }

  void encode_payload(uint64_t features) override {
    header.version = HEAD_VERSION;
    header.compat_version = COMPAT_VERSION;
    using ceph::encode;
    paxos_encode();

    if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) {
      header.version = 7;
      header.compat_version = 1;
      encode(server_addrs.legacy_addr(), payload, features);
    } else {
      encode(server_addrs, payload, features);
    }
    encode(gid, payload);
    encode(available, payload);
    encode(name, payload);
    encode(fsid, payload);

    // Fill out old-style list of module names (deprecated by
    // later field of full ModuleInfos)
    std::set<std::string> module_names;
    for (const auto &info : modules) {
      module_names.insert(info.name);
    }
    encode(module_names, payload);

    encode(command_descs, payload);
    encode(metadata, payload);
    encode(services, payload);

    encode(modules, payload);
    encode(mgr_features, payload);
    encode(clients, payload, features);
  }
  void decode_payload() override {
    using ceph::decode;
    auto p = payload.cbegin();
    paxos_decode(p);
    decode(server_addrs, p);  // entity_addr_t for version < 8
    decode(gid, p);
    decode(available, p);
    decode(name, p);
    if (header.version >= 2) {
      decode(fsid, p);
    }
    if (header.version >= 3) {
      std::set<std::string> module_name_list;
      decode(module_name_list, p);
      // Only need to unpack this field if we won't have the full
      // ModuleInfo structures added in v7
      if (header.version < 7) {
        for (const auto &i : module_name_list) {
          MgrMap::ModuleInfo info;
          info.name = i;
          modules.push_back(std::move(info));
        }
      }
    }
    if (header.version >= 4) {
      decode(command_descs, p);
    }
    if (header.version >= 5) {
      decode(metadata, p);
    }
    if (header.version >= 6) {
      decode(services, p);
    }
    if (header.version >= 7) {
      decode(modules, p);
    }
    if (header.version >= 9) {
      decode(mgr_features, p);
    }
    if (header.version >= 10) {
      decode(clients, p);
    }
  }
private:
  template<class T, typename... Args>
  friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args);
};


#endif