| 963 | } |
| 964 | |
| 965 | bool MgrMonitor::preprocess_command(MonOpRequestRef op) |
| 966 | { |
| 967 | auto m = op->get_req<MMonCommand>(); |
| 968 | std::stringstream ss; |
| 969 | bufferlist rdata; |
| 970 | |
| 971 | cmdmap_t cmdmap; |
| 972 | if (!cmdmap_from_json(m->cmd, &cmdmap, ss)) { |
| 973 | string rs = ss.str(); |
| 974 | mon.reply_command(op, -EINVAL, rs, rdata, get_last_committed()); |
| 975 | return true; |
| 976 | } |
| 977 | |
| 978 | MonSession *session = op->get_session(); |
| 979 | if (!session) { |
| 980 | mon.reply_command(op, -EACCES, "access denied", rdata, |
| 981 | get_last_committed()); |
| 982 | return true; |
| 983 | } |
| 984 | |
| 985 | string format = cmd_getval_or<string>(cmdmap, "format", "plain"); |
| 986 | boost::scoped_ptr<Formatter> f(Formatter::create(format)); |
| 987 | |
| 988 | string prefix; |
| 989 | cmd_getval(cmdmap, "prefix", prefix); |
| 990 | int r = 0; |
| 991 | |
| 992 | if (prefix == "mgr stat") { |
| 993 | if (!f) { |
| 994 | f.reset(Formatter::create(format, "json-pretty", "json-pretty")); |
| 995 | } |
| 996 | f->open_object_section("stat"); |
| 997 | f->dump_unsigned("epoch", map.get_epoch()); |
| 998 | f->dump_bool("available", map.get_available()); |
| 999 | f->dump_string("active_name", map.get_active_name()); |
| 1000 | f->dump_unsigned("num_standby", map.get_num_standby()); |
| 1001 | f->close_section(); |
| 1002 | f->flush(rdata); |
| 1003 | } else if (prefix == "mgr dump") { |
| 1004 | if (!f) { |
| 1005 | f.reset(Formatter::create(format, "json-pretty", "json-pretty")); |
| 1006 | } |
| 1007 | int64_t epoch = cmd_getval_or<int64_t>(cmdmap, "epoch", map.get_epoch()); |
| 1008 | if (epoch == (int64_t)map.get_epoch()) { |
| 1009 | f->dump_object("mgrmap", map); |
| 1010 | } else { |
| 1011 | bufferlist bl; |
| 1012 | int err = get_version(epoch, bl); |
| 1013 | if (err == -ENOENT) { |
| 1014 | r = -ENOENT; |
| 1015 | ss << "there is no map for epoch " << epoch; |
| 1016 | goto reply; |
| 1017 | } |
| 1018 | MgrMap m; |
| 1019 | auto p = bl.cbegin(); |
| 1020 | m.decode(p); |
| 1021 | f->dump_object("mgrmap", m); |
| 1022 | } |
nothing calls this directly
no test coverage detected