private void Dispose(bool disposing) { lock (_syncObj) { if (!_disposed) { _disposed = true; IsDown = true; if (disposing) { GC.SuppressFinalize(this); } if (_heartBeatTimer != null) { _heartBeatTimer.Dispose(); } if (_ioService != null) { _ioService.Dispose(); } } } }
public override IConfigInfo GetConfig(string bucketName, string password) { Log.Debug(m => m("Getting config for bucket {0}", bucketName)); var bucketConfiguration = GetOrCreateConfiguration(bucketName); //if the client is using a password make sure the client configuration references it password = string.IsNullOrEmpty(password) ? bucketConfiguration.Password : password; if (string.IsNullOrEmpty(bucketConfiguration.Password)) { bucketConfiguration.Password = password; } var exceptions = new List <Exception>(); CouchbaseConfigContext configInfo = null; foreach (var server in bucketConfiguration.Servers.Shuffle()) { var port = bucketConfiguration.UseSsl ? BucketConfiguration.SslPort : bucketConfiguration.Port; var endPoint = server.GetIPEndPoint(port); Log.Debug(m => m("Bootstrapping with {0}", endPoint)); IIOService ioService = null; try { var poolConfig = bucketConfiguration.ClonePoolConfiguration(server); var connectionPool = ConnectionPoolFactory(poolConfig, endPoint); ioService = IOServiceFactory(connectionPool); var saslMechanism = SaslFactory(bucketName, password, ioService, Transcoder); ioService.SaslMechanism = saslMechanism; var operationResult = ioService.Execute( new Config(Transcoder, ClientConfig.DefaultOperationLifespan, endPoint)); if (operationResult.Success) { var bucketConfig = operationResult.Value; bucketConfig.SurrogateHost = connectionPool.EndPoint.Address.ToString(); bucketConfig.Password = password; configInfo = new CouchbaseConfigContext(bucketConfig, ClientConfig, IOServiceFactory, ConnectionPoolFactory, SaslFactory, Transcoder); Log.Info(m => m("Bootstrap config: {0}", JsonConvert.SerializeObject(bucketConfig))); configInfo.LoadConfig(ioService); Configs[bucketName] = configInfo; break; } var exception = operationResult.Exception; if (exception != null) { exceptions.Add(exception); } //CCCP only supported for Couchbase Buckets if (operationResult.Status == ResponseStatus.UnknownCommand) { throw new ConfigException("{0} is this a Memcached bucket?", operationResult.Value); } Log.Warn(m => m("Could not retrieve configuration for {0}. Reason: {1}", bucketName, operationResult.Message)); } catch (ConfigException) { ioService.Dispose(); Log.Debug(m => m("Bootstrapping with {0} failed.", endPoint)); throw; } catch (AuthenticationException e) { const string msg = "A failure to authenticate may mean that the server has not joined the cluster" + " yet or that the Bucket does not exist. Please check that {0} has joined that" + " cluster and that the Bucket '{1}' exists."; Log.Warn(m => m(msg, endPoint, bucketName)); Log.Warn(e); exceptions.Add(e); } catch (Exception e) { Log.Debug(m => m("Bootstrapping with {0} failed.", endPoint)); Log.Warn(e); exceptions.Add(e); } finally { if (ioService != null && configInfo == null) { ioService.Dispose(); } } } //Client cannot bootstrap with this provider if (configInfo == null) { throw new AggregateException(exceptions); } return(configInfo); }
public override IConfigInfo GetConfig(string bucketName, string username, string password) { Log.Debug("Getting config for bucket {0}", bucketName); var bucketConfiguration = GetOrCreateConfiguration(bucketName); //if the client is using a password make sure the client configuration references it password = string.IsNullOrEmpty(password) ? bucketConfiguration.Password : password; if (string.IsNullOrEmpty(bucketConfiguration.Password)) { bucketConfiguration.Password = password; } var exceptions = new List <Exception>(); CouchbaseConfigContext configInfo = null; foreach (var server in bucketConfiguration.Servers.Shuffle()) { var port = bucketConfiguration.UseSsl ? BucketConfiguration.SslPort : bucketConfiguration.Port; var endPoint = server.GetIPEndPoint(port); Log.Debug("Bootstrapping with {0}", endPoint); IIOService ioService = null; try { var poolConfig = bucketConfiguration.ClonePoolConfiguration(server); var connectionPool = ConnectionPoolFactory(poolConfig, endPoint); var saslMechanism = SaslFactory(username, password, connectionPool, Transcoder); connectionPool.SaslMechanism = saslMechanism; // setup IO service, this does SASL negotiation & hello ioService = IOServiceFactory(connectionPool); // finish initialising connection pool ready to be used connectionPool.Initialize(); var operation = new Config(Transcoder, ClientConfig.DefaultOperationLifespan, endPoint); IOperationResult <BucketConfig> operationResult; using (poolConfig.ClientConfiguration.Tracer.StartParentScope(operation, addIgnoreTag: true, ignoreActiveSpan: true)) { operationResult = ioService.Execute(operation); } if (operationResult.Success) { var bucketConfig = operationResult.Value; if (string.IsNullOrWhiteSpace(bucketConfig.BucketType) && bucketConfig.BucketCapabilities != null) { bucketConfig.BucketType = (bucketConfig.BucketCapabilities.Contains("couchapi", StringComparer.OrdinalIgnoreCase) ? BucketTypeEnum.Couchbase : BucketTypeEnum.Ephemeral).ToString().ToLowerInvariant(); } bucketConfig.SurrogateHost = connectionPool.EndPoint.Address.ToString(); bucketConfig.Password = password; if (ClientConfig.UseSsl) { foreach (var ipEndPoint in bucketConfig.VBucketServerMap.IPEndPoints) { ipEndPoint.Port = ClientConfig.SslPort; } } configInfo = new CouchbaseConfigContext(bucketConfig, ClientConfig, IOServiceFactory, ConnectionPoolFactory, SaslFactory, Transcoder, username, password); Log.Info("Bootstrap config: {0}", JsonConvert.SerializeObject(bucketConfig)); configInfo.LoadConfig(ioService); Configs[bucketName] = configInfo; break; } var exception = operationResult.Exception; if (exception != null) { exceptions.Add(exception); } //CCCP only supported for Couchbase Buckets if (operationResult.Status == ResponseStatus.UnknownCommand) { const string message = "Config operation returned UnknownCommand."; Log.Info(message); exceptions.Add(new ConfigException(message)); break; } Log.Warn("Could not retrieve configuration for {0}. Reason: {1}", bucketName, operationResult.Message); } catch (AuthenticationException e) { const string msg = "A failure to authenticate may mean that the server has not joined the cluster" + " yet or that the Bucket does not exist. Please check that {0} has joined that" + " cluster and that the Bucket '{1}' exists. If using LDAP, please set" + " forceSaslPlain to true."; Log.Warn(msg, endPoint, bucketName); Log.Warn(e); exceptions.Add(e); } catch (Exception e) { Log.Debug("Bootstrapping with {0} failed.", endPoint); Log.Warn(e); exceptions.Add(e); } finally { if (ioService != null && configInfo == null) { ioService.Dispose(); } } } //Client cannot bootstrap with this provider if (configInfo == null) { throw new AggregateException("Could not bootstrap with CCCP.", exceptions); } return(configInfo); }
public void TestFixtureTearDown() { _ioService.Dispose(); }
public override IConfigInfo GetConfig(string bucketName, string username, string password) { Log.Debug("Getting config for bucket {0}", bucketName); var bucketConfiguration = GetOrCreateConfiguration(bucketName); //if the client is using a password make sure the client configuration references it password = string.IsNullOrEmpty(password) ? bucketConfiguration.Password : password; if (string.IsNullOrEmpty(bucketConfiguration.Password)) { bucketConfiguration.Password = password; } var exceptions = new List <Exception>(); CouchbaseConfigContext configInfo = null; foreach (var server in bucketConfiguration.Servers.Shuffle()) { var port = bucketConfiguration.UseSsl ? BucketConfiguration.SslPort : bucketConfiguration.Port; var endPoint = server.GetIPEndPoint(port); Log.Debug("Bootstrapping with {0}", endPoint); IIOService ioService = null; try { var poolConfig = bucketConfiguration.ClonePoolConfiguration(server); var connectionPool = ConnectionPoolFactory(poolConfig, endPoint); var saslMechanism = SaslFactory(username, password, connectionPool, Transcoder); connectionPool.SaslMechanism = saslMechanism; connectionPool.Initialize(); ioService = IOServiceFactory(connectionPool); if (ioService.SupportsKvErrorMap) { var errorMapResult = ioService.Execute(new GetErrorMap(Transcoder, ClientConfig.DefaultOperationLifespan)); if (!errorMapResult.Success) { throw new Exception("Error retrieving error map. Cluster indicated it was available."); } ioService.SetErrorMap(errorMapResult.Value); } if (ioService.SupportsEnhancedAuthentication) // only execute this if RBAC is enabled on the cluster { var selectBucketResult = ioService.Execute(new SelectBucket(bucketName, Transcoder, ClientConfig.DefaultOperationLifespan)); if (!selectBucketResult.Success) { throw new AuthenticationException(string.Format("Authentication failed for bucket '{0}'", bucketName)); } } var operationResult = ioService.Execute(new Config(Transcoder, ClientConfig.DefaultOperationLifespan, endPoint)); if (operationResult.Success) { var bucketConfig = operationResult.Value; if (string.IsNullOrWhiteSpace(bucketConfig.BucketType) && bucketConfig.BucketCapabilities != null) { bucketConfig.BucketType = (bucketConfig.BucketCapabilities.Contains("couchapi", StringComparer.OrdinalIgnoreCase) ? BucketTypeEnum.Couchbase : BucketTypeEnum.Ephemeral).ToString().ToLowerInvariant(); } bucketConfig.SurrogateHost = connectionPool.EndPoint.Address.ToString(); bucketConfig.Password = password; configInfo = new CouchbaseConfigContext(bucketConfig, ClientConfig, IOServiceFactory, ConnectionPoolFactory, SaslFactory, Transcoder); Log.Info("Bootstrap config: {0}", JsonConvert.SerializeObject(bucketConfig)); configInfo.LoadConfig(ioService); Configs[bucketName] = configInfo; break; } var exception = operationResult.Exception; if (exception != null) { exceptions.Add(exception); } //CCCP only supported for Couchbase Buckets if (operationResult.Status == ResponseStatus.UnknownCommand) { throw new ConfigException("{0} is this a Memcached bucket?", operationResult.Value); } Log.Warn("Could not retrieve configuration for {0}. Reason: {1}", bucketName, operationResult.Message); } catch (ConfigException) { ioService.Dispose(); Log.Debug("Bootstrapping with {0} failed.", endPoint); throw; } catch (AuthenticationException e) { const string msg = "A failure to authenticate may mean that the server has not joined the cluster" + " yet or that the Bucket does not exist. Please check that {0} has joined that" + " cluster and that the Bucket '{1}' exists."; Log.Warn(msg, endPoint, bucketName); Log.Warn(e); exceptions.Add(e); } catch (Exception e) { Log.Debug("Bootstrapping with {0} failed.", endPoint); Log.Warn(e); exceptions.Add(e); } finally { if (ioService != null && configInfo == null) { ioService.Dispose(); } } } //Client cannot bootstrap with this provider if (configInfo == null) { throw new AggregateException(exceptions); } return(configInfo); }
public void OneTimeTearDown() { _ioService.Dispose(); }