]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: basic rgw services registry
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 10 Aug 2018 00:04:48 +0000 (17:04 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 8 Nov 2018 17:18:09 +0000 (09:18 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/CMakeLists.txt
src/rgw/rgw_service.cc [new file with mode: 0644]
src/rgw/rgw_service.h [new file with mode: 0644]
src/rgw/services/svc_rados.cc [new file with mode: 0644]
src/rgw/services/svc_rados.h [new file with mode: 0644]

index 939282733c221d698617d75df02b8a9974c92f31..fa3a4d3c5a1c13cf5c0e233a1f46fa89e3fe08c9 100644 (file)
@@ -39,6 +39,8 @@ function(gperf_generate input output)
 endfunction()
 
 set(librgw_common_srcs
+  services/svc_rados.cc
+  rgw_service.cc
   rgw_acl.cc
   rgw_acl_s3.cc
   rgw_acl_swift.cc
@@ -117,6 +119,8 @@ set(librgw_common_srcs
 
 add_library(rgw_common OBJECT ${librgw_common_srcs})
 
+target_include_directories(rgw_common SYSTEM PUBLIC "services")
+
 if(WITH_LTTNG)
   # rgw/rgw_op.cc includes "tracing/rgw_op.h"
   # rgw/rgw_rados.cc includes "tracing/rgw_rados.h"
diff --git a/src/rgw/rgw_service.cc b/src/rgw/rgw_service.cc
new file mode 100644 (file)
index 0000000..5a4da59
--- /dev/null
@@ -0,0 +1,61 @@
+#include "rgw_service.h"
+
+#include "services/svc_rados.h"
+
+
+
+RGWServiceInstance::~RGWServiceInstance()
+{
+  if (svc) {
+    svc->svc_registry->remove_instance(this);
+  }
+}
+
+void RGWServiceRegistry::register_all(CephContext *cct)
+{
+  services["rados"] = make_shared<RGWS_RADOS>(cct);
+}
+
+bool RGWServiceRegistry::find(const string& name, RGWServiceRef *svc)
+{
+  auto iter = services.find(name);
+  if (iter == services.end()) {
+    return false;
+  }
+
+  *svc = iter->second;
+  return true;
+}
+
+int RGWServiceRegistry::instantiate(RGWServiceRegistryRef& registry, RGWServiceRef& svc, JSONFormattable& conf) {
+  auto self_ref = shared_from_this();
+  RGWServiceInstanceRef instance_ref;
+  int r = svc->create_instance(conf, &instance_ref);
+  if (r < 0) {
+    return r;
+  }
+  instance_ref->svc = svc;
+  instance_ref->svc_id = ++max_registry_id;
+
+  r = instance_ref->init(conf);
+  if (r < 0) {
+    return r;
+  }
+
+  if (instance_ref->svc_instance.empty()) {
+    char buf[32];
+    snprintf(buf, sizeof(buf), "%lld", (long long)instance_ref->svc_id);
+    instance_ref->svc_instance = buf;
+  }
+
+  instance_info& iinfo = instances[instance_ref->svc_id];
+  iinfo.id = instance_ref->svc_id;
+  iinfo.title = instance_ref->get_title();
+  iinfo.conf = conf;
+
+  return 0;
+}
+
+void RGWServiceRegistry::remove_instance(RGWServiceInstance *instance) {
+  instances.erase(instance->svc_id);
+}
diff --git a/src/rgw/rgw_service.h b/src/rgw/rgw_service.h
new file mode 100644 (file)
index 0000000..04022b3
--- /dev/null
@@ -0,0 +1,90 @@
+#ifndef CEPH_RGW_SERVICE_H
+#define CEPH_RGW_SERVICE_H
+
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "rgw/rgw_common.h"
+
+
+class CephContext;
+class JSONFormattable;
+class RGWServiceInstance;
+class RGWServiceRegistry;
+
+using RGWServiceInstanceRef = std::shared_ptr<RGWServiceInstance>;
+using RGWServiceRegistryRef = std::shared_ptr<RGWServiceRegistry>;
+
+class RGWService
+{
+  friend class RGWServiceRegistry;
+  friend class RGWServiceInstance;
+
+protected:
+  RGWServiceRegistryRef svc_registry;
+  CephContext *cct;
+  std::string svc_type;
+
+public:
+  RGWService(CephContext *_cct, const std::string& _svc_type) : cct(_cct),
+                                                           svc_type(_svc_type) {}
+  virtual ~RGWService() = default;
+
+  const std::string& type() {
+    return svc_type;
+  }
+  virtual std::vector<std::string> deps() = 0;
+  virtual int create_instance(JSONFormattable& conf, RGWServiceInstanceRef *instance) = 0;
+};
+
+
+using RGWServiceRef = std::shared_ptr<RGWService>;
+
+
+class RGWServiceInstance
+{
+  friend class RGWServiceRegistry;
+protected:
+  CephContext *cct;
+  std::shared_ptr<RGWService> svc;
+  string svc_instance;
+  uint64_t svc_id{0};
+
+public:
+  RGWServiceInstance(RGWService *svc, CephContext *_cct) : cct(_cct) {}
+
+  virtual ~RGWServiceInstance();
+  virtual int init(JSONFormattable& conf) = 0;
+
+  string get_title() {
+    return svc->type() + ":" + svc_instance;
+  }
+};
+
+class RGWServiceRegistry : std::enable_shared_from_this<RGWServiceRegistry> {
+  map<string, RGWServiceRef> services;
+
+  struct instance_info {
+    uint64_t id;
+    string title;
+    JSONFormattable conf;
+    RGWServiceInstanceRef ref;
+  };
+  map<uint64_t, instance_info> instances; /* registry_id -> instance */
+
+  std::atomic<uint64_t> max_registry_id;
+
+  void register_all(CephContext *cct);
+public:
+  RGWServiceRegistry(CephContext *cct) {
+    register_all(cct);
+  }
+  bool find(const string& name, RGWServiceRef *svc);
+
+  int instantiate(RGWServiceRegistryRef& registry, RGWServiceRef& svc, JSONFormattable& conf);
+  void remove_instance(RGWServiceInstance *instance);
+};
+
+#endif
diff --git a/src/rgw/services/svc_rados.cc b/src/rgw/services/svc_rados.cc
new file mode 100644 (file)
index 0000000..fed1e20
--- /dev/null
@@ -0,0 +1 @@
+#include "svc_rados.h"
diff --git a/src/rgw/services/svc_rados.h b/src/rgw/services/svc_rados.h
new file mode 100644 (file)
index 0000000..a53efdd
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef CEPH_RGW_SERVICES_ZONE_H
+#define CEPH_RGW_SERVICES_ZONE_H
+
+
+#include "rgw/rgw_service.h"
+
+
+class RGWS_RADOS : public RGWService
+{
+public:
+  RGWS_RADOS(CephContext *cct) : RGWService(cct, "rados") {}
+
+  std::vector<std::string> deps();
+  int create_instance(JSONFormattable& conf, RGWServiceInstanceRef *instance);
+};
+
+
+#endif