]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_MMONCOMMAND_H | |
16 | #define CEPH_MMONCOMMAND_H | |
17 | ||
18 | #include "messages/PaxosServiceMessage.h" | |
19 | ||
20 | #include <vector> | |
11fdf7f2 TL |
21 | #include <string> |
22 | ||
adb31ebb TL |
23 | using TOPNSPC::common::cmdmap_from_json; |
24 | using TOPNSPC::common::cmd_getval; | |
25 | ||
f67539c2 | 26 | class MMonCommand final : public PaxosServiceMessage { |
11fdf7f2 | 27 | public: |
9f95a23c TL |
28 | // weird note: prior to octopus, MgrClient would leave fsid blank when |
29 | // sending commands to the mgr. Starting with octopus, this is either | |
30 | // populated with a valid fsid (tell command) or an MMgrCommand is sent | |
31 | // instead. | |
7c673cae | 32 | uuid_d fsid; |
11fdf7f2 | 33 | std::vector<std::string> cmd; |
7c673cae | 34 | |
9f95a23c | 35 | MMonCommand() : PaxosServiceMessage{MSG_MON_COMMAND, 0} {} |
7c673cae | 36 | MMonCommand(const uuid_d &f) |
9f95a23c | 37 | : PaxosServiceMessage{MSG_MON_COMMAND, 0}, |
7c673cae FG |
38 | fsid(f) |
39 | { } | |
40 | ||
41 | private: | |
f67539c2 | 42 | ~MMonCommand() final {} |
7c673cae | 43 | |
9f95a23c | 44 | public: |
11fdf7f2 | 45 | std::string_view get_type_name() const override { return "mon_command"; } |
9f95a23c | 46 | void print(std::ostream& o) const override { |
adb31ebb | 47 | cmdmap_t cmdmap; |
f67539c2 | 48 | std::ostringstream ss; |
20effc67 | 49 | std::string prefix; |
adb31ebb TL |
50 | cmdmap_from_json(cmd, &cmdmap, ss); |
51 | cmd_getval(cmdmap, "prefix", prefix); | |
52 | // Some config values contain sensitive data, so don't log them | |
7c673cae | 53 | o << "mon_command("; |
adb31ebb | 54 | if (prefix == "config set") { |
20effc67 | 55 | std::string name; |
adb31ebb TL |
56 | cmd_getval(cmdmap, "name", name); |
57 | o << "[{prefix=" << prefix << ", name=" << name << "}]"; | |
58 | } else if (prefix == "config-key set") { | |
20effc67 | 59 | std::string key; |
adb31ebb TL |
60 | cmd_getval(cmdmap, "key", key); |
61 | o << "[{prefix=" << prefix << ", key=" << key << "}]"; | |
62 | } else { | |
63 | for (unsigned i=0; i<cmd.size(); i++) { | |
64 | if (i) o << ' '; | |
65 | o << cmd[i]; | |
66 | } | |
7c673cae FG |
67 | } |
68 | o << " v " << version << ")"; | |
69 | } | |
9f95a23c | 70 | |
7c673cae | 71 | void encode_payload(uint64_t features) override { |
11fdf7f2 | 72 | using ceph::encode; |
7c673cae | 73 | paxos_encode(); |
11fdf7f2 TL |
74 | encode(fsid, payload); |
75 | encode(cmd, payload); | |
7c673cae FG |
76 | } |
77 | void decode_payload() override { | |
9f95a23c | 78 | using ceph::decode; |
11fdf7f2 | 79 | auto p = payload.cbegin(); |
7c673cae | 80 | paxos_decode(p); |
11fdf7f2 TL |
81 | decode(fsid, p); |
82 | decode(cmd, p); | |
7c673cae | 83 | } |
9f95a23c TL |
84 | private: |
85 | template<class T, typename... Args> | |
86 | friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); | |
7c673cae FG |
87 | }; |
88 | ||
89 | #endif |