Esempio n. 1
0
        public void TestCommandDownloadBucketWithInvalidRemotePathIsBlockedBySanitizationAndThrowError(string invalidPath, string pathType = null)
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new DownloadBucketCommand();
            var config           = new BucketConfiguration()
            {
                RemoteRelativePathFiles   = new List <string>(),
                RemoteRelativePathFolders = new List <string>(),
                LocalPathGet       = "a",
                RemoteRelativePath = "b",
                DeleteFiles        = true,
            };

            switch (pathType)
            {
            case "folder":
                config.RemoteRelativePathFolders.Add(invalidPath);
                break;

            case "file":
            default:
                config.RemoteRelativePathFiles.Add(invalidPath);
                break;
            }
            var ret = Assert.ThrowsAsync <Exception>(
                async() => await command.ExecuteAsync(bucket, config, ct),
                "Invalid path should throw an error");

            var expectedErrorMessage = "Download failed. Invalid remote path(s)";

            Assert.AreEqual(expectedErrorMessage, ret.Message);
        }
Esempio n. 2
0
        public void ListBucketOptionsCheckTestParsArg()
        {
            string[]            argv = null;
            var                 commandLineParser = new CommandLine.Parser();
            CommandLineParser   parser            = new CommandLineParser(new OptionConverter(new JsonDeserializer()), commandLineParser, new ParserUsage(), new VerbFormater());
            IConfiguration      iConfSet          = null;
            BucketConfiguration confset           = null;

            argv     = new string[] { "bucket", "list" };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.List);

            argv     = new string[] { "bucket", "list" };
            iConfSet = parser.Parse(argv);

            if (!(iConfSet is BucketConfiguration))
            {
                throw new Exception("return value is not ConfigurationBucket ");
            }

            confset = (BucketConfiguration)iConfSet;
            Assert.AreEqual(confset.Type, ConfigType.Bucket);
            Assert.AreEqual(confset.Command, CommandApi.List);
            commandLineParser.Dispose();
        }
Esempio n. 3
0
        public async Task TestToGetFilesInfoFromABucketAndCheckTheReturnHumanReadableStringInfo()
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new ListBucketEntriesCommand(new BytesFormatter());
            var config           = new BucketConfiguration()
            {
                Name                      = "myName",
                LocalPathGet              = "a",
                RemoteRelativePath        = "b",
                RemoteRelativePathFolders = new List <string>()
                {
                    "folder1", "folder2"
                },
                DeleteFiles   = true,
                HumanReadable = true,
            };

            CommandValues.BucketInfoCommandValue ret = await command.ExecuteAsync(bucket, config, ct);

            Assert.IsTrue(ret is CommandValues.BucketInfoCommandValue);
            Assert.AreEqual(ret.Shortname, "Shortname1");
            Assert.AreEqual(ret.BucketFilesDetail[0], "120.56 KB - test/path");
            Assert.AreEqual(ret.TotalFileCount, "156");
            Assert.AreEqual(ret.TotalUsedSpaceBytes, "52.94 KB");
        }
Esempio n. 4
0
        public void When_NotSupportedException_Thrown_When_Proxy_Port_Is_Configured()
        {
            var configuration = new ClientConfiguration {
                PoolConfiguration = new PoolConfiguration
                {
                    MaxSize = 10,
                    MinSize = 10
                }
            };

            configuration.Servers.Clear();
            configuration.Servers.Add(new Uri("http://127.0.0.1:8091/pools"));

            var bc = new BucketConfiguration();

            bc.Password   = "******";
            bc.Username   = "******";
            bc.BucketName = "authenticated";

            bc.Servers.Clear();
            bc.Servers.Add(new Uri("http://127.0.0.1:8091/pools"));
            bc.Port = 11211;

            configuration.BucketConfigs.Clear();
            configuration.BucketConfigs.Add("authenticated", bc);
            Assert.Throws <NotSupportedException>(() => configuration.Initialize());
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BucketCacheHandle{TCacheValue}"/> class.
        /// </summary>
        /// <param name="managerConfiguration">The manager configuration.</param>
        /// <param name="configuration">The cache handle configuration.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <exception cref="System.InvalidOperationException">
        /// If <c>configuration.HandleName</c> is not valid.
        /// </exception>
        public BucketCacheHandle(CacheManagerConfiguration managerConfiguration, CacheHandleConfiguration configuration, ILoggerFactory loggerFactory)
            : base(managerConfiguration, configuration)
        {
            NotNull(configuration, nameof(configuration));
            NotNull(loggerFactory, nameof(loggerFactory));

            this.Logger = loggerFactory.CreateLogger(this);

            // we can configure the bucket name by having "<configKey>:<bucketName>" as handle's
            // name value
            var nameParts = configuration.Key.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);

            Ensure(nameParts.Length > 0, "Handle key is not valid {0}", configuration.Key);

            this.configurationName = nameParts[0];

            if (nameParts.Length == 2)
            {
                this.bucketName = nameParts[1];
            }

            this.configuration       = CouchbaseConfigurationManager.GetConfiguration(this.configurationName);
            this.bucketConfiguration = CouchbaseConfigurationManager.GetBucketConfiguration(this.configuration, this.bucketName);
            this.bucket = CouchbaseConfigurationManager.GetBucket(this.configuration, this.configurationName, this.bucketName);
        }
Esempio n. 6
0
        public async Task TestToGetABucketListAndCheckTheReturnStringInfo()
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new BucketListResumeCommand(new BytesFormatter());
            var config           = new BucketConfiguration()
            {
                Name                      = "myName",
                LocalPathGet              = "a",
                RemoteRelativePath        = "b",
                RemoteRelativePathFolders = new List <string>()
                {
                    "folder1", "folder2"
                },
                DeleteFiles = true,
            };

            CommandValues.BucketCommandValue ret = await command.ExecuteAsync(bucket, config, ct);

            Assert.IsTrue(ret is CommandValues.BucketCommandValue);
            Assert.AreEqual(ret.Shortname, "Shortname1");
            Assert.AreEqual(ret.FileCount, "156");
            Assert.AreEqual(ret.UsedSpaceBytes, "54213");
        }
Esempio n. 7
0
        public async Task TestCommandDownloadBucketWithinvalidRemotePathIsBlockedBySanitization(string invalidPath, string pathType = null)
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new DownloadBucketCommand();
            var config           = new BucketConfiguration()
            {
                RemoteRelativePathFiles   = new List <string>(),
                RemoteRelativePathFolders = new List <string>(),
                LocalPathGet       = "a",
                RemoteRelativePath = "b",
                DeleteFiles        = true,
            };

            switch (pathType)
            {
            case "folder":
                config.RemoteRelativePathFolders.Add(invalidPath);
                break;

            case "file":
            default:
                config.RemoteRelativePathFiles.Add(invalidPath);
                break;
            }
            CommandValues.GenericInfoCommandValue ret = await command.ExecuteAsync(bucket, config, ct);

            Assert.IsTrue(ret is CommandValues.GenericInfoCommandValue);
            Assert.AreEqual(ret.Uuid, "Shortname1");
            Assert.AreEqual("Download failed. Invalid remote path(s)", (ret as CommandValues.GenericInfoCommandValue).Message);
        }
Esempio n. 8
0
        protected void CreateCouchBaseDBClientConfiguration(Config config)
        {
            if (config.GetBoolean("UseClusterHelper"))
            {
                BucketName            = config.GetString("BucketName");
                CBClientConfiguration = ClusterHelper.GetBucket(BucketName).Cluster.Configuration;
                UseClusterHelper      = true;
            }
            else
            {
                CBClientConfiguration = new ClientConfiguration();

                // Reset the serializers and deserializers so that JSON is stored as PascalCase instead of camelCase
                CBClientConfiguration.Serializer = () => new DefaultSerializer(new JsonSerializerSettings(), new JsonSerializerSettings());
                CBClientConfiguration.Servers.RemoveAt(0);

                //Get the URI's from the HOCON config
                try
                {
                    if (config.GetStringList("ServersURI").Count > 0)
                    {
                        List <Uri> uris = new List <Uri>();
                        foreach (string s in config.GetStringList("ServersURI"))
                        {
                            CBClientConfiguration.Servers.Add(new Uri(s));
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Invalid URI specified in HOCON configuration", ex);
                }

                // Use SSL?
                CBClientConfiguration.UseSsl = config.GetBoolean("UseSSL");

                // This will not be needed since we are not creating a bucket on the fly.
                //AdminPassword = config.GetString("AdminPassword");
                //AdminUserName = config.GetString("AdminUserName");


                // Get the bucket(s) configuration
                Dictionary <string, BucketConfiguration> BucketConfigs = new Dictionary <string, BucketConfiguration>();
                BucketConfiguration newBC = new BucketConfiguration();


                newBC.UseSsl   = config.GetBoolean("BucketUseSSL");
                newBC.Password = config.GetString("Password");
                newBC.DefaultOperationLifespan = (uint)config.GetInt("DefaultOperationLifespan");
                BucketName       = config.GetString("BucketName");
                newBC.BucketName = BucketName;
                newBC.PoolConfiguration.MinSize = config.GetInt("PoolConfiguration.MinSize");
                newBC.PoolConfiguration.MaxSize = config.GetInt("PoolConfiguration.MaxSize");

                // Create the bucket config specified in the HOCON
                BucketConfigs.Add(newBC.BucketName, newBC);
                CBClientConfiguration.BucketConfigs = BucketConfigs;
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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();
                }
            }
        }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
        /// <summary>
        /// Gets an <see cref="BucketConfiguration"/> from the <see cref="ClientConfiguration"/>. If one doesn't exist
        /// for a given bucket, a new one will be created and added to the configuration.
        /// </summary>
        /// <param name="bucketName">The <see cref="IBucket.Name"/> to use for the lookup.</param>
        /// <returns>An <see cref="BucketConfiguration"/> instance.</returns>
        protected virtual BucketConfiguration GetOrCreateConfiguration(string bucketName)
        {
            try
            {
                ConfigLock.EnterWriteLock();

                // do we already have the bucket config cached?
                if (ClientConfig.BucketConfigs.TryGetValue(bucketName, out var bucketConfiguration))
                {
                    SetNetworkType(bucketConfiguration.NetworkType);
                    return(bucketConfiguration);
                }

                // need to create new config
                // can we copy settings from another bucket's config?
                if (ClientConfig.BucketConfigs.Any())
                {
                    // use settings from existing config
                    var defaultConfig = ClientConfig.BucketConfigs.First().Value;
                    bucketConfiguration = new BucketConfiguration
                    {
                        BucketName        = bucketName,
                        PoolConfiguration = defaultConfig.PoolConfiguration,
                        Servers           = defaultConfig.Servers,
                        Port     = defaultConfig.Port,
                        Username = defaultConfig.Username,
                        Password = string.Empty,
                        UseSsl   = defaultConfig.UseSsl
                    };
                }
                else
                {
                    // create new config using client configuration settings
                    bucketConfiguration = new BucketConfiguration
                    {
                        BucketName        = bucketName,
                        PoolConfiguration = ClientConfig.PoolConfiguration,
                        Servers           = ClientConfig.Servers,
                        UseSsl            = ClientConfig.UseSsl,
                        Port = ClientConfig.DirectPort
                    };
                }

                SetNetworkType(bucketConfiguration.NetworkType);

                // cache bucket config
                ClientConfig.BucketConfigs.Add(bucketConfiguration.BucketName, bucketConfiguration);

                return(bucketConfiguration);
            }
            finally
            {
                ConfigLock.ExitWriteLock();
            }
        }
Esempio n. 16
0
        public void TestBasicCommandOnBucketNotFoundReturnTheNotFoundErrorMessage(CommandApi commandType)
        {
            QBucket bucket = null; // symbolize the null return from sdk retrieve bucket method if the bucket doses not exist
            ICommand <QBucket, CommandValues.GenericInfoCommandValue> command;
            Task commandAsync    = null;
            CancellationToken ct = default(CancellationToken);
            var config           = new BucketConfiguration()
            {
                Name                = "NonExistingBucket",
                LocalPathGet        = "a",
                RemoteRelativePaths = new List <string> {
                    "b"
                },
            };

            switch (commandType)
            {
            case CommandApi.Delete:
                command      = new DeleteBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.SyncFrom:
                command      = new SynchronizeLocalFolderFromBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.SyncTo:
                command      = new SynchronizeLocalFolderToBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.Upload:
                command      = new UploadBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.Download:
                command      = new DownloadBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;

            case CommandApi.Remove:
                command      = new RemoveEntityBucketCommand();
                commandAsync = command.ExecuteAsync(bucket, config, ct);
                break;
            }

            var    cliException = Assert.ThrowsAsync <Exception>(async() => await commandAsync, "Bucket not found should throw an error");
            string expected1    = "Bucket not found";

            StringAssert.Contains(expected1, cliException.Message);
        }
Esempio n. 17
0
        public void When_UseSsl_True_N1QL_Uri_Contains_Https()
        {
            var serverConfigJson = File.ReadAllText("Data\\Configuration\\nodesext-with-json-and-kv.json");
            var serverConfig     = JsonConvert.DeserializeObject <BucketConfig>(serverConfigJson);
            var clientConfig     = new BucketConfiguration {
                UseSsl = true
            };

            var expected = new Uri("https://192.168.77.102:18093/query");
            var actual   = UrlUtil.GetN1QLBaseUri(serverConfig.GetNodes().First(x => x.Hostname.Equals("192.168.77.102")), clientConfig);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 18
0
        public void When_NodeExt_And_UseSsl_Is_True_And_IPv6_IPEndpoint_Uses_Port_11207()
        {
            var serverConfigJson = ResourceHelper.ReadResource("Data\\Configuration\\config-with-nodes-ext.json");
            var serverConfig     = JsonConvert.DeserializeObject <BucketConfig>(serverConfigJson);
            var clientConfig     = new BucketConfiguration {
                UseSsl = true
            };

            const string expected = "192.168.56.101:11207";
            var          actual   = IPEndPointExtensions.GetEndPoint(serverConfig.NodesExt[0].Hostname);

            Assert.AreEqual(expected, actual.ToString());
        }
        public void When_NodeAdapter_And_UseSsl_Is_True_IPEndPoint_Uses_Port_11210()
        {
            var serverConfigJson = ResourceHelper.ReadResource("Data\\Configuration\\config-with-nodes-ext.json");
            var serverConfig     = JsonConvert.DeserializeObject <BucketConfig>(serverConfigJson);
            var clientConfig     = new BucketConfiguration {
                UseSsl = false
            };

            const string expected = "192.168.56.102:11210";
            var          actual   = IPEndPointExtensions.GetEndPoint(serverConfig.GetNodes()[0], clientConfig, serverConfig);

            Assert.AreEqual(expected, actual.ToString());
        }
        public void When_UseSsl_True_View_Uri_Contains_Http()
        {
            var serverConfigJson = ResourceHelper.ReadResource("Data\\Configuration\\nodesext-with-json-and-kv.json");
            var serverConfig     = JsonConvert.DeserializeObject <BucketConfig>(serverConfigJson);
            var clientConfig     = new BucketConfiguration {
                UseSsl = false
            };

            var expected = new Uri("http://192.168.77.102:8092/default/");
            var actual   = UrlUtil.GetViewBaseUri(serverConfig.GetNodes().First(x => x.Hostname.Equals("192.168.77.102")), clientConfig);

            Assert.AreEqual(expected, actual);
        }
        public void When_Node_And_UseSsl_Is_True_IPEndPoint_Uses_Port_11207()
        {
            var serverConfigJson = File.ReadAllText("Data\\Configuration\\config-with-nodes-ext.json");
            var serverConfig     = JsonConvert.DeserializeObject <BucketConfig>(serverConfigJson);
            var clientConfig     = new BucketConfiguration {
                UseSsl = true
            };

            const string expected = "192.168.56.101:11207";
            var          actual   = IPEndPointExtensions.GetEndPoint(serverConfig.Nodes[0], clientConfig, serverConfig);

            Assert.AreEqual(expected, actual.ToString());
        }
Esempio n. 22
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;
            }
        }
Esempio 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();
                }
            }
        }
 /// <summary>
 /// Gets an <see cref="BucketConfiguration"/> from the <see cref="ClientConfiguration"/>. If one doesn't exist
 /// for a given bucket, a new one will be created and added to the configuration.
 /// </summary>
 /// <param name="bucketName">The <see cref="IBucket.Name"/> to use for the lookup.</param>
 /// <returns>An <see cref="BucketConfiguration"/> instance.</returns>
 protected virtual BucketConfiguration GetOrCreateConfiguration(string bucketName)
 {
     try
     {
         ConfigLock.EnterWriteLock();
         BucketConfiguration bucketConfiguration = null;
         if (ClientConfig.BucketConfigs.ContainsKey(bucketName))
         {
             bucketConfiguration = ClientConfig.BucketConfigs[bucketName];
         }
         if (bucketConfiguration != null)
         {
             return(bucketConfiguration);
         }
         var defaultBucket = ClientConfig.BucketConfigs.FirstOrDefault();
         if (defaultBucket.Value == null)
         {
             bucketConfiguration = new BucketConfiguration
             {
                 BucketName        = bucketName,
                 PoolConfiguration = ClientConfig.PoolConfiguration,
                 Servers           = ClientConfig.Servers,
                 UseSsl            = ClientConfig.UseSsl
             };
         }
         else
         {
             var defaultConfig = defaultBucket.Value;
             bucketConfiguration = new BucketConfiguration
             {
                 BucketName        = bucketName,
                 PoolConfiguration = defaultConfig.PoolConfiguration,
                 Servers           = defaultConfig.Servers,
                 Port     = defaultConfig.Port,
                 Username = defaultConfig.Username,
                 Password = string.Empty,
                 UseSsl   = defaultConfig.UseSsl
             };
         }
         ClientConfig.BucketConfigs.Add(bucketConfiguration.BucketName, bucketConfiguration);
         return(bucketConfiguration);
     }
     finally
     {
         ConfigLock.ExitWriteLock();
     }
 }
Esempio n. 25
0
        public static IPEndPoint GetEndPoint(Node node, BucketConfiguration clientConfig, IBucketConfig serverConfig)
        {
            var       address = node.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 ? node.Ports.SslDirect : node.Ports.Direct;

            return(new IPEndPoint(ipAddress, port));
        }
Esempio n. 26
0
        public static IPEndPoint GetEndPoint(NodeExt nodeExt, BucketConfiguration bucketConfig, IBucketConfig serverConfig)
        {
            var       address = nodeExt.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 = bucketConfig.UseSsl ? nodeExt.Services.KvSSL : nodeExt.Services.KV;

            return(new IPEndPoint(ipAddress, port));
        }
Esempio n. 27
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));
        }
Esempio n. 28
0
        public async Task TestCommandSynchronizeLocalFolderFromBucket()
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new SynchronizeLocalFolderFromBucketCommand();
            var config           = new BucketConfiguration()
            {
                LocalPathGet       = "a",
                RemoteRelativePath = "b",
                DeleteFiles        = true,
            };

            CommandValues.GenericInfoCommandValue ret = await command.ExecuteAsync(bucket, config, ct);

            Assert.IsTrue(ret is CommandValues.GenericInfoCommandValue);
            Assert.AreEqual(ret.Uuid, "Shortname1");
        }
Esempio n. 29
0
        public async Task TestCommandSynchronizeLocalFolderToBucketWithInvalidRemotePathIsBlockedBySanitization()
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new SynchronizeLocalFolderToBucketCommand();
            var config           = new BucketConfiguration()
            {
                LocalPathGet       = "a",
                RemoteRelativePath = "/invalid//Path",
                DeleteFiles        = true,
            };

            CommandValues.GenericInfoCommandValue ret = await command.ExecuteAsync(bucket, config, ct);

            Assert.IsTrue(ret is CommandValues.GenericInfoCommandValue);
            Assert.AreEqual(ret.Uuid, "Shortname1");
            Assert.AreEqual("Synchronization failed. Invalid remote path", (ret as CommandValues.GenericInfoCommandValue).Message);
        }
Esempio n. 30
0
        public async Task TestCommandRemoveBucketEntity()
        {
            var bucket = Builder <FakeBucket> .CreateNew().Build();

            CancellationToken ct = default(CancellationToken);
            var command          = new RemoveEntityBucketCommand();
            var config           = new BucketConfiguration()
            {
                LocalPathGet        = "a",
                RemoteRelativePaths = new List <string> {
                    "b"
                },
                DeleteFiles = true,
            };

            CommandValues.GenericInfoCommandValue ret = await command.ExecuteAsync(bucket, config, ct);

            Assert.IsTrue(ret is CommandValues.GenericInfoCommandValue);
            Assert.AreEqual(ret.Uuid, "Shortname1");
        }