]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MgrMonitor: add 'mgr dump [epoch]' command 15158/head
authorSage Weil <sage@redhat.com>
Thu, 18 May 2017 16:05:13 +0000 (12:05 -0400)
committerSage Weil <sage@redhat.com>
Thu, 18 May 2017 16:05:13 +0000 (12:05 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
qa/workunits/cephtool/test.sh
src/mon/MgrMonitor.cc
src/mon/MonCommands.h

index 92a8db1f3c54f16ec9bcc644e965677c7635a905..07b8df941cb70c1946fa9b2197fde51add503a59 100755 (executable)
@@ -680,6 +680,8 @@ function test_mon_misc()
   ceph log "$mymsg"
   ceph_watch_wait "$mymsg"
 
+  ceph mgr dump
+
   ceph mon metadata a
   ceph mon metadata
   ceph node ls
index b36da2fce57c43cfea62901354c8a664abab3f95..0eda70d994dbc8a5df5f4ba2644aeae81c999c11 100644 (file)
@@ -444,8 +444,60 @@ void MgrMonitor::drop_standby(uint64_t gid)
 
 bool MgrMonitor::preprocess_command(MonOpRequestRef op)
 {
-  return false;
+  MMonCommand *m = static_cast<MMonCommand*>(op->get_req());
+  std::stringstream ss;
+  bufferlist rdata;
+
+  std::map<std::string, cmd_vartype> cmdmap;
+  if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) {
+    string rs = ss.str();
+    mon->reply_command(op, -EINVAL, rs, rdata, get_last_committed());
+    return true;
+  }
+
+  MonSession *session = m->get_session();
+  if (!session) {
+    mon->reply_command(op, -EACCES, "access denied", rdata,
+                      get_last_committed());
+    return true;
+  }
 
+  string format;
+  cmd_getval(g_ceph_context, cmdmap, "format", format, string("json-pretty"));
+  boost::scoped_ptr<Formatter> f(Formatter::create(format));
+
+  string prefix;
+  cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
+  int r = 0;
+
+  if (prefix == "mgr dump") {
+    int64_t epoch = 0;
+    cmd_getval(g_ceph_context, cmdmap, "epoch", epoch, (int64_t)map.get_epoch());
+    if (epoch == (int64_t)map.get_epoch()) {
+      f->dump_object("mgrmap", map);
+    } else {
+      bufferlist bl;
+      int err = get_version(epoch, bl);
+      if (err == -ENOENT) {
+       r = -ENOENT;
+       ss << "there is no map for epoch " << epoch;
+       goto reply;
+      }
+      MgrMap m;
+      auto p = bl.begin();
+      m.decode(p);
+      f->dump_object("mgrmap", m);
+    }
+    f->flush(rdata);
+  } else {
+    return false;
+  }
+
+reply:
+  string rs;
+  getline(ss, rs);
+  mon->reply_command(op, r, rs, rdata, get_last_committed());
+  return true;
 }
 
 bool MgrMonitor::prepare_command(MonOpRequestRef op)
index c7b932690b91ed1d070a38b4680edccbf213443a..2c91d79c5d4cab5a8d9ca2f8ab7e463455080437 100644 (file)
@@ -840,5 +840,9 @@ COMMAND("config-key dump", "dump keys and values", "config-key", "r", "cli,rest"
 /*
  * mon/MgrMonitor.cc
  */
+COMMAND("mgr dump "                                 \
+       "name=epoch,type=CephInt,range=0,req=false", \
+       "dump the latest MgrMap",                    \
+       "mgr", "rw", "cli,rest")
 COMMAND("mgr fail name=who,type=CephString", \
        "treat the named manager daemon as failed", "mgr", "rw", "cli,rest")