]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: 'ceph mon dump [--format=json]'
authorSage Weil <sage@newdream.net>
Thu, 28 Jul 2011 21:08:08 +0000 (14:08 -0700)
committerSage Weil <sage@newdream.net>
Thu, 28 Jul 2011 23:01:07 +0000 (16:01 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/mon/MonMap.cc
src/mon/MonMap.h
src/mon/MonmapMonitor.cc

index 2eddf47a5ebcfdd0ccda47139d39718d52f30bfe..89c6666890e53d2d47b43f8f281ba316a0813593 100644 (file)
@@ -5,6 +5,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#include "common/Formatter.h"
+
+using ceph::Formatter;
 
 // read from/write to a file
 int MonMap::write(const char *fn) 
@@ -47,3 +50,23 @@ void MonMap::print(ostream& out) const
        p++)
     out << i++ << ": " << p->second << " mon." << p->first << "\n";
 }
+
+void MonMap::dump(Formatter *f) const
+{
+  f->dump_int("epoch", epoch);
+  f->dump_stream("fsid") <<  fsid;
+  f->dump_stream("modified") << last_changed;
+  f->dump_stream("created") << created;
+  f->open_array_section("mons");
+  int i = 0;
+  for (map<string,entity_addr_t>::const_iterator p = mon_addr.begin();
+       p != mon_addr.end();
+       ++p, ++i) {
+    f->open_object_section("mon");
+    f->dump_int("rank", i);
+    f->dump_string("name", p->first);
+    f->dump_stream("addr") << p->second;
+    f->close_section();
+  }
+  f->close_section();
+}
index 635a83b38367d2cda207e9d35dc6e03e4b2794a1..025500eb0c26b29a05e6990675a089266c8ac051 100644 (file)
 #include "include/types.h"
 //#include "common/config.h"
 
+namespace ceph {
+  class Formatter;
+}
+
 class MonMap {
  public:
   epoch_t epoch;       // what epoch/version of the monmap
@@ -198,6 +202,7 @@ class MonMap {
 
   void print(ostream& out) const;
   void print_summary(ostream& out) const;
+  void dump(ceph::Formatter *f) const;
 };
 
 inline void encode(MonMap &m, bufferlist &bl) {
index 5d352ff50903f3fdd91aa2d0c26e3f0bf379e63b..3f5909324f716334d8444a92ceb1c89309b1a3ad 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "messages/MMonCommand.h"
 #include "common/Timer.h"
+#include "common/ceph_argparse.h"
 #include "mon/MDSMonitor.h"
 #include "mon/OSDMonitor.h"
 #include "mon/PGMonitor.h"
@@ -119,6 +120,10 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
   bufferlist rdata;
   stringstream ss;
 
+  vector<const char*> args;
+  for (unsigned i = 1; i < m->cmd.size(); i++)
+    args.push_back(m->cmd[i].c_str());
+
   if (m->cmd.size() > 1) {
     if (m->cmd[1] == "stat") {
       mon->monmap->print_summary(ss);
@@ -129,6 +134,66 @@ bool MonmapMonitor::preprocess_command(MMonCommand *m)
       mon->monmap->encode(rdata);
       r = 0;
       ss << "got latest monmap";
+    }
+    else if (m->cmd[1] == "dump") {
+      string format = "plain";
+      string val;
+      epoch_t epoch = 0;
+      string cmd = args[0];
+      for (std::vector<const char*>::iterator i = args.begin()+1; i != args.end(); ) {
+       if (ceph_argparse_witharg(args, i, &val, "-f", "--format", (char*)NULL))
+         format = val;
+       else if (!epoch)
+         epoch = atoi(*i++);
+       else
+         i++;
+      }
+
+      MonMap *p = mon->monmap;
+      if (epoch) {
+       /*
+       bufferlist b;
+       mon->store->get_bl_sn(b,"osdmap_full", epoch);
+       if (!b.length()) {
+         p = 0;
+         r = -ENOENT;
+       } else {
+         p = new OSDMap;
+         p->decode(b);
+       }
+       */
+      }
+      if (p) {
+       stringstream ds;
+       if (format == "json") {
+         Formatter *f = new JSONFormatter(true);
+         f->open_object_section("monmap");
+         p->dump(f);
+         f->open_array_section("quorum");
+         for (set<int>::iterator q = mon->get_quorum().begin(); q != mon->get_quorum().end(); ++q)
+           f->dump_int("mon", *q);
+         f->close_section();
+         f->close_section();
+         f->flush(ds);
+         delete f;
+         r = 0;
+       } else if (format == "plain") {
+         p->print(ds);
+         r = 0;
+       } else {
+         ss << "unrecognized format '" << format << "'";
+         r = -EINVAL;
+       }
+       if (r == 0) {
+         rdata.append(ds);
+         ss << "dumped monmap epoch " << p->get_epoch();
+       }
+       if (p != mon->monmap)
+         delete p;
+      }
+
+      
+
     }
     else if (m->cmd.size() >= 3 && m->cmd[1] == "tell") {
       dout(20) << "got tell: " << m->cmd << dendl;