Kapil Earanky
Kapil Earanky

Reputation: 211

Managing Couchbase buckets dynamically through Java SDK

I would like to know if there's some way to perform functions like listing the existing buckets in a couchbase cluster, creating a new bucket, retrieving cluster information etc. using the Couchbase Java SDK?

I know this can be done through the REST API, but I'm trying to manage the cluster dynamically using Java.

Upvotes: 1

Views: 184

Answers (2)

Prashant_Sharma
Prashant_Sharma

Reputation: 176

To create a new bucket you can use the cluster manager class's insertBucket() method that takes in a BucketSettings object. For example you can create a bucket like this :

....

    BucketSettings PrashantSampleBucket = new 
    DefaultBucketSettings.Builder()
            .type(BucketType.COUCHBASE)
            .name("PrashantSampleBucket")
            .password("")
            .quota(2048) // megabytes
            .replicas(1)
            .indexReplicas(true)
            .enableFlush(true)
            .build();

.... and now you need to insert your bucket in your cluster this can be done by :

    cluster.clusterManager().insertBucket(PrashantSampleBucket);

Upvotes: 0

Simon Baslé
Simon Baslé

Reputation: 28301

Yes, there is a ClusterManager class accessible through the Clusterobject's clusterManager() method. You'll need the administrative credentials.

Upvotes: 2

Related Questions