예제 #1
0
        private static void WaitUntilServiceIsUp(SqlDServiceModel service)
        {
            var wait = new ManualResetEvent(false);

            using (var endPointMonitor = new EndPointMonitor(service.ToEndPoint()))
            {
                endPointMonitor.OnUp += (args) =>
                {
                    Log.Out.Info($"Child process {service.Host}:{service.Port}/{service.Database} is up!");
                    wait.Set();
                };

                try
                {
                    Log.Out.Info($"Waiting {Constants.END_POINT_UP_WAIT_FOR_TIMEOUT.TotalSeconds}s for child process {service.Host}:{service.Port}/{service.Database}");
                    wait.WaitOne(Constants.END_POINT_UP_WAIT_FOR_TIMEOUT);

                    var client = SqlDStart.NewClient().ConnectedTo(service.ToEndPoint());
                    if (!client.Ping(service.ToEndPoint()))
                    {
                        throw new ProcessStartFailedException($"Failed to launch child process {service.Host}:{service.Port}/{service.Database}");
                    }
                }
                catch (Exception err)
                {
                    Log.Out.Error($"Failed to start {service.Host}:{service.Port}/{service.Database} as a separate process");
                    Log.Out.Error(err.ToString());
                }
            }
        }
예제 #2
0
        public ConnectionClient GetClientOrDefault(QueryContext context, ConfigService config)
        {
            var sqlDConfiguration = config.Get();
            var cfg    = sqlDConfiguration.Services.FirstOrDefault(x => x.Tags.Contains("master"));
            var client = SqlDStart.NewClient().ConnectedTo(EndPoint.FromUri(context.TargetUri) ?? cfg.ToEndPoint());

            return(client);
        }
예제 #3
0
        public void KillService(string host, int port, bool removeFromConfig)
        {
            var hostToKill = new EndPoint(host, port);

            try
            {
                Log.Out.Info($"Sending remote kill command to {hostToKill.ToUrl()}");
                SqlDStart.NewClient(withRetries: false).ConnectedTo(hostToKill).Kill();
            }
            catch (Exception err)
            {
                Log.Out.Error(err.Message);
                Log.Out.Error(err.StackTrace);
            }

            try
            {
                Log.Out.Info($"Unregistering {hostToKill.ToUrl()}");
                Registry.Unregister(hostToKill);
            }
            catch (Exception err)
            {
                Log.Out.Error(err.Message);
                Log.Out.Error(err.StackTrace);
            }

            if (removeFromConfig)
            {
                try
                {
                    Log.Out.Info($"Removing {hostToKill.ToUrl()} from config");
                    var config = this.config.Get();
                    config.Services = config.Services.Where(x => !x.ToEndPoint().Equals(hostToKill)).ToList();
                    this.config.Set(config);
                }
                catch (Exception err)
                {
                    Log.Out.Error(err.Message);
                    Log.Out.Error(err.StackTrace);
                }
            }
        }
예제 #4
0
            public static void SetUp()
            {
                lock (Synchronise)
                {
                    RegistryClient = SqlDStart.NewClient().ConnectedTo(EndPoints.Registry);
                    EndPointMonitor.WaitUntil(RegistryClient.EndPoint, EndPointIs.Up);

                    AlphaClient = SqlDStart.NewClient().ConnectedTo(EndPoints.Alpha);
                    EndPointMonitor.WaitUntil(AlphaClient.EndPoint, EndPointIs.Up);

                    BetaClient = SqlDStart.NewClient().ConnectedTo(EndPoints.Beta);
                    EndPointMonitor.WaitUntil(BetaClient.EndPoint, EndPointIs.Up);

                    Free1Client = SqlDStart.NewClient().ConnectedTo(EndPoints.Free1);
                    EndPointMonitor.WaitUntil(Free1Client.EndPoint, EndPointIs.Up);

                    Free2Client = SqlDStart.NewClient().ConnectedTo(EndPoints.Free2);
                    EndPointMonitor.WaitUntil(Free2Client.EndPoint, EndPointIs.Up);
                }
            }
예제 #5
0
        private async Task MonitorEndPoint()
        {
            while (Interlocked.Read(ref isRunning) == 1)
            {
                try
                {
                    var client     = SqlDStart.NewClient().ConnectedTo(EndPoint);
                    var pingResult = await client.PingAsync();

                    Interlocked.Exchange(ref isUp, pingResult ? 1 : 0);
                    DoEvents();
                }
                finally
                {
                    if (Interlocked.Read(ref isRunning) != 1)
                    {
                        Thread.Sleep(Constants.END_POINT_MONTIOR_SLEEP_INTERVAL);
                    }
                }
            }
        }
예제 #6
0
        private async Task ForwardToClients(Func <ConnectionClient, Task <CommandResponse> > clientApiCall)
        {
            foreach (var forwardAddress in forwardAddresses)
            {
                try
                {
                    var client = SqlDStart.NewClient().ConnectedTo(forwardAddress);

                    var commandResponse = await clientApiCall(client);

                    if (commandResponse.StatusCode != StatusCode.Ok)
                    {
                        Logging.Log.Out.Error($"Replicated to {forwardAddress} with {commandResponse.Error}");
                    }
                }
                catch (Exception err)
                {
                    Logging.Log.Out.Error(err.ToString());
                }
            }
        }
예제 #7
0
        public virtual void Push(EndPoint target)
        {
            var targetRegistry = SqlDStart.NewClient().ConnectedTo(target);
            var sourceRegistry = SqlDStart.NewClient().ConnectedTo(target);
            var registry       = sourceRegistry.Get <Registration, RegistrationResponse>(REGISTRY_RESOURCE);

            foreach (var registryItem in registry.Registry)
            {
                if (!registryItem.Tags.Contains(Registry.REGISTRY))
                {
                    targetRegistry.Post <Registration, RegistrationResponse>(
                        REGISTRY_RESOURCE,
                        new Registration
                    {
                        Name     = registryItem.Name,
                        Database = registryItem.Database,
                        Source   = registryItem.ToEndPoint(),
                        Tags     = registryItem.TagsAsArray
                    });
                }
            }
        }
예제 #8
0
 public RegistryClient(EndPoint endPoint)
 {
     this.client = SqlDStart.NewClient().ConnectedTo(endPoint);
 }