Ejemplo n.º 1
0
        public Server(IOStrategy ioStrategy, IViewClient viewClient, IQueryClient queryClient, INodeAdapter nodeAdapter,
                      ClientConfiguration clientConfiguration, ITypeTranscoder transcoder, IBucketConfig bucketConfig)
        {
            _ioStrategy = ioStrategy;
            _ioStrategy.ConnectionPool.Owner = this;
            _nodeAdapter         = nodeAdapter;
            _clientConfiguration = clientConfiguration;
            _timingEnabled       = _clientConfiguration.EnableOperationTiming;
            _typeTranscoder      = transcoder;
            _bucketConfig        = bucketConfig;

            //services that this node is responsible for
            IsMgmtNode  = _nodeAdapter.MgmtApi > 0;
            IsDataNode  = _nodeAdapter.KeyValue > 0;
            IsQueryNode = _nodeAdapter.N1QL > 0;
            IsIndexNode = _nodeAdapter.IndexAdmin > 0;
            IsViewNode  = _nodeAdapter.Views > 0;

            //View and query clients
            ViewClient  = viewClient;
            QueryClient = queryClient;

            //timer and node status
            _heartBeatTimer = new Timer(1000)
            {
                Enabled = false
            };
            _heartBeatTimer.Elapsed += _heartBeatTimer_Elapsed;
            TakeOffline(_ioStrategy.ConnectionPool.InitializationFailed);
        }
Ejemplo n.º 2
0
 public Server(IIOService ioService, INodeAdapter nodeAdapter, ITypeTranscoder transcoder, ConcurrentDictionary <string, QueryPlan> queryCache, ConfigContextBase context) :
     this(ioService,
          new ViewClient(new CouchbaseHttpClient(context)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, context.ClientConfig.ViewRequestTimeout)
 }, new JsonDataMapper(context), context),
          new StreamingViewClient(new CouchbaseHttpClient(context)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, context.ClientConfig.ViewRequestTimeout)
 }, new JsonDataMapper(context), context),
          new QueryClient(new CouchbaseHttpClient(context)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)context.ClientConfig.QueryRequestTimeout)
 }, new JsonDataMapper(context), queryCache, context),
          new StreamingQueryClient(new CouchbaseHttpClient(context)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)context.ClientConfig.QueryRequestTimeout)
 }, new JsonDataMapper(context), queryCache, context),
          new SearchClient(new CouchbaseHttpClient(context)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)context.ClientConfig.SearchRequestTimeout)
 }, new SearchDataMapper(), context),
          new AnalyticsClient(new CouchbaseHttpClient(context)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)context.ClientConfig.QueryRequestTimeout)
 }, new JsonDataMapper(context), context),
          nodeAdapter, transcoder, context)
 {
 }
 internal static IIOService CreateIOService(INodeAdapter node)
 {
     var server = node.Hostname.Replace("8091", node.KeyValue.ToString(CultureInfo.InvariantCulture));
     var connectionPool = new ConnectionPool<Connection>(new PoolConfiguration(), UriExtensions.GetEndPoint(server));
     var ioService = new PooledIOService(connectionPool);
     return ioService;
 }
Ejemplo n.º 4
0
 public Server(IIOService ioService, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder, ConcurrentDictionary <string, QueryPlan> queryCache) :
     this(ioService,
          new ViewClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, clientConfiguration.ViewRequestTimeout)
 }, new JsonDataMapper(clientConfiguration), clientConfiguration),
          new StreamingViewClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, clientConfiguration.ViewRequestTimeout)
 }, new JsonDataMapper(clientConfiguration), clientConfiguration),
          new QueryClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)clientConfiguration.QueryRequestTimeout)
 }, new JsonDataMapper(clientConfiguration), clientConfiguration, queryCache),
          new StreamingQueryClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)clientConfiguration.QueryRequestTimeout)
 }, new JsonDataMapper(clientConfiguration), clientConfiguration, queryCache),
          new SearchClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)clientConfiguration.SearchRequestTimeout)
 }, new SearchDataMapper(), clientConfiguration),
          new AnalyticsClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)clientConfiguration.QueryRequestTimeout)
 }, new JsonDataMapper(clientConfiguration), clientConfiguration),
          nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
Ejemplo n.º 5
0
 public Server(IOStrategy ioStrategy, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration, IBucketConfig bucketConfig) :
     this(ioStrategy,
          new ViewClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          new QueryClient(new HttpClient(), new JsonDataMapper(clientConfiguration), clientConfiguration),
          nodeAdapter, clientConfiguration)
 {
 }
Ejemplo n.º 6
0
 public Server(IOStrategy ioStrategy, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder, ConcurrentDictionary <string, QueryPlan> queryCache) :
     this(ioStrategy,
          new ViewClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          new QueryClient(new HttpClient(), new JsonDataMapper(clientConfiguration), clientConfiguration, queryCache),
          nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
        internal static IOStrategy CreateIOStrategy(INodeAdapter node)
        {
            var server         = node.Hostname.Replace("8091", node.KeyValue.ToString(CultureInfo.InvariantCulture));
            var connectionPool = new ConnectionPool <Connection>(new PoolConfiguration(), UriExtensions.GetEndPoint(server));
            var ioStrategy     = new DefaultIOStrategy(connectionPool);

            return(ioStrategy);
        }
Ejemplo n.º 8
0
 public Server(IIOService ioService, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder) :
     this(ioService,
          new ViewClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          new QueryClient(new HttpClient(), new JsonDataMapper(clientConfiguration), bucketConfig, clientConfiguration),
          nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
Ejemplo n.º 9
0
        public static string GetAnalyticsUri(INodeAdapter adapter, BucketConfiguration config)
        {
            var uri = string.Format(AnalyticsUriFormat,
                                    config.UseSsl ? Https : Http,
                                    adapter.Hostname,
                                    config.UseSsl ? adapter.AnalyticsSsl : adapter.Analytics);

            return(uri);
        }
Ejemplo n.º 10
0
 public Server(IOStrategy ioStrategy, IViewClient viewClient, IQueryClient queryClient, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration)
 {
     _ioStrategy          = ioStrategy;
     ViewClient           = viewClient;
     QueryClient          = queryClient;
     _nodeAdapter         = nodeAdapter;
     _clientConfiguration = clientConfiguration;
     _timingEnabled       = _clientConfiguration.EnableOperationTiming;
 }
Ejemplo n.º 11
0
        public Server(IIOService ioService, IViewClient viewClient, IViewClient streamingViewClient, IQueryClient queryClient, IQueryClient streamingQueryClient, ISearchClient searchClient,
                      IAnalyticsClient analyticsClient, INodeAdapter nodeAdapter,
                      ClientConfiguration clientConfiguration, ITypeTranscoder transcoder, IBucketConfig bucketConfig)
        {
            if (ioService != null)
            {
                _ioService = ioService;
                _ioService.ConnectionPool.Owner = this;
            }
            _nodeAdapter         = nodeAdapter;
            _clientConfiguration = clientConfiguration;
            _bucketConfiguration = clientConfiguration.BucketConfigs[bucketConfig.Name];
            _timingEnabled       = _clientConfiguration.EnableOperationTiming;
            _typeTranscoder      = transcoder;
            _bucketConfig        = bucketConfig;

            //services that this node is responsible for
            IsMgmtNode      = _nodeAdapter.MgmtApi > 0;
            IsDataNode      = _nodeAdapter.KeyValue > 0;
            IsQueryNode     = _nodeAdapter.N1QL > 0;
            IsIndexNode     = _nodeAdapter.IndexAdmin > 0;
            IsViewNode      = _nodeAdapter.Views > 0;
            IsSearchNode    = _nodeAdapter.IsSearchNode;
            IsAnalyticsNode = _nodeAdapter.IsAnalyticsNode;

            //View and query clients
            ViewClient            = viewClient;
            _streamingViewClient  = streamingViewClient;
            QueryClient           = queryClient;
            SearchClient          = searchClient;
            _streamingQueryClient = streamingQueryClient;
            AnalyticsClient       = analyticsClient;

            CachedViewBaseUri  = UrlUtil.GetViewBaseUri(_nodeAdapter, _bucketConfiguration);
            CachedQueryBaseUri = UrlUtil.GetN1QLBaseUri(_nodeAdapter, _bucketConfiguration);

            if (IsDataNode || IsQueryNode)
            {
                _lastIOErrorCheckedTime = DateTime.Now;

                //On initialization, data nodes are authenticated, so they can start in a down state.
                //If the node is down immediately start the timer, otherwise disable it.
                if (IsDataNode)
                {
                    _isDown = _ioService.ConnectionPool.InitializationFailed;
                }

                Log.Info("Initialization {0} for node {1}", _isDown ? "failed" : "succeeded", EndPoint);

                //timer and node status
                _heartBeatTimer = new Timer(_heartBeatTimer_Elapsed, null, Timeout.Infinite, Timeout.Infinite);
                if (_isDown)
                {
                    StartHeartbeatTimer();
                }
            }
        }
Ejemplo n.º 12
0
        // ReSharper disable once InconsistentNaming
        public static string GetN1QLBaseUriAsString(INodeAdapter adapter, BucketConfiguration config)
        {
            var uriAsString = string.Format(N1QLUriFormat,
                config.UseSsl ? Https : Http,
                adapter.Hostname,
                config.UseSsl ? adapter.N1QLSsl : adapter.N1QL);

            return uriAsString;
        }
Ejemplo n.º 13
0
        // ReSharper disable once InconsistentNaming
        public static string GetN1QLBaseUriAsString(INodeAdapter adapter, BucketConfiguration config)
        {
            var uriAsString = string.Format(N1QLUriFormat,
                                            config.UseSsl ? Https : Http,
                                            GetHostName(adapter),
                                            config.UseSsl ? adapter.N1QLSsl : adapter.N1QL);

            return(uriAsString);
        }
Ejemplo n.º 14
0
        public static string GetBaseUriAsString(INodeAdapter adapter, BucketConfiguration config)
        {
            var uriAsString = string.Format(BaseUriFormat,
                                            config.UseSsl ? Https : Http,
                                            adapter.Hostname,
                                            config.UseSsl ? adapter.MgmtApiSsl: adapter.MgmtApi);

            return(uriAsString);
        }
Ejemplo n.º 15
0
        public static string GetSearchBaseUri(INodeAdapter adapter,
            BucketConfiguration config)
        {
            var uriAsString = string.Format(BaseUriFormat,
                config.UseSsl ? Https : Http,
                adapter.Hostname,
                config.UseSsl ? adapter.FtsSsl : adapter.Fts);

            return uriAsString;
        }
Ejemplo n.º 16
0
        public static string GetViewBaseUriAsString(INodeAdapter adapter, BucketConfiguration config)
        {
            var uriAsString = string.Format(ViewUriFormat,
                config.UseSsl ? Https : Http,
                adapter.Hostname,
                config.UseSsl ? adapter.ViewsSsl : adapter.Views,
                config.BucketName);

            return uriAsString;
        }
Ejemplo n.º 17
0
        public static string GetViewBaseUriAsString(INodeAdapter adapter, BucketConfiguration config)
        {
            var uriAsString = string.Format(ViewUriFormat,
                                            config.UseSsl ? Https : Http,
                                            adapter.Hostname,
                                            config.UseSsl ? adapter.ViewsSsl : adapter.Views,
                                            config.BucketName);

            return(uriAsString);
        }
Ejemplo n.º 18
0
        public static string GetSearchBaseUri(INodeAdapter adapter,
                                              BucketConfiguration config)
        {
            var uriAsString = string.Format(BaseUriFormat,
                                            config.UseSsl ? Https : Http,
                                            GetHostName(adapter),
                                            config.UseSsl ? adapter.FtsSsl : adapter.Fts);

            return(uriAsString);
        }
Ejemplo n.º 19
0
        public Server(IOStrategy ioStrategy, IViewClient viewClient, IQueryClient queryClient, INodeAdapter nodeAdapter,
                      ClientConfiguration clientConfiguration, ITypeTranscoder transcoder, IBucketConfig bucketConfig)
        {
            if (ioStrategy != null)
            {
                _ioStrategy = ioStrategy;
                _ioStrategy.ConnectionPool.Owner = this;
            }
            _nodeAdapter         = nodeAdapter;
            _clientConfiguration = clientConfiguration;
            _bucketConfiguration = clientConfiguration.BucketConfigs[bucketConfig.Name];
            _timingEnabled       = _clientConfiguration.EnableOperationTiming;
            _typeTranscoder      = transcoder;
            _bucketConfig        = bucketConfig;

            //services that this node is responsible for
            IsMgmtNode  = _nodeAdapter.MgmtApi > 0;
            IsDataNode  = _nodeAdapter.KeyValue > 0;
            IsQueryNode = _nodeAdapter.N1QL > 0;
            IsIndexNode = _nodeAdapter.IndexAdmin > 0;
            IsViewNode  = _nodeAdapter.Views > 0;

            //View and query clients
            ViewClient  = viewClient;
            QueryClient = queryClient;

            CachedViewBaseUri  = UrlUtil.GetViewBaseUri(_nodeAdapter, _bucketConfiguration);
            CachedQueryBaseUri = UrlUtil.GetN1QLBaseUri(_nodeAdapter, _bucketConfiguration);

            if (IsDataNode || IsQueryNode)
            {
                _lastIOErrorCheckedTime = DateTime.Now;

                //On initialization, data nodes are authenticated, so they can start in a down state.
                //If the node is down immediately start the timer, otherwise disable it.
                if (IsDataNode)
                {
                    _isDown = _ioStrategy.ConnectionPool.InitializationFailed;
                }

                Log.InfoFormat("Initialization {0} for node {1}", _isDown ? "failed" : "succeeded", EndPoint);

                //timer and node status
                _heartBeatTimer = new Timer(_clientConfiguration.NodeAvailableCheckInterval)
                {
                    Enabled = _isDown
                };
                _heartBeatTimer.Elapsed += _heartBeatTimer_Elapsed;
            }
        }
Ejemplo n.º 20
0
 public Server(IIOService ioService, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder) :
     this(ioService,
          new ViewClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, clientConfiguration.ViewRequestTimeout)
 }, new JsonDataMapper(clientConfiguration)),
          new QueryClient(new CouchbaseHttpClient(clientConfiguration, bucketConfig)
 {
     Timeout = new TimeSpan(0, 0, 0, 0, (int)clientConfiguration.QueryRequestTimeout)
 }, new JsonDataMapper(clientConfiguration), clientConfiguration),
          new SearchClient(bucketConfig, clientConfiguration, new SearchDataMapper()),
          nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Updates the configured ports and URIs using the provided <see cref="T:Couchbase.Core.INodeAdapter" />.
        /// </summary>
        /// <param name="nodeAdapter">The node adapter.</param>
        public void LoadNodeAdapter(INodeAdapter nodeAdapter)
        {
            _nodeAdapter = nodeAdapter;

            //services that this node is responsible for
            IsMgmtNode      = _nodeAdapter.MgmtApi > 0;
            IsDataNode      = _nodeAdapter.KeyValue > 0;
            IsQueryNode     = _nodeAdapter.N1QL > 0;
            IsIndexNode     = _nodeAdapter.IndexAdmin > 0;
            IsViewNode      = _nodeAdapter.Views > 0;
            IsSearchNode    = _nodeAdapter.IsSearchNode;
            IsAnalyticsNode = _nodeAdapter.IsAnalyticsNode;

            CachedViewBaseUri  = UrlUtil.GetViewBaseUri(_nodeAdapter, _bucketConfiguration);
            CachedQueryBaseUri = UrlUtil.GetN1QLBaseUri(_nodeAdapter, _bucketConfiguration);
        }
 public static IPEndPoint GetEndPoint(INodeAdapter adapter, BucketConfiguration clientConfig, IBucketConfig server)
 {
     var address = adapter.Hostname.Split(':').First();
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address, out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address));
         ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     var port = clientConfig.UseSsl ? adapter.KeyValueSsl : adapter.KeyValue;
     return new IPEndPoint(ipAddress, port);
 }
Ejemplo n.º 23
0
        public Server(IIOService ioService, IViewClient viewClient, IViewClient streamingViewClient, IQueryClient queryClient, IQueryClient streamingQueryClient, ISearchClient searchClient,
                      IAnalyticsClient analyticsClient, INodeAdapter nodeAdapter, ITypeTranscoder transcoder, ConfigContextBase context)
        {
            if (ioService != null)
            {
                _ioService = ioService;
                _ioService.ConnectionPool.Owner = this;
            }

            _clientConfiguration = context.ClientConfig;
            _bucketConfiguration = context.ClientConfig.BucketConfigs[context.BucketConfig.Name];
            _timingEnabled       = _clientConfiguration.EnableOperationTiming;
            _typeTranscoder      = transcoder;
            _bucketConfig        = context.BucketConfig;

            //set all properties based off the nodes and nodeExt adapter
            LoadNodeAdapter(nodeAdapter);

            //View and query clients
            ViewClient            = viewClient;
            _streamingViewClient  = streamingViewClient;
            QueryClient           = queryClient;
            SearchClient          = searchClient;
            _streamingQueryClient = streamingQueryClient;
            AnalyticsClient       = analyticsClient;

            if (IsDataNode || IsQueryNode)
            {
                _lastIOErrorCheckedTime = DateTime.Now;

                //On initialization, data nodes are authenticated, so they can start in a down state.
                //If the node is down immediately start the timer, otherwise disable it.
                if (IsDataNode)
                {
                    _isDown = _ioService.ConnectionPool.InitializationFailed;
                }

                Log.Info("Initialization {0} for node {1}", _isDown ? "failed" : "succeeded", EndPoint);

                //timer and node status
                _heartBeatTimer = new Timer(_heartBeatTimer_Elapsed, null, Timeout.Infinite, Timeout.Infinite);
                if (_isDown)
                {
                    StartHeartbeatTimer();
                }
            }
        }
Ejemplo n.º 24
0
        public static IPEndPoint GetEndPoint(INodeAdapter adapter, BucketConfiguration clientConfig, IBucketConfig serverConfig)
        {
            var       address = adapter.Hostname.Split(':').First();
            IPAddress ipAddress;

            if (!IPAddress.TryParse(address, out ipAddress))
            {
                var uri = new Uri(String.Format("http://{0}", address));
                ipAddress = uri.GetIpAddress();
                if (ipAddress == null)
                {
                    throw new ArgumentException("ipAddress");
                }
            }
            var port = clientConfig.UseSsl ? adapter.KeyValueSsl : adapter.KeyValue;

            return(new IPEndPoint(ipAddress, port));
        }
Ejemplo n.º 25
0
 public static FailureCountingUri GetFailureCountinSearchBaseUri(INodeAdapter adapter,
     BucketConfiguration config)
 {
     return new FailureCountingUri(GetSearchBaseUri(adapter, config));
 }
Ejemplo n.º 26
0
 public static FailureCountingUri GetFailureCountingBaseUri(INodeAdapter adapter, BucketConfiguration config)
 {
     return new FailureCountingUri(GetN1QLBaseUriAsString(adapter, config));
 }
Ejemplo n.º 27
0
 public void LoadNodeAdapter(INodeAdapter nodeAdapter, uint rev)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 28
0
 public Server(IIOService ioService, INodeAdapter nodeAdapter, ClientConfiguration clientConfiguration,
               IBucketConfig bucketConfig, ITypeTranscoder transcoder) :
     this(ioService, null, null, null, null, null, null, nodeAdapter, clientConfiguration, transcoder, bucketConfig)
 {
 }
Ejemplo n.º 29
0
 public Server(IIOService ioService, INodeAdapter nodeAdapter, ITypeTranscoder transcoder, ConfigContextBase context) :
     this(ioService, null, null, null, null, null, null, nodeAdapter, transcoder, context)
 {
 }
Ejemplo n.º 30
0
 public static FailureCountingUri GetFailureCountingBaseUri(INodeAdapter adapter, BucketConfiguration config)
 {
     return(new FailureCountingUri(GetN1QLBaseUriAsString(adapter, config)));
 }
Ejemplo n.º 31
0
 public static FailureCountingUri GetFailureCountinSearchBaseUri(INodeAdapter adapter,
                                                                 BucketConfiguration config)
 {
     return(new FailureCountingUri(GetSearchBaseUri(adapter, config)));
 }
Ejemplo n.º 32
0
 public static FailureCountingUri GetFailureCountingAnalyticsUri(INodeAdapter adapter, BucketConfiguration config)
 {
     return(new FailureCountingUri(GetAnalyticsUri(adapter, config)));
 }
Ejemplo n.º 33
0
 public static Uri GetViewBaseUri(INodeAdapter adapter, BucketConfiguration config)
 {
     return new Uri(GetViewBaseUriAsString(adapter, config));
 }
Ejemplo n.º 34
0
 // ReSharper disable once InconsistentNaming
 public static Uri GetN1QLBaseUri(INodeAdapter adapter, BucketConfiguration config)
 {
     return(new Uri(GetN1QLBaseUriAsString(adapter, config)));
 }
Ejemplo n.º 35
0
 public static string GetHostName(INodeAdapter adapter)
 {
     return(adapter.IsIPv6 && !adapter.Hostname.Contains("[")
         ? string.Concat("[", adapter.Hostname, "]")
         : adapter.Hostname);
 }