]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: sync modules, use JSONFormattable
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 12 Dec 2017 13:03:54 +0000 (05:03 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 12 Apr 2018 22:38:36 +0000 (15:38 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
14 files changed:
src/cls/refcount/cls_refcount_ops.h
src/common/ceph_json.cc
src/common/ceph_json.h
src/rgw/rgw_admin.cc
src/rgw/rgw_data_sync.cc
src/rgw/rgw_data_sync.h
src/rgw/rgw_rados.h
src/rgw/rgw_sync_module.h
src/rgw/rgw_sync_module_aws.cc
src/rgw/rgw_sync_module_aws.h
src/rgw/rgw_sync_module_es.cc
src/rgw/rgw_sync_module_es.h
src/rgw/rgw_sync_module_log.cc
src/rgw/rgw_sync_module_log.h

index 24aa28482cae305cd63f6b8ebf79078abe08c1f7..ee560c52f2309aacf1a31e2f692591a2d667f9dd 100644 (file)
@@ -6,8 +6,6 @@
 
 #include "include/types.h"
 
-class Formatter;
-
 struct cls_refcount_get_op {
   string tag;
   bool implicit_ref;
index 29b551e8fb06877c45dd4a535840b7ffb3509197..102de1768758f3b6c21c9ddf8a61c5da9c7525ac 100644 (file)
@@ -5,10 +5,16 @@
 #include <fstream>
 #include <include/types.h>
 
+#include <boost/algorithm/string.hpp>
+
 using namespace json_spirit;
 
 #define dout_subsys ceph_subsys_rgw
 
+
+static JSONFormattable default_formattable;
+
+
 JSONObjIter::JSONObjIter()
 {
 }
@@ -515,3 +521,80 @@ void encode_json(const char *name, const bufferlist& bl, Formatter *f)
   encode_json(name, s, f);
 }
 
+
+
+/* JSONFormattable */
+
+const JSONFormattable& JSONFormattable::operator[](const string& name) const
+{
+  auto i = obj.find(name);
+  if (i == obj.end()) {
+    return default_formattable;
+  }
+  return i->second;
+}
+
+bool JSONFormattable::find(const string& name, string *val) const
+{
+  auto i = obj.find(name);
+  if (i == obj.end()) {
+    return false;
+  }
+  *val = i->second;
+  return true;
+}
+
+string JSONFormattable::get(const string& name, const string& def_val) const
+{
+  string s;
+  if (find(name, &s)) {
+    return s;
+  }
+
+  return def_val;
+}
+
+int JSONFormattable::get_int(const string& name, int def_val) const
+{
+  string s;
+  if (find(name, &s)) {
+    return atoi(s.c_str());
+  }
+
+  return def_val;
+}
+
+bool JSONFormattable::get_bool(const string& name, bool def_val) const
+{
+  string s;
+  if (find(name, &s)) {
+    return (boost::iequals(s, "true") ||
+            boost::iequals(s, "on") ||
+            boost::iequals(s, "yes") ||
+            boost::iequals(s, "1"));
+  }
+
+  return def_val;
+}
+
+void encode_json(const char *name, const JSONFormattable& v, Formatter *f)
+{
+  switch (v.type) {
+    case JSONFormattable::FMT_STRING:
+      encode_json(name, v.str, f);
+      break;
+    case JSONFormattable::FMT_ARRAY:
+      encode_json(name, v.arr, f);
+      break;
+    case JSONFormattable::FMT_OBJ:
+      f->open_object_section(name);
+      for (auto iter : v.obj) {
+        encode_json(iter.first.c_str(), iter.second, f);
+      }
+      f->close_section();
+      break;
+    case JSONFormattable::FMT_NONE:
+      break;
+  }
+}
+
index 08ec5e59a2882796110767e5ea37910ad785ab05..3299d4792ce9145abeeabda5829b9577154b1aaf 100644 (file)
@@ -467,4 +467,75 @@ void encode_json_map(const char *name, const char *index_name, const char *value
   encode_json_map<K, V>(name, index_name, NULL, value_name, NULL, NULL, m, f);
 }
 
+struct JSONFormattable {
+  enum Type {
+    FMT_NONE,
+    FMT_STRING,
+    FMT_ARRAY,
+    FMT_OBJ,
+  } type{FMT_NONE};
+  string str;
+  vector<JSONFormattable> arr;
+  map<string, JSONFormattable> obj;
+
+  void decode_json(JSONObj *jo) {
+    if (jo->is_array()) {
+      type = JSONFormattable::FMT_ARRAY;
+      decode_json_obj(arr, jo);
+    } else if (jo->is_object()) {
+      type = JSONFormattable::FMT_OBJ;
+      auto iter = jo->find_first();
+      while (!iter.end()) {
+        JSONObj *field = *iter;
+        decode_json_obj(obj[field->get_name()], field);
+      }
+    } else {
+      type = JSONFormattable::FMT_STRING;
+      decode_json_obj(str, jo);
+    }
+  }
+
+  void encode(bufferlist& bl) const {
+    ENCODE_START(1, 1, bl);
+    encode((uint8_t)type, bl);
+    encode(str, bl);
+    encode(arr, bl);
+    encode(obj, bl);
+    ENCODE_FINISH(bl);
+  }
+
+  void decode(bufferlist::iterator& bl) {
+    DECODE_START(1, bl);
+    uint8_t t;
+    decode(t, bl);
+    type = (Type)t;
+    decode(str, bl);
+    decode(arr, bl);
+    decode(obj, bl);
+    DECODE_FINISH(bl);
+  }
+  const string& val() const {
+    return str;
+  }
+
+  const vector<JSONFormattable>& array() const {
+    return arr;
+  }
+
+  const JSONFormattable& operator[](const string& name) const;
+
+  operator string() const {
+    return val();
+  }
+
+  bool find(const string& name, string *val) const;
+
+  string get(const string& name, const string& def_val) const;
+  int get_int(const string& name, int def_val) const;
+  bool get_bool(const string& name, bool def_val) const;
+};
+WRITE_CLASS_ENCODER(JSONFormattable)
+
+void encode_json(const char *name, const JSONFormattable& v, Formatter *f);
+
 #endif
index 37546ddfef7190b677c73da9cddea2bd0cf5d662..7b97e77a18a017ff73a13672bfd1f35db8766aab 100644 (file)
@@ -2448,77 +2448,6 @@ static int scan_totp(CephContext *cct, ceph::real_time& now, rados::cls::otp::ot
   return -ENOENT;
 }
 
-struct Formattable {
-  enum Type {
-    FMT_NONE,
-    FMT_STRING,
-    FMT_ARRAY,
-    FMT_OBJ,
-  } type{FMT_NONE};
-  string str;
-  vector<Formattable> arr;
-  map<string, Formattable> obj;
-
-  void decode_json(JSONObj *jo) {
-    if (jo->is_array()) {
-      type = Formattable::FMT_ARRAY;
-      decode_json_obj(arr, jo);
-    } else if (jo->is_object()) {
-      type = Formattable::FMT_OBJ;
-      auto iter = jo->find_first();
-      while (!iter.end()) {
-        JSONObj *field;
-        decode_json_obj(obj[field->get_name()], field);
-      }
-    } else {
-      type = Formattable::FMT_STRING;
-      decode_json_obj(str, jo);
-    }
-  }
-
-  const string& val() const {
-    return str;
-  }
-
-  const vector<Formattable>& array() const {
-    return arr;
-  }
-
-  const Formattable& operator[](const string& name) const;
-};
-
-static Formattable default_formattable;
-
-const Formattable& Formattable::operator[](const string& name) const {
-  auto i = obj.find(name);
-  if (i == obj.end()) {
-    return default_formattable;
-  }
-  return i->second;
-}
-
-void encode_json(const char *name, const Formattable& v, Formatter *f)
-{
-  switch (v.type) {
-    case Formattable::FMT_STRING:
-      encode_json(name, v.str, f);
-      break;
-    case Formattable::FMT_ARRAY:
-      encode_json(name, v.arr, f);
-      break;
-    case Formattable::FMT_OBJ:
-      f->open_object_section(name);
-      for (auto iter : v.obj) {
-        encode_json(iter.first.c_str(), iter.second, f);
-      }
-      f->close_section();
-      break;
-    case Formattable::FMT_NONE:
-      break;
-  }
-}
-
-
 #ifdef BUILDING_FOR_EMBEDDED
 extern "C" int cephd_rgw_admin(int argc, const char **argv)
 #else
index 807f1d81a0040cb497241ef1b71a0cea341fc3f7..a2312e8d6b650a25e430086566d8c3ab2f0d601c 100644 (file)
@@ -1721,7 +1721,7 @@ public:
   }
 };
 
-int RGWDefaultSyncModule::create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance)
+int RGWDefaultSyncModule::create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance)
 {
   instance->reset(new RGWDefaultSyncModuleInstance());
   return 0;
index 088486e13c4fbeedc65d6d1c135f6067f3071a98..a1442d35b059ab10673e75d284877b241a9b1469 100644 (file)
@@ -546,7 +546,7 @@ class RGWDefaultSyncModule : public RGWSyncModule {
 public:
   RGWDefaultSyncModule() {}
   bool supports_data_export() override { return true; }
-  int create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) override;
+  int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) override;
 };
 
 // DataLogTrimCR factory function
index 003c09e6ab1d1f936e010d659f6f1faf605e6c78..c82b77883e207ee69cc7080a69e25d04c1c432c9 100644 (file)
@@ -13,6 +13,7 @@
 #include "common/RWLock.h"
 #include "common/ceph_time.h"
 #include "common/lru_map.h"
+#include "common/ceph_json.h"
 #include "rgw_common.h"
 #include "cls/rgw/cls_rgw_types.h"
 #include "cls/version/cls_version_types.h"
@@ -1179,7 +1180,7 @@ struct RGWZoneParams : RGWSystemMetaObj {
 
   string realm_id;
 
-  map<string, string, ltstr_nocase> tier_config;
+  JSONFormattable tier_config;
 
   RGWZoneParams() : RGWSystemMetaObj() {}
   RGWZoneParams(const string& name) : RGWSystemMetaObj(name){}
index 9925d677eafd2cd7546c645d24322effd35b51bb..8b06767c0512cfc016429a937995d4d75dce0ff9 100644 (file)
@@ -43,6 +43,8 @@ public:
 
 typedef std::shared_ptr<RGWSyncModuleInstance> RGWSyncModuleInstanceRef;
 
+class JSONFormattable;
+
 class RGWSyncModule {
 
 public:
@@ -50,7 +52,7 @@ public:
   virtual ~RGWSyncModule() {}
 
   virtual bool supports_data_export() = 0;
-  virtual int create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) = 0;
+  virtual int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) = 0;
 };
 
 typedef std::shared_ptr<RGWSyncModule> RGWSyncModuleRef;
@@ -93,7 +95,7 @@ public:
     return module.get()->supports_data_export();
   }
 
-  int create_instance(CephContext *cct, const string& name, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) {
+  int create_instance(CephContext *cct, const string& name, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
     RGWSyncModuleRef module;
     if (!get_module(name, &module)) {
       return -ENOENT;
index 162b12d7e2d7d22bc438b8eda9bfc02ef23c88b7..30d3aa74d9526c98c089af95b7313025b8434d85 100644 (file)
@@ -951,14 +951,14 @@ public:
   }
 };
 
-static int conf_to_uint64(CephContext *cct, const map<string, string, ltstr_nocase>& config, const string& key, uint64_t *pval)
+static int conf_to_uint64(CephContext *cct, const JSONFormattable& config, const string& key, uint64_t *pval)
 {
-  auto i = config.find(key);
-  if (i != config.end()) {
+  string sval;
+  if (config.find(key, &sval)) {
     string err;
-    uint64_t val = strict_strtoll(i->second.c_str(), 10, &err);
+    uint64_t val = strict_strtoll(sval.c_str(), 10, &err);
     if (!err.empty()) {
-      ldout(cct, 0) << "ERROR: could not parse configurable value for cloud sync module: " << i->first << ": " << i->second << dendl;
+      ldout(cct, 0) << "ERROR: could not parse configurable value for cloud sync module: " << key << ": " << sval << dendl;
       return -EINVAL;
     }
     *pval = val;
@@ -966,22 +966,13 @@ static int conf_to_uint64(CephContext *cct, const map<string, string, ltstr_noca
   return 0;
 }
 
-int RGWAWSSyncModule::create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config,  RGWSyncModuleInstanceRef *instance){
+int RGWAWSSyncModule::create_instance(CephContext *cct, const JSONFormattable& config,  RGWSyncModuleInstanceRef *instance){
   AWSSyncConfig conf;
-  auto i = config.find("s3_endpoint");
-  if (i != config.end())
-    conf.s3_endpoint = i->second;
 
-  string access_key;
-  string secret;
+  conf.s3_endpoint = config["s3_endpoint"];
 
-  i = config.find("access_key");
-  if (i != config.end())
-    access_key = i->second;
-
-  i = config.find("secret");
-  if (i != config.end())
-    secret = i->second;
+  string access_key = config["access_key"];
+  string secret = config["secret"];
 
   conf.key = RGWAccessKey(access_key, secret);
 
index 14749d514b1e05b6d91c829efb2ad2a6dd53debe..350c14e32b104c6c5e9e08c97742bb89f724e66e 100644 (file)
@@ -99,7 +99,7 @@ class RGWAWSSyncModule : public RGWSyncModule {
  public:
   RGWAWSSyncModule() {}
   bool supports_data_export() override { return false;}
-  int create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) override;
+  int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) override;
 };
 
 #endif /* RGW_SYNC_MODULE_AWS_H */
index ab6e9fea1818990fd8d89f685776bffe1a30ea5c..cd219fffc2c5a79514903cd6616d4e6b0997ae0b 100644 (file)
@@ -103,6 +103,7 @@ public:
 #define ES_NUM_SHARDS_DEFAULT 16
 #define ES_NUM_REPLICAS_DEFAULT 1
 
+
 struct ElasticConfig {
   uint64_t sync_instance{0};
   string id;
@@ -115,19 +116,19 @@ struct ElasticConfig {
   uint32_t num_shards{0};
   uint32_t num_replicas{0};
 
-  void init(CephContext *cct, const map<string, string, ltstr_nocase>& config) {
-    string elastic_endpoint = rgw_conf_get(config, "endpoint", "");
+  void init(CephContext *cct, const JSONFormattable& config) {
+    string elastic_endpoint = config.get("endpoint", "");
     id = string("elastic:") + elastic_endpoint;
     conn.reset(new RGWRESTConn(cct, nullptr, id, { elastic_endpoint }));
-    explicit_custom_meta = rgw_conf_get_bool(config, "explicit_custom_meta", true);
-    index_buckets.init(rgw_conf_get(config, "index_buckets_list", ""), true); /* approve all buckets by default */
-    allow_owners.init(rgw_conf_get(config, "approved_owners_list", ""), true); /* approve all bucket owners by default */
-    override_index_path = rgw_conf_get(config, "override_index_path", "");
-    num_shards = rgw_conf_get_int(config, "num_shards", ES_NUM_SHARDS_DEFAULT);
+    explicit_custom_meta = config.get_bool("explicit_custom_meta", true);
+    index_buckets.init(config.get("index_buckets_list", ""), true); /* approve all buckets by default */
+    allow_owners.init(config.get("approved_owners_list", ""), true); /* approve all bucket owners by default */
+    override_index_path = config.get("override_index_path", "");
+    num_shards = config.get_int("num_shards", ES_NUM_SHARDS_DEFAULT);
     if (num_shards < ES_NUM_SHARDS_MIN) {
       num_shards = ES_NUM_SHARDS_MIN;
     }
-    num_replicas = rgw_conf_get_int(config, "num_replicas", ES_NUM_REPLICAS_DEFAULT);
+    num_replicas = config.get_int("num_replicas", ES_NUM_REPLICAS_DEFAULT);
   }
 
   void init_instance(RGWRealm& realm, uint64_t instance_id) {
@@ -534,7 +535,7 @@ public:
 class RGWElasticDataSyncModule : public RGWDataSyncModule {
   ElasticConfigRef conf;
 public:
-  RGWElasticDataSyncModule(CephContext *cct, const map<string, string, ltstr_nocase>& config) : conf(std::make_shared<ElasticConfig>()) {
+  RGWElasticDataSyncModule(CephContext *cct, const JSONFormattable& config) : conf(std::make_shared<ElasticConfig>()) {
     conf->init(cct, config);
   }
   ~RGWElasticDataSyncModule() override {}
@@ -580,7 +581,7 @@ public:
   }
 };
 
-RGWElasticSyncModuleInstance::RGWElasticSyncModuleInstance(CephContext *cct, const map<string, string, ltstr_nocase>& config)
+RGWElasticSyncModuleInstance::RGWElasticSyncModuleInstance(CephContext *cct, const JSONFormattable& config)
 {
   data_handler = std::unique_ptr<RGWElasticDataSyncModule>(new RGWElasticDataSyncModule(cct, config));
 }
@@ -607,12 +608,8 @@ RGWRESTMgr *RGWElasticSyncModuleInstance::get_rest_filter(int dialect, RGWRESTMg
   return new RGWRESTMgr_MDSearch_S3();
 }
 
-int RGWElasticSyncModule::create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) {
-  string endpoint;
-  auto i = config.find("endpoint");
-  if (i != config.end()) {
-    endpoint = i->second;
-  }
+int RGWElasticSyncModule::create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
+  string endpoint = config["endpoint"];
   instance->reset(new RGWElasticSyncModuleInstance(cct, config));
   return 0;
 }
index 43e591e42fc361b32fd1a9a09223caf0a3ce39f2..7dcda39cbf72b3bbc12b9fcaa66988e1c7620604 100644 (file)
@@ -9,7 +9,7 @@ public:
   bool supports_data_export() override {
     return false;
   }
-  int create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) override;
+  int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) override;
 };
 
 class RGWElasticDataSyncModule;
@@ -18,7 +18,7 @@ class RGWRESTConn;
 class RGWElasticSyncModuleInstance : public RGWSyncModuleInstance {
   std::unique_ptr<RGWElasticDataSyncModule> data_handler;
 public:
-  RGWElasticSyncModuleInstance(CephContext *cct, const std::map<std::string, std::string, ltstr_nocase>& config);
+  RGWElasticSyncModuleInstance(CephContext *cct, const JSONFormattable& config);
   RGWDataSyncModule *get_data_handler() override;
   RGWRESTMgr *get_rest_filter(int dialect, RGWRESTMgr *orig) override;
   RGWRESTConn *get_rest_conn();
index 93a853f56000c3f21c28def7454b791bd9000ba7..0378c040b6affea5b8ebff6e75c44e83d015c7a7 100644 (file)
@@ -63,12 +63,8 @@ public:
   }
 };
 
-int RGWLogSyncModule::create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) {
-  string prefix;
-  auto i = config.find("prefix");
-  if (i != config.end()) {
-    prefix = i->second;
-  }
+int RGWLogSyncModule::create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
+  string prefix = config["prefix"];
   instance->reset(new RGWLogSyncModuleInstance(prefix));
   return 0;
 }
index 9afc9108e6789955e94925e64b74b414d4646cc0..d64fb9d826de98253543eb10e7c587e5040eeed2 100644 (file)
@@ -9,7 +9,7 @@ public:
   bool supports_data_export() override {
     return false;
   }
-  int create_instance(CephContext *cct, map<string, string, ltstr_nocase>& config, RGWSyncModuleInstanceRef *instance) override;
+  int create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) override;
 };
 
 #endif