Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / messages / MMgrBeacon.h
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"
19 #include "mon/MonCommand.h"
20
21 #include "include/types.h"
22
23
24 class MMgrBeacon : public PaxosServiceMessage {
25
26   static const int HEAD_VERSION = 6;
27   static const int COMPAT_VERSION = 1;
28
29 protected:
30   uint64_t gid;
31   entity_addr_t server_addr;
32   bool available;
33   std::string name;
34   uuid_d fsid;
35   std::set<std::string> available_modules;
36   map<string,string> metadata; ///< misc metadata about this osd
37
38   // From active daemon to populate MgrMap::services
39   std::map<std::string, std::string> services;
40
41   // Only populated during activation
42   std::vector<MonCommand> command_descs;
43
44 public:
45   MMgrBeacon()
46     : PaxosServiceMessage(MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION),
47       gid(0), available(false)
48   {
49   }
50
51   MMgrBeacon(const uuid_d& fsid_, uint64_t gid_, const std::string &name_,
52              entity_addr_t server_addr_, bool available_,
53              const std::set<std::string>& module_list,
54              map<string,string>&& metadata)
55     : PaxosServiceMessage(MSG_MGR_BEACON, 0, HEAD_VERSION, COMPAT_VERSION),
56       gid(gid_), server_addr(server_addr_), available(available_), name(name_),
57       fsid(fsid_), available_modules(module_list), metadata(std::move(metadata))
58   {
59   }
60
61   uint64_t get_gid() const { return gid; }
62   entity_addr_t get_server_addr() const { return server_addr; }
63   bool get_available() const { return available; }
64   const std::string& get_name() const { return name; }
65   const uuid_d& get_fsid() const { return fsid; }
66   std::set<std::string>& get_available_modules() { return available_modules; }
67   const std::map<std::string,std::string>& get_metadata() const {
68     return metadata;
69   }
70
71   const std::map<std::string,std::string>& get_services() const {
72     return services;
73   }
74
75   void set_services(const std::map<std::string, std::string> &svcs)
76   {
77     services = svcs;
78   }
79
80   void set_command_descs(const std::vector<MonCommand> &cmds)
81   {
82     command_descs = cmds;
83   }
84
85   const std::vector<MonCommand> &get_command_descs()
86   {
87     return command_descs;
88   }
89
90 private:
91   ~MMgrBeacon() override {}
92
93 public:
94
95   const char *get_type_name() const override { return "mgrbeacon"; }
96
97   void print(ostream& out) const override {
98     out << get_type_name() << " mgr." << name << "(" << fsid << ","
99         << gid << ", " << server_addr << ", " << available
100         << ")";
101   }
102
103   void encode_payload(uint64_t features) override {
104     paxos_encode();
105     ::encode(server_addr, payload, features);
106     ::encode(gid, payload);
107     ::encode(available, payload);
108     ::encode(name, payload);
109     ::encode(fsid, payload);
110     ::encode(available_modules, payload);
111     ::encode(command_descs, payload);
112     ::encode(metadata, payload);
113     ::encode(services, payload);
114   }
115   void decode_payload() override {
116     bufferlist::iterator p = payload.begin();
117     paxos_decode(p);
118     ::decode(server_addr, p);
119     ::decode(gid, p);
120     ::decode(available, p);
121     ::decode(name, p);
122     if (header.version >= 2) {
123       ::decode(fsid, p);
124     }
125     if (header.version >= 3) {
126       ::decode(available_modules, p);
127     }
128     if (header.version >= 4) {
129       ::decode(command_descs, p);
130     }
131     if (header.version >= 5) {
132       ::decode(metadata, p);
133     }
134     if (header.version >= 6) {
135       ::decode(services, p);
136     }
137   }
138 };
139
140 #endif