Esempio n. 1
0
        public void WithServers_throws_argument_exception_for_invalid_args()
        {
            var config = new ClusterOptions();

            Assert.Throws <ArgumentException>(() => config.Servers());
            Assert.Throws <ArgumentException>(() => config.Servers((string[])null));
            Assert.Throws <ArgumentException>(() => config.Servers((Uri[])null));
            Assert.Throws <ArgumentException>(() => config.Servers(new string[0]));
        }
Esempio n. 2
0
        public async Task InitializeAsync()
        {
            // DNS-SRV
            if (ClusterOptions.IsValidDnsSrv())
            {
                try
                {
                    var dnsResolver = ServiceProvider.GetRequiredService <IDnsResolver>();

                    var bootstrapUri = ClusterOptions.ConnectionStringValue.GetDnsBootStrapUri();
                    var servers      = (await dnsResolver.GetDnsSrvEntriesAsync(bootstrapUri)).ToList();
                    if (servers.Any())
                    {
                        _logger.LogInformation($"Successfully retrieved DNS SRV entries: [{string.Join(",", servers)}]");
                        ClusterOptions.Servers(servers);
                    }
                }
                catch (Exception exception)
                {
                    _logger.LogInformation(exception, "Error trying to retrieve DNS SRV entries.");
                }
            }

            foreach (var server in ClusterOptions.ServersValue)
            {
                var bsEndpoint = server.GetIpEndPoint(ClusterOptions.KvPort, ClusterOptions.EnableIPV6Addressing);
                var node       = await _clusterNodeFactory.CreateAndConnectAsync(bsEndpoint);

                node.BootstrapUri = server;
                GlobalConfig      = await node.GetClusterMap();

                if (GlobalConfig == null) //TODO NCBC-1966 xerror info is being hidden, so on failure this will not be null
                {
                    AddNode(node);        //GCCCP is not supported - pre-6.5 server fall back to CCCP like SDK 2
                }
                else
                {
                    GlobalConfig.IsGlobal = true;
                    foreach (var nodeAdapter in GlobalConfig.GetNodes()) //Initialize cluster nodes for global services
                    {
                        if (server.Host.Equals(nodeAdapter.Hostname))    //this is the bootstrap node so update
                        {
                            node.BootstrapUri = server;
                            node.NodesAdapter = nodeAdapter;
                            node.BuildServiceUris();
                            SupportsCollections = node.Supports(ServerFeatures.Collections);
                            AddNode(node);
                        }
                        else
                        {
                            var endpoint = nodeAdapter.GetIpEndPoint(ClusterOptions.EnableTls);
                            if (endpoint.Port == 0)
                            {
                                endpoint.Port = 11210;
                            }
                            var newNode = await _clusterNodeFactory.CreateAndConnectAsync(endpoint);

                            newNode.BootstrapUri = server;
                            newNode.NodesAdapter = nodeAdapter;
                            newNode.BuildServiceUris();
                            SupportsCollections = node.Supports(ServerFeatures.Collections);
                            AddNode(newNode);
                        }
                    }
                }
            }
        }