twonote / radosgw-admin4j

A Ceph Object Storage Admin SDK / Client Library for Java ✨🍰✨
https://twonote.github.io/radosgw-admin4j
Apache License 2.0
61 stars 33 forks source link

individual bucket #22

Closed LoinApex closed 3 years ago

LoinApex commented 5 years ago

http://docs.ceph.com/docs/mimic/radosgw/adminops/#set-quota-for-an-individual-bucket

I need this, set quota for an individual (or one by one) bucket, Can you give me some advise? Thanks you very much.

@Override
public void setIndividualBucketQuota(String userId, String bucket, long maxObjects, long maxSizeKB) {
    setIndividualQuota(userId, bucket, "bucket", maxObjects, maxSizeKB);
}

//SET QUOTA FOR AN INDIVIDUAL BUCKET
public void setIndividualQuota(String userId, String bucket, String quotaType, long maxObjects, long maxSizeKB) {
    HttpUrl.Builder urlBuilder =
            HttpUrl.parse(endpoint).newBuilder()
                    .addPathSegment("user")
                    .query("quota")
                    .addQueryParameter("uid", userId)
                    .addQueryParameter("bucket", bucket)
                    .addQueryParameter("quota-type", quotaType);

    String body = gson.toJson(ImmutableMap.of(
            "max_objects", String.valueOf(maxObjects),
            "max_size_kb", String.valueOf(maxSizeKB),
            "enabled", "true"));

    Request request = new Request.Builder().put(RequestBody.create(null, body)).url(urlBuilder.build()).build();
    safeCall(request);
}
hrchu commented 5 years ago

@libingyu try

            HttpUrl.parse(endpoint).newBuilder()
                    .addPathSegment("bucket")
                    .query("quota")
                    .addQueryParameter("uid", userId)
                    .addQueryParameter("bucket", bucket)

BTW would you like to send an PR for this? Thanks!

hrchu commented 5 years ago

ref http://tracker.ceph.com/issues/21811 @Jeegn-Chen

LoinApex commented 5 years ago

It is work, Thanks you vury much. You cou update radosgw-admin4j project in the future, Thank you for your contribution , wish you a happy day.

hrchu commented 5 years ago

Addressed in af2bf1e

hrchu commented 5 years ago

@tianyale added in v1.3.0. Check it out : )

hrchu commented 5 years ago

It's buggy currently. https://github.com/twonote/radosgw-admin4j/commit/af2bf1e8e31db5a7dcee7a39b98c44a941ac79d4

hrchu commented 5 years ago

@tianyale it's fixed, and use the method name you suggested. Thanks for your comment.

Feel free to provide more comment and PRs, thanks!