示例#1
0
 public StartedGrpcServer([NotNull] Grpc.Core.Server server,
                          [NotNull] T serviceImplementation,
                          [CanBeNull] IServiceHealth serviceHealth)
 {
     Server = server;
     ServiceImplementation = serviceImplementation;
     ServiceHealth         = serviceHealth;
 }
示例#2
0
        private static Grpc.Core.Server StartServer([NotNull] MicroserverArguments arguments,
                                                    out IServiceHealth health)
        {
            // TODO: Move to ProSuite
            var healthService = new HealthServiceImpl();

            health = null;             // new ServiceHealth(healthService);

            int maxThreadCount = arguments.MaxParallel;

            if (maxThreadCount <= 0)
            {
                maxThreadCount = Environment.ProcessorCount - 1;
            }

            var taskScheduler = new StaTaskScheduler(maxThreadCount);

            var removeOverlapsServiceImpl = new RemoveOverlapsGrpcImpl(taskScheduler)
            {
                //Health = health
            };

            var advancedReshapeServiceImpl = new AdvancedReshapeGrpcImpl(taskScheduler);
            var changeAlongServiceImpl     = new ChangeAlongGrpcImpl(taskScheduler);

            //health.SetStatus(removeOverlapsServiceImpl.GetType(), true);

            ServerCredentials serverCredentials =
                GrpcServerUtils.GetServerCredentials(arguments.Certificate,
                                                     arguments.PrivateKeyFile);

            var oneGb = (int)Math.Pow(1024, 3);

            IList <ChannelOption> channelOptions = GrpcServerUtils.CreateChannelOptions(oneGb);

            var server =
                new Grpc.Core.Server(channelOptions)
            {
                Services =
                {
                    RemoveOverlapsGrpc.BindService(removeOverlapsServiceImpl),
                    ReshapeGrpc.BindService(advancedReshapeServiceImpl),
                    ChangeAlongGrpc.BindService(changeAlongServiceImpl)
                    //Health.BindService(healthService)
                },
                Ports =
                {
                    new ServerPort(arguments.HostName, arguments.Port, serverCredentials)
                }
            };

            server.Start();

            _msg.InfoFormat("Service is listening on host {0}, port {1}.", arguments.HostName,
                            arguments.Port);

            return(server);
        }
示例#3
0
        private static Grpc.Core.Server Run(string[] args,
                                            out IServiceHealth health)
        {
            Grpc.Core.Server server;

            try
            {
                MicroserverArguments arguments;
                string configFilePath;
                if (!TryGetArgumentsFromConfigFile(args, _configFileName, out arguments,
                                                   out configFilePath))
                {
                    var parsedArgs = Parser.Default.ParseArguments <MicroserverArguments>(args);

                    parsedArgs.WithParsed(a => { arguments = a; });
                }

                ConfigureLogging(arguments.VerboseLogging, _logConfigFileName);

                // Read the RuntimeUtils.Version to initialize it and use fall-back implementation
                // to avoid subsequent hang once the license has been initialized (this is probably
                // only relevant for 10.x).
                _msg.DebugFormat("Installed ArcGIS Version: {0}.", RuntimeUtils.Version);

                if (configFilePath != null)
                {
                    _msg.InfoFormat("Using service configuration defined in {0}", configFilePath);
                }
                else
                {
                    _msg.DebugFormat(
                        "Program was called with the following command line arguments: {0}{1}",
                        Environment.NewLine, arguments);
                }

                _msg.DebugFormat("Host: {0}", arguments.HostName);
                _msg.DebugFormat("Port: {0}", arguments.Port);

                _msg.InfoFormat("Checking out ArcGIS license...");

                ComUtils.ExecuteInStaThread(CheckoutLicense);

                EnvironmentUtils.SetConfigurationDirectoryProvider(
                    ConfigurationUtils.GetAppDataConfigDirectoryProvider());

                server = StartServer(arguments, out health);
            }
            catch (Exception ex)
            {
                _msg.Error("An error occurred in QA microservice startup.", ex);
                throw;
            }

            return(server);
        }
示例#4
0
        private static Grpc.Core.Server Run(string[] args,
                                            out IServiceHealth health)
        {
            Grpc.Core.Server server;

            try
            {
                MicroserverArguments arguments;
                string configFilePath;
                if (!ConfigurationUtils.TryGetArgumentsFromConfigFile(
                        args, _configFileName, out arguments, out configFilePath))
                {
                    var parsedArgs = Parser.Default.ParseArguments <MicroserverArguments>(args);

                    parsedArgs.WithParsed(a => { arguments = a; });
                }

                ConfigureLogging(arguments.VerboseLogging, _logConfigFileName);

                if (configFilePath != null)
                {
                    _msg.InfoFormat("Using service configuration defined in {0}", configFilePath);
                }
                else
                {
                    _msg.DebugFormat(
                        "Program was called with the following command line arguments: {0}{1}",
                        Environment.NewLine, arguments);
                }

                _msg.DebugFormat("Host: {0}", arguments.HostName);
                _msg.DebugFormat("Port: {0}", arguments.Port);

                _msg.InfoFormat("Checking out ArcGIS license...");

                ArcGISLicenses.InitializeAo11();

                EnvironmentUtils.SetConfigurationDirectoryProvider(
                    ConfigurationUtils.GetAppDataConfigDirectoryProvider());

                server = StartServer(arguments, out health);
            }
            catch (Exception ex)
            {
                _msg.Error("An error occurred in QA microservice startup.", ex);
                throw;
            }

            return(server);
        }
示例#5
0
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (_health == null)
            {
                return;
            }

            if (_health.IsAnyServiceUnhealthy())
            {
                _health = null;

                _msg.Warn("Shutting down due to unhealthy service...");

                GrpcServerUtils.GracefullyStop(_server);

                // This allows the auto-restart to kick in:
                Environment.Exit(-1);
            }
        }
示例#6
0
        private void StartHealthChecking(IServiceHealth health)
        {
            _health = health;

            if (_health == null)
            {
                return;
            }

            if (_timer != null)
            {
                _msg.Info("Health-check timer is already running.");
                return;
            }

            _timer = new Timer(_interval)
            {
                AutoReset = true
            };

            _timer.Elapsed += _timer_Elapsed;
            _timer.Start();
        }
示例#7
0
 public StartedGrpcServer([NotNull] Grpc.Core.Server server,
                          [CanBeNull] IServiceHealth serviceHealth)
 {
     Server        = server;
     ServiceHealth = serviceHealth;
 }