Add op to get Lifecycle configuration

Signed-off-by: Daniel Gryniewicz <dang@redhat.com>
This commit is contained in:
Daniel Gryniewicz 2016-07-14 12:39:53 -04:00 committed by Ji Chen
parent abe4b1378c
commit 1756b74935
9 changed files with 145 additions and 38 deletions

View 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()

View 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) {

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

View File

@ -16,17 +16,6 @@
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;
};

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

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

View 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() {}

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

View 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() {}