From dc49857a6529fe80b3b1f49f6e27e393c04d939e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 30 Mar 2017 12:19:41 -0400 Subject: [PATCH] mon/MgrMap: implement dump, add to ceph-dencoder Signed-off-by: Sage Weil --- src/mon/MgrMap.h | 59 +++++++++++++++++++++------------------ src/test/encoding/types.h | 3 ++ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/mon/MgrMap.h b/src/mon/MgrMap.h index 167573da474..1fd0500131c 100644 --- a/src/mon/MgrMap.h +++ b/src/mon/MgrMap.h @@ -98,43 +98,48 @@ public: DECODE_FINISH(p); } + void dump(Formatter *f) const { + f->dump_int("epoch", epoch); + f->dump_int("active_gid", get_active_gid()); + f->dump_string("active_name", get_active_name()); + f->dump_stream("active_addr") << active_addr; + f->dump_bool("available", available); + f->open_array_section("standbys"); + for (const auto &i : standbys) { + f->open_object_section("standby"); + f->dump_int("gid", i.second.gid); + f->dump_string("name", i.second.name); + f->close_section(); + } + f->close_section(); + } + + static void generate_test_instances(list &l) { + l.push_back(new MgrMap); + } + void print_summary(Formatter *f, std::ostream *ss) const { // One or the other, not both assert((ss != nullptr) != (f != nullptr)); - if (f) { - f->dump_int("active_gid", get_active_gid()); - f->dump_string("active_name", get_active_name()); + dump(f); } else { if (get_active_gid() != 0) { - *ss << "active: " << get_active_name() << " "; + *ss << "active: " << get_active_name() << " "; } else { - *ss << "no daemons active "; + *ss << "no daemons active "; } - } - - - if (f) { - f->open_array_section("standbys"); - for (const auto &i : standbys) { - f->open_object_section("standby"); - f->dump_int("gid", i.second.gid); - f->dump_string("name", i.second.name); - f->close_section(); - } - f->close_section(); - } else { if (standbys.size()) { - *ss << "standbys: "; - bool first = true; - for (const auto &i : standbys) { - if (!first) { - *ss << ", "; - } - *ss << i.second.name; - first = false; - } + *ss << "standbys: "; + bool first = true; + for (const auto &i : standbys) { + if (!first) { + *ss << ", "; + } + *ss << i.second.name; + first = false; + } } } } diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index a3736bdffc5..1d7694169d2 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -154,6 +154,9 @@ TYPE_FEATUREFUL(MonMap) #include "mon/MonCap.h" TYPE(MonCap) +#include "mon/MgrMap.h" +TYPE_FEATUREFUL(MgrMap) + #include "mon/mon_types.h" TYPE(LevelDBStoreStats) -- 2.39.5