]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
admin_socket: dump config in json; add test
authorSage Weil <sage@inktank.com>
Wed, 25 Jul 2012 00:23:03 +0000 (17:23 -0700)
committerSage Weil <sage@inktank.com>
Wed, 25 Jul 2012 00:23:03 +0000 (17:23 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/common/ceph_context.cc
src/common/config.cc
src/common/config.h

index 1e7637606c4b9c66863dd539f7e7d1287ae20915..838f9d6c935782977a0d0d0fe52291695d8ed3d7 100644 (file)
@@ -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 <iostream>
@@ -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") {
index 94390c1924b7166a074bf42b25ad17cc2437272a..21ff86063d04c13c619306b4d264730449dff098 100644 (file)
@@ -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<const char*>& args)
@@ -327,7 +353,7 @@ int md_config_t::parse_argv(std::vector<const char*>& 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)) {
index c98b8ba88ff1427d76537f3d3914a8fa0f0c52cb..67efc57d73b34623754c7c6f43b21ba93bebb33c 100644 (file)
@@ -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 <std::string> &sections) const;