|
| 1 | += Managing Couchbase Clusters from the SDK |
| 2 | +:page-aliases: buckets-and-clusters.adoc |
| 3 | +:page-toclevels: 2 |
| 4 | +:description: Cluster management from the SDK. |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +[abstract] |
| 9 | +{description} |
| 10 | + |
| 11 | + |
| 12 | +The Couchbase {name-sdk} has a management API to provision clusters. |
| 13 | +This is not the only programmatic way to deploy Couchbase, and you may wish to look at |
| 14 | +xref:cloud:terraform:index.adoc[Terraform] for Capella, or some of our command line tools. |
| 15 | + |
| 16 | + |
| 17 | +== Buckets and Clusters |
| 18 | + |
| 19 | +include::{version-common}@sdk:shared:partial$clusters-buckets.adoc[tag=management] |
| 20 | + |
| 21 | +// ... |
| 22 | +Management operations in the Java SDK may be performed through several interfaces depending on the object: |
| 23 | + |
| 24 | +== Creating and Removing Buckets |
| 25 | + |
| 26 | +To create or delete a bucket, call the bucket manager with the `buckets()` call on the cluster: |
| 27 | + |
| 28 | +[source,java] |
| 29 | +---- |
| 30 | +Cluster cluster = Cluster.connect("127.0.0.1", "user", "123456"); |
| 31 | +BucketManager manager = cluster.buckets(); |
| 32 | +manager.createBucket(bucketSettings); |
| 33 | +---- |
| 34 | + |
| 35 | +// The `BucketSettings` can be created via a builder, [.api]`DefaultBucketSettings.builder()`. |
| 36 | +This class is also used to expose information about an existing bucket (`manager.getBucket(string)`) or to update an existing bucket (`manager.updateBucket(bucketSettings)`). |
| 37 | + |
| 38 | +The default Collection & Default Scope will be used automatically. |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +// Collections & Scopes |
| 46 | +//// |
| 47 | +
|
| 48 | +The Collections feature in Couchbase Server 7.0 is fully implemented in the Scala SDK version 1.2. |
| 49 | +
|
| 50 | +Please see the xref:{version-server}@server:learn:data/scopes-and-collections.adoc[Scopes and Collections page] in the Server docs. |
| 51 | +
|
| 52 | +== Using Collections & Scopes |
| 53 | +
|
| 54 | +Access a non-default collection, in the default scope, with: |
| 55 | +
|
| 56 | +[source,scala] |
| 57 | +---- |
| 58 | +include::example$CollectionsExample.scala[tag=collections_1,indent=0] |
| 59 | +---- |
| 60 | +
|
| 61 | +And for a non-default scope: |
| 62 | +[source,scala] |
| 63 | +---- |
| 64 | +include::example$CollectionsExample.scala[tag=collections_2,indent=0] |
| 65 | +---- |
| 66 | +
|
| 67 | +
|
| 68 | +== Further Reading |
| 69 | +
|
| 70 | +To see Collections in action, take a look at our xref:howtos:working-with-collections.adoc[Collections-enabled Travel Sample page]. |
| 71 | +//// |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +== User Management |
| 78 | + |
| 79 | +include::{version-common}@sdk:pages:partial$user-management.adoc[] |
| 80 | + |
| 81 | + |
| 82 | +The SDK lets you programmatically create _users_, assign them _roles_ and associated _privileges_, and remove them from the system. |
| 83 | + |
| 84 | +This is an overview of the user management API's capabilities. |
| 85 | + For a practical look at using it, see xref:howtos:sdk-user-management-example.adoc[Sample Code]. |
| 86 | + |
| 87 | +=== Creating a User |
| 88 | + |
| 89 | +The syntax required for creating a user varies according to language, and is covered for each SDK in the management documentation. |
| 90 | +The basic form is as follows: |
| 91 | + |
| 92 | +---- |
| 93 | +boolean upsertUser (String userid, UserSettings settings) |
| 94 | +---- |
| 95 | + |
| 96 | +The method *upsertUser* creates a user and adds the user to the Couchbase Cluster. |
| 97 | +The user will subsequently be visible in the *Security* panel of the Couchbase Web Console. |
| 98 | +Note that successful user-addition results in a user _locally_ defined, with _username_ and _password_ stored on Couchbase Server: _external_ users (whose credentials reside on a network-available server, possibly accessed by means of LDAP) should not be created by this SDK method. |
| 99 | +If the local user created by *upsertUser* already exists, the previous definition is overwritten. |
| 100 | + |
| 101 | +The method takes two arguments. |
| 102 | +The first, a _String_ is the user ID of the user to be created: for example, `johnsmith0325`, or `user734`. |
| 103 | +This must be specified. |
| 104 | + |
| 105 | +The second is a _UserSettings_ object. |
| 106 | +This takes the following form: |
| 107 | + |
| 108 | +---- |
| 109 | +UserSettings { |
| 110 | + String password; |
| 111 | + String name; |
| 112 | + Role[] roles; |
| 113 | +} |
| 114 | +---- |
| 115 | + |
| 116 | +The object contains three data-members. |
| 117 | +The first is a _String_ that specifies the user's password: this must be provided. |
| 118 | +The second is a _String_ that specifies the user's name (for example, `John Smith`): this is optional, and so may be omitted. |
| 119 | +The third is an array of _Role_ objects: this must be specified. |
| 120 | +Each _Role_ object takes the following form: |
| 121 | + |
| 122 | +---- |
| 123 | +Role { |
| 124 | + String role; |
| 125 | + String bucket_name; |
| 126 | +} |
| 127 | +---- |
| 128 | + |
| 129 | +The object's two data-members are both _Strings_, and must both be specified. |
| 130 | +The _String_ specified as the role must correspond to a role supported by Couchbase Server. |
| 131 | +The _String_ specified as the bucket_name must either correspond to a bucket currently defined on Couchbase Server; or be the asterisk character (_*_), meaning _all buckets_. |
| 132 | + |
| 133 | +The method returns a _boolean_, which is `true` if the operation is successful, otherwise `false`. |
| 134 | +// end::creating_a_user[] |
| 135 | + |
| 136 | +[#listing_users] |
| 137 | +// tag::listing_users[] |
| 138 | +=== Listing Users |
| 139 | + |
| 140 | +The basic form of the method used to return currently defined users is as follows: |
| 141 | + |
| 142 | +---- |
| 143 | +List<User> getUsers() |
| 144 | +---- |
| 145 | + |
| 146 | +The method returns a list of _User_ objects, each of which takes the following form: |
| 147 | + |
| 148 | +---- |
| 149 | +User { |
| 150 | + String name; |
| 151 | + String id; |
| 152 | + String domain; |
| 153 | + Role[] roles; |
| 154 | +} |
| 155 | +---- |
| 156 | + |
| 157 | +The name is the full name of the user. |
| 158 | +The id is the user's ID. |
| 159 | +The domain is either `local` or `external`. |
| 160 | +Each Role object in the Role-array has the form already described above, in _Creating a User_. |
| 161 | + |
| 162 | + |
| 163 | +=== Getting a User |
| 164 | + |
| 165 | +The basic form of the method used to return an already defined user is as follows: |
| 166 | + |
| 167 | +---- |
| 168 | +User getUser (String userid) |
| 169 | +---- |
| 170 | + |
| 171 | +The method returns a _User_ object, which takes the following form: |
| 172 | + |
| 173 | +---- |
| 174 | +User { |
| 175 | + String name; |
| 176 | + String id; |
| 177 | + String domain; |
| 178 | + Role[] roles; |
| 179 | +} |
| 180 | +---- |
| 181 | + |
| 182 | +The name is the full name of the user. |
| 183 | +The id is the user's ID. |
| 184 | +The domain is either `local` or `external`. |
| 185 | +Each Role object in the Role-array has the form described above, in _Creating a User_. |
| 186 | + |
| 187 | + |
| 188 | +=== Removing a User |
| 189 | + |
| 190 | +The basic form of the method used to remove users is as follows: |
| 191 | + |
| 192 | +---- |
| 193 | +boolean removeUser (String userid) |
| 194 | +---- |
| 195 | + |
| 196 | +The method's sole argument is the id of the user to be removed from the system, specified as a _String_. |
| 197 | +The method returns a _boolean_, whose value is `true` if the operation is successful, otherwise `false`. |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | +// == Further Information |
| 202 | + |
| 203 | +// For SDK implementation of the API, see xref:howtos:sdk-user-management-example.adoc[Sample Code]. |
0 commit comments