| 292 | } |
| 293 | |
| 294 | bool MonmapMonitor::preprocess_command(MonOpRequestRef op) |
| 295 | { |
| 296 | auto m = op->get_req<MMonCommand>(); |
| 297 | int r = -1; |
| 298 | bufferlist rdata; |
| 299 | stringstream ss; |
| 300 | |
| 301 | cmdmap_t cmdmap; |
| 302 | if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) { |
| 303 | string rs = ss.str(); |
| 304 | mon.reply_command(op, -EINVAL, rs, rdata, get_last_committed()); |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | string prefix; |
| 309 | cmd_getval(cmdmap, "prefix", prefix); |
| 310 | |
| 311 | MonSession *session = op->get_session(); |
| 312 | if (!session) { |
| 313 | mon.reply_command(op, -EACCES, "access denied", get_last_committed()); |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | string format = cmd_getval_or<string>(cmdmap, "format", "plain"); |
| 318 | boost::scoped_ptr<Formatter> f(Formatter::create(format)); |
| 319 | |
| 320 | if (prefix == "mon stat") { |
| 321 | if (f) { |
| 322 | f->open_object_section("monmap"); |
| 323 | mon.monmap->dump_summary(f.get()); |
| 324 | f->dump_string("leader", mon.get_leader_name()); |
| 325 | f->open_array_section("quorum"); |
| 326 | for (auto rank: mon.get_quorum()) { |
| 327 | std::string name = mon.monmap->get_name(rank); |
| 328 | f->open_object_section("mon"); |
| 329 | f->dump_int("rank", rank); |
| 330 | f->dump_string("name", name); |
| 331 | f->close_section(); // mon |
| 332 | } |
| 333 | f->close_section(); // quorum |
| 334 | f->close_section(); // monmap |
| 335 | f->flush(ss); |
| 336 | } else { |
| 337 | mon.monmap->print_summary(ss); |
| 338 | ss << ", election epoch " << mon.get_epoch() << ", leader " |
| 339 | << mon.get_leader() << " " << mon.get_leader_name() |
| 340 | << ", quorum " << mon.get_quorum() |
| 341 | << " " << mon.get_quorum_names(); |
| 342 | } |
| 343 | |
| 344 | rdata.append(ss); |
| 345 | ss.str(""); |
| 346 | r = 0; |
| 347 | |
| 348 | } else if (prefix == "mon getmap" || |
| 349 | prefix == "mon dump") { |
| 350 | |
| 351 | epoch_t epoch; |
nothing calls this directly
no test coverage detected