From 0133392bdb916116276e247ceafb81baf12347da Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 24 Jul 2012 17:23:03 -0700 Subject: [PATCH] admin_socket: dump config in json; add test Signed-off-by: Sage Weil --- src/common/ceph_context.cc | 5 ++++- src/common/config.cc | 44 ++++++++++++++++++++++++++++++-------- src/common/config.h | 4 +++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 1e7637606c4b9..838f9d6c93578 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -23,6 +23,7 @@ #include "common/HeartbeatMap.h" #include "common/errno.h" #include "common/lockdep.h" +#include "common/Formatter.h" #include "log/Log.h" #include @@ -172,8 +173,10 @@ void CephContext::do_command(std::string command, std::string args, bufferlist * _perf_counters_collection->write_json_to_buf(*out, true); } else if (command == "config show") { + JSONFormatter jf(true); + _conf->show_config(&jf); ostringstream ss; - _conf->show_config(ss); + jf.flush(ss); out->append(ss.str()); } else if (command == "config set") { diff --git a/src/common/config.cc b/src/common/config.cc index 94390c1924b71..21ff86063d04c 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -22,6 +22,7 @@ #include "common/version.h" #include "include/str_list.h" #include "include/types.h" +#include "include/stringify.h" #include "msg/msg_types.h" #include "osd/osd_types.h" @@ -283,24 +284,49 @@ void md_config_t::parse_env() void md_config_t::show_config(std::ostream& out) { Mutex::Locker l(lock); - _show_config(out); + _show_config(&out, NULL); } -void md_config_t::_show_config(std::ostream& out) +void md_config_t::show_config(Formatter *f) { - out << "name = " << name << std::endl; - out << "cluster = " << cluster << std::endl; + Mutex::Locker l(lock); + _show_config(NULL, f); +} + +void md_config_t::_show_config(std::ostream *out, Formatter *f) +{ + if (out) { + *out << "name = " << name << std::endl; + *out << "cluster = " << cluster << std::endl; + } + if (f) { + f->open_object_section("config"); + f->dump_string("name", stringify(name)); + f->dump_string("cluster", cluster); + } for (int o = 0; o < subsys.get_num(); o++) { - out << "debug_" << subsys.get_name(o) - << " = " << subsys.get_log_level(o) - << "/" << subsys.get_gather_level(o) << std::endl; + if (out) + *out << "debug_" << subsys.get_name(o) + << " = " << subsys.get_log_level(o) + << "/" << subsys.get_gather_level(o) << std::endl; + if (f) { + ostringstream ss; + ss << subsys.get_log_level(o) + << "/" << subsys.get_gather_level(o); + f->dump_string(subsys.get_name(o).c_str(), ss.str()); + } } for (int i = 0; i < NUM_CONFIG_OPTIONS; i++) { config_option *opt = config_optionsp + i; char *buf; _get_val(opt->name, &buf, -1); - out << opt->name << " = " << buf << std::endl; + if (out) + *out << opt->name << " = " << buf << std::endl; + if (f) + f->dump_string(opt->name, buf); } + if (f) + f->close_section(); } int md_config_t::parse_argv(std::vector& args) @@ -327,7 +353,7 @@ int md_config_t::parse_argv(std::vector& args) } else if (ceph_argparse_flag(args, i, "--show_config", (char*)NULL)) { expand_all_meta(); - _show_config(cout); + _show_config(&cout, NULL); _exit(0); } else if (ceph_argparse_witharg(args, i, &val, "--show_config_value", (char*)NULL)) { diff --git a/src/common/config.h b/src/common/config.h index c98b8ba88ff14..67efc57d73b34 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -141,9 +141,11 @@ public: /// dump all config values to a stream void show_config(std::ostream& out); + /// dump all config values to a formatter + void show_config(Formatter *f); private: - void _show_config(std::ostream& out); + void _show_config(std::ostream *out, Formatter *f); void _get_my_sections(std::vector §ions) const; -- 2.39.5