]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Formatter: new_formatter -> Formatter::create 3366/head
authorSage Weil <sage@redhat.com>
Tue, 13 Jan 2015 16:32:45 +0000 (08:32 -0800)
committerSage Weil <sage@redhat.com>
Tue, 13 Jan 2015 16:32:45 +0000 (08:32 -0800)
Also make the default formatter selection more explicit.

Signed-off-by: Sage Weil <sage@redhat.com>
23 files changed:
src/client/Client.cc
src/common/Formatter.cc
src/common/Formatter.h
src/common/admin_socket.cc
src/common/ceph_context.cc
src/mds/MDS.cc
src/mon/AuthMonitor.cc
src/mon/MDSMonitor.cc
src/mon/Monitor.cc
src/mon/MonmapMonitor.cc
src/mon/OSDMonitor.cc
src/mon/PGMonitor.cc
src/os/MemStore.cc
src/osd/OSD.cc
src/osd/ReplicatedPG.cc
src/osdc/Objecter.cc
src/test/bench/small_io_bench_fs.cc
src/test/common/get_command_descriptions.cc
src/test/common/test_sloppy_crc_map.cc
src/test/common/test_tableformatter.cc
src/test/crush/TestCrushWrapper.cc
src/test/crush/indep.cc
src/test/osd/TestOSDMap.cc

index bee6a4e3388b13dbb8ceb77ce31eaf20ad5ce4ae..aeb0485e23f93921807dbfdce7ebd548d6a588be 100644 (file)
@@ -119,9 +119,7 @@ Client::CommandHook::CommandHook(Client *client) :
 bool Client::CommandHook::call(std::string command, cmdmap_t& cmdmap,
                               std::string format, bufferlist& out)
 {
-  Formatter *f = new_formatter(format);
-  if (!f)
-    f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create(format);
   f->open_object_section("result");
   m_client->client_lock.Lock();
   if (command == "mds_requests")
index 51c4c4bac1e5cd4421327599111ca07f87d2dd0f..0bd6520063ca066a478efc6661cb532733bb0c0e 100644 (file)
@@ -63,12 +63,12 @@ Formatter::Formatter() { }
 
 Formatter::~Formatter() { }
 
-Formatter *
-new_formatter(const std::string &type)
+Formatter *Formatter::create(const std::string &type,
+                            const std::string& default_type)
 {
   std::string mytype = type;
   if (mytype == "")
-    mytype = "json-pretty";
+    mytype = default_type;
 
   if (mytype == "json")
     return new JSONFormatter(false);
index 0012f001c64f328dc68d9a1bd7ed8e5437e8b84b..4929a2f091c29fdfbd23abbb0e0cacad319ba7e0 100644 (file)
@@ -1,3 +1,5 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
 #ifndef CEPH_FORMATTER_H
 #define CEPH_FORMATTER_H
 
@@ -25,6 +27,12 @@ namespace ceph {
 
   class Formatter {
   public:
+    static Formatter *create(const std::string& type,
+                            const std::string& default_type);
+    static Formatter *create(const std::string& type) {
+      return create(type, "json-pretty");
+    }
+
     Formatter();
     virtual ~Formatter();
 
@@ -72,8 +80,6 @@ namespace ceph {
     }
   };
 
-  Formatter *new_formatter(const std::string &type);
-
   class JSONFormatter : public Formatter {
   public:
     JSONFormatter(bool p = false);
index 24d165671c484e1970036e5fecd4cbf94fa21868..248228bd5405a65d4e7fce6d9a74878c1a5304bf 100644 (file)
@@ -448,9 +448,7 @@ class HelpHook : public AdminSocketHook {
 public:
   HelpHook(AdminSocket *as) : m_as(as) {}
   bool call(string command, cmdmap_t &cmdmap, string format, bufferlist& out) {
-    Formatter *f = new_formatter(format);
-    if (!f)
-      f = new_formatter("json-pretty");
+    Formatter *f = Formatter::create(format);
     f->open_object_section("help");
     for (map<string,string>::iterator p = m_as->m_help.begin();
         p != m_as->m_help.end();
index 6775fd03af0684a9693e6f9de32b7e757b7be2c3..db41420a50f83f11722f8f86b09c8f59ddb952b8 100644 (file)
@@ -225,9 +225,7 @@ public:
 void CephContext::do_command(std::string command, cmdmap_t& cmdmap,
                             std::string format, bufferlist *out)
 {
-  Formatter *f = new_formatter(format);
-  if (!f)
-    f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create(format);
   stringstream ss;
   for (cmdmap_t::iterator it = cmdmap.begin(); it != cmdmap.end(); ++it) {
     if (it->first != "prefix") {
index ffd49db358aa146f9c16143a4821dda3986cba1e..e4ea69366330990c532b6384490b3e901631dd6d 100644 (file)
@@ -221,9 +221,7 @@ bool MDS::asok_command(string command, cmdmap_t& cmdmap, string format,
 {
   dout(1) << "asok_command: " << command << " (starting...)" << dendl;
 
-  Formatter *f = new_formatter(format);
-  if (!f)
-    f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create(format);
   if (command == "status") {
 
     const OSDMap *osdmap = objecter->get_osdmap_read();
index 2050a447430ea632942159eda0f0164edbbabb34..c259e85ab0a3f4b9ec7440e3dd3cabd444d4d639 100644 (file)
@@ -557,7 +557,7 @@ bool AuthMonitor::preprocess_command(MMonCommand *m)
 
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   if (prefix == "auth export") {
     KeyRing keyring;
@@ -685,7 +685,7 @@ bool AuthMonitor::prepare_command(MMonCommand *m)
 
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   MonSession *session = m->get_session();
   if (!session) {
index 399dd2e387006989d9a4a23fc3786ea90f279ead..865b71f586eab2b2197d69a4a869ed052884aeba 100644 (file)
@@ -647,7 +647,7 @@ bool MDSMonitor::preprocess_command(MMonCommand *m)
   cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   MonSession *session = m->get_session();
   if (!session) {
index 78e2061fe6bebf4d74d09f0423ac2bd896aee1b9..1c26350b74c4cfc9b23f7159c78b1298ac370fdf 100644 (file)
@@ -267,7 +267,7 @@ void Monitor::do_admin_command(string command, cmdmap_t& cmdmap, string format,
 {
   Mutex::Locker l(lock);
 
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   string args;
   for (cmdmap_t::iterator p = cmdmap.begin();
@@ -2371,7 +2371,7 @@ void Monitor::handle_command(MMonCommand *m)
   cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
   if (prefix == "get_command_descriptions") {
     bufferlist rdata;
-    Formatter *f = new_formatter("json");
+    Formatter *f = Formatter::create("json");
     format_command_descriptions(leader_supported_mon_commands,
                                leader_supported_mon_commands_size, f, &rdata);
     delete f;
@@ -2386,7 +2386,7 @@ void Monitor::handle_command(MMonCommand *m)
 
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   get_str_vec(prefix, fullcmd);
   module = fullcmd[0];
@@ -2587,7 +2587,7 @@ void Monitor::handle_command(MMonCommand *m)
 
     // this must be formatted, in its current form
     if (!f)
-      f.reset(new_formatter("json-pretty"));
+      f.reset(Formatter::create("json-pretty"));
     f->open_object_section("report");
     f->dump_stream("cluster_fingerprint") << fingerprint;
     f->dump_string("version", ceph_version_to_str());
index d01fb8238176f775f924cbde4ec4f81a152b6584..c6b21cb47fc7c7d56bee38252d3b78eee5aa03fa 100644 (file)
@@ -216,7 +216,7 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
       string format;
       cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
       stringstream ds;
-      boost::scoped_ptr<Formatter> f(new_formatter(format));
+      boost::scoped_ptr<Formatter> f(Formatter::create(format));
       if (f) {
         f->open_object_section("monmap");
         p->dump(f.get());
index 97ed96e9d2b970b232b22c8fbe34da0a1066b4d3..963185c87af37a4b047c4ff158868793c6376ad7 100644 (file)
@@ -2334,7 +2334,7 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
 
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   if (prefix == "osd stat") {
     osdmap.print_summary(f.get(), ds);
@@ -2479,10 +2479,7 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
     }
     string format;
     cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
-    boost::scoped_ptr<Formatter> f(new_formatter(format));
-    if (!f)
-      f.reset(new_formatter("json-pretty"));
-
+    boost::scoped_ptr<Formatter> f(Formatter::create(format));
     f->open_object_section("osd_location");
     f->dump_int("osd", osd);
     f->dump_stream("ip") << osdmap.get_addr(osd);
@@ -2508,9 +2505,7 @@ bool OSDMonitor::preprocess_command(MMonCommand *m)
     }
     string format;
     cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
-    boost::scoped_ptr<Formatter> f(new_formatter(format));
-    if (!f)
-      f.reset(new_formatter("json-pretty"));
+    boost::scoped_ptr<Formatter> f(Formatter::create(format));
     f->open_object_section("osd_metadata");
     r = dump_osd_metadata(osd, f.get(), &ss);
     if (r < 0)
@@ -3007,10 +3002,7 @@ stats_out:
             prefix == "osd crush rule ls") {
     string format;
     cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
-    Formatter *fp = new_formatter(format);
-    if (!fp)
-      fp = new_formatter("json-pretty");
-    boost::scoped_ptr<Formatter> f(fp);
+    boost::scoped_ptr<Formatter> f(Formatter::create(format));
     f->open_array_section("rules");
     osdmap.crush->list_rules(f.get());
     f->close_section();
@@ -3023,10 +3015,7 @@ stats_out:
     cmd_getval(g_ceph_context, cmdmap, "name", name);
     string format;
     cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
-    Formatter *fp = new_formatter(format);
-    if (!fp)
-      fp = new_formatter("json-pretty");
-    boost::scoped_ptr<Formatter> f(fp);
+    boost::scoped_ptr<Formatter> f(Formatter::create(format));
     if (name == "") {
       f->open_array_section("rules");
       osdmap.crush->dump_rules(f.get());
@@ -3047,10 +3036,7 @@ stats_out:
   } else if (prefix == "osd crush dump") {
     string format;
     cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
-    Formatter *fp = new_formatter(format);
-    if (!fp)
-      fp = new_formatter("json-pretty");
-    boost::scoped_ptr<Formatter> f(fp);
+    boost::scoped_ptr<Formatter> f(Formatter::create(format));
     f->open_object_section("crush_map");
     osdmap.crush->dump(f.get());
     f->close_section();
@@ -3061,10 +3047,7 @@ stats_out:
   } else if (prefix == "osd crush show-tunables") {
     string format;
     cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
-    Formatter *fp = new_formatter(format);
-    if (!fp)
-      fp = new_formatter("json-pretty");
-    boost::scoped_ptr<Formatter> f(fp);
+    boost::scoped_ptr<Formatter> f(Formatter::create(format));
     f->open_object_section("crush_map_tunables");
     osdmap.crush->dump_tunables(f.get());
     f->close_section();
@@ -4102,7 +4085,7 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
 
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   string prefix;
   cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
index 5e73a7b9e529fab3bb25e609823003bb9222b0e4..87f32d69e28ca51854214aca66126f71eaaab541 100644 (file)
@@ -1482,7 +1482,7 @@ bool PGMonitor::preprocess_command(MMonCommand *m)
 
   string format;
   cmd_getval(g_ceph_context, cmdmap, "format", format, string("plain"));
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
 
   if (prefix == "pg stat") {
     if (f) {
index 5c75226e06cc919bec210803dbbdab3a3748ea40..7682a513e634679f9b2916334558ca4326ab482d 100644 (file)
@@ -101,7 +101,7 @@ int MemStore::_save()
 
 void MemStore::dump_all()
 {
-  Formatter *f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create("json-pretty");
   f->open_object_section("store");
   dump(f);
   f->close_section();
index 31187576fba8b92b0f60201a829fcd0a32ec9d5a..b7dca97f3a37538f20278a3c72d25381d609b00c 100644 (file)
@@ -1626,9 +1626,7 @@ public:
 bool OSD::asok_command(string command, cmdmap_t& cmdmap, string format,
                       ostream& ss)
 {
-  Formatter *f = new_formatter(format);
-  if (!f)
-    f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create(format);
   if (command == "status") {
     f->open_object_section("status");
     f->dump_stream("cluster_fsid") << superblock.cluster_fsid;
@@ -4897,7 +4895,7 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, buffe
   }
 
   cmd_getval(cct, cmdmap, "format", format);
-  f.reset(new_formatter(format));
+  f.reset(Formatter::create(format));
 
   if (prefix == "version") {
     if (f) {
@@ -8220,7 +8218,7 @@ void OSD::ShardedOpWQ::_process(uint32_t thread_index, heartbeat_handle_d *hb )
   }
 
   lgeneric_subdout(osd->cct, osd, 30) << "dequeue status: ";
-  Formatter *f = new_formatter("json");
+  Formatter *f = Formatter::create("json");
   f->open_object_section("q");
   dump(f);
   f->close_section();
index bea2a5f032c5d13d128586abb72f66840918c849..ea0babe79eacd09a5c23b537e96b36f6b8fce6a7 100644 (file)
@@ -603,10 +603,7 @@ int ReplicatedPG::do_command(cmdmap_t cmdmap, ostream& ss,
   string format;
 
   cmd_getval(cct, cmdmap, "format", format);
-  boost::scoped_ptr<Formatter> f(new_formatter(format));
-  // demand that we have a formatter
-  if (!f)
-    f.reset(new_formatter("json"));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format, "json"));
 
   string command;
   cmd_getval(cct, cmdmap, "cmd", command);
@@ -12271,7 +12268,7 @@ bool ReplicatedPG::agent_maybe_evict(ObjectContextRef& obc)
             << ", evict_effort " << agent_state->evict_effort
             << dendl;
     dout(30) << "agent_state:\n";
-    Formatter *f = new_formatter("");
+    Formatter *f = Formatter::create("");
     f->open_object_section("agent_state");
     agent_state->dump(f);
     f->close_section();
index 3e0d2caf9577d16db703f6db474e5a7c0af317fd..ca472a693888ccc208998dfa7073ec4322aaf394 100644 (file)
@@ -4225,9 +4225,7 @@ Objecter::RequestStateHook::RequestStateHook(Objecter *objecter) :
 bool Objecter::RequestStateHook::call(std::string command, cmdmap_t& cmdmap,
                                      std::string format, bufferlist& out)
 {
-  Formatter *f = new_formatter(format);
-  if (!f)
-    f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create(format);
   RWLock::RLocker rl(m_objecter->rwlock);
   m_objecter->dump_requests(f);
   f->flush(out);
index 23de6d16052313f3c66c53bcf64b07efdeecb35f..f5845855a1d5fa8c60a1b76ac458eca4f79acf7d 100644 (file)
@@ -32,7 +32,7 @@ struct MorePrinting : public DetailedStatCollector::AdditionalPrinting {
   MorePrinting(CephContext *cct) : cct(cct) {}
   void operator()(std::ostream *out) {
     bufferlist bl;
-    Formatter *f = new_formatter("json-pretty");
+    Formatter *f = Formatter::create("json-pretty");
     cct->get_perfcounters_collection()->dump_formatted(f, 0);
     f->flush(bl);
     delete f;
index c35e47ba6bdb7788b8abf4672932fd430fa0a89a..56d5359deaa646e37514453fd3fb99ccac207794 100644 (file)
@@ -44,7 +44,7 @@ static void usage(ostream &out)
 static void json_print(const MonCommand *mon_commands, int size)
 {
   bufferlist rdata;
-  Formatter *f = new_formatter("json");
+  Formatter *f = Formatter::create("json");
   Monitor::format_command_descriptions(mon_commands, size, f, &rdata);
   delete f;
   string data(rdata.c_str(), rdata.length());
index 2650f4f960d3f2d2f1b488171abf5a962f2fb5f8..1cdb6e459ded0cb414185e3105c4cf039a01089d 100644 (file)
@@ -7,7 +7,7 @@
 
 void dump(const SloppyCRCMap& scm)
 {
-  Formatter *f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create("json-pretty");
   f->open_object_section("map");
   scm.dump(f);
   f->close_section();
index cf00bbc8ed4341e0f6336c906585a6e6212114e6..88648f01d73b5e29992515d465aa171ae8e6b0fe 100644 (file)
@@ -195,7 +195,7 @@ TEST(tableformatter, extendingheader)
 TEST(tableformatter, stream)
 {
   std::stringstream sout;
-  TableFormatter* formatter = (TableFormatter*) new_formatter("table");
+  TableFormatter* formatter = (TableFormatter*) Formatter::create("table");
   formatter->dump_stream("integer") << 10;
   formatter->dump_stream("float") << 10.0;
   formatter->dump_stream("string") << "string";
@@ -215,7 +215,7 @@ TEST(tableformatter, stream)
 TEST(tableformatter, multiline_keyval)
 {
   std::stringstream sout;
-  TableFormatter* formatter = (TableFormatter*) new_formatter("table-kv");
+  TableFormatter* formatter = (TableFormatter*) Formatter::create("table-kv");
   formatter->dump_int("integer", 10);
   formatter->dump_float("float", 10.0);
   formatter->dump_string("string", "string");
index 40ead7f5c9b4e4e096288cf511b19f951aecaf02..ac6e06c878e34f285c88f897846403a4caa695ce 100644 (file)
@@ -845,7 +845,7 @@ TEST(CrushWrapper, dump_rules) {
 
   // no ruleset by default
   {
-    Formatter *f = new_formatter("json-pretty");
+    Formatter *f = Formatter::create("json-pretty");
     c->dump_rules(f);
     stringstream ss;
     f->flush(ss);
@@ -859,7 +859,7 @@ TEST(CrushWrapper, dump_rules) {
   EXPECT_EQ(0, ruleset);
 
   {
-    Formatter *f = new_formatter("xml");
+    Formatter *f = Formatter::create("xml");
     c->dump_rules(f);
     stringstream ss;
     f->flush(ss);
@@ -868,7 +868,7 @@ TEST(CrushWrapper, dump_rules) {
   }
 
   {
-    Formatter *f = new_formatter("xml");
+    Formatter *f = Formatter::create("xml");
     c->dump_rule(ruleset, f);
     stringstream ss;
     f->flush(ss);
index dd0b54272dbd5f5e91677bc8b2e5cc8347c7f7ee..887791472588f08f7063958538e6f4bb7ab6d65d 100644 (file)
@@ -68,7 +68,7 @@ CrushWrapper *build_indep_map(CephContext *cct, int num_rack, int num_host,
   c->set_rule_name(ruleno, "data");
 
   if (false) {
-    Formatter *f = new_formatter("json-pretty");
+    Formatter *f = Formatter::create("json-pretty");
     f->open_object_section("crush_map");
     c->dump(f);
     f->close_section();
index a4a62dccc956bbce0777cc4c07a834f4134c0dda..3f784fac99905040610e467e40b58bf1e4153fa7 100644 (file)
@@ -324,7 +324,7 @@ TEST_F(OSDMapTest, PrimaryAffinity) {
 
   /*
   osdmap.print(cout);
-  Formatter *f = new_formatter("json-pretty");
+  Formatter *f = Formatter::create("json-pretty");
   f->open_object_section("CRUSH");
   osdmap.crush->dump(f);
   f->close_section();