From: Abhishek Lekshmanan Date: Thu, 23 Feb 2017 16:50:19 +0000 (+0100) Subject: rgw_aws_sync: untested code for bucket create X-Git-Tag: v13.1.0~270^2~111 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=031aff0286752b56c5ce54748c82ca60e0429cf5;p=ceph.git rgw_aws_sync: untested code for bucket create Signed-off-by: Abhishek Lekshmanan --- diff --git a/src/rgw/rgw_sync_module_aws.cc b/src/rgw/rgw_sync_module_aws.cc index 3fb020004299..9a96ec75303c 100644 --- a/src/rgw/rgw_sync_module_aws.cc +++ b/src/rgw/rgw_sync_module_aws.cc @@ -9,15 +9,19 @@ #define dout_subsys ceph_subsys_rgw -static string aws_object_name(const RGWBucketInfo& bucket_info, const rgw_obj_key&key, bool user_buckets=false){ - string obj_name; - if(!user_buckets){ - obj_name = bucket_info.owner.tenant + bucket_info.owner.id + "/" + bucket_info.bucket.name + "/" + key.name; - } else { - // for future when every tenant gets their own bucket - obj_name = bucket_info.bucket.name + "/" + key.name; +// TODO: have various bucket naming schemes at a global/user and a bucket level + +static string aws_bucket_name(const RGWBucketInfo& bucket_info, bool user_buckets=false){ + string bucket_name="rgwx" + bucket_info.zonegroup; + if (user_buckets){ + bucket_name+=bucket_info.owner.tenant + bucket_info.owner.id; } - return obj_name; + return bucket_name; +} + +static string aws_object_name(const RGWBucketInfo& bucket_info, const rgw_obj_key&key, bool user_buckets=false){ + auto bucket = aws_bucket_name(bucket_info, user_buckets); + return bucket + key.name; } struct AWSConfig { @@ -29,6 +33,8 @@ struct AWSConfig { class RGWAWSHandleRemoteObjCBCR: public RGWStatRemoteObjCBCR { const AWSConfig& conf; bufferlist res; + unordered_map bucket_created; + string bucket_name; public: RGWAWSHandleRemoteObjCBCR(RGWDataSyncEnv *_sync_env, RGWBucketInfo& _bucket_info, @@ -58,9 +64,9 @@ public: // Don't try this at home, very hacky, probably need a proper aws client // written so RESTResourceCR expects a JSON as a result, we workaround - // by providing a list which is a native json type + // by providing a bufferlist, need to rewrite the class to support RAW requests - // And we should do a part by part get and initiate mp on the aws side + // TODO-future: And we should do a part by part get and initiate mp on the aws side call(new RGWReadRESTResourceCR(sync_env->cct, conn, sync_env->http_manager, @@ -74,10 +80,26 @@ public: if (retcode < 0) { return set_cr_error(retcode); } - ldout(sync_env->cct,0) << "abhi: download complete, printing object"<< dendl; + ldout(sync_env->cct,0) << "abhi: download complete, creating buckets"<< dendl; + + bucket_name=aws_bucket_name(bucket_info); + if (bucket_created.find(bucket_name) == bucket_created.end()){ + // // TODO: maybe do a head request for subsequent tries & make it configurable + yield { + //string bucket_name = aws_bucket_name(bucket_info); + bufferlist bl; + call(new RGWPutRawRESTResourceCR (sync_env->cct, conf.conn, + sync_env->http_manager, + bucket_name, nullptr, bl, nullptr)); + } + if (retcode < 0) { + return set_cr_error(retcode); + } + + bucket_created[bucket_name]=true; + } + yield { - // TODO: actually create buckets if they dont' exist, we currently just - // create object, assuming buckets are already there string path=aws_object_name(bucket_info, key); ldout(sync_env->cct,0) << "abhi sending request to " << conf.conn << " path" << path << dendl; call(new RGWPutRawRESTResourceCR (sync_env->cct, conf.conn, @@ -90,9 +112,6 @@ public: } - - // }; - return set_cr_done(); }