项目作者: twonote

项目描述 :
A Ceph Object Storage Admin SDK / Client Library for Java ✨🍰✨
高级语言: Java
项目地址: git://github.com/twonote/radosgw-admin4j.git
创建时间: 2017-03-12T06:21:00Z
项目社区:https://github.com/twonote/radosgw-admin4j

开源协议:Apache License 2.0

下载


Build Status
License
Javadocs
Maven Central

About

radosgw-admin4j is a powerful Ceph object storage admin client designed for provisioning and managing Ceph object storage deployments. It offers a wide range of features, including user and subuser management, quota control, usage reporting, and bucket/object management, among others.

Highlights

  • Full Support for All Operations: We fully support all operations, including subuser and quota management, for the latest Ceph versions.
  • Simplified Radosgw Management: Manage your radosgw instance with ease, avoiding the complexities often associated with radosgw admin APIs.
  • Quality and Compatibility: Our codebase undergoes continuous integration and testing against active Ceph releases, including Octopus, Pacific, Quincy, and Reef.
  • Contributor-Friendly: We welcome contributions with a straightforward contribution process and no unusual policies.

Getting Started

Add Dependency

You can include radosgw-admin4j in your project by adding the following Maven Central dependency:

  1. <dependency>
  2. <groupId>io.github.twonote</groupId>
  3. <artifactId>radosgw-admin4j</artifactId>
  4. <version>2.0.9</version> <!-- Replace with the latest version -->
  5. </dependency>

Configuration

  1. RgwAdmin rgwAdmin = new RgwAdminBuilder()
  2. .accessKey("administrator access key")
  3. .secretKey("administrator secret key")
  4. .endpoint("radosgw admin endpoint, e.g., http://127.0.0.1:8080/admin")
  5. .build();

Usage Example

We offer a comprehensive set of operations, including User, Subuser, Key, Bucket, Capability, Quota, and Usage. Please refer to the Javadocs for all available operations.

User Management

  1. // List users in the system
  2. List<User> users = rgwAdmin.listUserInfo();
  3. // Create a user
  4. rgwAdmin.createUser(userId);
  5. // Get user information and display keys
  6. User user = rgwAdmin.getUserInfo(userId).get();
  7. user.getS3Credentials().forEach(System.out::println);
  8. // Create a subuser
  9. SubUser subUser = rgwAdmin.createSubUser(userId, "subUserId", SubUser.Permission.FULL, CredentialType.SWIFT);
  10. // Suspend a user
  11. rgwAdmin.suspendUser(userId, true);
  12. // Remove a user
  13. rgwAdmin.removeUser(userId);

Quota Management

  1. // Allow the user to own more buckets
  2. rgwAdmin.modifyUser(userId, ImmutableMap.of("max-buckets", String.valueOf(Integer.MAX_VALUE)));
  3. // Set a quota that limits the user to a maximum of one thousand objects and a maximum usage of 1 GiB
  4. rgwAdmin.setUserQuota(userId, 1000, 1048576);

Bucket Management

  1. // Transfer the bucket ownership from the user to the administrator
  2. BucketInfo bucketInfo = rgwAdmin.getBucketInfo(bucketName).get();
  3. rgwAdmin.linkBucket(bucketName, bucketInfo.getId(), adminUserId);
  4. // Remove a bucket
  5. rgwAdmin.removeBucket(bucketName);

Usage Report

  1. // Retrieve and display the usage report for a given user
  2. UsageInfo userUsage = rgwAdmin.getUserUsage(userId).get();
  3. userUsage.getSummary().forEach(System.out::println);

One More Thing: Radosgw Setup

To get started, you need a ready-to-use radosgw instance and an admin account with the necessary capabilities. Here’s how you can set up a radosgw instance:

If You Don’t Have a Radosgw Setup

  1. You can refer to the Ceph official manual for a quick Ceph cluster setup. If you’re not familiar with Ceph, this may be a bit challenging. An easier approach is available if you have Docker in your environment. To set up a standalone instance with an admin account using the Ceph daemon Docker image, follow these instructions:

    1. $ docker run -d -p 80:8080 -v /etc/ceph/:/etc/ceph/ -e CEPH_DEMO_UID=qqq -e CEPH_DEMO_ACCESS_KEY=qqq -e CEPH_DEMO_SECRET_KEY=qqq -e NETWORK_AUTO_DETECT=4 --name rgw ceph/daemon:v6.0.3-stable-6.0-pacific-centos-8-x86_64 demo

    Note that port 80 should be available.

  2. It takes about two minutes to initialize the Ceph cluster. Check if the setup succeeded with the following command:

    1. $ timeout 120 bash -c "until docker logs rgw &> rgw.log && grep SUCCESS rgw.log; do sleep 1; done"
  3. Once the setup is complete, you can run radosgw-admin4j tests without any additional configuration on the client side since the default config should suffice. Run tests with the following commands:

    1. $ git clone https://github.com/twonote/radosgw-admin4j.git
    2. $ cd radosgw-admin4j
    3. $ mvn test

If You Already Have a Radosgw Instance

  1. First, ensure you have an admin account. If not, create the account with the following commands:

    1. $ radosgw-admin user create --uid=qqq --display-name="qqq" --access-key=qqq --secret-key=qqq
    2. $ radosgw-admin --id admin caps add --caps="buckets=*;users=*;usage=*;metadata=*" --uid=qqq
  2. Enter the key pair (qqq,qqq) and add your radosgw endpoint to the config file.

  3. Note that radosgw does not enable usage log by default. If you need this feature or plan to run test cases, make sure you enable the usage log in your Ceph config file. For example, in your ceph.conf:

    1. ...
    2. [client.radosgw.gateway]
    3. rgw enable usage log = true
    4. rgw usage log tick interval = 1
    5. rgw usage log flush threshold = 1
    6. rgw usage max shards = 32
    7. rgw usage max user shards = 1
    8. ...

That’s it!

Contributing

We welcome all contributions to the project. Our code style follows the Google Java Style Guide, and we use google-java-format for code formatting. There are no unusual policies, and we encourage you to get involved.

Legal

Copyright 2017-2023 twonote & The “radosgw-admin4j” contributors.

Licensed under the Apache License, Version 2.0. You may not use this file except in compliance with the License. You can obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, without warranties or conditions of any kind, either express or implied. See the License for the specific language governing permissions and limitations under the License.