]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/admin: move config hooks into admin_socket.cc
authorKefu Chai <kchai@redhat.com>
Tue, 4 Aug 2020 06:27:35 +0000 (14:27 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 4 Aug 2020 07:28:47 +0000 (15:28 +0800)
they are not specific to OSD, let's move them into admin_socket.cc

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/admin/admin_socket.cc
src/crimson/admin/osd_admin.cc
src/crimson/admin/osd_admin.h
src/crimson/osd/osd.cc

index 07244fed84b49261db5c7b552f700e066e549850..21d97b8093b18e2a3c87c89d31d6c70143dd9ef0 100644 (file)
@@ -415,6 +415,104 @@ public:
   }
 };
 
+/**
+ * listing the configuration values
+ */
+class ConfigShowHook : public AdminSocketHook {
+public:
+  explicit ConfigShowHook() :
+  AdminSocketHook("config show",
+                 "config show",
+                  "dump current config settings")
+  {}
+  seastar::future<tell_result_t> call(const cmdmap_t&,
+                                      std::string_view format,
+                                      ceph::bufferlist&& input) const final
+  {
+    unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
+    f->open_object_section("config_show");
+    local_conf().show_config(f.get());
+    f->close_section();
+    return seastar::make_ready_future<tell_result_t>(f.get());
+  }
+};
+
+/**
+ * fetching the value of a specific configuration item
+ */
+class ConfigGetHook : public AdminSocketHook {
+public:
+  ConfigGetHook() :
+    AdminSocketHook("config get",
+                    "config get name=var,type=CephString",
+                    "config get <field>: get the config value")
+  {}
+  seastar::future<tell_result_t> call(const cmdmap_t& cmdmap,
+                                      std::string_view format,
+                                      ceph::bufferlist&& input) const final
+  {
+    std::string var;
+    if (!cmd_getval(cmdmap, "var", var)) {
+      // should have been caught by 'validate()'
+      return seastar::make_ready_future<tell_result_t>(
+        tell_result_t{-EINVAL, "syntax error: 'config get <var>'"});
+    }
+    try {
+      unique_ptr<Formatter> f{Formatter::create(format,
+                                                "json-pretty",
+                                                "json-pretty")};
+      f->open_object_section("config_get");
+      std::string conf_val =
+        local_conf().get_val<std::string>(var);
+      f->dump_string(var.c_str(), conf_val.c_str());
+      f->close_section();
+      return seastar::make_ready_future<tell_result_t>(f.get());
+    } catch (const boost::bad_get&) {
+      return seastar::make_ready_future<tell_result_t>(
+        tell_result_t{-EINVAL, fmt::format("unrecognized option {}", var)});
+    }
+  }
+};
+
+/**
+ * setting the value of a specific configuration item (an example:
+ * {"prefix": "config set", "var":"debug_osd", "val": ["30/20"]} )
+ */
+class ConfigSetHook : public AdminSocketHook {
+public:
+  ConfigSetHook()
+    : AdminSocketHook("config set",
+                      "config set"
+                      " name=var,type=CephString"
+                      " name=val,type=CephString,n=N",
+                      "config set <field> <val> [<val> ...]: set a config variable")
+  {}
+  seastar::future<tell_result_t> call(const cmdmap_t& cmdmap,
+                                      std::string_view format,
+                                      ceph::bufferlist&&) const final
+  {
+    std::string var;
+    std::vector<std::string> new_val;
+    if (!cmd_getval(cmdmap, "var", var) ||
+        !cmd_getval(cmdmap, "val", new_val)) {
+      return seastar::make_ready_future<tell_result_t>(
+        tell_result_t{-EINVAL, "syntax error: 'config set <var> <value>'"});
+    }
+    // val may be multiple words
+    const std::string joined_values = boost::algorithm::join(new_val, " ");
+    return local_conf().set_val(var, joined_values).then([format] {
+      unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
+      f->open_object_section("config_set");
+      f->dump_string("success", "");
+      f->close_section();
+      return seastar::make_ready_future<tell_result_t>(f.get());
+    }).handle_exception_type([](std::invalid_argument& e) {
+      return seastar::make_ready_future<tell_result_t>(
+        tell_result_t{-EINVAL, e.what()});
+    });
+  }
+};
+
 /// the hooks that are served directly by the admin_socket server
 seastar::future<> AdminSocket::register_admin_commands()
 {
@@ -423,6 +521,9 @@ seastar::future<> AdminSocket::register_admin_commands()
     register_command(std::make_unique<GitVersionHook>()),
     register_command(std::make_unique<HelpHook>(*this)),
     register_command(std::make_unique<GetdescsHook>(*this)),
+    register_command(std::make_unique<ConfigGetHook>()),
+    register_command(std::make_unique<ConfigSetHook>()),
+    register_command(std::make_unique<ConfigShowHook>()),
     register_command(std::make_unique<InjectArgsHook>()));
 }
 
index 4675d8d2230c8cb6f9e49f00611ae4fb8ed3ab90..e4f5f401df4f0875f18563a529813d00e62115cf 100644 (file)
@@ -79,105 +79,6 @@ private:
 template std::unique_ptr<AdminSocketHook>
 make_asok_hook<SendBeaconHook>(crimson::osd::OSD& osd);
 
-/**
- * A CephContext admin hook: listing the configuration values
- */
-class ConfigShowHook : public AdminSocketHook {
-public:
-  explicit ConfigShowHook() :
-  AdminSocketHook("config show",
-                  "config show",
-                  "dump current config settings")
-  {}
-  seastar::future<tell_result_t> call(const cmdmap_t&,
-                                     std::string_view format,
-                                     ceph::bufferlist&& input) const final
-  {
-    unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
-    f->open_object_section("config_show");
-    local_conf().show_config(f.get());
-    f->close_section();
-    return seastar::make_ready_future<tell_result_t>(f.get());
-  }
-};
-template std::unique_ptr<AdminSocketHook> make_asok_hook<ConfigShowHook>();
-
-/**
- * A CephContext admin hook: fetching the value of a specific
- * configuration item
- */
-class ConfigGetHook : public AdminSocketHook {
-public:
-  ConfigGetHook() :
-    AdminSocketHook("config get",
-                    "config get name=var,type=CephString",
-                    "config get <field>: get the config value")
-  {}
-  seastar::future<tell_result_t> call(const cmdmap_t& cmdmap,
-                                     std::string_view format,
-                                     ceph::bufferlist&& input) const final
-  {
-    std::string var;
-    if (!cmd_getval(cmdmap, "var", var)) {
-      // should have been caught by 'validate()'
-      return seastar::make_ready_future<tell_result_t>(
-        tell_result_t{-EINVAL, "syntax error: 'config get <var>'"});
-    }
-    try {
-      unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
-      f->open_object_section("config_get");
-      std::string conf_val =
-        local_conf().get_val<std::string>(var);
-      f->dump_string(var.c_str(), conf_val.c_str());
-      f->close_section();
-      return seastar::make_ready_future<tell_result_t>(f.get());
-    } catch (const boost::bad_get&) {
-      return seastar::make_ready_future<tell_result_t>(
-        tell_result_t{-EINVAL, fmt::format("unrecognized option {}", var)});
-    }
-  }
-};
-template std::unique_ptr<AdminSocketHook> make_asok_hook<ConfigGetHook>();
-
-/**
- * A CephContext admin hook: setting the value of a specific configuration
- * item (a real example: {"prefix": "config set", "var":"debug_osd", "val":
- * ["30/20"]} )
- */
-class ConfigSetHook : public AdminSocketHook {
-public:
-  ConfigSetHook()  :
-    AdminSocketHook("config set",
-                    "config set name=var,type=CephString name=val,type=CephString,n=N",
-                    "config set <field> <val> [<val> ...]: set a config variable")
-  {}
-  seastar::future<tell_result_t> call(const cmdmap_t& cmdmap,
-                                     std::string_view format,
-                                     ceph::bufferlist&&) const final
-  {
-    std::string var;
-    std::vector<std::string> new_val;
-    if (!cmd_getval(cmdmap, "var", var) ||
-        !cmd_getval(cmdmap, "val", new_val)) {
-      return seastar::make_ready_future<tell_result_t>(
-        tell_result_t{-EINVAL, "syntax error: 'config set <var> <value>'"});
-    }
-    // val may be multiple words
-    string valstr = str_join(new_val, " ");
-    return local_conf().set_val(var, valstr).then([format] {
-      unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
-      f->open_object_section("config_set");
-      f->dump_string("success", "");
-      f->close_section();
-      return seastar::make_ready_future<tell_result_t>(f.get());
-    }).handle_exception_type([](std::invalid_argument& e) {
-      return seastar::make_ready_future<tell_result_t>(
-        tell_result_t{-EINVAL, e.what()});
-    });
-  }
-};
-template std::unique_ptr<AdminSocketHook> make_asok_hook<ConfigSetHook>();
-
 /**
  * send the latest pg stats to mgr
  */
index 6a0b8b230ba705a0383070ecde12d4ed6d8d921d..3f750fbcc019ff87a1d4f625ad04162120affbe2 100644 (file)
@@ -9,9 +9,6 @@
 namespace crimson::admin {
 
 class AssertAlwaysHook;
-class ConfigShowHook;
-class ConfigGetHook;
-class ConfigSetHook;
 class FlushPgStatsHook;
 class OsdStatusHook;
 class SendBeaconHook;
index 87409c242f7c993808894d9791806f132a454c74..8454780f4ca1d5f1f59dd18140054959ecaadac9 100644 (file)
@@ -429,9 +429,6 @@ seastar::future<> OSD::start_asok_admin()
       asok->register_admin_commands(),
       asok->register_command(make_asok_hook<OsdStatusHook>(*this)),
       asok->register_command(make_asok_hook<SendBeaconHook>(*this)),
-      asok->register_command(make_asok_hook<ConfigShowHook>()),
-      asok->register_command(make_asok_hook<ConfigGetHook>()),
-      asok->register_command(make_asok_hook<ConfigSetHook>()),
       asok->register_command(make_asok_hook<FlushPgStatsHook>(*this)));
   });
 }