]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: register as a service 15858/head
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 30 Jun 2017 16:04:05 +0000 (12:04 -0400)
committerSage Weil <sage@redhat.com>
Sun, 9 Jul 2017 18:09:05 +0000 (14:09 -0400)
support dynamic reload, and also add frontend info

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_frontend.h
src/rgw/rgw_main.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_realm_reloader.cc
src/rgw/rgw_realm_reloader.h

index 1c999b4d68fe4cfa77faef800d0ffd6785468e06..dc4563c76d91b1b36d91e074f1b1207e11d48856 100644 (file)
@@ -50,6 +50,10 @@ public:
     return out;
   }
 
+  const std::string& get_config() {
+    return config;
+  }
+
   std::map<std::string, std::string>& get_config_map() {
     return config_map;
   }
index f4e57be713a9268fd22fc28072775ff46955d0d8..85ec5fec0c0ecf0174841a2255b1598e9f0bcac2 100644 (file)
@@ -26,6 +26,7 @@
 #include "common/safe_io.h"
 #include "include/compat.h"
 #include "include/str_list.h"
+#include "include/stringify.h"
 #include "rgw_common.h"
 #include "rgw_rados.h"
 #include "rgw_user.h"
@@ -470,15 +471,21 @@ int main(int argc, const char **argv)
   register_async_signal_handler(SIGUSR1, handle_sigterm);
   sighandler_alrm = signal(SIGALRM, godown_alarm);
 
+  map<string, string> service_map_meta;
+  service_map_meta["pid"] = stringify(getpid());
+
   list<RGWFrontend *> fes;
 
+  int fe_count = 0;
+
   for (multimap<string, RGWFrontendConfig *>::iterator fiter = fe_map.begin();
-       fiter != fe_map.end(); ++fiter) {
+       fiter != fe_map.end(); ++fiter, ++fe_count) {
     RGWFrontendConfig *config = fiter->second;
     string framework = config->get_framework();
     RGWFrontend *fe = NULL;
 
     if (framework == "civetweb" || framework == "mongoose") {
+      framework = "civetweb";
       std::string uri_prefix;
       config->get_val("prefix", "", &uri_prefix);
 
@@ -509,6 +516,7 @@ int main(int argc, const char **argv)
 #endif /* WITH_RADOSGW_BEAST_FRONTEND */
 #if defined(WITH_RADOSGW_FCGI_FRONTEND)
     else if (framework == "fastcgi" || framework == "fcgi") {
+      framework = "fastcgi";
       std::string uri_prefix;
       config->get_val("prefix", "", &uri_prefix);
       RGWProcessEnv fcgi_pe = { store, &rest, olog, 0, uri_prefix, auth_registry };
@@ -517,6 +525,9 @@ int main(int argc, const char **argv)
     }
 #endif /* WITH_RADOSGW_FCGI_FRONTEND */
 
+    service_map_meta["frontend_type#" + stringify(fe_count)] = framework;
+    service_map_meta["frontend_config#" + stringify(fe_count)] = config->get_config();
+
     if (fe == NULL) {
       dout(0) << "WARNING: skipping unknown framework: " << framework << dendl;
       continue;
@@ -537,10 +548,18 @@ int main(int argc, const char **argv)
     fes.push_back(fe);
   }
 
+  r = store->register_to_service_map("rgw", service_map_meta);
+  if (r < 0) {
+    derr << "ERROR: failed to register to service map: " << cpp_strerror(-r) << dendl;
+
+    /* ignore error */
+  }
+
+
   // add a watcher to respond to realm configuration changes
   RGWPeriodPusher pusher(store);
   RGWFrontendPauser pauser(fes, &pusher);
-  RGWRealmReloader reloader(store, &pauser);
+  RGWRealmReloader reloader(store, service_map_meta, &pauser);
 
   preloader = &reloader;
 
index 9dafa0b420c2981b8bb7c5eaf53b78e3fdd54d93..53cee1148bb9ace797932c4ffc446787553fffad 100644 (file)
@@ -3752,7 +3752,6 @@ int RGWRados::init_rados()
     if (ret < 0) {
       return ret;
     }
-
     ret = r.connect();
     if (ret < 0) {
       return ret;
@@ -3778,6 +3777,28 @@ int RGWRados::init_rados()
   return ret;
 }
 
+
+int RGWRados::register_to_service_map(const string& daemon_type, const map<string, string>& meta)
+{
+  map<string,string> metadata = meta;
+  metadata["num_handles"] = stringify(rados.size());
+  metadata["zonegroup_id"] = zonegroup.get_id();
+  metadata["zonegroup_name"] = zonegroup.get_name();
+  metadata["zone_name"] = zone_name();
+  metadata["zone_id"] = zone_id();;
+  string name = cct->_conf->name.get_id();
+  if (name.find("rgw.") == 0) {
+    name = name.substr(4);
+  }
+  int ret = rados[0].service_daemon_register(daemon_type, name, metadata);
+  if (ret < 0) {
+    ldout(cct, 0) << "ERROR: service_daemon_register() returned ret=" << ret << ": " << cpp_strerror(-ret) << dendl;
+    return ret;
+  }
+
+  return 0;
+}
+
 /**
  * Add new connection to connections map
  * @param zonegroup_conn_map map which new connection will be added to
@@ -5893,7 +5914,7 @@ int RGWRados::select_bucket_location_by_rule(const string& location_rule, RGWZon
   map<string, RGWZonePlacementInfo>::iterator piter = get_zone_params().placement_pools.find(location_rule);
   if (piter == get_zone_params().placement_pools.end()) {
     /* couldn't find, means we cannot really place data for this bucket in this zone */
-    if (get_zonegroup().equals(zonegroup_id)) {
+    if (get_zonegroup().equals(zonegroup.get_id())) {
       /* that's a configuration error, zone should have that rule, as we're within the requested
        * zonegroup */
       return -EINVAL;
index 4759320f39c78a99efd16e53301aa4fccfc3f042..a36226c088f846836df10b63d14b2b7227b61f78 100644 (file)
@@ -2332,8 +2332,6 @@ protected:
 
   bool pools_initialized;
 
-  string zonegroup_id;
-  string zone_name;
   string trans_id_suffix;
 
   RGWQuotaHandler *quota_handler;
@@ -2565,6 +2563,8 @@ public:
   int initialize();
   void finalize();
 
+  int register_to_service_map(const string& daemon_type, const map<string, string>& meta);
+
   void schedule_context(Context *c);
 
   /** set up a bucket listing. handle is filled in. */
@@ -3537,6 +3537,9 @@ public:
   int add_bucket_to_reshard(const RGWBucketInfo& bucket_info, uint32_t new_num_shards);
 
   uint64_t instance_id();
+  const string& zone_name() {
+    return get_zone_params().get_name();
+  }
   const string& zone_id() {
     return get_zone_params().get_id();
   }
index 8df554a5f3b31415947178be4ddf3af538f27e67..2bae84c1ecbd296fd56e1ac7ab8ee59f52d87d91 100644 (file)
@@ -9,6 +9,8 @@
 #include "rgw_rest.h"
 #include "rgw_user.h"
 
+#include "common/errno.h"
+
 #define dout_subsys ceph_subsys_rgw
 
 #undef dout_prefix
 static constexpr bool USE_SAFE_TIMER_CALLBACKS = false;
 
 
-RGWRealmReloader::RGWRealmReloader(RGWRados*& store, Pauser* frontends)
+RGWRealmReloader::RGWRealmReloader(RGWRados*& store, std::map<std::string, std::string>& service_map_meta,
+                                   Pauser* frontends)
   : store(store),
+    service_map_meta(service_map_meta),
     frontends(frontends),
     timer(store->ctx(), mutex, USE_SAFE_TIMER_CALLBACKS),
     mutex("RGWRealmReloader"),
@@ -144,6 +148,13 @@ void RGWRealmReloader::reload()
     }
   }
 
+  int r = store->register_to_service_map("rgw", service_map_meta);
+  if (r < 0) {
+    lderr(cct) << "ERROR: failed to register to service map: " << cpp_strerror(-r) << dendl;
+
+    /* ignore error */
+  }
+
   ldout(cct, 1) << "Finishing initialization of new store" << dendl;
   // finish initializing the new store
   ldout(cct, 1) << " - REST subsystem init" << dendl;
index e4e3a4363425c3c00aedda7db8e0321cde064256..ab9f4e56ec4b1b7c5443c680db64d5dc88e5d85a 100644 (file)
@@ -32,7 +32,8 @@ class RGWRealmReloader : public RGWRealmWatcher::Watcher {
     virtual void resume(RGWRados* store) = 0;
   };
 
-  RGWRealmReloader(RGWRados*& store, Pauser* frontends);
+  RGWRealmReloader(RGWRados*& store, std::map<std::string, std::string>& service_map_meta,
+                   Pauser* frontends);
   ~RGWRealmReloader() override;
 
   /// respond to realm notifications by scheduling a reload()
@@ -46,6 +47,7 @@ class RGWRealmReloader : public RGWRealmWatcher::Watcher {
 
   /// main()'s RGWRados pointer as a reference, modified by reload()
   RGWRados*& store;
+  std::map<std::string, std::string>& service_map_meta;
   Pauser *const frontends;
 
   /// reload() takes a significant amount of time, so we don't want to run