1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
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.
19 #include "msg/msg_types.h"
20 #include "common/Formatter.h"
21 #include "include/encoding.h"
29 StandbyInfo(uint64_t gid_
, const std::string
&name_
)
30 : gid(gid_
), name(name_
)
37 void encode(bufferlist
& bl
) const
39 ENCODE_START(1, 1, bl
);
45 void decode(bufferlist::iterator
& p
)
53 WRITE_CLASS_ENCODER(StandbyInfo
)
60 /// global_id of the ceph-mgr instance selected as a leader
61 uint64_t active_gid
= 0;
62 /// server address reported by the leader once it is active
63 entity_addr_t active_addr
;
64 /// whether the nominated leader is active (i.e. has initialized its server)
65 bool available
= false;
66 /// the name (foo in mgr.<foo>) of the active daemon
67 std::string active_name
;
69 std::map
<uint64_t, StandbyInfo
> standbys
;
71 epoch_t
get_epoch() const { return epoch
; }
72 entity_addr_t
get_active_addr() const { return active_addr
; }
73 uint64_t get_active_gid() const { return active_gid
; }
74 bool get_available() const { return available
; }
75 const std::string
&get_active_name() const { return active_name
; }
77 void encode(bufferlist
& bl
, uint64_t features
) const
79 ENCODE_START(1, 1, bl
);
81 ::encode(active_addr
, bl
, features
);
82 ::encode(active_gid
, bl
);
83 ::encode(available
, bl
);
84 ::encode(active_name
, bl
);
85 ::encode(standbys
, bl
);
89 void decode(bufferlist::iterator
& p
)
93 ::decode(active_addr
, p
);
94 ::decode(active_gid
, p
);
95 ::decode(available
, p
);
96 ::decode(active_name
, p
);
97 ::decode(standbys
, p
);
101 void dump(Formatter
*f
) const {
102 f
->dump_int("epoch", epoch
);
103 f
->dump_int("active_gid", get_active_gid());
104 f
->dump_string("active_name", get_active_name());
105 f
->dump_stream("active_addr") << active_addr
;
106 f
->dump_bool("available", available
);
107 f
->open_array_section("standbys");
108 for (const auto &i
: standbys
) {
109 f
->open_object_section("standby");
110 f
->dump_int("gid", i
.second
.gid
);
111 f
->dump_string("name", i
.second
.name
);
117 static void generate_test_instances(list
<MgrMap
*> &l
) {
118 l
.push_back(new MgrMap
);
121 void print_summary(Formatter
*f
, std::ostream
*ss
) const
123 // One or the other, not both
124 assert((ss
!= nullptr) != (f
!= nullptr));
128 if (get_active_gid() != 0) {
129 *ss
<< "active: " << get_active_name();
131 // If the daemon hasn't gone active yet, indicate that.
136 *ss
<< "no daemons active ";
138 if (standbys
.size()) {
141 for (const auto &i
: standbys
) {
145 *ss
<< i
.second
.name
;
152 friend ostream
& operator<<(ostream
& out
, const MgrMap
& m
) {
154 m
.print_summary(nullptr, &ss
);
155 return out
<< ss
.str();
159 WRITE_CLASS_ENCODER_FEATURES(MgrMap
)