예제 #1
0
 public AutobahnSpec WithServer(string name, string url)
 {
     Servers.Add(new ServerSpec(name, url));
     return(this);
 }
예제 #2
0
파일: Core.cs 프로젝트: v0lat1le/krpc
 /// <summary>
 /// Add a server to the core.
 /// </summary>
 internal void Add(Server.Server server)
 {
     Servers.Add(server);
     Configure(server);
     Logger.WriteLine("Added server '" + server.Name + "'");
 }
예제 #3
0
        public void Start(DashboardOptions dashboardOptions)
        {
            IsRestApi = dashboardOptions.Dashboard == null;

            if (!dashboardOptions.DisableTelemetry)
            {
                TelemetryClient client = new TelemetryClient();
                client.InstrumentationKey = "20963fa8-39e9-404f-98f4-b74627b140f4";
                client.TrackEvent("Start", new Dictionary <string, string> {
                    { "Edition", Constants.Edition },
                    { "Type", IsRestApi ? "REST" : "Dashboard" }
                });
            }

            Port = dashboardOptions.Port;

            var assemblyBasePath = Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location);
            var libraryDirectory = Path.Combine(assemblyBasePath, "..", "client");

            var calc = new CustomAssemblyLoadContext();

            calc.LoadNativeLibraries();

            var builder = new WebHostBuilder()
                          .ConfigureServices((y) =>
            {
                DashboardService = new DashboardService(dashboardOptions, _reloadKey);
                y.Add(new ServiceDescriptor(typeof(IDashboardService), DashboardService));

                if (_reloader != null)
                {
                    y.Add(new ServiceDescriptor(typeof(AutoReloader), _reloader));
                }
            });

            builder = builder.UseKestrel(options =>
            {
                // If we have a certificate configured
                if (dashboardOptions.Certificate != null || dashboardOptions.CertificateFile != null)
                {
                    Action <ListenOptions> listenOptionsAction = (ListenOptions listenOptions) => {
                        if (dashboardOptions.Certificate != null)
                        {
                            listenOptions.UseHttps(dashboardOptions.Certificate);
                        }

                        if (dashboardOptions.CertificateFile != null)
                        {
                            listenOptions.UseHttps(dashboardOptions.CertificateFile, SecureStringToString(dashboardOptions.Password));
                        }
                    };

                    // If the ports are different, listen on HTTP and HTTPS
                    if (dashboardOptions.Port != dashboardOptions.HttpsPort)
                    {
                        options.Listen(dashboardOptions.ListenAddress, dashboardOptions.Port);
                        options.Listen(dashboardOptions.ListenAddress, dashboardOptions.HttpsPort, listenOptionsAction);
                    }
                    // If the ports are the same, just listen on the port and configure HTTPS
                    else
                    {
                        options.Listen(dashboardOptions.ListenAddress, dashboardOptions.Port, listenOptionsAction);
                    }
                }
                // If no certificate is configured, just listen on the port
                else
                {
                    options.Listen(dashboardOptions.ListenAddress, dashboardOptions.Port);
                }

                options.Limits.MaxRequestBodySize = null;
            });

            builder = builder
                      .UseSetting("detailedErrors", "true")
                      .UseLibuv()
                      .UseStartup <ServerStartup>()
                      .CaptureStartupErrors(true);

            if (Directory.Exists(libraryDirectory))
            {
                builder.UseContentRoot(libraryDirectory);
            }

            host = builder.Build();

            if (dashboardOptions.Wait)
            {
                this.host.Run();
            }
            else
            {
                this.host.Start();
            }

            this.Running = true;

            Servers.Add(this);
        }
예제 #4
0
        protected async Task <(List <RavenServer> Nodes, RavenServer Leader)> CreateRaftCluster(
            int numberOfNodes,
            bool?shouldRunInMemory = null,
            int?leaderIndex        = null,
            bool useSsl            = false,
            IDictionary <string, string> customSettings             = null,
            List <IDictionary <string, string> > customSettingsList = null,
            bool watcherCluster = false,
            [CallerMemberName] string caller = null)
        {
            string[] allowedNodeTags = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
            leaderIndex = leaderIndex ?? _random.Next(0, numberOfNodes);
            RavenServer leader         = null;
            var         serversToPorts = new Dictionary <RavenServer, string>();
            var         clusterNodes   = new List <RavenServer>(); // we need this in case we create more than 1 cluster in the same test

            _electionTimeoutInMs = Math.Max(300, numberOfNodes * 80);

            if (customSettingsList != null && customSettingsList.Count != numberOfNodes)
            {
                throw new InvalidOperationException("The number of custom settings must equal the number of nodes.");
            }

            for (var i = 0; i < numberOfNodes; i++)
            {
                if (customSettingsList == null)
                {
                    customSettings = customSettings ?? new Dictionary <string, string>(DefaultClusterSettings)
                    {
                        [RavenConfiguration.GetKey(x => x.Cluster.ElectionTimeout)] = _electionTimeoutInMs.ToString(),
                    };
                }
                else
                {
                    customSettings = customSettingsList[i];
                }

                string serverUrl;

                if (useSsl)
                {
                    serverUrl = UseFiddlerUrl("https://127.0.0.1:0");
                    SetupServerAuthentication(customSettings, serverUrl);
                }
                else
                {
                    serverUrl = UseFiddlerUrl("http://127.0.0.1:0");
                    customSettings[RavenConfiguration.GetKey(x => x.Core.ServerUrls)] = serverUrl;
                }
                var co = new ServerCreationOptions
                {
                    CustomSettings      = customSettings,
                    RunInMemory         = shouldRunInMemory,
                    RegisterForDisposal = false,
                    NodeTag             = allowedNodeTags[i]
                };
                var server = GetNewServer(co, caller);
                var port   = Convert.ToInt32(server.ServerStore.GetNodeHttpServerUrl().Split(':')[2]);
                var prefix = useSsl ? "https" : "http";
                serverUrl = UseFiddlerUrl($"{prefix}://127.0.0.1:{port}");
                Servers.Add(server);
                clusterNodes.Add(server);

                serversToPorts.Add(server, serverUrl);
                if (i == leaderIndex)
                {
                    await server.ServerStore.EnsureNotPassiveAsync(null, nodeTag : co.NodeTag);

                    leader = server;
                }
            }

            using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5)))
            {
                for (var i = 0; i < numberOfNodes; i++)
                {
                    if (i == leaderIndex)
                    {
                        continue;
                    }
                    var follower = clusterNodes[i];
                    // ReSharper disable once PossibleNullReferenceException
                    leader = await ActionWithLeader(l =>
                                                    l.ServerStore.AddNodeToClusterAsync(serversToPorts[follower], nodeTag: allowedNodeTags[i], asWatcher: watcherCluster, token: cts.Token), clusterNodes);

                    if (watcherCluster)
                    {
                        await follower.ServerStore.WaitForTopology(Leader.TopologyModification.NonVoter, cts.Token);
                    }
                    else
                    {
                        await follower.ServerStore.WaitForTopology(Leader.TopologyModification.Voter, cts.Token);
                    }
                }
            }

            await WaitForClusterTopologyOnAllNodes(clusterNodes);

            // ReSharper disable once PossibleNullReferenceException
            var condition = await leader.ServerStore.WaitForState(RachisState.Leader, CancellationToken.None).WaitAsync(numberOfNodes * _electionTimeoutInMs * 5);

            var states = string.Empty;

            if (condition == false)
            {
                states = GetLastStatesFromAllServersOrderedByTime();
            }
            Assert.True(condition, "The leader has changed while waiting for cluster to become stable. All nodes status: " + states);
            return(clusterNodes, leader);
        }
예제 #5
0
        /// <summary>
        /// For synchronization with App.config or Web.configs.
        /// </summary>
        /// <param name="couchbaseClientSection"></param>
        public ClientConfiguration(CouchbaseClientSection couchbaseClientSection)
        {
            //For operation timing
            Timer = TimingFactory.GetTimer(Log);

            UseSsl                = couchbaseClientSection.UseSsl;
            SslPort               = couchbaseClientSection.SslPort;
            ApiPort               = couchbaseClientSection.ApiPort;
            DirectPort            = couchbaseClientSection.DirectPort;
            MgmtPort              = couchbaseClientSection.MgmtPort;
            HttpsMgmtPort         = couchbaseClientSection.HttpsMgmtPort;
            HttpsApiPort          = couchbaseClientSection.HttpsApiPort;
            ObserveInterval       = couchbaseClientSection.ObserveInterval;
            ObserveTimeout        = couchbaseClientSection.ObserveTimeout;
            MaxViewRetries        = couchbaseClientSection.MaxViewRetries;
            ViewHardTimeout       = couchbaseClientSection.ViewHardTimeout;
            SerializationSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            DeserializationSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            EnableConfigHeartBeat   = couchbaseClientSection.EnableConfigHeartBeat;
            HeartbeatConfigInterval = couchbaseClientSection.HeartbeatConfigInterval;
            ViewRequestTimeout      = couchbaseClientSection.ViewRequestTimeout;
            Expect100Continue       = couchbaseClientSection.Expect100Continue;
            EnableOperationTiming   = couchbaseClientSection.EnableOperationTiming;
            PoolConfiguration       = new PoolConfiguration(this);

            foreach (var server in couchbaseClientSection.Servers)
            {
                Servers.Add(((UriElement)server).Uri);
                _serversChanged = true;
            }

            BucketConfigs = new Dictionary <string, BucketConfiguration>();
            foreach (var bucketElement in couchbaseClientSection.Buckets)
            {
                var bucket = (BucketElement)bucketElement;
                var bucketConfiguration = new BucketConfiguration
                {
                    BucketName        = bucket.Name,
                    UseSsl            = bucket.UseSsl,
                    Password          = bucket.Password,
                    ObserveInterval   = bucket.ObserveInterval,
                    ObserveTimeout    = bucket.ObserveTimeout,
                    PoolConfiguration = new PoolConfiguration
                    {
                        MaxSize             = bucket.ConnectionPool.MaxSize,
                        MinSize             = bucket.ConnectionPool.MinSize,
                        WaitTimeout         = bucket.ConnectionPool.WaitTimeout,
                        ShutdownTimeout     = bucket.ConnectionPool.ShutdownTimeout,
                        UseSsl              = bucket.ConnectionPool.UseSsl,
                        ClientConfiguration = this
                    }
                };
                BucketConfigs.Add(bucket.Name, bucketConfiguration);
            }

            //Set back to default
            _poolConfigurationChanged = false;
        }
예제 #6
0
        public void Start(DashboardOptions dashboardOptions)
        {
            AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolver.OnAssemblyResolve;

            IsRestApi = dashboardOptions.Dashboard == null;
            Port      = dashboardOptions.Port;

            var assemblyBasePath = Path.GetDirectoryName(this.GetType().GetTypeInfo().Assembly.Location);
            var libraryDirectory = Path.Combine(assemblyBasePath, "..", "client");

            var calc = new CustomAssemblyLoadContext();

            calc.LoadNativeLibraries();

            var builder = new WebHostBuilder()
                          .ConfigureServices((y) =>
            {
                DashboardService dashboardService;
                if (dashboardOptions.Dashboard == null)
                {
                    dashboardService = new DashboardService(dashboardOptions.StaticEndpoints?.ToArray(), dashboardOptions.EndpointInitializationScript, dashboardOptions.UpdateToken, _reloadKey);
                }
                else
                {
                    dashboardService = new DashboardService(dashboardOptions.Dashboard, dashboardOptions.StaticEndpoints?.ToArray(), dashboardOptions.UpdateToken, _reloadKey);
                }

                y.Add(new ServiceDescriptor(typeof(IDashboardService), dashboardService));

                if (_reloader != null)
                {
                    y.Add(new ServiceDescriptor(typeof(AutoReloader), _reloader));
                }
            });

            builder = builder.UseKestrel(options =>
            {
                options.Listen(IPAddress.Any, dashboardOptions.Port, listenOptions =>
                {
                    if (dashboardOptions.Certificate != null)
                    {
                        listenOptions.UseHttps(dashboardOptions.Certificate);
                    }

                    if (dashboardOptions.CertificateFile != null)
                    {
                        listenOptions.UseHttps(dashboardOptions.CertificateFile, SecureStringToString(dashboardOptions.Password));
                    }
                });
            });

            host = builder
                   .UseContentRoot(libraryDirectory)
                   .UseSetting("detailedErrors", "true")
                   .UseStartup <ServerStartup>()
                   .CaptureStartupErrors(true)
                   .Build();

            if (dashboardOptions.Wait)
            {
                this.host.Run();
            }
            else
            {
                this.host.Start();
            }

            this.Running = true;

            Servers.Add(this);
        }
예제 #7
0
 private void AddServer(string[] values)
 {
     Console.WriteLine(String.Format("Adding server '{0}' user: '******'", values[0], values[1]));
     Servers.Add(new TeamCityServer(values[0], values[1], values[2]));
 }
예제 #8
0
        protected void btnNext_Click(Object Sender, EventArgs e)
        {
            oOnDemand.Next(intID, Int32.Parse(Request.QueryString["sid"]));
            Servers oServer    = new Servers(0, dsn);
            DataSet dsClusters = oCluster.Gets(intRequest);

            foreach (DataRow drCluster in dsClusters.Tables[0].Rows)
            {
                int intNodes   = Int32.Parse(drCluster["nodes"].ToString());
                int intDRLeft  = Int32.Parse(drCluster["dr"].ToString());
                int intHALeft  = Int32.Parse(drCluster["ha"].ToString());
                int intCluster = Int32.Parse(drCluster["id"].ToString());
                oServer.DeleteClusters(intCluster);
                DataSet dsServers = oServer.GetClusters(intCluster);
                if (dsServers.Tables[0].Rows.Count > 0)
                {
                    int intServerCopy = Int32.Parse(dsServers.Tables[0].Rows[0]["id"].ToString());
                    int intHA         = 0;
                    if (intHALeft > 0)
                    {
                        intHALeft--;
                        intHA = 1;
                    }
                    int intDR = 0;
                    if (intDRLeft > 0)
                    {
                        intDRLeft--;
                        intDR = 1;
                    }
                    oServer.Update(intServerCopy, intHA, intDR);
                    for (int ii = 1; ii < intNodes; ii++)
                    {
                        intHA = 0;
                        if (intHALeft > 0)
                        {
                            intHALeft--;
                            intHA = 1;
                        }
                        intDR = 0;
                        if (intDRLeft > 0)
                        {
                            intDRLeft--;
                            intDR = 1;
                        }
                        int        intOS         = Int32.Parse(dsServers.Tables[0].Rows[0]["osid"].ToString());
                        int        intSP         = Int32.Parse(dsServers.Tables[0].Rows[0]["spid"].ToString());
                        int        intTemplate   = Int32.Parse(dsServers.Tables[0].Rows[0]["templateid"].ToString());
                        int        intDomain     = Int32.Parse(dsServers.Tables[0].Rows[0]["domainid"].ToString());
                        int        intDomainTest = Int32.Parse(dsServers.Tables[0].Rows[0]["test_domainid"].ToString());
                        int        intINF        = Int32.Parse(dsServers.Tables[0].Rows[0]["infrastructure"].ToString());
                        int        intDRExist    = Int32.Parse(dsServers.Tables[0].Rows[0]["dr_exist"].ToString());
                        string     strDRName     = dsServers.Tables[0].Rows[0]["dr_name"].ToString();
                        int        intDRCons     = Int32.Parse(dsServers.Tables[0].Rows[0]["dr_consistency"].ToString());
                        int        intDRConsID   = Int32.Parse(dsServers.Tables[0].Rows[0]["dr_consistencyid"].ToString());
                        int        intLocal      = Int32.Parse(dsServers.Tables[0].Rows[0]["local_storage"].ToString());
                        int        intAccounts   = Int32.Parse(dsServers.Tables[0].Rows[0]["accounts"].ToString());
                        int        intF          = Int32.Parse(dsServers.Tables[0].Rows[0]["fdrive"].ToString());
                        int        intDBA        = Int32.Parse(dsServers.Tables[0].Rows[0]["dba"].ToString());
                        int        intPNC        = Int32.Parse(dsServers.Tables[0].Rows[0]["pnc"].ToString());
                        int        intDNSAuto    = Int32.Parse(dsServers.Tables[0].Rows[0]["dns_auto"].ToString());
                        int        intServer     = oServer.Add(intRequest, intID, 0, 0, intCluster, ii, intOS, intSP, intTemplate, intDomain, intDomainTest, intINF, intHA, intDR, intDRExist, strDRName, intDRCons, intDRConsID, 1, intLocal, intAccounts, intF, intDBA, intPNC, 0, intDNSAuto);
                        ServerName oServerName   = new ServerName(0, dsn);
                        DataSet    dsComponents  = oServerName.GetComponentDetailSelected(intServerCopy, 1);
                        foreach (DataRow drComponent in dsComponents.Tables[0].Rows)
                        {
                            oServerName.AddComponentDetailSelected(intServer, Int32.Parse(drComponent["detailid"].ToString()), Int32.Parse(drComponent["prerequisiteid"].ToString()), false);
                        }
                    }
                }
            }
            // Add the server entries for each node.
            Response.Redirect(Request.Path + "?id=" + intID.ToString() + "&forward=true");
        }
예제 #9
0
        /// <summary>
        /// Gets all settings from XML file.
        /// </summary>
        private void LoadFromXml()
        {
            //Create XmlDocument object to read XML settings file
            var settingsXmlDoc = new XmlDocument();

            settingsXmlDoc.Load(FilePath);

            //Get Settings section
            var resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Settings/Setting");

            if (resultNodes == null)
            {
                return;
            }

            foreach (XmlNode node in resultNodes)
            {
                _settings[node.Attributes["Key"].Value] = node.Attributes["Value"].Value;
            }

            if (string.IsNullOrEmpty(_settings["ThisServerName"]))
            {
                throw new NGRIDException("ThisServerName is not defined.");
            }

            _thisServerName = _settings["ThisServerName"];

            //Get Servers section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Servers/Server");
            if (resultNodes == null)
            {
                throw new NGRIDException("No server defined.");
            }

            foreach (XmlNode node in resultNodes)
            {
                Servers.Add(new ServerInfoItem
                {
                    Name      = node.Attributes["Name"].Value.Trim(),
                    IpAddress = node.Attributes["IpAddress"].Value,
                    Port      = Convert.ToInt32(node.Attributes["Port"].Value),
                    Adjacents = node.Attributes["Adjacents"].Value
                });
            }

            //Get Applications section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Applications/Application");
            if (resultNodes != null)
            {
                //Read all application entries from xml file
                foreach (XmlNode node in resultNodes)
                {
                    var application = new ApplicationInfoItem
                    {
                        Name = node.Attributes["Name"].Value
                    };

                    //Add predefined communication channels
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        switch (childNode.Name)
                        {
                        case "Communication":
                            switch (childNode.Attributes["Type"].Value)
                            {
                            case "WebService":
                                var webServiceComm = new ApplicationInfoItem.CommunicationChannelInfoItem
                                {
                                    CommunicationType = "WebService"
                                };
                                webServiceComm.CommunicationSettings.Add("Url", childNode.Attributes["Url"].Value);
                                application.CommunicationChannels.Add(webServiceComm);
                                break;
                            }

                            break;
                        }
                    }

                    Applications.Add(application);
                }
            }

            //Get Routes section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Routes/Route");
            if (resultNodes != null)
            {
                //Read all route entries from xml file
                foreach (XmlNode node in resultNodes)
                {
                    var route = new RouteInfoItem
                    {
                        Name             = node.Attributes["Name"].Value,
                        DistributionType = GetAttribute(node, "DistributionType")
                    };

                    //Read all filter entries of route from xml file
                    var filterNodes = node.SelectNodes("/NGRIDConfiguration/Routes/Route/Filters/Filter");
                    if (filterNodes != null)
                    {
                        foreach (XmlNode filterNode in filterNodes)
                        {
                            var filter = new RouteInfoItem.FilterInfoItem
                            {
                                SourceServer           = GetAttribute(filterNode, "SourceServer"),
                                SourceApplication      = GetAttribute(filterNode, "SourceApplication"),
                                DestinationServer      = GetAttribute(filterNode, "DestinationServer"),
                                DestinationApplication =
                                    GetAttribute(filterNode, "DestinationApplication"),
                                TransmitRule = GetAttribute(filterNode, "TransmitRule")
                            };
                            route.Filters.Add(filter);
                        }
                    }

                    //Read all destination entries of route from xml file
                    var destinationNodes = node.SelectNodes("/NGRIDConfiguration/Routes/Route/Destinations/Destination");
                    if (destinationNodes != null)
                    {
                        foreach (XmlNode destinationNode in destinationNodes)
                        {
                            var destination = new RouteInfoItem.DestinationInfoItem
                            {
                                Application = GetAttribute(destinationNode, "Application"),
                                Server      = GetAttribute(destinationNode, "Server"),
                                RouteFactor = Convert.ToInt32(GetAttribute(destinationNode, "RouteFactor") ?? "1")
                            };
                            if (destination.RouteFactor <= 0)
                            {
                                destination.RouteFactor = 1;
                            }

                            route.Destinations.Add(destination);
                        }
                    }

                    Routes.Add(route);
                }
            }
        }
예제 #10
0
 public void AddServer(string address)
 {
     Servers.Add(new Server(CreateIPEndPoint(address)));
 }
예제 #11
0
        protected async Task <(List <RavenServer> Nodes, RavenServer Leader)> CreateRaftCluster(
            int numberOfNodes,
            bool shouldRunInMemory = true,
            int?leaderIndex        = null,
            bool useSsl            = false,
            bool createNewCert     = false,
            string serverCertPath  = null,
            IDictionary <string, string> customSettings             = null,
            List <IDictionary <string, string> > customSettingsList = null,
            bool watcherCluster = false)
        {
            leaderIndex = leaderIndex ?? _random.Next(0, numberOfNodes);
            RavenServer leader          = null;
            var         serversToPorts  = new Dictionary <RavenServer, string>();
            var         clustersServers = new List <RavenServer>();

            _electionTimeoutInMs = Math.Max(300, numberOfNodes * 80);

            if (customSettingsList != null && customSettingsList.Count != numberOfNodes)
            {
                throw new InvalidOperationException("The number of custom settings must equal the number of nodes.");
            }

            for (var i = 0; i < numberOfNodes; i++)
            {
                if (customSettingsList == null)
                {
                    customSettings = customSettings ?? new Dictionary <string, string>()
                    {
                        [RavenConfiguration.GetKey(x => x.Cluster.MoveToRehabGraceTime)] = "1",
                        [RavenConfiguration.GetKey(x => x.Cluster.AddReplicaTimeout)]    = "1",
                        [RavenConfiguration.GetKey(x => x.Cluster.ElectionTimeout)]      = _electionTimeoutInMs.ToString(),
                        [RavenConfiguration.GetKey(x => x.Cluster.StabilizationTime)]    = "1",
                    };
                }
                else
                {
                    customSettings = customSettingsList[i];
                }

                string serverUrl;

                if (useSsl)
                {
                    serverUrl = UseFiddlerUrl("https://127.0.0.1:0");
                    var shouldCreateNewCert = createNewCert && i == 0;
                    SetupServerAuthentication(customSettings, serverUrl, createNew: shouldCreateNewCert, serverCertPath: serverCertPath);
                }
                else
                {
                    serverUrl = UseFiddlerUrl("http://127.0.0.1:0");
                    customSettings[RavenConfiguration.GetKey(x => x.Core.ServerUrls)] = serverUrl;
                }
                var co = new ServerCreationOptions
                {
                    CustomSettings      = customSettings,
                    RunInMemory         = shouldRunInMemory,
                    RegisterForDisposal = false
                };
                var server = GetNewServer(co);
                var port   = Convert.ToInt32(server.ServerStore.GetNodeHttpServerUrl().Split(':')[2]);
                var prefix = useSsl ? "https" : "http";
                serverUrl = UseFiddlerUrl($"{prefix}://127.0.0.1:{port}");
                Servers.Add(server);
                clustersServers.Add(server);

                serversToPorts.Add(server, serverUrl);
                if (i == leaderIndex)
                {
                    server.ServerStore.EnsureNotPassive();
                    leader = server;
                }
            }
            for (var i = 0; i < numberOfNodes; i++)
            {
                if (i == leaderIndex)
                {
                    continue;
                }
                var follower = clustersServers[i];
                // ReSharper disable once PossibleNullReferenceException
                await leader.ServerStore.AddNodeToClusterAsync(serversToPorts[follower], asWatcher : watcherCluster);

                if (watcherCluster)
                {
                    await follower.ServerStore.WaitForTopology(Leader.TopologyModification.NonVoter);
                }
                else
                {
                    await follower.ServerStore.WaitForTopology(Leader.TopologyModification.Voter);
                }
            }
            // ReSharper disable once PossibleNullReferenceException
            var condition = await leader.ServerStore.WaitForState(RachisState.Leader, CancellationToken.None).WaitAsync(numberOfNodes * _electionTimeoutInMs * 5);

            var states = string.Empty;

            if (condition == false)
            {
                states = GetLastStatesFromAllServersOrderedByTime();
            }
            Assert.True(condition, "The leader has changed while waiting for cluster to become stable. All nodes status: " + states);
            return(clustersServers, leader);
        }
예제 #12
0
        protected void btnSaveConfig_Click(Object Sender, EventArgs e)
        {
            int intConfigured = (ddlOS.SelectedIndex > 0 && (panSP.Visible == false || ddlServicePack.SelectedIndex > 0) && (panMaintenance.Visible == false || ddlMaintenance.SelectedIndex > 0) && (panTemplate.Visible == false || ddlTemplate.SelectedIndex > 0) && ddlDomain.SelectedIndex > 0 && (panTest.Visible == false || ddlTestDomain.SelectedIndex > 0) && (panInfrastructure.Visible == false || radInfrastructureYes.Checked == true || radInfrastructureNo.Checked == true) && (radDRYes.Checked == true || radDRNo.Checked == true) ? 1 : 0);
            int intServer     = 0;
            int intDBA        = 0;

            if (Request.Form[hdnUser.UniqueID] != "")
            {
                intDBA = Int32.Parse(Request.Form[hdnUser.UniqueID]);
            }
            int intSP = 0;

            if (Int32.Parse(ddlServicePack.SelectedItem.Value) > 0)
            {
                intSP = Int32.Parse(ddlServicePack.SelectedItem.Value);
            }
            else if (Int32.Parse(ddlMaintenance.SelectedItem.Value) > 0)
            {
                intSP = Int32.Parse(ddlMaintenance.SelectedItem.Value);
            }
            int  intClass = Int32.Parse(oForecast.GetAnswer(intAnswer, "classid"));
            bool boolPNC  = (oClass.Get(intClass, "pnc") == "1");

            if (lblId.Text != "")
            {
                intServer = Int32.Parse(lblId.Text);
                oServer.Update(intServer, Int32.Parse(ddlOS.SelectedItem.Value), intSP, Int32.Parse(ddlTemplate.SelectedItem.Value), Int32.Parse(ddlDomain.SelectedItem.Value), Int32.Parse(ddlTestDomain.SelectedItem.Value), (radInfrastructureYes.Checked ? 1 : 0), (radHAYes.Checked ? 1 : 0), (radDRYes.Checked ? 1 : 0), (radDRYes.Checked && radExistYes.Checked ? 1 : 0), (radDRYes.Checked && radExistYes.Checked ? txtRecovery.Text : ""), (radDRYes.Checked && radConsistencyYes.Checked ? 1 : 0), (radDRYes.Checked && radConsistencyYes.Checked ? Int32.Parse(Request.Form[hdnConsistencyGroup.UniqueID]) : 0), intConfigured, intDBA, (boolPNC == true ? 1 : 0));
            }
            else
            {
                bool boolFDrive = (oForecast.IsDRUnder48(intAnswer, false));
                intServer = oServer.Add(intRequest, intAnswer, 0, intConfig, intCluster, intNumber, Int32.Parse(ddlOS.SelectedItem.Value), intSP, Int32.Parse(ddlTemplate.SelectedItem.Value), Int32.Parse(ddlDomain.SelectedItem.Value), Int32.Parse(ddlTestDomain.SelectedItem.Value), (radInfrastructureYes.Checked ? 1 : 0), (radHAYes.Checked ? 1 : 0), (radDRYes.Checked ? 1 : 0), (radDRYes.Checked && radExistYes.Checked ? 1 : 0), (radDRYes.Checked && radExistYes.Checked ? txtRecovery.Text : ""), (radDRYes.Checked && radConsistencyYes.Checked ? 1 : 0), (radDRYes.Checked && radConsistencyYes.Checked ? Int32.Parse(Request.Form[hdnConsistencyGroup.UniqueID]) : 0), intConfigured, (oForecast.IsStorage(intAnswer) ? 0 : -1), 0, (boolFDrive ? 0 : -1), intDBA, (boolPNC == true ? 1 : 0), 0, (boolPNC == true ? 0 : -100));
                if (intCluster > 0)
                {
                    Cluster oCluster = new Cluster(0, dsn);
                    oCluster.UpdateNonShared(intCluster, 1);
                }
                // Change configured to 0 so that when loading the components, the pre-selected stuff will appear (only when first loading...not after reloading a saved one)
                oServer.UpdateConfigured(intServer, 0);
            }
            // Add Break Fix Name
            string strName = oForecast.GetAnswer(intAnswer, "nameid");

            if (strName != "" && strName != "0")
            {
                oServer.UpdateServerNamed(intServer, Int32.Parse(strName));
            }

            bool    boolReset = false;
            DataSet dsOld     = oServerName.GetComponentDetailSelected(intServer, 1);

            // Save Components
            if (Request.Form["hdnComponents"] != null)
            {
                string strComponents = Request.Form["hdnComponents"];
                //if (strComponents != "")
                //{
                oServerName.DeleteComponentDetailSelected(intServer);
                while (strComponents != "")
                {
                    int intDetail = Int32.Parse(strComponents.Substring(0, strComponents.IndexOf("&")));
                    if (intDetail > 0)
                    {
                        oServerName.AddComponentDetailSelected(intServer, intDetail, 0, true);
                        oServerName.AddComponentDetailPrerequisites(intServer, intDetail, true);
                    }
                    strComponents = strComponents.Substring(strComponents.IndexOf("&") + 1);
                }
                //}
            }

            // Save Application Prerequisites
            int     intApplication = Int32.Parse(oForecast.GetAnswer(intAnswer, "applicationid"));
            DataSet dsInclude      = oServerName.GetComponentDetailSelectedRelated(intApplication, 1);

            foreach (DataRow drInclude in dsInclude.Tables[0].Rows)
            {
                int intDetail = Int32.Parse(drInclude["detailid"].ToString());
                oServerName.AddComponentDetailSelected(intServer, intDetail, -1, true);
                oServerName.AddComponentDetailPrerequisites(intServer, intDetail, true);
            }

            // Send to software component approver(s)
            oServerName.SendComponentNotification(intAnswer, intEnvironment, dsnAsset, dsnIP, intSoftwarePageID);

            DataSet dsNew = oServerName.GetComponentDetailSelected(intServer, 1);

            // Check components and erase if necessary
            foreach (DataRow drOld in dsOld.Tables[0].Rows)
            {
                bool boolFound = false;
                foreach (DataRow drNew in dsNew.Tables[0].Rows)
                {
                    if (drOld["detailid"].ToString() == drNew["detailid"].ToString())
                    {
                        boolFound = true;
                        break;
                    }
                }
                if (boolFound == false)
                {
                    if (drOld["reset_storage"].ToString() == "1")
                    {
                        boolReset = true;
                        break;
                    }
                }
            }
            if (boolReset == false)
            {
                foreach (DataRow drNew in dsNew.Tables[0].Rows)
                {
                    bool boolFound = false;
                    foreach (DataRow drOld in dsOld.Tables[0].Rows)
                    {
                        if (drNew["detailid"].ToString() == drOld["detailid"].ToString())
                        {
                            boolFound = true;
                            break;
                        }
                    }
                    if (boolFound == false)
                    {
                        if (drNew["reset_storage"].ToString() == "1")
                        {
                            boolReset = true;
                            break;
                        }
                    }
                }
            }
            if (boolReset == true)
            {
                oStorage.DeleteLuns(intAnswer, 0, intCluster, intConfig, intNumber);
                oServer.UpdateLocalStorage(intServer, 0);
                if (intCluster > 0)
                {
                    Cluster oCluster = new Cluster(intProfile, dsn);
                    oCluster.UpdateAddInstance(intCluster, 0);
                }
                if (oServer.Get(intServer, "fdrive") == "-1" || oServer.Get(intServer, "fdrive") == "1")
                {
                    oServer.UpdateFDrive(intServer, 0);
                }
            }

            // Check if DBA is required
            bool boolDBA = false;

            foreach (DataRow drNew in dsNew.Tables[0].Rows)
            {
                if (drNew["sql"].ToString() == "1" || drNew["dbase"].ToString() == "1")
                {
                    boolDBA = true;
                    break;
                }
            }

            // Redirect
            if (panComponentsNo.Visible == true)
            {
                Response.Redirect(Request.Url.PathAndQuery + "&menu_tab=2&refresh=true");
            }
            else
            {
                if (boolDBA == true && intDBA == 0)
                {
                    oServer.UpdateConfigured(intServer, 0);
                    Response.Redirect(Request.Url.PathAndQuery + "&required=true&dba=true");
                }
                else
                {
                    Response.Redirect(Request.Url.PathAndQuery + "&save=true");
                }
            }
        }
예제 #13
0
        public async Task CanSnapshotCompareExchangeWithExpiration()
        {
            var count = 45;

            var(_, leader) = await CreateRaftCluster(1, watcherCluster : true);

            using (var store = GetDocumentStore(options: new Options
            {
                Server = leader
            }))
            {
                var expiry           = DateTime.Now.AddMinutes(2);
                var compareExchanges = new Dictionary <string, User>();
                await CompareExchangeExpirationTest.AddCompareExchangesWithExpire(count, compareExchanges, store, expiry);

                await CompareExchangeExpirationTest.AssertCompareExchanges(compareExchanges, store, expiry);

                using (leader.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
                    using (context.OpenReadTransaction())
                    {
                        Assert.Equal(count, CompareExchangeExpirationStorage.GetExpiredValues(context, long.MaxValue).Count());
                    }

                var server2    = GetNewServer();
                var server2Url = server2.ServerStore.GetNodeHttpServerUrl();
                Servers.Add(server2);

                using (var requestExecutor = ClusterRequestExecutor.CreateForSingleNode(leader.WebUrl, null))
                    using (requestExecutor.ContextPool.AllocateOperationContext(out var ctx))
                    {
                        await requestExecutor.ExecuteAsync(new AddClusterNodeCommand(server2Url, watcher : true), ctx);

                        var addDatabaseNode = new AddDatabaseNodeOperation(store.Database);
                        await store.Maintenance.Server.SendAsync(addDatabaseNode);
                    }

                using (server2.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
                    using (context.OpenReadTransaction())
                    {
                        Assert.Equal(count, CompareExchangeExpirationStorage.GetExpiredValues(context, long.MaxValue).Count());
                    }

                var now = DateTime.UtcNow;
                leader.ServerStore.Observer.Time.UtcDateTime = () => now.AddMinutes(3);

                var leaderCount = WaitForValue(() =>
                {
                    using (leader.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
                        using (context.OpenReadTransaction())
                        {
                            return(CompareExchangeExpirationStorage.GetExpiredValues(context, long.MaxValue).Count());
                        }
                }, 0, interval: 333);

                Assert.Equal(0, leaderCount);

                var server2count = WaitForValue(() =>
                {
                    using (server2.ServerStore.Engine.ContextPool.AllocateOperationContext(out ClusterOperationContext context))
                        using (context.OpenReadTransaction())
                        {
                            return(CompareExchangeExpirationStorage.GetExpiredValues(context, long.MaxValue).Count());
                        }
                }, 0, interval: 333);

                Assert.Equal(0, server2count);
            }
        }
예제 #14
0
 private void ServerMaster_ServerCreateEvent(IServer newServer)
 {
     Servers.Add(newServer);
     newServer.PortfoliosChangeEvent += _server_PortfoliosChangeEvent;
     newServer.SecuritiesChangeEvent += _server_SecuritiesChangeEvent;
 }
예제 #15
0
        private void Add(Server s)
        {
            ServerViewModel vm = new ServerViewModel(s);

            Servers.Add(vm);
        }
예제 #16
0
        /// <summary>
        /// For synchronization with App.config or Web.configs.
        /// </summary>
        /// <param name="definition"></param>
        public ClientConfiguration(ICouchbaseClientDefinition definition)
        {
            Timer = TimingFactory.GetTimer(Log);
            NodeAvailableCheckInterval = definition.NodeAvailableCheckInterval;
            UseSsl          = definition.UseSsl;
            SslPort         = definition.SslPort;
            ApiPort         = definition.ApiPort;
            DirectPort      = definition.DirectPort;
            MgmtPort        = definition.MgmtPort;
            HttpsMgmtPort   = definition.HttpsMgmtPort;
            HttpsApiPort    = definition.HttpsApiPort;
            ObserveInterval = definition.ObserveInterval;
            ObserveTimeout  = definition.ObserveTimeout;
            MaxViewRetries  = definition.MaxViewRetries;
#pragma warning disable 618
            ViewHardTimeout       = definition.ViewHardTimeout;
            SerializationSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            DeserializationSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
#pragma warning restore 618
            EnableConfigHeartBeat    = definition.EnableConfigHeartBeat;
            HeartbeatConfigInterval  = definition.HeartbeatConfigInterval;
            ViewRequestTimeout       = definition.ViewRequestTimeout;
            Expect100Continue        = definition.Expect100Continue;
            DefaultConnectionLimit   = definition.DefaultConnectionLimit;
            MaxServicePointIdleTime  = definition.MaxServicePointIdleTime;
            EnableOperationTiming    = definition.EnableOperationTiming;
            DefaultOperationLifespan = definition.OperationLifespan;
            QueryRequestTimeout      = definition.QueryRequestTimeout;
            EnableQueryTiming        = definition.EnableQueryTiming;
            SearchRequestTimeout     = definition.SearchRequestTimeout;
            VBucketRetrySleepTime    = definition.VBucketRetrySleepTime;

            IOErrorCheckInterval = definition.IOErrorCheckInterval;
            IOErrorThreshold     = definition.IOErrorThreshold;

            //transcoders, converters, and serializers...o mai.
            Serializer = definition.Serializer != null
                ? SerializerFactory.GetSerializer(definition.Serializer)
                : SerializerFactory.GetSerializer();

            Converter = definition.Converter != null
                ? ConverterFactory.GetConverter(definition.Converter)
                : ConverterFactory.GetConverter();

            Transcoder = definition.Transcoder != null
                ? TranscoderFactory.GetTranscoder(this, definition.Transcoder)
                : TranscoderFactory.GetTranscoder(this);

            IOServiceCreator = definition.IOService != null
                ? IOServiceFactory.GetFactory(definition.IOService)
                : IOServiceFactory.GetFactory();

            //to enable tcp keep-alives
            EnableTcpKeepAlives  = definition.EnableTcpKeepAlives;
            TcpKeepAliveInterval = definition.TcpKeepAliveInterval;
            TcpKeepAliveTime     = definition.TcpKeepAliveTime;

            var keepAlivesChanged = EnableTcpKeepAlives != true ||
                                    TcpKeepAliveInterval != 1000 ||
                                    TcpKeepAliveTime != 2 * 60 * 60 * 1000;

            //The default sasl mechanism creator
            CreateSaslMechanism = SaslFactory.GetFactory();

            //NOTE: this is a global setting and applies to all instances
            IgnoreRemoteCertificateNameMismatch = definition.IgnoreRemoteCertificateNameMismatch;

            UseInterNetworkV6Addresses = definition.UseInterNetworkV6Addresses;

            foreach (var server in definition.Servers ?? new[] { Defaults.Server })
            {
                Servers.Add(server);
                _serversChanged = true;
            }

            if (definition.ConnectionPool != null)
            {
                ConnectionPoolCreator = definition.ConnectionPool.Type != null
                    ? ConnectionPoolFactory.GetFactory(definition.ConnectionPool.Type)
                    : ConnectionPoolFactory.GetFactory();

                PoolConfiguration = new PoolConfiguration(definition.ConnectionPool.MaxSize, definition.ConnectionPool.MinSize)
                {
                    WaitTimeout         = definition.ConnectionPool.WaitTimeout,
                    ShutdownTimeout     = definition.ConnectionPool.ShutdownTimeout,
                    UseSsl              = UseSsl ? UseSsl : definition.ConnectionPool.UseSsl,
                    BufferSize          = definition.ConnectionPool.BufferSize,
                    BufferAllocator     = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize),
                    ConnectTimeout      = definition.ConnectionPool.ConnectTimeout,
                    SendTimeout         = definition.ConnectionPool.SendTimeout,
                    EnableTcpKeepAlives =
                        keepAlivesChanged ? EnableTcpKeepAlives : definition.ConnectionPool.EnableTcpKeepAlives,
                    TcpKeepAliveInterval =
                        keepAlivesChanged ? TcpKeepAliveInterval : definition.ConnectionPool.TcpKeepAliveInterval,
                    TcpKeepAliveTime     = keepAlivesChanged ? TcpKeepAliveTime : definition.ConnectionPool.TcpKeepAliveTime,
                    CloseAttemptInterval = definition.ConnectionPool.CloseAttemptInterval,
                    MaxCloseAttempts     = definition.ConnectionPool.MaxCloseAttempts,
                    ClientConfiguration  = this
                };
            }
            else
            {
                ConnectionPoolCreator = ConnectionPoolFactory.GetFactory();
                PoolConfiguration     = new PoolConfiguration(this);
            }

            BucketConfigs = new Dictionary <string, BucketConfiguration>();
            if (definition.Buckets != null)
            {
                foreach (var bucket in definition.Buckets)
                {
                    var bucketConfiguration = new BucketConfiguration
                    {
                        BucketName               = bucket.Name,
                        UseSsl                   = bucket.UseSsl,
                        Password                 = bucket.Password,
                        ObserveInterval          = bucket.ObserveInterval,
                        DefaultOperationLifespan = bucket.OperationLifespan ?? (uint)DefaultOperationLifespan,
                        ObserveTimeout           = bucket.ObserveTimeout,
                        UseEnhancedDurability    = bucket.UseEnhancedDurability
                    };

                    //By skipping the bucket specific connection pool settings we allow inheritance from clien-wide connection pool settings.
                    if (bucket.ConnectionPool != null)
                    {
                        bucketConfiguration.PoolConfiguration = new PoolConfiguration(bucket.ConnectionPool.MaxSize, bucket.ConnectionPool.MinSize)
                        {
                            WaitTimeout         = bucket.ConnectionPool.WaitTimeout,
                            ShutdownTimeout     = bucket.ConnectionPool.ShutdownTimeout,
                            UseSsl              = bucket.ConnectionPool.UseSsl,
                            BufferSize          = bucket.ConnectionPool.BufferSize,
                            BufferAllocator     = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize),
                            ConnectTimeout      = bucket.ConnectionPool.ConnectTimeout,
                            SendTimeout         = bucket.ConnectionPool.SendTimeout,
                            EnableTcpKeepAlives =
                                keepAlivesChanged ? EnableTcpKeepAlives : bucket.ConnectionPool.EnableTcpKeepAlives,
                            TcpKeepAliveInterval =
                                keepAlivesChanged ? TcpKeepAliveInterval : bucket.ConnectionPool.TcpKeepAliveInterval,
                            TcpKeepAliveTime =
                                keepAlivesChanged ? TcpKeepAliveTime : bucket.ConnectionPool.TcpKeepAliveTime,
                            CloseAttemptInterval  = bucket.ConnectionPool.CloseAttemptInterval,
                            MaxCloseAttempts      = bucket.ConnectionPool.MaxCloseAttempts,
                            UseEnhancedDurability = bucket.UseEnhancedDurability,
                            ClientConfiguration   = this
                        };
                    }
                    else
                    {
                        bucketConfiguration.PoolConfiguration        = PoolConfiguration;
                        bucketConfiguration.PoolConfiguration.UseSsl = bucketConfiguration.UseSsl;
                        bucketConfiguration.PoolConfiguration.UseEnhancedDurability = bucketConfiguration.UseEnhancedDurability;
                    }
                    BucketConfigs.Add(bucket.Name, bucketConfiguration);
                }
            }

            //Set back to default
            _operationLifespanChanged = false;
            _poolConfigurationChanged = false;
        }
예제 #17
0
        void SetServersTimeTable()
        {
            Server tmp1 = new Server();

            tmp1.ID = 1;

            TimeDistribution S1T1 = new TimeDistribution();

            S1T1.Time            = 2;
            S1T1.Probability     = 0.30m;
            S1T1.CummProbability = 0.30m;
            S1T1.MinRange        = 1;
            S1T1.MaxRange        = 30;

            TimeDistribution S1T2 = new TimeDistribution();

            S1T2.Time            = 3;
            S1T2.Probability     = 0.28m;
            S1T2.CummProbability = 0.58m;
            S1T2.MinRange        = 31;
            S1T2.MaxRange        = 58;

            TimeDistribution S1T3 = new TimeDistribution();

            S1T3.Time            = 4;
            S1T3.Probability     = 0.25m;
            S1T3.CummProbability = 0.83m;
            S1T3.MinRange        = 59;
            S1T3.MaxRange        = 83;

            TimeDistribution S1T4 = new TimeDistribution();

            S1T4.Time            = 5;
            S1T4.Probability     = 0.17m;
            S1T4.CummProbability = 1m;
            S1T4.MinRange        = 84;
            S1T4.MaxRange        = 100;

            tmp1.TimeDistribution.Add(S1T1);
            tmp1.TimeDistribution.Add(S1T2);
            tmp1.TimeDistribution.Add(S1T3);
            tmp1.TimeDistribution.Add(S1T4);


            Server tmp2 = new Server();

            tmp2.ID = 2;

            TimeDistribution S2T1 = new TimeDistribution();

            S2T1.Time            = 3;
            S2T1.Probability     = 0.35m;
            S2T1.CummProbability = 0.35m;
            S2T1.MinRange        = 1;
            S2T1.MaxRange        = 35;

            TimeDistribution S2T2 = new TimeDistribution();

            S2T2.Time            = 4;
            S2T2.Probability     = 0.25m;
            S2T2.CummProbability = 0.60m;
            S2T2.MinRange        = 36;
            S2T2.MaxRange        = 60;

            TimeDistribution S2T3 = new TimeDistribution();

            S2T3.Time            = 5;
            S2T3.Probability     = 0.20m;
            S2T3.CummProbability = 0.80m;
            S2T3.MinRange        = 61;
            S2T3.MaxRange        = 80;

            TimeDistribution S2T4 = new TimeDistribution();

            S2T4.Time            = 6;
            S2T4.Probability     = 0.20m;
            S2T4.CummProbability = 1m;
            S2T4.MinRange        = 81;
            S2T4.MaxRange        = 100;

            tmp2.TimeDistribution.Add(S2T1);
            tmp2.TimeDistribution.Add(S2T2);
            tmp2.TimeDistribution.Add(S2T3);
            tmp2.TimeDistribution.Add(S2T4);

            Servers.Add(tmp1);
            Servers.Add(tmp2);
        }
예제 #18
0
 public void AddServer(string address, int port)
 {
     Servers.Add(new Server {
         Address = address, Port = port
     });
 }
예제 #19
0
 public void UseServer(Func <BackgroundJobServer> server)
 {
     Servers.Add(server);
 }
        /// <summary>
        /// For synchronization with App.config or Web.configs.
        /// </summary>
        /// <param name="section"></param>
        public ClientConfiguration(CouchbaseClientSection section)
        {
            Timer = TimingFactory.GetTimer(Log);
            NodeAvailableCheckInterval = section.NodeAvailableCheckInterval;
            UseSsl                = section.UseSsl;
            SslPort               = section.SslPort;
            ApiPort               = section.ApiPort;
            DirectPort            = section.DirectPort;
            MgmtPort              = section.MgmtPort;
            HttpsMgmtPort         = section.HttpsMgmtPort;
            HttpsApiPort          = section.HttpsApiPort;
            ObserveInterval       = section.ObserveInterval;
            ObserveTimeout        = section.ObserveTimeout;
            MaxViewRetries        = section.MaxViewRetries;
            ViewHardTimeout       = section.ViewHardTimeout;
            SerializationSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            DeserializationSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
            EnableConfigHeartBeat    = section.EnableConfigHeartBeat;
            HeartbeatConfigInterval  = section.HeartbeatConfigInterval;
            ViewRequestTimeout       = section.ViewRequestTimeout;
            Expect100Continue        = section.Expect100Continue;
            DefaultConnectionLimit   = section.DefaultConnectionLimit;
            MaxServicePointIdleTime  = section.MaxServicePointIdleTime;
            EnableOperationTiming    = section.EnableOperationTiming;
            DefaultOperationLifespan = section.OperationLifespan;
            QueryRequestTimeout      = section.QueryRequestTimeout;
            IOErrorCheckInterval     = section.IOErrorCheckInterval;
            IOErrorThreshold         = section.IOErrorThreshold;

            //transcoders, converters, and serializers...o mai.
            Serializer = SerializerFactory.GetSerializer(this, section.Serializer);
            Converter  = ConverterFactory.GetConverter(section.Converter);
            Transcoder = TranscoderFactory.GetTranscoder(this, section.Transcoder);

            //to enable tcp keep-alives
            EnableTcpKeepAlives  = section.EnableTcpKeepAlives;
            TcpKeepAliveInterval = section.TcpKeepAliveInterval;
            TcpKeepAliveTime     = section.TcpKeepAliveTime;

            var keepAlivesChanged = EnableTcpKeepAlives != true ||
                                    TcpKeepAliveInterval != 1000 ||
                                    TcpKeepAliveTime != 2 * 60 * 60 * 1000;

            //the default ioservice - this should be refactored to come from the configsection
            IOServiceCreator = IOServiceFactory.GetFactory(section.IOService);

            //the default connection pool creator
            if (section.UseSsl)
            {
                section.ConnectionPool.UseSsl = section.UseSsl;
            }
            ConnectionPoolCreator = ConnectionPoolFactory.GetFactory(section.ConnectionPool);

            //The default sasl mechanism creator
            CreateSaslMechanism = SaslFactory.GetFactory();

            foreach (var server in section.Servers)
            {
                Servers.Add(((UriElement)server).Uri);
                _serversChanged = true;
            }

            PoolConfiguration = new PoolConfiguration
            {
                MaxSize              = section.ConnectionPool.MaxSize,
                MinSize              = section.ConnectionPool.MinSize,
                WaitTimeout          = section.ConnectionPool.WaitTimeout,
                ShutdownTimeout      = section.ConnectionPool.ShutdownTimeout,
                UseSsl               = UseSsl ? UseSsl : section.ConnectionPool.UseSsl,
                BufferSize           = section.ConnectionPool.BufferSize,
                BufferAllocator      = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize),
                ConnectTimeout       = section.ConnectionPool.ConnectTimeout,
                SendTimeout          = section.ConnectionPool.SendTimeout,
                EnableTcpKeepAlives  = keepAlivesChanged ? EnableTcpKeepAlives : section.ConnectionPool.EnableTcpKeepAlives,
                TcpKeepAliveInterval = keepAlivesChanged ? TcpKeepAliveInterval : section.ConnectionPool.TcpKeepAliveInterval,
                TcpKeepAliveTime     = keepAlivesChanged ? TcpKeepAliveTime : section.ConnectionPool.TcpKeepAliveTime,
                CloseAttemptInterval = section.ConnectionPool.CloseAttemptInterval,
                MaxCloseAttempts     = section.ConnectionPool.MaxCloseAttempts,
                ClientConfiguration  = this
            };

            BucketConfigs = new Dictionary <string, BucketConfiguration>();
            foreach (var bucketElement in section.Buckets)
            {
                var bucket = (BucketElement)bucketElement;
                var bucketConfiguration = new BucketConfiguration
                {
                    BucketName               = bucket.Name,
                    UseSsl                   = bucket.UseSsl,
                    Password                 = bucket.Password,
                    ObserveInterval          = bucket.ObserveInterval,
                    DefaultOperationLifespan = bucket.OperationLifespan ?? (uint)DefaultOperationLifespan,
                    ObserveTimeout           = bucket.ObserveTimeout,
                    UseEnhancedDurability    = bucket.UseEnhancedDurability
                };
                //Configuration properties (including elements) can not be null, but we can check if it was originally presnt in xml and skip it.
                //By skipping the bucket specific connection pool settings we allow inheritance from clien-wide connection pool settings.
                if (bucket.ConnectionPool.ElementInformation.IsPresent)
                {
                    bucketConfiguration.PoolConfiguration = new PoolConfiguration
                    {
                        MaxSize             = bucket.ConnectionPool.MaxSize,
                        MinSize             = bucket.ConnectionPool.MinSize,
                        WaitTimeout         = bucket.ConnectionPool.WaitTimeout,
                        ShutdownTimeout     = bucket.ConnectionPool.ShutdownTimeout,
                        UseSsl              = bucket.ConnectionPool.UseSsl,
                        BufferSize          = bucket.ConnectionPool.BufferSize,
                        BufferAllocator     = (p) => new BufferAllocator(p.MaxSize * p.BufferSize, p.BufferSize),
                        ConnectTimeout      = bucket.ConnectionPool.ConnectTimeout,
                        SendTimeout         = bucket.ConnectionPool.SendTimeout,
                        EnableTcpKeepAlives =
                            keepAlivesChanged ? EnableTcpKeepAlives : bucket.ConnectionPool.EnableTcpKeepAlives,
                        TcpKeepAliveInterval =
                            keepAlivesChanged ? TcpKeepAliveInterval : bucket.ConnectionPool.TcpKeepAliveInterval,
                        TcpKeepAliveTime      = keepAlivesChanged ? TcpKeepAliveTime : bucket.ConnectionPool.TcpKeepAliveTime,
                        CloseAttemptInterval  = bucket.ConnectionPool.CloseAttemptInterval,
                        MaxCloseAttempts      = bucket.ConnectionPool.MaxCloseAttempts,
                        UseEnhancedDurability = bucket.UseEnhancedDurability,
                        ClientConfiguration   = this
                    };
                }
                else
                {
                    bucketConfiguration.PoolConfiguration = PoolConfiguration;
                }
                BucketConfigs.Add(bucket.Name, bucketConfiguration);
            }

            //Set back to default
            _operationLifespanChanged = false;
            _poolConfigurationChanged = false;
        }
예제 #21
0
        /// <summary>
        ///     Initialize from <see cref="XmlElement" />. Can be used to embed cache configuration in larger configuration files
        /// </summary>
        /// <param name="doc"> </param>
        private void LoadFromElement(XmlElement doc)
        {
            var persistent = StringFromXpath(doc, "@isPersistent");

            IsPersistent = IsYes(persistent);

            var nodeList = doc.SelectNodes("//connectionPool");

            if (nodeList != null)
            {
                foreach (XmlNode node in nodeList)
                {
                    var capacity = StringFromXpath(node, "capacity");
                    ConnectionPoolCapacity = int.Parse(capacity);

                    var preloaded = StringFromXpath(node, "preloaded");
                    PreloadedConnections = int.Parse(preloaded);
                }
            }


            //read servers
            nodeList = doc.SelectNodes("//servers/server");
            if (nodeList != null)
            {
                foreach (XmlNode node in nodeList)
                {
                    var cfg = new ServerConfig();

                    var port = StringFromXpath(node, "port");
                    cfg.Port = int.Parse(port);

                    var host = StringFromXpath(node, "host");
                    cfg.Host = host;

                    var weight = StringFromXpath(node, "weight");


                    Servers.Add(cfg);
                }
            }

            //read converters
            nodeList = doc.SelectNodes("//keyConverters/converter");


            if (nodeList != null)
            {
                foreach (XmlNode node in nodeList)
                {
                    var converterTypeName = StringFromXpath(node, "@fullName");

                    var converterType = Type.GetType(converterTypeName);
                    if (converterType == null)
                    {
                        throw new CacheException(
                                  $"Can not instantiate a key converter for type {converterTypeName}");
                    }

                    if (!(Activator.CreateInstance(converterType) is IKeyConverter converter))
                    {
                        throw new CacheException(
                                  $"Can not instantiate a key converter for type {converterTypeName}");
                    }
                }
            }

            //type descriptions
            nodeList = doc.SelectNodes("//typeDescriptions/type");
            if (nodeList != null)
            {
                foreach (XmlNode node in nodeList)
                {
                    var typeDescription = new TypeDescriptionConfig();
                    var typeName        = StringFromXpath(node, "@fullName");
                    if (string.IsNullOrEmpty(typeName))
                    {
                        throw new CacheException("Missing fullName attribute on a type description");
                    }

                    var assemblyName = StringFromXpath(node, "@assembly");
                    if (string.IsNullOrEmpty(assemblyName))
                    {
                        throw new CacheException("Missing assembly attribute on a type description");
                    }

                    var useCompression = StringFromXpath(node, "@useCompression");
                    typeDescription.UseCompression = IsYes(useCompression);

                    typeDescription.FullTypeName = typeName;
                    typeDescription.AssemblyName = assemblyName;

                    var propertyNodes = node.SelectNodes("property");
                    if (propertyNodes != null)
                    {
                        foreach (XmlNode propertyNode in propertyNodes)
                        {
                            var     propertyName = StringFromXpath(propertyNode, "@name");
                            var     propertyType = StringFromXpath(propertyNode, "@keyType");
                            KeyType keyType;
                            switch (propertyType.ToUpper())
                            {
                            case "PRIMARY":
                                keyType = KeyType.Primary;
                                break;

                            case "UNIQUE":
                                keyType = KeyType.Unique;
                                break;

                            case "INDEX":
                                keyType = KeyType.ScalarIndex;
                                break;

                            case "LIST":
                                keyType = KeyType.ListIndex;
                                break;

                            default:
                                throw new CacheException(
                                          $"Unknown key type {propertyType} for property{propertyName}");
                            }

                            var keyDataType = StringFromXpath(propertyNode, "@dataType");

                            KeyDataType dataType;
                            switch (keyDataType.ToUpper())
                            {
                            case "INT":
                            case "INTEGER":
                                dataType = KeyDataType.IntKey;
                                break;

                            case "STRING":
                                dataType = KeyDataType.StringKey;
                                break;

                            default:
                                throw new CacheException(
                                          $"Unknown key data type {keyDataType} for property{propertyName}");
                            }

                            var orderedIndex = StringFromXpath(propertyNode, "@ordered");
                            var ordered      = orderedIndex.ToUpper() == "TRUE";


                            typeDescription.Add(propertyName, keyType, dataType, ordered);
                        }
                    }

                    TypeDescriptions.Add(typeName, typeDescription);
                }
            }
        }
예제 #22
0
        protected async Task <RavenServer> CreateRaftClusterAndGetLeader(int numberOfNodes, bool shouldRunInMemory = true, int?leaderIndex = null, bool useSsl = false, IDictionary <string, string> customSettings = null)
        {
            leaderIndex = leaderIndex ?? _random.Next(0, numberOfNodes);
            RavenServer leader          = null;
            var         serversToPorts  = new Dictionary <RavenServer, string>();
            var         clustersServers = new List <RavenServer>();

            _electionTimeoutInMs = Math.Max(300, numberOfNodes * 80);
            for (var i = 0; i < numberOfNodes; i++)
            {
                customSettings = customSettings ?? new Dictionary <string, string>()
                {
                    [RavenConfiguration.GetKey(x => x.Cluster.MoveToRehabGraceTime)] = "1",
                    [RavenConfiguration.GetKey(x => x.Cluster.ElectionTimeout)]      = _electionTimeoutInMs.ToString(),
                    [RavenConfiguration.GetKey(x => x.Cluster.StabilizationTime)]    = "1",
                };
                string serverUrl;

                if (useSsl)
                {
                    serverUrl = UseFiddlerUrl("https://127.0.0.1:0");
                    SetupServerAuthentication(customSettings, serverUrl);
                }
                else
                {
                    serverUrl = UseFiddlerUrl("http://127.0.0.1:0");
                    customSettings[RavenConfiguration.GetKey(x => x.Core.ServerUrls)] = serverUrl;
                }

                var server = GetNewServer(customSettings, runInMemory: shouldRunInMemory);
                var port   = Convert.ToInt32(server.ServerStore.GetNodeHttpServerUrl().Split(':')[2]);
                var prefix = useSsl ? "https" : "http";
                serverUrl = UseFiddlerUrl($"{prefix}://127.0.0.1:{port}");
                Servers.Add(server);
                clustersServers.Add(server);

                serversToPorts.Add(server, serverUrl);
                if (i == leaderIndex)
                {
                    server.ServerStore.EnsureNotPassive();
                    leader = server;
                }
            }
            for (var i = 0; i < numberOfNodes; i++)
            {
                if (i == leaderIndex)
                {
                    continue;
                }
                var follower = clustersServers[i];
                // ReSharper disable once PossibleNullReferenceException
                await leader.ServerStore.AddNodeToClusterAsync(serversToPorts[follower]);

                await follower.ServerStore.WaitForTopology(Leader.TopologyModification.Voter);
            }
            // ReSharper disable once PossibleNullReferenceException
            var condition = await leader.ServerStore.WaitForState(RachisState.Leader, CancellationToken.None).WaitAsync(numberOfNodes * _electionTimeoutInMs * 5);

            var states = string.Empty;

            if (condition == false)
            {
                states = GetLastStatesFromAllServersOrderedByTime();
            }
            Assert.True(condition, "The leader has changed while waiting for cluster to become stable. All nodes status: " + states);
            return(leader);
        }
예제 #23
0
        protected async Task <(RavenServer, Dictionary <RavenServer, ProxyServer>)> CreateRaftClusterWithProxiesAndGetLeader(int numberOfNodes, bool shouldRunInMemory = true, int?leaderIndex = null, bool useSsl = false, int delay = 0, [CallerMemberName] string caller = null)
        {
            leaderIndex = leaderIndex ?? _random.Next(0, numberOfNodes);
            RavenServer leader           = null;
            var         serversToPorts   = new Dictionary <RavenServer, string>();
            var         serversToProxies = new Dictionary <RavenServer, ProxyServer>();

            for (var i = 0; i < numberOfNodes; i++)
            {
                string serverUrl;
                var    customSettings = GetServerSettingsForPort(useSsl, out serverUrl);

                int proxyPort = 10000;
                var co        = new ServerCreationOptions
                {
                    CustomSettings      = customSettings,
                    RunInMemory         = shouldRunInMemory,
                    RegisterForDisposal = false
                };
                var server = GetNewServer(co, caller);
                var proxy  = new ProxyServer(ref proxyPort, Convert.ToInt32(server.ServerStore.GetNodeHttpServerUrl()), delay);
                serversToProxies.Add(server, proxy);

                if (Servers.Any(s => s.WebUrl.Equals(server.WebUrl, StringComparison.OrdinalIgnoreCase)) == false)
                {
                    Servers.Add(server);
                }

                serversToPorts.Add(server, serverUrl);
                if (i == leaderIndex)
                {
                    await server.ServerStore.EnsureNotPassiveAsync();

                    leader = server;
                }
            }
            using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5)))
            {
                for (var i = 0; i < numberOfNodes; i++)
                {
                    if (i == leaderIndex)
                    {
                        continue;
                    }
                    var follower = Servers[i];
                    // ReSharper disable once PossibleNullReferenceException
                    await leader.ServerStore.AddNodeToClusterAsync(serversToPorts[follower], token : cts.Token);

                    await follower.ServerStore.WaitForTopology(Leader.TopologyModification.Voter, cts.Token);
                }
            }
            // ReSharper disable once PossibleNullReferenceException
            var condition = await leader.ServerStore.WaitForState(RachisState.Leader, CancellationToken.None).WaitAsync(numberOfNodes * _electionTimeoutInMs * 5);

            var states = string.Empty;

            if (condition == false)
            {
                states = GetLastStatesFromAllServersOrderedByTime();
            }
            Assert.True(condition, "The leader has changed while waiting for cluster to become stable. All nodes status: " + states);
            return(leader, serversToProxies);
        }
예제 #24
0
파일: Builder.cs 프로젝트: vegah/siridb.net
 public Builder AddServer(Server server)
 {
     Servers.Add(server);
     return(this);
 }