1
0
mirror of https://github.com/ceph/ceph synced 2025-04-01 14:51:13 +00:00

rgw: basic rgw services registry

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
This commit is contained in:
Yehuda Sadeh 2018-08-09 17:04:48 -07:00
parent d9c9cf65f0
commit add60c82ea
5 changed files with 174 additions and 0 deletions

View 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"

61
src/rgw/rgw_service.cc Normal file
View File

@ -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);
}

90
src/rgw/rgw_service.h Normal file
View File

@ -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

View File

@ -0,0 +1 @@
#include "svc_rados.h"

View File

@ -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