]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Add op to get Lifecycle configuration 9737/head
authorDaniel Gryniewicz <dang@redhat.com>
Thu, 14 Jul 2016 16:39:53 +0000 (12:39 -0400)
committerJi Chen <insomnia@139.com>
Fri, 22 Jul 2016 04:22:23 +0000 (12:22 +0800)
Signed-off-by: Daniel Gryniewicz <dang@redhat.com>
src/rgw/rgw_lc.cc
src/rgw/rgw_lc.h
src/rgw/rgw_lc_s3.cc
src/rgw/rgw_lc_s3.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest.h
src/rgw/rgw_rest_s3.cc
src/rgw/rgw_rest_s3.h

index 3d110e829febbfb55011f47739ef41ce1b225a58..0e8df5ed333dd9a6e749f1b186945fd9323f515b 100644 (file)
@@ -40,19 +40,7 @@ void RGWLifecycleConfiguration::add_rule(LCRule *rule)
 
 void RGWLifecycleConfiguration::_add_rule(LCRule *rule)
 {
-  string prefix;
-  LCExpiration expiration;
-  int days;
-  if (!rule->get_prefix(prefix)) {
-    ldout(cct, 5) << "ERROR: rule->get_prefix() failed" << dendl;
-  }
-  if (!rule->get_expiration(expiration)) {
-    ldout(cct, 5) << "ERROR: rule->get_expiration() failed" << dendl;
-  }
-  if (!expiration.get_days(&days)) {
-    ldout(cct, 5) << "ERROR: expiration->get_days() failed" << dendl;
-  }
-  prefix_map[prefix] = days;
+  prefix_map[rule->get_prefix()] = rule->get_expiration().get_days();
 }
 
 void *RGWLC::LCWorker::entry() {
@@ -481,7 +469,7 @@ exit:
 void RGWLC::start_processor()
 {
   worker = new LCWorker(cct, this);
-  worker->create("lifecycle_thread");
+  worker->create("lifecycle_thr");
 }
 
 void RGWLC::stop_processor()
index cdc5ff2f6badfd7cca51090fc66af568a4faefc7..0c4126c1ece8bee47696039dfd1a7e1accc62182 100644 (file)
@@ -53,7 +53,7 @@ public:
   void dump(Formatter *f) const;
 //  static void generate_test_instances(list<ACLOwner*>& o);
   void set_days(const string& _days) { days = _days; }
-  bool get_days(int* _days) {*_days = atoi(days.c_str()); return true; }
+  int get_days() {return atoi(days.c_str()); }
 };
 WRITE_CLASS_ENCODER(LCExpiration)
 
@@ -75,19 +75,16 @@ public:
       return true;
   }
 
-  bool get_status(string& _status) {
-      _status = status;
-      return true;
+  string& get_status() {
+      return status;
   }
   
-  bool get_prefix(string& _prefix) {
-      _prefix = prefix;
-      return true;
+  string& get_prefix() {
+      return prefix;
   }
 
-  bool get_expiration(LCExpiration& _expriation) {
-    _expriation = expiration;
-    return true;
+  LCExpiration& get_expiration() {
+    return expiration;
   }
 
   void set_id(string*_id) {
index cee710bb9a746c547ec62355c1d5bca5a8f0e2cb..cc05a2a35906f47e6c06cea1eb4e00be34bc48f6 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "include/types.h"
 
+#include "rgw_user.h"
 #include "rgw_lc_s3.h"
 
 
@@ -41,7 +42,7 @@ bool LCRule_S3::xml_end(const char *el) {
   id.clear();
   prefix.clear();
   status.clear();
-  
+
   lc_id = static_cast<LCID_S3 *>(find_first("ID"));
   if (!lc_id)
     return false;
@@ -56,7 +57,7 @@ bool LCRule_S3::xml_end(const char *el) {
   if (!lc_status)
     return false;
   status = lc_status->get_data();
-  
+
   lc_expiration = static_cast<LCExpiration_S3 *>(find_first("Expiration"));
   if (!lc_expiration)
     return false;
@@ -87,7 +88,19 @@ int RGWLifecycleConfiguration_S3::rebuild(RGWRados *store, RGWLifecycleConfigura
     }
   }
 
-  return 0; 
+  return 0;
+}
+
+void RGWLifecycleConfiguration_S3::dump_xml(Formatter *f) const
+{
+       f->open_object_section_in_ns("LifecycleConfiguration", XMLNS_AWS_S3);
+
+    for (auto iter = rule_map.begin(); iter != rule_map.end(); ++iter) {
+               const LCRule_S3& rule = static_cast<const LCRule_S3&>(iter->second);
+               rule.dump_xml(f);
+       }
+
+       f->close_section(); // Lifecycle
 }
 
 XMLObj *RGWLCXMLParser_S3::alloc_obj(const char *el)
index 1de47d5fb60fb941963285e8f4a16c3db9f8eefb..01f3b324f9d7a935652f671834df7d2be6a456bd 100644 (file)
 
 using namespace std;
 
-class LCRule_S3 : public LCRule, public XMLObj
-{
-public:
-  LCRule_S3() {}
-  ~LCRule_S3() {}
-
-  void to_xml(CephContext *cct, ostream& out);
-  bool xml_end(const char *el);
-  bool xml_start(const char *el, const char **attr);
-};
-
 class LCID_S3 : public XMLObj
 {
 public:
@@ -69,6 +58,32 @@ public:
   void to_xml(ostream& out) {
     out << "<Expiration>" << "<Days>" << days << "</Days>"<< "</Expiration>";
   }
+  void dump_xml(Formatter *f) const {
+         f->open_object_section("Expiration");
+         encode_xml("Days", days, f);
+         f->close_section(); // Expiration
+  }
+};
+
+class LCRule_S3 : public LCRule, public XMLObj
+{
+public:
+  LCRule_S3() {}
+  ~LCRule_S3() {}
+
+  void to_xml(CephContext *cct, ostream& out);
+  bool xml_end(const char *el);
+  bool xml_start(const char *el, const char **attr);
+  void dump_xml(Formatter *f) const {
+         const LCExpiration_S3& expir = static_cast<const LCExpiration_S3&>(expiration);
+
+         f->open_object_section("Rule");
+         encode_xml("ID", id, f);
+         encode_xml("Prefix", prefix, f);
+         encode_xml("Status", status, f);
+         expir.dump_xml(f);
+         f->close_section(); // Rule
+  }
 };
 
 class RGWLCXMLParser_S3 : public RGWXMLParser
@@ -84,6 +99,7 @@ class RGWLifecycleConfiguration_S3 : public RGWLifecycleConfiguration, public XM
 {
 public:
   RGWLifecycleConfiguration_S3(CephContext *_cct) : RGWLifecycleConfiguration(_cct) {}
+  RGWLifecycleConfiguration_S3() : RGWLifecycleConfiguration(NULL) {}
   ~RGWLifecycleConfiguration_S3() {}
 
   bool xml_end(const char *el);
@@ -98,6 +114,7 @@ public:
     out << "</LifecycleConfiguration>";
   }
   int rebuild(RGWRados *store, RGWLifecycleConfiguration& dest);
+  void dump_xml(Formatter *f) const;
 };
 
 
index 6bd66a03e8650d7896ebd6dfddbb04ec6d68ecbf..48813d6522c6c5d90242e3d6cc7a3be9155161d4 100644 (file)
@@ -3669,6 +3669,16 @@ int RGWPutACLs::verify_permission()
   return 0;
 }
 
+int RGWGetLC::verify_permission()
+{
+  bool perm;
+  perm = verify_bucket_permission(s, RGW_PERM_WRITE_ACP);
+  if (!perm)
+    return -EACCES;
+
+  return 0;
+}
+
 int RGWPutLC::verify_permission()
 {
   bool perm;
@@ -3694,6 +3704,11 @@ void RGWPutACLs::pre_exec()
   rgw_bucket_object_pre_exec(s);
 }
 
+void RGWGetLC::pre_exec()
+{
+  rgw_bucket_object_pre_exec(s);
+}
+
 void RGWPutLC::pre_exec()
 {
   rgw_bucket_object_pre_exec(s);
@@ -3806,6 +3821,7 @@ static void get_lc_oid(struct req_state *s, string& oid)
   oid.append(buf);
   return;
 }
+
 void RGWPutLC::execute()
 {
   bufferlist bl;
index 1fbb34832431ea4c87f2c6413d4fd1adb99c6996..578b13773115aac7b483310e997fe0120832a67c 100644 (file)
@@ -34,6 +34,7 @@
 #include "rgw_acl.h"
 #include "rgw_cors.h"
 #include "rgw_quota.h"
+#include "rgw_lc.h"
 
 #include "include/assert.h"
 
@@ -1005,6 +1006,23 @@ public:
   virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; }
 };
 
+class RGWGetLC : public RGWOp {
+protected:
+  int ret;
+
+public:
+  RGWGetLC() : ret(0) { }
+  virtual ~RGWGetLC() { }
+
+  int verify_permission();
+  void pre_exec();
+  virtual void execute() = 0;
+
+  virtual void send_response() = 0;
+  virtual const string name() { return "get_lifecycle"; }
+  virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; }
+};
+
 class RGWPutLC : public RGWOp {
 protected:
   int ret;
index 831b214df754c54c2a4a401ec9354b340ed9c044..928a7a10aaad20c862a6dd7f3f75cd8105f22f28 100644 (file)
@@ -278,6 +278,12 @@ public:
   virtual int get_params();
 };
 
+class RGWGetLC_ObjStore : public RGWGetLC {
+public:
+  RGWGetLC_ObjStore() {}
+  ~RGWGetLC_ObjStore() {}
+};
+
 class RGWPutLC_ObjStore : public RGWPutLC {
 public:
   RGWPutLC_ObjStore() {}
index 679d423568dfcbbb9ae8a73c2ad33fecc5dab354..b3ed5c2578404c3f6e511a33cda4f277fc83e51b 100644 (file)
@@ -2260,6 +2260,44 @@ void RGWPutACLs_ObjStore_S3::send_response()
   dump_start(s);
 }
 
+void RGWGetLC_ObjStore_S3::execute()
+{
+  map<string, bufferlist> bucket_attrs;
+
+  config.set_ctx(s->cct);
+
+  RGWObjectCtx& obj_ctx = *static_cast<RGWObjectCtx *>(s->obj_ctx);
+  int ret = store->get_bucket_info(obj_ctx, s->bucket_tenant, s->bucket_name, s->bucket_info, NULL, &bucket_attrs);
+  if (ret < 0) {
+    ldout(s->cct, 0) << "LC:get_bucket_info failed" << s->bucket_name << dendl;
+    return;
+  }
+
+  map<string, bufferlist>::iterator aiter = bucket_attrs.find(RGW_ATTR_LC);
+  if (aiter == bucket_attrs.end())
+    return;
+
+  bufferlist::iterator iter(&aiter->second);
+  try {
+      config.decode(iter);
+    } catch (const buffer::error& e) {
+      ldout(s->cct, 0) << __func__ <<  "decode life cycle config failed" << dendl;
+      return;
+    }
+}
+
+void RGWGetLC_ObjStore_S3::send_response()
+{
+  if (ret)
+    set_req_state_err(s, ret);
+  dump_errno(s);
+  end_header(s, this, "application/xml");
+  dump_start(s);
+
+  config.dump_xml(s->formatter);
+  rgw_flush_formatter_and_reset(s, s->formatter);
+}
+
 void RGWPutLC_ObjStore_S3::send_response()
 {
   if (ret)
@@ -2833,6 +2871,8 @@ RGWOp *RGWHandler_REST_Bucket_S3::op_get()
     return new RGWGetRequestPayment_ObjStore_S3;
   } else if (s->info.args.exists("uploads")) {
     return new RGWListBucketMultiparts_ObjStore_S3;
+  } else if(is_lc_op()) {
+    return new RGWGetLC_ObjStore_S3;
   }
   return get_obj_op(true);
 }
index 43c254e3825c65bc91aee6b4635f9db4002f7dd1..c48b2eb1f6987fd06a768a5421a4564376870a38 100644 (file)
@@ -12,6 +12,7 @@
 #include "rgw_http_errors.h"
 #include "rgw_acl_s3.h"
 #include "rgw_policy_s3.h"
+#include "rgw_lc_s3.h"
 #include "rgw_keystone.h"
 #include "rgw_rest_conn.h"
 #include "rgw_ldap.h"
@@ -257,6 +258,17 @@ public:
   int get_params();
 };
 
+class RGWGetLC_ObjStore_S3 : public RGWGetLC_ObjStore {
+protected:
+  RGWLifecycleConfiguration_S3  config;
+public:
+  RGWGetLC_ObjStore_S3() {}
+  ~RGWGetLC_ObjStore_S3() {}
+  virtual void execute();
+
+ void send_response();
+};
+
 class RGWPutLC_ObjStore_S3 : public RGWPutLC_ObjStore {
 public:
   RGWPutLC_ObjStore_S3() {}