From 19cb24acdfd1ef9032b212e56f4fe400cc9ba389 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 9 Jul 2018 15:20:03 -0700 Subject: [PATCH] rgw-admin: pubsub: use effective conf the effective conf has the defaults set if needed Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 10 ++++++---- src/rgw/rgw_rados.cc | 26 +++++++++++++------------- src/rgw/rgw_sync_module_pubsub.cc | 10 ++++++++++ src/rgw/rgw_sync_module_pubsub.h | 4 ++++ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index fde88f0dd39..f4c7d3f041d 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -53,6 +53,7 @@ extern "C" { #include "rgw_http_client_curl.h" #include "rgw_zone.h" #include "rgw_pubsub.h" +#include "rgw_sync_module_pubsub.h" #include "services/svc_sync_modules.h" @@ -7990,18 +7991,19 @@ next: return EINVAL; } - auto& tier_config = get_tier_config(store); - rgw_pubsub_sub_dest dest_config; dest_config.bucket_name = sub_dest_bucket; dest_config.oid_prefix = sub_oid_prefix; dest_config.push_endpoint = sub_push_endpoint; + auto psmodule = static_cast(store->get_sync_module().get()); + auto conf = psmodule->get_effective_conf(); + if (dest_config.bucket_name.empty()) { - dest_config.bucket_name = string(tier_config["data_bucket_prefix"]) + user_info.user_id.to_str() + "-" + topic.topic.name; + dest_config.bucket_name = string(conf["data_bucket_prefix"]) + user_info.user_id.to_str() + "-" + topic.topic.name; } if (dest_config.oid_prefix.empty()) { - dest_config.oid_prefix = tier_config["data_oid_prefix"]; + dest_config.oid_prefix = conf["data_oid_prefix"]; } auto sub = ups.get_sub(sub_name); ret = sub->subscribe(topic_name, dest_config); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 2d17ec20876..d0c31ea28f5 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1417,7 +1417,6 @@ int RGWRados::init_rados() return ret; } - int RGWRados::register_to_service_map(const string& daemon_type, const map& meta) { map metadata = meta; @@ -1458,19 +1457,20 @@ int RGWRados::init_complete() { int ret; - if (run_sync_thread) { - auto& zone_public_config = svc.zone->get_zone(); - ret = svc.sync_modules->get_manager()->create_instance(cct, zone_public_config.tier_type, svc.zone->get_zone_params().tier_config, &sync_module); - if (ret < 0) { - lderr(cct) << "ERROR: failed to init sync module instance, ret=" << ret << dendl; - if (ret == -ENOENT) { - lderr(cct) << "ERROR: " << zone_public_config.tier_type - << " sync module does not exist. valid sync modules: " - << svc.sync_modules->get_manager()->get_registered_module_names() - << dendl; - } - return ret; + /* + * create sync module instance even if we don't run sync thread, might need it for radosgw-admin + */ + auto& zone_public_config = svc.zone->get_zone(); + ret = svc.sync_modules->get_manager()->create_instance(cct, zone_public_config.tier_type, svc.zone->get_zone_params().tier_config, &sync_module); + if (ret < 0) { + lderr(cct) << "ERROR: failed to init sync module instance, ret=" << ret << dendl; + if (ret == -ENOENT) { + lderr(cct) << "ERROR: " << zone_public_config.tier_type + << " sync module does not exist. valid sync modules: " + << svc.sync_modules->get_manager()->get_registered_module_names() + << dendl; } + return ret; } period_puller.reset(new RGWPeriodPuller(this)); diff --git a/src/rgw/rgw_sync_module_pubsub.cc b/src/rgw/rgw_sync_module_pubsub.cc index 24a72862714..61045a1d3af 100644 --- a/src/rgw/rgw_sync_module_pubsub.cc +++ b/src/rgw/rgw_sync_module_pubsub.cc @@ -1164,11 +1164,21 @@ public: << " versioned=" << versioned << " versioned_epoch=" << versioned_epoch << dendl; return new RGWPSGenericObjEventCBCR(sync_env, env, bucket_info, key, mtime, DELETE_MARKER_CREATE); } + + PSConfigRef& get_conf() { return conf; } }; RGWPSSyncModuleInstance::RGWPSSyncModuleInstance(CephContext *cct, const JSONFormattable& config) { data_handler = std::unique_ptr(new RGWPSDataSyncModule(cct, config)); + string jconf = json_str("conf", *data_handler->get_conf()); + JSONParser p; + if (!p.parse(jconf.c_str(), jconf.size())) { + ldout(cct, 0) << "ERROR: failed to parse sync module effective conf: " << jconf << dendl; + effective_conf = config; + } else { + effective_conf.decode_json(&p); + } } RGWDataSyncModule *RGWPSSyncModuleInstance::get_data_handler() diff --git a/src/rgw/rgw_sync_module_pubsub.h b/src/rgw/rgw_sync_module_pubsub.h index b12bf904583..72259ba69c7 100644 --- a/src/rgw/rgw_sync_module_pubsub.h +++ b/src/rgw/rgw_sync_module_pubsub.h @@ -17,6 +17,7 @@ class RGWRESTConn; class RGWPSSyncModuleInstance : public RGWSyncModuleInstance { std::unique_ptr data_handler; + JSONFormattable effective_conf; public: RGWPSSyncModuleInstance(CephContext *cct, const JSONFormattable& config); RGWDataSyncModule *get_data_handler() override; @@ -24,6 +25,9 @@ public: bool supports_user_writes() override { return true; } + const JSONFormattable& get_effective_conf() { + return effective_conf; + } }; #endif -- 2.39.5