Code Monkey home page Code Monkey logo

radosgw-admin4j's Introduction

Build Status License Javadocs

About

radosgw-admin4j is a Ceph object storage admin client that allows provisioning and control of a Ceph object storage deployment. Features include user/sub user management, quota management, usage report, bucket/object management, etc.

Highlight

  • Fully support all operations includes sub user, quota and more in the latest Ceph version.
  • An easier way to manage radosgw. Avoid troubles when working with radosgw admin APIs, especially that docs are a bit confusing and inconsistent with the code base.
  • Quality and compatibility - Continuous Integration and tests against Ceph LTS versions (Mimic/Nautilus currently.)
  • Contributor friendly - typical contribution process, no weird policies, all contributions are welcome!

Start using

Add dependency

You can obtain radosgw-admim4j from Maven Central using the following identifier:

Configuration

RgwAdmin RGW_ADMIN =
              new RgwAdminBuilder()
                  .accessKey("administrator access key")
                  .secretKey("administrator secret key")
                  .endpoint("radosgw admin endpoint, e.g., http://127.0.0.1:8080/admin")
                  .build();

Usage example

We support all types of operation includes User, Subuser, Key, Bucket, Capability, Quota and Usage. Please check all available operations in Javadocs

User management

// List user in the system
List<User> users = RGW_ADMIN.listUserInfo();

// Create user
RGW_ADMIN.createUser(userId);

// Get user information and show keys
User user = RGW_ADMIN.getUserInfo(userId).get();
user.getS3Credentials().stream().peek(System.out::println);

// Create subuser
SubUser subUser = RGW_ADMIN.createSubUser(userId, "subUserId", SubUser.Permission.FULL, CredentialType.SWIFT);

// Suspend a user
RGW_ADMIN.suspendUser(userId, true);

// Remove a user
RGW_ADMIN.removeUser(userId);

Quota management

// Allow the user owns more buckets
RGW_ADMIN.modifyUser(userId, ImmutableMap.of("max-buckets", String.valueOf(Integer.MAX_VALUE)));

// Set the quota that causes the user can have at most one thousand objects, and the maximal usage is 1 GiB
RGW_ADMIN.setUserQuota(userId, 1000, 1048576);

Bucket management

// Transfer the bucket owner from the user just created to the administrator
BucketInfo bucketInfo = RGW_ADMIN.getBucketInfo(bucketName).get();
RGW_ADMIN.linkBucket(bucketName, bucketInfo.getId(), adminUserId);

// Remove a bucket
RGW_ADMIN.removeBucket(bucketName);

Usage report

// Retrieve and show the usage report for a given user
UsageInfo userUsage = RGW_ADMIN.getUserUsage(userId).get();
userUsage.getSummary().stream().peek(System.out::println);

One more thing: Radosgw setup

To kick off, you need one ready to use radosgw instance and one radosgw account with proper admin capabilities. Follow the guide below to have a radowgw setup then you can fire the example code.

“I do not have a radosgw setup currently”

You could refer the Ceph official manual to setup a Ceph cluster with radosgw quickly. In fact, it is not a piece of cake if you do not familiar with Ceph. Things will be easier if you have docker in your environment. To setup a setup instance with an admin account powered by the Ceph daemon image, follow instructions below:

$ sudo docker rm -f rgwn; rm -rf /etc/cephn rgwn.log; sudo docker run -d -p 80:80 -v /etc/cephn/:/etc/ceph/ -e CEPH_DEMO_UID=qqq -e CEPH_DEMO_ACCESS_KEY=qqq -e CEPH_DEMO_SECRET_KEY=qqq -e  RGW_CIVETWEB_PORT=80  -e NETWORK_AUTO_DETECT=4 --name rgwn ceph/daemon:v4.0.1-stable-4.0-nautilus-centos-7 demo; 

Note that port 80 should be available.

Check the setup succeeded by the following command:

$ timeout 60 bash -c "until docker logs rgwn &> rgwn.log && grep SUCCESS rgwn.log; do sleep 1; done"

Once the above procedure is done, you can now run radosgw-admin4j tests without any config on the client side, since the default config is meet the case. Run tests by:

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

“I already have a radosgw instance on hand”

First, you need an admin account. If you not yet have it, create the account with the following command:

$ radosgw-admin user create --uid=qqq --display-name="qqq" --access-key=qqq --secret-key=qqq
$ radosgw-admin --id admin caps add --caps="buckets=*;users=*;usage=*;metadata=*" --uid=qqq

Second, enter the key pair (qqq,qqq) and add your radosgw endpoint to the config file

Note that radosgw does not enable usage log in default. If you need the feature (or run test cases), be sure that you enable the usage log in Ceph config file. Example ceph.conf:

...
[client.radosgw.gateway]
rgw enable usage log = true
rgw usage log tick interval = 1
rgw usage log flush threshold = 1
rgw usage max shards = 32
rgw usage max user shards = 1
...

That's all!

Contributing

All contributions are welcome. Our code style is Google java style and we use google-java-format to do code formatting. Nothing else special.

Legal

Copyright 2017-2019 twonote & The "radosgw-admin4j" contributors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may 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.

radosgw-admin4j's People

Contributors

alexwangd avatar faust64 avatar hrchu avatar swimfish09 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.