/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="proxyPort">Optional parameter. Does not apply to Ephemeral buckets.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket.</param> /// <returns> /// A boolean value indicating the result. /// </returns> public async Task <IResult> CreateBucketAsync(string name, int proxyPort, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Three) { var uri = GetBucketAPIUri(); var formData = new Dictionary <string, string> { { "user", _username }, { "password", _password }, { "name", name }, { "authType", authType.ToString().ToLowerInvariant() }, { "bucketType", bucketType.ToString().ToLowerInvariant() }, { "flushEnabled", flushEnabled ? "1" : "0" }, { "parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant() }, { "ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture) }, { "replicaNumber", ((int)replicaNumber).ToString(CultureInfo.InvariantCulture) }, { "saslPassword", saslPassword }, { "threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture) } }; if (bucketType != BucketTypeEnum.Ephemeral) { formData.Add("replicaIndex", indexReplicas ? "1" : "0"); if (proxyPort > 0) { formData.Add("proxyPort", proxyPort.ToString(CultureInfo.InvariantCulture)); } } return(await PostFormDataAsync(uri, formData).ContinueOnAnyContext()); }
public void CreateBucket_DoesNotExist_Success(BucketTypeEnum bucketType) { if (!TestConfiguration.Settings.EnhancedAuth && bucketType == BucketTypeEnum.Ephemeral) { Assert.Ignore("Emphemeral buckets require CB server 5.0+"); } // Ensure the bucket doesn't already exist _clusterManager.RemoveBucket(BucketName + "_" + bucketType); Thread.Sleep(250); // Act var result = _clusterManager.CreateBucket(BucketName, bucketType: bucketType); try { // Assert Assert.NotNull(result); Assert.True(result.Success); } finally { // Cleanup Thread.Sleep(250); var removeResult = _clusterManager.RemoveBucket(BucketName); Assert.True(removeResult.Success); Thread.Sleep(250); } }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { IResult result; try { using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(_username, _password) }) { using (var client = new HttpClient(handler)) { var server = _clientConfig.Servers.First(); const string api = "{0}://{1}:{2}/pools/default/buckets"; var protocol = _clientConfig.UseSsl ? "https" : "http"; var port = _clientConfig.UseSsl ? _clientConfig.HttpsMgmtPort : _clientConfig.MgmtPort; var uri = new Uri(string.Format(api, protocol, server.Host, port)); var contentType = new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Host = uri.Authority; var request = new HttpRequestMessage(HttpMethod.Post, uri); request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Concat(_username, ":", _password)))); request.Content = new FormUrlEncodedContent(new Dictionary <string, string> { { "user", _username }, { "password", _password }, { "name", name }, { "authType", authType.ToString().ToLowerInvariant() }, { "bucketType", bucketType.ToString().ToLowerInvariant() }, { "flushEnabled", flushEnabled ? "0" : "1" }, { "proxyPort", 0.ToString(CultureInfo.InvariantCulture) }, { "parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant() }, { "ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture) }, { "replicaIndex", indexReplicas ? "0" : "1" }, { "replicaNumber", ((int)replicaNumber).ToString(CultureInfo.InvariantCulture) }, { "saslPassword", saslPassword }, { "threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture) } }); request.Content.Headers.ContentType = contentType; var task = client.PostAsync(uri, request.Content); task.Wait(); result = GetResult(task.Result); } } } catch (AggregateException e) { Log.Error(e); result = new DefaultResult(false, e.Message, e); } return(result); }
public void CreateBucket_DoesNotExist_Success(BucketTypeEnum bucketType) { // Arrange // Ensure the bucket doesn't already exist _clusterManager.RemoveBucket(BucketName + "_" + bucketType); Thread.Sleep(250); // Act var result = _clusterManager.CreateBucket(BucketName, bucketType: bucketType); try { // Assert Assert.NotNull(result); Assert.True(result.Success); } finally { // Cleanup Thread.Sleep(250); var removeResult = _clusterManager.RemoveBucket(BucketName); Assert.True(removeResult.Success); Thread.Sleep(250); } }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { using (new SynchronizationContextExclusion()) { return (CreateBucketAsync(name, ramQuota, bucketType, replicaNumber, authType, indexReplicas, flushEnabled, parallelDbAndViewCompaction, saslPassword, threadNumber).Result); } }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public Task <IResult> CreateBucketAsync(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Three) { return(CreateBucketAsync(name, 0, ramQuota, bucketType, replicaNumber, authType, indexReplicas, flushEnabled, parallelDbAndViewCompaction, saslPassword, threadNumber)); }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { var uri = GetBucketAPIUri(); var formData = new Dictionary <string, object> { { "user", _username }, { "password", _password }, { "name", name }, { "authType", authType.ToString().ToLowerInvariant() }, { "bucketType", bucketType.ToString().ToLowerInvariant() }, { "flushEnabled", flushEnabled ? "0" : "1" }, { "proxyPort", 0.ToString(CultureInfo.InvariantCulture) }, { "parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant() }, { "ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture) }, { "replicaIndex", indexReplicas ? "0" : "1" }, { "replicaNumber", ((int)replicaNumber).ToString(CultureInfo.InvariantCulture) }, { "saslPassword", saslPassword }, { "threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture) } }; return(PostFormData(uri, formData)); }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public async Task<IResult> CreateBucketAsync(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { var uri = GetBucketAPIUri(); var formData = new Dictionary<string, string> { {"user", _username}, {"password", _password}, {"name", name}, {"authType", authType.ToString().ToLowerInvariant()}, {"bucketType", bucketType.ToString().ToLowerInvariant()}, {"flushEnabled", flushEnabled ? "1" : "0"}, {"proxyPort", 0.ToString(CultureInfo.InvariantCulture)}, {"parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant()}, {"ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture)}, {"replicaIndex", indexReplicas ? "1" : "0"}, {"replicaNumber", ((int) replicaNumber).ToString(CultureInfo.InvariantCulture)}, {"saslPassword", saslPassword}, {"threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture)} }; return await PostFormDataAsync(uri, formData); }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { using (new SynchronizationContextExclusion()) { return CreateBucketAsync(name, ramQuota, bucketType, replicaNumber, authType, indexReplicas, flushEnabled, parallelDbAndViewCompaction, saslPassword, threadNumber).Result; } }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public async Task<IResult> CreateBucketAsync(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { IResult result; try { using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(_username, _password) }) { using (var client = new HttpClient(handler)) { var uri = GetBucketAPIUri(); var contentType = new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"); client.DefaultRequestHeaders.Accept.Add(contentType); client.DefaultRequestHeaders.Host = uri.Authority; var request = new HttpRequestMessage(HttpMethod.Post, uri); request.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Concat(_username, ":", _password)))); request.Content = new FormUrlEncodedContent(new Dictionary<string, string> { {"user", _username}, {"password", _password}, {"name", name}, {"authType", authType.ToString().ToLowerInvariant()}, {"bucketType", bucketType.ToString().ToLowerInvariant()}, {"flushEnabled", flushEnabled ? "0" : "1"}, {"proxyPort", 0.ToString(CultureInfo.InvariantCulture)}, {"parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant()}, {"ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture)}, {"replicaIndex", indexReplicas ? "0" : "1"}, {"replicaNumber", ((int) replicaNumber).ToString(CultureInfo.InvariantCulture)}, {"saslPassword", saslPassword}, {"threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture)} }); request.Content.Headers.ContentType = contentType; var task = client.PostAsync(uri, request.Content); var postResult = await task; result = await GetResult(postResult); } } } catch (AggregateException e) { Log.Error(e); result = new DefaultResult(false, e.Message, e); } return result; }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { IResult result; try { var uri = GetBucketAPIUri(); var request = WebRequest.Create(uri) as HttpWebRequest; request.Method = "POST"; request.Accept = request.ContentType = "application/x-www-form-urlencoded"; request.Credentials = new NetworkCredential(_username, _password); var formData = new Dictionary<string, object> { {"user", _username}, {"password", _password}, {"name", name}, {"authType", authType.ToString().ToLowerInvariant()}, {"bucketType", bucketType.ToString().ToLowerInvariant()}, {"flushEnabled", flushEnabled ? "0" : "1"}, {"proxyPort", 0.ToString(CultureInfo.InvariantCulture)}, {"parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant()}, {"ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture)}, {"replicaIndex", indexReplicas ? "0" : "1"}, {"replicaNumber", ((int) replicaNumber).ToString(CultureInfo.InvariantCulture)}, {"saslPassword", saslPassword}, {"threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture)} }; var bytes = System.Text.Encoding.UTF8.GetBytes(PostDataDicToString(formData)); request.ContentLength = bytes.Length; using (var stream = request.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } using (var response = request.GetResponse() as HttpWebResponse) { using (var reqStream = response.GetResponseStream()) { result = GetResult(response.StatusCode, reqStream); } } } catch (WebException e) { if (e.Response != null) { var stream = e.Response.GetResponseStream(); result = WebRequestError(e, GetString(stream)); } else result = WebRequestError(e); Log.Error(e); } catch (Exception e) { result = WebRequestError(e); Log.Error(e); } return result; }
/// <summary> /// Creates a new bucket on the cluster /// </summary> /// <param name="name">Required parameter. Name for new bucket.</param> /// <param name="ramQuota">The RAM quota in megabytes. The default is 100.</param> /// <param name="bucketType">Required parameter. Type of bucket to be created. “Memcached” configures as Memcached bucket. “Couchbase” configures as Couchbase bucket</param> /// <param name="replicaNumber">The number of replicas of each document: minimum 0, maximum 3.</param> /// <param name="authType">The authentication type.</param> /// <param name="indexReplicas">Disable or enable indexes for bucket replicas.</param> /// <param name="flushEnabled">Enables the flush functionality on the specified bucket.</param> /// <param name="parallelDbAndViewCompaction">Indicates whether database and view files on disk can be compacted simultaneously.</param> /// <param name="saslPassword">Optional Parameter. String. Password for SASL authentication. Required if SASL authentication has been enabled.</param> /// <param name="threadNumber">Optional Parameter. Integer from 2 to 8. Change the number of concurrent readers and writers for the data bucket. </param> /// <returns>A boolean value indicating the result.</returns> public IResult CreateBucket(string name, uint ramQuota = 100, BucketTypeEnum bucketType = BucketTypeEnum.Couchbase, ReplicaNumber replicaNumber = ReplicaNumber.Two, AuthType authType = AuthType.Sasl, bool indexReplicas = false, bool flushEnabled = false, bool parallelDbAndViewCompaction = false, string saslPassword = "", ThreadNumber threadNumber = ThreadNumber.Two) { IResult result; try { var uri = GetBucketAPIUri(); var request = WebRequest.Create(uri) as HttpWebRequest; request.Method = "POST"; request.Accept = request.ContentType = "application/x-www-form-urlencoded"; request.Credentials = new NetworkCredential(_username, _password); var formData = new Dictionary <string, object> { { "user", _username }, { "password", _password }, { "name", name }, { "authType", authType.ToString().ToLowerInvariant() }, { "bucketType", bucketType.ToString().ToLowerInvariant() }, { "flushEnabled", flushEnabled ? "0" : "1" }, { "proxyPort", 0.ToString(CultureInfo.InvariantCulture) }, { "parallelDBAndViewCompaction", parallelDbAndViewCompaction.ToString().ToLowerInvariant() }, { "ramQuotaMB", ramQuota.ToString(CultureInfo.InvariantCulture) }, { "replicaIndex", indexReplicas ? "0" : "1" }, { "replicaNumber", ((int)replicaNumber).ToString(CultureInfo.InvariantCulture) }, { "saslPassword", saslPassword }, { "threadsNumber", ((int)threadNumber).ToString(CultureInfo.InvariantCulture) } }; var bytes = System.Text.Encoding.UTF8.GetBytes(PostDataDicToString(formData)); request.ContentLength = bytes.Length; using (var stream = request.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); } using (var response = request.GetResponse() as HttpWebResponse) { using (var reqStream = response.GetResponseStream()) { result = GetResult(response.StatusCode, reqStream); } } } catch (WebException e) { if (e.Response != null) { var stream = e.Response.GetResponseStream(); result = WebRequestError(e, GetString(stream)); } else { result = WebRequestError(e); } Log.Error(e); } catch (Exception e) { result = WebRequestError(e); Log.Error(e); } return(result); }